user_helper = $user_helper; $this->capability_helper = $capability_helper; } /** * Registers all hooks to WordPress. * * @return void */ public function register_hooks() { \add_action( 'wp_ajax_wpseo_resolve_alert', [ $this, 'resolve_alert' ] ); } /** * Runs the callback to resolve an alert for the current user. * * @return void. */ public function resolve_alert() { if ( ! \check_ajax_referer( 'wpseo-resolve-alert-nonce', 'nonce', false ) || ! $this->capability_helper->current_user_can( 'wpseo_manage_options' ) ) { \wp_send_json_error( [ 'message' => 'Security check failed.', ], ); return; } if ( ! isset( $_POST['alertId'] ) ) { \wp_send_json_error( [ 'message' => 'Alert ID is missing.', ], ); return; } $alert_id = \sanitize_text_field( \wp_unslash( $_POST['alertId'] ) ); $user_id = \get_current_user_id(); $this->user_helper->update_meta( $user_id, $alert_id . '_resolved', true ); \wp_send_json_success( [ 'message' => 'Alert resolved successfully.', ], ); } }