Plugin Directory

Changeset 3837767


Ignore:
Timestamp:
12/01/2026 01:34:44 PM (less than one hour ago)
Author:
wpprovider
Message:

Update to version 0.1.33 from GitHub

Location:
translate-by-wp-provider
Files:
8 added
54 edited
1 copied

Legend:

Unmodified
Added
Removed
  • translate-by-wp-provider/tags/0.1.33/readme.txt

    r3836113 r3837767  
    55Tested up to: 7.2
    66Requires PHP: 7.4
    7 Stable tag: 0.1.32
     7Stable tag: 0.1.33
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
    … …  
    6060= I use WPML or TranslatePress. Can I switch? =
    6161
    62 Yes. The plugin imports the translations you already have, so pages do not need to be translated again. You start the import from the command line with WP-CLI (`wp wpprovider-translate wpml-import` or `wp wpprovider-translate translatepress-import`); wp-admin has no button for it. On a large site both run in batches (`--limit` and `--offset`), so each command stays well within the time a host allows.
     62Yes. The plugin imports the translations you already have, so pages do not need to be translated again. From TranslatePress, a small and simple site does it in wp-admin: after connecting, click "Bring my translations over" and keep the screen open while your pages are read. Your visitors keep TranslatePress. Look at your new pages privately, then switch over with one click; you can go back with one click until you say that everything looks good. When your site is larger or set up differently, the screen says why, and you can write to support@wpptranslate.com: we move it for you. From WPML, or from TranslatePress on the command line, you start the import with WP-CLI (`wp wpprovider-translate wpml-import` or `wp wpprovider-translate translatepress-import`). On a large site both run in batches (`--limit` and `--offset`), so each command stays well within the time a host allows.
    6363
    6464= Can a product feed or a search index use my translations? =
  • translate-by-wp-provider/tags/0.1.33/src/Admin.php

    r3836113 r3837767  
    155155                        <?php
    156156                        $step = Onboarding::step();
     157                        $card = Import\MoveScreen::render( 'connect' === $step && Connect::waiting() );
    157158                        if ( 'done' !== $step ) {
    158                                 Onboarding::render_steps( $step );
    159                                 if ( 'connect' === $step ) {
     159                                $card ? null : Onboarding::render_steps( $step );
     160                                if ( $card ) {
     161                                        $step = 'move';
     162                                } elseif ( 'connect' === $step ) {
    160163                                        $settings['source_lang'] = FirstLanguages::chosen()['source'] ?? $settings['source_lang'];
    161164                                        Onboarding::render_start( fn ( array $langs ) => self::render_targets( $settings, $langs ) );
  • translate-by-wp-provider/tags/0.1.33/src/Cli.php

    r3836067 r3837767  
    545545                update_option( Settings::OPTION, $saved );
    546546                WP_CLI::log( sprintf( 'Languages: %s, translated into %s.', $languages['source'], implode( ', ', $saved['target_langs'] ) ) );
    547                 // One language menu item of ours per menu, where TranslatePress had its switcher.
    548                 $menus = 0;
    549                 $seen  = array();
    550                 foreach ( Import\TranslatePress::menu_items() as $item ) {
    551                         $menu = wp_get_post_terms( $item, 'nav_menu', array( 'fields' => 'ids' ) );
    552                         $menu = is_array( $menu ) && $menu ? (int) $menu[0] : 0;
    553                         if ( $menu && ! isset( $seen[ $menu ] ) ) {
    554                                 $seen[ $menu ] = true;
    555                                 update_post_meta( $item, '_menu_item_type', 'custom' );
    556                                 update_post_meta( $item, '_menu_item_object', 'custom' );
    557                                 update_post_meta( $item, '_menu_item_object_id', $item );
    558                                 update_post_meta( $item, '_menu_item_url', Menu::URL );
    559                                 wp_update_post(
    560                                         array(
    561                                                 'ID'         => $item,
    562                                                 'post_title' => __( 'Languages', 'translate-by-wp-provider' ),
    563                                         )
    564                                 );
    565                                 ++$menus;
    566                         } else {
    567                                 wp_delete_post( $item, true );
    568                         }
    569                 }
    570                 WP_CLI::log( sprintf( 'Language switchers in menus replaced: %d.', $menus ) );
     547                WP_CLI::log( sprintf( 'Language switchers in menus replaced: %d.', Import\TranslatePress::replace_menu_items() ) );
    571548                foreach ( Import\TranslatePress::content_usage() as $what => $count ) {
    572549                        WP_CLI::log( sprintf( '%s in %d page(s): keeps working through WP Provider Translate.', $what, $count ) );
  • translate-by-wp-provider/tags/0.1.33/src/Compat/Multilingual.php

    r3814274 r3837767  
    1010defined( 'ABSPATH' ) || exit;
    1111
     12use WPPTranslate\Import\MoveScreen;
    1213use WPPTranslate\Settings;
    1314
    … …  
    127128         */
    128129        public static function render( bool $offer_choice = false ): void {
    129                 $active = self::active();
     130                // Moving over has a card of its own.
     131                $active = ! $offer_choice && MoveScreen::replaces_choice() ? array_diff( self::active(), array( 'translatepress' ) ) : self::active();
    130132                if ( ! $active ) {
    131133                        return;
  • translate-by-wp-provider/tags/0.1.33/src/Compat/TranslatePress.php

    r3814274 r3837767  
    1010defined( 'ABSPATH' ) || exit;
    1111
     12use WPPTranslate\Dormant;
    1213use WPPTranslate\Import\TranslatePress as Source;
    1314use WPPTranslate\LanguageContent;
     15use WPPTranslate\Menu;
    1416use WPPTranslate\Picker;
    1517
    1618/**
    1719 * Once TranslatePress is off, its shortcodes and block in the site's
    18  * content are handled here, so no page shows `[language-switcher]` and no
    19  * content meant for one language shows in all of them. The content itself
    20  * is not changed.
     20 * content and its switchers in menus are handled here, so no page shows `[language-switcher]` and no
     21 * content meant for one language shows in all of them. The content and
     22 * the menus themselves are not changed.
    2123 */
    2224final class TranslatePress {
    2325
    2426        /**
    25          * Hooks, only when TranslatePress is not running and left settings.
     27         * Hooks, only when TranslatePress is not running (or stays out of this
     28         * request) and left settings.
    2629         */
    2730        public static function register(): void {
    28                 if ( Source::active() || ! Source::available() ) {
     31                if ( ( Source::active() && ! Dormant::alone() ) || ! Source::available() ) {
    2932                        return;
    3033                }
    3134                add_action( 'init', array( self::class, 'shortcodes' ), 20 );
    3235                add_action( 'init', array( self::class, 'block' ), 20 );
     36                add_action( 'init', array( self::class, 'post_type' ), 20 );
     37                if ( ! is_admin() ) {
     38                        add_filter( 'wp_nav_menu_objects', array( self::class, 'one_switcher' ), 4 );
     39                }
     40        }
     41
     42        /** Its switcher in a menu is ours, where the menu is shown: one for all, where it has an item per language. */
     43        public static function one_switcher( $items ) {
     44                $out  = array();
     45                $seen = false;
     46                foreach ( $items as $item ) {
     47                        $theirs = 'language_switcher' === ( $item->object ?? '' );
     48                        if ( $theirs && ! $seen ) {
     49                                $item        = clone $item;
     50                                $item->url   = Menu::URL;
     51                                $item->title = __( 'Languages', 'translate-by-wp-provider' );
     52                        }
     53                        if ( ! $theirs || ! $seen ) {
     54                                $out[] = $item;
     55                        }
     56                        $seen = $seen || $theirs;
     57                }
     58                return $out;
     59        }
     60
     61        /** Its post type, so that WordPress knows its menu items. */
     62        public static function post_type(): void {
     63                register_post_type( 'language_switcher', array( 'public' => false ) );
    3364        }
    3465
  • translate-by-wp-provider/tags/0.1.33/src/Compat/WooCommerceEmails.php

    r3814274 r3837767  
    1212use WPPTranslate\Html\Segmenter;
    1313use WPPTranslate\Languages;
     14use WPPTranslate\PlanLanguages;
    1415use WPPTranslate\Settings;
    1516use WPPTranslate\StoredText;
    … …  
    238239                $url = StoredText::url( self::GROUP );
    239240                SegmentUrls::add( $texts, $url, $lang );
     241                if ( in_array( $lang, PlanLanguages::by_hand(), true ) ) {
     242                        // Recorded, to be translated by hand; never sent.
     243                        return;
     244                }
    240245                $missing = array_diff_key( $texts, Translations::lookup( $lang, array_keys( $texts ) ) );
    241246                $items   = array();
  • translate-by-wp-provider/tags/0.1.33/src/Connect.php

    r3836113 r3837767  
    4848        public static function start(): void {
    4949                self::guard( 'wppt_connect' );
     50                FirstLanguages::drop();
    5051                self::login();
    5152        }
    … …  
    189190        public static function auto(): void {
    190191                self::guard( 'wppt_auto_connect' );
     192                FirstLanguages::drop();
    191193                self::connect();
    192194        }
    … …  
    286288         */
    287289        private static function connected( string $account ): string {
    288                 return Settings::targets()
     290                return Settings::targets() || Import\MoveScreen::replaces_choice()
    289291                        /* translators: %s: account name. */
    290292                        ? sprintf( __( 'Connected to %s.', 'translate-by-wp-provider' ), $account )
  • translate-by-wp-provider/tags/0.1.33/src/Crawl.php

    r3814274 r3837767  
    4949         */
    5050        public static function start(): void {
    51                 if ( ! Settings::targets() ) {
     51                if ( ! Settings::targets() || Dormant::holds() ) {
    5252                        return;
    5353                }
  • translate-by-wp-provider/tags/0.1.33/src/Dormant.php

    r3814274 r3837767  
    3030 *   argument so that no page cache in front of the site answers them
    3131 *   instead; it is removed again before WordPress reads the request.
     32 *
     33 * While a site moves over from TranslatePress the option holds the move
     34 * (Import\Move): dormant while TranslatePress is loaded, and until
     35 * everything was read. So one plugin shows, whatever switches that one.
    3236 */
    3337final class Dormant {
    … …  
    5054        private static ?string $kind = null;
    5155
     56        /** Whether this request shows the plugin while a move is open, to anyone or in an administrator's preview. */
     57        private static bool $shown    = false;
     58        private static bool $previews = false;
     59
    5260        /**
    5361         * Whether the plugin is dormant on this site.
    5462         */
    5563        public static function on(): bool {
    56                 return function_exists( 'get_option' ) && (bool) get_option( self::OPTION, false );
     64                return ! self::$shown && function_exists( 'get_option' ) && (bool) get_option( self::OPTION, false );
     65        }
     66
     67        /** The move that is open (status, source, targets); null when there is none. */
     68        public static function move( bool $fresh = false ): ?array {
     69                $move = $fresh ? Fresh::option( self::OPTION ) : ( function_exists( 'get_option' ) ? get_option( self::OPTION ) : null );
     70                return is_array( $move ) && isset( $move['status'], $move['source'], $move['targets'] ) ? $move : null;
     71        }
     72
     73        /** Whether nothing is sent: from the start of a move until its owner chose the switch, whatever is off or on. */
     74        public static function holds(): bool {
     75                // A background run that shows the plugin lives for minutes: the owner may have gone back since.
     76                $move = self::move( self::$shown );
     77                if ( self::$shown && in_array( $move['file'] ?? '', (array) Fresh::option( 'active_plugins', array() ), true ) ) {
     78                        return true;
     79                }
     80                return self::$shown ? 'switched' !== ( $move['status'] ?? '' ) : null !== $move && 'switched' !== $move['status'];
     81        }
     82
     83        /** Whether visitors get this plugin while a move is open, given whether the other plugin is loaded. */
     84        public static function shows( string $status, bool $loaded ): bool {
     85                return ! $loaded && in_array( $status, array( 'ready', 'switched' ), true );
     86        }
     87
     88        /**
     89         * Filter on the settings while a move is open: its languages are in no
     90         * request but one that shows this plugin, and not stored before the move
     91         * is confirmed. So nothing is sent, also by an older version of this plugin.
     92         *
     93         * @param mixed $saved Settings as stored.
     94         */
     95        public static function languages( $saved ) {
     96                $move  = self::move();
     97                $saved = is_array( $saved ) ? $saved : array();
     98                if ( null === $move ) {
     99                        return $saved;
     100                }
     101                return self::$shown || self::$previews ? self::languages_of( $move ) + $saved : array( 'target_langs' => array() ) + $saved;
     102        }
     103
     104        /** Filter `pre_update_option` on the settings while a move is open: whoever writes them, the move's languages stay out. */
     105        public static function without_languages( $value ) {
     106                remove_filter( 'option_' . Settings::OPTION, array( self::class, 'languages' ) );
     107                $stored = (array) get_option( Settings::OPTION, array() );
     108                add_filter( 'option_' . Settings::OPTION, array( self::class, 'languages' ) );
     109                $source = array_intersect_key( $stored, array( 'source_lang' => '' ) );
     110                return array( 'target_langs' => array() ) + $source + array_diff_key( (array) $value, array( 'source_lang' => '' ) );
    57111        }
    58112
    … …  
    60114         * What a request gets while dormant.
    61115         *
    62          * @param array{cli?: bool, cron?: bool, admin?: bool, ajax?: bool, ajax_action?: string, uri?: string, own_render?: bool, preview?: bool, can_manage?: bool} $request What is known about the request.
     116         * @param array{cli?: bool, cron?: bool, admin?: bool, ajax?: bool, ajax_action?: string, uri?: string, own_render?: bool, import?: bool, preview?: bool, can_manage?: bool} $request What is known about the request.
    63117         * @return string One of HIDDEN, BACKGROUND, FULL.
    64118         */
    65119        public static function kind_of( array $request ): string {
     120                // The import reads the page as a visitor gets it, from the other plugin.
     121                if ( ! empty( $request['own_render'] ) && ! empty( $request['import'] ) ) {
     122                        return self::HIDDEN;
     123                }
    66124                if ( ! empty( $request['own_render'] ) ) {
    67125                        return self::FULL;
    … …  
    140198         */
    141199        public static function decide(): void {
     200                $move = self::move();
     201                if ( null !== $move ) {
     202                        add_filter( 'option_' . Settings::OPTION, array( self::class, 'languages' ) );
     203                        add_filter( 'pre_update_option_' . Settings::OPTION, array( self::class, 'without_languages' ) );
     204                        self::$shown = self::shows( $move['status'], Import\TranslatePress::active() );
     205                }
     206                if ( self::$shown ) {
     207                        Plugin::hooks();
     208                        return;
     209                }
    142210                // phpcs:disable WordPress.Security.NonceVerification.Recommended -- only which request this is, nothing is changed.
    143211                $action     = isset( $_REQUEST['action'] ) ? sanitize_key( wp_unslash( $_REQUEST['action'] ) ) : '';
    144212                $preview    = ! empty( $_GET[ self::PREVIEW ] );
     213                $render     = isset( $_SERVER['HTTP_X_WPPT_RENDER'] ) ? sanitize_key( wp_unslash( $_SERVER['HTTP_X_WPPT_RENDER'] ) ) : '';
    145214                self::$kind = self::kind_of(
    146215                        array(
    … …  
    152221                                'uri'         => Router::request_uri(),
    153222                                'own_render'  => RenderPass::is_own_render(),
     223                                'import'      => 'import' === $render,
    154224                                'preview'     => $preview,
    155225                                // Asked only for a preview: a visitor's request does not load the user early.
    … …  
    159229                // phpcs:enable
    160230                if ( self::HIDDEN === self::$kind ) {
     231                        if ( RenderPass::is_own_render() ) {
     232                                // The import reads past page caches, and past a maintenance mode.
     233                                self::remove_args();
     234                                self::keep_out_of_caches();
     235                                RenderPass::register();
     236                        }
    161237                        return;
    162238                }
    … …  
    165241                        self::keep_out_of_caches();
    166242                        self::quiet_other_plugin();
     243                        if ( $preview && ! RenderPass::is_own_render() ) {
     244                                self::$previews = null !== $move;
     245                                add_action( 'wp_footer', array( self::class, 'keep_preview' ) );
     246                        }
    167247                }
    168248                Plugin::hooks();
    … …  
    209289                add_filter( 'weglot_active_translation_before_treat_page', '__return_false', PHP_INT_MAX );
    210290                add_filter( 'weglot_active_translation', '__return_false', PHP_INT_MAX );
     291                // TranslatePress: none of its hooks. It asks at `plugins_loaded`, after this.
     292                add_filter( 'trp_allow_tp_to_run', '__return_false', PHP_INT_MAX );
     293        }
     294
     295        /** The move's languages, as settings. */
     296        private static function languages_of( array $move ): array {
     297                return array_combine( array( 'source_lang', 'target_langs' ), array( $move['source'], $move['targets'] ) );
     298        }
     299
     300        /** The move is over. Given the move, its languages are stored, unless others were chosen since. */
     301        public static function end( ?array $move = null ): void {
     302                remove_filter( 'pre_update_option_' . Settings::OPTION, array( self::class, 'without_languages' ) );
     303                remove_filter( 'option_' . Settings::OPTION, array( self::class, 'languages' ) );
     304                if ( null !== $move && ! Settings::targets() ) {
     305                        Settings::save_connection( self::languages_of( $move ) );
     306                }
     307                delete_option( self::OPTION );
     308        }
     309
     310        /** A link in an administrator's preview leads to the preview of the next page. */
     311        public static function keep_preview(): void {
     312                wp_print_inline_script_tag(
     313                        'document.addEventListener("click",function(e){var a=e.target.closest&&e.target.closest("a[href]");if(!a||a.origin!==location.origin||/\/wp-(admin|login)/.test(a.pathname)||a.getAttribute("href").charAt(0)==="#"){return;}var u=new URL(a.href);u.searchParams.set("' . self::PREVIEW . '","1");a.href=u.href;},true);'
     314                );
     315        }
     316
     317        /** Whether the other plugin stays out of this request. */
     318        public static function alone(): bool {
     319                return self::FULL === self::$kind;
    211320        }
    212321
    … …  
    215324         */
    216325        public static function notice(): void {
    217                 if ( ! self::on() || ! current_user_can( 'manage_options' ) ) {
     326                if ( self::$shown && 'plugins' === ( get_current_screen()->id ?? '' ) && current_user_can( 'manage_options' ) ) {
     327                        echo '<div class="notice notice-warning"><p>' . esc_html__( 'Your translated pages come from WP Provider Translate. If you switch it off, visitors have no translations. To return to TranslatePress, use "Go back" first.', 'translate-by-wp-provider' ) . ' <a href="' . esc_url( Admin::url() ) . '">' . esc_html__( 'Open', 'translate-by-wp-provider' ) . '</a></p></div>';
     328                }
     329                $own = null !== self::move() && preg_match( '/wp-?provider/', get_current_screen()->id ?? '' ); // Our own screens: the card says it.
     330                if ( $own || ! self::on() || ! current_user_can( 'manage_options' ) ) {
    218331                        return;
    219332                }
    220333                echo '<div class="notice notice-warning"><p>';
     334                if ( null !== self::move() ) {
     335                        echo esc_html__( 'Your translations are being brought over. Visitors still get TranslatePress.', 'translate-by-wp-provider' ) . ' <a href="' . esc_url( Admin::url() ) . '">' . esc_html__( 'See how far it is', 'translate-by-wp-provider' ) . '</a></p></div>';
     336                        return;
     337                }
    221338                echo esc_html__( 'WP Provider Translate is dormant: it translates the site in the background, but visitors do not see the translations yet. Administrators can preview a page by adding ?wppt_preview=1 to its address. To go live, delete the option wppt_dormant (wp option delete wppt_dormant).', 'translate-by-wp-provider' );
    222339                echo '</p></div>';
    … …  
    227344         */
    228345        public static function reset(): void {
    229                 self::$kind = null;
     346                self::$kind     = null;
     347                self::$shown    = false;
     348                self::$previews = false;
    230349        }
    231350}
  • translate-by-wp-provider/tags/0.1.33/src/FirstLanguages.php

    r3836113 r3837767  
    4040        /**
    4141         * What the first screen starts with: English for a site in another
    42          * language, nothing for a site in English.
     42         * language, nothing for a site in English or next to another translation
     43         * plugin, which usually has that address.
    4344         *
    4445         * @param string $source Site language.
    … …  
    4647         */
    4748        public static function suggested( string $source ): array {
    48                 return 'en' === $source ? array() : array( 'en' );
     49                return 'en' === $source || Multilingual::active() ? array() : array( 'en' );
    4950        }
    5051
    … …  
    6263                        return false;
    6364                }
     65                if ( null !== Dormant::move() ) {
     66                        return true;
     67                }
    6468                update_option(
    6569                        self::OPTION,
    6670                        array(
     71                                'instead'         => null !== Import\Move::offer(),
    6772                                'source'          => $source,
    6873                                'targets'         => $langs,
    … …  
    7277                );
    7378                return true;
     79        }
     80
     81        /**
     82         * Connecting to move over from another plugin, or not from the first
     83         * screen: what that screen kept is not what was asked for now.
     84         */
     85        public static function drop(): void {
     86                if ( null !== Import\Move::offer() ) {
     87                        delete_option( self::OPTION );
     88                }
    7489        }
    7590
    … …  
    93108         */
    94109        public static function apply(): void {
     110                $kept = get_option( self::OPTION );
     111                if ( null !== Dormant::move() || ( empty( $kept['instead'] ) && null !== Import\Move::offer() ) ) {
     112                        return;
     113                }
    95114                $chosen = self::chosen();
    96115                if ( null === $chosen || Settings::targets() ) {
  • translate-by-wp-provider/tags/0.1.33/src/Import/Progress.php

    r3814274 r3837767  
    6868        public static function busy( int $now ): bool {
    6969                $started = (int) get_option( self::RUNNING, 0 );
    70                 if ( $started > 0 && $now - $started < self::RUN_SECONDS ) {
     70                if ( null !== \WPPTranslate\Dormant::move() || ( $started > 0 && $now - $started < self::RUN_SECONDS ) ) {
    7171                        return true;
    7272                }
  • translate-by-wp-provider/tags/0.1.33/src/Import/RenderedImport.php

    r3814274 r3837767  
    105105                                }
    106106                                $aligned = Aligner::align( self::segments( $original ), self::segments( $translated ) );
    107                                 $pairs   = $aligned['pairs'];
    108                                 // Image descriptions, titles and labels, in page order.
    109                                 $a = array_values( Attributes::extract( $original ) );
    110                                 $b = array_values( Attributes::extract( $translated ) );
    111                                 if ( count( $a ) === count( $b ) ) {
    112                                         foreach ( $a as $i => $text ) {
    113                                                 if ( Aligner::fits( $text, $b[ $i ] ) ) {
    114                                                         $pairs[] = array( $text, $b[ $i ] );
    115                                                 }
    116                                         }
    117                                 }
    118                                 $count = 0;
    119                                 foreach ( $pairs as $pair ) {
     107                                $count   = 0;
     108                                foreach ( array_merge( $aligned['pairs'], self::attribute_pairs( $original, $translated ) ) as $pair ) {
    120109                                        // The same text on both sides was not translated: nothing to import.
    121110                                        if ( Segment::normalize( $pair[0] ) !== Segment::normalize( $pair[1] ) ) {
    … …  
    167156                }
    168157                return $report;
     158        }
     159
     160        /** Image descriptions, titles and labels of two pages, paired in page order. */
     161        public static function attribute_pairs( string $original, string $translated ): array {
     162                $a = array_values( Attributes::extract( $original ) );
     163                $b = array_values( Attributes::extract( $translated ) );
     164                return count( $a ) !== count( $b ) ? array() : array_filter( array_map( null, $a, $b ), static fn ( array $pair ): bool => Aligner::fits( $pair[0], $pair[1] ) );
    169165        }
    170166
    … …  
    344340         * @param string $lang Language code.
    345341         */
    346         private static function prefixed( string $url, string $lang ): string {
     342        public static function prefixed( string $url, string $lang ): string {
    347343                $home = untrailingslashit( home_url() );
    348344                return $home . '/' . $lang . substr( $url, strlen( $home ) );
    … …  
    365361         * @return string[]
    366362         */
    367         private static function segments( string $html ): array {
     363        public static function segments( string $html ): array {
    368364                return array_map( fn ( Segment $s ) => $s->source, Segmenter::parse( $html )->segments );
    369365        }
  • translate-by-wp-provider/tags/0.1.33/src/Import/TranslatePress.php

    r3814274 r3837767  
    99
    1010defined( 'ABSPATH' ) || exit;
     11
     12use WPPTranslate\Menu;
    1113
    1214/**
    … …  
    7779        }
    7880
     81        /** One language menu item of ours per menu, where TranslatePress had its switcher; its others go. Gives how many menus. */
     82        public static function replace_menu_items(): int {
     83                $seen = array();
     84                foreach ( self::menu_items() as $item ) {
     85                        $menu = wp_get_post_terms( $item, 'nav_menu', array( 'fields' => 'ids' ) );
     86                        $menu = is_array( $menu ) && $menu ? (int) $menu[0] : 0;
     87                        if ( $menu && ! isset( $seen[ $menu ] ) ) {
     88                                $seen[ $menu ] = true;
     89                                foreach ( array_combine( array( 'type', 'object', 'object_id', 'url' ), array( 'custom', 'custom', $item, Menu::URL ) ) as $key => $value ) {
     90                                        update_post_meta( $item, '_menu_item_' . $key, $value );
     91                                }
     92                                wp_update_post( array_combine( array( 'ID', 'post_title' ), array( $item, __( 'Languages', 'translate-by-wp-provider' ) ) ) );
     93                        } else {
     94                                foreach ( wp_list_pluck( wp_get_nav_menu_items( $menu ) ?: array(), 'menu_item_parent', 'ID' ) as $below => $parent ) { // phpcs:ignore Universal.Operators.DisallowShortTernary -- no menu: false.
     95                                        if ( (int) $parent === $item ) {
     96                                                update_post_meta( $below, '_menu_item_menu_item_parent', get_post_meta( $item, '_menu_item_menu_item_parent', true ) );
     97                                        }
     98                                }
     99                                wp_delete_post( $item, true );
     100                        }
     101                }
     102                return count( $seen );
     103        }
     104
    79105        /**
    80106         * Posts whose content uses its shortcodes or block.
  • translate-by-wp-provider/tags/0.1.33/src/PageCaches.php

    r3814274 r3837767  
    103103        }
    104104
     105        /** Drop every page from every page cache that is active. */
     106        public static function purge_everything(): void {
     107                $purges   = array_filter( array( 'rocket_clean_domain', 'w3tc_flush_all', 'wp_cache_clear_cache', 'sg_cachepress_purge_everything' ), 'function_exists' );
     108                $purges[] = static fn () => do_action( 'litespeed_purge_all' ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- LiteSpeed Cache's own hook.
     109                /** Every page may be another one now, for other page caches. */
     110                $purges[] = static fn () => do_action( 'wppt_purge_everything' );
     111                foreach ( $purges as $purge ) {
     112                        try {
     113                                $purge();
     114                        } catch ( \Throwable $e ) {
     115                                unset( $e ); // Another plugin's code: what we were doing goes on.
     116                        }
     117                }
     118        }
     119
    105120        /**
    106121         * LiteSpeed Cache: drop each address through its hook. For every address
  • translate-by-wp-provider/tags/0.1.33/src/PlanLanguages.php

    r3814274 r3837767  
    4444                return array_values(
    4545                        array_filter(
    46                                 LanguageChoice::automatic( Settings::targets(), self::by_hand() ),
     46                                Dormant::holds() ? array() : LanguageChoice::automatic( Settings::targets(), self::by_hand() ),
    4747                                static fn ( string $lang ): bool => ! get_transient( self::REFUSED . $lang )
    4848                        )
  • translate-by-wp-provider/tags/0.1.33/src/Plugin.php

    r3836113 r3837767  
    167167                PagesScreen::register();
    168168                Report::register();
     169                Import\Move::register();
    169170                Compat\TranslatePress::register();
    170171                Compat\Weglot::register();
  • translate-by-wp-provider/tags/0.1.33/src/Store/Addresses.php

    r3814274 r3837767  
    3232         * @param string $type post | term.
    3333         * @param int    $id   Object id of the page now.
     34         * @param string $at   Marks the rows of an import.
    3435         */
    35         public static function remember( string $lang, string $url, string $type, int $id ): void {
     36        public static function remember( string $lang, string $url, string $type, int $id, string $at = '' ): bool {
    3637                global $wpdb;
    3738                $path = self::path( $url );
    3839                if ( '/' === $path || $id <= 0 ) {
    39                         return;
     40                        return true;
    4041                }
    4142                $table = Schema::table( 'addresses' );
    … …  
    4445                );
    4546                if ( null !== $known ) {
    46                         return;
     47                        return true;
    4748                }
    48                 $wpdb->insert(
     49                return false !== $wpdb->insert(
    4950                        $table,
    5051                        array(
    … …  
    5354                                'object_type' => $type,
    5455                                'object_id'   => $id,
    55                                 'created_at'  => current_time( 'mysql', true ),
     56                                'created_at'  => '' === $at ? current_time( 'mysql', true ) : $at,
    5657                        )
    5758                );
  • translate-by-wp-provider/tags/0.1.33/src/Store/PageState.php

    r3836113 r3837767  
    299299         * @param string $url  Source URL.
    300300         * @param string $lang Target language.
    301          */
    302         public static function mark_live( string $url, string $lang ): void {
    303                 global $wpdb;
    304                 $now = current_time( 'mysql', true );
     301         * @param string $seen When it was first seen, which marks the rows of an import; now when ''.
     302         */
     303        public static function mark_live( string $url, string $lang, string $seen = '' ): bool {
     304                global $wpdb;
     305                $now  = current_time( 'mysql', true );
     306                $seen = '' === $seen ? $now : $seen;
    305307                if ( Schema::is_current() ) {
    306                         $wpdb->query(
     308                        $done = $wpdb->query(
    307309                                $wpdb->prepare(
    308310                                        'INSERT INTO %i (page_key, lang, url, post_id, live, missing, first_seen, updated_at, url_hash) VALUES (%s, %s, %s, %d, 1, 0, %s, %s, %s)
    … …  
    313315                                        $url,
    314316                                        self::post_id( $url ),
    315                                         $now,
     317                                        $seen,
    316318                                        $now,
    317319                                        md5( $url )
    … …  
    319321                        );
    320322                } else {
    321                         $wpdb->query(
     323                        $done = $wpdb->query(
    322324                                $wpdb->prepare(
    323325                                        'INSERT INTO %i (page_key, lang, url, post_id, live, missing, first_seen, updated_at) VALUES (%s, %s, %s, %d, 1, 0, %s, %s)
    … …  
    328330                                        $url,
    329331                                        self::post_id( $url ),
    330                                         $now,
     332                                        $seen,
    331333                                        $now
    332334                                )
    … …  
    334336                }
    335337                self::$live = null;
     338                return false !== $done;
    336339        }
    337340
  • translate-by-wp-provider/tags/0.1.33/src/Store/Queue.php

    r3814274 r3837767  
    8888                // In the order of the key: two requests that queue overlapping texts then lock the rows in the same order, so neither holds a row the other waits for while it waits for one the other holds (a deadlock).
    8989                ksort( $items, SORT_STRING );
    90                 foreach ( array_chunk( $items, 100, true ) as $chunk ) {
     90                foreach ( \WPPTranslate\Dormant::holds() ? array() : array_chunk( $items, 100, true ) as $chunk ) {
    9191                        $values = array();
    9292                        $args   = array( Schema::table( 'queue' ) );
  • translate-by-wp-provider/tags/0.1.33/src/Store/SegmentUrls.php

    r3836113 r3837767  
    2222
    2323        /**
     24         * In the one order every request writes its rows: two requests that
     25         * render the same texts lock the same rows, and in two orders the
     26         * database ends one of them (a deadlock), whose rows are then missing.
     27         *
     28         * @template T
     29         * @param array<string, T> $by_key Anything by segment key.
     30         * @return array<string, T>
     31         */
     32        private static function ordered( array $by_key ): array {
     33                ksort( $by_key, SORT_STRING );
     34                return $by_key;
     35        }
     36
     37        /**
    2438         * Replace the record for a URL with what its latest render contains, so
    2539         * text edited away stops counting as needed.
    … …  
    3145         */
    3246        public static function record( array $sources, string $url, string $lang ): array {
    33                 $keys = array_keys( $sources );
    3447                self::remember_sources( $sources );
     48                // Each text's place on the page; written in one order (ordered()).
     49                $positions = self::ordered( array_flip( array_keys( $sources ) ) );
    3550                global $wpdb;
    3651                $hash     = md5( $url );
    … …  
    4055                );
    4156                $wpdb->query( $wpdb->prepare( 'DELETE FROM %i WHERE url_hash = %s AND lang = %s', Schema::table( 'segment_urls' ), $hash, $lang ) );
    42                 $position = 0;
    43                 foreach ( array_chunk( array_values( array_unique( $keys ) ), 200 ) as $chunk ) {
     57                foreach ( array_chunk( $positions, 200, true ) as $chunk ) {
    4458                        $values = array();
    4559                        $args   = array( Schema::table( 'segment_urls' ) );
    46                         foreach ( $chunk as $key ) {
     60                        foreach ( $chunk as $key => $position ) {
    4761                                $values[] = '(%s, %s, %s, %s, %d, %s)';
    48                                 array_push( $args, $key, $hash, $lang, $url, $position++, $now );
     62                                array_push( $args, $key, $hash, $lang, $url, $position, $now );
    4963                        }
    5064                        $wpdb->query( // phpcs:ignore PluginCheck.Security.DirectDB.UnescapedDBParameter -- only placeholder groups are concatenated; every value goes through prepare().
    … …  
    7589                $hash = md5( $url );
    7690                $now  = current_time( 'mysql', true );
    77                 foreach ( array_chunk( array_keys( $sources ), 200 ) as $chunk ) {
     91                foreach ( array_chunk( array_keys( self::ordered( $sources ) ), 200 ) as $chunk ) {
    7892                        $values = array();
    7993                        $args   = array( Schema::table( 'segment_urls' ) );
    … …  
    532546                global $wpdb;
    533547                $now = current_time( 'mysql', true );
    534                 foreach ( array_chunk( $sources, 100, true ) as $chunk ) {
     548                foreach ( array_chunk( self::ordered( $sources ), 100, true ) as $chunk ) {
    535549                        $values = array();
    536550                        $args   = array( Schema::table( 'segments' ) );
  • translate-by-wp-provider/tags/0.1.33/src/Store/Slugs.php

    r3818523 r3837767  
    134134        public static function store_base( string $lang, string $kind, int $id, string $slug, string $source_path, string $path ): ?string {
    135135                $kept = self::kept_path( $lang, $kind, $id );
    136                 if ( null !== $kept || self::path_taken( $lang, $path, 0 ) ) {
     136                if ( null !== $kept || null !== \WPPTranslate\Dormant::move() || self::path_taken( $lang, $path, 0 ) ) {
    137137                        return $kept;
    138138                }
    … …  
    337337         */
    338338        private static function claim( string $lang, string $type, int $id, string $slug, string $source_path, string $wanted, bool $replace ): ?string {
     339                if ( null !== \WPPTranslate\Dormant::move() ) {
     340                        return null; // The plugin a site may go back to does not know our addresses.
     341                }
    339342                global $wpdb;
    340343                $lock   = 'wppt_slugs_' . md5( Schema::table( 'slugs' ) . '|' . $lang );
  • translate-by-wp-provider/tags/0.1.33/src/StoredText.php

    r3818452 r3837767  
    5555                        return;
    5656                }
    57                 $url = self::url( $group );
     57                $url     = self::url( $group );
     58                $by_hand = PlanLanguages::by_hand();
    5859                foreach ( Settings::targets() as $lang ) {
    5960                        SegmentUrls::add( $sources, $url, $lang );
     61                        if ( in_array( $lang, $by_hand, true ) ) {
     62                                // Recorded, to be translated by hand; never sent.
     63                                continue;
     64                        }
    6065                        $missing = array_diff_key( $sources, Translations::lookup( $lang, array_keys( $sources ) ) );
    6166                        $items   = array();
  • translate-by-wp-provider/tags/0.1.33/src/Sync.php

    r3814274 r3837767  
    311311         */
    312312        private static function submit( Client $client, string $lang, string $source, array $rows, array $segments, ?string $page, array &$stats ): ?string {
     313                if ( Dormant::holds() ) {
     314                        return 'stop';
     315                }
    313316                $response = $client->submit( $source, array( $lang ), $segments, $page );
    314317                if ( is_wp_error( $response ) && 'wppt_payment' === $response->get_error_code() ) {
  • translate-by-wp-provider/tags/0.1.33/translate-by-wp-provider.php

    r3836113 r3837767  
    44 * Plugin URI:        https://wpptranslate.com/
    55 * Description:       Translate what visitors read into other languages. Translations are stored in your own database; page views never call an external service.
    6  * Version:           0.1.32
     6 * Version:           0.1.33
    77 * Requires at least: 6.5
    88 * Requires PHP:      7.4
    … …  
    2929
    3030define( 'WPPT_FILE', __FILE__ );
    31 define( 'WPPT_VERSION', '0.1.32' );
     31define( 'WPPT_VERSION', '0.1.33' );
    3232
    3333/**
  • translate-by-wp-provider/tags/0.1.33/vendor/composer/autoload_classmap.php

    r3836113 r3837767  
    7070    'WPPTranslate\\Html\\VisitorValues' => $baseDir . '/src/Html/VisitorValues.php',
    7171    'WPPTranslate\\Import\\Aligner' => $baseDir . '/src/Import/Aligner.php',
     72    'WPPTranslate\\Import\\Move' => $baseDir . '/src/Import/Move.php',
     73    'WPPTranslate\\Import\\MoveScreen' => $baseDir . '/src/Import/MoveScreen.php',
     74    'WPPTranslate\\Import\\PageMove' => $baseDir . '/src/Import/PageMove.php',
    7275    'WPPTranslate\\Import\\PairBook' => $baseDir . '/src/Import/PairBook.php',
    7376    'WPPTranslate\\Import\\Progress' => $baseDir . '/src/Import/Progress.php',
  • translate-by-wp-provider/tags/0.1.33/vendor/composer/autoload_static.php

    r3836113 r3837767  
    8585        'WPPTranslate\\Html\\VisitorValues' => __DIR__ . '/../..' . '/src/Html/VisitorValues.php',
    8686        'WPPTranslate\\Import\\Aligner' => __DIR__ . '/../..' . '/src/Import/Aligner.php',
     87        'WPPTranslate\\Import\\Move' => __DIR__ . '/../..' . '/src/Import/Move.php',
     88        'WPPTranslate\\Import\\MoveScreen' => __DIR__ . '/../..' . '/src/Import/MoveScreen.php',
     89        'WPPTranslate\\Import\\PageMove' => __DIR__ . '/../..' . '/src/Import/PageMove.php',
    8790        'WPPTranslate\\Import\\PairBook' => __DIR__ . '/../..' . '/src/Import/PairBook.php',
    8891        'WPPTranslate\\Import\\Progress' => __DIR__ . '/../..' . '/src/Import/Progress.php',
  • translate-by-wp-provider/tags/0.1.33/vendor/composer/installed.php

    r3836113 r3837767  
    22    'root' => array(
    33        'name' => 'wp-provider/translate-by-wp-provider',
    4         'pretty_version' => 'v0.1.32',
    5         'version' => '0.1.32.0',
    6         'reference' => '0f1e6b6144c11679adb2f95a236105a58bca9377',
     4        'pretty_version' => 'v0.1.33',
     5        'version' => '0.1.33.0',
     6        'reference' => '77f3a39bc23d04cde67366e80a6931e842edc44d',
    77        'type' => 'wordpress-plugin',
    88        'install_path' => __DIR__ . '/../../',
    … …  
    1212    'versions' => array(
    1313        'wp-provider/translate-by-wp-provider' => array(
    14             'pretty_version' => 'v0.1.32',
    15             'version' => '0.1.32.0',
    16             'reference' => '0f1e6b6144c11679adb2f95a236105a58bca9377',
     14            'pretty_version' => 'v0.1.33',
     15            'version' => '0.1.33.0',
     16            'reference' => '77f3a39bc23d04cde67366e80a6931e842edc44d',
    1717            'type' => 'wordpress-plugin',
    1818            'install_path' => __DIR__ . '/../../',
  • translate-by-wp-provider/trunk/readme.txt

    r3836113 r3837767  
    55Tested up to: 7.2
    66Requires PHP: 7.4
    7 Stable tag: 0.1.32
     7Stable tag: 0.1.33
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
    … …  
    6060= I use WPML or TranslatePress. Can I switch? =
    6161
    62 Yes. The plugin imports the translations you already have, so pages do not need to be translated again. You start the import from the command line with WP-CLI (`wp wpprovider-translate wpml-import` or `wp wpprovider-translate translatepress-import`); wp-admin has no button for it. On a large site both run in batches (`--limit` and `--offset`), so each command stays well within the time a host allows.
     62Yes. The plugin imports the translations you already have, so pages do not need to be translated again. From TranslatePress, a small and simple site does it in wp-admin: after connecting, click "Bring my translations over" and keep the screen open while your pages are read. Your visitors keep TranslatePress. Look at your new pages privately, then switch over with one click; you can go back with one click until you say that everything looks good. When your site is larger or set up differently, the screen says why, and you can write to support@wpptranslate.com: we move it for you. From WPML, or from TranslatePress on the command line, you start the import with WP-CLI (`wp wpprovider-translate wpml-import` or `wp wpprovider-translate translatepress-import`). On a large site both run in batches (`--limit` and `--offset`), so each command stays well within the time a host allows.
    6363
    6464= Can a product feed or a search index use my translations? =
  • translate-by-wp-provider/trunk/src/Admin.php

    r3836113 r3837767  
    155155                        <?php
    156156                        $step = Onboarding::step();
     157                        $card = Import\MoveScreen::render( 'connect' === $step && Connect::waiting() );
    157158                        if ( 'done' !== $step ) {
    158                                 Onboarding::render_steps( $step );
    159                                 if ( 'connect' === $step ) {
     159                                $card ? null : Onboarding::render_steps( $step );
     160                                if ( $card ) {
     161                                        $step = 'move';
     162                                } elseif ( 'connect' === $step ) {
    160163                                        $settings['source_lang'] = FirstLanguages::chosen()['source'] ?? $settings['source_lang'];
    161164                                        Onboarding::render_start( fn ( array $langs ) => self::render_targets( $settings, $langs ) );
  • translate-by-wp-provider/trunk/src/Cli.php

    r3836067 r3837767  
    545545                update_option( Settings::OPTION, $saved );
    546546                WP_CLI::log( sprintf( 'Languages: %s, translated into %s.', $languages['source'], implode( ', ', $saved['target_langs'] ) ) );
    547                 // One language menu item of ours per menu, where TranslatePress had its switcher.
    548                 $menus = 0;
    549                 $seen  = array();
    550                 foreach ( Import\TranslatePress::menu_items() as $item ) {
    551                         $menu = wp_get_post_terms( $item, 'nav_menu', array( 'fields' => 'ids' ) );
    552                         $menu = is_array( $menu ) && $menu ? (int) $menu[0] : 0;
    553                         if ( $menu && ! isset( $seen[ $menu ] ) ) {
    554                                 $seen[ $menu ] = true;
    555                                 update_post_meta( $item, '_menu_item_type', 'custom' );
    556                                 update_post_meta( $item, '_menu_item_object', 'custom' );
    557                                 update_post_meta( $item, '_menu_item_object_id', $item );
    558                                 update_post_meta( $item, '_menu_item_url', Menu::URL );
    559                                 wp_update_post(
    560                                         array(
    561                                                 'ID'         => $item,
    562                                                 'post_title' => __( 'Languages', 'translate-by-wp-provider' ),
    563                                         )
    564                                 );
    565                                 ++$menus;
    566                         } else {
    567                                 wp_delete_post( $item, true );
    568                         }
    569                 }
    570                 WP_CLI::log( sprintf( 'Language switchers in menus replaced: %d.', $menus ) );
     547                WP_CLI::log( sprintf( 'Language switchers in menus replaced: %d.', Import\TranslatePress::replace_menu_items() ) );
    571548                foreach ( Import\TranslatePress::content_usage() as $what => $count ) {
    572549                        WP_CLI::log( sprintf( '%s in %d page(s): keeps working through WP Provider Translate.', $what, $count ) );
  • translate-by-wp-provider/trunk/src/Compat/Multilingual.php

    r3814274 r3837767  
    1010defined( 'ABSPATH' ) || exit;
    1111
     12use WPPTranslate\Import\MoveScreen;
    1213use WPPTranslate\Settings;
    1314
    … …  
    127128         */
    128129        public static function render( bool $offer_choice = false ): void {
    129                 $active = self::active();
     130                // Moving over has a card of its own.
     131                $active = ! $offer_choice && MoveScreen::replaces_choice() ? array_diff( self::active(), array( 'translatepress' ) ) : self::active();
    130132                if ( ! $active ) {
    131133                        return;
  • translate-by-wp-provider/trunk/src/Compat/TranslatePress.php

    r3814274 r3837767  
    1010defined( 'ABSPATH' ) || exit;
    1111
     12use WPPTranslate\Dormant;
    1213use WPPTranslate\Import\TranslatePress as Source;
    1314use WPPTranslate\LanguageContent;
     15use WPPTranslate\Menu;
    1416use WPPTranslate\Picker;
    1517
    1618/**
    1719 * Once TranslatePress is off, its shortcodes and block in the site's
    18  * content are handled here, so no page shows `[language-switcher]` and no
    19  * content meant for one language shows in all of them. The content itself
    20  * is not changed.
     20 * content and its switchers in menus are handled here, so no page shows `[language-switcher]` and no
     21 * content meant for one language shows in all of them. The content and
     22 * the menus themselves are not changed.
    2123 */
    2224final class TranslatePress {
    2325
    2426        /**
    25          * Hooks, only when TranslatePress is not running and left settings.
     27         * Hooks, only when TranslatePress is not running (or stays out of this
     28         * request) and left settings.
    2629         */
    2730        public static function register(): void {
    28                 if ( Source::active() || ! Source::available() ) {
     31                if ( ( Source::active() && ! Dormant::alone() ) || ! Source::available() ) {
    2932                        return;
    3033                }
    3134                add_action( 'init', array( self::class, 'shortcodes' ), 20 );
    3235                add_action( 'init', array( self::class, 'block' ), 20 );
     36                add_action( 'init', array( self::class, 'post_type' ), 20 );
     37                if ( ! is_admin() ) {
     38                        add_filter( 'wp_nav_menu_objects', array( self::class, 'one_switcher' ), 4 );
     39                }
     40        }
     41
     42        /** Its switcher in a menu is ours, where the menu is shown: one for all, where it has an item per language. */
     43        public static function one_switcher( $items ) {
     44                $out  = array();
     45                $seen = false;
     46                foreach ( $items as $item ) {
     47                        $theirs = 'language_switcher' === ( $item->object ?? '' );
     48                        if ( $theirs && ! $seen ) {
     49                                $item        = clone $item;
     50                                $item->url   = Menu::URL;
     51                                $item->title = __( 'Languages', 'translate-by-wp-provider' );
     52                        }
     53                        if ( ! $theirs || ! $seen ) {
     54                                $out[] = $item;
     55                        }
     56                        $seen = $seen || $theirs;
     57                }
     58                return $out;
     59        }
     60
     61        /** Its post type, so that WordPress knows its menu items. */
     62        public static function post_type(): void {
     63                register_post_type( 'language_switcher', array( 'public' => false ) );
    3364        }
    3465
  • translate-by-wp-provider/trunk/src/Compat/WooCommerceEmails.php

    r3814274 r3837767  
    1212use WPPTranslate\Html\Segmenter;
    1313use WPPTranslate\Languages;
     14use WPPTranslate\PlanLanguages;
    1415use WPPTranslate\Settings;
    1516use WPPTranslate\StoredText;
    … …  
    238239                $url = StoredText::url( self::GROUP );
    239240                SegmentUrls::add( $texts, $url, $lang );
     241                if ( in_array( $lang, PlanLanguages::by_hand(), true ) ) {
     242                        // Recorded, to be translated by hand; never sent.
     243                        return;
     244                }
    240245                $missing = array_diff_key( $texts, Translations::lookup( $lang, array_keys( $texts ) ) );
    241246                $items   = array();
  • translate-by-wp-provider/trunk/src/Connect.php

    r3836113 r3837767  
    4848        public static function start(): void {
    4949                self::guard( 'wppt_connect' );
     50                FirstLanguages::drop();
    5051                self::login();
    5152        }
    … …  
    189190        public static function auto(): void {
    190191                self::guard( 'wppt_auto_connect' );
     192                FirstLanguages::drop();
    191193                self::connect();
    192194        }
    … …  
    286288         */
    287289        private static function connected( string $account ): string {
    288                 return Settings::targets()
     290                return Settings::targets() || Import\MoveScreen::replaces_choice()
    289291                        /* translators: %s: account name. */
    290292                        ? sprintf( __( 'Connected to %s.', 'translate-by-wp-provider' ), $account )
  • translate-by-wp-provider/trunk/src/Crawl.php

    r3814274 r3837767  
    4949         */
    5050        public static function start(): void {
    51                 if ( ! Settings::targets() ) {
     51                if ( ! Settings::targets() || Dormant::holds() ) {
    5252                        return;
    5353                }
  • translate-by-wp-provider/trunk/src/Dormant.php

    r3814274 r3837767  
    3030 *   argument so that no page cache in front of the site answers them
    3131 *   instead; it is removed again before WordPress reads the request.
     32 *
     33 * While a site moves over from TranslatePress the option holds the move
     34 * (Import\Move): dormant while TranslatePress is loaded, and until
     35 * everything was read. So one plugin shows, whatever switches that one.
    3236 */
    3337final class Dormant {
    … …  
    5054        private static ?string $kind = null;
    5155
     56        /** Whether this request shows the plugin while a move is open, to anyone or in an administrator's preview. */
     57        private static bool $shown    = false;
     58        private static bool $previews = false;
     59
    5260        /**
    5361         * Whether the plugin is dormant on this site.
    5462         */
    5563        public static function on(): bool {
    56                 return function_exists( 'get_option' ) && (bool) get_option( self::OPTION, false );
     64                return ! self::$shown && function_exists( 'get_option' ) && (bool) get_option( self::OPTION, false );
     65        }
     66
     67        /** The move that is open (status, source, targets); null when there is none. */
     68        public static function move( bool $fresh = false ): ?array {
     69                $move = $fresh ? Fresh::option( self::OPTION ) : ( function_exists( 'get_option' ) ? get_option( self::OPTION ) : null );
     70                return is_array( $move ) && isset( $move['status'], $move['source'], $move['targets'] ) ? $move : null;
     71        }
     72
     73        /** Whether nothing is sent: from the start of a move until its owner chose the switch, whatever is off or on. */
     74        public static function holds(): bool {
     75                // A background run that shows the plugin lives for minutes: the owner may have gone back since.
     76                $move = self::move( self::$shown );
     77                if ( self::$shown && in_array( $move['file'] ?? '', (array) Fresh::option( 'active_plugins', array() ), true ) ) {
     78                        return true;
     79                }
     80                return self::$shown ? 'switched' !== ( $move['status'] ?? '' ) : null !== $move && 'switched' !== $move['status'];
     81        }
     82
     83        /** Whether visitors get this plugin while a move is open, given whether the other plugin is loaded. */
     84        public static function shows( string $status, bool $loaded ): bool {
     85                return ! $loaded && in_array( $status, array( 'ready', 'switched' ), true );
     86        }
     87
     88        /**
     89         * Filter on the settings while a move is open: its languages are in no
     90         * request but one that shows this plugin, and not stored before the move
     91         * is confirmed. So nothing is sent, also by an older version of this plugin.
     92         *
     93         * @param mixed $saved Settings as stored.
     94         */
     95        public static function languages( $saved ) {
     96                $move  = self::move();
     97                $saved = is_array( $saved ) ? $saved : array();
     98                if ( null === $move ) {
     99                        return $saved;
     100                }
     101                return self::$shown || self::$previews ? self::languages_of( $move ) + $saved : array( 'target_langs' => array() ) + $saved;
     102        }
     103
     104        /** Filter `pre_update_option` on the settings while a move is open: whoever writes them, the move's languages stay out. */
     105        public static function without_languages( $value ) {
     106                remove_filter( 'option_' . Settings::OPTION, array( self::class, 'languages' ) );
     107                $stored = (array) get_option( Settings::OPTION, array() );
     108                add_filter( 'option_' . Settings::OPTION, array( self::class, 'languages' ) );
     109                $source = array_intersect_key( $stored, array( 'source_lang' => '' ) );
     110                return array( 'target_langs' => array() ) + $source + array_diff_key( (array) $value, array( 'source_lang' => '' ) );
    57111        }
    58112
    … …  
    60114         * What a request gets while dormant.
    61115         *
    62          * @param array{cli?: bool, cron?: bool, admin?: bool, ajax?: bool, ajax_action?: string, uri?: string, own_render?: bool, preview?: bool, can_manage?: bool} $request What is known about the request.
     116         * @param array{cli?: bool, cron?: bool, admin?: bool, ajax?: bool, ajax_action?: string, uri?: string, own_render?: bool, import?: bool, preview?: bool, can_manage?: bool} $request What is known about the request.
    63117         * @return string One of HIDDEN, BACKGROUND, FULL.
    64118         */
    65119        public static function kind_of( array $request ): string {
     120                // The import reads the page as a visitor gets it, from the other plugin.
     121                if ( ! empty( $request['own_render'] ) && ! empty( $request['import'] ) ) {
     122                        return self::HIDDEN;
     123                }
    66124                if ( ! empty( $request['own_render'] ) ) {
    67125                        return self::FULL;
    … …  
    140198         */
    141199        public static function decide(): void {
     200                $move = self::move();
     201                if ( null !== $move ) {
     202                        add_filter( 'option_' . Settings::OPTION, array( self::class, 'languages' ) );
     203                        add_filter( 'pre_update_option_' . Settings::OPTION, array( self::class, 'without_languages' ) );
     204                        self::$shown = self::shows( $move['status'], Import\TranslatePress::active() );
     205                }
     206                if ( self::$shown ) {
     207                        Plugin::hooks();
     208                        return;
     209                }
    142210                // phpcs:disable WordPress.Security.NonceVerification.Recommended -- only which request this is, nothing is changed.
    143211                $action     = isset( $_REQUEST['action'] ) ? sanitize_key( wp_unslash( $_REQUEST['action'] ) ) : '';
    144212                $preview    = ! empty( $_GET[ self::PREVIEW ] );
     213                $render     = isset( $_SERVER['HTTP_X_WPPT_RENDER'] ) ? sanitize_key( wp_unslash( $_SERVER['HTTP_X_WPPT_RENDER'] ) ) : '';
    145214                self::$kind = self::kind_of(
    146215                        array(
    … …  
    152221                                'uri'         => Router::request_uri(),
    153222                                'own_render'  => RenderPass::is_own_render(),
     223                                'import'      => 'import' === $render,
    154224                                'preview'     => $preview,
    155225                                // Asked only for a preview: a visitor's request does not load the user early.
    … …  
    159229                // phpcs:enable
    160230                if ( self::HIDDEN === self::$kind ) {
     231                        if ( RenderPass::is_own_render() ) {
     232                                // The import reads past page caches, and past a maintenance mode.
     233                                self::remove_args();
     234                                self::keep_out_of_caches();
     235                                RenderPass::register();
     236                        }
    161237                        return;
    162238                }
    … …  
    165241                        self::keep_out_of_caches();
    166242                        self::quiet_other_plugin();
     243                        if ( $preview && ! RenderPass::is_own_render() ) {
     244                                self::$previews = null !== $move;
     245                                add_action( 'wp_footer', array( self::class, 'keep_preview' ) );
     246                        }
    167247                }
    168248                Plugin::hooks();
    … …  
    209289                add_filter( 'weglot_active_translation_before_treat_page', '__return_false', PHP_INT_MAX );
    210290                add_filter( 'weglot_active_translation', '__return_false', PHP_INT_MAX );
     291                // TranslatePress: none of its hooks. It asks at `plugins_loaded`, after this.
     292                add_filter( 'trp_allow_tp_to_run', '__return_false', PHP_INT_MAX );
     293        }
     294
     295        /** The move's languages, as settings. */
     296        private static function languages_of( array $move ): array {
     297                return array_combine( array( 'source_lang', 'target_langs' ), array( $move['source'], $move['targets'] ) );
     298        }
     299
     300        /** The move is over. Given the move, its languages are stored, unless others were chosen since. */
     301        public static function end( ?array $move = null ): void {
     302                remove_filter( 'pre_update_option_' . Settings::OPTION, array( self::class, 'without_languages' ) );
     303                remove_filter( 'option_' . Settings::OPTION, array( self::class, 'languages' ) );
     304                if ( null !== $move && ! Settings::targets() ) {
     305                        Settings::save_connection( self::languages_of( $move ) );
     306                }
     307                delete_option( self::OPTION );
     308        }
     309
     310        /** A link in an administrator's preview leads to the preview of the next page. */
     311        public static function keep_preview(): void {
     312                wp_print_inline_script_tag(
     313                        'document.addEventListener("click",function(e){var a=e.target.closest&&e.target.closest("a[href]");if(!a||a.origin!==location.origin||/\/wp-(admin|login)/.test(a.pathname)||a.getAttribute("href").charAt(0)==="#"){return;}var u=new URL(a.href);u.searchParams.set("' . self::PREVIEW . '","1");a.href=u.href;},true);'
     314                );
     315        }
     316
     317        /** Whether the other plugin stays out of this request. */
     318        public static function alone(): bool {
     319                return self::FULL === self::$kind;
    211320        }
    212321
    … …  
    215324         */
    216325        public static function notice(): void {
    217                 if ( ! self::on() || ! current_user_can( 'manage_options' ) ) {
     326                if ( self::$shown && 'plugins' === ( get_current_screen()->id ?? '' ) && current_user_can( 'manage_options' ) ) {
     327                        echo '<div class="notice notice-warning"><p>' . esc_html__( 'Your translated pages come from WP Provider Translate. If you switch it off, visitors have no translations. To return to TranslatePress, use "Go back" first.', 'translate-by-wp-provider' ) . ' <a href="' . esc_url( Admin::url() ) . '">' . esc_html__( 'Open', 'translate-by-wp-provider' ) . '</a></p></div>';
     328                }
     329                $own = null !== self::move() && preg_match( '/wp-?provider/', get_current_screen()->id ?? '' ); // Our own screens: the card says it.
     330                if ( $own || ! self::on() || ! current_user_can( 'manage_options' ) ) {
    218331                        return;
    219332                }
    220333                echo '<div class="notice notice-warning"><p>';
     334                if ( null !== self::move() ) {
     335                        echo esc_html__( 'Your translations are being brought over. Visitors still get TranslatePress.', 'translate-by-wp-provider' ) . ' <a href="' . esc_url( Admin::url() ) . '">' . esc_html__( 'See how far it is', 'translate-by-wp-provider' ) . '</a></p></div>';
     336                        return;
     337                }
    221338                echo esc_html__( 'WP Provider Translate is dormant: it translates the site in the background, but visitors do not see the translations yet. Administrators can preview a page by adding ?wppt_preview=1 to its address. To go live, delete the option wppt_dormant (wp option delete wppt_dormant).', 'translate-by-wp-provider' );
    222339                echo '</p></div>';
    … …  
    227344         */
    228345        public static function reset(): void {
    229                 self::$kind = null;
     346                self::$kind     = null;
     347                self::$shown    = false;
     348                self::$previews = false;
    230349        }
    231350}
  • translate-by-wp-provider/trunk/src/FirstLanguages.php

    r3836113 r3837767  
    4040        /**
    4141         * What the first screen starts with: English for a site in another
    42          * language, nothing for a site in English.
     42         * language, nothing for a site in English or next to another translation
     43         * plugin, which usually has that address.
    4344         *
    4445         * @param string $source Site language.
    … …  
    4647         */
    4748        public static function suggested( string $source ): array {
    48                 return 'en' === $source ? array() : array( 'en' );
     49                return 'en' === $source || Multilingual::active() ? array() : array( 'en' );
    4950        }
    5051
    … …  
    6263                        return false;
    6364                }
     65                if ( null !== Dormant::move() ) {
     66                        return true;
     67                }
    6468                update_option(
    6569                        self::OPTION,
    6670                        array(
     71                                'instead'         => null !== Import\Move::offer(),
    6772                                'source'          => $source,
    6873                                'targets'         => $langs,
    … …  
    7277                );
    7378                return true;
     79        }
     80
     81        /**
     82         * Connecting to move over from another plugin, or not from the first
     83         * screen: what that screen kept is not what was asked for now.
     84         */
     85        public static function drop(): void {
     86                if ( null !== Import\Move::offer() ) {
     87                        delete_option( self::OPTION );
     88                }
    7489        }
    7590
    … …  
    93108         */
    94109        public static function apply(): void {
     110                $kept = get_option( self::OPTION );
     111                if ( null !== Dormant::move() || ( empty( $kept['instead'] ) && null !== Import\Move::offer() ) ) {
     112                        return;
     113                }
    95114                $chosen = self::chosen();
    96115                if ( null === $chosen || Settings::targets() ) {
  • translate-by-wp-provider/trunk/src/Import/Progress.php

    r3814274 r3837767  
    6868        public static function busy( int $now ): bool {
    6969                $started = (int) get_option( self::RUNNING, 0 );
    70                 if ( $started > 0 && $now - $started < self::RUN_SECONDS ) {
     70                if ( null !== \WPPTranslate\Dormant::move() || ( $started > 0 && $now - $started < self::RUN_SECONDS ) ) {
    7171                        return true;
    7272                }
  • translate-by-wp-provider/trunk/src/Import/RenderedImport.php

    r3814274 r3837767  
    105105                                }
    106106                                $aligned = Aligner::align( self::segments( $original ), self::segments( $translated ) );
    107                                 $pairs   = $aligned['pairs'];
    108                                 // Image descriptions, titles and labels, in page order.
    109                                 $a = array_values( Attributes::extract( $original ) );
    110                                 $b = array_values( Attributes::extract( $translated ) );
    111                                 if ( count( $a ) === count( $b ) ) {
    112                                         foreach ( $a as $i => $text ) {
    113                                                 if ( Aligner::fits( $text, $b[ $i ] ) ) {
    114                                                         $pairs[] = array( $text, $b[ $i ] );
    115                                                 }
    116                                         }
    117                                 }
    118                                 $count = 0;
    119                                 foreach ( $pairs as $pair ) {
     107                                $count   = 0;
     108                                foreach ( array_merge( $aligned['pairs'], self::attribute_pairs( $original, $translated ) ) as $pair ) {
    120109                                        // The same text on both sides was not translated: nothing to import.
    121110                                        if ( Segment::normalize( $pair[0] ) !== Segment::normalize( $pair[1] ) ) {
    … …  
    167156                }
    168157                return $report;
     158        }
     159
     160        /** Image descriptions, titles and labels of two pages, paired in page order. */
     161        public static function attribute_pairs( string $original, string $translated ): array {
     162                $a = array_values( Attributes::extract( $original ) );
     163                $b = array_values( Attributes::extract( $translated ) );
     164                return count( $a ) !== count( $b ) ? array() : array_filter( array_map( null, $a, $b ), static fn ( array $pair ): bool => Aligner::fits( $pair[0], $pair[1] ) );
    169165        }
    170166
    … …  
    344340         * @param string $lang Language code.
    345341         */
    346         private static function prefixed( string $url, string $lang ): string {
     342        public static function prefixed( string $url, string $lang ): string {
    347343                $home = untrailingslashit( home_url() );
    348344                return $home . '/' . $lang . substr( $url, strlen( $home ) );
    … …  
    365361         * @return string[]
    366362         */
    367         private static function segments( string $html ): array {
     363        public static function segments( string $html ): array {
    368364                return array_map( fn ( Segment $s ) => $s->source, Segmenter::parse( $html )->segments );
    369365        }
  • translate-by-wp-provider/trunk/src/Import/TranslatePress.php

    r3814274 r3837767  
    99
    1010defined( 'ABSPATH' ) || exit;
     11
     12use WPPTranslate\Menu;
    1113
    1214/**
    … …  
    7779        }
    7880
     81        /** One language menu item of ours per menu, where TranslatePress had its switcher; its others go. Gives how many menus. */
     82        public static function replace_menu_items(): int {
     83                $seen = array();
     84                foreach ( self::menu_items() as $item ) {
     85                        $menu = wp_get_post_terms( $item, 'nav_menu', array( 'fields' => 'ids' ) );
     86                        $menu = is_array( $menu ) && $menu ? (int) $menu[0] : 0;
     87                        if ( $menu && ! isset( $seen[ $menu ] ) ) {
     88                                $seen[ $menu ] = true;
     89                                foreach ( array_combine( array( 'type', 'object', 'object_id', 'url' ), array( 'custom', 'custom', $item, Menu::URL ) ) as $key => $value ) {
     90                                        update_post_meta( $item, '_menu_item_' . $key, $value );
     91                                }
     92                                wp_update_post( array_combine( array( 'ID', 'post_title' ), array( $item, __( 'Languages', 'translate-by-wp-provider' ) ) ) );
     93                        } else {
     94                                foreach ( wp_list_pluck( wp_get_nav_menu_items( $menu ) ?: array(), 'menu_item_parent', 'ID' ) as $below => $parent ) { // phpcs:ignore Universal.Operators.DisallowShortTernary -- no menu: false.
     95                                        if ( (int) $parent === $item ) {
     96                                                update_post_meta( $below, '_menu_item_menu_item_parent', get_post_meta( $item, '_menu_item_menu_item_parent', true ) );
     97                                        }
     98                                }
     99                                wp_delete_post( $item, true );
     100                        }
     101                }
     102                return count( $seen );
     103        }
     104
    79105        /**
    80106         * Posts whose content uses its shortcodes or block.
  • translate-by-wp-provider/trunk/src/PageCaches.php

    r3814274 r3837767  
    103103        }
    104104
     105        /** Drop every page from every page cache that is active. */
     106        public static function purge_everything(): void {
     107                $purges   = array_filter( array( 'rocket_clean_domain', 'w3tc_flush_all', 'wp_cache_clear_cache', 'sg_cachepress_purge_everything' ), 'function_exists' );
     108                $purges[] = static fn () => do_action( 'litespeed_purge_all' ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- LiteSpeed Cache's own hook.
     109                /** Every page may be another one now, for other page caches. */
     110                $purges[] = static fn () => do_action( 'wppt_purge_everything' );
     111                foreach ( $purges as $purge ) {
     112                        try {
     113                                $purge();
     114                        } catch ( \Throwable $e ) {
     115                                unset( $e ); // Another plugin's code: what we were doing goes on.
     116                        }
     117                }
     118        }
     119
    105120        /**
    106121         * LiteSpeed Cache: drop each address through its hook. For every address
  • translate-by-wp-provider/trunk/src/PlanLanguages.php

    r3814274 r3837767  
    4444                return array_values(
    4545                        array_filter(
    46                                 LanguageChoice::automatic( Settings::targets(), self::by_hand() ),
     46                                Dormant::holds() ? array() : LanguageChoice::automatic( Settings::targets(), self::by_hand() ),
    4747                                static fn ( string $lang ): bool => ! get_transient( self::REFUSED . $lang )
    4848                        )
  • translate-by-wp-provider/trunk/src/Plugin.php

    r3836113 r3837767  
    167167                PagesScreen::register();
    168168                Report::register();
     169                Import\Move::register();
    169170                Compat\TranslatePress::register();
    170171                Compat\Weglot::register();
  • translate-by-wp-provider/trunk/src/Store/Addresses.php

    r3814274 r3837767  
    3232         * @param string $type post | term.
    3333         * @param int    $id   Object id of the page now.
     34         * @param string $at   Marks the rows of an import.
    3435         */
    35         public static function remember( string $lang, string $url, string $type, int $id ): void {
     36        public static function remember( string $lang, string $url, string $type, int $id, string $at = '' ): bool {
    3637                global $wpdb;
    3738                $path = self::path( $url );
    3839                if ( '/' === $path || $id <= 0 ) {
    39                         return;
     40                        return true;
    4041                }
    4142                $table = Schema::table( 'addresses' );
    … …  
    4445                );
    4546                if ( null !== $known ) {
    46                         return;
     47                        return true;
    4748                }
    48                 $wpdb->insert(
     49                return false !== $wpdb->insert(
    4950                        $table,
    5051                        array(
    … …  
    5354                                'object_type' => $type,
    5455                                'object_id'   => $id,
    55                                 'created_at'  => current_time( 'mysql', true ),
     56                                'created_at'  => '' === $at ? current_time( 'mysql', true ) : $at,
    5657                        )
    5758                );
  • translate-by-wp-provider/trunk/src/Store/PageState.php

    r3836113 r3837767  
    299299         * @param string $url  Source URL.
    300300         * @param string $lang Target language.
    301          */
    302         public static function mark_live( string $url, string $lang ): void {
    303                 global $wpdb;
    304                 $now = current_time( 'mysql', true );
     301         * @param string $seen When it was first seen, which marks the rows of an import; now when ''.
     302         */
     303        public static function mark_live( string $url, string $lang, string $seen = '' ): bool {
     304                global $wpdb;
     305                $now  = current_time( 'mysql', true );
     306                $seen = '' === $seen ? $now : $seen;
    305307                if ( Schema::is_current() ) {
    306                         $wpdb->query(
     308                        $done = $wpdb->query(
    307309                                $wpdb->prepare(
    308310                                        'INSERT INTO %i (page_key, lang, url, post_id, live, missing, first_seen, updated_at, url_hash) VALUES (%s, %s, %s, %d, 1, 0, %s, %s, %s)
    … …  
    313315                                        $url,
    314316                                        self::post_id( $url ),
    315                                         $now,
     317                                        $seen,
    316318                                        $now,
    317319                                        md5( $url )
    … …  
    319321                        );
    320322                } else {
    321                         $wpdb->query(
     323                        $done = $wpdb->query(
    322324                                $wpdb->prepare(
    323325                                        'INSERT INTO %i (page_key, lang, url, post_id, live, missing, first_seen, updated_at) VALUES (%s, %s, %s, %d, 1, 0, %s, %s)
    … …  
    328330                                        $url,
    329331                                        self::post_id( $url ),
    330                                         $now,
     332                                        $seen,
    331333                                        $now
    332334                                )
    … …  
    334336                }
    335337                self::$live = null;
     338                return false !== $done;
    336339        }
    337340
  • translate-by-wp-provider/trunk/src/Store/Queue.php

    r3814274 r3837767  
    8888                // In the order of the key: two requests that queue overlapping texts then lock the rows in the same order, so neither holds a row the other waits for while it waits for one the other holds (a deadlock).
    8989                ksort( $items, SORT_STRING );
    90                 foreach ( array_chunk( $items, 100, true ) as $chunk ) {
     90                foreach ( \WPPTranslate\Dormant::holds() ? array() : array_chunk( $items, 100, true ) as $chunk ) {
    9191                        $values = array();
    9292                        $args   = array( Schema::table( 'queue' ) );
  • translate-by-wp-provider/trunk/src/Store/SegmentUrls.php

    r3836113 r3837767  
    2222
    2323        /**
     24         * In the one order every request writes its rows: two requests that
     25         * render the same texts lock the same rows, and in two orders the
     26         * database ends one of them (a deadlock), whose rows are then missing.
     27         *
     28         * @template T
     29         * @param array<string, T> $by_key Anything by segment key.
     30         * @return array<string, T>
     31         */
     32        private static function ordered( array $by_key ): array {
     33                ksort( $by_key, SORT_STRING );
     34                return $by_key;
     35        }
     36
     37        /**
    2438         * Replace the record for a URL with what its latest render contains, so
    2539         * text edited away stops counting as needed.
    … …  
    3145         */
    3246        public static function record( array $sources, string $url, string $lang ): array {
    33                 $keys = array_keys( $sources );
    3447                self::remember_sources( $sources );
     48                // Each text's place on the page; written in one order (ordered()).
     49                $positions = self::ordered( array_flip( array_keys( $sources ) ) );
    3550                global $wpdb;
    3651                $hash     = md5( $url );
    … …  
    4055                );
    4156                $wpdb->query( $wpdb->prepare( 'DELETE FROM %i WHERE url_hash = %s AND lang = %s', Schema::table( 'segment_urls' ), $hash, $lang ) );
    42                 $position = 0;
    43                 foreach ( array_chunk( array_values( array_unique( $keys ) ), 200 ) as $chunk ) {
     57                foreach ( array_chunk( $positions, 200, true ) as $chunk ) {
    4458                        $values = array();
    4559                        $args   = array( Schema::table( 'segment_urls' ) );
    46                         foreach ( $chunk as $key ) {
     60                        foreach ( $chunk as $key => $position ) {
    4761                                $values[] = '(%s, %s, %s, %s, %d, %s)';
    48                                 array_push( $args, $key, $hash, $lang, $url, $position++, $now );
     62                                array_push( $args, $key, $hash, $lang, $url, $position, $now );
    4963                        }
    5064                        $wpdb->query( // phpcs:ignore PluginCheck.Security.DirectDB.UnescapedDBParameter -- only placeholder groups are concatenated; every value goes through prepare().
    … …  
    7589                $hash = md5( $url );
    7690                $now  = current_time( 'mysql', true );
    77                 foreach ( array_chunk( array_keys( $sources ), 200 ) as $chunk ) {
     91                foreach ( array_chunk( array_keys( self::ordered( $sources ) ), 200 ) as $chunk ) {
    7892                        $values = array();
    7993                        $args   = array( Schema::table( 'segment_urls' ) );
    … …  
    532546                global $wpdb;
    533547                $now = current_time( 'mysql', true );
    534                 foreach ( array_chunk( $sources, 100, true ) as $chunk ) {
     548                foreach ( array_chunk( self::ordered( $sources ), 100, true ) as $chunk ) {
    535549                        $values = array();
    536550                        $args   = array( Schema::table( 'segments' ) );
  • translate-by-wp-provider/trunk/src/Store/Slugs.php

    r3818523 r3837767  
    134134        public static function store_base( string $lang, string $kind, int $id, string $slug, string $source_path, string $path ): ?string {
    135135                $kept = self::kept_path( $lang, $kind, $id );
    136                 if ( null !== $kept || self::path_taken( $lang, $path, 0 ) ) {
     136                if ( null !== $kept || null !== \WPPTranslate\Dormant::move() || self::path_taken( $lang, $path, 0 ) ) {
    137137                        return $kept;
    138138                }
    … …  
    337337         */
    338338        private static function claim( string $lang, string $type, int $id, string $slug, string $source_path, string $wanted, bool $replace ): ?string {
     339                if ( null !== \WPPTranslate\Dormant::move() ) {
     340                        return null; // The plugin a site may go back to does not know our addresses.
     341                }
    339342                global $wpdb;
    340343                $lock   = 'wppt_slugs_' . md5( Schema::table( 'slugs' ) . '|' . $lang );
  • translate-by-wp-provider/trunk/src/StoredText.php

    r3818452 r3837767  
    5555                        return;
    5656                }
    57                 $url = self::url( $group );
     57                $url     = self::url( $group );
     58                $by_hand = PlanLanguages::by_hand();
    5859                foreach ( Settings::targets() as $lang ) {
    5960                        SegmentUrls::add( $sources, $url, $lang );
     61                        if ( in_array( $lang, $by_hand, true ) ) {
     62                                // Recorded, to be translated by hand; never sent.
     63                                continue;
     64                        }
    6065                        $missing = array_diff_key( $sources, Translations::lookup( $lang, array_keys( $sources ) ) );
    6166                        $items   = array();
  • translate-by-wp-provider/trunk/src/Sync.php

    r3814274 r3837767  
    311311         */
    312312        private static function submit( Client $client, string $lang, string $source, array $rows, array $segments, ?string $page, array &$stats ): ?string {
     313                if ( Dormant::holds() ) {
     314                        return 'stop';
     315                }
    313316                $response = $client->submit( $source, array( $lang ), $segments, $page );
    314317                if ( is_wp_error( $response ) && 'wppt_payment' === $response->get_error_code() ) {
  • translate-by-wp-provider/trunk/translate-by-wp-provider.php

    r3836113 r3837767  
    44 * Plugin URI:        https://wpptranslate.com/
    55 * Description:       Translate what visitors read into other languages. Translations are stored in your own database; page views never call an external service.
    6  * Version:           0.1.32
     6 * Version:           0.1.33
    77 * Requires at least: 6.5
    88 * Requires PHP:      7.4
    … …  
    2929
    3030define( 'WPPT_FILE', __FILE__ );
    31 define( 'WPPT_VERSION', '0.1.32' );
     31define( 'WPPT_VERSION', '0.1.33' );
    3232
    3333/**
  • translate-by-wp-provider/trunk/vendor/composer/autoload_classmap.php

    r3836113 r3837767  
    7070    'WPPTranslate\\Html\\VisitorValues' => $baseDir . '/src/Html/VisitorValues.php',
    7171    'WPPTranslate\\Import\\Aligner' => $baseDir . '/src/Import/Aligner.php',
     72    'WPPTranslate\\Import\\Move' => $baseDir . '/src/Import/Move.php',
     73    'WPPTranslate\\Import\\MoveScreen' => $baseDir . '/src/Import/MoveScreen.php',
     74    'WPPTranslate\\Import\\PageMove' => $baseDir . '/src/Import/PageMove.php',
    7275    'WPPTranslate\\Import\\PairBook' => $baseDir . '/src/Import/PairBook.php',
    7376    'WPPTranslate\\Import\\Progress' => $baseDir . '/src/Import/Progress.php',
  • translate-by-wp-provider/trunk/vendor/composer/autoload_static.php

    r3836113 r3837767  
    8585        'WPPTranslate\\Html\\VisitorValues' => __DIR__ . '/../..' . '/src/Html/VisitorValues.php',
    8686        'WPPTranslate\\Import\\Aligner' => __DIR__ . '/../..' . '/src/Import/Aligner.php',
     87        'WPPTranslate\\Import\\Move' => __DIR__ . '/../..' . '/src/Import/Move.php',
     88        'WPPTranslate\\Import\\MoveScreen' => __DIR__ . '/../..' . '/src/Import/MoveScreen.php',
     89        'WPPTranslate\\Import\\PageMove' => __DIR__ . '/../..' . '/src/Import/PageMove.php',
    8790        'WPPTranslate\\Import\\PairBook' => __DIR__ . '/../..' . '/src/Import/PairBook.php',
    8891        'WPPTranslate\\Import\\Progress' => __DIR__ . '/../..' . '/src/Import/Progress.php',
  • translate-by-wp-provider/trunk/vendor/composer/installed.php

    r3836113 r3837767  
    22    'root' => array(
    33        'name' => 'wp-provider/translate-by-wp-provider',
    4         'pretty_version' => 'v0.1.32',
    5         'version' => '0.1.32.0',
    6         'reference' => '0f1e6b6144c11679adb2f95a236105a58bca9377',
     4        'pretty_version' => 'v0.1.33',
     5        'version' => '0.1.33.0',
     6        'reference' => '77f3a39bc23d04cde67366e80a6931e842edc44d',
    77        'type' => 'wordpress-plugin',
    88        'install_path' => __DIR__ . '/../../',
    … …  
    1212    'versions' => array(
    1313        'wp-provider/translate-by-wp-provider' => array(
    14             'pretty_version' => 'v0.1.32',
    15             'version' => '0.1.32.0',
    16             'reference' => '0f1e6b6144c11679adb2f95a236105a58bca9377',
     14            'pretty_version' => 'v0.1.33',
     15            'version' => '0.1.33.0',
     16            'reference' => '77f3a39bc23d04cde67366e80a6931e842edc44d',
    1717            'type' => 'wordpress-plugin',
    1818            'install_path' => __DIR__ . '/../../',
Note: See TracChangeset for help on using the changeset viewer.