WordPress 在线修改 php 文件提示 Scrape key check failed. Please try again

wp教程11个月前更新 知道君
94 0 0

挺郁闷的,知道君今天修改 php 文件时报错了。

WordPress 在线修改 php 文件提示 Scrape key check failed. Please try again

网上找了一圈没结果,但是这个功能又不能不管,于是只能使用下策了,修改 wordpress 核心文件。

找到 wp-indludes 文件夹下面的 load.php 文件,修改 wp_start_scraping_edited_file_errors 函数。

原代码:

function wp_start_scraping_edited_file_errors() {
    if ( ! isset( $_REQUEST['wp_scrape_key'] ) || ! isset( $_REQUEST['wp_scrape_nonce'] ) ) {
        return;
    }
    $key   = substr( sanitize_key( wp_unslash( $_REQUEST['wp_scrape_key'] ) ), 0, 32 );
    $nonce = wp_unslash( $_REQUEST['wp_scrape_nonce'] );

    if ( get_transient( 'scrape_key_' . $key ) !== $nonce ) {
        echo "###### wp_scraping_result_start:$key ######";
        echo wp_json_encode(
            array(
                'code'    => 'scrape_nonce_failure',
                'message' => __( 'Scrape key check failed. Please try again.' ),
            )
        );
        echo "###### wp_scraping_result_end:$key ######";
        die();
    }
    if ( ! defined( 'WP_SANDBOX_SCRAPING' ) ) {
        define( 'WP_SANDBOX_SCRAPING', true );
    }
    register_shutdown_function( 'wp_finalize_scraping_edited_file_errors', $key );
}

这里只需要修改一下判断逻辑即可。

function wp_start_scraping_edited_file_errors() {
    if ( ! isset( $_REQUEST['wp_scrape_key'] ) || ! isset( $_REQUEST['wp_scrape_nonce'] ) ) {
        return;
    }
    $key   = substr( sanitize_key( wp_unslash( $_REQUEST['wp_scrape_key'] ) ), 0, 32 );
    $nonce = wp_unslash( $_REQUEST['wp_scrape_nonce'] );

    if ( get_transient( 'scrape_key_' . $key ) == $nonce ) {
        echo "###### wp_scraping_result_start:$key ######";
        echo wp_json_encode(
            array(
                'code'    => 'scrape_nonce_failure',
                'message' => __( 'Scrape key check failed. Please try again.' ),
            )
        );
        echo "###### wp_scraping_result_end:$key ######";
        die();
    }
    if ( ! defined( 'WP_SANDBOX_SCRAPING' ) ) {
        define( 'WP_SANDBOX_SCRAPING', true );
    }
    register_shutdown_function( 'wp_finalize_scraping_edited_file_errors', $key );
}

 

© 版权声明

相关文章

暂无评论

暂无评论...