woocommerce-multilingual
/
inc
/
template-classes
/
status
/
class-wcml-status-config-warnings-ui.php
class-wcml-status-config-warnings-ui.php
4 weeks ago
class-wcml-status-media-ui.php
4 weeks ago
class-wcml-status-multi-currencies-ui.php
4 weeks ago
class-wcml-status-products-ui.php
4 weeks ago
class-wcml-status-status-ui.php
4 weeks ago
class-wcml-status-store-pages-ui.php
4 weeks ago
class-wcml-status-taxonomies-ui.php
4 weeks ago
class-wcml-status-ui.php
4 weeks ago
class-wcml-status-config-warnings-ui.php
106 lines
| 1 | <?php |
| 2 | |
| 3 | use WPML\Core\Twig_SimpleFunction; |
| 4 | |
| 5 | class WCML_Status_Config_Warnings_UI extends WCML_Templates_Factory { |
| 6 | |
| 7 | private $woocommerce_wpml; |
| 8 | private $sitepress; |
| 9 | private $sitepress_settings; |
| 10 | |
| 11 | public function __construct( $sitepress, $woocommerce_wpml, $sitepress_settings ) { |
| 12 | parent::__construct(); |
| 13 | |
| 14 | $this->woocommerce_wpml = $woocommerce_wpml; |
| 15 | $this->sitepress = $sitepress; |
| 16 | $this->sitepress_settings = $sitepress_settings; |
| 17 | } |
| 18 | |
| 19 | public function init_twig_functions() { |
| 20 | $function = new Twig_SimpleFunction( 'get_flag_url', [ $this, 'get_flag_url' ] ); |
| 21 | |
| 22 | $twig = $this->get_twig(); |
| 23 | $twig->addFunction( $function ); |
| 24 | } |
| 25 | |
| 26 | public function get_model() { |
| 27 | $this->init_twig_functions(); |
| 28 | |
| 29 | $wcml_dependencies = \WPML\Container\make( WCML_Dependencies::class ); |
| 30 | |
| 31 | $model = [ |
| 32 | 'default_language' => $this->sitepress->get_default_language(), |
| 33 | 'miss_slug_lang' => $this->get_missed_product_slug_translations_languages(), |
| 34 | 'prod_slug' => $this->woocommerce_wpml->strings->product_permalink_slug(), |
| 35 | 'dismiss_non_default' => isset( $this->woocommerce_wpml->settings['dismiss_non_default_language_warning'] ), |
| 36 | 'xml_config_errors' => ! empty( $wcml_dependencies->xml_config_errors ) ? $wcml_dependencies->xml_config_errors : false, |
| 37 | 'slugs_tab' => \WCML\Utilities\AdminUrl::getStoreURLTab(), |
| 38 | 'st_lang' => $this->sitepress_settings['st']['strings_language'], |
| 39 | 'not_en_doc_page' => 'https://wpml.org/?page_id=355545', |
| 40 | 'strings' => [ |
| 41 | 'conf' => __( 'Configuration Warnings', 'woocommerce-multilingual' ), |
| 42 | 'base_not_trnsl' => __( 'Your product permalink base is not translated to:', 'woocommerce-multilingual' ), |
| 43 | 'trsl_urls' => __( 'Translate URLs', 'woocommerce-multilingual' ), |
| 44 | 'run_not_en' => __( 'Running WPML Multilingual & Multicurrency for WooCommerce with default language other than English.', 'woocommerce-multilingual' ), |
| 45 | 'url_problems' => __( 'This may cause problems with URLs in different languages.', 'woocommerce-multilingual' ), |
| 46 | 'change_def_lang' => __( 'Change default language', 'woocommerce-multilingual' ), |
| 47 | 'attent_sett' => __( 'There are some settings that require careful attention.', 'woocommerce-multilingual' ), |
| 48 | 'over_sett' => __( 'Some settings from the WPML Multilingual & Multicurrency for WooCommerce wpml-config.xml file have been overwritten.', 'woocommerce-multilingual' ), |
| 49 | /* translators: %s is link to Multilingual Content Setup */ |
| 50 | 'check_conf' => __( 'You should check WPML configuration files added by other plugins or manual settings on the %s section.', 'woocommerce-multilingual' ), |
| 51 | 'cont_set' => '<a href="' . admin_url( 'admin.php?page=' . WPML_TM_FOLDER . '/menu/main.php&sm=mcsetup' ) . '">' . __( 'Multilingual Content Setup', 'woocommerce-multilingual' ) . '</a>', |
| 52 | ], |
| 53 | ]; |
| 54 | |
| 55 | return $model; |
| 56 | |
| 57 | } |
| 58 | |
| 59 | private function get_missed_product_slug_translations_languages() { |
| 60 | |
| 61 | $slug_settings = $this->sitepress->get_setting( 'posts_slug_translation' ); |
| 62 | $miss_slug_lang = []; |
| 63 | |
| 64 | if ( ! empty( $slug_settings['on'] ) ) { |
| 65 | $slug = $this->woocommerce_wpml->strings->product_permalink_slug(); |
| 66 | |
| 67 | if ( has_filter( 'wpml_slug_translation_available' ) ) { |
| 68 | $slug_translation_languages = apply_filters( 'wpml_get_slug_translation_languages', [], 'product' ); |
| 69 | } else { |
| 70 | $string_id = icl_get_string_id( $slug, $this->woocommerce_wpml->url_translation->url_strings_context(), $this->woocommerce_wpml->url_translation->url_string_name( 'product' ) ); |
| 71 | $slug_translations = icl_get_string_translations_by_id( $string_id ); |
| 72 | } |
| 73 | |
| 74 | $string_language = $this->woocommerce_wpml->strings->get_string_language( $slug, $this->woocommerce_wpml->url_translation->url_strings_context(), $this->woocommerce_wpml->url_translation->url_string_name( 'product' ) ); |
| 75 | |
| 76 | foreach ( $this->sitepress->get_active_languages() as $lang_info ) { |
| 77 | if ( |
| 78 | ( |
| 79 | ( isset( $slug_translations ) && ! array_key_exists( $lang_info['code'], $slug_translations ) ) || |
| 80 | ( isset( $slug_translation_languages ) && ! in_array( $lang_info['code'], $slug_translation_languages ) ) |
| 81 | ) && $lang_info['code'] != $string_language |
| 82 | ) { |
| 83 | $miss_slug_lang[] = $lang_info; |
| 84 | } |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | return $miss_slug_lang; |
| 89 | } |
| 90 | |
| 91 | public function get_flag_url( $language ) { |
| 92 | return $this->sitepress->get_flag_url( $language ); |
| 93 | } |
| 94 | |
| 95 | public function init_template_base_dir() { |
| 96 | $this->template_paths = [ |
| 97 | WCML_PLUGIN_PATH . '/templates/status/', |
| 98 | ]; |
| 99 | } |
| 100 | |
| 101 | public function get_template() { |
| 102 | return 'conf-warn.twig'; |
| 103 | } |
| 104 | |
| 105 | } |
| 106 |