Opened 15 years ago
Closed 15 years ago
#18405 closed enhancement (duplicate)
Check if pluggable function was already defined by other plugin
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Priority: | normal | |
| Severity: | normal | Version: | |
| Component: | Plugins | Keywords: | |
| Focuses: | Cc: |
Description (last modified by )
Currently there's no way to check if a pluggable function is already defined by some other plugin in a normal single site WP installation.
With the current design "pluggables" are only really pluggable for your own installations. Hosting a plugin the redefines a pluggable function in the official repository will only lead to lots of problems and unsatisfied/angry users that run into non-debugable errors.
The problem is that there's no standartized way to check if the function was already defined. Imho there should be a hook to allow for save checking if the function was defined and then throw something like a
_doing_it_wrong();
-message, visible only for developers.
Sample plugin (for a multisite installation) to test and discuss this.
/*
Plugin Name: ___Pluggable Test
Plugin URI: ___
Description: ___
Author: ___
Author URI: ___
Version: 0.1
License: ___
*/
function wp_rand( $min = 0, $max = 0 )
{
return 'I am just a test';
}
function trac_test_the_hook()
{
$title = 'pluggable test output';
$msg = 'The current filter is "'.current_filter().'" and works.';
if ( function_exists( 'wp_rand' ) )
$msg .= '<br />The function <em>"wp_rand()"</em> was already defined elsewhere.';
wp_die( $msg, $title );
}
// Change the 'muplugins_loaded' to test other hooks
add_action( 'muplugins_loaded', 'trac_test_the_hook', 999 );
[1] {wp-hackers thread|https://groups.google.com/forum/?hl=de#!topic/wp-hackers/-EJbmkdMLjg]
See also: #8833 - Pluggable functions shouldn't really be needed, instead, all pluggable functions should be a filter set.