[wp-trac] [WordPress Trac] #9915: Cannot activate plugin which
override function from pluggable.php
WordPress Trac
wp-trac at lists.automattic.com
Sat May 23 08:14:54 GMT 2009
#9915: Cannot activate plugin which override function from pluggable.php
--------------------------+-------------------------------------------------
Reporter: sirzooro | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: 2.9
Component: General | Version: 2.7.1
Severity: normal | Keywords:
--------------------------+-------------------------------------------------
I have plugin which overrides some functions from pluggable.php file. It
works fine on my development server (Apache, Windows, WP 2.7.1). On
production server (Apache, Linux, WP 2.7.1) it cannot be activated - WP
reports following error:
Plugin could not be activated because it triggered a fatal error.
Fatal error: Cannot redeclare wp_new_user_notification() (previously
declared in /some/path/wp-includes/pluggable.php:1100) in /some/path/wp-
content/plugins/plugin/plugin.php on line xxx
I can workaround this by just checking if function already exists, which
will allow to activate plugin. Unfortunately this is not a good solution -
some other plugin can override this function too, so my plugin may stop
working if it will be loaded after that one. I can add additional code to
validate if functions are overridden - this can be checked in init hook,
which is not called while plugin is installed.
All of this is a bit complicated (preferred solution is to provide
override functions only). Therefore I suggest to add new functions which
will allow to register replacement functions like hooks now. See example
code:
{{{
if ( !function_exists( 'some_function' ) ) :
function some_function( $param ) {
call_replacement_function( 'some_function', '_some_function',
$param );
}
endif;
function _some_function( $param ) {
}
}}}
Plugin code:
{{{
register_replacement_function( 'some_function', 'new_fun' );
function new_fun( $param ) {}
}}}
register_replacement_function() function should check if another
replacement function is already registered and report error if there is
one.
--
Ticket URL: <http://core.trac.wordpress.org/ticket/9915>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list