WPSEO_Customizer

Class with functionality to support WP SEO settings in WordPress Customizer.

Defined (1)

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

/admin/class-customizer.php  
  1. class WPSEO_Customizer { 
  2.  
  3. /** 
  4. * @var WP_Customize_Manager 
  5. */ 
  6. protected $wp_customize; 
  7.  
  8. /** 
  9. * Construct Method. 
  10. */ 
  11. public function __construct() { 
  12. add_action( 'customize_register', array( $this, 'wpseo_customize_register' ) ); 
  13.  
  14. /** 
  15. * Function to support WordPress Customizer 
  16. * @param WP_Customize_Manager $wp_customize Manager class instance. 
  17. */ 
  18. public function wpseo_customize_register( $wp_customize ) { 
  19. if ( ! current_user_can( 'manage_options' ) ) { 
  20. return; 
  21.  
  22. $this->wp_customize = $wp_customize; 
  23.  
  24. $this->breadcrumbs_section(); 
  25. $this->breadcrumbs_blog_remove_setting(); 
  26. $this->breadcrumbs_separator_setting(); 
  27. $this->breadcrumbs_home_setting(); 
  28. $this->breadcrumbs_prefix_setting(); 
  29. $this->breadcrumbs_archiveprefix_setting(); 
  30. $this->breadcrumbs_searchprefix_setting(); 
  31. $this->breadcrumbs_404_setting(); 
  32.  
  33. /** 
  34. * Add the breadcrumbs section to the customizer 
  35. */ 
  36. private function breadcrumbs_section() { 
  37. $this->wp_customize->add_section( 
  38. 'wpseo_breadcrumbs_customizer_section', array( 
  39. /** translators: %s is the name of the plugin */ 
  40. 'title' => sprintf( __( '%s Breadcrumbs', 'wordpress-seo' ), 'Yoast SEO' ),  
  41. 'priority' => 999,  
  42. 'active_callback' => array( $this, 'breadcrumbs_active_callback' ),  
  43. ); 
  44.  
  45.  
  46. /** 
  47. * Returns whether or not the breadcrumbs are active 
  48. * @return bool 
  49. */ 
  50. public function breadcrumbs_active_callback() { 
  51. $options = WPSEO_Options::get_option( 'wpseo_internallinks' ); 
  52.  
  53. return true === ( current_theme_supports( 'yoast-seo-breadcrumbs' ) || $options['breadcrumbs-enable'] ); 
  54.  
  55. /** 
  56. * Adds the breadcrumbs remove blog checkbox 
  57. */ 
  58. private function breadcrumbs_blog_remove_setting() { 
  59. $this->wp_customize->add_setting( 
  60. 'wpseo_internallinks[breadcrumbs-blog-remove]', array( 
  61. 'default' => '',  
  62. 'type' => 'option',  
  63. 'transport' => 'refresh',  
  64. ); 
  65.  
  66. $this->wp_customize->add_control( 
  67. new WP_Customize_Control( 
  68. $this->wp_customize, 'wpseo-breadcrumbs-blog-remove', array( 
  69. 'label' => __( 'Remove blog page from breadcrumbs', 'wordpress-seo' ),  
  70. 'type' => 'checkbox',  
  71. 'section' => 'wpseo_breadcrumbs_customizer_section',  
  72. 'settings' => 'wpseo_internallinks[breadcrumbs-blog-remove]',  
  73. 'context' => '',  
  74. 'active_callback' => array( $this, 'breadcrumbs_blog_remove_active_cb' ),  
  75. ); 
  76.  
  77. /** 
  78. * Returns whether or not to show the breadcrumbs blog remove option 
  79. * @return bool 
  80. */ 
  81. public function breadcrumbs_blog_remove_active_cb() { 
  82. return 'page' === get_option( 'show_on_front' ); 
  83.  
  84. /** 
  85. * Adds the breadcrumbs separator text field 
  86. */ 
  87. private function breadcrumbs_separator_setting() { 
  88. $this->wp_customize->add_setting( 
  89. 'wpseo_internallinks[breadcrumbs-sep]', array( 
  90. 'default' => '',  
  91. 'type' => 'option',  
  92. 'transport' => 'refresh',  
  93. ); 
  94.  
  95. $this->wp_customize->add_control( 
  96. new WP_Customize_Control( 
  97. $this->wp_customize, 'wpseo-breadcrumbs-separator', array( 
  98. 'label' => __( 'Breadcrumbs separator:', 'wordpress-seo' ),  
  99. 'type' => 'text',  
  100. 'section' => 'wpseo_breadcrumbs_customizer_section',  
  101. 'settings' => 'wpseo_internallinks[breadcrumbs-sep]',  
  102. 'context' => '',  
  103. ); 
  104.  
  105. /** 
  106. * Adds the breadcrumbs home anchor text field 
  107. */ 
  108. private function breadcrumbs_home_setting() { 
  109. $this->wp_customize->add_setting( 
  110. 'wpseo_internallinks[breadcrumbs-home]', array( 
  111. 'default' => '',  
  112. 'type' => 'option',  
  113. 'transport' => 'refresh',  
  114. ); 
  115.  
  116. $this->wp_customize->add_control( 
  117. new WP_Customize_Control( 
  118. $this->wp_customize, 'wpseo-breadcrumbs-home', array( 
  119. 'label' => __( 'Anchor text for the homepage:', 'wordpress-seo' ),  
  120. 'type' => 'text',  
  121. 'section' => 'wpseo_breadcrumbs_customizer_section',  
  122. 'settings' => 'wpseo_internallinks[breadcrumbs-home]',  
  123. 'context' => '',  
  124. ); 
  125.  
  126. /** 
  127. * Adds the breadcrumbs prefix text field 
  128. */ 
  129. private function breadcrumbs_prefix_setting() { 
  130. $this->wp_customize->add_setting( 
  131. 'wpseo_internallinks[breadcrumbs-prefix]', array( 
  132. 'default' => '',  
  133. 'type' => 'option',  
  134. 'transport' => 'refresh',  
  135. ); 
  136.  
  137. $this->wp_customize->add_control( 
  138. new WP_Customize_Control( 
  139. $this->wp_customize, 'wpseo-breadcrumbs-prefix', array( 
  140. 'label' => __( 'Prefix for breadcrumbs:', 'wordpress-seo' ),  
  141. 'type' => 'text',  
  142. 'section' => 'wpseo_breadcrumbs_customizer_section',  
  143. 'settings' => 'wpseo_internallinks[breadcrumbs-prefix]',  
  144. 'context' => '',  
  145. ); 
  146.  
  147. /** 
  148. * Adds the breadcrumbs archive prefix text field 
  149. */ 
  150. private function breadcrumbs_archiveprefix_setting() { 
  151. $this->wp_customize->add_setting( 
  152. 'wpseo_internallinks[breadcrumbs-archiveprefix]', array( 
  153. 'default' => '',  
  154. 'type' => 'option',  
  155. 'transport' => 'refresh',  
  156. ); 
  157.  
  158. $this->wp_customize->add_control( 
  159. new WP_Customize_Control( 
  160. $this->wp_customize, 'wpseo-breadcrumbs-archiveprefix', array( 
  161. 'label' => __( 'Prefix for archive pages:', 'wordpress-seo' ),  
  162. 'type' => 'text',  
  163. 'section' => 'wpseo_breadcrumbs_customizer_section',  
  164. 'settings' => 'wpseo_internallinks[breadcrumbs-archiveprefix]',  
  165. 'context' => '',  
  166. ); 
  167.  
  168. /** 
  169. * Adds the breadcrumbs search prefix text field 
  170. */ 
  171. private function breadcrumbs_searchprefix_setting() { 
  172. $this->wp_customize->add_setting( 
  173. 'wpseo_internallinks[breadcrumbs-searchprefix]', array( 
  174. 'default' => '',  
  175. 'type' => 'option',  
  176. 'transport' => 'refresh',  
  177. ); 
  178.  
  179. $this->wp_customize->add_control( 
  180. new WP_Customize_Control( 
  181. $this->wp_customize, 'wpseo-breadcrumbs-searchprefix', array( 
  182. 'label' => __( 'Prefix for search result pages:', 'wordpress-seo' ),  
  183. 'type' => 'text',  
  184. 'section' => 'wpseo_breadcrumbs_customizer_section',  
  185. 'settings' => 'wpseo_internallinks[breadcrumbs-searchprefix]',  
  186. 'context' => '',  
  187. ); 
  188.  
  189. /** 
  190. * Adds the breadcrumb 404 prefix text field 
  191. */ 
  192. private function breadcrumbs_404_setting() { 
  193. $this->wp_customize->add_setting( 
  194. 'wpseo_internallinks[breadcrumbs-404crumb]', array( 
  195. 'default' => '',  
  196. 'type' => 'option',  
  197. 'transport' => 'refresh',  
  198. ); 
  199.  
  200. $this->wp_customize->add_control( 
  201. new WP_Customize_Control( 
  202. $this->wp_customize, 'wpseo-breadcrumbs-404crumb', array( 
  203. 'label' => __( 'Breadcrumb for 404 pages:', 'wordpress-seo' ),  
  204. 'type' => 'text',  
  205. 'section' => 'wpseo_breadcrumbs_customizer_section',  
  206. 'settings' => 'wpseo_internallinks[breadcrumbs-404crumb]',  
  207. 'context' => '',  
  208. );