/wp-content/plugins/wordpress-seo/admin/class-admin-help-panel.php

https://bitbucket.org/carloskikea/helpet · PHP · 94 lines · 41 code · 14 blank · 39 comment · 7 complexity · fab6f38ef1e013356ef82cd97c365ec0 MD5 · raw file

  1. <?php
  2. /**
  3. * WPSEO plugin file.
  4. *
  5. * @package WPSEO\Admin
  6. */
  7. /**
  8. * Generates the HTML for an inline Help Button and Panel.
  9. */
  10. class WPSEO_Admin_Help_Panel {
  11. /**
  12. * @var string
  13. */
  14. private $id;
  15. /**
  16. * @var string
  17. */
  18. private $help_button_text;
  19. /**
  20. * @var string
  21. */
  22. private $help_content;
  23. /**
  24. * @var string
  25. */
  26. private $wrapper;
  27. /**
  28. * Constructor.
  29. *
  30. * @param string $id Unique identifier of the element the inline help refers to, used as an identifier in the html.
  31. * @param string $help_button_text The Help Button text. Needs a properly escaped string.
  32. * @param string $help_content The Help Panel content. Needs a properly escaped string (might contain HTML).
  33. * @param string $wrapper Optional Whether to print out a container div element for the Help Panel, used for styling.
  34. * Pass a `has-wrapper` value to print out the container. Default: no container.
  35. */
  36. public function __construct( $id, $help_button_text, $help_content, $wrapper = '' ) {
  37. $this->id = $id;
  38. $this->help_button_text = $help_button_text;
  39. $this->help_content = $help_content;
  40. $this->wrapper = $wrapper;
  41. }
  42. /**
  43. * Returns the html for the Help Button.
  44. *
  45. * @return string
  46. */
  47. public function get_button_html() {
  48. if ( ! $this->id || ! $this->help_button_text || ! $this->help_content ) {
  49. return '';
  50. }
  51. return sprintf(
  52. ' <button type="button" class="yoast_help yoast-help-button dashicons" id="%1$s-help-toggle" aria-expanded="false" aria-controls="%1$s-help"><span class="yoast-help-icon" aria-hidden="true"></span><span class="screen-reader-text">%2$s</span></button>',
  53. esc_attr( $this->id ),
  54. $this->help_button_text
  55. );
  56. }
  57. /**
  58. * Returns the html for the Help Panel.
  59. *
  60. * @return string
  61. */
  62. public function get_panel_html() {
  63. if ( ! $this->id || ! $this->help_button_text || ! $this->help_content ) {
  64. return '';
  65. }
  66. $wrapper_start = '';
  67. $wrapper_end = '';
  68. if ( 'has-wrapper' === $this->wrapper ) {
  69. $wrapper_start = '<div class="yoast-seo-help-container">';
  70. $wrapper_end = '</div>';
  71. }
  72. return sprintf(
  73. '%1$s<p id="%2$s-help" class="yoast-help-panel">%3$s</p>%4$s',
  74. $wrapper_start,
  75. esc_attr( $this->id ),
  76. $this->help_content,
  77. $wrapper_end
  78. );
  79. }
  80. }