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 4.7.6 4.7.7 4.7.8 4.7.9 4.8.0 4.9.0 4.9.1 5.0.1 5.0.2 5.1.1 5.1.2 5.1.3 5.2.0 5.2.1 5.3.2 5.3.3.1 5.3.4 5.3.5 5.3.6 5.3.7
woocommerce-multilingual / classes / Permalinks / Settings / TranslationControls.php
woocommerce-multilingual / classes / Permalinks / Settings Last commit date
TranslationControls.php 1 week ago
TranslationControls.php
161 lines
1 <?php
2
3 namespace WCML\Permalinks\Settings;
4
5 use WCML\Permalinks\Strings;
6 use WCML\TranslationControls\Hooks as TranslationControlsBase;
7 use WCML\Utilities\AdminUrl;
8 use WCML\Utilities\WpAdminPages;
9
10 class TranslationControls extends TranslationControlsBase {
11
12 const PERMALINK_BASES = [
13 'tag_base' => 'product_tag',
14 'category_base' => 'product_cat',
15 'attribute_base' => 'attribute',
16 'product_base' => 'product',
17 ];
18
19 const INSTRUCTIONS_FOR_PRODUCTS = 'products';
20 const INSTRUCTIONS_FOR_PRODUCT_TAXONOMIES = 'product-taxonomies';
21
22 protected function addAdminPageHooks() {
23 add_action( 'admin_footer', [ $this, 'translationInstructions' ] );
24 add_action( 'admin_footer', [ $this, 'translationControls' ] );
25 $this->registerStringsOnSave();
26 }
27
28 protected function isAdminPage() {
29 return WpAdminPages::isPermalinksSettings();
30 }
31
32 protected function getInstructionsLink( $domain, $search = '' ) {
33 return AdminUrl::getStoreURLTab();
34 }
35
36 private function getInstructionsVariation( $variation ) {
37 if ( ! $this->hasStringsInDomain( Strings::TRANSLATION_DOMAIN ) ) {
38 return $this->getInstructionsWithoutRegisteredStrings( Strings::TRANSLATION_DOMAIN );
39 }
40 switch ( $variation ) {
41 case self::INSTRUCTIONS_FOR_PRODUCT_TAXONOMIES:
42 return sprintf(
43 /* translators: %1$s and %2$s are opening and closing HTML link tags */
44 esc_html__( 'To translate permalinks for product taxonomies, go to %1$sWPML Multilingual & Multicurrency for WooCommerce → Store URLs%2$s.', 'woocommerce-multilingual' ),
45 '<a href="' . esc_url( $this->getInstructionsLink( Strings::TRANSLATION_DOMAIN ) ) . '">',
46 '</a>'
47 );
48 case self::INSTRUCTIONS_FOR_PRODUCTS:
49 default:
50 return sprintf(
51 /* translators: %1$s and %2$s are opening and closing HTML link tags */
52 esc_html__( 'To translate product permalinks, go to %1$sWPML Multilingual & Multicurrency for WooCommerce → Store URLs%2$s.', 'woocommerce-multilingual' ),
53 '<a href="' . esc_url( $this->getInstructionsLink( Strings::TRANSLATION_DOMAIN ) ) . '">',
54 '</a>'
55 );
56 }
57 }
58
59 public function translationInstructions() {
60 $this->pointerFactory
61 ->create( [
62 'anchor' => esc_html__( 'How to translate permalinks for product taxonomies', 'woocommerce-multilingual' ),
63 'content' => $this->getInstructionsVariation( self::INSTRUCTIONS_FOR_PRODUCT_TAXONOMIES ),
64 'selectorId' => 'wpbody-content h2:nth-of-type(2) + p',
65 ] )->show();
66
67 $this->pointerFactory
68 ->create( [
69 'anchor' => esc_html__( 'How to translate product permalinks', 'woocommerce-multilingual' ),
70 'content' => $this->getInstructionsVariation( self::INSTRUCTIONS_FOR_PRODUCTS ),
71 'selectorId' => 'wpbody-content table.form-table.wc-permalink-structure',
72 'method' => 'before',
73 ] )->show();
74 }
75
76 protected function getTranslationControls() {
77 $translationControls = [];
78 $permalink_options = get_option( 'woocommerce_permalinks' );
79
80 foreach ( self::PERMALINK_BASES as $baseKey => $base ) {
81
82 switch ( $base ) {
83 case 'product_tag':
84 $value = ! empty( $permalink_options['tag_base'] )
85 ? $permalink_options['tag_base']
86 : Strings::DEFAULT_PRODUCT_TAG_BASE;
87 break;
88 case 'product_cat':
89 $value = ! empty( $permalink_options['category_base'] )
90 ? $permalink_options['category_base']
91 : Strings::DEFAULT_PRODUCT_CATEGORY_BASE;
92 break;
93 case 'attribute':
94 $value = ! empty( $permalink_options['attribute_base'] )
95 ? $permalink_options['attribute_base']
96 : Strings::DEFAULT_PRODUCT_ATTRIBUTE_BASE;
97 break;
98 case 'product':
99 $value = ! empty( $permalink_options['product_base'] )
100 ? trim( $permalink_options['product_base'], '/' )
101 : _x( Strings::DEFAULT_PRODUCT_BASE, 'default-slug', 'woocommerce' );
102 break;
103 default:
104 $value = '';
105 }
106
107 $translationControls[] = $this->getTranslationControl(
108 '',
109 $baseKey,
110 trim( $value, '/' ),
111 Strings::TRANSLATION_DOMAIN,
112 $this->getStringName( '', $base )
113 );
114 }
115
116 return $translationControls;
117 }
118
119 public function registerStringsOnSave() {
120 add_filter( 'pre_update_option_woocommerce_permalinks', [ $this, 'registerStringsOnPreUpdate' ] );
121 }
122
123 public function registerStringsOnPreUpdate( $wcPermalinks ) {
124 return $this->wcmlStrings->getUrlTranslation()->register_product_and_taxonomy_bases( $wcPermalinks );
125 }
126
127 protected function getStringName( $dummyContext, $base ) {
128 return Strings::getStringName( $base );
129 }
130
131 protected function getInputName( $dummyContext, $baseKey ) {
132 switch ( $baseKey ) {
133 case 'tag_base':
134 return 'woocommerce_product_tag_slug';
135 case 'category_base':
136 return 'woocommerce_product_category_slug';
137 case 'attribute_base':
138 return 'woocommerce_product_attribute_slug';
139 case 'product_base':
140 return 'product_permalink_structure';
141 }
142
143 return '';
144 }
145
146 protected function getInputId( $dummyContext, $baseKey ) {
147 return '';
148 }
149
150 protected function getLanguageSelectorId( $dummyContext, $baseKey ) {
151 return $baseKey . '_' . self::LANGUAGE_SELECTOR_ID_SUFFIX;
152 }
153
154
155
156 protected function getLanguageSelectorName( $dummy, $baseKey ) {
157 return $baseKey . '_language';
158 }
159
160 }
161