Changeset 2696275
- Timestamp:
- 03/18/2022 10:01:41 PM (4 years ago)
- Location:
- redirect-emails-on-staging
- Files:
-
- 44 added
- 2 deleted
- 4 edited
- 1 copied
-
tags/1.2.0 (copied) (copied from redirect-emails-on-staging/trunk)
-
tags/1.2.0/README.txt (modified) (2 diffs)
-
tags/1.2.0/changelog.txt (added)
-
tags/1.2.0/classes (deleted)
-
tags/1.2.0/composer.json (added)
-
tags/1.2.0/composer.lock (added)
-
tags/1.2.0/languages (added)
-
tags/1.2.0/languages/.gitignore (added)
-
tags/1.2.0/languages/redirect-emails-on-staging.pot (added)
-
tags/1.2.0/package-lock.json (added)
-
tags/1.2.0/package.json (added)
-
tags/1.2.0/phpcs.xml.dist (added)
-
tags/1.2.0/redirect-emails-on-staging.php (modified) (2 diffs)
-
tags/1.2.0/vendor (added)
-
tags/1.2.0/vendor/autoload.php (added)
-
tags/1.2.0/vendor/composer (added)
-
tags/1.2.0/vendor/composer/ClassLoader.php (added)
-
tags/1.2.0/vendor/composer/InstalledVersions.php (added)
-
tags/1.2.0/vendor/composer/LICENSE (added)
-
tags/1.2.0/vendor/composer/autoload_classmap.php (added)
-
tags/1.2.0/vendor/composer/autoload_namespaces.php (added)
-
tags/1.2.0/vendor/composer/autoload_psr4.php (added)
-
tags/1.2.0/vendor/composer/autoload_real.php (added)
-
tags/1.2.0/vendor/composer/autoload_static.php (added)
-
tags/1.2.0/vendor/composer/installed.json (added)
-
tags/1.2.0/vendor/composer/installed.php (added)
-
trunk/README.txt (modified) (2 diffs)
-
trunk/changelog.txt (added)
-
trunk/classes (deleted)
-
trunk/composer.json (added)
-
trunk/composer.lock (added)
-
trunk/languages (added)
-
trunk/languages/.gitignore (added)
-
trunk/languages/redirect-emails-on-staging.pot (added)
-
trunk/package-lock.json (added)
-
trunk/package.json (added)
-
trunk/phpcs.xml.dist (added)
-
trunk/redirect-emails-on-staging.php (modified) (2 diffs)
-
trunk/vendor (added)
-
trunk/vendor/autoload.php (added)
-
trunk/vendor/composer (added)
-
trunk/vendor/composer/ClassLoader.php (added)
-
trunk/vendor/composer/InstalledVersions.php (added)
-
trunk/vendor/composer/LICENSE (added)
-
trunk/vendor/composer/autoload_classmap.php (added)
-
trunk/vendor/composer/autoload_namespaces.php (added)
-
trunk/vendor/composer/autoload_psr4.php (added)
-
trunk/vendor/composer/autoload_real.php (added)
-
trunk/vendor/composer/autoload_static.php (added)
-
trunk/vendor/composer/installed.json (added)
-
trunk/vendor/composer/installed.php (added)
Legend:
- Unmodified
- Added
- Removed
-
redirect-emails-on-staging/tags/1.2.0/README.txt
r871476 r2696275 3 3 Tags: email, wpengine 4 4 Requires at least: 3.5.2 5 Tested up to: 3.8.1 6 Stable Tag: 1.1 5 Tested up to: 5.9 6 Requires PHP: 5.3.2 7 Stable tag: 1.2.0 7 8 License: GPL2 8 9 … … 43 44 == Screenshots == 44 45 45 ( none yet)46 (Not applicable to this plugin) 46 47 47 48 == Changelog == 48 49 49 = 1.1 = 50 = 1.2.0 - 2022-03-18 = 51 * Add - Native wp_get_environment_type() support. 52 * Add - Support for checking with Jetpack for staging. 53 * Add - Support for modifying CC and BCC lists in emails. 54 * Dev - Add separate changelog file. 55 * Dev - add automated build process. 56 * Tweak - WP 5.9 compatibility. 57 58 = 1.1.0 = 50 59 * Under-the-hood change: use a class for the main plugin functionality 51 60 * Check PHP version with an activation hook 52 61 * Update the "Tested up to" tag 53 62 54 = 1.0 =63 = 1.0.0 = 55 64 * Created the plugin 56 65 -
redirect-emails-on-staging/tags/1.2.0/redirect-emails-on-staging.php
r871476 r2696275 1 1 <?php 2 2 /** 3 * Plugin Name: Redirect Emails on Staging 4 * Plugin URI: http://wordpress.org/plugins/redirect-emails-on-staging/ 5 * Description: (For WP Engine only) On the Staging site, redirect all emails to the site admin. This is useful in making sure that the staging site doesn't send out confusing emails to your users. 6 * Version: 1.1 7 * Author: Jeremy Pry 8 * Author URI: http://jeremypry.com/ 9 * License: GPL2 3 * Plugin Name: Redirect Emails on Staging 4 * Plugin URI: http://wordpress.org/plugins/redirect-emails-on-staging/ 5 * Description: On a Staging site, redirect all emails to the site admin. This is useful in making sure that the staging site doesn't send out confusing emails to your users. 6 * Version: 1.2.0 7 * Author: Jeremy Pry 8 * Author URI: https://jeremypry.com/ 9 * License: GPL2 10 * Requires at least: 5.5.0 11 * Tested up to: 5.9 12 * Requires PHP: 5.3.2 13 * Text Domain: redirect-emails-on-staging 10 14 */ 15 16 use Automattic\Jetpack\Status; 11 17 12 18 // Prevent direct access to this file … … 15 21 } 16 22 17 // Activation check 18 register_activation_hook( plugin_basename( __FILE__ ), 'jpry_res_activation_check' ); 23 define( 'JPRY_REDIRECT_EMAILS_ON_STAGING_VERSION', '1.2.0' ); // WRCS: DEFINED_VERSION. 19 24 20 /** 21 * Check to ensure the plugin is able to run 22 * 23 * We're specifically looking to make sure there is a PHP version of 5.3.2 or greater 24 * 25 * @since 1.1 26 */ 27 function jpry_res_activation_check() { 28 $min_php_version = '5.3.2'; 29 $installed_php_version = phpversion(); 25 add_filter( 26 'wp_mail', 27 function( $args ) { 28 // Jetpack is the most comprehensive, so use that if available. 29 if ( class_exists( Status::class ) && method_exists( Status::class, 'is_staging_site' ) ) { 30 $is_staging = ( new Status() )->is_staging_site(); 31 } else { 32 // Check WP environment. 33 $wp_staging = function_exists( 'wp_get_environment_type' ) && 'staging' === wp_get_environment_type(); 30 34 31 if ( version_compare( $min_php_version, $installed_php_version, '>' ) ) { 32 deactivate_plugins( plugin_basename( __FILE__ ) ); 33 wp_die( sprintf( "This plugin requires a minimum PHP version of %s. You only have version %s installed. Please upgrade PHP to use this plugin.", $min_php_version, $installed_php_version ) ); 34 } 35 } 35 // Check on WP Engine hosting (the original purpose of this plugin). 36 $wpe_staging = function_exists( 'is_wpe_snapshot' ) && is_wpe_snapshot(); 36 37 37 // Some constants 38 define( 'RES_FILE', __FILE__ ); 39 define( 'RES_DIR', dirname( RES_FILE ) ); 38 $is_staging = $wp_staging || $wpe_staging; 39 } 40 40 41 // Pull in the class files 42 require_once( RES_DIR . "/classes/class-jpry_singleton.php" ); 43 require_once( RES_DIR . "/classes/class-jpry_redirect_staging_email.php" ); 41 // Bail if we're not in a staging situation. 42 if ( ! $is_staging ) { 43 return $args; 44 } 44 45 45 // Instantiate the class 46 JPry_Redirect_Staging_Email::get_instance(); 46 /** 47 * Filter jpry_redirect_staging_emails_email. 48 * 49 * @since 1.2.0 50 * 51 * @var string $email The email address where all emails generated by the site should be sent. 52 */ 53 $email = apply_filters( 'jpry_redirect_staging_emails_email', get_site_option( 'admin_email' ) ); 54 55 // If the email is already to the admin, then no need to modify anything. 56 if ( $email === $args['to'] ) { 57 return $args; 58 } 59 60 // We've established that we need to modify the email arguments, so let's do so. 61 $args['message'] = sprintf( 62 /* translators: 1: original email address, 2: the original message */ 63 esc_html__( "Originally sent to: %1\$s\n\n%2\$s", 'redirect-emails-on-staging' ), 64 $args['to'], 65 $args['message'] 66 ); 67 68 $args['subject'] = sprintf( 69 /* translators: %s is the original email subject */ 70 esc_html__( 'REDIRECTED EMAIL | %s', 'redirect-emails-on-staging' ), 71 $args['subject'] 72 ); 73 74 $args['to'] = $email; 75 76 // Try to handle CC and BCC headers. If there aren't any headers, bail early. 77 if ( empty( $args['headers'] ) ) { 78 return $args; 79 } 80 81 $ccs = $bccs = []; 82 83 $headers = (array) $args['headers']; 84 foreach ( $headers as $index => $header ) { 85 if ( false === strpos( $header, ':' ) ) { 86 continue; 87 } 88 89 list( $name, $content ) = explode( ':', trim( $header ), 2 ); 90 91 $name = trim( $name ); 92 93 switch ( strtolower( $name ) ) { 94 case 'cc': 95 $ccs = array_merge( $ccs, explode( ',', $content ) ); 96 break; 97 98 case 'bcc': 99 $bccs = array_merge( $bccs, explode( ',', $content ) ); 100 break; 101 102 default: 103 continue 2; 104 } 105 106 // If we got this far, remove the header from the array. 107 unset( $headers[ $index ] ); 108 } 109 110 // Update the headers array. 111 $args['headers'] = $headers; 112 113 // Add a note to the message body about what was removed. 114 $additional_message = ''; 115 if ( ! empty( $ccs ) ) { 116 $additional_message .= sprintf( 117 /* translators: %s is the comma-separated list of any CC emails removed */ 118 esc_html__( 'CCs removed: %s', 'redirect-emails-on-staging' ), 119 join( ', ', $ccs ) 120 ) . PHP_EOL; 121 } 122 123 if ( ! empty( $bccs ) ) { 124 $additional_message .= sprintf( 125 /* translators: %s is the comma-separated list of any BCC emails removed */ 126 esc_html__( 'BCCs removed: %s', 'redirect-emails-on-staging' ), 127 join( ', ', $bccs ) 128 ) . PHP_EOL; 129 } 130 131 $args['message'] = $additional_message . $args['message']; 132 133 return $args; 134 }, 135 99999 136 ); -
redirect-emails-on-staging/trunk/README.txt
r871476 r2696275 3 3 Tags: email, wpengine 4 4 Requires at least: 3.5.2 5 Tested up to: 3.8.1 6 Stable Tag: 1.1 5 Tested up to: 5.9 6 Requires PHP: 5.3.2 7 Stable tag: 1.2.0 7 8 License: GPL2 8 9 … … 43 44 == Screenshots == 44 45 45 ( none yet)46 (Not applicable to this plugin) 46 47 47 48 == Changelog == 48 49 49 = 1.1 = 50 = 1.2.0 - 2022-03-18 = 51 * Add - Native wp_get_environment_type() support. 52 * Add - Support for checking with Jetpack for staging. 53 * Add - Support for modifying CC and BCC lists in emails. 54 * Dev - Add separate changelog file. 55 * Dev - add automated build process. 56 * Tweak - WP 5.9 compatibility. 57 58 = 1.1.0 = 50 59 * Under-the-hood change: use a class for the main plugin functionality 51 60 * Check PHP version with an activation hook 52 61 * Update the "Tested up to" tag 53 62 54 = 1.0 =63 = 1.0.0 = 55 64 * Created the plugin 56 65 -
redirect-emails-on-staging/trunk/redirect-emails-on-staging.php
r871476 r2696275 1 1 <?php 2 2 /** 3 * Plugin Name: Redirect Emails on Staging 4 * Plugin URI: http://wordpress.org/plugins/redirect-emails-on-staging/ 5 * Description: (For WP Engine only) On the Staging site, redirect all emails to the site admin. This is useful in making sure that the staging site doesn't send out confusing emails to your users. 6 * Version: 1.1 7 * Author: Jeremy Pry 8 * Author URI: http://jeremypry.com/ 9 * License: GPL2 3 * Plugin Name: Redirect Emails on Staging 4 * Plugin URI: http://wordpress.org/plugins/redirect-emails-on-staging/ 5 * Description: On a Staging site, redirect all emails to the site admin. This is useful in making sure that the staging site doesn't send out confusing emails to your users. 6 * Version: 1.2.0 7 * Author: Jeremy Pry 8 * Author URI: https://jeremypry.com/ 9 * License: GPL2 10 * Requires at least: 5.5.0 11 * Tested up to: 5.9 12 * Requires PHP: 5.3.2 13 * Text Domain: redirect-emails-on-staging 10 14 */ 15 16 use Automattic\Jetpack\Status; 11 17 12 18 // Prevent direct access to this file … … 15 21 } 16 22 17 // Activation check 18 register_activation_hook( plugin_basename( __FILE__ ), 'jpry_res_activation_check' ); 23 define( 'JPRY_REDIRECT_EMAILS_ON_STAGING_VERSION', '1.2.0' ); // WRCS: DEFINED_VERSION. 19 24 20 /** 21 * Check to ensure the plugin is able to run 22 * 23 * We're specifically looking to make sure there is a PHP version of 5.3.2 or greater 24 * 25 * @since 1.1 26 */ 27 function jpry_res_activation_check() { 28 $min_php_version = '5.3.2'; 29 $installed_php_version = phpversion(); 25 add_filter( 26 'wp_mail', 27 function( $args ) { 28 // Jetpack is the most comprehensive, so use that if available. 29 if ( class_exists( Status::class ) && method_exists( Status::class, 'is_staging_site' ) ) { 30 $is_staging = ( new Status() )->is_staging_site(); 31 } else { 32 // Check WP environment. 33 $wp_staging = function_exists( 'wp_get_environment_type' ) && 'staging' === wp_get_environment_type(); 30 34 31 if ( version_compare( $min_php_version, $installed_php_version, '>' ) ) { 32 deactivate_plugins( plugin_basename( __FILE__ ) ); 33 wp_die( sprintf( "This plugin requires a minimum PHP version of %s. You only have version %s installed. Please upgrade PHP to use this plugin.", $min_php_version, $installed_php_version ) ); 34 } 35 } 35 // Check on WP Engine hosting (the original purpose of this plugin). 36 $wpe_staging = function_exists( 'is_wpe_snapshot' ) && is_wpe_snapshot(); 36 37 37 // Some constants 38 define( 'RES_FILE', __FILE__ ); 39 define( 'RES_DIR', dirname( RES_FILE ) ); 38 $is_staging = $wp_staging || $wpe_staging; 39 } 40 40 41 // Pull in the class files 42 require_once( RES_DIR . "/classes/class-jpry_singleton.php" ); 43 require_once( RES_DIR . "/classes/class-jpry_redirect_staging_email.php" ); 41 // Bail if we're not in a staging situation. 42 if ( ! $is_staging ) { 43 return $args; 44 } 44 45 45 // Instantiate the class 46 JPry_Redirect_Staging_Email::get_instance(); 46 /** 47 * Filter jpry_redirect_staging_emails_email. 48 * 49 * @since 1.2.0 50 * 51 * @var string $email The email address where all emails generated by the site should be sent. 52 */ 53 $email = apply_filters( 'jpry_redirect_staging_emails_email', get_site_option( 'admin_email' ) ); 54 55 // If the email is already to the admin, then no need to modify anything. 56 if ( $email === $args['to'] ) { 57 return $args; 58 } 59 60 // We've established that we need to modify the email arguments, so let's do so. 61 $args['message'] = sprintf( 62 /* translators: 1: original email address, 2: the original message */ 63 esc_html__( "Originally sent to: %1\$s\n\n%2\$s", 'redirect-emails-on-staging' ), 64 $args['to'], 65 $args['message'] 66 ); 67 68 $args['subject'] = sprintf( 69 /* translators: %s is the original email subject */ 70 esc_html__( 'REDIRECTED EMAIL | %s', 'redirect-emails-on-staging' ), 71 $args['subject'] 72 ); 73 74 $args['to'] = $email; 75 76 // Try to handle CC and BCC headers. If there aren't any headers, bail early. 77 if ( empty( $args['headers'] ) ) { 78 return $args; 79 } 80 81 $ccs = $bccs = []; 82 83 $headers = (array) $args['headers']; 84 foreach ( $headers as $index => $header ) { 85 if ( false === strpos( $header, ':' ) ) { 86 continue; 87 } 88 89 list( $name, $content ) = explode( ':', trim( $header ), 2 ); 90 91 $name = trim( $name ); 92 93 switch ( strtolower( $name ) ) { 94 case 'cc': 95 $ccs = array_merge( $ccs, explode( ',', $content ) ); 96 break; 97 98 case 'bcc': 99 $bccs = array_merge( $bccs, explode( ',', $content ) ); 100 break; 101 102 default: 103 continue 2; 104 } 105 106 // If we got this far, remove the header from the array. 107 unset( $headers[ $index ] ); 108 } 109 110 // Update the headers array. 111 $args['headers'] = $headers; 112 113 // Add a note to the message body about what was removed. 114 $additional_message = ''; 115 if ( ! empty( $ccs ) ) { 116 $additional_message .= sprintf( 117 /* translators: %s is the comma-separated list of any CC emails removed */ 118 esc_html__( 'CCs removed: %s', 'redirect-emails-on-staging' ), 119 join( ', ', $ccs ) 120 ) . PHP_EOL; 121 } 122 123 if ( ! empty( $bccs ) ) { 124 $additional_message .= sprintf( 125 /* translators: %s is the comma-separated list of any BCC emails removed */ 126 esc_html__( 'BCCs removed: %s', 'redirect-emails-on-staging' ), 127 join( ', ', $bccs ) 128 ) . PHP_EOL; 129 } 130 131 $args['message'] = $additional_message . $args['message']; 132 133 return $args; 134 }, 135 99999 136 );
Note: See TracChangeset
for help on using the changeset viewer.