PageRenderTime 24ms CodeModel.GetById 20ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/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/**
 9 * Generates the HTML for an inline Help Button and Panel.
10 */
11class WPSEO_Admin_Help_Panel {
12
13	/**
14	 * @var string
15	 */
16	private $id;
17
18	/**
19	 * @var string
20	 */
21	private $help_button_text;
22
23	/**
24	 * @var string
25	 */
26	private $help_content;
27
28	/**
29	 * @var string
30	 */
31	private $wrapper;
32
33	/**
34	 * Constructor.
35	 *
36	 * @param string $id                Unique identifier of the element the inline help refers to, used as an identifier in the html.
37	 * @param string $help_button_text  The Help Button text. Needs a properly escaped string.
38	 * @param string $help_content      The Help Panel content. Needs a properly escaped string (might contain HTML).
39	 * @param string $wrapper           Optional Whether to print out a container div element for the Help Panel, used for styling.
40	 *                                  Pass a `has-wrapper` value to print out the container. Default: no container.
41	 */
42	public function __construct( $id, $help_button_text, $help_content, $wrapper = '' ) {
43		$this->id               = $id;
44		$this->help_button_text = $help_button_text;
45		$this->help_content     = $help_content;
46		$this->wrapper          = $wrapper;
47	}
48
49	/**
50	 * Returns the html for the Help Button.
51	 *
52	 * @return string
53	 */
54	public function get_button_html() {
55
56		if ( ! $this->id || ! $this->help_button_text || ! $this->help_content ) {
57			return '';
58		}
59
60		return sprintf(
61			' <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>',
62			esc_attr( $this->id ),
63			$this->help_button_text
64		);
65	}
66
67	/**
68	 * Returns the html for the Help Panel.
69	 *
70	 * @return string
71	 */
72	public function get_panel_html() {
73
74		if ( ! $this->id || ! $this->help_button_text || ! $this->help_content ) {
75			return '';
76		}
77
78		$wrapper_start = '';
79		$wrapper_end   = '';
80
81		if ( 'has-wrapper' === $this->wrapper ) {
82			$wrapper_start = '<div class="yoast-seo-help-container">';
83			$wrapper_end   = '</div>';
84		}
85
86		return sprintf(
87			'%1$s<p id="%2$s-help" class="yoast-help-panel">%3$s</p>%4$s',
88			$wrapper_start,
89			esc_attr( $this->id ),
90			$this->help_content,
91			$wrapper_end
92		);
93	}
94}