Changeset 2537985
- Timestamp:
- 05/26/2021 12:39:48 PM (5 years ago)
- Location:
- multisite-sync-for-woocommerce
- Files:
-
- 12 added
- 3 edited
-
tags/3.3 (added)
-
tags/3.3/img (added)
-
tags/3.3/img/lemontec-logo.svg (added)
-
tags/3.3/inc (added)
-
tags/3.3/inc/inc-backend.php (added)
-
tags/3.3/languages (added)
-
tags/3.3/languages/multisite-sync-for-woocommerce-de_DE.mo (added)
-
tags/3.3/languages/multisite-sync-for-woocommerce-de_DE.po (added)
-
tags/3.3/languages/multisite-sync-for-woocommerce-de_DE_formal.mo (added)
-
tags/3.3/languages/multisite-sync-for-woocommerce-de_DE_formal.po (added)
-
tags/3.3/lemontec-woocommerce-multisite-sync.php (added)
-
tags/3.3/readme.txt (added)
-
trunk/inc/inc-backend.php (modified) (7 diffs)
-
trunk/lemontec-woocommerce-multisite-sync.php (modified) (3 diffs)
-
trunk/readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
multisite-sync-for-woocommerce/trunk/inc/inc-backend.php
r2521105 r2537985 1 1 <?php 2 3 // METABOX 4 function multisite_sync_for_woocommerce_json_fileds() { 5 $setting_blog_ids = get_site_option( 'lemontec_woocommerce_mulitsite_sync_blogid'); 6 7 // VARS 8 $current_blog_id = get_current_blog_id(); 9 $get_blog_ids = get_sites(array('fields' => 'ids', 'site__not_in' => $current_blog_id)); 10 11 // BUILD JSON ARRAY FOR FIELDS 12 $lang_field_array = array ( 'title' => 'Multisite Sync language settings', 'prefix' => 'lemontec_woocommerce_mulitsite_sync_options_', 'domain' => 'multisite-sync-for-woocommerce', 'class_name' => 'multisite_sync_for_woocommerce', 'post-type' => array ( 0 => 'post', 1 => 'page', ), 'context' => 'side', 'priority' => 'high', 'cpt' => 'product', 'fields' => array (), ); 13 foreach($get_blog_ids as $blog) { 14 if(! in_array($blog, $setting_blog_ids)) { 15 continue; 16 } 17 $lang_field_array['fields'][] = array( 18 'type' => 'url', 19 'label' => 'Target URL for:<br> ' . get_site_url($blog) . '<br><br>', 20 'id' => 'lemontec_woocommerce_mulitsite_sync_options_target_url_blogid_' . $blog, 21 ); 22 } 23 24 $json = json_encode($lang_field_array ); 25 return $json; 26 } 27 28 class multisite_sync_for_woocommerce { 29 30 private $config = ''; 31 public function __construct() { 32 $this->config = json_decode(multisite_sync_for_woocommerce_json_fileds(), true ); 33 $this->process_cpts(); 34 add_action( 'add_meta_boxes', [ $this, 'add_meta_boxes' ] ); 35 add_action( 'save_post', [ $this, 'save_post' ] ); 36 } 37 38 public function process_cpts() { 39 if ( !empty( $this->config['cpt'] ) ) { 40 if ( empty( $this->config['post-type'] ) ) { 41 $this->config['post-type'] = []; 42 } 43 $parts = explode( ',', $this->config['cpt'] ); 44 $parts = array_map( 'trim', $parts ); 45 $this->config['post-type'] = array_merge( $this->config['post-type'], $parts ); 46 } 47 } 48 49 public function add_meta_boxes() { 50 foreach ( $this->config['post-type'] as $screen ) { 51 add_meta_box( 52 sanitize_title( $this->config['title'] ), 53 $this->config['title'], 54 [ $this, 'add_meta_box_callback' ], 55 $screen, 56 $this->config['context'], 57 $this->config['priority'] 58 ); 59 } 60 } 61 62 public function save_post( $post_id ) { 63 foreach ( $this->config['fields'] as $field ) { 64 switch ( $field['type'] ) { 65 case 'url': 66 if ( isset( $_POST[ $field['id'] ] ) ) { 67 $sanitized = esc_url_raw( $_POST[ $field['id'] ] ); 68 update_post_meta( $post_id, $field['id'], $sanitized ); 69 } 70 break; 71 default: 72 if ( isset( $_POST[ $field['id'] ] ) ) { 73 $sanitized = sanitize_text_field( $_POST[ $field['id'] ] ); 74 update_post_meta( $post_id, $field['id'], $sanitized ); 75 } 76 } 77 } 78 } 79 80 public function add_meta_box_callback() { 81 $this->fields_div(); 82 } 83 84 private function fields_div() { 85 foreach ( $this->config['fields'] as $field ) { 86 ?><div class="components-base-control"> 87 <div class="components-base-control__field"><?php 88 $this->label( $field ); 89 $this->field( $field ); 90 ?></div> 91 </div><?php 92 } 93 } 94 95 private function label( $field ) { 96 switch ( $field['type'] ) { 97 default: 98 printf( 99 '<label class="components-base-control__label" for="%s">%s</label>', 100 $field['id'], $field['label'] 101 ); 102 } 103 } 104 105 private function field( $field ) { 106 switch ( $field['type'] ) { 107 default: 108 $this->input( $field ); 109 } 110 } 111 112 private function input( $field ) { 113 printf( 114 '<input class="components-text-control__input %s" id="%s" name="%s" %s type="%s" value="%s">', 115 isset( $field['class'] ) ? $field['class'] : '', 116 $field['id'], $field['id'], 117 isset( $field['pattern'] ) ? "pattern='{$field['pattern']}'" : '', 118 $field['type'], 119 $this->value( $field ) 120 ); 121 } 122 123 private function value( $field ) { 124 global $post; 125 if ( metadata_exists( 'post', $post->ID, $field['id'] ) ) { 126 $value = get_post_meta( $post->ID, $field['id'], true ); 127 } else if ( isset( $field['default'] ) ) { 128 $value = $field['default']; 129 } else { 130 return ''; 131 } 132 return str_replace( '\u0027', "'", $value ); 133 } 134 135 } 136 new multisite_sync_for_woocommerce; 2 137 3 138 /* CREATE MULTISITE BACKEND SETTING MENÜ */ … … 33 168 </li> 34 169 <li> 35 < ?php esc_html_e('Language switch with href-lang-tags' , 'multisite-sync-for-woocommerce'); ?>170 <s><?php esc_html_e('Language switch with href-lang-tags' , 'multisite-sync-for-woocommerce'); ?></s> 36 171 </li> 37 172 <li> … … 108 243 </tr> 109 244 </table> 245 <h2><?php esc_html_e('Extra settings:' , 'multisite-sync-for-woocommerce'); ?></h2> 246 <table class="form-table"> 247 <tr> 248 <th scope="row"><?php esc_html_e('Language settings' , 'multisite-sync-for-woocommerce'); ?></th> 249 <td> 250 <label> 251 <?php if(get_site_option( 'lemontec_woocommerce_mulitsite_sync_checkbox_hreflang_active') == true) : ?> 252 <input name="lemontec_woocommerce_mulitsite_sync_checkbox_hreflang_active" type="checkbox" value="true" checked> 253 <?php else : ?> 254 <input name="lemontec_woocommerce_mulitsite_sync_checkbox_hreflang_active" type="checkbox" value="true"> 255 <?php endif; ?> 256 <b><?php esc_html_e('Activate hreflang tags' , 'multisite-sync-for-woocommerce'); ?></b> 257 <em> 258 <?php esc_html_e('(<link rel="alternate" hreflang="xx-XX" href="URL"/>)' , 'multisite-sync-for-woocommerce'); ?> 259 <br> 260 <?php esc_html_e('The right urls will genearte by sku, you can overwrite per product, page, post...' , 'multisite-sync-for-woocommerce'); ?> 261 </em> 262 </label> 263 </td> 264 </tr> 265 </table> 266 <table class="form-table"> 267 <tr> 268 <th scope="row"> 269 <label for="some_field"> 270 <?php esc_html_e('Canonical page (important for SEO duplicate content):' , 'multisite-sync-for-woocommerce'); ?> 271 </label> 272 </th> 273 <td> 274 <fieldset> 275 <ul> 276 <?php 277 $get_blogs = get_sites(); 278 $saved_blogs = get_site_option('lemontec_woocommerce_mulitsite_sync_blogid_canonical'); 279 foreach($get_blogs as $row) : ?> 280 <li> 281 <label> 282 <?php 283 if(in_array($row->blog_id, $saved_blogs)) : ?> 284 <input type="radio" name="blog_id_canonical[]" value="<?php echo $row->blog_id ?>" checked> 285 <b>URL:</b> <?php echo esc_html($row->domain); ?> 286 <?php else : ?> 287 <input type="radio" name="blog_id_canonical[]" value="<?php echo $row->blog_id ?>"> 288 <b>URL:</b> <?php echo esc_html($row->domain); ?> 289 <?php endif; ?> 290 </label> 291 </li> 292 <?php endforeach; ?> 293 <?php 294 foreach($saved_blogs as $row) { 295 if(empty($row)) : ?> 296 <li> 297 <input type="radio" name="blog_id_canonical[]" value="false" checked> 298 <?php esc_html_e('disable' , 'multisite-sync-for-woocommerce'); ?> 299 </li> 300 <?php else : ?> 301 <li> 302 <input type="radio" name="blog_id_canonical[]" value="false"> 303 <?php esc_html_e('disable' , 'multisite-sync-for-woocommerce'); ?> 304 </li> 305 <?php 306 endif; 307 }?> 308 </ul> 309 </fieldset> 310 </td> 311 </tr> 312 </table> 110 313 <?php submit_button(); ?> 111 314 </form> … … 121 324 $post_sync_stock = sanitize_text_field($_POST['lemontec_woocommerce_mulitsite_sync_checkbox_stock']); 122 325 $post_sync_price = sanitize_text_field($_POST['lemontec_woocommerce_mulitsite_sync_checkbox_price']); 326 $post_sync_hreflang = sanitize_text_field($_POST['lemontec_woocommerce_mulitsite_sync_checkbox_hreflang_active']); 123 327 $post_sync_blog_id = $_POST['blog_id']; 328 $post_sync_blog_id_canonical = $_POST['blog_id_canonical']; 124 329 125 330 check_admin_referer( 'lemontec-validate' ); // Nonce security check … … 128 333 update_site_option( 'lemontec_woocommerce_mulitsite_sync_checkbox_stock', $post_sync_stock ); 129 334 } 130 131 335 if($post_sync_price == true || $post_sync_price == false) { 132 336 update_site_option( 'lemontec_woocommerce_mulitsite_sync_checkbox_price', $post_sync_price ); 337 } 338 if($post_sync_hreflang == true || $post_sync_hreflang == false) { 339 update_site_option( 'lemontec_woocommerce_mulitsite_sync_checkbox_hreflang_active', $post_sync_hreflang ); 133 340 } 134 341 … … 138 345 } 139 346 update_site_option( 'lemontec_woocommerce_mulitsite_sync_blogid', $blog_ids); 347 348 $blog_ids = array(); 349 foreach($post_sync_blog_id_canonical as $row) { 350 array_push($blog_ids, intval($row)); 351 } 352 update_site_option( 'lemontec_woocommerce_mulitsite_sync_blogid_canonical', $blog_ids); 140 353 141 354 … … 144 357 'updated' => true ), network_admin_url('admin.php') 145 358 )); 146 147 359 exit; 148 360 } -
multisite-sync-for-woocommerce/trunk/lemontec-woocommerce-multisite-sync.php
r2521105 r2537985 5 5 Description: Sync WooCommerce-Products data by SKU 6 6 Author: LEMONTEC 7 Version: 3. 27 Version: 3.3 8 8 Author URI: https://lemontec.at/kontakt/ 9 9 Text Domain: multisite-sync-for-woocommerce … … 78 78 update_post_meta($p_id, '_sale_price', $get_sale_price); 79 79 } 80 80 wc_delete_product_transients($p_id); 81 81 } 82 82 … … 85 85 } 86 86 87 /* HREFLANG */ 88 add_action('wp_head', 'lemontec_woocommerce_mulitsite_sync_wp_head'); 89 function lemontec_woocommerce_mulitsite_sync_wp_head(){ 90 91 if(get_site_option( 'lemontec_woocommerce_mulitsite_sync_checkbox_hreflang_active') == true && class_exists( 'WooCommerce' )) { 92 $custom_lang = false; 93 94 // GET OPTIONS 95 $setting_blog_ids = get_site_option( 'lemontec_woocommerce_mulitsite_sync_blogid'); 96 97 // WOO 98 $product = ''; 99 $sku = ''; 100 if(is_product()) { 101 $product = wc_get_product(get_the_ID()); 102 $sku = $product->get_sku(); 103 } 104 105 // VARS 106 $current_blog_id = get_current_blog_id(); 107 $get_blog_ids = get_sites(array('fields' => 'ids')); 108 $custom_meta_post_id = get_the_ID(); 109 110 foreach($setting_blog_ids as $blog) { 111 $custom_meta = get_post_meta($custom_meta_post_id, 'lemontec_woocommerce_mulitsite_sync_options_target_url_blogid_'.$blog, true); 112 if(! empty($custom_meta)) { 113 $iso_code = get_option( 'WPLANG'); 114 $permalink = get_permalink(); 115 switch_to_blog($blog); 116 echo '<link rel="alternate" hreflang="'.$iso_code.'" href="'.$permalink.'" />'; 117 118 $iso_code = get_option( 'WPLANG'); 119 restore_current_blog(); 120 121 echo '<link rel="alternate" hreflang="'.$iso_code.'" href="'.$custom_meta.'" />'; 122 123 $custom_lang = true; 124 } 125 } 126 127 // SET HREFLANG TAGS 128 if($custom_lang == false) { 129 foreach($get_blog_ids as $blog) { 130 if(! in_array($blog, $setting_blog_ids)) { 131 continue; 132 } 133 134 switch_to_blog($blog); 135 136 // INSTANCE VARS 137 $iso_code = get_option( 'WPLANG'); 138 $current_home_url = get_home_url(); 139 140 $p_id = ''; 141 if($sku) { 142 $p_id = wc_get_product_id_by_sku($sku); 143 } 144 145 // HOME 146 if(is_front_page()) { 147 echo '<link rel="alternate" hreflang="'.$iso_code.'" href="'.$current_home_url.'" />'; 148 } 149 // PRODUCT 150 if(! empty($p_id)) { 151 echo '<link rel="alternate" hreflang="'.$iso_code.'" href="'.get_permalink($p_id).'" />'; 152 } 153 // CATEGORY 154 if(is_product_category()) { 155 echo '<link rel="alternate" hreflang="'.$iso_code.'" href="'.get_permalink().'" />'; 156 } 157 restore_current_blog(); 158 } 159 } 160 } 161 162 if(get_site_option( 'lemontec_woocommerce_mulitsite_sync_blogid_canonical')[0] == true && class_exists( 'WooCommerce' )) { 163 switch_to_blog(get_site_option( 'lemontec_woocommerce_mulitsite_sync_blogid_canonical')[0]); 164 $canonical_permalink = get_permalink(); 165 restore_current_blog(); 166 echo '<link rel="canonical" href="'.$canonical_permalink.'" />'; 167 } 168 }; 169 87 170 // ACTIONS 88 171 add_action( 'woocommerce_update_product', 'lemon_woocommerce_sync_multisite', 10, 1 ); -
multisite-sync-for-woocommerce/trunk/readme.txt
r2521105 r2537985 3 3 Tags: WooCommerce, Stock, Multisite Sync, Order Sync 4 4 Requires at least: 4.6 5 Tested up to: 5. 5.35 Tested up to: 5.7.2 6 6 Requires PHP: 7 7 Stable tag: 3. 27 Stable tag: 3.3 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html
Note: See TracChangeset
for help on using the changeset viewer.