Ok I am trying to modify some code in a WP Plugin. The plugin declares a file for this:

// overwrite hooks 
$plugin_dir = trailingslashit(dirname(dirname(__FILE__)));
if(file_exists($plugin_dir . "auto_overwrite.php")){
include_once($plugin_dir . "auto_overwrite.php");
}

So I created a file in the above directory called auto_overwrite.php and included the function I wanted to change.

The problem I am having is that I still get the error:

Fatal error: Cannot redeclare listing_tabs() (previously declared in....

I thought the idea of include_once was that is would not include functions that are already defined.

The other function is in a file named meta_boxes.php and it too is called via

include_once("meta_boxes.php");

I am relatively new to PHP so maybe I'm missing something, any help is greatly appreciated. Thanks!

EDIT: From answers below I see that I cant just call out the function as include_once only limits that specific file from being loaded more than once. Basically I am trying to modify a function specified downstream from this file. Is it possible to do this?

1

There are 1 best solutions below

0
On

You can check if a function has been defined, and if not act accordingly like this...

 if (!function_exists('listing_tabs')){
    // include file with function
 }