Changeset 3832012
- Timestamp:
- 11/28/2026 06:57:58 PM (14 hours ago)
- Location:
- nanopost-email-check
- Files:
-
- 2 added
- 20 edited
- 1 copied
-
tags/1.9.0 (copied) (copied from nanopost-email-check/trunk )
-
tags/1.9.0/includes/class-nanopost-email-check-admin.php (modified) (2 diffs)
-
tags/1.9.0/includes/class-nanopost-email-check-app.php (modified) (2 diffs)
-
tags/1.9.0/includes/class-nanopost-email-check-cli.php (modified) (1 diff)
-
tags/1.9.0/includes/class-nanopost-email-check-connection.php (modified) (4 diffs)
-
tags/1.9.0/includes/class-nanopost-email-check-help.php (modified) (1 diff)
-
tags/1.9.0/includes/class-nanopost-email-check-key.php (added)
-
tags/1.9.0/includes/class-nanopost-email-check-plugin.php (modified) (1 diff)
-
tags/1.9.0/includes/class-nanopost-email-check-scheduler.php (modified) (2 diffs)
-
tags/1.9.0/nanopost-email-check.php (modified) (3 diffs)
-
tags/1.9.0/readme.txt (modified) (4 diffs)
-
tags/1.9.0/uninstall.php (modified) (1 diff)
-
trunk/includes/class-nanopost-email-check-admin.php (modified) (2 diffs)
-
trunk/includes/class-nanopost-email-check-app.php (modified) (2 diffs)
-
trunk/includes/class-nanopost-email-check-cli.php (modified) (1 diff)
-
trunk/includes/class-nanopost-email-check-connection.php (modified) (4 diffs)
-
trunk/includes/class-nanopost-email-check-help.php (modified) (1 diff)
-
trunk/includes/class-nanopost-email-check-key.php (added)
-
trunk/includes/class-nanopost-email-check-plugin.php (modified) (1 diff)
-
trunk/includes/class-nanopost-email-check-scheduler.php (modified) (2 diffs)
-
trunk/nanopost-email-check.php (modified) (3 diffs)
-
trunk/readme.txt (modified) (4 diffs)
-
trunk/uninstall.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
nanopost-email-check/tags/1.9.0/includes/class-nanopost-email-check-admin.php
r3830659 r3832012 1050 1050 1051 1051 echo '<p>' . esc_html__( 'Email Check can tell you that WordPress sent the email. Email Canary checks that it arrived, and emails you when it does not.', 'nanopost-email-check' ) . '</p>'; 1052 self::render_key_line(); 1052 1053 if ( ! self::site_is_public() ) { 1053 1054 echo '<div class="notice notice-warning inline"><p>' . esc_html__( 'This site address is not public. Test emails from it may never leave the server.', 'nanopost-email-check' ) . '</p></div>'; 1054 1055 } 1055 1056 self::render_turn_on_form( $email, __( 'Turn on Email Canary', 'nanopost-email-check' ) ); 1056 echo '<p class="description nanopost-email-check-consent">' . esc_html__( 'When you turn on Email Canary, this site sends to nanoPost: the site address, the alert address above, the site\'s time zone, the test interval, the webhook URL, and the versions of this plugin, WordPress and PHP. After each test it sends the test ID, the time, how the test started, and whether WordPress accepted the email, with the error text if it did not. nanoPost keeps the IP address of each call for 30 days. ', 'nanopost-email-check' ) . '</p>';1057 echo '<p class="description nanopost-email-check-consent">' . esc_html__( 'When you turn on Email Canary, this site sends to nanoPost: the site address, the alert address above, the site\'s time zone, the test interval, the webhook URL, and the versions of this plugin, WordPress and PHP. After each test it sends the test ID, the time, how the test started, and whether WordPress accepted the email, with the error text if it did not. nanoPost keeps the IP address of each call for 30 days. If an account key is set, the site sends it once, to add the site to that nanoPost account.', 'nanopost-email-check' ) . '</p>'; 1057 1058 echo '<p>' . self::help_link( NanoPost_Email_Check_Help::canary( NanoPost_Email_Check_Help::CANARY_SENT, NanoPost_Email_Check_Help::PLACE_CANARY ), __( 'What is sent to nanoPost', 'nanopost-email-check' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Escaped in help_link(). 1058 1059 echo ' · ' . self::help_link( NanoPost_Email_Check_Help::TERMS_URL, __( 'Terms', 'nanopost-email-check' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Escaped in help_link(). … … 1060 1061 echo ' · ' . self::help_link( NanoPost_Email_Check_Help::canary( NanoPost_Email_Check_Help::CANARY_TURN_ON, NanoPost_Email_Check_Help::PLACE_CANARY ), __( 'How Email Canary works', 'nanopost-email-check' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Escaped in help_link(). 1061 1062 echo '</p>'; 1063 } 1064 1065 /** 1066 * One line while an account key is set in wp-config.php: what it does on this site, or 1067 * why it does not. 1068 */ 1069 private static function render_key_line() { 1070 if ( '' === NanoPost_Email_Check_Key::constant_key() ) { 1071 return; 1072 } 1073 $link = ' ' . self::help_link( NanoPost_Email_Check_Help::canary( NanoPost_Email_Check_Help::CANARY_KEY, NanoPost_Email_Check_Help::PLACE_CANARY ), __( 'How the account key works', 'nanopost-email-check' ) ); 1074 $error = NanoPost_Email_Check_Key::error(); 1075 if ( '' !== $error ) { 1076 echo '<div class="notice notice-error inline nanopost-email-check-key"><p>' . esc_html( NanoPost_Email_Check_Key::error_text( $error ) ) . $link . '</p></div>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- $link is escaped in help_link(). 1077 return; 1078 } 1079 switch ( NanoPost_Email_Check_Key::blocked_reason() ) { 1080 case 'not_public': 1081 $text = __( 'An account key is set in wp-config.php, but this site address is not public, so the key does not turn Email Canary on by itself.', 'nanopost-email-check' ); 1082 break; 1083 case 'not_main_site': 1084 $text = __( 'An account key is set in wp-config.php. On a network it turns Email Canary on only for the main site. For this site, use WP-CLI: wp email-check connect --key=<key> --url=<site address>', 'nanopost-email-check' ); 1085 break; 1086 case 'tried': 1087 case 'ended': 1088 $text = __( 'An account key is set in wp-config.php. It does not turn Email Canary on by itself again for this site address. Use the button below.', 'nanopost-email-check' ); 1089 break; 1090 default: 1091 $text = __( 'An account key is set in wp-config.php. Email Canary turns on by itself in a moment, with alerts to the address of the nanoPost account.', 'nanopost-email-check' ); 1092 } 1093 echo '<p class="description nanopost-email-check-key">' . esc_html( $text ) . $link . '</p>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- $link is escaped in help_link(). 1062 1094 } 1063 1095 -
nanopost-email-check/tags/1.9.0/includes/class-nanopost-email-check-app.php
r3830659 r3832012 75 75 * connection. The owner's click (admin-post) or WP-CLI. 76 76 * 77 * @param string $email Alert address. 77 * With an account key in place of the address (#58), the canary watches at once, with 78 * alerts to the account's address. Exactly one of the two is sent. The key is sent in 79 * this call only, and never stored. 80 * 81 * @param string $email Alert address, or '' with a key. 82 * @param string $key Account key, or ''. 78 83 * @return array Call result (see request()). error "bad_answer" when the answer lacks 79 84 * a valid canary address; "connected" when a connection already exists. 80 85 */ 81 public static function connect( $email ) { 82 $token = NanoPost_Email_Check_Connection::begin( $email ); 86 public static function connect( $email, $key = '' ) { 87 $identity = '' !== $key ? 'key:' . NanoPost_Email_Check_Key::fingerprint( $key ) : (string) $email; 88 $token = NanoPost_Email_Check_Connection::begin( $identity, '' === $key ? (string) $email : '' ); 83 89 if ( '' === $token ) { 84 90 return self::not_sent( 'connected' ); … … 87 93 $hash = md5( (string) wp_json_encode( $body ) ); 88 94 89 $body['alert_email'] = (string) $email; 90 $result = self::request( 'POST', '/connect', $body, self::TIMEOUT_LONG, true, false, $token ); 95 if ( '' !== $key ) { 96 $body['account_key'] = (string) $key; 97 } else { 98 $body['alert_email'] = (string) $email; 99 } 100 $result = self::request( 'POST', '/connect', $body, self::TIMEOUT_LONG, true, false, $token ); 91 101 92 102 if ( $result['ok'] && ! NanoPost_Email_Check_Connection::save_from_connect( $result['body'], $hash ) ) { -
nanopost-email-check/tags/1.9.0/includes/class-nanopost-email-check-cli.php
r3830659 r3832012 178 178 WP_CLI::halt( $code ); 179 179 } 180 } 181 182 /** 183 * Turn Email Canary on, with an account key or an alert address. 184 * 185 * With a key, Email Canary watches at once, with alerts to the address of the nanoPost 186 * account. With an address, a confirm email goes there, and alerts are off until it is 187 * confirmed. Either way, one test email goes out at once. The key is sent in this call 188 * only, and never stored. 189 * 190 * Exits with 0 when Email Canary is on (or waits for the confirm), and 1 when it is not, 191 * or when its alerts are off because the nanoPost account has no room for this site. 192 * 193 * ## OPTIONS 194 * 195 * [--key=<key>] 196 * : An account key from nanoPost (Settings > Profile > Account key). With no --key and no --email, 197 * the key in the NANOPOST_EMAIL_CHECK_KEY constant is used. 198 * 199 * [--email=<email>] 200 * : An alert address, in place of a key. 201 * 202 * ## EXAMPLES 203 * 204 * $ wp email-check connect --key=npk_... 205 * Success: Email Canary is on. Alerts go to owner@example.com. 206 * 207 * $ wp email-check connect --email=owner@example.com 208 * Success: Email Canary is on. We sent a confirm email to owner@example.com. Alerts are off until it is confirmed. 209 * 210 * @param array $args Positional arguments (none). 211 * @param array $assoc_args Options. 212 */ 213 public function connect( $args, $assoc_args ) { 214 $email = isset( $assoc_args['email'] ) ? sanitize_email( (string) $assoc_args['email'] ) : ''; 215 $key = isset( $assoc_args['key'] ) ? trim( (string) $assoc_args['key'] ) : ''; 216 if ( isset( $assoc_args['email'] ) && isset( $assoc_args['key'] ) ) { 217 WP_CLI::error( __( 'Use --key or --email, not both.', 'nanopost-email-check' ) ); 218 } 219 if ( isset( $assoc_args['email'] ) && ! is_email( $email ) ) { 220 WP_CLI::error( __( 'The --email value is not a valid email address.', 'nanopost-email-check' ) ); 221 } 222 if ( '' === $email && '' === $key ) { 223 $key = NanoPost_Email_Check_Key::constant_key(); 224 if ( '' === $key ) { 225 WP_CLI::error( __( 'Give --key or --email, or set NANOPOST_EMAIL_CHECK_KEY in wp-config.php.', 'nanopost-email-check' ) ); 226 } 227 } 228 if ( NanoPost_Email_Check_Connection::is_connected() ) { 229 WP_CLI::error( __( 'Email Canary is already set up for this site. Turn it off on the plugin screen first.', 'nanopost-email-check' ) ); 230 } 231 232 $call = '' !== $key ? NanoPost_Email_Check_Key::connect( $key ) : NanoPost_Email_Check_App::connect( $email ); 233 if ( ! $call['ok'] ) { 234 if ( in_array( $call['error'], array( NanoPost_Email_Check_Key::ERROR_INVALID, NanoPost_Email_Check_Key::ERROR_EXISTS ), true ) ) { 235 WP_CLI::error( NanoPost_Email_Check_Key::error_text( $call['error'] ) ); 236 } 237 $detail = '' !== $call['message'] ? $call['message'] : ( 0 === $call['code'] ? $call['error'] : 'HTTP ' . $call['code'] ); 238 /* translators: %s: error text or HTTP status. */ 239 WP_CLI::error( sprintf( __( 'Email Canary did not turn on: %s', 'nanopost-email-check' ), $detail ) ); 240 } 241 242 $block = NanoPost_Email_Check_Canary::block(); 243 $results = NanoPost_Email_Check_Plugin::run_checks( NanoPost_Email_Check_Result::TRIGGER_CLI ); 244 if ( ! empty( $results ) && '' !== $results[0]->test_id ) { 245 /* translators: %s: test ID. */ 246 WP_CLI::log( sprintf( __( 'A test email went out (test %s).', 'nanopost-email-check' ), $results[0]->test_id ) ); 247 } 248 $address = NanoPost_Email_Check_Admin::alert_address( $block ); 249 if ( null !== $block && 'over_limit' === $block['watching'] ) { 250 WP_CLI::error( __( 'Email Canary: alerts are OFF. Your nanoPost account has reached its limit of sites. Remove one in nanoPost, or ask us for more.', 'nanopost-email-check' ) ); 251 } 252 if ( null !== $block && 'unconfirmed' === $block['watching'] ) { 253 /* translators: %s: email address. */ 254 WP_CLI::success( sprintf( __( 'Email Canary is on. We sent a confirm email to %s. Alerts are off until it is confirmed.', 'nanopost-email-check' ), $address ) ); 255 return; 256 } 257 /* translators: %s: email address. */ 258 WP_CLI::success( sprintf( __( 'Email Canary is on. Alerts go to %s.', 'nanopost-email-check' ), $address ) ); 180 259 } 181 260 -
nanopost-email-check/tags/1.9.0/includes/class-nanopost-email-check-connection.php
r3830659 r3832012 51 51 'site_hash' => '', 52 52 'alert_email' => '', 53 'pending_for' => '', 53 54 'pending_at' => 0, 54 55 ); … … 65 66 * Start "Turn on Email Canary": the token the plugin makes for the connect call. It is 66 67 * stored before the call, so a retry sends the same token and the app does not make a 67 * second canary. A pending token for the same address is used again; another address 68 * gets a new token. Two requests at the same time get the same token (add_option()). 69 * 70 * @param string $email Alert address. 68 * second canary. A pending token for the same address (or the same key) is used again; 69 * another one gets a new token. Two requests at the same time get the same token 70 * (add_option()). 71 * 72 * @param string $identity The alert address, or "key:" and the key's fingerprint. 73 * @param string $email The alert address to keep, or '' for a key. 71 74 * @return string The token, or '' while a connection with an address exists (except 72 75 * for a canary that was not confirmed, which connects again). 73 76 */ 74 public static function begin( $email ) { 77 public static function begin( $identity, $email = null ) { 78 $email = null === $email ? (string) $identity : (string) $email; 75 79 $current = self::get(); 80 // A connection stored by 1.8.0 has no pending_for: its alert address stands in. 81 if ( '' === $current['pending_for'] ) { 82 $current['pending_for'] = $current['alert_email']; 83 } 76 84 if ( '' !== $current['address'] && '' !== $current['token'] ) { 77 85 // A canary that was not confirmed in 24 hours: connect again with its token. 78 86 $block = NanoPost_Email_Check_Canary::block(); 79 return null !== $block && 'not_confirmed' === $block['stopped_reason'] && $ email === $current['alert_email'] ? $current['token'] : '';80 } 81 if ( '' !== $current['token'] && $ email === $current['alert_email'] ) {87 return null !== $block && 'not_confirmed' === $block['stopped_reason'] && $identity === $current['pending_for'] ? $current['token'] : ''; 88 } 89 if ( '' !== $current['token'] && $identity === $current['pending_for'] ) { 82 90 return $current['token']; 83 91 } 84 92 $pending = array( 85 93 'token' => self::new_token(), 86 'alert_email' => (string) $email, 94 'alert_email' => $email, 95 'pending_for' => (string) $identity, 87 96 'pending_at' => time(), 88 97 'home_url' => home_url(), … … 92 101 wp_cache_delete( self::OPTION, 'options' ); 93 102 $current = self::get(); 94 if ( $ email === $current['alert_email'] && '' !== $current['token'] ) {103 if ( $identity === $current['pending_for'] && '' !== $current['token'] ) { 95 104 return $current['token']; 96 105 } … … 134 143 'connected_at' => time(), 135 144 'alert_email' => $current['alert_email'], 145 'pending_for' => $current['pending_for'], 136 146 'site_hash' => (string) $site_hash, 137 147 ), -
nanopost-email-check/tags/1.9.0/includes/class-nanopost-email-check-help.php
r3830659 r3832012 115 115 const CANARY_STOP = 'stop-watching'; 116 116 const CANARY_SENT = 'what-is-sent-to-nanopost'; 117 const CANARY_KEY = 'turn-on-with-an-account-key'; 117 118 118 119 /** -
nanopost-email-check/tags/1.9.0/includes/class-nanopost-email-check-plugin.php
r3830659 r3832012 22 22 NanoPost_Email_Check_App::init(); 23 23 NanoPost_Email_Check_Canary::init(); 24 NanoPost_Email_Check_Key::init(); 24 25 25 26 if ( is_admin() ) { -
nanopost-email-check/tags/1.9.0/includes/class-nanopost-email-check-scheduler.php
r3830659 r3832012 107 107 wp_clear_scheduled_hook( NanoPost_Email_Check_App::SYNC_HOOK ); 108 108 wp_clear_scheduled_hook( NanoPost_Email_Check_App::START_HOOK ); 109 wp_clear_scheduled_hook( NanoPost_Email_Check_Key::HOOK ); 109 110 wp_unschedule_hook( NanoPost_Email_Check_Canary::FETCH_HOOK ); 110 111 return; … … 117 118 wp_clear_scheduled_hook( NanoPost_Email_Check_App::SYNC_HOOK ); 118 119 wp_clear_scheduled_hook( NanoPost_Email_Check_App::START_HOOK ); 120 wp_clear_scheduled_hook( NanoPost_Email_Check_Key::HOOK ); 119 121 wp_unschedule_hook( NanoPost_Email_Check_Canary::FETCH_HOOK ); 120 122 restore_current_blog(); -
nanopost-email-check/tags/1.9.0/nanopost-email-check.php
r3830659 r3832012 4 4 * Plugin URI: https://nanopo.st/email-check-plugin/ 5 5 * Description: Check that your site can still send email. Sends a scheduled test email, logs each result and warns you when a check fails. 6 * Version: 1. 8.06 * Version: 1.9.0 7 7 * Requires at least: 6.4 8 8 * Requires PHP: 7.4 … … 18 18 defined( 'ABSPATH' ) || exit; 19 19 20 define( 'NANOPOST_EMAIL_CHECK_VERSION', '1. 8.0' );20 define( 'NANOPOST_EMAIL_CHECK_VERSION', '1.9.0' ); 21 21 define( 'NANOPOST_EMAIL_CHECK_FILE', __FILE__ ); 22 22 define( 'NANOPOST_EMAIL_CHECK_DIR', plugin_dir_path( __FILE__ ) ); … … 36 36 require_once NANOPOST_EMAIL_CHECK_DIR . 'includes/class-nanopost-email-check-app.php'; 37 37 require_once NANOPOST_EMAIL_CHECK_DIR . 'includes/class-nanopost-email-check-canary.php'; 38 require_once NANOPOST_EMAIL_CHECK_DIR . 'includes/class-nanopost-email-check-key.php'; 38 39 require_once NANOPOST_EMAIL_CHECK_DIR . 'includes/class-nanopost-email-check-admin.php'; 39 40 -
nanopost-email-check/tags/1.9.0/readme.txt
r3830659 r3832012 5 5 Tested up to: 7.1 6 6 Requires PHP: 7.4 7 Stable tag: 1. 8.07 Stable tag: 1.9.0 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 121 121 `run` and `test-alert` have no once-a-minute limit. On multisite, choose the site with `--url`. For details, run `wp help email-check`, or read [settings in code and WP-CLI](https://nanopo.st/email-check-plugin/code-and-cli/). 122 122 123 = Can I turn on Email Canary on many sites at once? = 124 125 Yes, with an account key. Make one in nanoPost (Settings > Profile > Account key), then add `define( 'NANOPOST_EMAIL_CHECK_KEY', '...' );` to `wp-config.php`, or run `wp email-check connect --key=...` on each site. Email Canary then turns on by itself, with alerts to your nanoPost account's address and no confirm email. The key only adds sites; it cannot read your account. It turns a site on once: not again after you turn it off, and not on a copy of the site at another address or on a site address that is not public. On a multisite network, the constant turns on only the main site; use WP-CLI with `--url` for the other sites. 126 123 127 = Does it work on multisite? = 124 128 … … 145 149 = nanoPost Email Canary (optional, after you turn it on) = 146 150 147 nanoPost Email Canary (app.nanopo.st) is a service run by the plugin's authors. It checks that each test email arrives, and emails you when one does not. The plugin calls it only after you type an alert address and click "Turn on Email Canary" on the plugin screen . Until then, nothing is sent. When you turn it off, deactivate the plugin or delete it, the plugin tells Email Canary.151 nanoPost Email Canary (app.nanopo.st) is a service run by the plugin's authors. It checks that each test email arrives, and emails you when one does not. The plugin calls it only after you type an alert address and click "Turn on Email Canary" on the plugin screen, or after you set a nanoPost account key in `wp-config.php` or run `wp email-check connect`. Until then, nothing is sent. When you turn it off, deactivate the plugin or delete it, the plugin tells Email Canary. 148 152 149 153 While Email Canary is on, the site sends: 150 154 151 155 * when you turn it on: the site address, the alert address you typed, the site's time zone, the test interval, the webhook URL if you set one, the versions of the plugin, WordPress and PHP, and a random key that the plugin makes for this site; 156 * if you set a nanoPost account key (in `wp-config.php` or with WP-CLI) in place of an alert address: that key, once, in the call that turns Email Canary on. The plugin does not store it; 152 157 * the same site settings again when one of them changes; 153 158 * for each test: a test ID, the time it was sent, what started it (the schedule, a user or WP-CLI), whether WordPress accepted the email, and its error text if it did not (at most 500 characters; it can contain host names or email addresses); … … 191 196 192 197 == Changelog == 198 199 = 1.9.0 = 200 * Account key for agencies: `NANOPOST_EMAIL_CHECK_KEY` in `wp-config.php` turns Email Canary on by itself, once per site address, with alerts to the nanoPost account's address and no confirm email. The key is never stored. 201 * New WP-CLI command `wp email-check connect`, with `--key` or `--email`. 193 202 194 203 = 1.8.0 = -
nanopost-email-check/tags/1.9.0/uninstall.php
r3830659 r3832012 60 60 wp_unschedule_hook( 'nanopost_email_check_fetch_test' ); 61 61 wp_clear_scheduled_hook( 'nanopost_email_check_start' ); 62 delete_option( 'nanopost_email_check_key_state' ); 63 wp_clear_scheduled_hook( 'nanopost_email_check_key_connect' ); 62 64 delete_option( 'nanopost_email_check_settings' ); 63 65 delete_option( 'nanopost_email_check_log' ); -
nanopost-email-check/trunk/includes/class-nanopost-email-check-admin.php
r3830659 r3832012 1050 1050 1051 1051 echo '<p>' . esc_html__( 'Email Check can tell you that WordPress sent the email. Email Canary checks that it arrived, and emails you when it does not.', 'nanopost-email-check' ) . '</p>'; 1052 self::render_key_line(); 1052 1053 if ( ! self::site_is_public() ) { 1053 1054 echo '<div class="notice notice-warning inline"><p>' . esc_html__( 'This site address is not public. Test emails from it may never leave the server.', 'nanopost-email-check' ) . '</p></div>'; 1054 1055 } 1055 1056 self::render_turn_on_form( $email, __( 'Turn on Email Canary', 'nanopost-email-check' ) ); 1056 echo '<p class="description nanopost-email-check-consent">' . esc_html__( 'When you turn on Email Canary, this site sends to nanoPost: the site address, the alert address above, the site\'s time zone, the test interval, the webhook URL, and the versions of this plugin, WordPress and PHP. After each test it sends the test ID, the time, how the test started, and whether WordPress accepted the email, with the error text if it did not. nanoPost keeps the IP address of each call for 30 days. ', 'nanopost-email-check' ) . '</p>';1057 echo '<p class="description nanopost-email-check-consent">' . esc_html__( 'When you turn on Email Canary, this site sends to nanoPost: the site address, the alert address above, the site\'s time zone, the test interval, the webhook URL, and the versions of this plugin, WordPress and PHP. After each test it sends the test ID, the time, how the test started, and whether WordPress accepted the email, with the error text if it did not. nanoPost keeps the IP address of each call for 30 days. If an account key is set, the site sends it once, to add the site to that nanoPost account.', 'nanopost-email-check' ) . '</p>'; 1057 1058 echo '<p>' . self::help_link( NanoPost_Email_Check_Help::canary( NanoPost_Email_Check_Help::CANARY_SENT, NanoPost_Email_Check_Help::PLACE_CANARY ), __( 'What is sent to nanoPost', 'nanopost-email-check' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Escaped in help_link(). 1058 1059 echo ' · ' . self::help_link( NanoPost_Email_Check_Help::TERMS_URL, __( 'Terms', 'nanopost-email-check' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Escaped in help_link(). … … 1060 1061 echo ' · ' . self::help_link( NanoPost_Email_Check_Help::canary( NanoPost_Email_Check_Help::CANARY_TURN_ON, NanoPost_Email_Check_Help::PLACE_CANARY ), __( 'How Email Canary works', 'nanopost-email-check' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Escaped in help_link(). 1061 1062 echo '</p>'; 1063 } 1064 1065 /** 1066 * One line while an account key is set in wp-config.php: what it does on this site, or 1067 * why it does not. 1068 */ 1069 private static function render_key_line() { 1070 if ( '' === NanoPost_Email_Check_Key::constant_key() ) { 1071 return; 1072 } 1073 $link = ' ' . self::help_link( NanoPost_Email_Check_Help::canary( NanoPost_Email_Check_Help::CANARY_KEY, NanoPost_Email_Check_Help::PLACE_CANARY ), __( 'How the account key works', 'nanopost-email-check' ) ); 1074 $error = NanoPost_Email_Check_Key::error(); 1075 if ( '' !== $error ) { 1076 echo '<div class="notice notice-error inline nanopost-email-check-key"><p>' . esc_html( NanoPost_Email_Check_Key::error_text( $error ) ) . $link . '</p></div>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- $link is escaped in help_link(). 1077 return; 1078 } 1079 switch ( NanoPost_Email_Check_Key::blocked_reason() ) { 1080 case 'not_public': 1081 $text = __( 'An account key is set in wp-config.php, but this site address is not public, so the key does not turn Email Canary on by itself.', 'nanopost-email-check' ); 1082 break; 1083 case 'not_main_site': 1084 $text = __( 'An account key is set in wp-config.php. On a network it turns Email Canary on only for the main site. For this site, use WP-CLI: wp email-check connect --key=<key> --url=<site address>', 'nanopost-email-check' ); 1085 break; 1086 case 'tried': 1087 case 'ended': 1088 $text = __( 'An account key is set in wp-config.php. It does not turn Email Canary on by itself again for this site address. Use the button below.', 'nanopost-email-check' ); 1089 break; 1090 default: 1091 $text = __( 'An account key is set in wp-config.php. Email Canary turns on by itself in a moment, with alerts to the address of the nanoPost account.', 'nanopost-email-check' ); 1092 } 1093 echo '<p class="description nanopost-email-check-key">' . esc_html( $text ) . $link . '</p>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- $link is escaped in help_link(). 1062 1094 } 1063 1095 -
nanopost-email-check/trunk/includes/class-nanopost-email-check-app.php
r3830659 r3832012 75 75 * connection. The owner's click (admin-post) or WP-CLI. 76 76 * 77 * @param string $email Alert address. 77 * With an account key in place of the address (#58), the canary watches at once, with 78 * alerts to the account's address. Exactly one of the two is sent. The key is sent in 79 * this call only, and never stored. 80 * 81 * @param string $email Alert address, or '' with a key. 82 * @param string $key Account key, or ''. 78 83 * @return array Call result (see request()). error "bad_answer" when the answer lacks 79 84 * a valid canary address; "connected" when a connection already exists. 80 85 */ 81 public static function connect( $email ) { 82 $token = NanoPost_Email_Check_Connection::begin( $email ); 86 public static function connect( $email, $key = '' ) { 87 $identity = '' !== $key ? 'key:' . NanoPost_Email_Check_Key::fingerprint( $key ) : (string) $email; 88 $token = NanoPost_Email_Check_Connection::begin( $identity, '' === $key ? (string) $email : '' ); 83 89 if ( '' === $token ) { 84 90 return self::not_sent( 'connected' ); … … 87 93 $hash = md5( (string) wp_json_encode( $body ) ); 88 94 89 $body['alert_email'] = (string) $email; 90 $result = self::request( 'POST', '/connect', $body, self::TIMEOUT_LONG, true, false, $token ); 95 if ( '' !== $key ) { 96 $body['account_key'] = (string) $key; 97 } else { 98 $body['alert_email'] = (string) $email; 99 } 100 $result = self::request( 'POST', '/connect', $body, self::TIMEOUT_LONG, true, false, $token ); 91 101 92 102 if ( $result['ok'] && ! NanoPost_Email_Check_Connection::save_from_connect( $result['body'], $hash ) ) { -
nanopost-email-check/trunk/includes/class-nanopost-email-check-cli.php
r3830659 r3832012 178 178 WP_CLI::halt( $code ); 179 179 } 180 } 181 182 /** 183 * Turn Email Canary on, with an account key or an alert address. 184 * 185 * With a key, Email Canary watches at once, with alerts to the address of the nanoPost 186 * account. With an address, a confirm email goes there, and alerts are off until it is 187 * confirmed. Either way, one test email goes out at once. The key is sent in this call 188 * only, and never stored. 189 * 190 * Exits with 0 when Email Canary is on (or waits for the confirm), and 1 when it is not, 191 * or when its alerts are off because the nanoPost account has no room for this site. 192 * 193 * ## OPTIONS 194 * 195 * [--key=<key>] 196 * : An account key from nanoPost (Settings > Profile > Account key). With no --key and no --email, 197 * the key in the NANOPOST_EMAIL_CHECK_KEY constant is used. 198 * 199 * [--email=<email>] 200 * : An alert address, in place of a key. 201 * 202 * ## EXAMPLES 203 * 204 * $ wp email-check connect --key=npk_... 205 * Success: Email Canary is on. Alerts go to owner@example.com. 206 * 207 * $ wp email-check connect --email=owner@example.com 208 * Success: Email Canary is on. We sent a confirm email to owner@example.com. Alerts are off until it is confirmed. 209 * 210 * @param array $args Positional arguments (none). 211 * @param array $assoc_args Options. 212 */ 213 public function connect( $args, $assoc_args ) { 214 $email = isset( $assoc_args['email'] ) ? sanitize_email( (string) $assoc_args['email'] ) : ''; 215 $key = isset( $assoc_args['key'] ) ? trim( (string) $assoc_args['key'] ) : ''; 216 if ( isset( $assoc_args['email'] ) && isset( $assoc_args['key'] ) ) { 217 WP_CLI::error( __( 'Use --key or --email, not both.', 'nanopost-email-check' ) ); 218 } 219 if ( isset( $assoc_args['email'] ) && ! is_email( $email ) ) { 220 WP_CLI::error( __( 'The --email value is not a valid email address.', 'nanopost-email-check' ) ); 221 } 222 if ( '' === $email && '' === $key ) { 223 $key = NanoPost_Email_Check_Key::constant_key(); 224 if ( '' === $key ) { 225 WP_CLI::error( __( 'Give --key or --email, or set NANOPOST_EMAIL_CHECK_KEY in wp-config.php.', 'nanopost-email-check' ) ); 226 } 227 } 228 if ( NanoPost_Email_Check_Connection::is_connected() ) { 229 WP_CLI::error( __( 'Email Canary is already set up for this site. Turn it off on the plugin screen first.', 'nanopost-email-check' ) ); 230 } 231 232 $call = '' !== $key ? NanoPost_Email_Check_Key::connect( $key ) : NanoPost_Email_Check_App::connect( $email ); 233 if ( ! $call['ok'] ) { 234 if ( in_array( $call['error'], array( NanoPost_Email_Check_Key::ERROR_INVALID, NanoPost_Email_Check_Key::ERROR_EXISTS ), true ) ) { 235 WP_CLI::error( NanoPost_Email_Check_Key::error_text( $call['error'] ) ); 236 } 237 $detail = '' !== $call['message'] ? $call['message'] : ( 0 === $call['code'] ? $call['error'] : 'HTTP ' . $call['code'] ); 238 /* translators: %s: error text or HTTP status. */ 239 WP_CLI::error( sprintf( __( 'Email Canary did not turn on: %s', 'nanopost-email-check' ), $detail ) ); 240 } 241 242 $block = NanoPost_Email_Check_Canary::block(); 243 $results = NanoPost_Email_Check_Plugin::run_checks( NanoPost_Email_Check_Result::TRIGGER_CLI ); 244 if ( ! empty( $results ) && '' !== $results[0]->test_id ) { 245 /* translators: %s: test ID. */ 246 WP_CLI::log( sprintf( __( 'A test email went out (test %s).', 'nanopost-email-check' ), $results[0]->test_id ) ); 247 } 248 $address = NanoPost_Email_Check_Admin::alert_address( $block ); 249 if ( null !== $block && 'over_limit' === $block['watching'] ) { 250 WP_CLI::error( __( 'Email Canary: alerts are OFF. Your nanoPost account has reached its limit of sites. Remove one in nanoPost, or ask us for more.', 'nanopost-email-check' ) ); 251 } 252 if ( null !== $block && 'unconfirmed' === $block['watching'] ) { 253 /* translators: %s: email address. */ 254 WP_CLI::success( sprintf( __( 'Email Canary is on. We sent a confirm email to %s. Alerts are off until it is confirmed.', 'nanopost-email-check' ), $address ) ); 255 return; 256 } 257 /* translators: %s: email address. */ 258 WP_CLI::success( sprintf( __( 'Email Canary is on. Alerts go to %s.', 'nanopost-email-check' ), $address ) ); 180 259 } 181 260 -
nanopost-email-check/trunk/includes/class-nanopost-email-check-connection.php
r3830659 r3832012 51 51 'site_hash' => '', 52 52 'alert_email' => '', 53 'pending_for' => '', 53 54 'pending_at' => 0, 54 55 ); … … 65 66 * Start "Turn on Email Canary": the token the plugin makes for the connect call. It is 66 67 * stored before the call, so a retry sends the same token and the app does not make a 67 * second canary. A pending token for the same address is used again; another address 68 * gets a new token. Two requests at the same time get the same token (add_option()). 69 * 70 * @param string $email Alert address. 68 * second canary. A pending token for the same address (or the same key) is used again; 69 * another one gets a new token. Two requests at the same time get the same token 70 * (add_option()). 71 * 72 * @param string $identity The alert address, or "key:" and the key's fingerprint. 73 * @param string $email The alert address to keep, or '' for a key. 71 74 * @return string The token, or '' while a connection with an address exists (except 72 75 * for a canary that was not confirmed, which connects again). 73 76 */ 74 public static function begin( $email ) { 77 public static function begin( $identity, $email = null ) { 78 $email = null === $email ? (string) $identity : (string) $email; 75 79 $current = self::get(); 80 // A connection stored by 1.8.0 has no pending_for: its alert address stands in. 81 if ( '' === $current['pending_for'] ) { 82 $current['pending_for'] = $current['alert_email']; 83 } 76 84 if ( '' !== $current['address'] && '' !== $current['token'] ) { 77 85 // A canary that was not confirmed in 24 hours: connect again with its token. 78 86 $block = NanoPost_Email_Check_Canary::block(); 79 return null !== $block && 'not_confirmed' === $block['stopped_reason'] && $ email === $current['alert_email'] ? $current['token'] : '';80 } 81 if ( '' !== $current['token'] && $ email === $current['alert_email'] ) {87 return null !== $block && 'not_confirmed' === $block['stopped_reason'] && $identity === $current['pending_for'] ? $current['token'] : ''; 88 } 89 if ( '' !== $current['token'] && $identity === $current['pending_for'] ) { 82 90 return $current['token']; 83 91 } 84 92 $pending = array( 85 93 'token' => self::new_token(), 86 'alert_email' => (string) $email, 94 'alert_email' => $email, 95 'pending_for' => (string) $identity, 87 96 'pending_at' => time(), 88 97 'home_url' => home_url(), … … 92 101 wp_cache_delete( self::OPTION, 'options' ); 93 102 $current = self::get(); 94 if ( $ email === $current['alert_email'] && '' !== $current['token'] ) {103 if ( $identity === $current['pending_for'] && '' !== $current['token'] ) { 95 104 return $current['token']; 96 105 } … … 134 143 'connected_at' => time(), 135 144 'alert_email' => $current['alert_email'], 145 'pending_for' => $current['pending_for'], 136 146 'site_hash' => (string) $site_hash, 137 147 ), -
nanopost-email-check/trunk/includes/class-nanopost-email-check-help.php
r3830659 r3832012 115 115 const CANARY_STOP = 'stop-watching'; 116 116 const CANARY_SENT = 'what-is-sent-to-nanopost'; 117 const CANARY_KEY = 'turn-on-with-an-account-key'; 117 118 118 119 /** -
nanopost-email-check/trunk/includes/class-nanopost-email-check-plugin.php
r3830659 r3832012 22 22 NanoPost_Email_Check_App::init(); 23 23 NanoPost_Email_Check_Canary::init(); 24 NanoPost_Email_Check_Key::init(); 24 25 25 26 if ( is_admin() ) { -
nanopost-email-check/trunk/includes/class-nanopost-email-check-scheduler.php
r3830659 r3832012 107 107 wp_clear_scheduled_hook( NanoPost_Email_Check_App::SYNC_HOOK ); 108 108 wp_clear_scheduled_hook( NanoPost_Email_Check_App::START_HOOK ); 109 wp_clear_scheduled_hook( NanoPost_Email_Check_Key::HOOK ); 109 110 wp_unschedule_hook( NanoPost_Email_Check_Canary::FETCH_HOOK ); 110 111 return; … … 117 118 wp_clear_scheduled_hook( NanoPost_Email_Check_App::SYNC_HOOK ); 118 119 wp_clear_scheduled_hook( NanoPost_Email_Check_App::START_HOOK ); 120 wp_clear_scheduled_hook( NanoPost_Email_Check_Key::HOOK ); 119 121 wp_unschedule_hook( NanoPost_Email_Check_Canary::FETCH_HOOK ); 120 122 restore_current_blog(); -
nanopost-email-check/trunk/nanopost-email-check.php
r3830659 r3832012 4 4 * Plugin URI: https://nanopo.st/email-check-plugin/ 5 5 * Description: Check that your site can still send email. Sends a scheduled test email, logs each result and warns you when a check fails. 6 * Version: 1. 8.06 * Version: 1.9.0 7 7 * Requires at least: 6.4 8 8 * Requires PHP: 7.4 … … 18 18 defined( 'ABSPATH' ) || exit; 19 19 20 define( 'NANOPOST_EMAIL_CHECK_VERSION', '1. 8.0' );20 define( 'NANOPOST_EMAIL_CHECK_VERSION', '1.9.0' ); 21 21 define( 'NANOPOST_EMAIL_CHECK_FILE', __FILE__ ); 22 22 define( 'NANOPOST_EMAIL_CHECK_DIR', plugin_dir_path( __FILE__ ) ); … … 36 36 require_once NANOPOST_EMAIL_CHECK_DIR . 'includes/class-nanopost-email-check-app.php'; 37 37 require_once NANOPOST_EMAIL_CHECK_DIR . 'includes/class-nanopost-email-check-canary.php'; 38 require_once NANOPOST_EMAIL_CHECK_DIR . 'includes/class-nanopost-email-check-key.php'; 38 39 require_once NANOPOST_EMAIL_CHECK_DIR . 'includes/class-nanopost-email-check-admin.php'; 39 40 -
nanopost-email-check/trunk/readme.txt
r3830659 r3832012 5 5 Tested up to: 7.1 6 6 Requires PHP: 7.4 7 Stable tag: 1. 8.07 Stable tag: 1.9.0 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 121 121 `run` and `test-alert` have no once-a-minute limit. On multisite, choose the site with `--url`. For details, run `wp help email-check`, or read [settings in code and WP-CLI](https://nanopo.st/email-check-plugin/code-and-cli/). 122 122 123 = Can I turn on Email Canary on many sites at once? = 124 125 Yes, with an account key. Make one in nanoPost (Settings > Profile > Account key), then add `define( 'NANOPOST_EMAIL_CHECK_KEY', '...' );` to `wp-config.php`, or run `wp email-check connect --key=...` on each site. Email Canary then turns on by itself, with alerts to your nanoPost account's address and no confirm email. The key only adds sites; it cannot read your account. It turns a site on once: not again after you turn it off, and not on a copy of the site at another address or on a site address that is not public. On a multisite network, the constant turns on only the main site; use WP-CLI with `--url` for the other sites. 126 123 127 = Does it work on multisite? = 124 128 … … 145 149 = nanoPost Email Canary (optional, after you turn it on) = 146 150 147 nanoPost Email Canary (app.nanopo.st) is a service run by the plugin's authors. It checks that each test email arrives, and emails you when one does not. The plugin calls it only after you type an alert address and click "Turn on Email Canary" on the plugin screen . Until then, nothing is sent. When you turn it off, deactivate the plugin or delete it, the plugin tells Email Canary.151 nanoPost Email Canary (app.nanopo.st) is a service run by the plugin's authors. It checks that each test email arrives, and emails you when one does not. The plugin calls it only after you type an alert address and click "Turn on Email Canary" on the plugin screen, or after you set a nanoPost account key in `wp-config.php` or run `wp email-check connect`. Until then, nothing is sent. When you turn it off, deactivate the plugin or delete it, the plugin tells Email Canary. 148 152 149 153 While Email Canary is on, the site sends: 150 154 151 155 * when you turn it on: the site address, the alert address you typed, the site's time zone, the test interval, the webhook URL if you set one, the versions of the plugin, WordPress and PHP, and a random key that the plugin makes for this site; 156 * if you set a nanoPost account key (in `wp-config.php` or with WP-CLI) in place of an alert address: that key, once, in the call that turns Email Canary on. The plugin does not store it; 152 157 * the same site settings again when one of them changes; 153 158 * for each test: a test ID, the time it was sent, what started it (the schedule, a user or WP-CLI), whether WordPress accepted the email, and its error text if it did not (at most 500 characters; it can contain host names or email addresses); … … 191 196 192 197 == Changelog == 198 199 = 1.9.0 = 200 * Account key for agencies: `NANOPOST_EMAIL_CHECK_KEY` in `wp-config.php` turns Email Canary on by itself, once per site address, with alerts to the nanoPost account's address and no confirm email. The key is never stored. 201 * New WP-CLI command `wp email-check connect`, with `--key` or `--email`. 193 202 194 203 = 1.8.0 = -
nanopost-email-check/trunk/uninstall.php
r3830659 r3832012 60 60 wp_unschedule_hook( 'nanopost_email_check_fetch_test' ); 61 61 wp_clear_scheduled_hook( 'nanopost_email_check_start' ); 62 delete_option( 'nanopost_email_check_key_state' ); 63 wp_clear_scheduled_hook( 'nanopost_email_check_key_connect' ); 62 64 delete_option( 'nanopost_email_check_settings' ); 63 65 delete_option( 'nanopost_email_check_log' );
Note:
See TracChangeset
for help on using the changeset viewer.