Nonces and Ajax request to REST API and verification

For restricting access to your REST API endpoint, you can use the permission_callback parameter like so: register_rest_route( ‘rw-user/v1’, ‘/log-out’, array( ‘methods’ => ‘POST’, ‘callback’ => ‘ajax_logout’, ‘permission_callback’ => function () { return current_user_can( ‘read’ ); }, ) ); And that will require the current user to be logged into WordPress and also the REST API … Read more

Load page content with AJAX using Fancybox?

Here it is. Google use no JS and there is no fancy. Also links can be used with no get, just simple url: page.com/post-name/ On single page: <?php $apost = $_GET[“type”]; preg_replace(‘/_/’, ‘html’, preg_replace(‘/%/’, ‘html’, htmlentities(mysql_real_escape_string($apost)))); ?> <?php if($apost == ‘iframe’) { ?> <?php get_header(‘single’); ?> <?php if (have_posts()) : while (have_posts()) : the_post();?> <div … Read more

Run again current query via ajax but changing a var

You have to note that an ajax request is an entirely new http request, so the $query variable is defined in the page that send the ajax request but will be not set in the page that receive the request. That means that you have completely recreate the query and not change a param. That … Read more

Shortcodes not resolved in AJAX call response

Since version 4.9 visual composer added shortcode lazy loading. To use VC shortcodes on AJAX content use this function before printing the content WPBMap::addAllMappedShortcodes();. So below code may help you, function get_page_content(){ $id = $_REQUEST[‘id’]; $page_data = get_page($id); WPBMap::addAllMappedShortcodes(); echo apply_filters(‘the_content’, $page_data->post_content); wp_die(); } add_action( ‘wp_ajax_nopriv_get_page_content’, ‘get_page_content’ ); add_action( ‘wp_ajax_get_page_content’, ‘get_page_content’ );