Stopping user deletion from running on error

After the discussion with @CelsoBessa in the comments section of the question, I came up with this solution function display_admin_notices () { // NOTE: Maybe code should be added here to ensure you are displaying those notices only for certain admin pages if (isset($_GET[‘update’])) { switch ($_GET[‘update’]) { case NOTICE__ERROR: $type=”notice-error”; break; case NOTICE__WARNING: $type=”notice-warning”; … Read more

Custom HTML in specific category single page and its descendant categories

A few changes to your code: Changed the action hook to wp_head. Removed the false ‘pluggable’ wrapping of your function. if ( ! function_exists( ‘post_is_in_descendant_category’ ) ) { function post_is_in_descendant_category( $cats, $_post = null ) { foreach ( (array) $cats as $cat ) { // get_term_children() accepts integer ID only $descendants = get_term_children( (int) $cat, … Read more

How to track post number on the_loop

This should do it: $real_current_post = $wp_query->current_post + 1; switch( $real_current_post ){ case 2: // Do something for 2 break; case 5: // Do something for 5 break; case 7: // Do something for 7 break; } You may need to globalize $wp_query, but as long as you’re using the normal template hierarchy, it should … Read more

WordPress custom form action url

simple with jQuery: //first make sure you have jQuery on that page add_action(‘wp_enqueue_scripts’,’make_sure_i_have_jquery’); function make_sure_i_have_jquery(){ if (!is_admin()) wp_enqueue_script( ‘jquery’ ); } //then just change the url to you own add_action(‘wp_footer’,’change_comment_form’); function make_sure_i_have_jquery(){ if (!is_admin() && (is_page() || is_single())) echo ‘<script> $(“#commentform”).attr(“action”, “http://yourUrl.com”); </script>’; } just paste this in your theme’s functions.php or the plugin your … Read more

Remove action from shortcode

I do not want to removing and re-adding shortcode, because there is huge function beyond it. This might not answer your question, but the size of the shortcode function itself does not make much of a difference for removing and re-adding. Short or long functions take the same time here. So don’t hinder yourself removing … Read more

add_action in class and use it in theme

I recommend to add a static method to access the plugin instance. Example, taken from this answer: class My_Plugin { private $var=”foo”; protected static $instance = NULL; public static function get_instance() { // create an object NULL === self::$instance and self::$instance = new self; return self::$instance; // return the object } public function __construct() { … Read more

remove_action returns FALSE

Locate the original add_action call and make sure that your remove_action call exactly mimics it including the $priority and $accepted_args parameters.