Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP - override existing function [duplicate]

Can I redeclare a existing function, with the same name, but different code? Or somehow "disable" the old function?

I want to redefince a core WordPress function, but since plugins and theme call this function a lot, I need to keep the same function name.

like image 510
Alex Avatar asked Jan 18 '11 14:01

Alex


1 Answers

You could use the WordPress hooks (called filters and actions) and then use the add_filter() function to override the function you are using.

i.e.

function function_name() {
 //code goes here
}

$hook = 'get_options'; // the function name you're filtering
add_filter( $hook, 'function_name' );

The Codex will help a lot with this.

http://codex.wordpress.org/Plugin_API/Filter_Reference

like image 107
rachael Avatar answered Nov 15 '22 22:11

rachael