Full Front End, AJAX comment system and comment reply script

<script> var addComment = { settings: function( parentId, postId ) { var t = $(this), commentDivName = $(‘#comment-‘+parentId), formDivName = $(‘#commentForm-‘+postId), formReplyDivName = $(‘#commentReplyForm-‘+parentId), postDivName = $(‘#post-‘+postId), theform = formDivName.find(‘form.comment-form’); if( !t.length || !commentDivName.length || !formDivName.length || !postDivName.length ) { return; } if(!theform.length){ $(postDivName).find(‘[id^=commentReplyForm-]’).each(function(){ if($(this).find(‘form.comment-form’).length){ formDivName = $(‘#’+$(this).attr(‘id’)); } }); theform = formDivName.find(‘form.comment-form’); } theform.find(‘input[name=parent]’).val(parentId); … Read more

Output multi-steps form results in same page

You will need a function that will handle the sent data from the form. Then you have to attach this function to the wp_ajax_nopriv_[your_action_name] hook. function process_form() { // process $_POST data, prepare $output to return // // send: array( ‘success’ => true, ‘data’ => $data ) wp_send_json_success( $data ); wp_die(); } // add_action( ‘wp_ajax_my_action’, … Read more

How to continuously send feedback via AJAX responses to my client?

wp_send_json just does a basic data sanitization under the hood using wp_json_encode function. So you can use PHP’s built-in functionality json_encode the problem that you’re going to have is keeping the connection alive, If you’re not going to have a lot of visitors you can block the PHP thread by simply running a while true … Read more

How can I wp_send_json data?

It seems wp_send_json_success works! I just did something very wrong with it. When you hit the AJAX endpoint, at the end of the logic, simply: wp_send_json_success( [‘next_step’ => ‘enpoint_2’], 200 ); This will send an object to JS: Object{next_step: ‘endpoint_2’} Which you can then use to further your process.

Get post content and show it in a div

OK, I managed to make it work, here’s how i did : Jquery part : jQuery(“.post-link”).click(function(){ var post_id = jQuery(this).data(‘id’); jQuery.post( ajaxurl, { ‘action’: ‘load_post_content’, ‘the_ID’: post_id }, function(response){ jQuery(‘#the-post-content’).html(response); } ); return false; }); And the function.php part : add_action( ‘wp_ajax_load_post_content’, ‘load_post_content’ ); add_action( ‘wp_ajax_nopriv_load_post_content’, ‘load_post_content’ ); function load_post_content() { $the_post_id = $_POST[‘the_ID’]; $args … Read more

How to check nonce lifetime value of plugins?

Check codex info about Nonces life time here. Here is a quick code that will echo life time of nonces in footer of your site’s front-end as html comment. Put it in your functions.php file. $n = “”; add_filter(‘nonce_life’, ‘wptuts_change_nonce_hourly’); function wptuts_change_nonce_hourly( $nonce_life ) { global $n ; $n = $nonce_life; return $nonce_life; } // … Read more