• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In
Build has been canceled!

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

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

8
/**
9
 * Performs the load on admin side.
10
 */
11
class WPSEO_Admin_Init {
12

13
        /**
14
         * Holds the global `$pagenow` variable's value.
15
         *
16
         * @var string
17
         */
18
        private $pagenow;
19

20
        /**
21
         * Holds the asset manager.
22
         *
23
         * @var WPSEO_Admin_Asset_Manager
24
         */
25
        private $asset_manager;
26

27
        /**
28
         * Class constructor.
29
         */
30
        public function __construct() {
×
31
                $GLOBALS['wpseo_admin'] = new WPSEO_Admin();
×
32

33
                $this->pagenow = $GLOBALS['pagenow'];
×
34

35
                $this->asset_manager = new WPSEO_Admin_Asset_Manager();
×
36

37
                add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_dismissible' ] );
×
38
                add_action( 'admin_init', [ $this, 'unsupported_php_notice' ], 15 );
×
39
                add_action( 'admin_init', [ $this, 'remove_translations_notification' ], 15 );
×
40
                add_action( 'admin_init', [ $this->asset_manager, 'register_assets' ] );
×
41
                add_action( 'admin_init', [ $this, 'show_hook_deprecation_warnings' ] );
×
42
                add_action( 'admin_init', [ 'WPSEO_Plugin_Conflict', 'hook_check_for_plugin_conflicts' ] );
×
43
                add_action( 'admin_notices', [ $this, 'permalink_settings_notice' ] );
×
44
                add_action( 'post_submitbox_misc_actions', [ $this, 'add_publish_box_section' ] );
×
45

46
                $this->load_meta_boxes();
×
47
                $this->load_taxonomy_class();
×
48
                $this->load_admin_page_class();
×
49
                $this->load_admin_user_class();
×
50
                $this->load_xml_sitemaps_admin();
×
51
                $this->load_plugin_suggestions();
×
52
        }
53

54
        /**
55
         * Enqueue our styling for dismissible yoast notifications.
56
         */
57
        public function enqueue_dismissible() {
×
58
                $this->asset_manager->enqueue_style( 'dismissible' );
×
59
        }
60

61
        /**
62
         * Removes any notification for incomplete translations.
63
         *
64
         * @return void
65
         */
66
        public function remove_translations_notification() {
×
67
                $notification_center = Yoast_Notification_Center::get();
×
68
                $notification_center->remove_notification_by_id( 'i18nModuleTranslationAssistance' );
×
69
        }
70

71
        /**
72
         * Creates an unsupported PHP version notification in the notification center.
73
         *
74
         * @return void
75
         */
76
        public function unsupported_php_notice() {
×
77
                $notification_center = Yoast_Notification_Center::get();
×
78
                $notification_center->remove_notification_by_id( 'wpseo-dismiss-unsupported-php' );
×
79
        }
80

81
        /**
82
         * Gets the latest released major WordPress version from the WordPress stable-check api.
83
         *
84
         * @return float|int The latest released major WordPress version. 0 when the stable-check API doesn't respond.
85
         */
86
        private function get_latest_major_wordpress_version() {
×
87
                $core_updates = get_core_updates( [ 'dismissed' => true ] );
×
88

89
                if ( $core_updates === false ) {
×
90
                        return 0;
×
91
                }
92

93
                $wp_version_latest = get_bloginfo( 'version' );
×
94
                foreach ( $core_updates as $update ) {
×
95
                        if ( $update->response === 'upgrade' && version_compare( $update->version, $wp_version_latest, '>' ) ) {
×
96
                                $wp_version_latest = $update->version;
×
97
                        }
98
                }
99

100
                // Strip the patch version and convert to a float.
101
                return (float) $wp_version_latest;
×
102
        }
103

104
        /**
105
         * Helper to verify if the user is currently visiting one of our admin pages.
106
         *
107
         * @return bool
108
         */
109
        private function on_wpseo_admin_page() {
×
110
                // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information.
111
                if ( ! isset( $_GET['page'] ) || ! is_string( $_GET['page'] ) ) {
×
112
                        return false;
×
113
                }
114

115
                if ( $this->pagenow !== 'admin.php' ) {
×
116
                        return false;
×
117
                }
118

119
                // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information.
120
                $current_page = sanitize_text_field( wp_unslash( $_GET['page'] ) );
×
121
                return strpos( $current_page, 'wpseo' ) === 0;
×
122
        }
123

124
        /**
125
         * Whether we should load the meta box classes.
126
         *
127
         * @return bool true if we should load the meta box classes, false otherwise.
128
         */
129
        private function should_load_meta_boxes() {
×
130
                /**
131
                 * Filter: 'wpseo_always_register_metaboxes_on_admin' - Allow developers to change whether
132
                 * the WPSEO metaboxes are only registered on the typical pages (lean loading) or always
133
                 * registered when in admin.
134
                 *
135
                 * @api bool Whether to always register the metaboxes or not. Defaults to false.
136
                 */
137
                if ( apply_filters( 'wpseo_always_register_metaboxes_on_admin', false ) ) {
×
138
                        return true;
×
139
                }
140

141
                // If we are in a post editor.
142
                if ( WPSEO_Metabox::is_post_overview( $this->pagenow ) || WPSEO_Metabox::is_post_edit( $this->pagenow ) ) {
×
143
                        return true;
×
144
                }
145

146
                // If we are doing an inline save.
147
                if ( check_ajax_referer( 'inlineeditnonce', '_inline_edit', false ) && isset( $_POST['action'] ) && sanitize_text_field( wp_unslash( $_POST['action'] ) ) === 'inline-save' ) {
×
148
                        return true;
×
149
                }
150

151
                return false;
×
152
        }
153

154
        /**
155
         * Determine whether we should load the meta box class and if so, load it.
156
         */
157
        private function load_meta_boxes() {
×
158
                if ( $this->should_load_meta_boxes() ) {
×
159
                        $GLOBALS['wpseo_metabox']      = new WPSEO_Metabox();
×
160
                        $GLOBALS['wpseo_meta_columns'] = new WPSEO_Meta_Columns();
×
161
                }
162
        }
163

164
        /**
165
         * Determine if we should load our taxonomy edit class and if so, load it.
166
         */
167
        private function load_taxonomy_class() {
×
168
                if (
169
                        WPSEO_Taxonomy::is_term_edit( $this->pagenow )
×
170
                        || WPSEO_Taxonomy::is_term_overview( $this->pagenow )
×
171
                ) {
172
                        new WPSEO_Taxonomy();
×
173
                }
174
        }
175

176
        /**
177
         * Determine if we should load our admin pages class and if so, load it.
178
         *
179
         * Loads admin page class for all admin pages starting with `wpseo_`.
180
         */
181
        private function load_admin_user_class() {
×
182
                if ( in_array( $this->pagenow, [ 'user-edit.php', 'profile.php' ], true )
×
183
                        && current_user_can( 'edit_users' )
×
184
                ) {
185
                        new WPSEO_Admin_User_Profile();
×
186
                }
187
        }
188

189
        /**
190
         * Determine if we should load our admin pages class and if so, load it.
191
         *
192
         * Loads admin page class for all admin pages starting with `wpseo_`.
193
         */
194
        private function load_admin_page_class() {
×
195

196
                if ( $this->on_wpseo_admin_page() ) {
×
197
                        // For backwards compatabilty, this still needs a global, for now...
198
                        $GLOBALS['wpseo_admin_pages'] = new WPSEO_Admin_Pages();
×
199

200
                        $page = null;
×
201

202
                        // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information.
203
                        if ( isset( $_GET['page'] ) && is_string( $_GET['page'] ) ) {
×
204
                                // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information.
205
                                $page = sanitize_text_field( wp_unslash( $_GET['page'] ) );
×
206
                        }
207

208
                        // Only renders Yoast SEO Premium upsells when the page is a Yoast SEO page.
209
                        if ( $page !== null && WPSEO_Utils::is_yoast_seo_free_page( $page ) ) {
×
210
                                $this->register_premium_upsell_admin_block();
×
211
                        }
212
                }
213
        }
214

215
        /**
216
         * Loads the plugin suggestions.
217
         */
218
        private function load_plugin_suggestions() {
×
219
                $suggestions = new WPSEO_Suggested_Plugins( new WPSEO_Plugin_Availability(), Yoast_Notification_Center::get() );
×
220
                $suggestions->register_hooks();
×
221
        }
222

223
        /**
224
         * Registers the Premium Upsell Admin Block.
225
         *
226
         * @return void
227
         */
228
        private function register_premium_upsell_admin_block() {
×
229
                if ( ! YoastSEO()->helpers->product->is_premium() ) {
×
230
                        $upsell_block = new WPSEO_Premium_Upsell_Admin_Block( 'wpseo_admin_promo_footer' );
×
231
                        $upsell_block->register_hooks();
×
232
                }
233
        }
234

235
        /**
236
         * See if we should start our XML Sitemaps Admin class.
237
         */
238
        private function load_xml_sitemaps_admin() {
×
239
                if ( WPSEO_Options::get( 'enable_xml_sitemap', false ) ) {
×
240
                        new WPSEO_Sitemaps_Admin();
×
241
                }
242
        }
243

244
        /**
245
         * Shows deprecation warnings to the user if a plugin has registered a filter we have deprecated.
246
         */
247
        public function show_hook_deprecation_warnings() {
×
248
                global $wp_filter;
×
249

250
                if ( wp_doing_ajax() ) {
×
251
                        return;
×
252
                }
253

254
                // WordPress hooks that have been deprecated since a Yoast SEO version.
255
                $deprecated_filters = [
×
256
                        'wpseo_genesis_force_adjacent_rel_home' => [
×
257
                                'version'     => '9.4',
×
258
                                'alternative' => null,
×
259
                        ],
×
260
                        'wpseo_opengraph' => [
×
261
                                'version'     => '14.0',
×
262
                                'alternative' => null,
×
263
                        ],
×
264
                        'wpseo_twitter' => [
×
265
                                'version'     => '14.0',
×
266
                                'alternative' => null,
×
267
                        ],
×
268
                        'wpseo_twitter_taxonomy_image' => [
×
269
                                'version'     => '14.0',
×
270
                                'alternative' => null,
×
271
                        ],
×
272
                        'wpseo_twitter_metatag_key' => [
×
273
                                'version'     => '14.0',
×
274
                                'alternative' => null,
×
275
                        ],
×
276
                        'wp_seo_get_bc_ancestors' => [
×
277
                                'version'     => '14.0',
×
278
                                'alternative' => 'wpseo_breadcrumb_links',
×
279
                        ],
×
280
                        'validate_facebook_app_id_api_response_code' => [
×
281
                                'version'     => '15.5',
×
282
                                'alternative' => null,
×
283
                        ],
×
284
                        'validate_facebook_app_id_api_response_body' => [
×
285
                                'version'     => '15.5',
×
286
                                'alternative' => null,
×
287
                        ],
×
288
                ];
×
289

290
                // Determine which filters have been registered.
291
                $deprecated_notices = array_intersect(
×
292
                        array_keys( $deprecated_filters ),
×
293
                        array_keys( $wp_filter )
×
294
                );
×
295

296
                // Show notice for each deprecated filter or action that has been registered.
297
                foreach ( $deprecated_notices as $deprecated_filter ) {
×
298
                        $deprecation_info = $deprecated_filters[ $deprecated_filter ];
×
299
                        // phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped -- Only uses the hardcoded values from above.
300
                        _deprecated_hook(
×
301
                                $deprecated_filter,
×
302
                                'WPSEO ' . $deprecation_info['version'],
×
303
                                $deprecation_info['alternative']
×
304
                        );
×
305
                        // phpcs:enable
306
                }
307
        }
308

309
        /**
310
         * Check if the permalink uses %postname%.
311
         *
312
         * @return bool
313
         */
314
        private function has_postname_in_permalink() {
×
315
                return ( strpos( get_option( 'permalink_structure' ), '%postname%' ) !== false );
×
316
        }
317

318
        /**
319
         * Shows a notice on the permalink settings page.
320
         */
321
        public function permalink_settings_notice() {
×
322
                global $pagenow;
×
323

324
                if ( $pagenow === 'options-permalink.php' ) {
×
325
                        printf(
×
326
                                '<div class="notice notice-warning"><p><strong>%1$s</strong><br>%2$s<br><a href="%3$s" target="_blank">%4$s</a></p></div>',
×
327
                                esc_html__( 'WARNING:', 'wordpress-seo' ),
×
328
                                sprintf(
×
329
                                        /* translators: %1$s and %2$s expand to <em> items to emphasize the word in the middle. */
330
                                        esc_html__( 'Changing your permalinks settings can seriously impact your search engine visibility. It should almost %1$s never %2$s be done on a live website.', 'wordpress-seo' ),
×
331
                                        '<em>',
×
332
                                        '</em>'
×
333
                                ),
×
334
                                esc_url( WPSEO_Shortlinker::get( 'https://yoa.st/why-permalinks/' ) ),
×
335
                                // The link's content.
336
                                esc_html__( 'Learn about why permalinks are important for SEO.', 'wordpress-seo' )
×
337
                        );
×
338
                }
339
        }
340

341
        /**
342
         * Adds a custom Yoast section within the Classic Editor publish box.
343
         *
344
         * @param \WP_Post $post The current post object.
345
         *
346
         * @return void
347
         */
348
        public function add_publish_box_section( $post ) {
×
349
                if ( in_array( $this->pagenow, [ 'post.php', 'post-new.php' ], true ) ) {
×
350
                        ?>
351
                        <div id="yoast-seo-publishbox-section"></div>
×
352
                        <?php
353
                        /**
354
                         * Fires after the post time/date setting in the Publish meta box.
355
                         *
356
                         * @api \WP_Post The current post object.
357
                         */
358
                        do_action( 'wpseo_publishbox_misc_actions', $post );
×
359
                }
360
        }
361
}
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