WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 4 years ago

#18405 closed enhancement (duplicate)

Check if pluggable function was already defined by other plugin

Reported by: F J Kaiser Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Plugins Keywords:
Focuses: Cc:

Description (last modified by dd32)

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]

Change History (3)

comment:1 @dd324 years ago

  • Description modified (diff)

See also: #8833 - Pluggable functions shouldn't really be needed, instead, all pluggable functions should be a filter set.

comment:2 @scribu4 years ago

Pluggable functions suck, for this and other reasons.

Closing as duplicate of #8833 since I don't see another way to handle this - with or without a _doing_it_wrong() call.

comment:3 @scribu4 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.