• hastibe

    (@hastibe)


    Is any example code available to programmatically implement the define( 'WPMS_DO_NOT_SEND', true ); constant from true to false when a staging URL is detected?

    I often use the Duplicator plugin to copy a site to a “staging.main-site.com” subdomain, and am looking for a way that I can have email sending automatically disabled immediately upon the site being copied over to the staging subdomain.

Viewing 1 replies (of 1 total)
  • Plugin Author Gregor Capuder

    (@capuderg)

    Hi,

    there is no way to change an already defined constant in PHP. So if possible, perform the staging URL detection and then set the correct value of the constant.

    Or you can use this WP filter hook: wp_mail_smtp_options_get_const_value. Which allows you to change the value of any plugin constant. The code you would use would look something like this:

    
    add_filter( 'wp_mail_smtp_options_get_const_value', function( $return, $group, $key, $value ) {
    	if ( true && $group === 'general' && $key === 'do_not_send' ) {
    		return false;
    	}
    
    	return $return;
    }, 10, 4 );
    

    Replace the true in the if condition with your staging URL detection.

    Have a nice day!

Viewing 1 replies (of 1 total)
  • The topic ‘Code to Disable Sending in Staging Environment’ is closed to new replies.