javascript ajax and nonce

Okay, so I found a working solution which is as simple as I thought the whole process should be. The confusing WordPress codex made things harder really. The creation and naming of the nonce is as simple as: wp_create_nonce( ‘example’ ); This is passed though AJAX and localisation of the script to the PHP. Then … Read more

woocommerce search by sku and title ajax

Pls Try this code if(is_numeric($search_keyword)){ $args = array( ‘posts_per_page’ => 3, ‘post_type’ => ‘product’, ‘meta_query’ => array( array( ‘key’ => ‘_sku’, ‘value’ => $search_keyword, ‘compare’ => ‘LIKE’ ) ) ); } else if(is_string($search_keyword)){ $args = array( ‘s’ => $search_keyword, ‘post_type’ => ‘product’, ‘post_status’ => ‘publish’, ‘ignore_sticky_posts’ => 1, ‘posts_per_page’ => 3, ‘orderby’ => $ordering_args[‘orderby’], ‘order’ … Read more

How to disable drag-and-drop upload function in Media Library?

Instead of removing upload script you can make the upload error out if the user does not have admin privileges. Like this- function tomjn_only_upload_for_admin( $file ) { if ( ! current_user_can( ‘manage_options’ ) ) { $file[‘error’] = ‘You can\’t upload images without admin privileges!’; } return $file; } add_filter( ‘wp_handle_upload_prefilter’, ‘tomjn_only_upload_for_admin’ ); For other possible … Read more

Wait ajax to complete before continue loop

I’ve modified my codes based on Jory Hogeveen comments, and it solved my problem. What I do is, to not using the regular loop but instead use a recursive function that calls itself after it finishes calling for the request. For those who are looking for the same answer, please see below. var users_info = … Read more

How can I call an api before user login

I think this is just a slight mistake on your “if” condition $result = preg_split(‘/\//’,’domain.com/api/user/verify_phone’); var_dump($result); Results in: array(4) { [0]=> string(10) “domain.com” [1]=> string(3) “api” [2]=> string(4) “user” [3]=> string(12) “verify_phone” } So the result at [1] is “api”, but you are checking for “/api/” on the fourth line of your code sample.

Hide Load more Ajax button if there is no more users to load or less than the number?

I think something like this may work, if response is just HTML and returns an empty string ” when there are no more results: <script type=”text/javascript”> var ajaxurl = “<?php echo admin_url( ‘admin-ajax.php’ ); ?>”; var page = 2; jQuery(function($) { $(‘body’).on(‘click’, ‘.loadmorefollowing’, function() { var data = { ‘action’: ‘user_following_by_ajax’, ‘page’: page, ‘security’: ‘<?php … Read more

wp_mail doesn’t work when logged in?

You’ve got a typo in the hook that runs for logged in users: add_action(‘wp_ajax_search_notify_emaill’, ‘search_notify_email’); There’s an extra l in the hook name. The hook names need to be the same, apart from nopriv_, so you should have: add_action(‘wp_ajax_nopriv_search_notify_email’, ‘search_notify_email’); add_action(‘wp_ajax_search_notify_email’, ‘search_notify_email’); When you send an AJAX request with an action WordPress runs the hook … Read more