WPSEO_Taxonomy_Metabox

This class generates the metabox on the edit term page.

Defined (1)

The class is defined in the following location(s).

/admin/taxonomy/class-taxonomy-metabox.php  
  1. class WPSEO_Taxonomy_Metabox { 
  2.  
  3. /** 
  4. * @var stdClass 
  5. */ 
  6. private $term; 
  7.  
  8. /** 
  9. * @var string 
  10. */ 
  11. private $taxonomy; 
  12.  
  13. /** 
  14. * @var WPSEO_Taxonomy_Fields_Presenter 
  15. */ 
  16. private $taxonomy_tab_content; 
  17.  
  18. /** 
  19. * The constructor. 
  20. * @param string $taxonomy The taxonomy. 
  21. * @param stdClass $term The term. 
  22. */ 
  23. public function __construct( $taxonomy, $term ) { 
  24. $this->term = $term; 
  25. $this->taxonomy = $taxonomy; 
  26. $this->taxonomy_tab_content = new WPSEO_Taxonomy_Fields_Presenter( $this->term ); 
  27.  
  28. add_action( 'admin_footer', array( $this, 'template_generic_tab' ) ); 
  29. add_action( 'admin_footer', array( $this, 'template_keyword_tab' ) ); 
  30.  
  31. /** 
  32. * Shows the Yoast SEO metabox for the term. 
  33. */ 
  34. public function display() { 
  35.  
  36. $content_sections = $this->get_content_sections(); 
  37.  
  38. $product_title = 'Yoast SEO'; 
  39. if ( file_exists( WPSEO_PATH . 'premium/' ) ) { 
  40. $product_title .= ' Premium'; 
  41.  
  42. printf( '<div id="wpseo_meta" class="postbox yoast wpseo-taxonomy-metabox-postbox"><h2><span>%1$s</span></h2>', $product_title ); 
  43.  
  44. echo '<div class="inside">'; 
  45.  
  46. $helpcenter_tab = new WPSEO_Option_Tab( 'tax-metabox', 'Meta box',  
  47. array( 'video_url' => 'https://yoa.st/metabox-taxonomy-screencast' ) ); 
  48.  
  49. $helpcenter = new WPSEO_Help_Center( 'tax-metabox', $helpcenter_tab ); 
  50. $helpcenter->output_help_center(); 
  51.  
  52. echo '<div id="taxonomy_overall"></div>'; 
  53.  
  54. if ( ! defined( 'WPSEO_PREMIUM_FILE' ) ) { 
  55. echo $this->get_buy_premium_link(); 
  56.  
  57. echo '<div class="wpseo-metabox-sidebar"><ul>'; 
  58.  
  59. foreach ( $content_sections as $content_section ) { 
  60. if ( $content_section->name === 'premium' ) { 
  61. continue; 
  62.  
  63. $content_section->display_link(); 
  64.  
  65. echo '</ul></div>'; 
  66.  
  67. foreach ( $content_sections as $content_section ) { 
  68. $content_section->display_content(); 
  69. echo '</div></div>'; 
  70.  
  71. /** 
  72. * Returns the relevant metabox sections for the current view. 
  73. * @return WPSEO_Metabox_Section[] 
  74. */ 
  75. private function get_content_sections() { 
  76. $content_sections = array( 
  77. $this->get_content_meta_section(),  
  78. $this->get_social_meta_section(),  
  79. $this->get_settings_meta_section(),  
  80. ); 
  81.  
  82. if ( ! defined( 'WPSEO_PREMIUM_FILE' ) ) { 
  83. $content_sections[] = $this->get_buy_premium_section(); 
  84.  
  85. return $content_sections; 
  86.  
  87. /** 
  88. * Returns the metabox section for the content analysis. 
  89. * @return WPSEO_Metabox_Section 
  90. */ 
  91. private function get_content_meta_section() { 
  92. $taxonomy_content_fields = new WPSEO_Taxonomy_Content_Fields( $this->term ); 
  93. $content = $this->taxonomy_tab_content->html( $taxonomy_content_fields->get() ); 
  94.  
  95. $tab = new WPSEO_Metabox_Form_Tab( 
  96. 'content',  
  97. $content,  
  98. '',  
  99. array( 
  100. 'tab_class' => 'yoast-seo__remove-tab',  
  101. ); 
  102.  
  103. return new WPSEO_Metabox_Tab_Section( 
  104. 'content',  
  105. '<span class="screen-reader-text">' . __( 'Content optimization', 'wordpress-seo' ) . '</span><span class="yst-traffic-light-container">' . $this->traffic_light_svg() . '</span>',  
  106. array( $tab ),  
  107. array( 
  108. 'link_aria_label' => __( 'Content optimization', 'wordpress-seo' ),  
  109. 'link_class' => 'yoast-tooltip yoast-tooltip-e',  
  110. ); 
  111.  
  112. /** 
  113. * Returns the metabox section for the settings. 
  114. * @return WPSEO_Metabox_Section 
  115. */ 
  116. private function get_settings_meta_section() { 
  117. $taxonomy_settings_fields = new WPSEO_Taxonomy_Settings_Fields( $this->term ); 
  118. $content = $this->taxonomy_tab_content->html( $taxonomy_settings_fields->get() ); 
  119.  
  120. $tab = new WPSEO_Metabox_Form_Tab( 
  121. 'settings',  
  122. $content,  
  123. __( 'Settings', 'wordpress-seo' ),  
  124. array( 
  125. 'single' => true,  
  126. ); 
  127.  
  128. return new WPSEO_Metabox_Tab_Section( 
  129. 'settings',  
  130. '<span class="screen-reader-text">' . __( 'Settings', 'wordpress-seo' ) . '</span><span class="dashicons dashicons-admin-generic"></span>',  
  131. array( $tab ),  
  132. array( 
  133. 'link_aria_label' => __( 'Settings', 'wordpress-seo' ),  
  134. 'link_class' => 'yoast-tooltip yoast-tooltip-e',  
  135. ); 
  136.  
  137. /** 
  138. * Returns the metabox section for the social settings. 
  139. * @return WPSEO_Metabox_Section 
  140. */ 
  141. private function get_social_meta_section() { 
  142. $options = WPSEO_Options::get_option( 'wpseo_social' ); 
  143. $taxonomy_social_fields = new WPSEO_Taxonomy_Social_Fields( $this->term ); 
  144.  
  145. $tabs = array(); 
  146. $single = true; 
  147.  
  148. if ( $options['opengraph'] === true && $options['twitter'] === true ) { 
  149. $single = null; 
  150.  
  151. if ( $options['opengraph'] === true ) { 
  152. $facebook_meta_fields = $taxonomy_social_fields->get_by_network( 'opengraph' ); 
  153.  
  154. $tabs[] = new WPSEO_Metabox_Form_Tab( 
  155. 'facebook',  
  156. $this->taxonomy_tab_content->html( $facebook_meta_fields ),  
  157. '<span class="screen-reader-text">' . __( 'Facebook / Open Graph metadata', 'wordpress-seo' ) . '</span><span class="dashicons dashicons-facebook-alt"></span>',  
  158. array( 
  159. 'link_aria_label' => __( 'Facebook / Open Graph metadata', 'wordpress-seo' ),  
  160. 'link_class' => 'yoast-tooltip yoast-tooltip-se',  
  161. 'single' => $single,  
  162. ); 
  163.  
  164. if ( $options['twitter'] === true ) { 
  165. $twitter_meta_fields = $taxonomy_social_fields->get_by_network( 'twitter' ); 
  166.  
  167. $tabs[] = new WPSEO_Metabox_Form_Tab( 
  168. 'twitter',  
  169. $this->taxonomy_tab_content->html( $twitter_meta_fields ),  
  170. '<span class="screen-reader-text">' . __( 'Twitter metadata', 'wordpress-seo' ) . '</span><span class="dashicons dashicons-twitter"></span>',  
  171. array( 
  172. 'link_aria_label' => __( 'Twitter metadata', 'wordpress-seo' ),  
  173. 'link_class' => 'yoast-tooltip yoast-tooltip-se',  
  174. 'single' => $single,  
  175. ); 
  176.  
  177. return new WPSEO_Metabox_Tab_Section( 
  178. 'social',  
  179. '<span class="screen-reader-text">' . __( 'Social', 'wordpress-seo' ) . '</span><span class="dashicons dashicons-share"></span>',  
  180. $tabs,  
  181. array( 
  182. 'link_aria_label' => __( 'Social', 'wordpress-seo' ),  
  183. 'link_class' => 'yoast-tooltip yoast-tooltip-e',  
  184. ); 
  185.  
  186. /** 
  187. * Returns a link to activate the Buy Premium tab. 
  188. * @return string 
  189. */ 
  190. private function get_buy_premium_link() { 
  191. return sprintf( "<div class='%s'><a href='#wpseo-meta-section-premium' class='wpseo-meta-section-link'><span class='dashicons dashicons-star-filled wpseo-buy-premium'></span>%s</a></div>",  
  192. 'wpseo-metabox-buy-premium',  
  193. __( 'Go Premium', 'wordpress-seo' ) 
  194. ); 
  195.  
  196. /** 
  197. * Returns the metabox section for the Premium section.. 
  198. * @return WPSEO_Metabox_Section 
  199. */ 
  200. private function get_buy_premium_section() { 
  201. $content = sprintf( "<div class='wpseo-metabox-premium-description'> 
  202. %s 
  203. <ul class='wpseo-metabox-premium-advantages'> 
  204. <li> 
  205. <strong>%s</strong> - %s 
  206. </li> 
  207. <li> 
  208. <strong>%s</strong> - %s 
  209. </li> 
  210. <li> 
  211. <strong>%s</strong> - %s 
  212. </li> 
  213. <li> 
  214. <strong>%s</strong> - %s 
  215. </li> 
  216. </ul> 
  217.  
  218. <a target='_blank' id='wpseo-buy-premium-popup-button' class='button button-buy-premium wpseo-metabox-go-to' href='%s'> 
  219. %s 
  220. </a> 
  221.  
  222. <p><a target='_blank' class='wpseo-metabox-go-to' href='%s'>%s</a></p> 
  223. </div>",  
  224. /** translators: %1$s expands to Yoast SEO Premium. */ 
  225. sprintf( __( 'You\'re not getting the benefits of %1$s yet. If you had %1$s, you could use its awesome features:', 'wordpress-seo' ), 'Yoast SEO Premium' ),  
  226. __( 'Redirect manager', 'wordpress-seo' ),  
  227. __( 'Create and manage redirects within your WordPress install.', 'wordpress-seo' ),  
  228. __( 'Multiple focus keywords', 'wordpress-seo' ),  
  229. __( 'Optimize a single post for up to 5 keywords.', 'wordpress-seo' ),  
  230. __( 'Social Previews', 'wordpress-seo' ),  
  231. __( 'Check what your Facebook or Twitter post will look like.', 'wordpress-seo' ),  
  232. __( 'Premium support', 'wordpress-seo' ),  
  233. __( 'Gain access to our 24/7 support team.', 'wordpress-seo' ),  
  234. WPSEO_Shortlinker::get( 'https://yoa.st/pe-buy-premium' ),  
  235. /** translators: %s expands to Yoast SEO Premium. */ 
  236. sprintf( __( 'Get %s now!', 'wordpress-seo' ), 'Yoast SEO Premium' ),  
  237. WPSEO_Shortlinker::get( 'https://yoa.st/pe-premium-page' ),  
  238. __( 'More info', 'wordpress-seo' ) 
  239. ); 
  240.  
  241. $tab = new WPSEO_Metabox_Form_Tab( 
  242. 'premium',  
  243. $content,  
  244. 'Yoast SEO Premium',  
  245. array( 
  246. 'single' => true,  
  247. ); 
  248.  
  249. return new WPSEO_Metabox_Tab_Section( 
  250. 'premium',  
  251. '<span class="dashicons dashicons-star-filled wpseo-buy-premium"></span>',  
  252. array( $tab ),  
  253. array( 
  254. 'link_aria_label' => 'Yoast SEO Premium',  
  255. 'link_class' => 'yoast-tooltip yoast-tooltip-e',  
  256. ); 
  257.  
  258. /** 
  259. * Test whether we are on a public taxonomy - no metabox actions needed if we are not 
  260. * Unfortunately we have to hook most everything in before the point where all taxonomies are registered and 
  261. * we know which taxonomy is being requested, so we need to use this check in nearly every hooked in function. 
  262. * @since 1.5.0 
  263. */ 
  264. private function tax_is_public() { 
  265. // Don't make static as taxonomies may still be added during the run. 
  266. $taxonomy = get_taxonomy( $this->taxonomy ); 
  267.  
  268. return $taxonomy->public; 
  269.  
  270. /** 
  271. * Return the SVG for the traffic light in the metabox. 
  272. */ 
  273. public function traffic_light_svg() { 
  274. return <<<SVG 
  275. <svg class="yst-traffic-light init" version="1.1" xmlns:x="&ns_extend;" xmlns:i="&ns_ai;" xmlns:graph="&ns_graphs;" 
  276. xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:a="http://ns.adobe.com/AdobeSVGViewerExtensions/3.0/" 
  277. x="0px" y="0px" viewBox="0 0 30 47" enable-background="new 0 0 30 47" xml:space="preserve"> 
  278. <g id="BG_1_"> 
  279. </g> 
  280. <g id="traffic_light"> 
  281. <g> 
  282. <g> 
  283. <g> 
  284. <path fill="#5B2942" d="M22, 0H8C3.6, 0, 0, 3.6, 0, 7.9v31.1C0, 43.4, 3.6, 47, 8, 47h14c4.4, 0, 8-3.6, 8-7.9V7.9C30, 3.6, 26.4, 0, 22, 0z 
  285. M27.5, 38.8c0, 3.1-2.6, 5.7-5.8, 5.7H8.3c-3.2, 0-5.8-2.5-5.8-5.7V8.3c0-1.5, 0.6-2.9, 1.7-4c1.1-1, 2.5-1.6, 4.1-1.6h13.4 
  286. c1.5, 0, 3, 0.6, 4.1, 1.6c1.1, 1.1, 1.7, 2.5, 1.7, 4V38.8z"/> 
  287. </g> 
  288. <g class="traffic-light-color traffic-light-red"> 
  289. <ellipse fill="#C8C8C8" cx="15" cy="23.5" rx="5.7" ry="5.6"/> 
  290. <ellipse fill="#DC3232" cx="15" cy="10.9" rx="5.7" ry="5.6"/> 
  291. <ellipse fill="#C8C8C8" cx="15" cy="36.1" rx="5.7" ry="5.6"/> 
  292. </g> 
  293. <g class="traffic-light-color traffic-light-orange"> 
  294. <ellipse fill="#F49A00" cx="15" cy="23.5" rx="5.7" ry="5.6"/> 
  295. <ellipse fill="#C8C8C8" cx="15" cy="10.9" rx="5.7" ry="5.6"/> 
  296. <ellipse fill="#C8C8C8" cx="15" cy="36.1" rx="5.7" ry="5.6"/> 
  297. </g> 
  298. <g class="traffic-light-color traffic-light-green"> 
  299. <ellipse fill="#C8C8C8" cx="15" cy="23.5" rx="5.7" ry="5.6"/> 
  300. <ellipse fill="#C8C8C8" cx="15" cy="10.9" rx="5.7" ry="5.6"/> 
  301. <ellipse fill="#63B22B" cx="15" cy="36.1" rx="5.7" ry="5.6"/> 
  302. </g> 
  303. <g class="traffic-light-color traffic-light-empty"> 
  304. <ellipse fill="#C8C8C8" cx="15" cy="23.5" rx="5.7" ry="5.6"/> 
  305. <ellipse fill="#C8C8C8" cx="15" cy="10.9" rx="5.7" ry="5.6"/> 
  306. <ellipse fill="#C8C8C8" cx="15" cy="36.1" rx="5.7" ry="5.6"/> 
  307. </g> 
  308. <g class="traffic-light-color traffic-light-init"> 
  309. <ellipse fill="#5B2942" cx="15" cy="23.5" rx="5.7" ry="5.6"/> 
  310. <ellipse fill="#5B2942" cx="15" cy="10.9" rx="5.7" ry="5.6"/> 
  311. <ellipse fill="#5B2942" cx="15" cy="36.1" rx="5.7" ry="5.6"/> 
  312. </g> 
  313. </g> 
  314. </g> 
  315. </g> 
  316. </svg> 
  317. SVG; 
  318.  
  319. /** 
  320. * Generic tab. 
  321. */ 
  322. public function template_generic_tab() { 
  323. // This template belongs to the post scraper so don't echo it if it isn't enqueued. 
  324. if ( ! wp_script_is( WPSEO_Admin_Asset_Manager::PREFIX . 'term-scraper' ) ) { 
  325. return; 
  326.  
  327. echo '<script type="text/html" id="tmpl-generic_tab"> 
  328. <li class="<# if ( data.classes ) { #>{{data.classes}}<# } #><# if ( data.active ) { #> active<# } #>"> 
  329. <a class="wpseo_tablink" href="#wpseo_generic" data-score="{{data.score}}"> 
  330. <span class="wpseo-score-icon {{data.score}}"></span> 
  331. <span class="wpseo-tab-prefix">{{data.prefix}}</span> 
  332. <span class="wpseo-tab-label">{{data.label}}</span> 
  333. <span class="screen-reader-text wpseo-generic-tab-textual-score">{{data.scoreText}}</span> 
  334. </a> 
  335. <# if ( data.hideable ) { #> 
  336. <button type="button" class="remove-tab" aria-label="{{data.removeLabel}}"><span>x</span></button> 
  337. <# } #> 
  338. </li> 
  339. </script>'; 
  340.  
  341. /** 
  342. * Keyword tab for enabling analysis of multiple keywords. 
  343. */ 
  344. public function template_keyword_tab() { 
  345. // This template belongs to the term scraper so don't echo it if it isn't enqueued. 
  346. if ( ! wp_script_is( WPSEO_Admin_Asset_Manager::PREFIX . 'term-scraper' ) ) { 
  347. return; 
  348.  
  349. echo '<script type="text/html" id="tmpl-keyword_tab"> 
  350. <li class="<# if ( data.classes ) { #>{{data.classes}}<# } #><# if ( data.active ) { #> active<# } #>"> 
  351. <a class="wpseo_tablink" href="#wpseo_content" data-keyword="{{data.keyword}}" data-score="{{data.score}}"> 
  352. <span class="wpseo-score-icon {{data.score}}"></span> 
  353. <span class="wpseo-tab-prefix">{{data.prefix}}</span> 
  354. <em class="wpseo-keyword">{{data.label}}</em> 
  355. <span class="screen-reader-text wpseo-keyword-tab-textual-score">{{data.scoreText}}</span> 
  356. </a> 
  357. <# if ( data.hideable ) { #> 
  358. <button type="button" class="remove-keyword" aria-label="{{data.removeLabel}}"><span>x</span></button> 
  359. <# } #> 
  360. </li> 
  361. </script>';