diff --git a/admin/blocks/main.php b/admin/blocks/main.php index 6a0278063f..8e2b007701 100644 --- a/admin/blocks/main.php +++ b/admin/blocks/main.php @@ -57,11 +57,12 @@ public function populateGlobalData( $globalData ) { } $blocks = get_posts( array( - 'post_type' => Brizy_Admin_Blocks_Main::CP_GLOBAL, - 'posts_per_page' => - 1, - 'post_status' => 'publish', - 'orderby' => 'ID', - 'order' => 'ASC', + 'post_type' => Brizy_Admin_Blocks_Main::CP_GLOBAL, + 'posts_per_page' => - 1, + 'post_status' => 'publish', + 'orderby' => 'ID', + 'order' => 'ASC', + 'suppress_filters' => false, ) ); foreach ( $blocks as $block ) { @@ -71,11 +72,12 @@ public function populateGlobalData( $globalData ) { } $blocks = get_posts( array( - 'post_type' => Brizy_Admin_Blocks_Main::CP_SAVED, - 'posts_per_page' => - 1, - 'post_status' => 'publish', - 'orderby' => 'ID', - 'order' => 'ASC', + 'post_type' => Brizy_Admin_Blocks_Main::CP_SAVED, + 'posts_per_page' => - 1, + 'post_status' => 'publish', + 'orderby' => 'ID', + 'order' => 'ASC', + 'suppress_filters' => false, ) ); foreach ( $blocks as $block ) { diff --git a/compatibilities/init.php b/compatibilities/init.php index fc48f87432..d4c94d7985 100644 --- a/compatibilities/init.php +++ b/compatibilities/init.php @@ -24,7 +24,7 @@ private function load_compatibilites() { new Brizy_Compatibilities_Autoptimize(); } - if ( defined( 'ICL_SITEPRESS_VERSION' ) ) { + if ( apply_filters( 'wpml_setting', false, 'setup_complete' ) ) { new Brizy_Compatibilities_WPML(); } diff --git a/compatibilities/wpml.php b/compatibilities/wpml.php index 6a6db6b4b0..5e5420a93f 100644 --- a/compatibilities/wpml.php +++ b/compatibilities/wpml.php @@ -8,6 +8,15 @@ class Brizy_Compatibilities_WPML { public function __construct() { add_action( 'wp_insert_post', array( $this, 'insertNewPost' ), -10000, 3 ); add_action( 'wp_insert_post', array( $this, 'duplicatePosts' ), -10000, 3 ); + + add_filter( 'wpml_decode_custom_field', array( $this, 'decode_custom_field' ), 10, 2 ); + add_filter( 'wpml_encode_custom_field', array( $this, 'encode_custom_field' ), 10, 2 ); + add_filter( 'wpml_pb_should_body_be_translated', array( $this, 'remove_body' ), 10, 2 ); + add_action( 'wpml_pro_translation_completed', array( $this, 'save_post' ), 10, 3 ); + + add_filter( 'wpml_basket_base64_item', '__return_false' ); + add_filter( 'wpml_document_view_item_link', '__return_empty_string' ); + add_filter( 'wpml_document_edit_item_link', '__return_empty_string' ); } /** @@ -65,4 +74,71 @@ public function insertNewPost($postId,$post) { } } } -} \ No newline at end of file + + /** + * Decodes editor_data to send for translation. + * + * @param array $value The value of the custom field. + * @param string $key The key of the custom field. + * @return array + */ + public function decode_custom_field( $value, $key ) { + // We only need to handle this for 'brizy' custom field. + if ( 'brizy' === $key ) { + // WPML calls this filter twice, so we need to check if it was already decoded. + if ( isset( $value['brizy-post']['editor_data'] ) && is_scalar( $value['brizy-post']['editor_data'] ) ) { + $value['brizy-post']['editor_data'] = json_decode( base64_decode( $value['brizy-post']['editor_data'], true ), true ); + } + } + return $value; + } + + /** + * Encode editor_data after its translated. + * + * @param array $value The value of the custom field. + * @param string $key The key of the custom field. + * @return array + */ + public function encode_custom_field( $value, $key ) { + // We only need to handle this for 'brizy' custom field. + if ( 'brizy' === $key ) { + // WPML calls this filter twice, so we need to check if it was already encoded. + if ( isset( $value['brizy-post']['editor_data'] ) && ! is_scalar( $value['brizy-post']['editor_data'] ) ) { + $value['brizy-post']['editor_data'] = base64_encode( json_encode( $value['brizy-post']['editor_data'] ) ); + } + } + return $value; + } + + /** + * Remove body from the translation editor because it is generated automatically. + * + * @param bool $translate Does body need to be translated. + * @param WP_Post $post The post we are translating. + * @return bool + */ + public function remove_body( $translate, $post ) { + $brizyPost = Brizy_Editor_Post::get( $post ); + if ( $brizyPost->uses_editor() ) { + $translate = false; + } + return $translate; + } + + /** + * Compile translated brizy pages. + * + * @param int $post_id The ID of the translated post. + */ + public function save_post( $post_id, $fields, $job ) { + $originalPost = Brizy_Editor_Post::get( $job->original_doc_id ); + if ( $originalPost->uses_editor() ) { + $translatedPost = Brizy_Editor_Post::get( $post_id ); + if ( ! $translatedPost->uses_editor() ) { + $translatedPost->set_uses_editor( true ); + } + $translatedPost->set_needs_compile( true ); + } + } +} diff --git a/editor/block.php b/editor/block.php index 573eb6144c..b45213fe8b 100644 --- a/editor/block.php +++ b/editor/block.php @@ -131,11 +131,12 @@ protected function populateAutoSavedData( $autosave ) { public static function getBlocksByType( $type, $arags = array() ) { $filterArgs = array( - 'post_type' => $type, - 'posts_per_page' => - 1, - 'post_status' => 'any', - 'orderby' => 'ID', - 'order' => 'ASC', + 'post_type' => $type, + 'posts_per_page' => - 1, + 'post_status' => 'any', + 'orderby' => 'ID', + 'order' => 'ASC', + 'suppress_filters' => false, ); $filterArgs = array_merge( $filterArgs, $arags ); diff --git a/wpml-config.xml b/wpml-config.xml new file mode 100644 index 0000000000..223bc86dbb --- /dev/null +++ b/wpml-config.xml @@ -0,0 +1,143 @@ + + + brizy-global-block + brizy-saved-block + brizy_template + + + brizy_post_uid + brizy-need-compile + brizy-post-plugin-version + brizy-post-editor-version + brizy-post-compiler-version + brizy + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file