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

How to jQuery Ajax show new data from successful insert?

Modify your code as follows: add_action(‘wp_ajax_send_projectmessage’, ‘send_projectmessage’); function send_projectmessage() { global $wpdb; $wpdb->insert( //insert stuff to db table)); // Call your function to retrieve your data and send it to browser $messages = load_projectmessages($projectid); wp_send_json_success($messages); } Display data through JS by modifying this ajaxRequest.done(function(data) { console.log(data); }); to this ajaxRequest.done(function(data) { // Put markup for … Read more

Preprocess submitted data

If I got your question right then maybe you could try using the update_option action, which according to the docs “Fires immediately before an option value is updated.”. It gets option, old value and new value as parameters. https://developer.wordpress.org/reference/hooks/update_option/ The accepted answer here, Hook if somebody saves plugin options?, might also be relevant for you. … Read more

No errors in the console but Ajax call doesn’t seem to be working

I cannot test everything since there are some dependencies on certain markup and functionality, but here’s what I found so far. Wrap your script in the following instead of $ = jQuery;. This is a better way to handle possible conflicts. (function($){ // your code here })(jQuery); While the way you’re enqueuing scripts works, it … Read more

ajax problem – function on server is not called

My guess is that the shipping method isn’t initialised when you make an ajax call. Try moving your actions directly into your init function. EG: function checkAjax(){ print_r($_POST); exit; } function dhlsweden_shipping_method_init() { //use checkAjax since you don’t have access to your shipping method class. If this is the case then you need to rework … Read more