Contents
How to create admin Ajax hook in WordPress?
1) Use AJAX to create an admin-ajax hook that you execute with JavaScript when the user clicks the button. You can learn about that approach here: http://codex.wordpress.org/AJAX (make sure to add a nonce for security ( http://codex.wordpress.org/WordPress_Nonces )).
How to use Ajax in a WordPress plugin?
Finally, on your functions.php file, there should be the function triggered by your AJAX call. Remember the suffixes: You need to add an ‘action’ to your AJAX call. The value should be the same as the add_action hook to wp_ajax. e.g. This allows WordPress to know which function to run when the AJAX call is made.
Which is the dedicated Ajax action in WordPress?
WordPress’ Dedicated Ajax Actions. There are two WordPress dedicated Ajax actions that we can use. The first is wp_ajax_$action which handles the Ajax request if the user is logged in. The second is wp_ajax_nopriv_$action which handles the Ajax request if the user is not logged in and has no privileges at all.
How to securely secure WordPress Ajax using nonce?
So, in the jQuery above, we submit our nonce data using $_POST [‘nonce_data’] and we get the data attributes using jQuery data: What we need to do now is to check and verify the nonce in our AJAX Callback. If it’s valid we can return the data requested, but if verification fail, stop the data.
If you create a plugin with the following code and it will add a left hand menu option called ‘Test Button’ when you are in the admin area. Click on this and you will see a button. Clicking that button runs the test_button_action function. In my example function I’ve both put a message on the page and written to a log file.
How to put a link at the bottom of a WordPress post?
To place the link under the each blog post, add the code bellow inside the run method: This will filter the post excerpt and place the link inside the loop. Now when you’re logging in to your WordPress website and you browse your home page (or the page showing your posts), you’ll see the ‘Read Me Later’ link at the bottom of every post.
How do you save a link in WordPress?
By clicking the link, the user can select that post to be saved in the ‘Read Me Later’ list. After they click, the link will disappear from the post and the post ID will be saved in the database. There are two considerations when we create the link: Only logged in user will see the link.