Screencasts – WP Theme Tutorial show

Screencasts – WP Theme Tutorial

Summary: We will cover WordPress development and best practices.

Join Now to Subscribe to this Podcast

Podcasts:

 Starting with WPtouch Pro 3 | File Type: video/x-m4v | Duration: 10:05

Today we take a look at WPtouch Pro 3 basics. We activate the plugin and do some basic theme configuration based on the built in theme settings. We cover: Turning off the default slider Setting up a custom menu Setting up custom menu icons Turning on Custom Post Type Support In future screencasts we'll add bbPress support as well as support for Easy Digital Downloads. Screencast http://www.youtube.com/watch?v=MK_KRrDAjSo

 Sending JSON in WordPress 3.5 | File Type: video/x-m4v | Duration: Unknown

In episode 50 we are going to look at 2 new functions in WordPress 3.5 called: wp_send_json_success and wp_send_json_error. Both of these function help us when sending JSON in our AJAX calls. I need to stop and thank Brady Vercher for pointing these new functions out to me. I had totally missed them being added to WordPress 3.5. How I used to handle it Before WordPress 3.5 I handled my JSON in AJAX with an array something like this: $ajax_response = array( 'success' => true, 'reason' => $our_response_text ); if ( defined( 'DOING_AJAX' ) && DOING_AJAX ){ echo json_encode( $ajax_response ); wp_die(); } If it was a failure I'd set success equal to false. On the frontend that allowed me to figure out if my AJAX call was successful or not. Then I could handle the response different depending on the results. What do they do? wp_send_json_success and wp_send_json_error save me a bunch of code though. Lets take a look at one of them and see what it does. /** * Send a JSON response back to an Ajax request, indicating success. * * @since 3.5.0 * * @param mixed $data Data to encode as JSON, then print and die. */ function wp_send_json_success( $data = null ) { $response = array( 'success' => true ); if ( isset( $data ) ) $response['data'] = $data; wp_send_json( $response ); } Here we see that it sets an array and sets success to true. Then it adds to the array (if we have data sent to the function). Finally it calls wp_send_json. /** * Send a JSON response back to an Ajax request. * * @since 3.5.0 * * @param mixed $response Variable (usually an array or object) to encode as JSON, then print and die. */ function wp_send_json( $response ) { @header( 'Content-Type: application/json; charset=' . get_option( 'blog_charset' ) ); echo json_encode( $response ); if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) wp_die(); else die; } wp_send_json does the rest of our AJAX heavy lifting. It sets our headers then uses echo and json_encode to make sure our javascript will have a nice array to play with. Finally it does all our DOING_AJAX detection for us and then calls wp_die. If we used wp_send_json_error it does the same thing but sets success to false. Instead of us needing to repeat our arrays all over to build our JSON responses all we need to do is use these 2 functions and WordPress does the rest for us. Don't forget I've mentioned it already but it bears mentioning again. If you need compatibility with versions of WordPress lower than 3.5 you can't use these functions. They are new and won't be included in versions before 3.5. Screencast

 do_action inside AJAX calls | File Type: video/x-m4v | Duration: 5:31

It seems I keep doing more and more AJAX work in my WordPress development. 99% of the time I'm doing it for clients on a plugin/theme that won't be widely released. That means that I don't have to worry adding actions and filters to allow others to ext...

Comments

Login or signup comment.