Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I was looking to change the "Wordpress" name in all of my sent mail. In the past I have customized my Wordpress backend to display my desired email. But I have downloaded a new plugin that has altered the email name field. I went to attempt to change it again but this time in the pluggable.php template file.

However things did not go as planned now I have a fatal error:

Fatal error: Call to undefined function _fill_user() in /home/content/61/7791761/html/Portal/wp-includes/pluggable.php on line 199

I need to fix this seems as though it has something to do with the $wpdb variable

/**
 * Retrieve user info by a given field
 *
 * @since 2.8.0
 *
 * @param string $field The field to retrieve the user with.  id | slug | email | login
 * @param int|string $value A value for $field.  A user ID, slug, email address, or      login name.
 * @return bool|object False on failure, User DB row object
 */
function get_user_by($field, $value) {
global $wpdb;

switch ($field) {
    case 'id':
        return get_userdata($value);
        break;
    case 'slug':
        $user_id = wp_cache_get($value, 'userslugs');
        $field = 'user_nicename';
        break;
    case 'email':
        $user_id = wp_cache_get($value, 'useremail');
        $field = 'user_email';
        break;
    case 'login':
        $value = sanitize_user( $value );
        $user_id = wp_cache_get($value, 'userlogins');
        $field = 'user_login';
        break;
    default:
        return false;
}

 if ( false !== $user_id )
    return get_userdata($user_id);

 if ( !$user = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->users WHERE $field = %s", $value) ) )
    return false;

_fill_user( $user );

return $user;
}
endif;   
share|improve this question

2 Answers 2

Don't mess around with changing those files directly. It will break when that file gets changed in an update. Do this instead.

add_filter( 'wp_mail_from', 'override_mail_from_address' );
add_filter( 'wp_mail_from_name', 'override_mail_from_name' );

function override_mail_from_address($email_address) {
    $from_array = explode('@', $email_address);
    $from_address = $from_array[0];
    $from_domain = $from_array[1];

    if (strtolower($from_address) == 'wordpress') {
        $from_address = "myname"; /* Put the email address you want here */
    }

    return ( $from_address . '@' . $from_domain );
}

function override_mail_from_name($email_name) {
    if (strtolower($email_name) == 'wordpress') {
        $email_name = "My Name"; /* Put the name you want here */
    }

    return ( $email_name );
}
share|improve this answer
    
How does Wordpress Update? Is it a manual from the dashboard? Or is it automatically done? The reason I ask this is because I have seen in the dashboard where it ask to update. My plan was to modify Wordpress in the way I wanted to and rarely update and if I did update have all my files backed up. I am still building this concept as you can see, due to the fact I don't have the back up to the pluggable.php file lol To my understanding your solution to my problem is for me to update and use the above code in functions.php? –  Jusherb Jun 12 '13 at 21:45
1  
I see your initial reasoning, @Jusherb, but trust us, this is a shitty approach that will annoy you very soon. Never change core files. It's much more of a hassle than it will bring in convenience... –  Johannes Pille Jun 12 '13 at 22:24
    
Yes, adding the above code snippet to your theme's functions.php should work just fine. –  XIROXAS Jun 12 '13 at 23:15

If there are hooks in place that will do the job, as in @XIROXAS answer, I think that using those is the best solution, but pluggable.php contains functions that are meant to be overwritten.

If, for example, you want to alter get_user_by, which you mention in the question, just create your own function with that name in a plugin file and it will be used instead of the function from pluggable.php.

Note that :

Pluggable functions are no longer being added to WordPress core. All new functions instead use filters on their output to allow for similar overriding of their functionality.

http://codex.wordpress.org/Pluggable_Functions

I suspect that means that these will eventually be deprecated, but that is a guess and they are not currently listed as such and so should still be safe to use.

Now, I can't find _fill_user on my WordPress 3.5.1 at all. I greped the whole thing. I assume it has been removed but can't find precise information on when. The last time I see a reference to it in get_user_by is WordPRess 3.2. At any rate, that function you posted mimics the old version of get_user_by. Compare against the new version.

Whatever has added that pluggable function has added one that does not seem to be compatible with the current WordPress core. It will need to be rewritten to operate without _fill_user

If your pluggable.php itself, and looks like it may, still has that call to _fill_user something has likely gone wrong with an update somewhere and you need to reupload that file. It wouldn't hurt to reupload all of your core files just to be sure you get everything the way it should be.

share|improve this answer
    
There was a discussion on the wp-hackers mailing list as to why pluggable functions were no longer added and it was due to plugin conflicts, like if two of them both tried to override wp_mail() or something. I don't know of any plan to deprecate everything in the file. –  Andrew Bartel Jun 12 '13 at 21:51
    
@AndrewBartel What do you suggest I do to get rid of the Fatal Error? –  Jusherb Jun 12 '13 at 21:53
1  
@AndrewBartel : "pluggable" functions have always struck me as being an unstable hack, honestly. I have no doubt they are a source of numerous conflicts. That is why I made a point to say that the filter solutions are the better solutions, if there are filters that will do the job. –  s_ha_dum Jun 12 '13 at 21:53
1  
@Jusherb I would reupload a fresh copy of pluggable.php and overwrite the broken file if you're unable to find the error. You can extract it from the main download from WordPress.org. –  Andrew Bartel Jun 12 '13 at 22:10

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.