diff --git a/.gitignore b/.gitignore index 3b181ec..abe8da6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,19 +1,5 @@ -*.log -wp-config.php -wp-content/advanced-cache.php -wp-content/backup-db/ -wp-content/backups/ -wp-content/blogs.dir/ -wp-content/cache/ -wp-content/upgrade/ -wp-content/uploads/ -wp-content/mu-plugins/ -wp-content/wp-cache-config.php -wp-content/plugins/hello.php - -/.htaccess -/license.txt -/readme.html -/sitemap.xml -/sitemap.xml.gz +vendor +node_modules +*.log +.DS_Store diff --git a/README.md b/README.md index e79cb09..692b607 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ * Contributors: ryanshoover * Tags: staging, woocommerce, email * Requires at least: 4.7 -* Tested up to: 5 +* Tested up to: 5.0 * Requires PHP: 7.0 * License: GPL3 * License URI: www.gnu.org/licenses/gpl-3.0.en.html @@ -12,7 +12,7 @@ Safely copy your WordPress, WooCommerce, and membership site between production ## Description -Simply define your production url in settings and copy your site to your staging instance without fear. The staging site won\'t send any emails and won\'t process any payments. +Simply define your production url in settings and copy your site to your staging instance without fear. The staging site won't send any emails and won't process any payments. ### Why should I use the plugin @@ -22,6 +22,8 @@ Instead, install this plugin in production, set the production URL, and safely c ### Features on Staging +A "noindex" tag is added to all pages. Your staging site won't show up in Google. + WordPress emails are stopped. The site won't send any emails except for the password reset email. Please note, this feature may not be compatible with plugins that offload email to a 3rd party service. The WooCommerce checkout page has a warning message notifying the visitor they are viewing the staging site. @@ -32,6 +34,38 @@ WooCommerce Subscriptions is put into staging mode. ## Installation -1. Upload the plugin to wp-content/plugins/ -2. Activate the plugin at wp-admin/plugins.php -3. Set the URL for your production site at /wp-admin/options-general.php?page=safe-staging +1. Upload the plugin to `/wp-content/plugins/` +2. Activate the plugin at `/wp-admin/plugins.php` +3. Set the URL for your production site at `/wp-admin/options-general.php?page=safe-staging` + +## Hooks and Filters + +```php +/** + * Change whether Safe Staging thinks the current site + * is the production site. + * + * @param bool $is_prod Is this the production site. + */ +apply_filters( 'safe_staging_is_production', $is_prod ); +``` + +```php +/** + * Determine whether a particular email should be sent. + * + * @param bool $whitelisted Should the email actually send. + * @param object $this Instance of the Fake PHPMailer class. + */ +apply_filters( 'safe_staging_is_whitelist_email', $whitelisted, $this ); +``` + +```php +/** + * Change the warning message that gets displayed on the checkout page + * of staging sites. + * + * @param string $notice HTML of the message to be shown. + */ +apply_filters( 'safe_staging_checkout_notice', $notice ); +``` diff --git a/changelog.txt b/changelog.txt new file mode 100644 index 0000000..e5bdcb8 --- /dev/null +++ b/changelog.txt @@ -0,0 +1,4 @@ +== Changelog == + += 0.2 = +* Adds noindex tag to the staging site. diff --git a/inc/class-fake-phpmailer.php b/inc/class-fake-phpmailer.php index bbd3a9b..7c7a33c 100644 --- a/inc/class-fake-phpmailer.php +++ b/inc/class-fake-phpmailer.php @@ -38,6 +38,12 @@ protected function is_whitelist_email() { $whitelisted = true; } + /** + * Determine whether the email should be sent. + * + * @param bool $whitelisted Should the email actually send. + * @param object $this Instance of the Fake PHPMailer class. + */ return apply_filters( 'safe_staging_is_whitelist_email', $whitelisted, $this ); } diff --git a/inc/class-notices.php b/inc/class-notices.php index 97faba6..4911b07 100644 --- a/inc/class-notices.php +++ b/inc/class-notices.php @@ -66,6 +66,12 @@ public function do_checkout_notice() { __( 'production site', 'safe-staging' ) ); - wc_add_notice( $notice, 'error' ); + /** + * Change the warning message that gets displayed on the checkout page + * of staging sites. + * + * @param string $notice HTML of the message to be shown. + */ + wc_add_notice( apply_filters( 'safe_staging_checkout_notice', $notice ), 'error' ); } } diff --git a/inc/class-protection.php b/inc/class-protection.php index dfac30a..e224819 100644 --- a/inc/class-protection.php +++ b/inc/class-protection.php @@ -25,6 +25,9 @@ public static function hooks() { // Stop all emails. $self->replace_mailer(); + // Add a noindex tag to the header to stop indexing bots. + add_action( 'wp_head', 'wp_no_robots' ); + // Remove all but most basic payment gateways. add_filter( 'woocommerce_payment_gateways', [ $self, 'disable_payment_gateways' ], 999999 ); @@ -54,6 +57,12 @@ public static function is_production() { $is_prod = true; } + /** + * Change whether Safe Staging thinks the current site + * is the production site. + * + * @param bool $is_prod Is this the production site. + */ return apply_filters( 'safe_staging_is_production', $is_prod ); } diff --git a/readme.txt b/readme.txt index f970fd5..6dfc9fa 100644 --- a/readme.txt +++ b/readme.txt @@ -2,7 +2,7 @@ Contributors: ryanshoover Tags: staging, woocommerce, email Requires at least: 4.7 -Tested up to: 5 +Tested up to: 5.0 Requires PHP: 7.0 License: GPL3 License URI: https://www.gnu.org/licenses/gpl-3.0.en.html @@ -18,15 +18,45 @@ If you host your site on a managed host that provides a staging instance (WP Eng Instead, install this plugin in production, set the production URL, and safely copy your site to and from staging. No other steps needed! = Features on Staging = -WordPress emails are stopped. The site won't send any emails except for the password reset email. Please note, this feature may not be compatible with plugins that offload email to a 3rd party service. - -The WooCommerce checkout page has a warning message notifying the visitor they are viewing the staging site. - -WooCommerce payment gateways are suspended. Bank account transfer, Cash on Delivery and Check are left enabled. Stripe is automatically put into test mode. - -WooCommerce Subscriptions is put into staging mode. +1. A "noindex" tag is added to all pages. Your staging site won't show up in Google. +2. WordPress emails are stopped. The site won't send any emails except for the password reset email. Please note, this feature may not be compatible with plugins that offload email to a 3rd party service. +3. The WooCommerce checkout page has a warning message notifying the visitor they are viewing the staging site. +4. WooCommerce payment gateways are suspended. Bank account transfer, Cash on Delivery and Check are left enabled. Stripe is automatically put into test mode. +5. WooCommerce Subscriptions is put into staging mode. == Installation == -1. Upload the plugin to wp-content/plugins/ -2. Activate the plugin at wp-admin/plugins.php -3. Set the URL for your production site at /wp-admin/options-general.php?page=safe-staging +1. Upload the plugin to `/wp-content/plugins/` +2. Activate the plugin at `/wp-admin/plugins.php` +3. Set the URL for your production site at `/wp-admin/options-general.php?page=safe-staging` + +== Hooks and Filters == + +```php +/** + * Change whether Safe Staging thinks the current site + * is the production site. + * + * @param bool $is_prod Is this the production site. + */ +apply_filters( 'safe_staging_is_production', $is_prod ); +``` + +```php +/** + * Determine whether a particular email should be sent. + * + * @param bool $whitelisted Should the email actually send. + * @param object $this Instance of the Fake PHPMailer class. + */ +apply_filters( 'safe_staging_is_whitelist_email', $whitelisted, $this ); +``` + +```php +/** + * Change the warning message that gets displayed on the checkout page + * of staging sites. + * + * @param string $notice HTML of the message to be shown. + */ +apply_filters( 'safe_staging_checkout_notice', $notice ); +```