PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / trunk
Yoast SEO – Advanced SEO with real-time guidance and built-in AI vtrunk
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-form-tab.php

class-metabox-form-tab.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI trunk, at admin/metabox/class-metabox-form-tab.php

136 lines 2.8 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 the HTML for a metabox tab.
10 */
11 class WPSEO_Metabox_Form_Tab implements WPSEO_Metabox_Tab {
12
13 /**
14 * The tab identifier.
15 *
16 * @var string
17 */
18 private $name;
19
20 /**
21 * The tab content.
22 *
23 * @var string
24 */
25 private $content;
26
27 /**
28 * The tab link content.
29 *
30 * @var string
31 */
32 private $link_content;
33
34 /**
35 * Additional tab content class.
36 *
37 * @var string
38 */
39 private $tab_class;
40
41 /**
42 * Additional tab link class.
43 *
44 * @var string
45 */
46 private $link_class;
47
48 /**
49 * Title attribute on the link span.
50 *
51 * @var string
52 */
53 private $link_title;
54
55 /**
56 * Arial label attribute on the link span.
57 *
58 * @var string
59 */
60 private $link_aria_label;
61
62 /**
63 * Does it contain a single tab.
64 *
65 * @var bool
66 */
67 private $single;
68
69 /**
70 * Constructor.
71 *
72 * @param string $name The name of the tab, used as an identifier in the html.
73 * @param string $content The tab content.
74 * @param string $link_content The text content of the tab link.
75 * @param array $options Optional link attributes.
76 */
77 public function __construct( $name, $content, $link_content, array $options = [] ) {
78 $default_options = [
79 'tab_class' => '',
80 'link_class' => '',
81 'link_title' => '',
82 'link_aria_label' => '',
83 'single' => false,
84 ];
85
86 $options = array_merge( $default_options, $options );
87
88 $this->name = $name;
89 $this->content = $content;
90 $this->link_content = $link_content;
91 $this->tab_class = $options['tab_class'];
92 $this->link_class = $options['link_class'];
93 $this->link_title = $options['link_title'];
94 $this->link_aria_label = $options['link_aria_label'];
95 $this->single = $options['single'];
96 }
97
98 /**
99 * Returns the html for the tab link.
100 *
101 * @return string
102 */
103 public function link() {
104
105 $html = '<li class="%1$s%2$s"><a class="wpseo_tablink%3$s" href="#wpseo_%1$s"%4$s%5$s>%6$s</a></li>';
106
107 if ( $this->single ) {
108 $html = '<li class="%1$s%2$s"><span class="wpseo_tablink%3$s"%4$s%5$s>%6$s</span></li>';
109 }
110
111 return sprintf(
112 $html,
113 esc_attr( $this->name ),
114 ( $this->tab_class !== '' ) ? ' ' . esc_attr( $this->tab_class ) : '',
115 ( $this->link_class !== '' ) ? ' ' . esc_attr( $this->link_class ) : '',
116 ( $this->link_title !== '' ) ? ' title="' . esc_attr( $this->link_title ) . '"' : '',
117 ( $this->link_aria_label !== '' ) ? ' aria-label="' . esc_attr( $this->link_aria_label ) . '"' : '',
118 $this->link_content,
119 );
120 }
121
122 /**
123 * Returns the html for the tab content.
124 *
125 * @return string
126 */
127 public function content() {
128 return sprintf(
129 '<div id="%1$s" class="wpseotab %2$s">%3$s</div>',
130 esc_attr( 'wpseo_' . $this->name ),
131 esc_attr( $this->name ),
132 $this->content,
133 );
134 }
135 }
136