get_wp_api(); $pre_gen_dissmissed = self::isDismissed(); $st_page = $wp_api->is_core_page( 'theme-localization.php' ) || $wp_api->is_string_translation_page(); if ( ( $st_page || ( ! $st_page && ! $pre_gen_dissmissed ) ) && ( DomainsAndLanguagesRepository::hasTranslationFilesTable() || is_network_admin() ) ) { $files_to_import = $st_page ? $this->getFilesToImport() : wpml_collect( [] ); $domains_to_pre_generate_count = self::getDomainsToPreGenerateCount(); if ( $files_to_import->count() || $domains_to_pre_generate_count || isset( $_GET['search'] ) ) { return partial( [ UI::class, 'add_hooks' ], Model::provider( $files_to_import, $domains_to_pre_generate_count, $st_page, is_network_admin() ), $st_page ); } } } return null; } public function get_load_action() { return 'init'; } /** * @return bool * @throws \WPML\Auryn\InjectionException */ public static function isDismissed() { return make( OptionManager::class )->get( self::OPTION_GROUP, 'pregen-dismissed', false ); } /** * @return Collection * @throws \WPML\Auryn\InjectionException */ private function getFilesToImport() { /** @var WPML_ST_Translations_File_Dictionary $file_dictionary */ $file_dictionary = make( WPML_ST_Translations_File_Dictionary::class, [ 'storage' => WPML_ST_Translations_File_Dictionary_Storage_Table::class ] ); $file_dictionary->clear_skipped(); return InstalledComponents::filter( wpml_collect( $file_dictionary->get_not_imported_files() ) ); } /** * @return bool */ private static function isPreGenerationRequired() { return self::shouldIgnoreWpmlVersion() || self::wpmlStartVersionBeforeMOFlow(); } /** * @return bool */ private static function wpmlStartVersionBeforeMOFlow() { return version_compare( get_option( \WPML_Installation::WPML_START_VERSION_KEY, '0.0.0' ), self::WPML_VERSION_INTRODUCING_ST_MO_FLOW, '<' ); } /** * @return int * @throws \WPML\Auryn\InjectionException */ public static function getDomainsToPreGenerateCount() { return self::isPreGenerationRequired() ? make( ProcessFactory::class )->create()->getPagesCount() : 0; } /** * @return bool */ public static function shouldIgnoreWpmlVersion() { return make( OptionManager::class )->get( self::OPTION_GROUP, self::IGNORE_WPML_VERSION, false ); } public static function ignoreWpmlVersion() { make( OptionManager::class )->set( self::OPTION_GROUP, self::IGNORE_WPML_VERSION, true ); } public static function clearIgnoreWpmlVersion() { make( OptionManager::class )->set( self::OPTION_GROUP, self::IGNORE_WPML_VERSION, false ); } }