• 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/ajax/class-yoast-plugin-conflict-ajax.php
1
<?php
2
/**
3
 * WPSEO plugin file.
4
 *
5
 * @package WPSEO\Admin\Ajax
6
 */
7

8
/**
9
 * Class Yoast_Plugin_Conflict_Ajax.
10
 */
11
class Yoast_Plugin_Conflict_Ajax {
12

13
        /**
14
         * Option identifier where dismissed conflicts are stored.
15
         *
16
         * @var string
17
         */
18
        private $option_name = 'wpseo_dismissed_conflicts';
19

20
        /**
21
         * List of notification identifiers that have been dismissed.
22
         *
23
         * @var array
24
         */
25
        private $dismissed_conflicts = [];
26

27
        /**
28
         * Initialize the hooks for the AJAX request.
29
         */
30
        public function __construct() {
×
31
                add_action( 'wp_ajax_wpseo_dismiss_plugin_conflict', [ $this, 'dismiss_notice' ] );
×
32
        }
33

34
        /**
35
         * Handles the dismiss notice request.
36
         *
37
         * @return void
38
         */
39
        public function dismiss_notice() {
×
40
                check_ajax_referer( 'dismiss-plugin-conflict' );
×
41

42
                if ( ! isset( $_POST['data'] ) || ! is_array( $_POST['data'] ) ) {
×
43
                        // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Reason: WPSEO_Utils::format_json_encode is considered safe.
44
                        wp_die( WPSEO_Utils::format_json_encode( [] ) );
×
45
                }
46

47
                // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Reason: $conflict_data is getting sanitized later.
48
                $conflict_data = wp_unslash( $_POST['data'] );
×
49

50
                $conflict_data = [
×
51
                        'section' => sanitize_text_field( $conflict_data['section'] ),
×
52
                        'plugins' => sanitize_text_field( $conflict_data['plugins'] ),
×
53
                ];
×
54

55
                $this->dismissed_conflicts = $this->get_dismissed_conflicts( $conflict_data['section'] );
×
56

57
                $this->compare_plugins( $conflict_data['plugins'] );
×
58

59
                $this->save_dismissed_conflicts( $conflict_data['section'] );
×
60

61
                wp_die( 'true' );
×
62
        }
63

64
        /**
65
         * Getting the user option from the database.
66
         *
67
         * @return bool|array
68
         */
69
        private function get_dismissed_option() {
×
70
                return get_user_meta( get_current_user_id(), $this->option_name, true );
×
71
        }
72

73
        /**
74
         * Getting the dismissed conflicts from the database
75
         *
76
         * @param string $plugin_section Type of conflict group (such as Open Graph or sitemap).
77
         *
78
         * @return array
79
         */
80
        private function get_dismissed_conflicts( $plugin_section ) {
×
81
                $dismissed_conflicts = $this->get_dismissed_option();
×
82

83
                if ( is_array( $dismissed_conflicts ) && array_key_exists( $plugin_section, $dismissed_conflicts ) ) {
×
84
                        return $dismissed_conflicts[ $plugin_section ];
×
85
                }
86

87
                return [];
×
88
        }
89

90
        /**
91
         * Storing the conflicting plugins as an user option in the database.
92
         *
93
         * @param string $plugin_section Plugin conflict type (such as Open Graph or sitemap).
94
         *
95
         * @return void
96
         */
97
        private function save_dismissed_conflicts( $plugin_section ) {
×
98
                $dismissed_conflicts = $this->get_dismissed_option();
×
99

100
                $dismissed_conflicts[ $plugin_section ] = $this->dismissed_conflicts;
×
101

102
                update_user_meta( get_current_user_id(), $this->option_name, $dismissed_conflicts );
×
103
        }
104

105
        /**
106
         * Loop through the plugins to compare them with the already stored dismissed plugin conflicts.
107
         *
108
         * @param array $posted_plugins Plugin set to check.
109
         *
110
         * @return void
111
         */
112
        public function compare_plugins( array $posted_plugins ) {
×
113
                foreach ( $posted_plugins as $posted_plugin ) {
×
114
                        $this->compare_plugin( $posted_plugin );
×
115
                }
116
        }
117

118
        /**
119
         * Check if plugin is already dismissed, if not store it in the array that will be saved later.
120
         *
121
         * @param string $posted_plugin Plugin to check against dismissed conflicts.
122
         *
123
         * @return void
124
         */
125
        private function compare_plugin( $posted_plugin ) {
×
126
                if ( ! in_array( $posted_plugin, $this->dismissed_conflicts, true ) ) {
×
127
                        $this->dismissed_conflicts[] = $posted_plugin;
×
128
                }
129
        }
130
}
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