); return $post_types; } /** * Polylang compatibility. * * Fix Polylang compatibility with Elementor. * * @since 2.0.0 * @access private * @static */ private static function polylang_compatibility() { // Fix language if the `get_user_locale` is difference from the `get_locale if ( isset( $_REQUEST['action'] ) && 0 === strpos( $_REQUEST['action'], 'elementor' ) ) { add_action( 'set_current_user', function() { global $current_user; $current_user->locale = get_locale(); } ); // Fix for Polylang define( 'PLL_AJAX_ON_FRONT', true ); add_action( 'pll_pre_init', function( $polylang ) { if ( isset( $_REQUEST['post'] ) ) { $post_language = $polylang->model->post->get_language( $_REQUEST['post'], 'locale' ); if ( ! empty( $post_language ) ) { $_REQUEST['lang'] = $post_language->locale; } } } ); } // Copy elementor data while polylang creates a translation copy add_filter( 'pll_copy_post_metas', [ __CLASS__, 'save_polylang_meta' ], 10, 4 ); } /** * Save polylang meta. * * Copy elementor data while polylang creates a translation copy. * * Fired by `pll_copy_post_metas` filter. * * @since 1.6.0 * @access public * @static * * @param array $keys List of custom fields names. * @param bool $sync True if it is synchronization, false if it is a copy. * @param int $from ID of the post from which we copy information. * @param int $to ID of the post to which we paste information. * * @return array List of custom fields names. */ public static function save_polylang_meta( $keys, $sync, $from, $to ) { // Copy only for a new post. if ( ! $sync ) { Plugin::$instance->db->copy_elementor_meta( $from, $to ); } return $keys; } /** * Process post meta before WP importer. * * Normalize Elementor post meta on import, We need the `wp_slash` in order * to avoid the unslashing during the `add_post_meta`. * * Fired by `wp_import_post_meta` filter. * * @since 1.0.0 * @access public * @static * * @param array $post_meta Post meta. * * @return array Updated post meta. */ public static function on_wp_import_post_meta( $post_meta ) { $is_wp_importer_before_0_7 = self::is_wp_importer_before_0_7(); if ( $is_wp_importer_before_0_7 ) { foreach ( $post_meta as &$meta ) { if ( '_elementor_data' === $meta['key'] ) { $meta['value'] = wp_slash( $meta['value'] ); break; } } } return $post_meta; } /** * Is WP Importer Before 0.7 * * Checks if WP Importer is installed, and whether its version is older than 0.7. * * @return bool */ public static function is_wp_importer_before_0_7() { $wp_importer = get_plugins( '/wordpress-importer' ); if ( ! empty( $wp_importer ) ) { $wp_importer_version = $wp_importer['wordpress-importer.php']['Version']; if ( version_compare( $wp_importer_version, '0.7', '<' ) ) { return true; } } return false; } /** * Process post meta before WXR importer. * * Normalize Elementor post meta on import with the new WP_importer, We need * the `wp_slash` in order to avoid the unslashing during the `add_post_meta`. * * Fired by `wxr_importer.pre_process.post_meta` filter. * * @since 1.0.0 * @access public * @static * * @param array $post_meta Post meta. * * @return array Updated post meta. */ public static function on_wxr_importer_pre_process_post_meta( $post_meta ) { $is_wp_importer_before_0_7 = self::is_wp_importer_before_0_7(); if ( $is_wp_importer_before_0_7 ) { if ( '_elementor_data' === $post_meta['key'] ) { $post_meta['value'] = wp_slash( $post_meta['value'] ); } } return $post_meta; } }