PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 18.1
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v18.1
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 / class-option-tabs.php

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

122 lines 2.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\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 $tab = filter_input( INPUT_GET, 'tab' );
46 $this->active_tab = empty( $tab ) ? $active_tab : $tab;
47 }
48
49 /**
50 * Get the base.
51 *
52 * @return string
53 */
54 public function get_base() {
55 return $this->base;
56 }
57
58 /**
59 * Add a tab.
60 *
61 * @param WPSEO_Option_Tab $tab Tab to add.
62 *
63 * @return $this
64 */
65 public function add_tab( WPSEO_Option_Tab $tab ) {
66 $this->tabs[] = $tab;
67
68 return $this;
69 }
70
71 /**
72 * Get active tab.
73 *
74 * @return WPSEO_Option_Tab|null Get the active tab.
75 */
76 public function get_active_tab() {
77 if ( empty( $this->active_tab ) ) {
78 return null;
79 }
80
81 $active_tabs = array_filter( $this->tabs, [ $this, 'is_active_tab' ] );
82 if ( ! empty( $active_tabs ) ) {
83 $active_tabs = array_values( $active_tabs );
84 if ( count( $active_tabs ) === 1 ) {
85 return $active_tabs[0];
86 }
87 }
88
89 return null;
90 }
91
92 /**
93 * Is the tab the active tab.
94 *
95 * @param WPSEO_Option_Tab $tab Tab to check for active tab.
96 *
97 * @return bool
98 */
99 public function is_active_tab( WPSEO_Option_Tab $tab ) {
100 return ( $tab->get_name() === $this->active_tab );
101 }
102
103 /**
104 * Get all tabs.
105 *
106 * @return WPSEO_Option_Tab[]
107 */
108 public function get_tabs() {
109 return $this->tabs;
110 }
111
112 /**
113 * Display the tabs.
114 *
115 * @param Yoast_Form $yform Yoast Form needed in the views.
116 */
117 public function display( Yoast_Form $yform ) {
118 $formatter = new WPSEO_Option_Tabs_Formatter();
119 $formatter->run( $this, $yform );
120 }
121 }
122