currency-switcher
4 weeks ago
multi-currency
4 weeks ago
setup
4 weeks ago
status
4 weeks ago
store-urls
4 weeks ago
class-wcml-currencies-dropdown-ui.php
5 years ago
class-wcml-custom-files-ui.php
4 weeks ago
class-wcml-languages-upgrade-notice.php
4 years ago
class-wcml-menus-wrap-base.php
4 weeks ago
class-wcml-menus-wrap.php
4 weeks ago
class-wcml-multilingual-ui.php
9 months ago
class-wcml-not-translatable-attributes.php
4 weeks ago
class-wcml-pointer-ui.php
1 year ago
class-wcml-removed-cart-items-ui.php
4 weeks ago
class-wcml-settings-ui.php
4 weeks ago
class-wcml-st-taxonomy-ui.php
11 months ago
class-wcml-sync-taxonomy.php
4 weeks ago
class-wcml-templates-factory.php
4 weeks ago
class-wcml-troubleshooting-ui.php
4 weeks ago
class-wcml-menus-wrap.php
195 lines
| 1 | <?php |
| 2 | |
| 3 | use WCML\Utilities\AdminPages; |
| 4 | |
| 5 | use function WCML\functions\getSetting; |
| 6 | |
| 7 | class WCML_Menus_Wrap extends WCML_Menu_Wrap_Base { |
| 8 | private $sitepress; |
| 9 | |
| 10 | private $sitepress_settings; |
| 11 | |
| 12 | public function __construct( $woocommerce_wpml, $sitepress, $sitepress_settings ) { |
| 13 | parent::__construct( $woocommerce_wpml ); |
| 14 | $this->sitepress = $sitepress; |
| 15 | $this->sitepress_settings = $sitepress_settings; |
| 16 | } |
| 17 | |
| 18 | protected function get_child_model() { |
| 19 | $current_tab = AdminPages::getTabToDisplay(); |
| 20 | |
| 21 | $model = [ |
| 22 | 'strings' => [ |
| 23 | 'title' => WCML_Admin_Menus::getWcmlLabel(), |
| 24 | 'untranslated_terms' => __( 'You have untranslated terms!', 'woocommerce-multilingual' ), |
| 25 | ], |
| 26 | 'menu' => [ |
| 27 | 'translations' => [ |
| 28 | 'title' => __( 'Multilingual', 'woocommerce-multilingual' ), |
| 29 | 'url' => \WCML\Utilities\AdminUrl::getMultilingualTab(), |
| 30 | 'active' => $current_tab == AdminPages::TAB_MULTILINGUAL ? 'nav-tab-active' : '', |
| 31 | ], |
| 32 | \WCML\Utilities\AdminUrl::TAB_SETTINGS => [ |
| 33 | 'name' => __( 'Settings', 'woocommerce-multilingual' ), |
| 34 | 'active' => \WCML\Utilities\AdminUrl::TAB_SETTINGS == $current_tab ? 'nav-tab-active' : '', |
| 35 | 'url' => \WCML\Utilities\AdminUrl::getSettingsTab(), |
| 36 | ], |
| 37 | 'multi_currency' => [ |
| 38 | 'name' => __( 'Multicurrency', 'woocommerce-multilingual' ), |
| 39 | 'active' => \WCML\Utilities\AdminUrl::TAB_MULTICURRENCY == $current_tab ? 'nav-tab-active' : '', |
| 40 | 'url' => \WCML\Utilities\AdminUrl::getMultiCurrencyTab(), |
| 41 | ], |
| 42 | \WCML\Utilities\AdminUrl::TAB_STORE_URL => [ |
| 43 | 'name' => __( 'Store URLs', 'woocommerce-multilingual' ), |
| 44 | 'active' => \WCML\Utilities\AdminUrl::TAB_STORE_URL == $current_tab ? 'nav-tab-active' : '', |
| 45 | 'url' => \WCML\Utilities\AdminUrl::getStoreURLTab(), |
| 46 | ], |
| 47 | \WCML\Utilities\AdminUrl::TAB_STATUS => [ |
| 48 | 'name' => __( 'Status', 'woocommerce-multilingual' ), |
| 49 | 'active' => \WCML\Utilities\AdminUrl::TAB_STATUS == $current_tab ? 'nav-tab-active' : '', |
| 50 | 'url' => \WCML\Utilities\AdminUrl::getStatusTab(), |
| 51 | ], |
| 52 | \WCML\Utilities\AdminUrl::TAB_TROUBLESHOOTING => [ |
| 53 | 'name' => __( 'Troubleshooting', 'woocommerce-multilingual' ), |
| 54 | 'active' => \WCML\Utilities\AdminUrl::TAB_TROUBLESHOOTING == $current_tab ? 'nav-tab-active' : '', |
| 55 | 'url' => \WCML\Utilities\AdminUrl::getTroubleshootingTab(), |
| 56 | ], |
| 57 | ], |
| 58 | 'set_up_wizard_run' => getSetting( 'set_up_wizard_run' ), |
| 59 | 'can_manage_options' => current_user_can( 'wpml_manage_woocommerce_multilingual' ), |
| 60 | 'content' => $this->get_current_menu_content( $current_tab ), |
| 61 | ]; |
| 62 | |
| 63 | return $model; |
| 64 | } |
| 65 | |
| 66 | protected function get_current_menu_content( $current_tab ) { |
| 67 | |
| 68 | switch ( $current_tab ) { |
| 69 | |
| 70 | case AdminPages::TAB_MULTILINGUAL_STANDALONE: |
| 71 | wcml_safe_redirect( \WCML\Utilities\AdminUrl::getMultilingualTab() ); |
| 72 | break; |
| 73 | |
| 74 | case AdminPages::TAB_MULTILINGUAL: |
| 75 | $wcml_products_ui = new WCML_Multilingual_UI(); |
| 76 | |
| 77 | return $wcml_products_ui->get_view(); |
| 78 | |
| 79 | case AdminPages::TAB_MULTICURRENCY: |
| 80 | if ( current_user_can( 'wpml_operate_woocommerce_multilingual' ) ) { |
| 81 | $wcml_mc_ui = new WCML_Multi_Currency_UI( $this->woocommerce_wpml, $this->sitepress ); |
| 82 | |
| 83 | return $wcml_mc_ui->get_view(); |
| 84 | } |
| 85 | break; |
| 86 | |
| 87 | case \WCML\Utilities\AdminUrl::TAB_STORE_URL: |
| 88 | if ( current_user_can( 'wpml_operate_woocommerce_multilingual' ) ) { |
| 89 | $wcml_store_urls = new WCML_Store_URLs_UI( $this->woocommerce_wpml, $this->sitepress ); |
| 90 | |
| 91 | return $wcml_store_urls->get_view(); |
| 92 | } |
| 93 | break; |
| 94 | |
| 95 | case \WCML\Utilities\AdminUrl::TAB_STATUS: |
| 96 | if ( current_user_can( 'wpml_manage_woocommerce_multilingual' ) ) { |
| 97 | $wcml_status = new WCML_Status_UI( $this->woocommerce_wpml, $this->sitepress, $this->sitepress_settings ); |
| 98 | |
| 99 | return $wcml_status->get_view(); |
| 100 | } |
| 101 | break; |
| 102 | |
| 103 | case \WCML\Utilities\AdminUrl::TAB_TROUBLESHOOTING: |
| 104 | if ( current_user_can( 'wpml_manage_woocommerce_multilingual' ) ) { |
| 105 | $wcml_troubleshooting = new WCML_Troubleshooting_UI( $this->woocommerce_wpml ); |
| 106 | |
| 107 | return $wcml_troubleshooting->get_view(); |
| 108 | } |
| 109 | break; |
| 110 | |
| 111 | case \WCML\Utilities\AdminUrl::TAB_SETTINGS: |
| 112 | if ( current_user_can( 'wpml_manage_woocommerce_multilingual' ) ) { |
| 113 | $wcml_settings_ui = new WCML_Settings_UI( $this->woocommerce_wpml, $this->sitepress ); |
| 114 | |
| 115 | return $wcml_settings_ui->get_view(); |
| 116 | } |
| 117 | break; |
| 118 | |
| 119 | } |
| 120 | |
| 121 | switch ( $current_tab ) { |
| 122 | |
| 123 | case \WCML\Utilities\AdminUrl::TAB_PRODUCTS: |
| 124 | wcml_safe_redirect( \WCML\Utilities\AdminUrl::getWPMLTMDashboardProducts() ); |
| 125 | break; |
| 126 | |
| 127 | case 'product-attributes': |
| 128 | if ( current_user_can( 'wpml_operate_woocommerce_multilingual' ) ) { |
| 129 | $this->redirectToWPMLTaxonomyTranslation( $_GET['taxonomy'] ?? null ); |
| 130 | } |
| 131 | break; |
| 132 | |
| 133 | case 'product_cat': |
| 134 | case 'product_tag': |
| 135 | case 'product_shipping_class': |
| 136 | case 'custom-taxonomies': |
| 137 | if ( current_user_can( 'wpml_operate_woocommerce_multilingual' ) ) { |
| 138 | $this->redirectToWPMLTaxonomyTranslation( $current_tab ); |
| 139 | } |
| 140 | break; |
| 141 | |
| 142 | default: |
| 143 | $taxonomy_names = $this->getAllProductTaxomyNames(); |
| 144 | if ( current_user_can( 'wpml_operate_woocommerce_multilingual' ) && in_array( $current_tab, $taxonomy_names ) ) { |
| 145 | $this->redirectToWPMLTaxonomyTranslation( $current_tab ); |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | return ''; |
| 150 | } |
| 151 | |
| 152 | private function getAllProductTaxomyNames() : array { |
| 153 | $product_builtin_taxonomy_names = [ |
| 154 | 'product_cat', |
| 155 | 'product_tag', |
| 156 | 'product_shipping_class', |
| 157 | 'product_type', |
| 158 | 'translation_priority', |
| 159 | ]; |
| 160 | |
| 161 | $product_extra_taxonomy_names = []; |
| 162 | |
| 163 | $product_attribute_names = $this->getProductAttributeNames(); |
| 164 | $product_taxonomies = get_object_taxonomies( 'product', 'objects' ); |
| 165 | foreach ( $product_taxonomies as $product_taxonomy_name => $product_taxonomy_object ) { |
| 166 | if ( |
| 167 | ! in_array( $product_taxonomy_name, $product_builtin_taxonomy_names ) && |
| 168 | ! in_array( $product_taxonomy_name, $product_attribute_names ) && |
| 169 | is_taxonomy_translated( $product_taxonomy_name ) |
| 170 | ) { |
| 171 | $product_extra_taxonomy_names[] = $product_taxonomy_name; |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | return array_merge( $product_builtin_taxonomy_names, $product_extra_taxonomy_names ); |
| 176 | } |
| 177 | |
| 178 | private function getProductAttributeNames(): array { |
| 179 | $product_attribute_names = []; |
| 180 | |
| 181 | $product_attributes = $this->woocommerce_wpml->attributes->get_translatable_attributes(); |
| 182 | if ( $product_attributes ) { |
| 183 | foreach ( $product_attributes as $product_attribute ) { |
| 184 | $product_attribute_names[] = \WCML\Utilities\WCTaxonomies::TAXONOMY_PREFIX_ATTRIBUTE . $product_attribute->attribute_name; |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | return $product_attribute_names; |
| 189 | } |
| 190 | |
| 191 | private function redirectToWPMLTaxonomyTranslation( $taxonomy = null ) { |
| 192 | wcml_safe_redirect( \WCML\Utilities\AdminUrl::getWPMLTaxonomyTranslation( $taxonomy ) ); |
| 193 | } |
| 194 | } |
| 195 |