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

Yoast / wordpress-seo / 49cdf70e861509c37a279de77f1105ee59c0f57f

20 Feb 2024 09:17AM UTC coverage: 53.172%. First build
49cdf70e861509c37a279de77f1105ee59c0f57f

push

github

YoastBot
Bump version to 22.1 on free

7564 of 13903 branches covered (54.41%)

Branch coverage included in aggregate %.

29067 of 54988 relevant lines covered (52.86%)

40245.15 hits per line

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

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

8
/**
9
 * A WordPress integration that listens for whether the SEO changes have been saved successfully.
10
 */
11
class WPSEO_Admin_Settings_Changed_Listener implements WPSEO_WordPress_Integration {
12

13
        /**
14
         * Have the Yoast SEO settings been saved.
15
         *
16
         * @var bool
17
         */
18
        private static $settings_saved = false;
19

20
        /**
21
         * Registers all hooks to WordPress.
22
         *
23
         * @return void
24
         */
25
        public function register_hooks() {
×
26
                add_action( 'admin_init', [ $this, 'intercept_save_update_notification' ] );
×
27
        }
28

29
        /**
30
         * Checks and overwrites the wp_settings_errors global to determine whether the Yoast SEO settings have been saved.
31
         *
32
         * @return void
33
         */
34
        public function intercept_save_update_notification() {
×
35
                global $pagenow;
×
36

37
                if ( $pagenow !== 'admin.php' || ! YoastSEO()->helpers->current_page->is_yoast_seo_page() ) {
×
38
                        return;
×
39
                }
40

41
                // Variable name is the same as the global that is set by get_settings_errors.
42
                $wp_settings_errors = get_settings_errors();
×
43

44
                foreach ( $wp_settings_errors as $key => $wp_settings_error ) {
×
45
                        if ( ! $this->is_settings_updated_notification( $wp_settings_error ) ) {
×
46
                                continue;
×
47
                        }
48

49
                        self::$settings_saved = true;
×
50
                        unset( $wp_settings_errors[ $key ] );
×
51
                        // phpcs:ignore WordPress.WP.GlobalVariablesOverride -- Overwrite the global with the list excluding the Changed saved message.
52
                        $GLOBALS['wp_settings_errors'] = $wp_settings_errors;
×
53
                        break;
×
54
                }
55
        }
56

57
        /**
58
         * Checks whether the settings notification is a settings_updated notification.
59
         *
60
         * @param array $wp_settings_error The settings object.
61
         *
62
         * @return bool Whether this is a settings updated settings notification.
63
         */
64
        public function is_settings_updated_notification( $wp_settings_error ) {
×
65
                return ! empty( $wp_settings_error['code'] ) && $wp_settings_error['code'] === 'settings_updated';
×
66
        }
67

68
        /**
69
         * Get whether the settings have successfully been saved
70
         *
71
         * @return bool Whether the settings have successfully been saved.
72
         */
73
        public function have_settings_been_saved() {
×
74
                return self::$settings_saved;
×
75
        }
76

77
        /**
78
         * Renders a success message if the Yoast SEO settings have been saved.
79
         *
80
         * @return void
81
         */
82
        public function show_success_message() {
×
83
                if ( $this->have_settings_been_saved() ) {
×
84
                        echo '<p class="wpseo-message"><span class="dashicons dashicons-yes"></span>',
×
85
                                esc_html__( 'Settings saved.', 'wordpress-seo' ),
×
86
                                '</p>';
×
87
                }
88
        }
89
}
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