PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 28.3
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v28.3
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 19.1 All 128 releases
wordpress-seo / admin / class-option-tabs.php

class-option-tabs.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 28.3, at admin/class-option-tabs.php

125 lines 2.3 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\Options\Tabs
6 */
7
8 /**
9 * Class WPSEO_Option_Tabs.
10 */
11 class WPSEO_Option_Tabs {
12
13 /**
14 * Tabs base.
15 *
16 * @var string
17 */
18 private $base;
19
20 /**
21 * The tabs in this group.
22 *
23 * @var array
24 */
25 private $tabs = [];
26
27 /**
28 * Name of the active tab.
29 *
30 * @var string
31 */
32 private $active_tab = '';
33
34 /**
35 * WPSEO_Option_Tabs constructor.
36 *
37 * @codeCoverageIgnore
38 *
39 * @param string $base Base of the tabs.
40 * @param string $active_tab Currently active tab.
41 */
42 public function __construct( $base, $active_tab = '' ) {
43 $this->base = sanitize_title( $base );
44
45 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information.
46 $tab = isset( $_GET['tab'] ) && is_string( $_GET['tab'] ) ? sanitize_text_field( wp_unslash( $_GET['tab'] ) ) : '';
47 $this->active_tab = empty( $tab ) ? $active_tab : $tab;
48 }
49
50 /**
51 * Get the base.
52 *
53 * @return string
54 */
55 public function get_base() {
56 return $this->base;
57 }
58
59 /**
60 * Add a tab.
61 *
62 * @param WPSEO_Option_Tab $tab Tab to add.
63 *
64 * @return $this
65 */
66 public function add_tab( WPSEO_Option_Tab $tab ) {
67 $this->tabs[] = $tab;
68
69 return $this;
70 }
71
72 /**
73 * Get active tab.
74 *
75 * @return WPSEO_Option_Tab|null Get the active tab.
76 */
77 public function get_active_tab() {
78 if ( empty( $this->active_tab ) ) {
79 return null;
80 }
81
82 $active_tabs = array_filter( $this->tabs, [ $this, 'is_active_tab' ] );
83 if ( ! empty( $active_tabs ) ) {
84 $active_tabs = array_values( $active_tabs );
85 if ( count( $active_tabs ) === 1 ) {
86 return $active_tabs[0];
87 }
88 }
89
90 return null;
91 }
92
93 /**
94 * Is the tab the active tab.
95 *
96 * @param WPSEO_Option_Tab $tab Tab to check for active tab.
97 *
98 * @return bool
99 */
100 public function is_active_tab( WPSEO_Option_Tab $tab ) {
101 return ( $tab->get_name() === $this->active_tab );
102 }
103
104 /**
105 * Get all tabs.
106 *
107 * @return WPSEO_Option_Tab[]
108 */
109 public function get_tabs() {
110 return $this->tabs;
111 }
112
113 /**
114 * Display the tabs.
115 *
116 * @param Yoast_Form $yform Yoast Form needed in the views.
117 *
118 * @return void
119 */
120 public function display( Yoast_Form $yform ) {
121 $formatter = new WPSEO_Option_Tabs_Formatter();
122 $formatter->run( $this, $yform );
123 }
124 }
125