• 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

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

8
use Yoast\WP\SEO\Integrations\Settings_Integration;
9

10
/**
11
 * Class that holds most of the admin functionality for Yoast SEO.
12
 */
13
class WPSEO_Admin {
14

15
        /**
16
         * The page identifier used in WordPress to register the admin page.
17
         *
18
         * !DO NOT CHANGE THIS!
19
         *
20
         * @var string
21
         */
22
        const PAGE_IDENTIFIER = 'wpseo_dashboard';
23

24
        /**
25
         * Array of classes that add admin functionality.
26
         *
27
         * @var array
28
         */
29
        protected $admin_features;
30

31
        /**
32
         * Class constructor.
33
         */
34
        public function __construct() {
×
35
                $integrations = [];
×
36

37
                global $pagenow;
×
38

39
                $wpseo_menu = new WPSEO_Menu();
×
40
                $wpseo_menu->register_hooks();
×
41

42
                if ( is_multisite() ) {
×
43
                        WPSEO_Options::maybe_set_multisite_defaults( false );
×
44
                }
45

46
                if ( WPSEO_Options::get( 'stripcategorybase' ) === true ) {
×
47
                        add_action( 'created_category', [ $this, 'schedule_rewrite_flush' ] );
×
48
                        add_action( 'edited_category', [ $this, 'schedule_rewrite_flush' ] );
×
49
                        add_action( 'delete_category', [ $this, 'schedule_rewrite_flush' ] );
×
50
                }
51

52
                if ( WPSEO_Options::get( 'disable-attachment' ) === true ) {
×
53
                        add_filter( 'wpseo_accessible_post_types', [ 'WPSEO_Post_Type', 'filter_attachment_post_type' ] );
×
54
                }
55

56
                add_filter( 'plugin_action_links_' . WPSEO_BASENAME, [ $this, 'add_action_link' ], 10, 2 );
×
57
                add_filter( 'network_admin_plugin_action_links_' . WPSEO_BASENAME, [ $this, 'add_action_link' ], 10, 2 );
×
58

59
                add_action( 'admin_enqueue_scripts', [ $this, 'config_page_scripts' ] );
×
60
                add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_global_style' ] );
×
61

62
                add_filter( 'user_contactmethods', [ $this, 'update_contactmethods' ], 10, 1 );
×
63

64
                add_action( 'after_switch_theme', [ $this, 'switch_theme' ] );
×
65
                add_action( 'switch_theme', [ $this, 'switch_theme' ] );
×
66

67
                add_filter( 'set-screen-option', [ $this, 'save_bulk_edit_options' ], 10, 3 );
×
68

69
                add_action( 'admin_init', [ 'WPSEO_Plugin_Conflict', 'hook_check_for_plugin_conflicts' ], 10, 1 );
×
70

71
                add_action( 'admin_init', [ $this, 'map_manage_options_cap' ] );
×
72

73
                WPSEO_Sitemaps_Cache::register_clear_on_option_update( 'wpseo' );
×
74
                WPSEO_Sitemaps_Cache::register_clear_on_option_update( 'home' );
×
75

76
                if ( YoastSEO()->helpers->current_page->is_yoast_seo_page() ) {
×
77
                        add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_assets' ] );
×
78
                }
79

80
                $this->set_upsell_notice();
×
81

82
                $this->initialize_cornerstone_content();
×
83

84
                if ( WPSEO_Utils::is_plugin_network_active() ) {
×
85
                        $integrations[] = new Yoast_Network_Admin();
×
86
                }
87

88
                $this->admin_features = [
×
89
                        'dashboard_widget'         => new Yoast_Dashboard_Widget(),
×
90
                        'wincher_dashboard_widget' => new Wincher_Dashboard_Widget(),
×
91
                ];
92

93
                if ( WPSEO_Metabox::is_post_overview( $pagenow ) || WPSEO_Metabox::is_post_edit( $pagenow ) ) {
×
94
                        $this->admin_features['primary_category'] = new WPSEO_Primary_Term_Admin();
×
95
                }
96

97
                $integrations[] = new WPSEO_Yoast_Columns();
×
98
                $integrations[] = new WPSEO_Statistic_Integration();
×
99
                $integrations[] = new WPSEO_Capability_Manager_Integration( WPSEO_Capability_Manager_Factory::get() );
×
100
                $integrations[] = new WPSEO_Admin_Gutenberg_Compatibility_Notification();
×
101
                $integrations[] = new WPSEO_Expose_Shortlinks();
×
102
                $integrations[] = new WPSEO_MyYoast_Proxy();
×
103
                $integrations[] = new WPSEO_Schema_Person_Upgrade_Notification();
×
104
                $integrations[] = new WPSEO_Tracking( 'https://tracking.yoast.com/stats', ( WEEK_IN_SECONDS * 2 ) );
×
105
                $integrations[] = new WPSEO_Admin_Settings_Changed_Listener();
×
106

107
                $integrations = array_merge(
×
108
                        $integrations,
×
109
                        $this->get_admin_features(),
×
110
                        $this->initialize_cornerstone_content()
×
111
                );
112

113
                foreach ( $integrations as $integration ) {
×
114
                        $integration->register_hooks();
×
115
                }
116
        }
117

118
        /**
119
         * Schedules a rewrite flush to happen at shutdown.
120
         */
121
        public function schedule_rewrite_flush() {
×
122
                // Bail if this is a multisite installation and the site has been switched.
123
                if ( is_multisite() && ms_is_switched() ) {
×
124
                        return;
×
125
                }
126

127
                add_action( 'shutdown', 'flush_rewrite_rules' );
×
128
        }
129

130
        /**
131
         * Returns all the classes for the admin features.
132
         *
133
         * @return array
134
         */
135
        public function get_admin_features() {
4✔
136
                return $this->admin_features;
4✔
137
        }
138

139
        /**
140
         * Register assets needed on admin pages.
141
         */
142
        public function enqueue_assets() {
×
143
                // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form data.
144
                $page = isset( $_GET['page'] ) && is_string( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : '';
×
145
                if ( $page === 'wpseo_licenses' ) {
×
146
                        $asset_manager = new WPSEO_Admin_Asset_Manager();
×
147
                        $asset_manager->enqueue_style( 'extensions' );
×
148
                }
149
        }
150

151
        /**
152
         * Returns the manage_options capability.
153
         *
154
         * @return string The capability to use.
155
         */
156
        public function get_manage_options_cap() {
×
157
                /**
158
                 * Filter: 'wpseo_manage_options_capability' - Allow changing the capability users need to view the settings pages.
159
                 *
160
                 * @api string unsigned The capability.
161
                 */
162
                return apply_filters( 'wpseo_manage_options_capability', 'wpseo_manage_options' );
×
163
        }
164

165
        /**
166
         * Maps the manage_options cap on saving an options page to wpseo_manage_options.
167
         */
168
        public function map_manage_options_cap() {
×
169
                // phpcs:ignore WordPress.Security -- The variable is only used in strpos and thus safe to not unslash or sanitize.
170
                $option_page = ! empty( $_POST['option_page'] ) ? $_POST['option_page'] : '';
×
171

172
                if ( strpos( $option_page, 'yoast_wpseo' ) === 0 || strpos( $option_page, Settings_Integration::PAGE ) === 0 ) {
×
173
                        add_filter( 'option_page_capability_' . $option_page, [ $this, 'get_manage_options_cap' ] );
×
174
                }
175
        }
176

177
        /**
178
         * Adds the ability to choose how many posts are displayed per page
179
         * on the bulk edit pages.
180
         */
181
        public function bulk_edit_options() {
×
182
                $option = 'per_page';
×
183
                $args   = [
184
                        'label'   => __( 'Posts', 'wordpress-seo' ),
×
185
                        'default' => 10,
×
186
                        'option'  => 'wpseo_posts_per_page',
×
187
                ];
188
                add_screen_option( $option, $args );
×
189
        }
190

191
        /**
192
         * Saves the posts per page limit for bulk edit pages.
193
         *
194
         * @param int    $status Status value to pass through.
195
         * @param string $option Option name.
196
         * @param int    $value  Count value to check.
197
         *
198
         * @return int
199
         */
200
        public function save_bulk_edit_options( $status, $option, $value ) {
×
201
                if ( $option && ( $value > 0 && $value < 1000 ) === 'wpseo_posts_per_page' ) {
×
202
                        return $value;
×
203
                }
204

205
                return $status;
×
206
        }
207

208
        /**
209
         * Adds links to Premium Support and FAQ under the plugin in the plugin overview page.
210
         *
211
         * @param array  $links Array of links for the plugins, adapted when the current plugin is found.
212
         * @param string $file  The filename for the current plugin, which the filter loops through.
213
         *
214
         * @return array
215
         */
216
        public function add_action_link( $links, $file ) {
×
217
                $first_time_configuration_notice_helper = \YoastSEO()->helpers->first_time_configuration_notice;
×
218

219
                if ( $file === WPSEO_BASENAME && WPSEO_Capability_Utils::current_user_can( 'wpseo_manage_options' ) ) {
×
220
                        if ( is_network_admin() ) {
×
221
                                $settings_url = network_admin_url( 'admin.php?page=' . self::PAGE_IDENTIFIER );
×
222
                        }
223
                        else {
224
                                $settings_url = admin_url( 'admin.php?page=' . self::PAGE_IDENTIFIER );
×
225
                        }
226
                        $settings_link = '<a href="' . esc_url( $settings_url ) . '">' . __( 'Settings', 'wordpress-seo' ) . '</a>';
×
227
                        array_unshift( $links, $settings_link );
×
228
                }
229

230
                // Add link to docs.
231
                $faq_link = '<a href="' . esc_url( WPSEO_Shortlinker::get( 'https://yoa.st/1yc' ) ) . '" target="_blank">' . __( 'FAQ', 'wordpress-seo' ) . '</a>';
×
232
                array_unshift( $links, $faq_link );
×
233

234
                if ( $first_time_configuration_notice_helper->first_time_configuration_not_finished() && ! is_network_admin() ) {
×
235
                        $configuration_title = ( ! $first_time_configuration_notice_helper->should_show_alternate_message() ) ? 'first-time configuration' : 'SEO configuration';
×
236
                        /* translators: CTA to finish the first time configuration. %s: Either first-time SEO configuration or SEO configuration. */
237
                        $message  = sprintf( __( 'Finish your %s', 'wordpress-seo' ), $configuration_title );
×
238
                        $ftc_link = '<a href="' . esc_url( admin_url( 'admin.php?page=wpseo_dashboard#top#first-time-configuration' ) ) . '" target="_blank">' . $message . '</a>';
×
239
                        array_unshift( $links, $ftc_link );
×
240
                }
241

242
                $addon_manager = new WPSEO_Addon_Manager();
×
243
                if ( YoastSEO()->helpers->product->is_premium() ) {
×
244

245
                        // Remove Free 'deactivate' link if Premium is active as well. We don't want users to deactivate Free when Premium is active.
246
                        unset( $links['deactivate'] );
×
247
                        $no_deactivation_explanation = '<span style="color: #32373c">' . sprintf(
×
248
                                /* translators: %s expands to Yoast SEO Premium. */
249
                                __( 'Required by %s', 'wordpress-seo' ),
×
250
                                'Yoast SEO Premium'
×
251
                        ) . '</span>';
×
252

253
                        array_unshift( $links, $no_deactivation_explanation );
×
254

255
                        if ( $addon_manager->has_valid_subscription( WPSEO_Addon_Manager::PREMIUM_SLUG ) ) {
×
256
                                return $links;
×
257
                        }
258

259
                        // Add link to where premium can be activated.
260
                        $activation_link = '<a style="font-weight: bold;" href="' . esc_url( WPSEO_Shortlinker::get( 'https://yoa.st/activate-my-yoast' ) ) . '" target="_blank">' . __( 'Activate your subscription', 'wordpress-seo' ) . '</a>';
×
261
                        array_unshift( $links, $activation_link );
×
262

263
                        return $links;
×
264
                }
265

266
                // Add link to premium landing page.
267
                $premium_link = '<a style="font-weight: bold;" href="' . esc_url( WPSEO_Shortlinker::get( 'https://yoa.st/1yb' ) ) . '" target="_blank" data-action="load-nfd-ctb" data-ctb-id="f6a84663-465f-4cb5-8ba5-f7a6d72224b2">' . __( 'Get Premium', 'wordpress-seo' ) . '</a>';
×
268
                array_unshift( $links, $premium_link );
×
269

270
                return $links;
×
271
        }
272

273
        /**
274
         * Enqueues the (tiny) global JS needed for the plugin.
275
         */
276
        public function config_page_scripts() {
×
277
                $asset_manager = new WPSEO_Admin_Asset_Manager();
×
278
                $asset_manager->enqueue_script( 'admin-global' );
×
279
                $asset_manager->localize_script( 'admin-global', 'wpseoAdminGlobalL10n', $this->localize_admin_global_script() );
×
280
        }
281

282
        /**
283
         * Enqueues the (tiny) global stylesheet needed for the plugin.
284
         */
285
        public function enqueue_global_style() {
×
286
                $asset_manager = new WPSEO_Admin_Asset_Manager();
×
287
                $asset_manager->enqueue_style( 'admin-global' );
×
288
        }
289

290
        /**
291
         * Filter the $contactmethods array and add a set of social profiles.
292
         *
293
         * These are used with the Facebook author, rel="author" and Twitter cards implementation.
294
         *
295
         * @param array $contactmethods Currently set contactmethods.
296
         *
297
         * @return array Contactmethods with added contactmethods.
298
         */
299
        public function update_contactmethods( $contactmethods ) {
2✔
300
                $contactmethods['facebook']   = __( 'Facebook profile URL', 'wordpress-seo' );
2✔
301
                $contactmethods['instagram']  = __( 'Instagram profile URL', 'wordpress-seo' );
2✔
302
                $contactmethods['linkedin']   = __( 'LinkedIn profile URL', 'wordpress-seo' );
2✔
303
                $contactmethods['myspace']    = __( 'MySpace profile URL', 'wordpress-seo' );
2✔
304
                $contactmethods['pinterest']  = __( 'Pinterest profile URL', 'wordpress-seo' );
2✔
305
                $contactmethods['soundcloud'] = __( 'SoundCloud profile URL', 'wordpress-seo' );
2✔
306
                $contactmethods['tumblr']     = __( 'Tumblr profile URL', 'wordpress-seo' );
2✔
307
                $contactmethods['twitter']    = __( 'Twitter username (without @)', 'wordpress-seo' );
2✔
308
                $contactmethods['youtube']    = __( 'YouTube profile URL', 'wordpress-seo' );
2✔
309
                $contactmethods['wikipedia']  = __( 'Wikipedia page about you', 'wordpress-seo' ) . '<br/><small>' . __( '(if one exists)', 'wordpress-seo' ) . '</small>';
2✔
310

311
                return $contactmethods;
2✔
312
        }
313

314
        /**
315
         * Log the updated timestamp for user profiles when theme is changed.
316
         */
317
        public function switch_theme() {
×
318

319
                $users = get_users( [ 'capability' => [ 'edit_posts' ] ] );
×
320

321
                if ( is_array( $users ) && $users !== [] ) {
×
322
                        foreach ( $users as $user ) {
×
323
                                update_user_meta( $user->ID, '_yoast_wpseo_profile_updated', time() );
×
324
                        }
325
                }
326
        }
327

328
        /**
329
         * Localization for the dismiss urls.
330
         *
331
         * @return array
332
         */
333
        private function localize_admin_global_script() {
×
334
                return array_merge(
×
335
                        [
336
                                'isRtl'                   => is_rtl(),
×
337
                                'variable_warning'        => sprintf(
×
338
                                /* translators: %1$s: '%%term_title%%' variable used in titles and meta's template that's not compatible with the given template, %2$s: expands to 'HelpScout beacon' */
339
                                        __( 'Warning: the variable %1$s cannot be used in this template. See the %2$s for more info.', 'wordpress-seo' ),
×
340
                                        '<code>%s</code>',
×
341
                                        'HelpScout beacon'
×
342
                                ),
343
                                /* translators: %s: expends to Yoast SEO */
344
                                'help_video_iframe_title' => sprintf( __( '%s video tutorial', 'wordpress-seo' ), 'Yoast SEO' ),
×
345
                                'scrollable_table_hint'   => __( 'Scroll to see the table content.', 'wordpress-seo' ),
×
346
                                'wincher_is_logged_in'    => WPSEO_Options::get( 'wincher_integration_active', true ) ? YoastSEO()->helpers->wincher->login_status() : false,
×
347
                        ],
348
                        YoastSEO()->helpers->wincher->get_admin_global_links()
×
349
                );
350
        }
351

352
        /**
353
         * Sets the upsell notice.
354
         */
355
        protected function set_upsell_notice() {
×
356
                $upsell = new WPSEO_Product_Upsell_Notice();
×
357
                $upsell->dismiss_notice_listener();
×
358
                $upsell->initialize();
×
359
        }
360

361
        /**
362
         * Whether we are on the admin dashboard page.
363
         *
364
         * @return bool
365
         */
366
        protected function on_dashboard_page() {
×
367
                return $GLOBALS['pagenow'] === 'index.php';
×
368
        }
369

370
        /**
371
         * Loads the cornerstone filter.
372
         *
373
         * @return WPSEO_WordPress_Integration[] The integrations to initialize.
374
         */
375
        protected function initialize_cornerstone_content() {
×
376
                if ( ! WPSEO_Options::get( 'enable_cornerstone_content' ) ) {
×
377
                        return [];
×
378
                }
379

380
                return [
381
                        'cornerstone_filter' => new WPSEO_Cornerstone_Filter(),
×
382
                ];
383
        }
384
}
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