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

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

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