• Resolved wekhter

    (@wekhter)


    I had the following code active on my site as a plugin:

    if ( !function_exists( 'wp_password_change_notification' ) ) {
     function wp_password_change_notification() {}
    }

    (this code prevents the admin from getting email notifications when users change their passwords)

    I moved this code from the plugin to a Code Snippet and the admin received a password change notification a few minutes later. Can Code Snippets not modify pluggable functions?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter wekhter

    (@wekhter)

    I know it’s been several weeks but I’m still wondering about this

    Plugin Author Shea Bunge

    (@bungeshea)

    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.

    Plugin Author Shea Bunge

    (@bungeshea)

    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 8 years, 3 months ago by Shea Bunge. Reason: minor formatting fix
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Pluggable functions?’ is closed to new replies.