Plugin Directory

Changeset 3841430


Ignore:
Timestamp:
12/03/2026 01:27:43 AM (less than one hour ago)
Author:
rotosix
Message:

Release 0.2.0

Location:
clonemute
Files:
8 added
14 edited
1 copied

Legend:

Unmodified
Added
Removed
  • clonemute/tags/0.2.0/clonemute.php

    r3828539 r3841430  
    44 * Plugin URI:        https://wordpress.org/plugins/clonemute/
    55 * Description:       Makes cloned WooCommerce sites safe: after you confirm a copy is a staging site, CloneMute blocks outgoing mail, payment gateways, scheduled tasks and known external services, and hides the site from search engines.
    6  * Version:           0.1.0
     6 * Version:           0.2.0
    77 * Requires at least: 7.0
    88 * Requires PHP:      7.4
  • clonemute/tags/0.2.0/languages/clonemute.pot

    r3828539 r3841430  
    33msgid ""
    44msgstr ""
    5 "Project-Id-Version: CloneMute Staging Safety for WooCommerce 0.1.0\n"
     5"Project-Id-Version: CloneMute Staging Safety for WooCommerce 0.2.0\n"
    66"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/clonemute\n"
    77"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
    … …  
    1010"Content-Type: text/plain; charset=UTF-8\n"
    1111"Content-Transfer-Encoding: 8bit\n"
    12 "POT-Creation-Date: 2026-11-26T01:23:54+00:00\n"
     12"POT-Creation-Date: 2026-12-02T09:24:48+00:00\n"
    1313"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
    1414"X-Generator: WP-CLI 2.12.0\n"
    … …  
    4040msgstr ""
    4141
    42 #: src/Admin/AdminActions.php:410
     42#: src/Admin/AdminActions.php:464
    4343msgid "CloneMute test mail"
    4444msgstr ""
    4545
    46 #: src/Admin/AdminActions.php:411
     46#: src/Admin/AdminActions.php:465
    4747msgid "If you can read this, mail is leaving this site. On a staging site that means the mail guard is not active."
    4848msgstr ""
    … …  
    7272msgstr ""
    7373
    74 #: src/Admin/Notices.php:88
     74#: src/Admin/Messages.php:23
    7575msgid "Protection is on. This site is now treated as a staging site."
    7676msgstr ""
    7777
    78 #: src/Admin/Notices.php:89
     78#: src/Admin/Messages.php:24
    7979msgid "Saved as a staging site, but CLONEMUTE_DISABLE_ALL in wp-config.php keeps every protection off. Remove that line to turn the protections on."
    8080msgstr ""
    8181
    82 #: src/Admin/Notices.php:90
     82#: src/Admin/Messages.php:25
    8383msgid "The host name does not match. Nothing was changed."
    8484msgstr ""
    8585
    86 #: src/Admin/Notices.php:91
     86#: src/Admin/Messages.php:26
    8787msgid "Protection cannot be enabled on this site (see the reasons below). Nothing was changed."
    8888msgstr ""
    8989
    90 #: src/Admin/Notices.php:92
     90#: src/Admin/Messages.php:27
    9191msgid "Recorded as a production site. No protection is enabled."
    9292msgstr ""
    9393
    94 #: src/Admin/Notices.php:93
     94#: src/Admin/Messages.php:28
    9595msgid "This site is protected as a staging site (or CLONEMUTE_ENV arms it). Remove the protection first if this really is the production site. Nothing was changed."
    9696msgstr ""
    9797
    98 #: src/Admin/Notices.php:94
     98#: src/Admin/Messages.php:29
    9999msgid "The production confirmation of this site was removed. CloneMute treats it as unconfirmed again."
    100100msgstr ""
    101101
    102 #: src/Admin/Notices.php:95
     102#: src/Admin/Messages.php:30
     103msgid "This site has no production confirmation to remove. Nothing was changed."
     104msgstr ""
     105
     106#: src/Admin/Messages.php:31
     107msgid "The address of this site cannot be read (its home URL has no host). Nothing was changed. With WP-CLI, pass --url=<site address>."
     108msgstr ""
     109
     110#: src/Admin/Messages.php:32
    103111msgid "OK, CloneMute will ask again the next time you log in."
    104112msgstr ""
    105113
    106 #: src/Admin/Notices.php:96
     114#: src/Admin/Messages.php:33
    107115msgid "All protections were removed. Scheduled tasks that were paused will run again and may run in a burst."
    108116msgstr ""
    109117
    110 #: src/Admin/Notices.php:97
     118#: src/Admin/Messages.php:34
    111119msgid "CLONEMUTE_ENV is set to \"staging\" in wp-config.php, so protection would come back on the next page load. Remove that line first. Nothing was changed."
    112120msgstr ""
    113121
    114 #: src/Admin/Notices.php:98
     122#: src/Admin/Messages.php:35
    115123msgid "Test mail handed to the mail system. Check your inbox: if it arrives, mail is leaving this site."
    116124msgstr ""
    117125
    118 #: src/Admin/Notices.php:99
     126#: src/Admin/Messages.php:36
    119127msgid "CloneMute stopped the test mail: mail protection works. It is listed under the blocked events."
    120128msgstr ""
    121129
    122 #: src/Admin/Notices.php:100
     130#: src/Admin/Messages.php:37
    123131msgid "The test mail was not sent: the server could not send it."
    124132msgstr ""
    125133
    126 #: src/Admin/Notices.php:101
     134#: src/Admin/Messages.php:38
    127135msgid "Added to the allow list."
    128136msgstr ""
    129137
    130 #: src/Admin/Notices.php:102
     138#: src/Admin/Messages.php:39
    131139msgid "That value cannot be added to an allow list."
    132140msgstr ""
    133141
     142#: src/Admin/Messages.php:40
     143msgid "The error message was dismissed. No protection was changed."
     144msgstr ""
     145
     146#: src/Admin/Messages.php:41
     147msgid "Something went wrong. Nothing was changed."
     148msgstr ""
     149
    134150#: src/Admin/Notices.php:103
    135 msgid "The error message was dismissed. No protection was changed."
     151msgid "CloneMute: the recorded staging host does not match this site. Protection is OFF."
    136152msgstr ""
    137153
    138154#: src/Admin/Notices.php:104
    139 msgid "Something went wrong. Nothing was changed."
    140 msgstr ""
    141 
    142 #: src/Admin/Notices.php:121
    143 msgid "CloneMute: the recorded staging host does not match this site. Protection is OFF."
    144 msgstr ""
    145 
    146 #: src/Admin/Notices.php:122
    147155msgid "This site was protected as a staging site under another address or on another installation, and has been moved or copied. Nothing is blocked here. If this is your production site, check that real mail and payments work again. If it is a copy of the staging site, protect it again on the CloneMute status page."
    148156msgstr ""
    149157
    150 #: src/Admin/Notices.php:123
    151 #: src/Admin/Notices.php:135
     158#: src/Admin/Notices.php:105
     159#: src/Admin/Notices.php:117
    152160#: src/Admin/Wizard.php:121
    153161#: src/Admin/Wizard.php:136
    … …  
    155163msgstr ""
    156164
    157 #: src/Admin/Notices.php:126
     165#: src/Admin/Notices.php:108
    158166#: src/Admin/Pages.php:136
    159167msgid "Send a test mail to me"
    160168msgstr ""
    161169
    162 #: src/Admin/Notices.php:129
     170#: src/Admin/Notices.php:111
    163171msgid "CloneMute: this site is armed but matches a production safeguard. Protection is OFF."
    164172msgstr ""
    165173
     174#: src/Admin/Notices.php:115
     175msgid "CloneMute: the saved settings are unreadable. Nothing is blocked."
     176msgstr ""
     177
     178#: src/Admin/Notices.php:116
     179msgid "Reset the saved state on the CloneMute status page, then check the environment and the settings."
     180msgstr ""
     181
     182#: src/Admin/Notices.php:119
     183msgid "CloneMute: an internal error occurred. Nothing is blocked."
     184msgstr ""
     185
    166186#: src/Admin/Notices.php:133
    167 msgid "CloneMute: the saved settings are unreadable. Nothing is blocked."
    168 msgstr ""
    169 
    170 #: src/Admin/Notices.php:134
    171 msgid "Reset the saved state on the CloneMute status page, then check the environment and the settings."
    172 msgstr ""
    173 
     187msgid "CloneMute: STAGING protection is active."
     188msgstr ""
     189
     190#. translators: %d: number of active protections
    174191#: src/Admin/Notices.php:137
    175 msgid "CloneMute: an internal error occurred. Nothing is blocked."
    176 msgstr ""
    177 
    178 #: src/Admin/Notices.php:151
    179 msgid "CloneMute: STAGING protection is active."
    180 msgstr ""
    181 
    182 #. translators: %d: number of active protections
    183 #: src/Admin/Notices.php:155
    184192#, php-format
    185193msgid "%d protection is on."
    … …  
    188196msgstr[1] ""
    189197
    190 #: src/Admin/Notices.php:159
     198#: src/Admin/Notices.php:141
    191199#: vendor-prefixed/rotosix-core/src/Log/LogPage.php:67
    192200msgid "Details"
    193201msgstr ""
    194202
    195 #: src/Admin/Notices.php:162
     203#: src/Admin/Notices.php:144
    196204#: src/Admin/Pages.php:133
    197205msgid "Remove all protections"
    198206msgstr ""
    199207
    200 #: src/Admin/Notices.php:178
     208#: src/Admin/Notices.php:160
    201209msgid "CloneMute: CLONEMUTE_ENV is set to \"staging\" in wp-config.php, but protection cannot be enabled on this site. Nothing is blocked."
    202210msgstr ""
    203211
    204212#. translators: 1: protection name, 2: error class, 3: date and time (UTC)
    205 #: src/Admin/Notices.php:199
     213#: src/Admin/Notices.php:181
    206214#, php-format
    207215msgid "CloneMute: the \"%1$s\" protection hit an error (%2$s, %3$s UTC) and let a request through."
    208216msgstr ""
    209217
     218#: src/Admin/Notices.php:188
     219msgid "Dismiss this message"
     220msgstr ""
     221
     222#: src/Admin/Notices.php:189
     223msgid "Dismissing changes no protection. The message comes back if the error happens again."
     224msgstr ""
     225
     226#. translators: %s: list of constants
    210227#: src/Admin/Notices.php:206
    211 msgid "Dismiss this message"
    212 msgstr ""
    213 
    214 #: src/Admin/Notices.php:207
    215 msgid "Dismissing changes no protection. The message comes back if the error happens again."
    216 msgstr ""
    217 
    218 #. translators: %s: list of constants
    219 #: src/Admin/Notices.php:224
    220228#, php-format
    221229msgid "CloneMute: overridden by constant in wp-config: %s"
    … …  
    223231
    224232#. translators: %s: file name
    225 #: src/Admin/Notices.php:243
     233#: src/Admin/Notices.php:225
    226234#, php-format
    227235msgid "The wp_mail() function is replaced by %s. CloneMute may not be able to see or change mail sent through it; mail services that use the WordPress HTTP API are still covered by the outbound request block."
    … …  
    813821msgstr ""
    814822
     823#: src/Cli/Commands.php:170
     824msgid "The stored CloneMute settings cannot be read. Nothing is blocked until the state is set again."
     825msgstr ""
     826
     827#: src/Cli/Commands.php:200
     828msgid "Saved as a staging site, but the protection is not active on this site."
     829msgstr ""
     830
     831#: src/Cli/Commands.php:281
     832msgid "Pass --host=<host>: this site's address as `wp clonemute status` shows it."
     833msgstr ""
     834
     835#. translators: %s: the reasons, joined
     836#: src/Cli/Commands.php:306
     837#, php-format
     838msgid "Protection cannot be enabled on this site: %s Nothing was changed."
     839msgstr ""
     840
     841#. translators: %s: this site's host key
     842#: src/Cli/Commands.php:310
     843#, php-format
     844msgid "This site is %s (on a network, choose the site with --url)."
     845msgstr ""
     846
     847#: src/Cli/Commands.php:340
     848msgid "The stored settings could not be read and were replaced by the defaults. Check the production domains and the other settings."
     849msgstr ""
     850
     851#: src/Cli/Commands.php:342
     852msgid "The stored state was invalid and has been replaced; the other settings were kept."
     853msgstr ""
     854
     855#: src/Cli/Commands.php:355
     856msgid "WP_ENVIRONMENT_TYPE is not set for WP-CLI. If only the web server sets it (fastcgi_param, SetEnv, PHP-FPM env), WP-CLI cannot check it: when it is \"production\" there, web requests stay unprotected. Check the CloneMute page in the admin."
     857msgstr ""
     858
     859#: src/Cli/Commands.php:369
     860msgid "Nothing was changed: the site was already in that state."
     861msgstr ""
     862
     863#: src/Cli/Commands.php:398
     864#: vendor-prefixed/rotosix-core/src/Api/CliCommands.php:217
     865msgid "Unknown --format; use table or json."
     866msgstr ""
     867
     868#: src/Cli/Commands.php:436
     869#: vendor-prefixed/rotosix-core/src/Api/CliCommands.php:250
     870msgid "Write commands are disabled in this environment."
     871msgstr ""
     872
     873#: src/Cli/Commands.php:440
     874#: vendor-prefixed/rotosix-core/src/Api/CliCommands.php:253
     875#: vendor-prefixed/rotosix-core/src/Api/RestRegistrar.php:63
     876msgid "Sorry, you are not allowed to do that."
     877msgstr ""
     878
    815879#: src/Guard/HttpGuard.php:148
    816880msgid "Request blocked by CloneMute (test site)."
    … …  
    9921056msgstr ""
    9931057
    994 #: vendor-prefixed/rotosix-core/src/Api/CliCommands.php:217
    995 msgid "Unknown --format; use table or json."
    996 msgstr ""
    997 
    998 #: vendor-prefixed/rotosix-core/src/Api/CliCommands.php:250
    999 msgid "Write commands are disabled in this environment."
    1000 msgstr ""
    1001 
    1002 #: vendor-prefixed/rotosix-core/src/Api/CliCommands.php:253
    1003 #: vendor-prefixed/rotosix-core/src/Api/RestRegistrar.php:63
    1004 msgid "Sorry, you are not allowed to do that."
    1005 msgstr ""
    1006 
    10071058#: vendor-prefixed/rotosix-core/src/Api/ErrorFactory.php:102
    10081059msgid "This batch has no rollback point."
  • clonemute/tags/0.2.0/readme.txt

    r3828539 r3841430  
    55Tested up to: 7.2
    66Requires PHP: 7.4
    7 Stable tag: 0.1.0
     7Stable tag: 0.2.0
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
    … …  
    51513. On a live site open the CloneMute page and choose "This is the new production site". CloneMute blocks nothing either way, but other Rotosix plugins (for example the scheduled imports of CatalogRelay) pause their scheduled work until the site is confirmed as production.
    5252
    53 To pre-confirm a clone in a script, define `define( 'CLONEMUTE_ENV', 'staging' );` in `wp-config.php` of the copy. Safeguards still apply: the constant is refused on hosts you listed or confirmed as production and when `WP_ENVIRONMENT_TYPE` is explicitly `production`, and the admin says so.
     53= WP-CLI =
     54
     55Confirm a copy from your clone script right after the copy is made:
     56
     57`wp clonemute arm --host=stg.example.com`
     58
     59This is the same confirmation as in the admin, with the same safeguards: it is refused on hosts you listed or confirmed as production and when `WP_ENVIRONMENT_TYPE` is explicitly `production`. WP-CLI only sees a `WP_ENVIRONMENT_TYPE` defined in `wp-config.php` or set in its own environment: a value set only in the web server configuration (fastcgi_param, SetEnv, PHP-FPM env) cannot be checked, so `arm` warns when it sees none, and you should check the CloneMute page in the admin. `--host` is this site's address without the scheme, with the port and the sub-directory if there is one, exactly as `wp clonemute status` shows it. On a multisite network choose the site with `--url=<site address>`.
     60
     61* `wp clonemute status [--format=json]` shows the state, why the site is or is not protected and the state of every protection.
     62* `wp clonemute disarm` removes every protection.
     63* `wp clonemute production confirm` records the site as the production site; `wp clonemute production forget --host=<host>` removes that record.
     64
     65Exit codes: 0 success (also when nothing had to change), 1 refused or failed, 2 saved as a staging site but no protection is active (for example because of `CLONEMUTE_DISABLE_ALL`). With `--format=json` the result or the error is one JSON document on standard output; messages go to standard error. Changes made with WP-CLI are marked "(WP-CLI)" in the event log.
     66
     67Without WP-CLI you can pre-confirm a clone with `define( 'CLONEMUTE_ENV', 'staging' );` in `wp-config.php` of the copy. The same safeguards apply, the admin says when the constant is refused, and the protection cannot be removed while the constant is set.
    5468
    5569Emergency switches for `wp-config.php`: `CLONEMUTE_DISABLE_ALL`, `CLONEMUTE_DISABLE_MAIL`, `CLONEMUTE_DISABLE_PAYMENTS`, `CLONEMUTE_DISABLE_CRON`, `CLONEMUTE_DISABLE_HTTP`, `CLONEMUTE_DISABLE_GATE` (login gate and REST limit).
    … …  
    7993== Changelog ==
    8094
     95= 0.2.0 =
     96* New: WP-CLI commands `wp clonemute status`, `arm --host=<host>`, `disarm`, `production confirm` and `production forget --host=<host>`, with `--format=json`. They make the same checks as the admin screens.
     97* State changes made with WP-CLI are marked in the event log.
     98
    8199= 0.1.0 =
    82100* First release: environment suggestions with explicit confirmation, mail, payment, scheduled task, outbound request, search engine and REST protections, read-only report, event log with privacy tools.
    … …  
    84102== Upgrade Notice ==
    85103
     104= 0.2.0 =
     105Adds WP-CLI commands to confirm a copy from a clone script. No setting changes.
     106
    86107= 0.1.0 =
    87108First release.
  • clonemute/tags/0.2.0/src/Admin/AdminActions.php

    r3828539 r3841430  
    2727 */
    2828final class AdminActions {
     29
     30        /**
     31         * Origins of a state change (written to the state_change log).
     32         */
     33        const ORIGIN_ADMIN = 'admin';
     34        const ORIGIN_CLI   = 'cli';
    2935
    3036        const STATE_ACTIONS = array( 'arm', 'production', 'forget_production', 'later', 'disarm' );
    … …  
    159165         * "This is staging": recompute the hard blocks, compare the typed host, then arm.
    160166         *
    161          * @param array $post Submitted fields.
    162          * @return array
    163          */
    164         public static function arm( array $post ): array {
     167         * @param array  $post   Submitted fields.
     168         * @param string $origin Where the request came from (ORIGIN_ADMIN or ORIGIN_CLI).
     169         * @return array {ok, code, changed, blocks?}
     170         */
     171        public static function arm( array $post, string $origin = self::ORIGIN_ADMIN ): array {
    165172                $s    = SettingsRepo::load();
    166173                $snap = EnvCapture::capture( $s, true );
    167                 $t    = StateMachine::arm( $snap, isset( $post['host'] ) ? (string) $post['host'] : '', time() );
     174                if ( self::ORIGIN_CLI === $origin ) {
     175                        // WP-CLI sets the Host header from --url or wp-cli.yml (operator configuration copied with the files, not a
     176                        // client header): judge it like any later request, without the request host.
     177                        $snap->request_host = '';
     178                }
     179                $t = StateMachine::arm( $snap, isset( $post['host'] ) ? (string) $post['host'] : '', time() );
    168180                if ( ! $t->ok ) {
    169181                        $codes = array(
    170182                                'hard_block'    => 'arm_blocked',
    171183                                'host_mismatch' => 'arm_host',
    172                                 'no_host'       => 'arm_blocked',
    173                         );
    174                         return array(
    175                                 'ok'   => false,
    176                                 'code' => $codes[ $t->error ] ?? 'error',
    177                         );
     184                                'no_host'       => 'no_host',
     185                        );
     186                        $out   = array(
     187                                'ok'      => false,
     188                                'code'    => $codes[ $t->error ] ?? 'error',
     189                                'changed' => false,
     190                        );
     191                        if ( 'hard_block' === $t->error ) {
     192                                $out['blocks'] = $t->blocks;
     193                        }
     194                        return $out;
    178195                }
    179196                $code = Constants::disableAll() ? 'armed_off' : 'armed'; // Saved, but CLONEMUTE_DISABLE_ALL keeps every guard off.
    … …  
    181198                        // Already armed for this site (a second submit of the form): keep "since" and log nothing.
    182199                        return array(
    183                                 'ok'   => true,
    184                                 'code' => $code,
     200                                'ok'      => true,
     201                                'code'    => $code,
     202                                'changed' => false,
    185203                        );
    186204                }
    187205                if ( ! self::write( $t->changes ) ) {
    188                         return array(
    189                                 'ok'   => false,
    190                                 'code' => 'error',
    191                         );
     206                        return self::failed();
    192207                }
    193208                Runtime::clearError();
    194                 LogWriter::event( 'state_change', 'state', StateMachine::fromLabel( $s, $snap ) . ' -> armed', array( 'to' => 'armed' ) );
    195                 return array(
    196                         'ok'   => true,
    197                         'code' => $code,
     209                self::logState( StateMachine::fromLabel( $s, $snap ) . ' -> armed', 'armed', $origin );
     210                return array(
     211                        'ok'      => true,
     212                        'code'    => $code,
     213                        'changed' => true,
    198214                );
    199215        }
    … …  
    202218         * "This is the new production site": record the fingerprint, enable nothing.
    203219         *
    204          * @return array
    205          */
    206         public static function production(): array {
     220         * @param string $origin Where the request came from.
     221         * @return array {ok, code, changed}
     222         */
     223        public static function production( string $origin = self::ORIGIN_ADMIN ): array {
    207224                $s    = SettingsRepo::load();
    208225                $snap = EnvCapture::capture( $s, false );
    … …  
    211228                        // lock the host as production. Removing the protection is a separate, explicit step.
    212229                        return array(
    213                                 'ok'   => false,
    214                                 'code' => 'production_armed',
     230                                'ok'      => false,
     231                                'code'    => 'production_armed',
     232                                'changed' => false,
    215233                        );
    216234                }
    … …  
    218236                if ( ! $t->ok ) {
    219237                        return array(
    220                                 'ok'   => false,
    221                                 'code' => 'error',
     238                                'ok'      => false,
     239                                'code'    => 'no_host',
     240                                'changed' => false,
    222241                        );
    223242                }
    … …  
    227246                if ( ! $again ) {
    228247                        if ( ! self::write( $t->changes ) ) {
    229                                 return array(
    230                                         'ok'   => false,
    231                                         'code' => 'error',
    232                                 );
     248                                return self::failed();
    233249                        }
    234                         LogWriter::event( 'state_change', 'state', StateMachine::fromLabel( $s, $snap ) . ' -> production', array( 'to' => 'production' ) );
     250                        self::logState( StateMachine::fromLabel( $s, $snap ) . ' -> production', 'production', $origin );
    235251                }
    236252                Runtime::clearError(); // No guard runs on a production site: an earlier guard error no longer applies.
    237253                return array(
    238                         'ok'   => true,
    239                         'code' => 'production',
     254                        'ok'      => true,
     255                        'code'    => 'production',
     256                        'changed' => ! $again,
    240257                );
    241258        }
    … …  
    244261         * Forget the production confirmation of this host after the host name was typed (the way back from "production").
    245262         *
    246          * @param array $post Submitted fields.
    247          * @return array
    248          */
    249         public static function forgetProduction( array $post ): array {
     263         * @param array  $post   Submitted fields.
     264         * @param string $origin Where the request came from.
     265         * @return array {ok, code, changed}
     266         */
     267        public static function forgetProduction( array $post, string $origin = self::ORIGIN_ADMIN ): array {
    250268                $s     = SettingsRepo::load();
    251269                $snap  = EnvCapture::capture( $s, false );
    … …  
    255273                        // No confirmation for this host (any more): a second submit of the form. Nothing to remove, nothing to log.
    256274                        return array(
    257                                 'ok'   => true,
    258                                 'code' => 'prod_forgotten',
     275                                'ok'      => true,
     276                                'code'    => 'prod_forgotten',
     277                                'changed' => false,
    259278                        );
    260279                }
    261280                if ( ! $t->ok ) {
    262                         return array(
    263                                 'ok'   => false,
    264                                 'code' => 'host_mismatch' === $t->error ? 'arm_host' : 'error',
     281                        $codes = array(
     282                                'host_mismatch'  => 'arm_host',
     283                                'not_production' => 'prod_none',
     284                                'no_host'        => 'no_host',
     285                        );
     286                        return array(
     287                                'ok'      => false,
     288                                'code'    => $codes[ $t->error ] ?? 'error',
     289                                'changed' => false,
    265290                        );
    266291                }
    267292                if ( ! self::write( $t->changes ) ) {
    268                         return array(
    269                                 'ok'   => false,
    270                                 'code' => 'error',
    271                         );
     293                        return self::failed();
    272294                }
    273295                Runtime::clearError();
    274                 LogWriter::event( 'state_change', 'state', StateMachine::fromLabel( $s, $snap ) . ' -> ' . ( $t->changes['state'] ?? $s->state ) . ' (production confirmation removed)', array( 'to' => $t->changes['state'] ?? $s->state ) );
    275                 return array(
    276                         'ok'   => true,
    277                         'code' => 'prod_forgotten',
     296                $to = $t->changes['state'] ?? $s->state;
     297                self::logState( StateMachine::fromLabel( $s, $snap ) . ' -> ' . $to . ' (production confirmation removed)', $to, $origin );
     298                return array(
     299                        'ok'      => true,
     300                        'code'    => 'prod_forgotten',
     301                        'changed' => true,
    278302                );
    279303        }
    … …  
    295319         * Remove every guard at once.
    296320         *
    297          * @return array
    298          */
    299         public static function disarm(): array {
     321         * @param string $origin Where the request came from.
     322         * @return array {ok, code, changed}
     323         */
     324        public static function disarm( string $origin = self::ORIGIN_ADMIN ): array {
    300325                $s = SettingsRepo::load();
    301326                $t = StateMachine::disarm( $s, time() );
    … …  
    303328                        // CLONEMUTE_ENV would arm the site again on the next request: report that instead of a success that does not stick.
    304329                        return array(
    305                                 'ok'   => false,
    306                                 'code' => 'disarm_const',
     330                                'ok'      => false,
     331                                'code'    => 'disarm_const',
     332                                'changed' => false,
    307333                        );
    308334                }
    309335                if ( $t->changes ) {
    310336                        if ( ! self::write( $t->changes ) ) {
    311                                 return array(
    312                                         'ok'   => false,
    313                                         'code' => 'error',
    314                                 );
     337                                return self::failed();
    315338                        }
    316                         LogWriter::event( 'state_change', 'state', StateMachine::fromLabel( $s, EnvCapture::capture( $s, false ) ) . ' -> unconfirmed', array( 'to' => 'unconfirmed' ) );
     339                        self::logState( StateMachine::fromLabel( $s, EnvCapture::capture( $s, false ) ) . ' -> unconfirmed', 'unconfirmed', $origin );
    317340                }
    318341                Runtime::clearError();
    319342                return array(
    320                         'ok'   => true,
    321                         'code' => 'disarmed',
    322                 );
     343                        'ok'      => true,
     344                        'code'    => 'disarmed',
     345                        'changed' => (bool) $t->changes,
     346                );
     347        }
     348
     349        /**
     350         * Result of a write that did not stick.
     351         *
     352         * @return array
     353         */
     354        private static function failed(): array {
     355                return array(
     356                        'ok'      => false,
     357                        'code'    => 'error',
     358                        'changed' => false,
     359                );
     360        }
     361
     362        /**
     363         * Log a state change with where it came from (changes made with WP-CLI say so in the summary).
     364         *
     365         * @param string $summary Summary ("from -> to").
     366         * @param string $to      New state.
     367         * @param string $origin  ORIGIN_ADMIN or ORIGIN_CLI.
     368         * @return void
     369         */
     370        private static function logState( string $summary, string $to, string $origin ): void {
     371                $context = array( 'to' => $to );
     372                if ( self::ORIGIN_CLI === $origin ) {
     373                        $summary       .= ' (WP-CLI)';
     374                        $context['via'] = 'cli';
     375                }
     376                LogWriter::event( 'state_change', 'state', $summary, $context );
    323377        }
    324378
  • clonemute/tags/0.2.0/src/Admin/Notices.php

    r3828539 r3841430  
    8585                // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- display-only code mapped through a whitelist.
    8686                $code = isset( $_GET['clonemute_msg'] ) ? sanitize_key( wp_unslash( $_GET['clonemute_msg'] ) ) : '';
    87                 $map  = array(
    88                         'armed'            => array( 'success', __( 'Protection is on. This site is now treated as a staging site.', 'clonemute' ) ),
    89                         'armed_off'        => array( 'warning', __( 'Saved as a staging site, but CLONEMUTE_DISABLE_ALL in wp-config.php keeps every protection off. Remove that line to turn the protections on.', 'clonemute' ) ),
    90                         'arm_host'         => array( 'error', __( 'The host name does not match. Nothing was changed.', 'clonemute' ) ),
    91                         'arm_blocked'      => array( 'error', __( 'Protection cannot be enabled on this site (see the reasons below). Nothing was changed.', 'clonemute' ) ),
    92                         'production'       => array( 'success', __( 'Recorded as a production site. No protection is enabled.', 'clonemute' ) ),
    93                         'production_armed' => array( 'error', __( 'This site is protected as a staging site (or CLONEMUTE_ENV arms it). Remove the protection first if this really is the production site. Nothing was changed.', 'clonemute' ) ),
    94                         'prod_forgotten'   => array( 'success', __( 'The production confirmation of this site was removed. CloneMute treats it as unconfirmed again.', 'clonemute' ) ),
    95                         'later'            => array( 'info', __( 'OK, CloneMute will ask again the next time you log in.', 'clonemute' ) ),
    96                         'disarmed'         => array( 'success', __( 'All protections were removed. Scheduled tasks that were paused will run again and may run in a burst.', 'clonemute' ) ),
    97                         'disarm_const'     => array( 'error', __( 'CLONEMUTE_ENV is set to "staging" in wp-config.php, so protection would come back on the next page load. Remove that line first. Nothing was changed.', 'clonemute' ) ),
    98                         'test_mail_sent'   => array( 'success', __( 'Test mail handed to the mail system. Check your inbox: if it arrives, mail is leaving this site.', 'clonemute' ) ),
    99                         'test_mail_caught' => array( 'success', __( 'CloneMute stopped the test mail: mail protection works. It is listed under the blocked events.', 'clonemute' ) ),
    100                         'test_mail_failed' => array( 'warning', __( 'The test mail was not sent: the server could not send it.', 'clonemute' ) ),
    101                         'allow_added'      => array( 'success', __( 'Added to the allow list.', 'clonemute' ) ),
    102                         'allow_invalid'    => array( 'error', __( 'That value cannot be added to an allow list.', 'clonemute' ) ),
    103                         'error_dismissed'  => array( 'info', __( 'The error message was dismissed. No protection was changed.', 'clonemute' ) ),
    104                         'error'            => array( 'error', __( 'Something went wrong. Nothing was changed.', 'clonemute' ) ),
    105                 );
    106                 if ( isset( $map[ $code ] ) ) {
    107                         echo '<div class="notice notice-' . esc_attr( $map[ $code ][0] ) . ' is-dismissible" role="status"><p>' . esc_html( $map[ $code ][1] ) . '</p></div>';
     87                $msg  = Messages::result( $code );
     88                if ( null !== $msg ) {
     89                        echo '<div class="notice notice-' . esc_attr( $msg[0] ) . ' is-dismissible" role="status"><p>' . esc_html( $msg[1] ) . '</p></div>';
    10890                }
    10991        }
  • clonemute/tags/0.2.0/src/Env/EnvCapture.php

    r3828539 r3841430  
    107107                return EnvSnapshot::fromArray(
    108108                        array(
    109                                 'home_key'           => HostNormalizer::homeKey( (string) ( $src['home'] ?? '' ) ),
    110                                 'stored_home_key'    => HostNormalizer::homeKey( (string) ( $src['stored_home'] ?? '' ) ),
    111                                 'request_host'       => HostNormalizer::requestHost( (string) ( $src['request_host'] ?? '' ) ),
    112                                 'abspath_h'          => Fingerprint::abspath( (string) ( $src['abspath'] ?? '' ) ),
    113                                 'db_h'               => Fingerprint::db( (string) ( $src['db'] ?? '' ) ),
    114                                 'wpdb_prefix'        => (string) ( $src['wpdb_prefix'] ?? '' ),
    115                                 'env_effective'      => $types['effective'],
    116                                 'env_explicit'       => $types['explicit'],
    117                                 'wpstg_const'        => ! empty( $src['wpstg_const'] ),
    118                                 'wpstg_option'       => ! empty( $src['wpstg_option'] ),
     109                                'home_key'            => HostNormalizer::homeKey( (string) ( $src['home'] ?? '' ) ),
     110                                'stored_home_key'     => HostNormalizer::homeKey( (string) ( $src['stored_home'] ?? '' ) ),
     111                                'request_host'        => HostNormalizer::requestHost( (string) ( $src['request_host'] ?? '' ) ),
     112                                'abspath_h'           => Fingerprint::abspath( (string) ( $src['abspath'] ?? '' ) ),
     113                                'db_h'                => Fingerprint::db( (string) ( $src['db'] ?? '' ) ),
     114                                'wpdb_prefix'         => (string) ( $src['wpdb_prefix'] ?? '' ),
     115                                'env_effective'       => $types['effective'],
     116                                'env_explicit'        => $types['explicit'],
     117                                'wpstg_const'         => ! empty( $src['wpstg_const'] ),
     118                                'wpstg_option'        => ! empty( $src['wpstg_option'] ),
    119119                                'clonemute_env_const' => array_key_exists( 'clonemute_env', $src ) ? $src['clonemute_env'] : Constants::env(),
    120                                 'baseline'           => $s->baseline,
    121                                 'production'         => $s->production,
    122                                 'whitelist'          => $s->prod_whitelist,
    123                                 'patterns'           => $patterns,
     120                                'baseline'            => $s->baseline,
     121                                'production'          => $s->production,
     122                                'whitelist'           => $s->prod_whitelist,
     123                                'patterns'            => $patterns,
    124124                        )
    125125                );
  • clonemute/tags/0.2.0/src/Plugin.php

    r3828539 r3841430  
    1414use Rotosix\CloneMute\Admin\Pages;
    1515use Rotosix\CloneMute\Admin\SettingsPage;
     16use Rotosix\CloneMute\Cli\Commands;
    1617use Rotosix\CloneMute\Env\EnvCapture;
    1718use Rotosix\CloneMute\Guard\Guard;
    … …  
    3334final class Plugin {
    3435
    35         const VERSION = '0.1.0';
     36        const VERSION = '0.2.0';
    3637
    3738        /**
    … …  
    163164                                self::registerAdmin();
    164165                        }
     166                        if ( defined( 'WP_CLI' ) && WP_CLI ) {
     167                                Commands::register();
     168                        }
    165169                        if ( 'armed' !== $s->state && ! Constants::armRequested() ) {
    166170                                return;
  • clonemute/trunk/clonemute.php

    r3828539 r3841430  
    44 * Plugin URI:        https://wordpress.org/plugins/clonemute/
    55 * Description:       Makes cloned WooCommerce sites safe: after you confirm a copy is a staging site, CloneMute blocks outgoing mail, payment gateways, scheduled tasks and known external services, and hides the site from search engines.
    6  * Version:           0.1.0
     6 * Version:           0.2.0
    77 * Requires at least: 7.0
    88 * Requires PHP:      7.4
  • clonemute/trunk/languages/clonemute.pot

    r3828539 r3841430  
    33msgid ""
    44msgstr ""
    5 "Project-Id-Version: CloneMute Staging Safety for WooCommerce 0.1.0\n"
     5"Project-Id-Version: CloneMute Staging Safety for WooCommerce 0.2.0\n"
    66"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/clonemute\n"
    77"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
    … …  
    1010"Content-Type: text/plain; charset=UTF-8\n"
    1111"Content-Transfer-Encoding: 8bit\n"
    12 "POT-Creation-Date: 2026-11-26T01:23:54+00:00\n"
     12"POT-Creation-Date: 2026-12-02T09:24:48+00:00\n"
    1313"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
    1414"X-Generator: WP-CLI 2.12.0\n"
    … …  
    4040msgstr ""
    4141
    42 #: src/Admin/AdminActions.php:410
     42#: src/Admin/AdminActions.php:464
    4343msgid "CloneMute test mail"
    4444msgstr ""
    4545
    46 #: src/Admin/AdminActions.php:411
     46#: src/Admin/AdminActions.php:465
    4747msgid "If you can read this, mail is leaving this site. On a staging site that means the mail guard is not active."
    4848msgstr ""
    … …  
    7272msgstr ""
    7373
    74 #: src/Admin/Notices.php:88
     74#: src/Admin/Messages.php:23
    7575msgid "Protection is on. This site is now treated as a staging site."
    7676msgstr ""
    7777
    78 #: src/Admin/Notices.php:89
     78#: src/Admin/Messages.php:24
    7979msgid "Saved as a staging site, but CLONEMUTE_DISABLE_ALL in wp-config.php keeps every protection off. Remove that line to turn the protections on."
    8080msgstr ""
    8181
    82 #: src/Admin/Notices.php:90
     82#: src/Admin/Messages.php:25
    8383msgid "The host name does not match. Nothing was changed."
    8484msgstr ""
    8585
    86 #: src/Admin/Notices.php:91
     86#: src/Admin/Messages.php:26
    8787msgid "Protection cannot be enabled on this site (see the reasons below). Nothing was changed."
    8888msgstr ""
    8989
    90 #: src/Admin/Notices.php:92
     90#: src/Admin/Messages.php:27
    9191msgid "Recorded as a production site. No protection is enabled."
    9292msgstr ""
    9393
    94 #: src/Admin/Notices.php:93
     94#: src/Admin/Messages.php:28
    9595msgid "This site is protected as a staging site (or CLONEMUTE_ENV arms it). Remove the protection first if this really is the production site. Nothing was changed."
    9696msgstr ""
    9797
    98 #: src/Admin/Notices.php:94
     98#: src/Admin/Messages.php:29
    9999msgid "The production confirmation of this site was removed. CloneMute treats it as unconfirmed again."
    100100msgstr ""
    101101
    102 #: src/Admin/Notices.php:95
     102#: src/Admin/Messages.php:30
     103msgid "This site has no production confirmation to remove. Nothing was changed."
     104msgstr ""
     105
     106#: src/Admin/Messages.php:31
     107msgid "The address of this site cannot be read (its home URL has no host). Nothing was changed. With WP-CLI, pass --url=<site address>."
     108msgstr ""
     109
     110#: src/Admin/Messages.php:32
    103111msgid "OK, CloneMute will ask again the next time you log in."
    104112msgstr ""
    105113
    106 #: src/Admin/Notices.php:96
     114#: src/Admin/Messages.php:33
    107115msgid "All protections were removed. Scheduled tasks that were paused will run again and may run in a burst."
    108116msgstr ""
    109117
    110 #: src/Admin/Notices.php:97
     118#: src/Admin/Messages.php:34
    111119msgid "CLONEMUTE_ENV is set to \"staging\" in wp-config.php, so protection would come back on the next page load. Remove that line first. Nothing was changed."
    112120msgstr ""
    113121
    114 #: src/Admin/Notices.php:98
     122#: src/Admin/Messages.php:35
    115123msgid "Test mail handed to the mail system. Check your inbox: if it arrives, mail is leaving this site."
    116124msgstr ""
    117125
    118 #: src/Admin/Notices.php:99
     126#: src/Admin/Messages.php:36
    119127msgid "CloneMute stopped the test mail: mail protection works. It is listed under the blocked events."
    120128msgstr ""
    121129
    122 #: src/Admin/Notices.php:100
     130#: src/Admin/Messages.php:37
    123131msgid "The test mail was not sent: the server could not send it."
    124132msgstr ""
    125133
    126 #: src/Admin/Notices.php:101
     134#: src/Admin/Messages.php:38
    127135msgid "Added to the allow list."
    128136msgstr ""
    129137
    130 #: src/Admin/Notices.php:102
     138#: src/Admin/Messages.php:39
    131139msgid "That value cannot be added to an allow list."
    132140msgstr ""
    133141
     142#: src/Admin/Messages.php:40
     143msgid "The error message was dismissed. No protection was changed."
     144msgstr ""
     145
     146#: src/Admin/Messages.php:41
     147msgid "Something went wrong. Nothing was changed."
     148msgstr ""
     149
    134150#: src/Admin/Notices.php:103
    135 msgid "The error message was dismissed. No protection was changed."
     151msgid "CloneMute: the recorded staging host does not match this site. Protection is OFF."
    136152msgstr ""
    137153
    138154#: src/Admin/Notices.php:104
    139 msgid "Something went wrong. Nothing was changed."
    140 msgstr ""
    141 
    142 #: src/Admin/Notices.php:121
    143 msgid "CloneMute: the recorded staging host does not match this site. Protection is OFF."
    144 msgstr ""
    145 
    146 #: src/Admin/Notices.php:122
    147155msgid "This site was protected as a staging site under another address or on another installation, and has been moved or copied. Nothing is blocked here. If this is your production site, check that real mail and payments work again. If it is a copy of the staging site, protect it again on the CloneMute status page."
    148156msgstr ""
    149157
    150 #: src/Admin/Notices.php:123
    151 #: src/Admin/Notices.php:135
     158#: src/Admin/Notices.php:105
     159#: src/Admin/Notices.php:117
    152160#: src/Admin/Wizard.php:121
    153161#: src/Admin/Wizard.php:136
    … …  
    155163msgstr ""
    156164
    157 #: src/Admin/Notices.php:126
     165#: src/Admin/Notices.php:108
    158166#: src/Admin/Pages.php:136
    159167msgid "Send a test mail to me"
    160168msgstr ""
    161169
    162 #: src/Admin/Notices.php:129
     170#: src/Admin/Notices.php:111
    163171msgid "CloneMute: this site is armed but matches a production safeguard. Protection is OFF."
    164172msgstr ""
    165173
     174#: src/Admin/Notices.php:115
     175msgid "CloneMute: the saved settings are unreadable. Nothing is blocked."
     176msgstr ""
     177
     178#: src/Admin/Notices.php:116
     179msgid "Reset the saved state on the CloneMute status page, then check the environment and the settings."
     180msgstr ""
     181
     182#: src/Admin/Notices.php:119
     183msgid "CloneMute: an internal error occurred. Nothing is blocked."
     184msgstr ""
     185
    166186#: src/Admin/Notices.php:133
    167 msgid "CloneMute: the saved settings are unreadable. Nothing is blocked."
    168 msgstr ""
    169 
    170 #: src/Admin/Notices.php:134
    171 msgid "Reset the saved state on the CloneMute status page, then check the environment and the settings."
    172 msgstr ""
    173 
     187msgid "CloneMute: STAGING protection is active."
     188msgstr ""
     189
     190#. translators: %d: number of active protections
    174191#: src/Admin/Notices.php:137
    175 msgid "CloneMute: an internal error occurred. Nothing is blocked."
    176 msgstr ""
    177 
    178 #: src/Admin/Notices.php:151
    179 msgid "CloneMute: STAGING protection is active."
    180 msgstr ""
    181 
    182 #. translators: %d: number of active protections
    183 #: src/Admin/Notices.php:155
    184192#, php-format
    185193msgid "%d protection is on."
    … …  
    188196msgstr[1] ""
    189197
    190 #: src/Admin/Notices.php:159
     198#: src/Admin/Notices.php:141
    191199#: vendor-prefixed/rotosix-core/src/Log/LogPage.php:67
    192200msgid "Details"
    193201msgstr ""
    194202
    195 #: src/Admin/Notices.php:162
     203#: src/Admin/Notices.php:144
    196204#: src/Admin/Pages.php:133
    197205msgid "Remove all protections"
    198206msgstr ""
    199207
    200 #: src/Admin/Notices.php:178
     208#: src/Admin/Notices.php:160
    201209msgid "CloneMute: CLONEMUTE_ENV is set to \"staging\" in wp-config.php, but protection cannot be enabled on this site. Nothing is blocked."
    202210msgstr ""
    203211
    204212#. translators: 1: protection name, 2: error class, 3: date and time (UTC)
    205 #: src/Admin/Notices.php:199
     213#: src/Admin/Notices.php:181
    206214#, php-format
    207215msgid "CloneMute: the \"%1$s\" protection hit an error (%2$s, %3$s UTC) and let a request through."
    208216msgstr ""
    209217
     218#: src/Admin/Notices.php:188
     219msgid "Dismiss this message"
     220msgstr ""
     221
     222#: src/Admin/Notices.php:189
     223msgid "Dismissing changes no protection. The message comes back if the error happens again."
     224msgstr ""
     225
     226#. translators: %s: list of constants
    210227#: src/Admin/Notices.php:206
    211 msgid "Dismiss this message"
    212 msgstr ""
    213 
    214 #: src/Admin/Notices.php:207
    215 msgid "Dismissing changes no protection. The message comes back if the error happens again."
    216 msgstr ""
    217 
    218 #. translators: %s: list of constants
    219 #: src/Admin/Notices.php:224
    220228#, php-format
    221229msgid "CloneMute: overridden by constant in wp-config: %s"
    … …  
    223231
    224232#. translators: %s: file name
    225 #: src/Admin/Notices.php:243
     233#: src/Admin/Notices.php:225
    226234#, php-format
    227235msgid "The wp_mail() function is replaced by %s. CloneMute may not be able to see or change mail sent through it; mail services that use the WordPress HTTP API are still covered by the outbound request block."
    … …  
    813821msgstr ""
    814822
     823#: src/Cli/Commands.php:170
     824msgid "The stored CloneMute settings cannot be read. Nothing is blocked until the state is set again."
     825msgstr ""
     826
     827#: src/Cli/Commands.php:200
     828msgid "Saved as a staging site, but the protection is not active on this site."
     829msgstr ""
     830
     831#: src/Cli/Commands.php:281
     832msgid "Pass --host=<host>: this site's address as `wp clonemute status` shows it."
     833msgstr ""
     834
     835#. translators: %s: the reasons, joined
     836#: src/Cli/Commands.php:306
     837#, php-format
     838msgid "Protection cannot be enabled on this site: %s Nothing was changed."
     839msgstr ""
     840
     841#. translators: %s: this site's host key
     842#: src/Cli/Commands.php:310
     843#, php-format
     844msgid "This site is %s (on a network, choose the site with --url)."
     845msgstr ""
     846
     847#: src/Cli/Commands.php:340
     848msgid "The stored settings could not be read and were replaced by the defaults. Check the production domains and the other settings."
     849msgstr ""
     850
     851#: src/Cli/Commands.php:342
     852msgid "The stored state was invalid and has been replaced; the other settings were kept."
     853msgstr ""
     854
     855#: src/Cli/Commands.php:355
     856msgid "WP_ENVIRONMENT_TYPE is not set for WP-CLI. If only the web server sets it (fastcgi_param, SetEnv, PHP-FPM env), WP-CLI cannot check it: when it is \"production\" there, web requests stay unprotected. Check the CloneMute page in the admin."
     857msgstr ""
     858
     859#: src/Cli/Commands.php:369
     860msgid "Nothing was changed: the site was already in that state."
     861msgstr ""
     862
     863#: src/Cli/Commands.php:398
     864#: vendor-prefixed/rotosix-core/src/Api/CliCommands.php:217
     865msgid "Unknown --format; use table or json."
     866msgstr ""
     867
     868#: src/Cli/Commands.php:436
     869#: vendor-prefixed/rotosix-core/src/Api/CliCommands.php:250
     870msgid "Write commands are disabled in this environment."
     871msgstr ""
     872
     873#: src/Cli/Commands.php:440
     874#: vendor-prefixed/rotosix-core/src/Api/CliCommands.php:253
     875#: vendor-prefixed/rotosix-core/src/Api/RestRegistrar.php:63
     876msgid "Sorry, you are not allowed to do that."
     877msgstr ""
     878
    815879#: src/Guard/HttpGuard.php:148
    816880msgid "Request blocked by CloneMute (test site)."
    … …  
    9921056msgstr ""
    9931057
    994 #: vendor-prefixed/rotosix-core/src/Api/CliCommands.php:217
    995 msgid "Unknown --format; use table or json."
    996 msgstr ""
    997 
    998 #: vendor-prefixed/rotosix-core/src/Api/CliCommands.php:250
    999 msgid "Write commands are disabled in this environment."
    1000 msgstr ""
    1001 
    1002 #: vendor-prefixed/rotosix-core/src/Api/CliCommands.php:253
    1003 #: vendor-prefixed/rotosix-core/src/Api/RestRegistrar.php:63
    1004 msgid "Sorry, you are not allowed to do that."
    1005 msgstr ""
    1006 
    10071058#: vendor-prefixed/rotosix-core/src/Api/ErrorFactory.php:102
    10081059msgid "This batch has no rollback point."
  • clonemute/trunk/readme.txt

    r3828539 r3841430  
    55Tested up to: 7.2
    66Requires PHP: 7.4
    7 Stable tag: 0.1.0
     7Stable tag: 0.2.0
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
    … …  
    51513. On a live site open the CloneMute page and choose "This is the new production site". CloneMute blocks nothing either way, but other Rotosix plugins (for example the scheduled imports of CatalogRelay) pause their scheduled work until the site is confirmed as production.
    5252
    53 To pre-confirm a clone in a script, define `define( 'CLONEMUTE_ENV', 'staging' );` in `wp-config.php` of the copy. Safeguards still apply: the constant is refused on hosts you listed or confirmed as production and when `WP_ENVIRONMENT_TYPE` is explicitly `production`, and the admin says so.
     53= WP-CLI =
     54
     55Confirm a copy from your clone script right after the copy is made:
     56
     57`wp clonemute arm --host=stg.example.com`
     58
     59This is the same confirmation as in the admin, with the same safeguards: it is refused on hosts you listed or confirmed as production and when `WP_ENVIRONMENT_TYPE` is explicitly `production`. WP-CLI only sees a `WP_ENVIRONMENT_TYPE` defined in `wp-config.php` or set in its own environment: a value set only in the web server configuration (fastcgi_param, SetEnv, PHP-FPM env) cannot be checked, so `arm` warns when it sees none, and you should check the CloneMute page in the admin. `--host` is this site's address without the scheme, with the port and the sub-directory if there is one, exactly as `wp clonemute status` shows it. On a multisite network choose the site with `--url=<site address>`.
     60
     61* `wp clonemute status [--format=json]` shows the state, why the site is or is not protected and the state of every protection.
     62* `wp clonemute disarm` removes every protection.
     63* `wp clonemute production confirm` records the site as the production site; `wp clonemute production forget --host=<host>` removes that record.
     64
     65Exit codes: 0 success (also when nothing had to change), 1 refused or failed, 2 saved as a staging site but no protection is active (for example because of `CLONEMUTE_DISABLE_ALL`). With `--format=json` the result or the error is one JSON document on standard output; messages go to standard error. Changes made with WP-CLI are marked "(WP-CLI)" in the event log.
     66
     67Without WP-CLI you can pre-confirm a clone with `define( 'CLONEMUTE_ENV', 'staging' );` in `wp-config.php` of the copy. The same safeguards apply, the admin says when the constant is refused, and the protection cannot be removed while the constant is set.
    5468
    5569Emergency switches for `wp-config.php`: `CLONEMUTE_DISABLE_ALL`, `CLONEMUTE_DISABLE_MAIL`, `CLONEMUTE_DISABLE_PAYMENTS`, `CLONEMUTE_DISABLE_CRON`, `CLONEMUTE_DISABLE_HTTP`, `CLONEMUTE_DISABLE_GATE` (login gate and REST limit).
    … …  
    7993== Changelog ==
    8094
     95= 0.2.0 =
     96* New: WP-CLI commands `wp clonemute status`, `arm --host=<host>`, `disarm`, `production confirm` and `production forget --host=<host>`, with `--format=json`. They make the same checks as the admin screens.
     97* State changes made with WP-CLI are marked in the event log.
     98
    8199= 0.1.0 =
    82100* First release: environment suggestions with explicit confirmation, mail, payment, scheduled task, outbound request, search engine and REST protections, read-only report, event log with privacy tools.
    … …  
    84102== Upgrade Notice ==
    85103
     104= 0.2.0 =
     105Adds WP-CLI commands to confirm a copy from a clone script. No setting changes.
     106
    86107= 0.1.0 =
    87108First release.
  • clonemute/trunk/src/Admin/AdminActions.php

    r3828539 r3841430  
    2727 */
    2828final class AdminActions {
     29
     30        /**
     31         * Origins of a state change (written to the state_change log).
     32         */
     33        const ORIGIN_ADMIN = 'admin';
     34        const ORIGIN_CLI   = 'cli';
    2935
    3036        const STATE_ACTIONS = array( 'arm', 'production', 'forget_production', 'later', 'disarm' );
    … …  
    159165         * "This is staging": recompute the hard blocks, compare the typed host, then arm.
    160166         *
    161          * @param array $post Submitted fields.
    162          * @return array
    163          */
    164         public static function arm( array $post ): array {
     167         * @param array  $post   Submitted fields.
     168         * @param string $origin Where the request came from (ORIGIN_ADMIN or ORIGIN_CLI).
     169         * @return array {ok, code, changed, blocks?}
     170         */
     171        public static function arm( array $post, string $origin = self::ORIGIN_ADMIN ): array {
    165172                $s    = SettingsRepo::load();
    166173                $snap = EnvCapture::capture( $s, true );
    167                 $t    = StateMachine::arm( $snap, isset( $post['host'] ) ? (string) $post['host'] : '', time() );
     174                if ( self::ORIGIN_CLI === $origin ) {
     175                        // WP-CLI sets the Host header from --url or wp-cli.yml (operator configuration copied with the files, not a
     176                        // client header): judge it like any later request, without the request host.
     177                        $snap->request_host = '';
     178                }
     179                $t = StateMachine::arm( $snap, isset( $post['host'] ) ? (string) $post['host'] : '', time() );
    168180                if ( ! $t->ok ) {
    169181                        $codes = array(
    170182                                'hard_block'    => 'arm_blocked',
    171183                                'host_mismatch' => 'arm_host',
    172                                 'no_host'       => 'arm_blocked',
    173                         );
    174                         return array(
    175                                 'ok'   => false,
    176                                 'code' => $codes[ $t->error ] ?? 'error',
    177                         );
     184                                'no_host'       => 'no_host',
     185                        );
     186                        $out   = array(
     187                                'ok'      => false,
     188                                'code'    => $codes[ $t->error ] ?? 'error',
     189                                'changed' => false,
     190                        );
     191                        if ( 'hard_block' === $t->error ) {
     192                                $out['blocks'] = $t->blocks;
     193                        }
     194                        return $out;
    178195                }
    179196                $code = Constants::disableAll() ? 'armed_off' : 'armed'; // Saved, but CLONEMUTE_DISABLE_ALL keeps every guard off.
    … …  
    181198                        // Already armed for this site (a second submit of the form): keep "since" and log nothing.
    182199                        return array(
    183                                 'ok'   => true,
    184                                 'code' => $code,
     200                                'ok'      => true,
     201                                'code'    => $code,
     202                                'changed' => false,
    185203                        );
    186204                }
    187205                if ( ! self::write( $t->changes ) ) {
    188                         return array(
    189                                 'ok'   => false,
    190                                 'code' => 'error',
    191                         );
     206                        return self::failed();
    192207                }
    193208                Runtime::clearError();
    194                 LogWriter::event( 'state_change', 'state', StateMachine::fromLabel( $s, $snap ) . ' -> armed', array( 'to' => 'armed' ) );
    195                 return array(
    196                         'ok'   => true,
    197                         'code' => $code,
     209                self::logState( StateMachine::fromLabel( $s, $snap ) . ' -> armed', 'armed', $origin );
     210                return array(
     211                        'ok'      => true,
     212                        'code'    => $code,
     213                        'changed' => true,
    198214                );
    199215        }
    … …  
    202218         * "This is the new production site": record the fingerprint, enable nothing.
    203219         *
    204          * @return array
    205          */
    206         public static function production(): array {
     220         * @param string $origin Where the request came from.
     221         * @return array {ok, code, changed}
     222         */
     223        public static function production( string $origin = self::ORIGIN_ADMIN ): array {
    207224                $s    = SettingsRepo::load();
    208225                $snap = EnvCapture::capture( $s, false );
    … …  
    211228                        // lock the host as production. Removing the protection is a separate, explicit step.
    212229                        return array(
    213                                 'ok'   => false,
    214                                 'code' => 'production_armed',
     230                                'ok'      => false,
     231                                'code'    => 'production_armed',
     232                                'changed' => false,
    215233                        );
    216234                }
    … …  
    218236                if ( ! $t->ok ) {
    219237                        return array(
    220                                 'ok'   => false,
    221                                 'code' => 'error',
     238                                'ok'      => false,
     239                                'code'    => 'no_host',
     240                                'changed' => false,
    222241                        );
    223242                }
    … …  
    227246                if ( ! $again ) {
    228247                        if ( ! self::write( $t->changes ) ) {
    229                                 return array(
    230                                         'ok'   => false,
    231                                         'code' => 'error',
    232                                 );
     248                                return self::failed();
    233249                        }
    234                         LogWriter::event( 'state_change', 'state', StateMachine::fromLabel( $s, $snap ) . ' -> production', array( 'to' => 'production' ) );
     250                        self::logState( StateMachine::fromLabel( $s, $snap ) . ' -> production', 'production', $origin );
    235251                }
    236252                Runtime::clearError(); // No guard runs on a production site: an earlier guard error no longer applies.
    237253                return array(
    238                         'ok'   => true,
    239                         'code' => 'production',
     254                        'ok'      => true,
     255                        'code'    => 'production',
     256                        'changed' => ! $again,
    240257                );
    241258        }
    … …  
    244261         * Forget the production confirmation of this host after the host name was typed (the way back from "production").
    245262         *
    246          * @param array $post Submitted fields.
    247          * @return array
    248          */
    249         public static function forgetProduction( array $post ): array {
     263         * @param array  $post   Submitted fields.
     264         * @param string $origin Where the request came from.
     265         * @return array {ok, code, changed}
     266         */
     267        public static function forgetProduction( array $post, string $origin = self::ORIGIN_ADMIN ): array {
    250268                $s     = SettingsRepo::load();
    251269                $snap  = EnvCapture::capture( $s, false );
    … …  
    255273                        // No confirmation for this host (any more): a second submit of the form. Nothing to remove, nothing to log.
    256274                        return array(
    257                                 'ok'   => true,
    258                                 'code' => 'prod_forgotten',
     275                                'ok'      => true,
     276                                'code'    => 'prod_forgotten',
     277                                'changed' => false,
    259278                        );
    260279                }
    261280                if ( ! $t->ok ) {
    262                         return array(
    263                                 'ok'   => false,
    264                                 'code' => 'host_mismatch' === $t->error ? 'arm_host' : 'error',
     281                        $codes = array(
     282                                'host_mismatch'  => 'arm_host',
     283                                'not_production' => 'prod_none',
     284                                'no_host'        => 'no_host',
     285                        );
     286                        return array(
     287                                'ok'      => false,
     288                                'code'    => $codes[ $t->error ] ?? 'error',
     289                                'changed' => false,
    265290                        );
    266291                }
    267292                if ( ! self::write( $t->changes ) ) {
    268                         return array(
    269                                 'ok'   => false,
    270                                 'code' => 'error',
    271                         );
     293                        return self::failed();
    272294                }
    273295                Runtime::clearError();
    274                 LogWriter::event( 'state_change', 'state', StateMachine::fromLabel( $s, $snap ) . ' -> ' . ( $t->changes['state'] ?? $s->state ) . ' (production confirmation removed)', array( 'to' => $t->changes['state'] ?? $s->state ) );
    275                 return array(
    276                         'ok'   => true,
    277                         'code' => 'prod_forgotten',
     296                $to = $t->changes['state'] ?? $s->state;
     297                self::logState( StateMachine::fromLabel( $s, $snap ) . ' -> ' . $to . ' (production confirmation removed)', $to, $origin );
     298                return array(
     299                        'ok'      => true,
     300                        'code'    => 'prod_forgotten',
     301                        'changed' => true,
    278302                );
    279303        }
    … …  
    295319         * Remove every guard at once.
    296320         *
    297          * @return array
    298          */
    299         public static function disarm(): array {
     321         * @param string $origin Where the request came from.
     322         * @return array {ok, code, changed}
     323         */
     324        public static function disarm( string $origin = self::ORIGIN_ADMIN ): array {
    300325                $s = SettingsRepo::load();
    301326                $t = StateMachine::disarm( $s, time() );
    … …  
    303328                        // CLONEMUTE_ENV would arm the site again on the next request: report that instead of a success that does not stick.
    304329                        return array(
    305                                 'ok'   => false,
    306                                 'code' => 'disarm_const',
     330                                'ok'      => false,
     331                                'code'    => 'disarm_const',
     332                                'changed' => false,
    307333                        );
    308334                }
    309335                if ( $t->changes ) {
    310336                        if ( ! self::write( $t->changes ) ) {
    311                                 return array(
    312                                         'ok'   => false,
    313                                         'code' => 'error',
    314                                 );
     337                                return self::failed();
    315338                        }
    316                         LogWriter::event( 'state_change', 'state', StateMachine::fromLabel( $s, EnvCapture::capture( $s, false ) ) . ' -> unconfirmed', array( 'to' => 'unconfirmed' ) );
     339                        self::logState( StateMachine::fromLabel( $s, EnvCapture::capture( $s, false ) ) . ' -> unconfirmed', 'unconfirmed', $origin );
    317340                }
    318341                Runtime::clearError();
    319342                return array(
    320                         'ok'   => true,
    321                         'code' => 'disarmed',
    322                 );
     343                        'ok'      => true,
     344                        'code'    => 'disarmed',
     345                        'changed' => (bool) $t->changes,
     346                );
     347        }
     348
     349        /**
     350         * Result of a write that did not stick.
     351         *
     352         * @return array
     353         */
     354        private static function failed(): array {
     355                return array(
     356                        'ok'      => false,
     357                        'code'    => 'error',
     358                        'changed' => false,
     359                );
     360        }
     361
     362        /**
     363         * Log a state change with where it came from (changes made with WP-CLI say so in the summary).
     364         *
     365         * @param string $summary Summary ("from -> to").
     366         * @param string $to      New state.
     367         * @param string $origin  ORIGIN_ADMIN or ORIGIN_CLI.
     368         * @return void
     369         */
     370        private static function logState( string $summary, string $to, string $origin ): void {
     371                $context = array( 'to' => $to );
     372                if ( self::ORIGIN_CLI === $origin ) {
     373                        $summary       .= ' (WP-CLI)';
     374                        $context['via'] = 'cli';
     375                }
     376                LogWriter::event( 'state_change', 'state', $summary, $context );
    323377        }
    324378
  • clonemute/trunk/src/Admin/Notices.php

    r3828539 r3841430  
    8585                // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- display-only code mapped through a whitelist.
    8686                $code = isset( $_GET['clonemute_msg'] ) ? sanitize_key( wp_unslash( $_GET['clonemute_msg'] ) ) : '';
    87                 $map  = array(
    88                         'armed'            => array( 'success', __( 'Protection is on. This site is now treated as a staging site.', 'clonemute' ) ),
    89                         'armed_off'        => array( 'warning', __( 'Saved as a staging site, but CLONEMUTE_DISABLE_ALL in wp-config.php keeps every protection off. Remove that line to turn the protections on.', 'clonemute' ) ),
    90                         'arm_host'         => array( 'error', __( 'The host name does not match. Nothing was changed.', 'clonemute' ) ),
    91                         'arm_blocked'      => array( 'error', __( 'Protection cannot be enabled on this site (see the reasons below). Nothing was changed.', 'clonemute' ) ),
    92                         'production'       => array( 'success', __( 'Recorded as a production site. No protection is enabled.', 'clonemute' ) ),
    93                         'production_armed' => array( 'error', __( 'This site is protected as a staging site (or CLONEMUTE_ENV arms it). Remove the protection first if this really is the production site. Nothing was changed.', 'clonemute' ) ),
    94                         'prod_forgotten'   => array( 'success', __( 'The production confirmation of this site was removed. CloneMute treats it as unconfirmed again.', 'clonemute' ) ),
    95                         'later'            => array( 'info', __( 'OK, CloneMute will ask again the next time you log in.', 'clonemute' ) ),
    96                         'disarmed'         => array( 'success', __( 'All protections were removed. Scheduled tasks that were paused will run again and may run in a burst.', 'clonemute' ) ),
    97                         'disarm_const'     => array( 'error', __( 'CLONEMUTE_ENV is set to "staging" in wp-config.php, so protection would come back on the next page load. Remove that line first. Nothing was changed.', 'clonemute' ) ),
    98                         'test_mail_sent'   => array( 'success', __( 'Test mail handed to the mail system. Check your inbox: if it arrives, mail is leaving this site.', 'clonemute' ) ),
    99                         'test_mail_caught' => array( 'success', __( 'CloneMute stopped the test mail: mail protection works. It is listed under the blocked events.', 'clonemute' ) ),
    100                         'test_mail_failed' => array( 'warning', __( 'The test mail was not sent: the server could not send it.', 'clonemute' ) ),
    101                         'allow_added'      => array( 'success', __( 'Added to the allow list.', 'clonemute' ) ),
    102                         'allow_invalid'    => array( 'error', __( 'That value cannot be added to an allow list.', 'clonemute' ) ),
    103                         'error_dismissed'  => array( 'info', __( 'The error message was dismissed. No protection was changed.', 'clonemute' ) ),
    104                         'error'            => array( 'error', __( 'Something went wrong. Nothing was changed.', 'clonemute' ) ),
    105                 );
    106                 if ( isset( $map[ $code ] ) ) {
    107                         echo '<div class="notice notice-' . esc_attr( $map[ $code ][0] ) . ' is-dismissible" role="status"><p>' . esc_html( $map[ $code ][1] ) . '</p></div>';
     87                $msg  = Messages::result( $code );
     88                if ( null !== $msg ) {
     89                        echo '<div class="notice notice-' . esc_attr( $msg[0] ) . ' is-dismissible" role="status"><p>' . esc_html( $msg[1] ) . '</p></div>';
    10890                }
    10991        }
  • clonemute/trunk/src/Env/EnvCapture.php

    r3828539 r3841430  
    107107                return EnvSnapshot::fromArray(
    108108                        array(
    109                                 'home_key'           => HostNormalizer::homeKey( (string) ( $src['home'] ?? '' ) ),
    110                                 'stored_home_key'    => HostNormalizer::homeKey( (string) ( $src['stored_home'] ?? '' ) ),
    111                                 'request_host'       => HostNormalizer::requestHost( (string) ( $src['request_host'] ?? '' ) ),
    112                                 'abspath_h'          => Fingerprint::abspath( (string) ( $src['abspath'] ?? '' ) ),
    113                                 'db_h'               => Fingerprint::db( (string) ( $src['db'] ?? '' ) ),
    114                                 'wpdb_prefix'        => (string) ( $src['wpdb_prefix'] ?? '' ),
    115                                 'env_effective'      => $types['effective'],
    116                                 'env_explicit'       => $types['explicit'],
    117                                 'wpstg_const'        => ! empty( $src['wpstg_const'] ),
    118                                 'wpstg_option'       => ! empty( $src['wpstg_option'] ),
     109                                'home_key'            => HostNormalizer::homeKey( (string) ( $src['home'] ?? '' ) ),
     110                                'stored_home_key'     => HostNormalizer::homeKey( (string) ( $src['stored_home'] ?? '' ) ),
     111                                'request_host'        => HostNormalizer::requestHost( (string) ( $src['request_host'] ?? '' ) ),
     112                                'abspath_h'           => Fingerprint::abspath( (string) ( $src['abspath'] ?? '' ) ),
     113                                'db_h'                => Fingerprint::db( (string) ( $src['db'] ?? '' ) ),
     114                                'wpdb_prefix'         => (string) ( $src['wpdb_prefix'] ?? '' ),
     115                                'env_effective'       => $types['effective'],
     116                                'env_explicit'        => $types['explicit'],
     117                                'wpstg_const'         => ! empty( $src['wpstg_const'] ),
     118                                'wpstg_option'        => ! empty( $src['wpstg_option'] ),
    119119                                'clonemute_env_const' => array_key_exists( 'clonemute_env', $src ) ? $src['clonemute_env'] : Constants::env(),
    120                                 'baseline'           => $s->baseline,
    121                                 'production'         => $s->production,
    122                                 'whitelist'          => $s->prod_whitelist,
    123                                 'patterns'           => $patterns,
     120                                'baseline'            => $s->baseline,
     121                                'production'          => $s->production,
     122                                'whitelist'           => $s->prod_whitelist,
     123                                'patterns'            => $patterns,
    124124                        )
    125125                );
  • clonemute/trunk/src/Plugin.php

    r3828539 r3841430  
    1414use Rotosix\CloneMute\Admin\Pages;
    1515use Rotosix\CloneMute\Admin\SettingsPage;
     16use Rotosix\CloneMute\Cli\Commands;
    1617use Rotosix\CloneMute\Env\EnvCapture;
    1718use Rotosix\CloneMute\Guard\Guard;
    … …  
    3334final class Plugin {
    3435
    35         const VERSION = '0.1.0';
     36        const VERSION = '0.2.0';
    3637
    3738        /**
    … …  
    163164                                self::registerAdmin();
    164165                        }
     166                        if ( defined( 'WP_CLI' ) && WP_CLI ) {
     167                                Commands::register();
     168                        }
    165169                        if ( 'armed' !== $s->state && ! Constants::armRequested() ) {
    166170                                return;
Note: See TracChangeset for help on using the changeset viewer.