Capture post content before page renders

WordPress does not concatenate the entire page into a string before printing it which is what would have to happen to “capture” the whole page template. Much of the page echos as it occurs– think about template tags like the_content and the_title which don’t return strings. The just echo them. You’d have to use output … Read more

How are Dynamic Sidebar Widgets rendered

That action is just there in case a plugin or theme wants to do something before sidebars are rendered. The code you’re looking for is in widgets.php, just before and just after that action: $callback = $wp_registered_widgets[$id][‘callback’]; do_action( ‘dynamic_sidebar’, $wp_registered_widgets[$id] ); if ( is_callable($callback) ) { call_user_func_array($callback, $params); $did_one = true; } In the wp_register_sidebar_widget() … Read more

admin_notices on runtime in function

I saw this on stackoverflow, may be able to modify it to work in your situation: function my_function($post_id){ if($error){ set_transient( get_current_user_id().’publisherror’, “Error Message” ); } return $post_id; } add_filter ( ‘publish_post’, ‘my_function’ ); function show_admin_notice() { if($out = get_transient( get_current_user_id().’publisherror’ ) ) { delete_transient( get_current_user_id().’publisherror’ ); echo ‘<div class=”error”><p>’.$out.'</p></div>’; } } add_action(‘admin_notices’, “show_admin_notice”);

get_term and get_term_by return null or false, even though term exists

To use get_term_by we need the term object before it gets deleted. Therefore, we should use the action hook delete_term_taxonomy that runs before the term is deleted. Now, we can go ahead and perform some tasks such as deleting all the postmeta related to the term being deleted. The code is: add_action( ‘delete_term_taxonomy’, function($tt_id) { … Read more

Ajax – Call to undefined function get_option()

You’re firing a request to a PHP file that won’t have the WordPress library loaded – hence the undefined function error. You could manually load in WordPress with something like require ‘../../../wp-load.php’. Or, better yet, use the awesome AJAX API. Just fire your request to wp-admin/admin-ajax.php and then register a callback in your plugin or … Read more

conditionally load javascript & CSS for do_action() calls from plugin

And…. the answer was actually correct, if you are using the correct functions. As Milo pointed out, it’s wp_enqueue_script not scripts. add_action(‘wp_footer’, ‘print_my_script’); function print_my_script() { if(did_action(‘my_custom_action’)) { wp_enqueue_script(‘listings’); wp_enqueue_script(‘isotope’); } } Hopefully this helps someone else in need!