Changeset 3837767
- Timestamp:
- 12/01/2026 01:34:44 PM (less than one hour ago)
- Location:
- translate-by-wp-provider
- Files:
-
- 8 added
- 54 edited
- 1 copied
-
tags/0.1.33 (copied) (copied from translate-by-wp-provider/trunk )
-
tags/0.1.33/assets/move.js (added)
-
tags/0.1.33/readme.txt (modified) (2 diffs)
-
tags/0.1.33/src/Admin.php (modified) (1 diff)
-
tags/0.1.33/src/Cli.php (modified) (1 diff)
-
tags/0.1.33/src/Compat/Multilingual.php (modified) (2 diffs)
-
tags/0.1.33/src/Compat/TranslatePress.php (modified) (1 diff)
-
tags/0.1.33/src/Compat/WooCommerceEmails.php (modified) (2 diffs)
-
tags/0.1.33/src/Connect.php (modified) (3 diffs)
-
tags/0.1.33/src/Crawl.php (modified) (1 diff)
-
tags/0.1.33/src/Dormant.php (modified) (10 diffs)
-
tags/0.1.33/src/FirstLanguages.php (modified) (5 diffs)
-
tags/0.1.33/src/Import/Move.php (added)
-
tags/0.1.33/src/Import/MoveScreen.php (added)
-
tags/0.1.33/src/Import/PageMove.php (added)
-
tags/0.1.33/src/Import/Progress.php (modified) (1 diff)
-
tags/0.1.33/src/Import/RenderedImport.php (modified) (4 diffs)
-
tags/0.1.33/src/Import/TranslatePress.php (modified) (2 diffs)
-
tags/0.1.33/src/PageCaches.php (modified) (1 diff)
-
tags/0.1.33/src/PlanLanguages.php (modified) (1 diff)
-
tags/0.1.33/src/Plugin.php (modified) (1 diff)
-
tags/0.1.33/src/Store/Addresses.php (modified) (3 diffs)
-
tags/0.1.33/src/Store/PageState.php (modified) (5 diffs)
-
tags/0.1.33/src/Store/Queue.php (modified) (1 diff)
-
tags/0.1.33/src/Store/SegmentUrls.php (modified) (5 diffs)
-
tags/0.1.33/src/Store/Slugs.php (modified) (2 diffs)
-
tags/0.1.33/src/StoredText.php (modified) (1 diff)
-
tags/0.1.33/src/Sync.php (modified) (1 diff)
-
tags/0.1.33/translate-by-wp-provider.php (modified) (2 diffs)
-
tags/0.1.33/vendor/composer/autoload_classmap.php (modified) (1 diff)
-
tags/0.1.33/vendor/composer/autoload_static.php (modified) (1 diff)
-
tags/0.1.33/vendor/composer/installed.php (modified) (2 diffs)
-
trunk/assets/move.js (added)
-
trunk/readme.txt (modified) (2 diffs)
-
trunk/src/Admin.php (modified) (1 diff)
-
trunk/src/Cli.php (modified) (1 diff)
-
trunk/src/Compat/Multilingual.php (modified) (2 diffs)
-
trunk/src/Compat/TranslatePress.php (modified) (1 diff)
-
trunk/src/Compat/WooCommerceEmails.php (modified) (2 diffs)
-
trunk/src/Connect.php (modified) (3 diffs)
-
trunk/src/Crawl.php (modified) (1 diff)
-
trunk/src/Dormant.php (modified) (10 diffs)
-
trunk/src/FirstLanguages.php (modified) (5 diffs)
-
trunk/src/Import/Move.php (added)
-
trunk/src/Import/MoveScreen.php (added)
-
trunk/src/Import/PageMove.php (added)
-
trunk/src/Import/Progress.php (modified) (1 diff)
-
trunk/src/Import/RenderedImport.php (modified) (4 diffs)
-
trunk/src/Import/TranslatePress.php (modified) (2 diffs)
-
trunk/src/PageCaches.php (modified) (1 diff)
-
trunk/src/PlanLanguages.php (modified) (1 diff)
-
trunk/src/Plugin.php (modified) (1 diff)
-
trunk/src/Store/Addresses.php (modified) (3 diffs)
-
trunk/src/Store/PageState.php (modified) (5 diffs)
-
trunk/src/Store/Queue.php (modified) (1 diff)
-
trunk/src/Store/SegmentUrls.php (modified) (5 diffs)
-
trunk/src/Store/Slugs.php (modified) (2 diffs)
-
trunk/src/StoredText.php (modified) (1 diff)
-
trunk/src/Sync.php (modified) (1 diff)
-
trunk/translate-by-wp-provider.php (modified) (2 diffs)
-
trunk/vendor/composer/autoload_classmap.php (modified) (1 diff)
-
trunk/vendor/composer/autoload_static.php (modified) (1 diff)
-
trunk/vendor/composer/installed.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
translate-by-wp-provider/tags/0.1.33/readme.txt
r3836113 r3837767 5 5 Tested up to: 7.2 6 6 Requires PHP: 7.4 7 Stable tag: 0.1.3 27 Stable tag: 0.1.33 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 60 60 = I use WPML or TranslatePress. Can I switch? = 61 61 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.62 Yes. 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. 63 63 64 64 = Can a product feed or a search index use my translations? = -
translate-by-wp-provider/tags/0.1.33/src/Admin.php
r3836113 r3837767 155 155 <?php 156 156 $step = Onboarding::step(); 157 $card = Import\MoveScreen::render( 'connect' === $step && Connect::waiting() ); 157 158 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 ) { 160 163 $settings['source_lang'] = FirstLanguages::chosen()['source'] ?? $settings['source_lang']; 161 164 Onboarding::render_start( fn ( array $langs ) => self::render_targets( $settings, $langs ) ); -
translate-by-wp-provider/tags/0.1.33/src/Cli.php
r3836067 r3837767 545 545 update_option( Settings::OPTION, $saved ); 546 546 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() ) ); 571 548 foreach ( Import\TranslatePress::content_usage() as $what => $count ) { 572 549 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 10 10 defined( 'ABSPATH' ) || exit; 11 11 12 use WPPTranslate\Import\MoveScreen; 12 13 use WPPTranslate\Settings; 13 14 … … 127 128 */ 128 129 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(); 130 132 if ( ! $active ) { 131 133 return; -
translate-by-wp-provider/tags/0.1.33/src/Compat/TranslatePress.php
r3814274 r3837767 10 10 defined( 'ABSPATH' ) || exit; 11 11 12 use WPPTranslate\Dormant; 12 13 use WPPTranslate\Import\TranslatePress as Source; 13 14 use WPPTranslate\LanguageContent; 15 use WPPTranslate\Menu; 14 16 use WPPTranslate\Picker; 15 17 16 18 /** 17 19 * Once TranslatePress is off, its shortcodes and block in the site's 18 * content a re handled here, so no page shows `[language-switcher]` and no19 * content meant for one language shows in all of them. The content itself20 * isnot 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. 21 23 */ 22 24 final class TranslatePress { 23 25 24 26 /** 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. 26 29 */ 27 30 public static function register(): void { 28 if ( Source::active() || ! Source::available() ) {31 if ( ( Source::active() && ! Dormant::alone() ) || ! Source::available() ) { 29 32 return; 30 33 } 31 34 add_action( 'init', array( self::class, 'shortcodes' ), 20 ); 32 35 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 ) ); 33 64 } 34 65 -
translate-by-wp-provider/tags/0.1.33/src/Compat/WooCommerceEmails.php
r3814274 r3837767 12 12 use WPPTranslate\Html\Segmenter; 13 13 use WPPTranslate\Languages; 14 use WPPTranslate\PlanLanguages; 14 15 use WPPTranslate\Settings; 15 16 use WPPTranslate\StoredText; … … 238 239 $url = StoredText::url( self::GROUP ); 239 240 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 } 240 245 $missing = array_diff_key( $texts, Translations::lookup( $lang, array_keys( $texts ) ) ); 241 246 $items = array(); -
translate-by-wp-provider/tags/0.1.33/src/Connect.php
r3836113 r3837767 48 48 public static function start(): void { 49 49 self::guard( 'wppt_connect' ); 50 FirstLanguages::drop(); 50 51 self::login(); 51 52 } … … 189 190 public static function auto(): void { 190 191 self::guard( 'wppt_auto_connect' ); 192 FirstLanguages::drop(); 191 193 self::connect(); 192 194 } … … 286 288 */ 287 289 private static function connected( string $account ): string { 288 return Settings::targets() 290 return Settings::targets() || Import\MoveScreen::replaces_choice() 289 291 /* translators: %s: account name. */ 290 292 ? sprintf( __( 'Connected to %s.', 'translate-by-wp-provider' ), $account ) -
translate-by-wp-provider/tags/0.1.33/src/Crawl.php
r3814274 r3837767 49 49 */ 50 50 public static function start(): void { 51 if ( ! Settings::targets() ) {51 if ( ! Settings::targets() || Dormant::holds() ) { 52 52 return; 53 53 } -
translate-by-wp-provider/tags/0.1.33/src/Dormant.php
r3814274 r3837767 30 30 * argument so that no page cache in front of the site answers them 31 31 * 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. 32 36 */ 33 37 final class Dormant { … … 50 54 private static ?string $kind = null; 51 55 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 52 60 /** 53 61 * Whether the plugin is dormant on this site. 54 62 */ 55 63 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' => '' ) ); 57 111 } 58 112 … … 60 114 * What a request gets while dormant. 61 115 * 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. 63 117 * @return string One of HIDDEN, BACKGROUND, FULL. 64 118 */ 65 119 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 } 66 124 if ( ! empty( $request['own_render'] ) ) { 67 125 return self::FULL; … … 140 198 */ 141 199 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 } 142 210 // phpcs:disable WordPress.Security.NonceVerification.Recommended -- only which request this is, nothing is changed. 143 211 $action = isset( $_REQUEST['action'] ) ? sanitize_key( wp_unslash( $_REQUEST['action'] ) ) : ''; 144 212 $preview = ! empty( $_GET[ self::PREVIEW ] ); 213 $render = isset( $_SERVER['HTTP_X_WPPT_RENDER'] ) ? sanitize_key( wp_unslash( $_SERVER['HTTP_X_WPPT_RENDER'] ) ) : ''; 145 214 self::$kind = self::kind_of( 146 215 array( … … 152 221 'uri' => Router::request_uri(), 153 222 'own_render' => RenderPass::is_own_render(), 223 'import' => 'import' === $render, 154 224 'preview' => $preview, 155 225 // Asked only for a preview: a visitor's request does not load the user early. … … 159 229 // phpcs:enable 160 230 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 } 161 237 return; 162 238 } … … 165 241 self::keep_out_of_caches(); 166 242 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 } 167 247 } 168 248 Plugin::hooks(); … … 209 289 add_filter( 'weglot_active_translation_before_treat_page', '__return_false', PHP_INT_MAX ); 210 290 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; 211 320 } 212 321 … … 215 324 */ 216 325 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' ) ) { 218 331 return; 219 332 } 220 333 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 } 221 338 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' ); 222 339 echo '</p></div>'; … … 227 344 */ 228 345 public static function reset(): void { 229 self::$kind = null; 346 self::$kind = null; 347 self::$shown = false; 348 self::$previews = false; 230 349 } 231 350 } -
translate-by-wp-provider/tags/0.1.33/src/FirstLanguages.php
r3836113 r3837767 40 40 /** 41 41 * 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. 43 44 * 44 45 * @param string $source Site language. … … 46 47 */ 47 48 public static function suggested( string $source ): array { 48 return 'en' === $source ? array() : array( 'en' );49 return 'en' === $source || Multilingual::active() ? array() : array( 'en' ); 49 50 } 50 51 … … 62 63 return false; 63 64 } 65 if ( null !== Dormant::move() ) { 66 return true; 67 } 64 68 update_option( 65 69 self::OPTION, 66 70 array( 71 'instead' => null !== Import\Move::offer(), 67 72 'source' => $source, 68 73 'targets' => $langs, … … 72 77 ); 73 78 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 } 74 89 } 75 90 … … 93 108 */ 94 109 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 } 95 114 $chosen = self::chosen(); 96 115 if ( null === $chosen || Settings::targets() ) { -
translate-by-wp-provider/tags/0.1.33/src/Import/Progress.php
r3814274 r3837767 68 68 public static function busy( int $now ): bool { 69 69 $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 ) ) { 71 71 return true; 72 72 } -
translate-by-wp-provider/tags/0.1.33/src/Import/RenderedImport.php
r3814274 r3837767 105 105 } 106 106 $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 ) { 120 109 // The same text on both sides was not translated: nothing to import. 121 110 if ( Segment::normalize( $pair[0] ) !== Segment::normalize( $pair[1] ) ) { … … 167 156 } 168 157 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] ) ); 169 165 } 170 166 … … 344 340 * @param string $lang Language code. 345 341 */ 346 p rivatestatic function prefixed( string $url, string $lang ): string {342 public static function prefixed( string $url, string $lang ): string { 347 343 $home = untrailingslashit( home_url() ); 348 344 return $home . '/' . $lang . substr( $url, strlen( $home ) ); … … 365 361 * @return string[] 366 362 */ 367 p rivatestatic function segments( string $html ): array {363 public static function segments( string $html ): array { 368 364 return array_map( fn ( Segment $s ) => $s->source, Segmenter::parse( $html )->segments ); 369 365 } -
translate-by-wp-provider/tags/0.1.33/src/Import/TranslatePress.php
r3814274 r3837767 9 9 10 10 defined( 'ABSPATH' ) || exit; 11 12 use WPPTranslate\Menu; 11 13 12 14 /** … … 77 79 } 78 80 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 79 105 /** 80 106 * Posts whose content uses its shortcodes or block. -
translate-by-wp-provider/tags/0.1.33/src/PageCaches.php
r3814274 r3837767 103 103 } 104 104 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 105 120 /** 106 121 * LiteSpeed Cache: drop each address through its hook. For every address -
translate-by-wp-provider/tags/0.1.33/src/PlanLanguages.php
r3814274 r3837767 44 44 return array_values( 45 45 array_filter( 46 LanguageChoice::automatic( Settings::targets(), self::by_hand() ),46 Dormant::holds() ? array() : LanguageChoice::automatic( Settings::targets(), self::by_hand() ), 47 47 static fn ( string $lang ): bool => ! get_transient( self::REFUSED . $lang ) 48 48 ) -
translate-by-wp-provider/tags/0.1.33/src/Plugin.php
r3836113 r3837767 167 167 PagesScreen::register(); 168 168 Report::register(); 169 Import\Move::register(); 169 170 Compat\TranslatePress::register(); 170 171 Compat\Weglot::register(); -
translate-by-wp-provider/tags/0.1.33/src/Store/Addresses.php
r3814274 r3837767 32 32 * @param string $type post | term. 33 33 * @param int $id Object id of the page now. 34 * @param string $at Marks the rows of an import. 34 35 */ 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 { 36 37 global $wpdb; 37 38 $path = self::path( $url ); 38 39 if ( '/' === $path || $id <= 0 ) { 39 return ;40 return true; 40 41 } 41 42 $table = Schema::table( 'addresses' ); … … 44 45 ); 45 46 if ( null !== $known ) { 46 return ;47 return true; 47 48 } 48 $wpdb->insert(49 return false !== $wpdb->insert( 49 50 $table, 50 51 array( … … 53 54 'object_type' => $type, 54 55 'object_id' => $id, 55 'created_at' => current_time( 'mysql', true ),56 'created_at' => '' === $at ? current_time( 'mysql', true ) : $at, 56 57 ) 57 58 ); -
translate-by-wp-provider/tags/0.1.33/src/Store/PageState.php
r3836113 r3837767 299 299 * @param string $url Source URL. 300 300 * @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; 305 307 if ( Schema::is_current() ) { 306 $ wpdb->query(308 $done = $wpdb->query( 307 309 $wpdb->prepare( 308 310 '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) … … 313 315 $url, 314 316 self::post_id( $url ), 315 $ now,317 $seen, 316 318 $now, 317 319 md5( $url ) … … 319 321 ); 320 322 } else { 321 $ wpdb->query(323 $done = $wpdb->query( 322 324 $wpdb->prepare( 323 325 'INSERT INTO %i (page_key, lang, url, post_id, live, missing, first_seen, updated_at) VALUES (%s, %s, %s, %d, 1, 0, %s, %s) … … 328 330 $url, 329 331 self::post_id( $url ), 330 $ now,332 $seen, 331 333 $now 332 334 ) … … 334 336 } 335 337 self::$live = null; 338 return false !== $done; 336 339 } 337 340 -
translate-by-wp-provider/tags/0.1.33/src/Store/Queue.php
r3814274 r3837767 88 88 // 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). 89 89 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 ) { 91 91 $values = array(); 92 92 $args = array( Schema::table( 'queue' ) ); -
translate-by-wp-provider/tags/0.1.33/src/Store/SegmentUrls.php
r3836113 r3837767 22 22 23 23 /** 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 /** 24 38 * Replace the record for a URL with what its latest render contains, so 25 39 * text edited away stops counting as needed. … … 31 45 */ 32 46 public static function record( array $sources, string $url, string $lang ): array { 33 $keys = array_keys( $sources );34 47 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 ) ) ); 35 50 global $wpdb; 36 51 $hash = md5( $url ); … … 40 55 ); 41 56 $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 ) { 44 58 $values = array(); 45 59 $args = array( Schema::table( 'segment_urls' ) ); 46 foreach ( $chunk as $key ) {60 foreach ( $chunk as $key => $position ) { 47 61 $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 ); 49 63 } 50 64 $wpdb->query( // phpcs:ignore PluginCheck.Security.DirectDB.UnescapedDBParameter -- only placeholder groups are concatenated; every value goes through prepare(). … … 75 89 $hash = md5( $url ); 76 90 $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 ) { 78 92 $values = array(); 79 93 $args = array( Schema::table( 'segment_urls' ) ); … … 532 546 global $wpdb; 533 547 $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 ) { 535 549 $values = array(); 536 550 $args = array( Schema::table( 'segments' ) ); -
translate-by-wp-provider/tags/0.1.33/src/Store/Slugs.php
r3818523 r3837767 134 134 public static function store_base( string $lang, string $kind, int $id, string $slug, string $source_path, string $path ): ?string { 135 135 $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 ) ) { 137 137 return $kept; 138 138 } … … 337 337 */ 338 338 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 } 339 342 global $wpdb; 340 343 $lock = 'wppt_slugs_' . md5( Schema::table( 'slugs' ) . '|' . $lang ); -
translate-by-wp-provider/tags/0.1.33/src/StoredText.php
r3818452 r3837767 55 55 return; 56 56 } 57 $url = self::url( $group ); 57 $url = self::url( $group ); 58 $by_hand = PlanLanguages::by_hand(); 58 59 foreach ( Settings::targets() as $lang ) { 59 60 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 } 60 65 $missing = array_diff_key( $sources, Translations::lookup( $lang, array_keys( $sources ) ) ); 61 66 $items = array(); -
translate-by-wp-provider/tags/0.1.33/src/Sync.php
r3814274 r3837767 311 311 */ 312 312 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 } 313 316 $response = $client->submit( $source, array( $lang ), $segments, $page ); 314 317 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 4 4 * Plugin URI: https://wpptranslate.com/ 5 5 * 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.3 26 * Version: 0.1.33 7 7 * Requires at least: 6.5 8 8 * Requires PHP: 7.4 … … 29 29 30 30 define( 'WPPT_FILE', __FILE__ ); 31 define( 'WPPT_VERSION', '0.1.3 2' );31 define( 'WPPT_VERSION', '0.1.33' ); 32 32 33 33 /** -
translate-by-wp-provider/tags/0.1.33/vendor/composer/autoload_classmap.php
r3836113 r3837767 70 70 'WPPTranslate\\Html\\VisitorValues' => $baseDir . '/src/Html/VisitorValues.php', 71 71 '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', 72 75 'WPPTranslate\\Import\\PairBook' => $baseDir . '/src/Import/PairBook.php', 73 76 'WPPTranslate\\Import\\Progress' => $baseDir . '/src/Import/Progress.php', -
translate-by-wp-provider/tags/0.1.33/vendor/composer/autoload_static.php
r3836113 r3837767 85 85 'WPPTranslate\\Html\\VisitorValues' => __DIR__ . '/../..' . '/src/Html/VisitorValues.php', 86 86 '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', 87 90 'WPPTranslate\\Import\\PairBook' => __DIR__ . '/../..' . '/src/Import/PairBook.php', 88 91 'WPPTranslate\\Import\\Progress' => __DIR__ . '/../..' . '/src/Import/Progress.php', -
translate-by-wp-provider/tags/0.1.33/vendor/composer/installed.php
r3836113 r3837767 2 2 'root' => array( 3 3 'name' => 'wp-provider/translate-by-wp-provider', 4 'pretty_version' => 'v0.1.3 2',5 'version' => '0.1.3 2.0',6 'reference' => ' 0f1e6b6144c11679adb2f95a236105a58bca9377',4 'pretty_version' => 'v0.1.33', 5 'version' => '0.1.33.0', 6 'reference' => '77f3a39bc23d04cde67366e80a6931e842edc44d', 7 7 'type' => 'wordpress-plugin', 8 8 'install_path' => __DIR__ . '/../../', … … 12 12 'versions' => array( 13 13 'wp-provider/translate-by-wp-provider' => array( 14 'pretty_version' => 'v0.1.3 2',15 'version' => '0.1.3 2.0',16 'reference' => ' 0f1e6b6144c11679adb2f95a236105a58bca9377',14 'pretty_version' => 'v0.1.33', 15 'version' => '0.1.33.0', 16 'reference' => '77f3a39bc23d04cde67366e80a6931e842edc44d', 17 17 'type' => 'wordpress-plugin', 18 18 'install_path' => __DIR__ . '/../../', -
translate-by-wp-provider/trunk/readme.txt
r3836113 r3837767 5 5 Tested up to: 7.2 6 6 Requires PHP: 7.4 7 Stable tag: 0.1.3 27 Stable tag: 0.1.33 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 60 60 = I use WPML or TranslatePress. Can I switch? = 61 61 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.62 Yes. 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. 63 63 64 64 = Can a product feed or a search index use my translations? = -
translate-by-wp-provider/trunk/src/Admin.php
r3836113 r3837767 155 155 <?php 156 156 $step = Onboarding::step(); 157 $card = Import\MoveScreen::render( 'connect' === $step && Connect::waiting() ); 157 158 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 ) { 160 163 $settings['source_lang'] = FirstLanguages::chosen()['source'] ?? $settings['source_lang']; 161 164 Onboarding::render_start( fn ( array $langs ) => self::render_targets( $settings, $langs ) ); -
translate-by-wp-provider/trunk/src/Cli.php
r3836067 r3837767 545 545 update_option( Settings::OPTION, $saved ); 546 546 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() ) ); 571 548 foreach ( Import\TranslatePress::content_usage() as $what => $count ) { 572 549 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 10 10 defined( 'ABSPATH' ) || exit; 11 11 12 use WPPTranslate\Import\MoveScreen; 12 13 use WPPTranslate\Settings; 13 14 … … 127 128 */ 128 129 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(); 130 132 if ( ! $active ) { 131 133 return; -
translate-by-wp-provider/trunk/src/Compat/TranslatePress.php
r3814274 r3837767 10 10 defined( 'ABSPATH' ) || exit; 11 11 12 use WPPTranslate\Dormant; 12 13 use WPPTranslate\Import\TranslatePress as Source; 13 14 use WPPTranslate\LanguageContent; 15 use WPPTranslate\Menu; 14 16 use WPPTranslate\Picker; 15 17 16 18 /** 17 19 * Once TranslatePress is off, its shortcodes and block in the site's 18 * content a re handled here, so no page shows `[language-switcher]` and no19 * content meant for one language shows in all of them. The content itself20 * isnot 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. 21 23 */ 22 24 final class TranslatePress { 23 25 24 26 /** 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. 26 29 */ 27 30 public static function register(): void { 28 if ( Source::active() || ! Source::available() ) {31 if ( ( Source::active() && ! Dormant::alone() ) || ! Source::available() ) { 29 32 return; 30 33 } 31 34 add_action( 'init', array( self::class, 'shortcodes' ), 20 ); 32 35 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 ) ); 33 64 } 34 65 -
translate-by-wp-provider/trunk/src/Compat/WooCommerceEmails.php
r3814274 r3837767 12 12 use WPPTranslate\Html\Segmenter; 13 13 use WPPTranslate\Languages; 14 use WPPTranslate\PlanLanguages; 14 15 use WPPTranslate\Settings; 15 16 use WPPTranslate\StoredText; … … 238 239 $url = StoredText::url( self::GROUP ); 239 240 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 } 240 245 $missing = array_diff_key( $texts, Translations::lookup( $lang, array_keys( $texts ) ) ); 241 246 $items = array(); -
translate-by-wp-provider/trunk/src/Connect.php
r3836113 r3837767 48 48 public static function start(): void { 49 49 self::guard( 'wppt_connect' ); 50 FirstLanguages::drop(); 50 51 self::login(); 51 52 } … … 189 190 public static function auto(): void { 190 191 self::guard( 'wppt_auto_connect' ); 192 FirstLanguages::drop(); 191 193 self::connect(); 192 194 } … … 286 288 */ 287 289 private static function connected( string $account ): string { 288 return Settings::targets() 290 return Settings::targets() || Import\MoveScreen::replaces_choice() 289 291 /* translators: %s: account name. */ 290 292 ? sprintf( __( 'Connected to %s.', 'translate-by-wp-provider' ), $account ) -
translate-by-wp-provider/trunk/src/Crawl.php
r3814274 r3837767 49 49 */ 50 50 public static function start(): void { 51 if ( ! Settings::targets() ) {51 if ( ! Settings::targets() || Dormant::holds() ) { 52 52 return; 53 53 } -
translate-by-wp-provider/trunk/src/Dormant.php
r3814274 r3837767 30 30 * argument so that no page cache in front of the site answers them 31 31 * 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. 32 36 */ 33 37 final class Dormant { … … 50 54 private static ?string $kind = null; 51 55 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 52 60 /** 53 61 * Whether the plugin is dormant on this site. 54 62 */ 55 63 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' => '' ) ); 57 111 } 58 112 … … 60 114 * What a request gets while dormant. 61 115 * 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. 63 117 * @return string One of HIDDEN, BACKGROUND, FULL. 64 118 */ 65 119 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 } 66 124 if ( ! empty( $request['own_render'] ) ) { 67 125 return self::FULL; … … 140 198 */ 141 199 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 } 142 210 // phpcs:disable WordPress.Security.NonceVerification.Recommended -- only which request this is, nothing is changed. 143 211 $action = isset( $_REQUEST['action'] ) ? sanitize_key( wp_unslash( $_REQUEST['action'] ) ) : ''; 144 212 $preview = ! empty( $_GET[ self::PREVIEW ] ); 213 $render = isset( $_SERVER['HTTP_X_WPPT_RENDER'] ) ? sanitize_key( wp_unslash( $_SERVER['HTTP_X_WPPT_RENDER'] ) ) : ''; 145 214 self::$kind = self::kind_of( 146 215 array( … … 152 221 'uri' => Router::request_uri(), 153 222 'own_render' => RenderPass::is_own_render(), 223 'import' => 'import' === $render, 154 224 'preview' => $preview, 155 225 // Asked only for a preview: a visitor's request does not load the user early. … … 159 229 // phpcs:enable 160 230 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 } 161 237 return; 162 238 } … … 165 241 self::keep_out_of_caches(); 166 242 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 } 167 247 } 168 248 Plugin::hooks(); … … 209 289 add_filter( 'weglot_active_translation_before_treat_page', '__return_false', PHP_INT_MAX ); 210 290 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; 211 320 } 212 321 … … 215 324 */ 216 325 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' ) ) { 218 331 return; 219 332 } 220 333 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 } 221 338 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' ); 222 339 echo '</p></div>'; … … 227 344 */ 228 345 public static function reset(): void { 229 self::$kind = null; 346 self::$kind = null; 347 self::$shown = false; 348 self::$previews = false; 230 349 } 231 350 } -
translate-by-wp-provider/trunk/src/FirstLanguages.php
r3836113 r3837767 40 40 /** 41 41 * 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. 43 44 * 44 45 * @param string $source Site language. … … 46 47 */ 47 48 public static function suggested( string $source ): array { 48 return 'en' === $source ? array() : array( 'en' );49 return 'en' === $source || Multilingual::active() ? array() : array( 'en' ); 49 50 } 50 51 … … 62 63 return false; 63 64 } 65 if ( null !== Dormant::move() ) { 66 return true; 67 } 64 68 update_option( 65 69 self::OPTION, 66 70 array( 71 'instead' => null !== Import\Move::offer(), 67 72 'source' => $source, 68 73 'targets' => $langs, … … 72 77 ); 73 78 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 } 74 89 } 75 90 … … 93 108 */ 94 109 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 } 95 114 $chosen = self::chosen(); 96 115 if ( null === $chosen || Settings::targets() ) { -
translate-by-wp-provider/trunk/src/Import/Progress.php
r3814274 r3837767 68 68 public static function busy( int $now ): bool { 69 69 $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 ) ) { 71 71 return true; 72 72 } -
translate-by-wp-provider/trunk/src/Import/RenderedImport.php
r3814274 r3837767 105 105 } 106 106 $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 ) { 120 109 // The same text on both sides was not translated: nothing to import. 121 110 if ( Segment::normalize( $pair[0] ) !== Segment::normalize( $pair[1] ) ) { … … 167 156 } 168 157 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] ) ); 169 165 } 170 166 … … 344 340 * @param string $lang Language code. 345 341 */ 346 p rivatestatic function prefixed( string $url, string $lang ): string {342 public static function prefixed( string $url, string $lang ): string { 347 343 $home = untrailingslashit( home_url() ); 348 344 return $home . '/' . $lang . substr( $url, strlen( $home ) ); … … 365 361 * @return string[] 366 362 */ 367 p rivatestatic function segments( string $html ): array {363 public static function segments( string $html ): array { 368 364 return array_map( fn ( Segment $s ) => $s->source, Segmenter::parse( $html )->segments ); 369 365 } -
translate-by-wp-provider/trunk/src/Import/TranslatePress.php
r3814274 r3837767 9 9 10 10 defined( 'ABSPATH' ) || exit; 11 12 use WPPTranslate\Menu; 11 13 12 14 /** … … 77 79 } 78 80 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 79 105 /** 80 106 * Posts whose content uses its shortcodes or block. -
translate-by-wp-provider/trunk/src/PageCaches.php
r3814274 r3837767 103 103 } 104 104 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 105 120 /** 106 121 * LiteSpeed Cache: drop each address through its hook. For every address -
translate-by-wp-provider/trunk/src/PlanLanguages.php
r3814274 r3837767 44 44 return array_values( 45 45 array_filter( 46 LanguageChoice::automatic( Settings::targets(), self::by_hand() ),46 Dormant::holds() ? array() : LanguageChoice::automatic( Settings::targets(), self::by_hand() ), 47 47 static fn ( string $lang ): bool => ! get_transient( self::REFUSED . $lang ) 48 48 ) -
translate-by-wp-provider/trunk/src/Plugin.php
r3836113 r3837767 167 167 PagesScreen::register(); 168 168 Report::register(); 169 Import\Move::register(); 169 170 Compat\TranslatePress::register(); 170 171 Compat\Weglot::register(); -
translate-by-wp-provider/trunk/src/Store/Addresses.php
r3814274 r3837767 32 32 * @param string $type post | term. 33 33 * @param int $id Object id of the page now. 34 * @param string $at Marks the rows of an import. 34 35 */ 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 { 36 37 global $wpdb; 37 38 $path = self::path( $url ); 38 39 if ( '/' === $path || $id <= 0 ) { 39 return ;40 return true; 40 41 } 41 42 $table = Schema::table( 'addresses' ); … … 44 45 ); 45 46 if ( null !== $known ) { 46 return ;47 return true; 47 48 } 48 $wpdb->insert(49 return false !== $wpdb->insert( 49 50 $table, 50 51 array( … … 53 54 'object_type' => $type, 54 55 'object_id' => $id, 55 'created_at' => current_time( 'mysql', true ),56 'created_at' => '' === $at ? current_time( 'mysql', true ) : $at, 56 57 ) 57 58 ); -
translate-by-wp-provider/trunk/src/Store/PageState.php
r3836113 r3837767 299 299 * @param string $url Source URL. 300 300 * @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; 305 307 if ( Schema::is_current() ) { 306 $ wpdb->query(308 $done = $wpdb->query( 307 309 $wpdb->prepare( 308 310 '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) … … 313 315 $url, 314 316 self::post_id( $url ), 315 $ now,317 $seen, 316 318 $now, 317 319 md5( $url ) … … 319 321 ); 320 322 } else { 321 $ wpdb->query(323 $done = $wpdb->query( 322 324 $wpdb->prepare( 323 325 'INSERT INTO %i (page_key, lang, url, post_id, live, missing, first_seen, updated_at) VALUES (%s, %s, %s, %d, 1, 0, %s, %s) … … 328 330 $url, 329 331 self::post_id( $url ), 330 $ now,332 $seen, 331 333 $now 332 334 ) … … 334 336 } 335 337 self::$live = null; 338 return false !== $done; 336 339 } 337 340 -
translate-by-wp-provider/trunk/src/Store/Queue.php
r3814274 r3837767 88 88 // 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). 89 89 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 ) { 91 91 $values = array(); 92 92 $args = array( Schema::table( 'queue' ) ); -
translate-by-wp-provider/trunk/src/Store/SegmentUrls.php
r3836113 r3837767 22 22 23 23 /** 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 /** 24 38 * Replace the record for a URL with what its latest render contains, so 25 39 * text edited away stops counting as needed. … … 31 45 */ 32 46 public static function record( array $sources, string $url, string $lang ): array { 33 $keys = array_keys( $sources );34 47 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 ) ) ); 35 50 global $wpdb; 36 51 $hash = md5( $url ); … … 40 55 ); 41 56 $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 ) { 44 58 $values = array(); 45 59 $args = array( Schema::table( 'segment_urls' ) ); 46 foreach ( $chunk as $key ) {60 foreach ( $chunk as $key => $position ) { 47 61 $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 ); 49 63 } 50 64 $wpdb->query( // phpcs:ignore PluginCheck.Security.DirectDB.UnescapedDBParameter -- only placeholder groups are concatenated; every value goes through prepare(). … … 75 89 $hash = md5( $url ); 76 90 $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 ) { 78 92 $values = array(); 79 93 $args = array( Schema::table( 'segment_urls' ) ); … … 532 546 global $wpdb; 533 547 $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 ) { 535 549 $values = array(); 536 550 $args = array( Schema::table( 'segments' ) ); -
translate-by-wp-provider/trunk/src/Store/Slugs.php
r3818523 r3837767 134 134 public static function store_base( string $lang, string $kind, int $id, string $slug, string $source_path, string $path ): ?string { 135 135 $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 ) ) { 137 137 return $kept; 138 138 } … … 337 337 */ 338 338 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 } 339 342 global $wpdb; 340 343 $lock = 'wppt_slugs_' . md5( Schema::table( 'slugs' ) . '|' . $lang ); -
translate-by-wp-provider/trunk/src/StoredText.php
r3818452 r3837767 55 55 return; 56 56 } 57 $url = self::url( $group ); 57 $url = self::url( $group ); 58 $by_hand = PlanLanguages::by_hand(); 58 59 foreach ( Settings::targets() as $lang ) { 59 60 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 } 60 65 $missing = array_diff_key( $sources, Translations::lookup( $lang, array_keys( $sources ) ) ); 61 66 $items = array(); -
translate-by-wp-provider/trunk/src/Sync.php
r3814274 r3837767 311 311 */ 312 312 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 } 313 316 $response = $client->submit( $source, array( $lang ), $segments, $page ); 314 317 if ( is_wp_error( $response ) && 'wppt_payment' === $response->get_error_code() ) { -
translate-by-wp-provider/trunk/translate-by-wp-provider.php
r3836113 r3837767 4 4 * Plugin URI: https://wpptranslate.com/ 5 5 * 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.3 26 * Version: 0.1.33 7 7 * Requires at least: 6.5 8 8 * Requires PHP: 7.4 … … 29 29 30 30 define( 'WPPT_FILE', __FILE__ ); 31 define( 'WPPT_VERSION', '0.1.3 2' );31 define( 'WPPT_VERSION', '0.1.33' ); 32 32 33 33 /** -
translate-by-wp-provider/trunk/vendor/composer/autoload_classmap.php
r3836113 r3837767 70 70 'WPPTranslate\\Html\\VisitorValues' => $baseDir . '/src/Html/VisitorValues.php', 71 71 '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', 72 75 'WPPTranslate\\Import\\PairBook' => $baseDir . '/src/Import/PairBook.php', 73 76 'WPPTranslate\\Import\\Progress' => $baseDir . '/src/Import/Progress.php', -
translate-by-wp-provider/trunk/vendor/composer/autoload_static.php
r3836113 r3837767 85 85 'WPPTranslate\\Html\\VisitorValues' => __DIR__ . '/../..' . '/src/Html/VisitorValues.php', 86 86 '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', 87 90 'WPPTranslate\\Import\\PairBook' => __DIR__ . '/../..' . '/src/Import/PairBook.php', 88 91 'WPPTranslate\\Import\\Progress' => __DIR__ . '/../..' . '/src/Import/Progress.php', -
translate-by-wp-provider/trunk/vendor/composer/installed.php
r3836113 r3837767 2 2 'root' => array( 3 3 'name' => 'wp-provider/translate-by-wp-provider', 4 'pretty_version' => 'v0.1.3 2',5 'version' => '0.1.3 2.0',6 'reference' => ' 0f1e6b6144c11679adb2f95a236105a58bca9377',4 'pretty_version' => 'v0.1.33', 5 'version' => '0.1.33.0', 6 'reference' => '77f3a39bc23d04cde67366e80a6931e842edc44d', 7 7 'type' => 'wordpress-plugin', 8 8 'install_path' => __DIR__ . '/../../', … … 12 12 'versions' => array( 13 13 'wp-provider/translate-by-wp-provider' => array( 14 'pretty_version' => 'v0.1.3 2',15 'version' => '0.1.3 2.0',16 'reference' => ' 0f1e6b6144c11679adb2f95a236105a58bca9377',14 'pretty_version' => 'v0.1.33', 15 'version' => '0.1.33.0', 16 'reference' => '77f3a39bc23d04cde67366e80a6931e842edc44d', 17 17 'type' => 'wordpress-plugin', 18 18 'install_path' => __DIR__ . '/../../',
Note:
See TracChangeset
for help on using the changeset viewer.