2016-06-16 10 views
1

だから、私はワードプレス(WP-API 2)でPHPのページを持っている:WP-API 2クッキー認証

<?php 
/** 
* Template Name: WP-Api 
*/ 
add_action("wp_enqueue_scripts", "enqueue_"); 
function enqueue_() { 
    wp_localize_script('wp-api', 'wpApiSettings', array('root' => esc_url_raw(rest_url()), 'nonce' => wp_create_nonce('wp_rest'))); 

} 
get_header(); ?> 

<h1>oi</h1> 
<script type="text/javascript"> 

jQuery.ajax({ 
    url: wpApiSettings.root + 'wp/v2/posts/1', 
    method: 'POST', 
    beforeSend: function (xhr) { 
     xhr.setRequestHeader('X-WP-Nonce', wpApiSettings.nonce); 
    }, 
    data:{ 
     'title' : 'Hello Moon' 
    } 
}).done(function (response) { 
    console.log(response); 
}); 

</script> 

私はこの例を実行したいが、コンソールが

Uncaught ReferenceError: wpApiSettings is not defined

何を言います私は間違っている?ありがとうございました!

答えて