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

Yoast / wordpress-seo / 6987097851

25 Nov 2023 04:49AM UTC coverage: 49.206% (-0.1%) from 49.302%
6987097851

push

github

web-flow
Merge pull request #20878 from Yoast/JRF/ghactions-minor-tweak

GH Actions: update a few links in inline comments

15305 of 31104 relevant lines covered (49.21%)

4.03 hits per line

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

12.61
/src/integrations/admin/crawl-settings-integration.php
1
<?php
2

3
namespace Yoast\WP\SEO\Integrations\Admin;
4

5
use WPSEO_Admin_Asset_Manager;
6
use WPSEO_Option;
7
use WPSEO_Shortlinker;
8
use Yoast\WP\SEO\Conditionals\Admin_Conditional;
9
use Yoast\WP\SEO\Integrations\Integration_Interface;
10
use Yoast\WP\SEO\Presenters\Admin\Alert_Presenter;
11
use Yoast_Form;
12

13
/**
14
 * Crawl_Settings_Integration class
15
 */
16
class Crawl_Settings_Integration implements Integration_Interface {
17

18
        /**
19
         * The admin asset manager.
20
         *
21
         * @var WPSEO_Admin_Asset_Manager
22
         */
23
        private $admin_asset_manager;
24

25
        /**
26
         * Holds the settings + labels for the head clean up piece.
27
         *
28
         * @var array
29
         */
30
        private $basic_settings;
31

32
        /**
33
         * Holds the settings + labels for the feeds clean up.
34
         *
35
         * @var array
36
         */
37
        private $feed_settings;
38

39
        /**
40
         * Holds the settings + labels for permalink cleanup settings.
41
         *
42
         * @var array
43
         */
44
        private $permalink_cleanup_settings;
45

46
        /**
47
         * Holds the settings + labels for search cleanup settings.
48
         *
49
         * @var array
50
         */
51
        private $search_cleanup_settings;
52

53
        /**
54
         * Holds the settings + labels for unused resources settings.
55
         *
56
         * @var array
57
         */
58
        private $unused_resources_settings;
59

60
        /**
61
         * The shortlinker.
62
         *
63
         * @var WPSEO_Shortlinker
64
         */
65
        private $shortlinker;
66

67
        /**
68
         * Returns the conditionals based in which this loadable should be active.
69
         *
70
         * In this case: when on an admin page.
71
         */
72
        public static function get_conditionals() {
2✔
73
                return [ Admin_Conditional::class ];
2✔
74
        }
75

76
        /**
77
         * Crawl_Settings_Integration constructor.
78
         *
79
         * @param WPSEO_Admin_Asset_Manager $admin_asset_manager The admin asset manager.
80
         * @param WPSEO_Shortlinker         $shortlinker         The shortlinker.
81
         */
82
        public function __construct( WPSEO_Admin_Asset_Manager $admin_asset_manager, WPSEO_Shortlinker $shortlinker ) {
×
83
                $this->admin_asset_manager = $admin_asset_manager;
×
84
                $this->shortlinker         = $shortlinker;
×
85
        }
86

87
        /**
88
         * Registers an action to add a new tab to the General page.
89
         */
90
        public function register_hooks() {
2✔
91
                $this->register_setting_labels();
2✔
92

93
                \add_action( 'wpseo_settings_tab_crawl_cleanup_network', [ $this, 'add_crawl_settings_tab_content_network' ] );
2✔
94
                \add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_assets' ] );
2✔
95
        }
1✔
96

97
        /**
98
         * Enqueue the workouts app.
99
         */
100
        public function enqueue_assets() {
8✔
101
                if ( ! \is_network_admin() ) {
8✔
102
                        return;
4✔
103
                }
104

105
                // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Page is not processed or saved.
106
                if ( ! isset( $_GET['page'] ) || $_GET['page'] !== 'wpseo_dashboard' ) {
4✔
107
                        return;
2✔
108
                }
109
                $this->admin_asset_manager->enqueue_script( 'crawl-settings' );
2✔
110
        }
1✔
111

112
        /**
113
         * Connects the settings to their labels.
114
         *
115
         * @return void
116
         */
117
        private function register_setting_labels() {
×
118
                $this->feed_settings = [
×
119
                        'remove_feed_global'            => \__( 'Global feed', 'wordpress-seo' ),
×
120
                        'remove_feed_global_comments'   => \__( 'Global comment feeds', 'wordpress-seo' ),
×
121
                        'remove_feed_post_comments'     => \__( 'Post comments feeds', 'wordpress-seo' ),
×
122
                        'remove_feed_authors'           => \__( 'Post authors feeds', 'wordpress-seo' ),
×
123
                        'remove_feed_post_types'        => \__( 'Post type feeds', 'wordpress-seo' ),
×
124
                        'remove_feed_categories'        => \__( 'Category feeds', 'wordpress-seo' ),
×
125
                        'remove_feed_tags'              => \__( 'Tag feeds', 'wordpress-seo' ),
×
126
                        'remove_feed_custom_taxonomies' => \__( 'Custom taxonomy feeds', 'wordpress-seo' ),
×
127
                        'remove_feed_search'            => \__( 'Search results feeds', 'wordpress-seo' ),
×
128
                        'remove_atom_rdf_feeds'         => \__( 'Atom/RDF feeds', 'wordpress-seo' ),
×
129
                ];
130

131
                $this->basic_settings = [
×
132
                        'remove_shortlinks'        => \__( 'Shortlinks', 'wordpress-seo' ),
×
133
                        'remove_rest_api_links'    => \__( 'REST API links', 'wordpress-seo' ),
×
134
                        'remove_rsd_wlw_links'     => \__( 'RSD / WLW links', 'wordpress-seo' ),
×
135
                        'remove_oembed_links'      => \__( 'oEmbed links', 'wordpress-seo' ),
×
136
                        'remove_generator'         => \__( 'Generator tag', 'wordpress-seo' ),
×
137
                        'remove_pingback_header'   => \__( 'Pingback HTTP header', 'wordpress-seo' ),
×
138
                        'remove_powered_by_header' => \__( 'Powered by HTTP header', 'wordpress-seo' ),
×
139
                ];
140

141
                $this->permalink_cleanup_settings = [
×
142
                        'clean_campaign_tracking_urls' => \__( 'Campaign tracking URL parameters', 'wordpress-seo' ),
×
143
                        'clean_permalinks'             => \__( 'Unregistered URL parameters', 'wordpress-seo' ),
×
144
                ];
145

146
                $this->search_cleanup_settings = [
×
147
                        'search_cleanup'              => \__( 'Filter search terms', 'wordpress-seo' ),
×
148
                        'search_cleanup_emoji'        => \__( 'Filter searches with emojis and other special characters', 'wordpress-seo' ),
×
149
                        'search_cleanup_patterns'     => \__( 'Filter searches with common spam patterns', 'wordpress-seo' ),
×
150
                        'deny_search_crawling'        => \__( 'Prevent search engines from crawling site search URLs', 'wordpress-seo' ),
×
151
                        'redirect_search_pretty_urls' => \__( 'Redirect pretty URLs for search pages to raw format', 'wordpress-seo' ),
×
152
                ];
153

154
                $this->unused_resources_settings = [
×
155
                        'remove_emoji_scripts'  => \__( 'Emoji scripts', 'wordpress-seo' ),
×
156
                        'deny_wp_json_crawling' => \__( 'Prevent search engines from crawling /wp-json/', 'wordpress-seo' ),
×
157
                        'deny_adsbot_crawling'  => \__( 'Prevent Google AdsBot from crawling', 'wordpress-seo' ),
×
158
                ];
159
        }
160

161
        /**
162
         * Adds content to the Crawl Cleanup tab.
163
         *
164
         * @deprecated 20.4
165
         * @codeCoverageIgnore
166
         *
167
         * @param Yoast_Form $yform The yoast form object.
168
         */
169
        public function add_crawl_settings_tab_content( $yform ) {
170
                \_deprecated_function( __METHOD__, 'Yoast SEO 20.4' );
171
                $this->add_crawl_settings( $yform );
172
        }
173

174
        /**
175
         * Adds content to the Crawl Cleanup network tab.
176
         *
177
         * @param Yoast_Form $yform The yoast form object.
178
         */
179
        public function add_crawl_settings_tab_content_network( $yform ) {
×
180
                $this->add_crawl_settings( $yform );
×
181
        }
182

183
        /**
184
         * Print the settings sections.
185
         *
186
         * @param Yoast_Form $yform The Yoast form class.
187
         *
188
         * @return void
189
         */
190
        private function add_crawl_settings( $yform ) {
×
191
                $this->print_toggles( $this->basic_settings, $yform, \__( 'Basic crawl settings', 'wordpress-seo' ) );
×
192

193
                $this->print_toggles( $this->feed_settings, $yform, \__( 'Feed crawl settings', 'wordpress-seo' ) );
×
194
                $this->print_toggles( $this->unused_resources_settings, $yform, \__( 'Remove unused resources', 'wordpress-seo' ) );
×
195

196
                $first_search_setting    = \array_slice( $this->search_cleanup_settings, 0, 1 );
×
197
                $rest_search_settings    = \array_slice( $this->search_cleanup_settings, 1 );
×
198
                $search_settings_toggles = [
199
                        'off' => \__( 'Disabled', 'wordpress-seo' ),
×
200
                        'on'  => \__( 'Enabled', 'wordpress-seo' ),
×
201
                ];
202

203
                $this->print_toggles( $first_search_setting, $yform, \__( 'Search cleanup settings', 'wordpress-seo' ), $search_settings_toggles );
×
204

205
                $this->print_toggles( $rest_search_settings, $yform, '', $search_settings_toggles );
×
206

207
                $permalink_warning = \sprintf(
×
208
                /* Translators: %1$s expands to an opening anchor tag for a link leading to the Yoast SEO page of the Permalink Cleanup features, %2$s expands to a closing anchor tag. */
209
                        \esc_html__(
×
210
                                'These are expert features, so make sure you know what you\'re doing before removing the parameters. %1$sRead more about how your site can be affected%2$s.',
×
211
                                'wordpress-seo'
×
212
                        ),
213
                        '<a href="' . \esc_url( $this->shortlinker->build_shortlink( 'https://yoa.st/permalink-cleanup' ) ) . '" target="_blank" rel="noopener noreferrer">',
×
214
                        '</a>'
×
215
                );
216

217
                $this->print_toggles( $this->permalink_cleanup_settings, $yform, \__( 'Permalink cleanup settings', 'wordpress-seo' ), [], $permalink_warning );
×
218

219
                // Add the original option as hidden, so as not to lose any values if it's disabled and the form is saved.
220
                $yform->hidden( 'clean_permalinks_extra_variables', 'clean_permalinks_extra_variables' );
×
221
        }
222

223
        /**
224
         * Prints a list of toggles for an array of settings with labels.
225
         *
226
         * @param array      $settings The settings being displayed.
227
         * @param Yoast_Form $yform    The Yoast form class.
228
         * @param string     $title    Optional title for the settings being displayed.
229
         * @param array      $toggles  Optional naming of the toggle buttons.
230
         * @param string     $warning  Optional warning to be displayed above the toggles.
231
         *
232
         * @return void
233
         */
234
        private function print_toggles( array $settings, Yoast_Form $yform, $title = '', $toggles = [], $warning = '' ) {
×
235
                if ( ! empty( $title ) ) {
×
236
                        echo '<h3 class="yoast-crawl-settings">', \esc_html( $title ), '</h3>';
×
237
                }
238

239
                if ( ! empty( $warning ) ) {
×
240
                        // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Output escaped in Alert_Presenter.
241
                        echo new Alert_Presenter( $warning, 'warning' );
×
242
                }
243

244
                if ( empty( $toggles ) ) {
×
245
                        $toggles = [
246
                                'off' => \__( 'Keep', 'wordpress-seo' ),
×
247
                                'on'  => \__( 'Remove', 'wordpress-seo' ),
×
248
                        ];
249
                }
250

251
                $setting_prefix = WPSEO_Option::ALLOW_KEY_PREFIX;
×
252
                $toggles        = [
253
                        // phpcs:ignore WordPress.WP.I18n.TextDomainMismatch -- Reason: text is originally from Yoast SEO.
254
                        'on'  => \__( 'Allow Control', 'wordpress-seo' ),
×
255
                        // phpcs:ignore WordPress.WP.I18n.TextDomainMismatch -- Reason: text is originally from Yoast SEO.
256
                        'off' => \__( 'Disable', 'wordpress-seo' ),
×
257
                ];
258

259
                foreach ( $settings as $setting => $label ) {
×
260
                        $attr     = [];
×
261
                        $variable = $setting_prefix . $setting;
×
262

263
                        if ( $this->should_feature_be_disabled_permalink( $setting ) ) {
×
264
                                $attr     = [
265
                                        'disabled' => true,
×
266
                                ];
267
                                $variable = $setting_prefix . $setting . '_disabled';
×
268

269
                                // Also add the original option as hidden, so as not to lose any values if it's disabled and the form is saved.
270
                                $yform->hidden( $setting_prefix . $setting, $setting_prefix . $setting );
×
271
                        }
272
                        elseif ( $this->should_feature_be_disabled_multisite( $setting ) ) {
×
273
                                $attr = [
274
                                        'disabled'                => true,
×
275
                                        'preserve_disabled_value' => false,
276
                                ];
277
                        }
278

279
                        $yform->toggle_switch(
×
280
                                $variable,
×
281
                                $toggles,
×
282
                                $label,
×
283
                                '',
×
284
                                $attr
×
285
                        );
286
                        if ( $this->should_feature_be_disabled_permalink( $setting ) ) {
×
287
                                echo '<p class="yoast-crawl-settings-help">';
×
288
                                if ( \current_user_can( 'manage_options' ) ) {
×
289
                                        echo \sprintf(
×
290
                                        /* translators: 1: Link start tag to the Permalinks settings page, 2: Link closing tag. */
291
                                                \esc_html__( 'This feature is disabled when your site is not using %1$spretty permalinks%2$s.', 'wordpress-seo' ),
×
292
                                                '<a href="' . \esc_url( \admin_url( 'options-permalink.php' ) ) . '">',
×
293
                                                '</a>'
×
294
                                        );
295
                                }
296
                                else {
297
                                        echo \esc_html__( 'This feature is disabled when your site is not using pretty permalinks.', 'wordpress-seo' );
×
298
                                }
299
                                echo '</p>';
×
300
                        }
301
                }
302
        }
303

304
        /**
305
         * Checks if the feature should be disabled due to non-pretty permalinks.
306
         *
307
         * @param string $setting The setting to be displayed.
308
         *
309
         * @return bool
310
         */
311
        protected function should_feature_be_disabled_permalink( $setting ) {
×
312
                return (
313
                        \in_array( $setting, [ 'clean_permalinks', 'clean_campaign_tracking_urls' ], true )
×
314
                        && empty( \get_option( 'permalink_structure' ) )
×
315
                );
316
        }
317

318
        /**
319
         * Checks if the feature should be disabled due to the site being a multisite.
320
         *
321
         * @param string $setting The setting to be displayed.
322
         *
323
         * @return bool
324
         */
325
        protected function should_feature_be_disabled_multisite( $setting ) {
×
326
                return (
327
                        \in_array( $setting, [ 'deny_search_crawling', 'deny_wp_json_crawling', 'deny_adsbot_crawling' ], true )
×
328
                        && \is_multisite()
×
329
                );
330
        }
331
}
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

© 2025 Coveralls, Inc