WPSEO_Help_Center

Class WPSEO_Help_Center.

Defined (1)

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

/admin/class-help-center.php  
  1. class WPSEO_Help_Center { 
  2. /** 
  3. * @var array Help_Center_Item list of helpcenter tabs to be shown in the helpcenter 
  4. */ 
  5. private $help_center_items = array(); 
  6.  
  7. /** 
  8. * @var String $group_name 
  9. */ 
  10. private $group_name; 
  11.  
  12. /** 
  13. * @var WPSEO_Option_Tab $tab 
  14. */ 
  15. private $tab; 
  16.  
  17. /** 
  18. * WPSEO_Help_Center constructor. 
  19. * @param String $group_name The name of the group of the tab the helpcenter is on. 
  20. * @param WPSEO_Option_Tab $tab The name of the tab the helpcenter is on. 
  21. */ 
  22. public function __construct( $group_name, $tab ) { 
  23. $this->group_name = $group_name; 
  24. $this->tab = $tab; 
  25.  
  26. $this->add_video_tutorial_item(); 
  27. $this->add_kb_search_item(); 
  28. $this->add_contact_support_item(); 
  29.  
  30. /** 
  31. * Add the knowledge base search help center item to the help center. 
  32. */ 
  33. private function add_kb_search_item() { 
  34. $kb_help_center_item = new WPSEO_Help_Center_Item( 
  35. 'knowledge-base',  
  36. __( 'Knowledge base', 'wordpress-seo' ),  
  37. array( 
  38. 'content' => '<div class="wpseo-kb-search"></div>',  
  39. 'view_arguments' => array( 'identifier' => $this->tab->get_name() ),  
  40. ),  
  41. 'dashicons-search' 
  42. ); 
  43. array_push( $this->help_center_items, $kb_help_center_item ); 
  44.  
  45. /** 
  46. * Add the contact support help center item to the help center. 
  47. */ 
  48. private function add_contact_support_item() { 
  49. /** translators: %s: expands to 'Yoast SEO Premium'. */ 
  50. $popup_title = sprintf( __( 'Email support is a %s feature', 'wordpress-seo' ), 'Yoast SEO Premium' ); 
  51.  
  52. $popup_content = '<p>' . __( 'Go Premium and our experts will be there for you to answer any questions you might have about the set-up and use of the plug-in! 
  53.  
  54. ', 'wordpress-seo' ) . '</p>'; 
  55. /** translators: %1$s: expands to 'Yoast SEO Premium'. */ 
  56. $popup_content .= '<p>' . sprintf( __( 'Other benefits of %1$s for you:', 'wordpress-seo' ), 'Yoast SEO Premium' ) . '</p>'; 
  57. $popup_content .= '<ul>'; 
  58. $popup_content .= '<li>' . __( 'No more dead links: easy redirect manager', 'wordpress-seo' ) . '</li>'; 
  59. $popup_content .= '<li>' . __( 'Superfast internal link suggestions', 'wordpress-seo' ) . '</li>'; 
  60. $popup_content .= '<li>' . __( 'Social media preview: Facebook & Twitter', 'wordpress-seo' ) . '</li>'; 
  61. $popup_content .= '<li>' . __( 'No ads!', 'wordpress-seo' ) . '</li>'; 
  62. $popup_content .= '</ul>'; 
  63.  
  64. $premium_popup = new WPSEO_Premium_Popup( 'contact-support', 'h2', $popup_title, $popup_content ); 
  65. $contact_support_help_center_item = new WPSEO_Help_Center_Item( 
  66. 'contact-support',  
  67. __( 'Email support', 'wordpress-seo' ),  
  68. array( 'content' => $premium_popup->get_premium_message( false ) ),  
  69. 'dashicons-email-alt' 
  70. ); 
  71.  
  72. array_push( $this->help_center_items, $contact_support_help_center_item ); 
  73.  
  74. /** 
  75. * Add the video tutorial help center item to the help center. 
  76. */ 
  77. private function add_video_tutorial_item() { 
  78. array_push( $this->help_center_items, $this->get_video_help_center_item() ); 
  79.  
  80. /** 
  81. * @return mixed (WPSEO_Help_Center_Item | null) Returns a help center item containing a video. 
  82. */ 
  83. private function get_video_help_center_item() { 
  84. $url = $this->tab->get_video_url(); 
  85. if ( empty( $url ) ) { 
  86. return null; 
  87.  
  88. return new WPSEO_Help_Center_Item( 
  89. 'video',  
  90. __( 'Video tutorial', 'wordpress-seo' ),  
  91. array( 
  92. 'view' => 'partial-help-center-video',  
  93. 'view_arguments' => array( 
  94. 'tab_video_url' => $url,  
  95. ),  
  96. ),  
  97. 'dashicons-video-alt3' 
  98. ); 
  99.  
  100. /** 
  101. * Outputs the help center. 
  102. */ 
  103. public function output_help_center() { 
  104. $help_center_items = apply_filters( 'wpseo_help_center_items', $this->help_center_items ); 
  105. $help_center_items = array_filter( $help_center_items, array( $this, 'is_a_help_center_item' ) ); 
  106. if ( empty( $help_center_items ) ) { 
  107. return; 
  108.  
  109. $id = sprintf( 'tab-help-center-%s-%s', $this->group_name, $this->tab->get_name() ); 
  110. ?> 
  111. <div class="wpseo-tab-video-container"> 
  112. <button type="button" class="wpseo-tab-video-container__handle" aria-controls="<?php echo $id ?>" 
  113. aria-expanded="false"> 
  114. <span 
  115. class="dashicons-before dashicons-editor-help"><?php _e( 'Help center', 'wordpress-seo' ) ?></span> 
  116. <span class="dashicons dashicons-arrow-down toggle__arrow"></span> 
  117. </button> 
  118. <div id="<?php echo $id ?>" class="wpseo-tab-video-slideout hidden"> 
  119. <div class="yoast-help-center-tabs"> 
  120. <ul> 
  121. <?php 
  122. $class = 'active wpseo-help-center-item'; 
  123.  
  124. foreach ( $help_center_items as $help_center_item ) { 
  125. $id = $help_center_item->get_identifier(); 
  126. $dashicon = $help_center_item->get_dashicon(); 
  127. if ( ! empty( $dashicon ) ) { 
  128. $dashicon = 'dashicons-before ' . $dashicon; 
  129. $link_id = "tab-link-{$this->group_name}_{$this->tab->get_name()}__{$id}"; 
  130. $panel_id = "tab-panel-{$this->group_name}_{$this->tab->get_name()}__{$id}"; 
  131. ?> 
  132.  
  133. <li id="<?php echo esc_attr( $link_id ); ?>" class="<?php echo $class; ?>"> 
  134. <a href="<?php echo esc_url( "#$panel_id" ); ?>" 
  135. class="<?php echo $id . ' ' . $dashicon?>" 
  136. aria-controls="<?php echo esc_attr( $panel_id ); ?>"><?php echo esc_html( $help_center_item->get_label() ); ?></a> 
  137. </li> 
  138. <?php 
  139. $class = 'wpseo-help-center-item'; 
  140. ?> 
  141. </ul> 
  142. </div> 
  143. <div class="yoast-help-center-tabs-wrap"> 
  144. <?php 
  145. $classes = 'yoast-help-tab-content active'; 
  146. foreach ( $help_center_items as $help_center_item ) { 
  147. $id = $help_center_item->get_identifier(); 
  148.  
  149. $video_tab_class = ( 'video' === $id ) ? ' yoast-help-tab-content-video' : ''; 
  150.  
  151. $panel_id = "tab-panel-{$this->group_name}_{$this->tab->get_name()}__{$id}"; 
  152. ?> 
  153. <div id="<?php echo esc_attr( $panel_id ); ?>" class="<?php echo $classes . $video_tab_class; ?>"> 
  154. <?php echo $help_center_item->get_content(); ?> 
  155. </div> 
  156. <?php 
  157. $classes = 'yoast-help-tab-content'; 
  158. ?> 
  159. </div> 
  160. </div> 
  161. </div> 
  162. <?php 
  163.  
  164. /** 
  165. * Checks if the param is a help center item. 
  166. * @param object $item The object compare. 
  167. * @return bool 
  168. */ 
  169. private function is_a_help_center_item( $item ) { 
  170. return ( $item instanceof WPSEO_Help_Center_Item ); 
  171.  
  172. /** 
  173. * Pass text variables to js for the help center JS module. 
  174. * %s is replaced with <code>%s</code> and replaced again in the javascript with the actual variable. 
  175. * @return array Translated text strings for the help center. 
  176. */ 
  177. public static function get_translated_texts() { 
  178. return array( 
  179. /** translators: %s: '%%term_title%%' variable used in titles and meta's template that's not compatible with the given template */ 
  180. 'variable_warning' => sprintf( __( 'Warning: the variable %s cannot be used in this template. See the help center for more info.', 'wordpress-seo' ), '<code>%s</code>' ),  
  181. 'contentLocale' => get_locale(),  
  182. 'userLocale' => WPSEO_Utils::get_user_locale(),  
  183. /** translators: %d: number of knowledge base search results found. */ 
  184. 'kb_found_results' => __( 'Number of search results: %d', 'wordpress-seo' ),  
  185. 'kb_no_results' => __( 'No results found.', 'wordpress-seo' ),  
  186. 'kb_heading' => __( 'Search the Yoast knowledge base', 'wordpress-seo' ),  
  187. 'kb_search_button_text' => __( 'Search', 'wordpress-seo' ),  
  188. 'kb_search_results_heading' => __( 'Search results', 'wordpress-seo' ),  
  189. 'kb_error_message' => __( 'Something went wrong. Please try again later.', 'wordpress-seo' ),  
  190. 'kb_loading_placeholder' => __( 'Loading...', 'wordpress-seo' ),  
  191. 'kb_search' => __( 'search', 'wordpress-seo' ),  
  192. 'kb_back' => __( 'Back', 'wordpress-seo' ),  
  193. 'kb_back_label' => __( 'Back to search results' , 'wordpress-seo' ),  
  194. 'kb_open' => __( 'Open', 'wordpress-seo' ),  
  195. 'kb_open_label' => __( 'Open the knowledge base article in a new window or read it in the iframe below' , 'wordpress-seo' ),  
  196. 'kb_iframe_title' => __( 'Knowledge base article', 'wordpress-seo' ),  
  197. );