• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Yoast / wordpress-seo / 8ef7dea17d00cfba5dc51c28979f6a5be7987344

07 May 2024 08:23AM UTC coverage: 51.403% (-1.0%) from 52.395%
8ef7dea17d00cfba5dc51c28979f6a5be7987344

push

github

web-flow
Merge pull request #21327 from Yoast/93-remove-snippetPreview

93 remove snippet preview

7404 of 13445 branches covered (55.07%)

Branch coverage included in aggregate %.

0 of 2 new or added lines in 1 file covered. (0.0%)

1438 existing lines in 42 files now uncovered.

28194 of 55808 relevant lines covered (50.52%)

40250.65 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/admin/class-customizer.php
1
<?php
2
/**
3
 * WPSEO plugin file.
4
 *
5
 * @package WPSEO\Admin\Customizer
6
 */
7

8
/**
9
 * Class with functionality to support WP SEO settings in WordPress Customizer.
10
 */
11
class WPSEO_Customizer {
12

13
        /**
14
         * Holds the customize manager.
15
         *
16
         * @var WP_Customize_Manager
17
         */
18
        protected $wp_customize;
19

20
        /**
21
         * Template for the setting IDs used for the customizer.
22
         *
23
         * @var string
24
         */
25
        private $setting_template = 'wpseo_titles[%s]';
26

27
        /**
28
         * Default arguments for the breadcrumbs customizer settings object.
29
         *
30
         * @var array
31
         */
32
        private $default_setting_args = [
33
                'default'   => '',
34
                'type'      => 'option',
35
                'transport' => 'refresh',
36
        ];
37

38
        /**
39
         * Default arguments for the breadcrumbs customizer control object.
40
         *
41
         * @var array
42
         */
43
        private $default_control_args = [
44
                'label'    => '',
45
                'type'     => 'text',
46
                'section'  => 'wpseo_breadcrumbs_customizer_section',
47
                'settings' => '',
48
                'context'  => '',
49
        ];
50

51
        /**
52
         * Construct Method.
53
         */
54
        public function __construct() {
×
55
                add_action( 'customize_register', [ $this, 'wpseo_customize_register' ] );
×
56
        }
57

58
        /**
59
         * Function to support WordPress Customizer.
60
         *
61
         * @param WP_Customize_Manager $wp_customize Manager class instance.
62
         *
63
         * @return void
64
         */
65
        public function wpseo_customize_register( $wp_customize ) {
×
66
                if ( ! WPSEO_Capability_Utils::current_user_can( 'wpseo_manage_options' ) ) {
×
67
                        return;
×
68
                }
69

70
                $this->wp_customize = $wp_customize;
×
71

72
                $this->breadcrumbs_section();
×
73
                $this->breadcrumbs_blog_show_setting();
×
74
                $this->breadcrumbs_separator_setting();
×
75
                $this->breadcrumbs_home_setting();
×
76
                $this->breadcrumbs_prefix_setting();
×
77
                $this->breadcrumbs_archiveprefix_setting();
×
78
                $this->breadcrumbs_searchprefix_setting();
×
79
                $this->breadcrumbs_404_setting();
×
80
        }
81

82
        /**
83
         * Add the breadcrumbs section to the customizer.
84
         *
85
         * @return void
86
         */
87
        private function breadcrumbs_section() {
×
UNCOV
88
                $section_args = [
×
89
                        /* translators: %s is the name of the plugin */
90
                        'title'           => sprintf( __( '%s Breadcrumbs', 'wordpress-seo' ), 'Yoast SEO' ),
×
91
                        'priority'        => 999,
×
92
                        'active_callback' => [ $this, 'breadcrumbs_active_callback' ],
×
UNCOV
93
                ];
×
94

95
                $this->wp_customize->add_section( 'wpseo_breadcrumbs_customizer_section', $section_args );
×
96
        }
97

98
        /**
99
         * Returns whether or not the breadcrumbs are active.
100
         *
101
         * @return bool
102
         */
103
        public function breadcrumbs_active_callback() {
×
104
                return current_theme_supports( 'yoast-seo-breadcrumbs' ) || WPSEO_Options::get( 'breadcrumbs-enable' );
×
105
        }
106

107
        /**
108
         * Adds the breadcrumbs show blog checkbox.
109
         *
110
         * @return void
111
         */
112
        private function breadcrumbs_blog_show_setting() {
×
113
                $index        = 'breadcrumbs-display-blog-page';
×
UNCOV
114
                $control_args = [
×
115
                        'label'           => __( 'Show blog page in breadcrumbs', 'wordpress-seo' ),
×
116
                        'type'            => 'checkbox',
×
117
                        'active_callback' => [ $this, 'breadcrumbs_blog_show_active_cb' ],
×
UNCOV
118
                ];
×
119

120
                $this->add_setting_and_control( $index, $control_args );
×
121
        }
122

123
        /**
124
         * Returns whether or not to show the breadcrumbs blog show option.
125
         *
126
         * @return bool
127
         */
128
        public function breadcrumbs_blog_show_active_cb() {
×
129
                return get_option( 'show_on_front' ) === 'page';
×
130
        }
131

132
        /**
133
         * Adds the breadcrumbs separator text field.
134
         *
135
         * @return void
136
         */
137
        private function breadcrumbs_separator_setting() {
×
138
                $index        = 'breadcrumbs-sep';
×
UNCOV
139
                $control_args = [
×
140
                        'label' => __( 'Breadcrumbs separator:', 'wordpress-seo' ),
×
UNCOV
141
                ];
×
142
                $id           = 'wpseo-breadcrumbs-separator';
×
143

144
                $this->add_setting_and_control( $index, $control_args, $id );
×
145
        }
146

147
        /**
148
         * Adds the breadcrumbs home anchor text field.
149
         *
150
         * @return void
151
         */
152
        private function breadcrumbs_home_setting() {
×
153
                $index        = 'breadcrumbs-home';
×
UNCOV
154
                $control_args = [
×
155
                        'label' => __( 'Anchor text for the homepage:', 'wordpress-seo' ),
×
UNCOV
156
                ];
×
157

158
                $this->add_setting_and_control( $index, $control_args );
×
159
        }
160

161
        /**
162
         * Adds the breadcrumbs prefix text field.
163
         *
164
         * @return void
165
         */
166
        private function breadcrumbs_prefix_setting() {
×
167
                $index        = 'breadcrumbs-prefix';
×
UNCOV
168
                $control_args = [
×
169
                        'label' => __( 'Prefix for breadcrumbs:', 'wordpress-seo' ),
×
UNCOV
170
                ];
×
171

172
                $this->add_setting_and_control( $index, $control_args );
×
173
        }
174

175
        /**
176
         * Adds the breadcrumbs archive prefix text field.
177
         *
178
         * @return void
179
         */
180
        private function breadcrumbs_archiveprefix_setting() {
×
181
                $index        = 'breadcrumbs-archiveprefix';
×
UNCOV
182
                $control_args = [
×
183
                        'label' => __( 'Prefix for archive pages:', 'wordpress-seo' ),
×
UNCOV
184
                ];
×
185

186
                $this->add_setting_and_control( $index, $control_args );
×
187
        }
188

189
        /**
190
         * Adds the breadcrumbs search prefix text field.
191
         *
192
         * @return void
193
         */
194
        private function breadcrumbs_searchprefix_setting() {
×
195
                $index        = 'breadcrumbs-searchprefix';
×
UNCOV
196
                $control_args = [
×
197
                        'label' => __( 'Prefix for search result pages:', 'wordpress-seo' ),
×
UNCOV
198
                ];
×
199

200
                $this->add_setting_and_control( $index, $control_args );
×
201
        }
202

203
        /**
204
         * Adds the breadcrumb 404 prefix text field.
205
         *
206
         * @return void
207
         */
208
        private function breadcrumbs_404_setting() {
×
209
                $index        = 'breadcrumbs-404crumb';
×
UNCOV
210
                $control_args = [
×
211
                        'label' => __( 'Breadcrumb for 404 pages:', 'wordpress-seo' ),
×
UNCOV
212
                ];
×
213

214
                $this->add_setting_and_control( $index, $control_args );
×
215
        }
216

217
        /**
218
         * Adds the customizer setting and control.
219
         *
220
         * @param string      $index           Array key index to use for the customizer setting.
221
         * @param array       $control_args    Customizer control object arguments.
222
         *                                     Only those different from the default need to be passed.
223
         * @param string|null $id              Optional. Customizer control object ID.
224
         *                                     Will default to 'wpseo-' . $index.
225
         * @param array       $custom_settings Optional. Customizer setting arguments.
226
         *                                     Only those different from the default need to be passed.
227
         *
228
         * @return void
229
         */
230
        private function add_setting_and_control( $index, $control_args, $id = null, $custom_settings = [] ) {
×
231
                $setting                  = sprintf( $this->setting_template, $index );
×
232
                $control_args             = array_merge( $this->default_control_args, $control_args );
×
233
                $control_args['settings'] = $setting;
×
234

235
                $settings_args = $this->default_setting_args;
×
236
                if ( ! empty( $custom_settings ) ) {
×
237
                        $settings_args = array_merge( $settings_args, $custom_settings );
×
238
                }
239

240
                if ( ! isset( $id ) ) {
×
241
                        $id = 'wpseo-' . $index;
×
242
                }
243

244
                $this->wp_customize->add_setting( $setting, $settings_args );
×
245

246
                $control = new WP_Customize_Control( $this->wp_customize, $id, $control_args );
×
247
                $this->wp_customize->add_control( $control );
×
248
        }
249
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc