update_option_new_admin_email()修改新的邮件地址

目录

描述

This function intercepts changes to the administrator's email address. It keeps the address from being updated and instead sends the user a confirmation email, with a link to confirm the change.

update_option_new_admin_email() 描述

用法

<?php update_option_new_admin_email$old_value$value ); ?>

Note: This function is not intended to be called directly! See below.

update_option_new_admin_email() 用法

参数

$old_value

(string) (必填) The administrator's old email address.

默认值: None

$value

(string) (必填) The new email address.

默认值: None

update_option_new_admin_email() 参数

示例

This function is hooked to the 'update_option_new_admin_email' and 'add_option_new_admin_email' actions by default. If for some reason you would like to disable it and allow administrators to change their email address without confirmation, you can do this:

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */

<?php

remove_action( 'add_option_new_admin_email', 'update_option_new_admin_email' );
remove_action( 'update_option_new_admin_email', 'update_option_new_admin_email' );

/**
 * Disable the confirmation notices when an administrator
 * changes their email address.
 *
 * @see http://codex.wordpress.com/Function_Reference/update_option_new_admin_email
 */
function wpdocs_update_option_new_admin_email( $old_value, $value ) {

    update_option( 'admin_email', $value );
}
add_action( 'add_option_new_admin_email', 'wpdocs_update_option_new_admin_email', 10, 2 );
add_action( 'update_option_new_admin_email', 'wpdocs_update_option_new_admin_email', 10, 2 );

?>

update_option_new_admin_email() 示例

注意

update_option_new_admin_email() 注意

历史

添加于 版本: 3.0.0

update_option_new_admin_email() 历史

源文件

update_option_new_admin_email() 函数的代码位于 wp-admin/includes/ms.php.

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * Sends an email when a site administrator email address is changed.
 *
 * @since 3.0.0
 *
 * @param string $old_value The old email address. Not currently used.
 * @param string $value     The new email address.
 */
function update_option_new_admin_email( $old_value, $value ) {
	if ( $value == get_option( 'admin_email' ) || !is_email( $value ) )
		return;

	$hash = md5( $value. time() .mt_rand() );
	$new_admin_email = array(
		'hash' => $hash,
		'newemail' => $value
	);
	update_option( 'adminhash', $new_admin_email );

	/* translators: Do not translate USERNAME, ADMIN_URL, EMAIL, SITENAME, SITEURL: those are placeholders. */
	$email_text = __( 'Howdy ###USERNAME###,

You recently requested to have the administration email address on
your site changed.

If this is correct, please click on the following link to change it:
###ADMIN_URL###

You can safely ignore and delete this email if you do not want to
take this action.

This email has been sent to ###EMAIL###

Regards,
All at ###SITENAME###
###SITEURL###' );

	/**
	 * Filter the email text sent when the site admin email is changed.
	 *
	 * The following strings have a special meaning and will get replaced dynamically:
	 * ###USERNAME###  The current user's username.
	 * ###ADMIN_URL### The link to click on to confirm the email change.
	 * ###EMAIL###     The new email.
	 * ###SITENAME###  The name of the site.
	 * ###SITEURL###   The URL to the site.
	 *
	 * @since MU
	 *
	 * @param string $email_text      Text in the email.
	 * @param string $new_admin_email New admin email that the current administration email was changed to.
	 */
	$content = apply_filters( 'new_admin_email_content', $email_text, $new_admin_email );

	$current_user = wp_get_current_user();
	$content = str_replace( '###USERNAME###', $current_user->user_login, $content );
	$content = str_replace( '###ADMIN_URL###', esc_url( admin_url( 'options.php?adminhash='.$hash ) ), $content );
	$content = str_replace( '###EMAIL###', $value, $content );
	$content = str_replace( '###SITENAME###', get_site_option( 'site_name' ), $content );
	$content = str_replace( '###SITEURL###', network_home_url(), $content );

	wp_mail( $value, sprintf( __( '[%s] New Admin Email Address' ), wp_specialchars_decode( get_option( 'blogname' ) ) ), $content );
}

update_option_new_admin_email() 源文件