php 如何在没有通知和确认过程的情况下更改 WordPress 中的主要管理员电子邮件地址
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/48201505/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to change main admin email address in WordPress without notification and confirmation processes
提问by developerme
I have created one site in staging server I want to change admin email address for that staging site. Because I want to test something on staging site at that time, and I want that no email is being sent to client (original admin email), I want to change main admin email.
我在登台服务器中创建了一个站点,我想更改该登台站点的管理员电子邮件地址。因为当时我想在临时站点上测试一些东西,并且我希望没有电子邮件被发送到客户端(原始管理员电子邮件),所以我想更改主管理员电子邮件。
But when I change admin email I get confirmation link on to my new admin email address.
但是当我更改管理员电子邮件时,我会收到指向我的新管理员电子邮件地址的确认链接。
The Admin email address won't change until I click on the link in the confirmation email.
在我单击确认电子邮件中的链接之前,管理员电子邮件地址不会更改。
After I click on the confirmation link, the original admin is receiving notice of Admin Email Change.
在我点击确认链接后,原来的管理员收到了管理员邮箱变更的通知。
I want to disable notice of Admin Email Change and also new Admin Email Address confirmation link in WordPress.
我想在 WordPress 中禁用管理员电子邮件更改通知以及新的管理员电子邮件地址确认链接。
How I do that? Could you please help me? Is there any code for this?
我怎么做?请你帮助我好吗?有没有这方面的代码?
回答by valerio
There is a 'secret' settings page which lets you change all of the settings in the options table.
有一个“秘密”设置页面,可让您更改选项表中的所有设置。
Access it by changing the URL from /options-general.php to /options.php
通过将 URL 从 /options-general.php 更改为 /options.php 来访问它
回答by Mladen Janjetovic
The one that you are trying to replace is actually the email in Wordpress settings, not the wp user email. That one can be changed directly in database in the table wp_options
where option_name
is admin_email
您尝试替换的实际上是 Wordpress 设置中的电子邮件,而不是 wp 用户电子邮件。这一个可以直接在数据库表中的变化wp_options
,其中option_name
的admin_email
Or with the given update query:
或者使用给定的更新查询:
UPDATE `wp_options` SET `option_value` = '[email protected]' WHERE `option_name` = 'admin_email';
回答by Nikola Kirincic
There are few ways to change admin email without using a 3rd party plugin.
在不使用 3rd 方插件的情况下,更改管理员电子邮件的方法很少。
Also, besides admin_email, there is another value that needs to be changed.
No matter that you change admin_email
value in DB, a confirmation notice will remain,
unless you change new_admin_email
too.
此外,除了 admin_email 之外,还有一个值需要更改。无论您更改admin_email
DB 中的值,都会保留确认通知,除非您也更改new_admin_email
。
Updating via the database:
通过数据库更新:
In case of updating option via DB directly, there are two options that need to be changed: admin_email
and new_admin_email
.
如果直接通过 DB 更新选项,则需要更改两个选项:admin_email
和new_admin_email
。
UPDATE wp_options SET option_value = '[email protected]' WHERE
option_name LIKE 'admin_email'
OR
option_name LIKE 'new_admin_email';
note:While by default every WordPress database has wp_
prefix for its tables, they can be changed, so check in wp-config.phpfor $table_prefix
value.
注意:虽然默认情况下每个 WordPress 数据库都有wp_
其表的前缀,但它们可以更改,因此请检查wp-config.php以获取$table_prefix
值。
Updating via options.php:
通过 options.php 更新:
Another way without the use of some plugin is as mentioned accessing secret page /wp-admin/options.php
. However, there might be too many options, and due to a number of $_POST
variables limit set for each server differently, having it quite impossible to change it that way.
另一种不使用某些插件的方法是如上所述访问 secret page /wp-admin/options.php
。但是,可能有太多选项,并且由于$_POST
为每个服务器设置的许多变量限制不同,因此很难以这种方式对其进行更改。
See more about max_input_vars
https://www.php.net/manual/en/info.configuration.php
查看更多关于max_input_vars
https://www.php.net/manual/en/info.configuration.php
Updating via functions.php in active theme:
在活动主题中通过 functions.php 更新:
You could set one time code (and delete it after) in functions.phpof your active theme to update these options:
您可以在活动主题的functions.php中设置一个时间码(并在之后删除)以更新这些选项:
update_option( 'admin_email', '[email protected]' );
and
和
update_option( 'new_admin_email', '[email protected]' );
Put these within some admin_init
action callback.
将这些放在一些admin_init
动作回调中。
Updating via wp-cli:
通过 wp-cli 更新:
Another way to update Admin email is via wp-cli ( if you have access to terminal ssh):
更新管理员电子邮件的另一种方法是通过 wp-cli(如果您有权访问终端 ssh):
wp option update admin_email '[email protected]'
and
和
wp option update new_admin_email '[email protected]'
see more about wp option commands:
查看更多关于 wp 选项命令:
回答by Abdulla Nilam
Note: Get dump and try it on local first. Don't test in production.
注意:获取转储并首先在本地尝试。不要在生产中测试。
Change with DB
用数据库改变
//email
UPDATE `wp_users` SET `user_email` = "new_email_address" WHERE `wp_users`.`user_login` = "admin";
//password
UPDATE `wp_users` SET `user_pass` = MD5('new_password_here') WHERE `wp_users`.`user_login` = "admin";
回答by Eric Caudle
Easier to use phpMyAdmin
更容易使用 phpMyAdmin
wp_options > admin_email
wp_options > admin_email
回答by sese smith
You have to enter mysql server
你必须进入mysql服务器
and run the following query
并运行以下查询
UPDATE `wp_options` SET `option_value` = '[email protected]' WHERE `option_id` = 6;
回答by ajaz
The network admin email is changed from wp_sitemeta table. Use following query in phpmyadmin or any mysql client in order to update the email if you are unable to change from network admin settings.
网络管理员电子邮件从 wp_sitemeta 表更改。如果您无法从网络管理设置进行更改,请在 phpmyadmin 或任何 mysql 客户端中使用以下查询来更新电子邮件。
UPDATE `wp_sitemeta` SET `meta_value` = '[email protected]' WHERE `meta_value` = '[email protected]';
Note: please use the table prefix accordingly used in db if it is not wp in your case.
注意:如果在您的情况下不是 wp,请相应地使用 db 中使用的表前缀。
回答by Rajnikant Das
You can disable the email confirmation by just adding the following code in your theme function.php
您可以通过在主题 function.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 );
回答by John Dee
I had the same problem so I wrote a plugin to rollback the confirmation link feature. You can download it on the .org repo:
我遇到了同样的问题,所以我写了一个插件来回滚确认链接功能。您可以在 .org 存储库上下载它:
Change Admin Email Setting Without Outbound Email
Here is the code:
这是代码:
<?php
/*
Plugin Name: Change Admin Email Setting Without Outbound Email
Plugin URI: https://wp-bdd.com/change-admin-email/
Description: Restores functionality removed since WordPress 4.9. Allows the changing of the admin email by admins in single site without outbound email or recipient email credentials.
Version: 1.0
Author: John Dee
Author URI: https://wp-bdd.com/
*/
$ChangeAdminEmailPlugin = new ChangeAdminEmailPlugin;
class ChangeAdminEmailPlugin{
public function __construct(){
//This plugin doesn't do anything unless it's WordPres version +4.9 and single site
if($this->isWordPressMinimiumVersion("4.9.0") && (!( is_multisite()))){
//pulls the default actions
remove_action( 'add_option_new_admin_email', 'update_option_new_admin_email' );
remove_action( 'update_option_new_admin_email', 'update_option_new_admin_email' );
//When you actually complete the change, another email gets fired to the old address
//this filter overides this:
add_filter('send_site_admin_email_change_email', function(){return FALSE;}, 10, 3 );
//hooks our own custom method to update the email
add_action( 'add_option_new_admin_email', array($this, 'updateOptionAdminEmail'), 10, 2 );
add_action( 'update_option_new_admin_email', array($this, 'updateOptionAdminEmail'), 10, 2 );
//this fixes the text in English. Translators wanted for other languages.
add_action('wp_after_admin_bar_render', array($this, 'modifyOptionsGeneralPHPForm'));
}
}
public function updateOptionAdminEmail( $old_value, $value ) {
update_option( 'admin_email', $value );
}
public function isWordPressMinimiumVersion($version){
global $wp_version;
if (version_compare($wp_version, $version, ">=")) {
return TRUE;
} else {
return FALSE;
}
}
//Changes the form on admin area options-general.php. Doesn't do anything unless on this page.
public function modifyOptionsGeneralPHPForm(){
$screen = get_current_screen();
if($screen->base == "options-general"){
add_filter( 'gettext', array($this, 'filterText'), 10, 3 );
}
}
//Changes the English text of WP core. Inspired by https://wordpress.stackexchange.com/questions/188332/override-default-wordpress-core-translation
public function filterText( $translated, $original, $domain ) {
if ( $translated == "This address is used for admin purposes. If you change this we will send you an email at your new address to confirm it. <strong>The new address will not become active until confirmed.</strong>"){
$translated = __("This address is used for admin purposes.");
}
return $translated;
}
}
回答by Thamaraiselvam
Run this query, This will change the email id without any confirmation
运行此查询,这将在没有任何确认的情况下更改电子邮件 ID
UPDATE `wp_users` SET `user_email` = 'newemail' WHERE `user_email` = 'old_email';