Wordpress:插件中的jQuery / JavaScript仅在登录时有效

时间:2016-06-05 19:16:43

标签: javascript jquery wordpress

我需要将哪些代码整合到我的插件中才能使其在登录和注销时都能正常运行?

function getdetailedsearchresults_scripts() {
    global $post;
    $temp = $_SERVER['HTTP_HOST'];

    if (in_array($post->post_name, array('detailed-search-results', 'detailed-gym-gw', 'detailed-gyms-page')) || in_array($temp, array('192.0.0.50')) ){
        wp_enqueue_script(
            'getdetailedsearchresults-script',
            plugin_dir_url(__FILE__) . "assets/getdetailedsearchresults.js",
            array('jquery'),
            '1.0',
            true
        );
    }
    wp_localize_script(
        'getdetailedsearchresults-script', // this needs to match the name of our enqueued script
        'resultsSearchDetailed',      // the name of the object
        array('ajaxurl' => admin_url('admin-ajax.php')) // the property/value
    );
}
add_action( 'wp_enqueue_scripts', 'getdetailedsearchresults_scripts' );
add_action( 'wp_ajax_detailedsearchresults', 'detailedsearchresults_callback' );
add_action( 'wp_ajax_no_priv_detailedsearchresults', 'detailedsearchresults_callback' );
function detailedsearchresults_callback() { }

0 个答案:

没有答案