class-wcml-downloadable-products.php
4 weeks ago
class-wcml-editor-save-filters.php
4 weeks ago
class-wcml-editor-ui-product-job.php
4 weeks ago
class-wcml-editor-ui-wysiwyg-field.php
5 years ago
class-wcml-page-builders.php
4 weeks ago
class-wcml-synchronize-product-data.php
4 weeks ago
class-wcml-synchronize-variations-data.php
4 weeks ago
class-wcml-translation-editor.php
4 weeks ago
class-wcml-wc-admin-duplicate-product.php
4 weeks ago
class-wcml-page-builders.php
108 lines
| 1 | <?php |
| 2 | |
| 3 | class WCML_Page_Builders { |
| 4 | |
| 5 | private $sitepress; |
| 6 | |
| 7 | public function __construct( $sitepress ) { |
| 8 | $this->sitepress = $sitepress; |
| 9 | } |
| 10 | |
| 11 | public function get_page_builders_string_packages( $product_id ) { |
| 12 | return apply_filters( 'wpml_st_get_post_string_packages', false, $product_id ); |
| 13 | } |
| 14 | |
| 15 | public function get_page_builders_strings( $product_id, $target_language ) { |
| 16 | |
| 17 | $string_packages = $this->get_page_builders_string_packages( $product_id ); |
| 18 | $translation_package = []; |
| 19 | |
| 20 | if ( $string_packages ) { |
| 21 | |
| 22 | foreach ( $string_packages as $package_id => $string_package ) { |
| 23 | |
| 24 | $translation_package[ $package_id ] = [ |
| 25 | 'title' => $string_package->title, |
| 26 | 'strings' => [], |
| 27 | ]; |
| 28 | |
| 29 | $strings = $string_package->get_package_strings(); |
| 30 | |
| 31 | $translated_strings = $string_package->get_translated_strings( [] ); |
| 32 | |
| 33 | foreach ( $strings as $string ) { |
| 34 | |
| 35 | if ( isset( $translated_strings[ $string->name ][ $target_language ] ) ) { |
| 36 | $string->translated_value = $translated_strings[ $string->name ][ $target_language ]['value']; |
| 37 | } |
| 38 | |
| 39 | $translation_package[ $package_id ]['strings'][] = $string; |
| 40 | } |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | return $translation_package; |
| 45 | |
| 46 | } |
| 47 | |
| 48 | public function get_page_builders_strings_section( $data, $product_id, $target_language ) { |
| 49 | |
| 50 | $string_packages = $this->get_page_builders_strings( $product_id, $target_language ); |
| 51 | $strings_section = false; |
| 52 | |
| 53 | foreach ( $string_packages as $string_package ) { |
| 54 | $strings_section = new WPML_Editor_UI_Field_Section( $string_package['title'] ); |
| 55 | |
| 56 | if ( isset( $string_package['strings'] ) ) { |
| 57 | foreach ( $string_package['strings'] as $string ) { |
| 58 | $field_label = apply_filters( 'wpml_string_title_from_id', false, $string->id ); |
| 59 | $strings_section->add_field( new WCML_Editor_UI_WYSIWYG_Field( $string->name, $field_label, $data, true ) ); |
| 60 | } |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | return $strings_section; |
| 65 | } |
| 66 | |
| 67 | public function page_builders_data( $element_data, $product_id, $target_language ) { |
| 68 | |
| 69 | $string_packages = $this->get_page_builders_strings( $product_id, $target_language ); |
| 70 | |
| 71 | foreach ( $string_packages as $string_package ) { |
| 72 | |
| 73 | if ( isset( $string_package['strings'] ) ) { |
| 74 | foreach ( $string_package['strings'] as $string ) { |
| 75 | $element_data[ $string->name ] = [ 'original' => $string->value ]; |
| 76 | if ( isset( $string->translated_value ) ) { |
| 77 | $element_data[ $string->name ]['translation'] = $string->translated_value; |
| 78 | } |
| 79 | } |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | return $element_data; |
| 84 | } |
| 85 | |
| 86 | public function save_page_builders_strings( $translations, $product_id, $target_language ) { |
| 87 | |
| 88 | $string_packages = $this->get_page_builders_strings( $product_id, $target_language ); |
| 89 | |
| 90 | foreach ( $string_packages as $string_package ) { |
| 91 | |
| 92 | if ( isset( $string_package['strings'] ) ) { |
| 93 | foreach ( $string_package['strings'] as $string ) { |
| 94 | |
| 95 | do_action( |
| 96 | 'wpml_add_string_translation', |
| 97 | $string->id, |
| 98 | $target_language, |
| 99 | $translations[ md5( $string->name ) ], |
| 100 | $this->sitepress->get_wp_api()->constant( 'ICL_TM_COMPLETE' ) |
| 101 | ); |
| 102 | |
| 103 | } |
| 104 | } |
| 105 | } |
| 106 | } |
| 107 | } |
| 108 |