Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to use wp_verify_nonce #6

Open
clh021 opened this issue Dec 1, 2018 · 2 comments
Open

how to use wp_verify_nonce #6

clh021 opened this issue Dec 1, 2018 · 2 comments

Comments

@clh021
Copy link

clh021 commented Dec 1, 2018

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?

@zombiefredrik
Copy link

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!

@tripflex
Copy link

	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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants