PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 27.9
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v27.9
28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 19.0 All 129 releases
wordpress-seo / admin / metabox / class-metabox-section-react.php

class-metabox-section-react.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 27.9, at admin/metabox/class-metabox-section-react.php

119 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * WPSEO plugin file.
4 *
5 * @package WPSEO\Admin
6 */
7
8 /**
9 * Generates and displays the React root element for a metabox section.
10 */
11 class WPSEO_Metabox_Section_React implements WPSEO_Metabox_Section {
12
13 /**
14 * Name of the section, used as an identifier in the HTML.
15 *
16 * @var string
17 */
18 public $name;
19
20 /**
21 * Content to use before the React root node.
22 *
23 * @var string
24 */
25 public $content;
26
27 /**
28 * Content to use to display the button to open this content block.
29 *
30 * @var string
31 */
32 private $link_content;
33
34 /**
35 * Class to add to the link.
36 *
37 * @var string
38 */
39 private $link_class;
40
41 /**
42 * Aria label to use for the link.
43 *
44 * @var string
45 */
46 private $link_aria_label;
47
48 /**
49 * Additional html content to be displayed within the section.
50 *
51 * @var string
52 */
53 private $html_after;
54
55 /**
56 * Constructor.
57 *
58 * @param string $name The name of the section, used as an identifier in the html.
59 * Can only contain URL safe characters.
60 * @param string $link_content The text content of the section link.
61 * @param string $content Optional. Content to use above the React root element.
62 * @param array $options Optional link attributes.
63 */
64 public function __construct( $name, $link_content, $content = '', array $options = [] ) {
65 $this->name = $name;
66 $this->content = $content;
67
68 $default_options = [
69 'link_class' => '',
70 'link_aria_label' => '',
71 'html_after' => '',
72 ];
73
74 $options = wp_parse_args( $options, $default_options );
75
76 $this->link_content = $link_content;
77 $this->link_class = $options['link_class'];
78 $this->link_aria_label = $options['link_aria_label'];
79 $this->html_after = $options['html_after'];
80 }
81
82 /**
83 * Outputs the section link.
84 *
85 * @return void
86 */
87 public function display_link() {
88 printf(
89 '<li role="presentation"><a role="tab" href="#wpseo-meta-section-%1$s" id="wpseo-meta-tab-%1$s" aria-controls="wpseo-meta-section-%1$s" class="wpseo-meta-section-link %2$s"%3$s>%4$s</a></li>',
90 esc_attr( $this->name ),
91 esc_attr( $this->link_class ),
92 ( $this->link_aria_label !== '' ) ? ' aria-label="' . esc_attr( $this->link_aria_label ) . '"' : '',
93 wp_kses_post( $this->link_content ),
94 );
95 }
96
97 /**
98 * Outputs the section content.
99 *
100 * @return void
101 */
102 public function display_content() {
103 add_filter( 'wp_kses_allowed_html', [ 'WPSEO_Utils', 'extend_kses_post_with_forms' ] );
104 add_filter( 'wp_kses_allowed_html', [ 'WPSEO_Utils', 'extend_kses_post_with_a11y' ] );
105
106 printf(
107 '<div role="tabpanel" id="wpseo-meta-section-%1$s" aria-labelledby="wpseo-meta-tab-%1$s" tabindex="0" class="wpseo-meta-section">',
108 esc_attr( $this->name ),
109 );
110 echo wp_kses_post( $this->content );
111 echo '<div id="wpseo-metabox-root" class="wpseo-metabox-root"></div>';
112 echo wp_kses_post( $this->html_after );
113 echo '</div>';
114
115 remove_filter( 'wp_kses_allowed_html', [ 'WPSEO_Utils', 'extend_kses_post_with_forms' ] );
116 remove_filter( 'wp_kses_allowed_html', [ 'WPSEO_Utils', 'extend_kses_post_with_a11y' ] );
117 }
118 }
119