Changeset 2795813
- Timestamp:
- 10/07/2022 10:11:19 PM (3 years ago)
- Location:
- easytranslate/trunk
- Files:
-
- 5 edited
-
README.txt (modified) (2 diffs)
-
admin/class-easy-translate-post-translation-list.php (modified) (2 diffs)
-
admin/class-easy-translate-translation-list.php (modified) (7 diffs)
-
admin/class-easy-translate-translation.php (modified) (2 diffs)
-
easy-translate.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
easytranslate/trunk/README.txt
r2780745 r2795813 5 5 Requires at least: 4.7 6 6 Tested up to: 6.0 7 Stable tag: 4. 77 Stable tag: 4.8 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 40 40 * Save time! Build your custom workflows (when this happens > do this) 41 41 * String Library > enabling you to localise your strings faster. This is especially useful within Apps 42 * Support for WooCommerce + WPML 43 * Support for Yoast SEO + WPML 42 44 43 45 == Installation == -
easytranslate/trunk/admin/class-easy-translate-post-translation-list.php
r2772023 r2795813 26 26 'oembed_cache', 27 27 'user_request', 28 'product_variation', 28 29 ]; 29 30 … … 417 418 <?php 418 419 foreach ($post_types as $post_type) { 420 if (in_array($post_type, self::EXCLUDED_POST_TYPES)) { 421 continue; 422 } 419 423 ?> 420 424 <option <?php selected($current_post_type, $post_type); ?> value="<?= $post_type ?>"> -
easytranslate/trunk/admin/class-easy-translate-translation-list.php
r2780745 r2795813 9 9 abstract class Easy_Translate_Translation_List extends WP_List_Table 10 10 { 11 const YOAST_SEO_FIELDS = [ 12 '_yoast_wpseo_opengraph-description', 13 '_yoast_wpseo_opengraph-title', 14 '_yoast_wpseo_twitter-description', 15 '_yoast_wpseo_twitter-title', 16 '_yoast_wpseo_focuskw', 17 '_yoast_wpseo_title', 18 '_yoast_wpseo_metadesc', 19 '_yoast_wpseo_bctitle', 20 ]; 11 21 /** 12 22 * Translation statuses. … … 434 444 * @param int $source_post_id 435 445 * @param int $post_id 446 * @param string $target_language 436 447 * @param string $post_content 437 448 * @param string $post_title 438 449 * @param string $post_excerpt 439 450 * @param array $woocommerce 451 * @param array $yoast_seo 440 452 */ 441 453 public static function update_post( 442 454 int $source_post_id, 443 455 int $post_id, 456 string $target_language, 444 457 string $post_content = '', 445 458 string $post_title = '', 446 459 string $post_excerpt = '', 447 array $woocommerce = [] 460 array $woocommerce = [], 461 array $yoast_seo = [] 448 462 ) { 449 463 $update = ''; … … 458 472 $post_content = esc_sql($post_content); 459 473 $query = "UPDATE {$wpdb->prefix}posts SET post_content = '{$post_content}' {$update} WHERE id = {$post_id}"; 460 $wpdb->query($query); 461 462 if (empty($woocommerce)) { 474 475 self::update_woocommerce_translations($source_post_id, $post_id, $target_language, $woocommerce); 476 self::update_yoast_translations($post_id, $yoast_seo); 477 478 delete_post_meta($post_id, '_icl_lang_duplicate_of', $source_post_id); 479 } 480 481 public static function update_yoast_translations(string $post_id, array $yoast_ceo) 482 { 483 if (empty($yoast_ceo)) { 463 484 return; 464 485 } 465 486 466 if (isset($woocommerce['_product_attributes'])) { 467 $post_meta_fields = get_post_meta($post_id); 468 $attributes = []; 469 if (isset($post_meta_fields['_product_attributes']) && !empty($product_attributes = $post_meta_fields['_product_attributes'])) { 470 foreach (unserialize($product_attributes[0]) as $field_name => $values) { 471 if (!isset($woocommerce['_product_attributes'][$field_name])) { 472 continue; 473 } 474 $attributes[$field_name] = $values; 475 $attributes[$field_name]['name'] = $woocommerce['_product_attributes'][$field_name]['name']; 476 $attributes[$field_name]['value'] = $woocommerce['_product_attributes'][$field_name]['value']; 477 } 478 479 if (!empty($attributes)) { 480 update_post_meta($post_id, '_product_attributes', $attributes); 481 } 482 } 487 foreach ($yoast_ceo as $key => $translation) { 488 update_post_meta($post_id, $key, $translation); 489 } 490 } 491 492 public static function update_woocommerce_translations( 493 string $source_post_id, 494 string $post_id, 495 string $target_language, 496 array $woocommerce 497 ) { 498 // WooCommerce WPML bridge is not installed 499 if (empty($woocommerce) || !class_exists('woocommerce_wpml')) { 500 return; 501 } 502 503 $translations = []; 504 foreach (($woocommerce['_product_attributes'] ?? []) as $key => $value) { 505 $translations[md5($key)] = $value['value']; 506 $translations[md5("{$key}_name")] = $value['name']; 483 507 } 484 508 if (isset($woocommerce['_purchase_note'])) { 485 update_post_meta($post_id, '_purchase_note', $woocommerce['_purchase_note']); 486 } 509 $translations[md5('_purchase_note')] = $woocommerce['_purchase_note']; 510 } 511 foreach (($woocommerce['_variations'] ?? []) as $variation_id => $value) { 512 $translations[md5("_variation_description{$variation_id}")] = $value['description']; 513 } 514 515 $woo_wpml = new woocommerce_wpml(); 516 $woo_wpml->init(); 517 do_action('wcml_before_sync_product_data', $source_post_id, $post_id, $target_language); 518 519 $woo_wpml->sync_product_data->duplicate_product_post_meta($source_post_id, $post_id, $translations); 520 $woo_wpml->sync_product_data->sync_product_taxonomies($source_post_id, $post_id, $target_language); 521 $woo_wpml->attributes->sync_product_attr($source_post_id, $post_id, $target_language, $translations); 522 $woo_wpml->attributes->sync_default_product_attr($source_post_id, $post_id, $target_language); 523 $woo_wpml->sync_variations_data->sync_product_variations( 524 $source_post_id, 525 $post_id, 526 $target_language, 527 [ 528 'editor_translations' => $translations, 529 'is_troubleshooting' => true, 530 ] 531 ); 532 $woo_wpml->sync_product_data->sync_linked_products($source_post_id, $post_id, $target_language); 533 $woo_wpml->sync_product_data->sync_product_stock(wc_get_product($source_post_id), wc_get_product($post_id)); 534 $woo_wpml->media->sync_thumbnail_id($source_post_id, $post_id, $target_language); 487 535 } 488 536 … … 614 662 $content['post_full'][$post_id]['excerpt'] = $post->post_excerpt; 615 663 } 616 617 664 $post_meta_fields = get_post_meta($post_id); 665 666 foreach (self::YOAST_SEO_FIELDS as $yoast_field_name) { 667 if (isset($post_meta_fields[$yoast_field_name][0]) && !empty($post_meta_fields[$yoast_field_name][0])) { 668 $content['post_full'][$post_id]['yoast_seo'][$yoast_field_name] = $post_meta_fields[$yoast_field_name][0]; 669 } 670 } 671 618 672 if (isset($post_meta_fields['_product_attributes']) && !empty($product_attributes = $post_meta_fields['_product_attributes'])) { 619 673 foreach (unserialize($product_attributes[0]) as $field_name => $values) { … … 622 676 } 623 677 } 624 if (isset($post_meta_fields['_purchase_note']) && !empty($purchase_note = $post_meta_fields['_purchase_note'])) { 625 $content['post_full'][$post_id]['woocommerce']['_purchase_note'] = $purchase_note; 678 679 if (isset($post_meta_fields['_purchase_note'][0]) && !empty($purchase_note = $post_meta_fields['_purchase_note'][0])) { 680 $content['post_full'][$post_id]['woocommerce']['_purchase_note'] = $purchase_note[0]; 681 } 682 683 // WooCommerce WPML bridge is not installed 684 if (class_exists('woocommerce_wpml')) { 685 $woo_wpml = new woocommerce_wpml(); 686 $woo_wpml->init(); 687 688 foreach ($woo_wpml->sync_variations_data->get_product_variations($post_id) as $variation) { 689 $description = get_post_meta($variation->ID, '_variation_description', true); 690 if (!empty($description)) { 691 $content['post_full'][$post_id]['woocommerce']['_variations'][$variation->ID]['description'] = $description; 692 } 693 } 626 694 } 627 695 } 628 696 629 697 return $content; 630 631 698 } 632 699 … … 640 707 protected static function get_strings_by_package_id($package_id, $updated = false) 641 708 { 642 643 //todo: needs update or refactor644 // if ($updated) {645 // $where = '(status = ' . self::STATUS_NEEDS_UPDATE . ' OR status = ' . self::STATUS_NOT_TRANSLATED . ' OR status = ' . self::STATUS_DUPLICATE . ')';646 // } else {647 // $where = 'status <> ' . self::STATUS_COMPLETE;648 // }649 650 709 global $wpdb; 651 710 $package_id = esc_sql($package_id); … … 653 712 654 713 return $wpdb->get_results($query, ARRAY_A); 655 656 714 } 657 715 -
easytranslate/trunk/admin/class-easy-translate-translation.php
r2770454 r2795813 76 76 $post_excerpt = $content[$source_post_id]['excerpt'] ?? ''; 77 77 $woocommerce = $content[$source_post_id]['woocommerce'] ?? []; 78 $yoast_seo = $content[$source_post_id]['yoast_seo'] ?? []; 78 79 79 80 if ($source_translations = Easy_Translate_Post_Translation_List::get_translations_by_element_id($source_post_id)) { … … 87 88 $source_post_id, 88 89 $translations['element_id'], 90 $target_language, 89 91 $post_content, 90 92 $post_title, 91 93 $post_excerpt, 92 $woocommerce 94 $woocommerce, 95 $yoast_seo 93 96 ); 94 97 Easy_Translate_Post_Translation_List::update_translations_status( -
easytranslate/trunk/easy-translate.php
r2780745 r2795813 15 15 * Plugin URI: https://www.easytranslate.com/en/integrations/cms/wordpress-plugin/ 16 16 * Description: This is a short description of what the plugin does. It's displayed in the WordPress admin area. 17 * Version: 1. 7.417 * Version: 1.8.0 18 18 * Author: EasyTranslate 19 19 * Author URI: https://easytranslate.com … … 34 34 * Rename this for your plugin and update it as you release new versions. 35 35 */ 36 define('EASY_TRANSLATE_VERSION', '1. 7.4');36 define('EASY_TRANSLATE_VERSION', '1.8.0'); 37 37 38 38 /**
Note: See TracChangeset
for help on using the changeset viewer.