| @@ -32,14 +32,27 @@ | ||
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | /** |
| 35 | 35 | * Handles the dismiss notice request. |
| 36 | + * | |
| 37 | + * @return void | |
| 36 | 38 | */ |
| 37 | 39 | public function dismiss_notice() { |
| 38 | 40 | check_ajax_referer( 'dismiss-plugin-conflict' ); |
| 39 | 41 | |
| 40 | - $conflict_data = filter_input( INPUT_POST, 'data', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ); | |
| 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 | + } | |
| 41 | 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 | + | |
| 42 | 55 | $this->dismissed_conflicts = $this->get_dismissed_conflicts( $conflict_data['section'] ); |
| 43 | 56 | |
| 44 | 57 | $this->compare_plugins( $conflict_data['plugins'] ); |
| 45 | 58 | |
| @@ -77,8 +90,10 @@ | ||
| 77 | 90 | /** |
| 78 | 91 | * Storing the conflicting plugins as an user option in the database. |
| 79 | 92 | * |
| 80 | 93 | * @param string $plugin_section Plugin conflict type (such as Open Graph or sitemap). |
| 94 | + * | |
| 95 | + * @return void | |
| 81 | 96 | */ |
| 82 | 97 | private function save_dismissed_conflicts( $plugin_section ) { |
| 83 | 98 | $dismissed_conflicts = $this->get_dismissed_option(); |
| 84 | 99 | |
| @@ -90,8 +105,10 @@ | ||
| 90 | 105 | /** |
| 91 | 106 | * Loop through the plugins to compare them with the already stored dismissed plugin conflicts. |
| 92 | 107 | * |
| 93 | 108 | * @param array $posted_plugins Plugin set to check. |
| 109 | + * | |
| 110 | + * @return void | |
| 94 | 111 | */ |
| 95 | 112 | public function compare_plugins( array $posted_plugins ) { |
| 96 | 113 | foreach ( $posted_plugins as $posted_plugin ) { |
| 97 | 114 | $this->compare_plugin( $posted_plugin ); |
| @@ -101,8 +118,10 @@ | ||
| 101 | 118 | /** |
| 102 | 119 | * Check if plugin is already dismissed, if not store it in the array that will be saved later. |
| 103 | 120 | * |
| 104 | 121 | * @param string $posted_plugin Plugin to check against dismissed conflicts. |
| 122 | + * | |
| 123 | + * @return void | |
| 105 | 124 | */ |
| 106 | 125 | private function compare_plugin( $posted_plugin ) { |
| 107 | 126 | if ( ! in_array( $posted_plugin, $this->dismissed_conflicts, true ) ) { |
| 108 | 127 | $this->dismissed_conflicts[] = $posted_plugin; |