class-template-variables-tab.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. /**
  3. * WPSEO plugin file.
  4. *
  5. * @package WPSEO\Admin
  6. */
  7. /**
  8. * Class that adds a template variables explanation tab to the Help Center.
  9. */
  10. class WPSEO_Help_Center_Template_Variables_Tab implements WPSEO_WordPress_Integration {
  11. /**
  12. * Priority to hook into the tab filter.
  13. *
  14. * @var int
  15. */
  16. private $priority;
  17. /**
  18. * Tab constructor.
  19. *
  20. * @param int $priority The priority to add the filter on, allows for ordering.
  21. */
  22. public function __construct( $priority = 10 ) {
  23. $this->priority = $priority;
  24. }
  25. /**
  26. * Registers all hooks to WordPress.
  27. *
  28. * @return void
  29. */
  30. public function register_hooks() {
  31. add_filter( 'wpseo_help_center_items', array( $this, 'add_meta_options_help_center_tabs' ), $this->priority );
  32. add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_assets' ) );
  33. }
  34. /**
  35. * Enqueues the styles needed in the Help Center tab.
  36. *
  37. * @return void
  38. */
  39. public function enqueue_assets() {
  40. $asset_manager = new WPSEO_Admin_Asset_Manager();
  41. $asset_manager->enqueue_style( 'admin-css' );
  42. }
  43. /**
  44. * Adds help tabs.
  45. *
  46. * @param array $tabs Current help center tabs.
  47. *
  48. * @return array List containing all the additional tabs.
  49. */
  50. public function add_meta_options_help_center_tabs( $tabs ) {
  51. $tabs[] = new WPSEO_Help_Center_Item(
  52. 'template-variables',
  53. __( 'Snippet variables', 'wordpress-seo' ),
  54. array( 'content' => $this->get_content() )
  55. );
  56. return $tabs;
  57. }
  58. /**
  59. * Adds template variables to the help center.
  60. *
  61. * @return string The content for the template variables tab.
  62. */
  63. private function get_content() {
  64. $explanation = sprintf(
  65. /* translators: %1$s expands to Yoast SEO. */
  66. __( 'The search appearance settings for %1$s are made up of variables that are replaced by specific values from the page when the page is displayed. The table below contains a list of the available variables.', 'wordpress-seo' ),
  67. 'Yoast SEO'
  68. );
  69. $output_explanation = sprintf(
  70. '<h2 class="wpseo-help-center-sub-title">%s</h2><p>%s</p><p>%s</p>',
  71. esc_html( __( 'Snippet variables', 'wordpress-seo' ) ),
  72. esc_html( $explanation ),
  73. esc_html( __( 'Note that not all variables can be used in every field.', 'wordpress-seo' ) )
  74. );
  75. $output_basic = sprintf(
  76. '<h2 class="wpseo-help-center-sub-title">%s</h2>%s',
  77. esc_html( __( 'Basic Variables', 'wordpress-seo' ) ),
  78. WPSEO_Replace_Vars::get_basic_help_texts()
  79. );
  80. $output_advanced = sprintf(
  81. '<h2 class="wpseo-help-center-sub-title">%s</h2>%s',
  82. esc_html( __( 'Advanced Variables', 'wordpress-seo' ) ),
  83. WPSEO_Replace_Vars::get_advanced_help_texts()
  84. );
  85. return $output_explanation . $output_basic . $output_advanced;
  86. }
  87. }