Disable password change email to user, send via another mailing service - php

I'm looking to disable the standard "You have reset your password" email in Wordpress for a user.
Is it possible to expand on that? I'm pretty sure the following disables the email:
/**
* Disable User Notification of Password Change Confirmation
*/
add_filter( 'send_password_change_email', '__return_false' );
Could I combine that with something else when that fires?
Essentially I want to use another mailing service to send the email using the following:
$this->sendinblue_send_template($customer_email, 6);
So how can I combine the two and use my snippet of code when the password change email fires?

I suggest you to build an plugin, this is the code to build an plugin that you need
and you can using this filter like this:
// define the send_password_change_email callback
function filter_send_password_change_email( $send, $user, $userdata ) {
$send = false;
// write the code if you want to send to other email provider
return $send;
};
// add the filter
add_filter( 'send_password_change_email', 'filter_send_password_change_email', 10, 3 );

Related

add recipients to "Customer invoice / Order details" in Woocommerce emails

In Woocommerce, there is already a built-in way to add recipients to the "New Order" , "Failed", and "Cancelled" emails, but for some reason, the "Customer invoice / Order details" don't allow any recipient other than the customer.
There is a simple plugin that allows for that, but it is very limited in features.
Any guidance for how to add recipients to this email?
I plan to use a Code Snippet to call the hook/filter/action and then tell it explicitly which email addresses to use. I intend to write the script so that whatever user initiates the action, will be CC'ed on that email. Presumably the same function that can do the first part of my question can help me to check current user and will grab their email address.
Any help is appreciated
I don't know what buil-in functionality are you talking about. But you can use the below filter to add recipients to the invoice email. You don't need any plugin, just use this below code snippet in your active theme/child theme functions.php
add_filter("woocommerce_email_recipient_customer_invoice", "add_recipient_to_email", 10, 2);
function add_recipient_to_email( $recipients, $object ){
$new_email = "newemail#domain.com"; //New email Id
$recipients = $recipients.','.$new_email;
return $recipients;
}

Is it possible to disable the change of password email and send one via another system?

I'd like to disable the standard Wordpress changed password (to the user) and send an email via a different system (in this case Send In Blue).
I've had a look around and found that this disables the email
add_filter( 'send_password_change_email', '__return_false' );
This is my code to send a particular template from Send in Blue:
$master->sendinblue_send_template($user_info->user_email, 34);
How can I combine the two? So when a user resets their password, the Send in Blue template is sent to them instead.
You can write a custom function and then call that function in your filter.
function send_custom_mail ()
{
$res = sendinblue_send_template($user_info->user_email, 34);
return false;
}
add_filter( 'send_password_change_email', 'send_custom_mail ');

Using Advanced Custom Field value as "Email to" in Contact Form 7

I'm creating a page in which you submit a Contact Form 7 to the email based on what email is added to the job_email field via my Advanced Custom Fields.
I have attempted to add the form via the PHP shortcode like this
[email* dynamic-email class:email-address placeholder "Email Address*"]
echo do_shortcode('[contact-form-7 id="234" title="Dynamic Submit CV" dynamic-email="'.get_field( 'job_email' ).'"]' );
The fields all display correctly, and upon submitting the email successfully, the email never receives the form. Meaning I am totally missing something here.
If I understand correctly, what you are after is send a notification with the entry details to the email address inputted on the job_email field.
If so, what you want to do is to set up an email on the email tab and in the To: setting put [job_email].
Update
As you stated in the comment, the email has to be the one set in the backend. You can guarantee the email notification to be sent to the ACF-based email via hooks, specifically the wpcf7_mail_components hook.
function so57013385_mail_components( $components, $number ) {
$job_mail = get_field( ... );
$components['recipient'] = (array) $components['recipient'];
$components['recipient'][] = $job_mail;
return $components;
};
add_filter( 'wpcf7_mail_components', 'so57013385_mail_components', 10, 2 );
Note: I'm casting the $components['recipient'] variable to array just to make sure the email is appended correctly, as this parameter is passed directly to wp_mail(), which can receive a string or an array. Also, you might need to add more validations on the form ID, sanitization, etc. The above code is not tested.

wp_mail use WordPress's default email template for sending email

Is there any way to send email from WordPress using the default template that WordPress uses for sending emails (on registration, password reset etc).
I'm using wp_mail function for sending email, but how to include the template in the message with custom contents.
Thanks
Try using this tutorial: https://www.wpbeginner.com/plugins/how-to-change-sender-name-in-outgoing-wordpress-email/
You will need to add the following code in your theme’s functions.php file or a site-specific plugin.
// Function to change email address
function wpb_sender_email( $original_email_address ) {
return 'tim.smith#example.com';
}
// Function to change sender name
function wpb_sender_name( $original_email_from ) {
return 'Tim Smith';
}
// Hooking up our functions to WordPress filters
add_filter( 'wp_mail_from', 'wpb_sender_email' );
add_filter( 'wp_mail_from_name', 'wpb_sender_name' );
This code simply replaces the default WordPress sender name and email address with your custom sender name and email address.

How to change main admin email address in WordPress without notification and confirmation processes

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.
How I do that? Could you please help me? Is there any code for this?
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
There are few ways to change admin email without using a 3rd party plugin.
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.
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.
UPDATE wp_options SET option_value = 'admin#example.com' 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.php for $table_prefix value.
Updating via 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.
See more about max_input_vars
https://www.php.net/manual/en/info.configuration.php
Updating via functions.php in active theme:
You could set one time code (and delete it after) in functions.php of your active theme to update these options:
update_option( 'admin_email', 'admin#example.com' );
and
update_option( 'new_admin_email', 'admin#example.com' );
Put these within some admin_init action callback.
Updating via wp-cli:
Another way to update Admin email is via wp-cli ( if you have access to terminal ssh):
wp option update admin_email 'admin#example.com'
and
wp option update new_admin_email 'admin#example.com'
see more about wp option commands:
https://developer.wordpress.org/cli/commands/option/update/
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
Or with the given update query:
UPDATE `wp_options` SET `option_value` = 'new#email.com' WHERE `option_name` = 'admin_email';
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";
Check This too
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.
UPDATE `wp_sitemeta` SET `meta_value` = 'the_new_email#abc.com' WHERE `meta_value` = 'the_old_email#abc.com';
Note: please use the table prefix accordingly used in db if it is not wp in your case.
Easier to use phpMyAdmin
wp_options > admin_email
You have to enter mysql server
and run the following query
UPDATE `wp_options` SET `option_value` = 'mail#email.com' WHERE `option_id` = 6;
Run this query, This will change the email id without any confirmation
UPDATE `wp_users` SET `user_email` = 'newemail' WHERE `user_email` = 'old_email';
I had the same problem so I wrote a plugin to rollback the confirmation link feature. You can download it on the .org repo:
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;
}
}
You can disable the email confirmation by just adding the following code in your theme 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 );
Just adding to some of the other answers that there might not be a 'new_admin_email' row in the options table.
The 'new_admin_email' value only gets set after you attempt to change the original admin email via the normal settings page (/wp-admin/options-general.php). And it will be deleted if you cancel the pending change.

Categories