vue-wp-starter icon indicating copy to clipboard operation
vue-wp-starter copied to clipboard

how to use wp_verify_nonce

Open clh021 opened this issue 6 years ago • 2 comments

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?

clh021 avatar Dec 01 '18 12:12 clh021

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!

zombiefredrik avatar Dec 19 '18 14:12 zombiefredrik


	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

tripflex avatar Jul 23 '19 18:07 tripflex