vue-wp-starter
vue-wp-starter copied to clipboard
how to use wp_verify_nonce
Very Good idea!
Just, I don't konw how to check nonce in ajax api.
wp_verify_nonce($_POST['nonce_check'],'action_name');
Any Good idea please?
This is a start for you:
In includes/class-admin.php
public function plugin_page() { echo '<div class="wrap"><div id="vue-admin-app"></div></div>'; wp_localize_script( 'baseplugin-admin', 'wpApAdminSettings', array( 'root' => esc_url_raw( rest_url() ), 'nonce' => wp_create_nonce( 'wp_rest_vue_admin_app_or_whatever' ) ) ); }
Then you add an header to $http according to this https://developer.wordpress.org/rest-api/using-the-rest-api/authentication/#cookie-authentication You can get the settings (nonce and root) in this object in vue: wpApAdminSettings
Sorry for the formatting - I suck at github apperently!
public function plugin_page() {
echo '<div class="wrap"><div id="vue-admin-app"></div></div>';
wp_localize_script( 'baseplugin-admin', 'wpApAdminSettings', array( 'root' => esc_url_raw( rest_url() ),
'nonce' => wp_create_nonce( 'wp_rest_vue_admin_app_or_whatever' )
) );
}
@zombiefredrik just place the code inside THREE ticks "```php`" followed by the code type, and close with those same three ticks
https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet#code-and-syntax-highlighting