Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Lets say I have a function set up like such:

add_action( 'init', 'jigoshop_add_to_cart_action' );

function jigoshop_add_to_cart_action($url = false){
//code
}

To make it pluggable by others plugins, I just need to change this to

add_action( 'init', 'jigoshop_add_to_cart_action' );
if (!function_exists('jigoshop_add_to_cart_action')) { //ADD THIS
function jigoshop_add_to_cart_action($url = false){
//code
}
} //AND THIS

right?

share|improve this question
add comment

1 Answer 1

up vote 0 down vote accepted

No, because you're hooking it to an init action, then somebody can replace the function simply by unhooking it themselves. You don't really need to wrap it or make it pluggable.

share|improve this answer
    
otto, i don't follow why this isn't considered pluggable? is it considered pluggable only if it cannot be unhooked? –  helgatheviking Aug 26 '12 at 0:24
    
It is pluggable, but it's unnecessarily so. In other words, there's no need to have this extra code at all, because if somebody wants to replace it, then all they really have to do is to unhook it and hook in their own function. Simpler, easier to manage. Pluggable functions are pretty bad mojo and should generally be avoided. –  Otto Aug 26 '12 at 14:16
    
Ok, thanks. I agree mostly, but I think they're a nice feature for people who don't understand hooks and filters... excerpt they probably train people to think you can override ANY function, when you can't. queue WSOD. –  helgatheviking Aug 26 '12 at 14:40
    
Actions and filters are easy to learn and better to use. I'd stick to them, and help improve the general programming skill level. :) –  Otto Aug 26 '12 at 14:44
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.