I know it’s been several weeks but I’m still wondering about this
Sorry, I have been meaning to have a look at this, but I have yet to figure out a solution. It’s possible that snippets are running after pluggable.php is loaded, and so the function is already defined before the snippet has a chance to redefine it. It may also be an issue with how I’m getting PHP to execute the snippet code. I’ll keep searching for a fix and let you know what I figure out.
Okay, so I now know what’s causing this issue. Basically, there’s nothing preventing you overriding pluggable functions with snippets. The issue is that the functions in wp-includes/pluggable.php are loaded before any of the snippets are loaded, so they have already been defined before you have a chance to define them.
For an example, trying to redefine the get_avatar() function like so will not work, as it will have already been defined before the snippet is evaluated:
if ( ! function_exists( 'get_avatar ) ) {
function get_avatar( $id_or_email, $size = '96', $default = '', $alt = false ) {
return '🙂';
}
}
But redefining a pluggable function which is defined after plugins and snippets have loaded, such as one from Twenty Sixteen, will work perfectly fine:
if ( ! function_exists( 'twentysixteen_entry_meta' ) ) {
function twentysixteen_entry_meta() {
echo 'overrides entry meta';
}
}
Unfortunately, I don’t think there’s much I can do to allow overriding built-in pluggable functions at this stage, but hopefully I will soon be able to restructure the snippet evaluation system to be more flexible and allow snippets to run earlier in the load process.
-
This reply was modified 9 years, 6 months ago by
Shea Bunge. Reason: minor formatting fix