恐怕你得用pluggable functions feature - 这些函数中没有过滤器或挂钩(如下面的代码所示)。更糟糕的是,对您来说,最好使用可插入功能in a plugin.
这是因为在主题函数中定义了新的可插入函数。php要求您在函数中使用新函数的定义(以便在所有插件完全加载后立即调用),这可能不好(请参阅本文下面的注释),但另一方面,它可以工作-请参阅第一个插件下面的代码。
对于那些不反对插件的人,这里有一个重写可插入函数的方法——只需将其保存到my\\u插件中即可。php(或任何其他)到插件目录,并从管理员处激活:
<?php
/*
Plugin Name: Name Of The Plugin
Plugin URI: http://URI_Of_Page_Describing_Plugin_and_Updates
Description: A brief description of the Plugin.
Version: The Plugin\'s Version Number, e.g.: 1.0
Author: Name Of The Plugin Author
Author URI: http://URI_Of_The_Plugin_Author
License: A "Slug" license name e.g. GPL2
*/
if( !function_exists(\'new_user_notification\') ){
function new_user_notifiaction(){
/**
* Notify the blog admin of a new user, normally via email.
*
* @since 2.0
*
* @param int $user_id User ID
* @param string $plaintext_pass Optional. The user\'s plaintext password
*/
function wp_new_user_notification($user_id, $plaintext_pass = \'\') {
$user = get_userdata( $user_id );
$user_login = stripslashes($user->user_login);
$user_email = stripslashes($user->user_email);
// The blogname option is escaped with esc_html on the way into the database in sanitize_option
// we want to reverse this for the plain text arena of emails.
$blogname = wp_specialchars_decode(get_option(\'blogname\'), ENT_QUOTES);
$message = sprintf(__(\'New user registration on your site %s:\'), $blogname) . "\\r\\n\\r\\n";
$message .= sprintf(__(\'Username: %s\'), $user_login) . "\\r\\n\\r\\n";
$message .= sprintf(__(\'E-mail: %s\'), $user_email) . "\\r\\n";
@wp_mail(get_option(\'admin_email\'), sprintf(__(\'[%s] New User Registration\'), $blogname), $message);
if ( empty($plaintext_pass) )
return;
$message = sprintf(__(\'Username: %s\'), $user_login) . "\\r\\n";
$message .= sprintf(__(\'Password: %s\'), $plaintext_pass) . "\\r\\n";
$message .= wp_login_url() . "\\r\\n";
wp_mail($user_email, sprintf(__(\'[%s] Your username and password\'), $blogname), $message);
}
}
}
如果你好奇的话,这里有一个函数管理的相同效果。php,在另一个函数中定义了一个新函数:
//redefine wp_new_user_notification as soon as all plugins are loaded
add_action( \'plugins_loaded\', \'new_user_notifiaction\' );
function new_user_notifiaction(){
/**
* Notify the blog admin of a new user, normally via email.
*
* @since 2.0
*
* @param int $user_id User ID
* @param string $plaintext_pass Optional. The user\'s plaintext password
*/
function wp_new_user_notification($user_id, $plaintext_pass = \'\') {
$user = get_userdata( $user_id );
$user_login = stripslashes($user->user_login);
$user_email = stripslashes($user->user_email);
// The blogname option is escaped with esc_html on the way into the database in sanitize_option
// we want to reverse this for the plain text arena of emails.
$blogname = wp_specialchars_decode(get_option(\'blogname\'), ENT_QUOTES);
$message = sprintf(__(\'New user registration on your site %s:\'), $blogname) . "\\r\\n\\r\\n";
$message .= sprintf(__(\'Username: %s\'), $user_login) . "\\r\\n\\r\\n";
$message .= sprintf(__(\'E-mail: %s\'), $user_email) . "\\r\\n";
@wp_mail(get_option(\'admin_email\'), sprintf(__(\'[%s] New User Registration\'), $blogname), $message);
if ( empty($plaintext_pass) )
return;
$message = sprintf(__(\'Username: %s\'), $user_login) . "\\r\\n";
$message .= sprintf(__(\'Password: %s\'), $plaintext_pass) . "\\r\\n";
$message .= wp_login_url() . "\\r\\n";
wp_mail($user_email, sprintf(__(\'[%s] Your username and password\'), $blogname), $message);
}
}