Skip to content

Commit

Permalink
fix: elementor import issue
Browse files Browse the repository at this point in the history
  • Loading branch information
HeyMehedi committed Aug 22, 2024
1 parent b268a3f commit 9783087
Showing 1 changed file with 34 additions and 3 deletions.
37 changes: 34 additions & 3 deletions app/Integrations/Elementor/Compatibility.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ class Compatibility {
use Singleton;

public function __construct() {
if ( ! wp_doing_ajax() || ( defined( 'ELEMENTOR_VERSION' ) && version_compare( ELEMENTOR_VERSION, '3.0.0', '>=' ) ) ) {
remove_filter( 'templatiq_import_post_meta', [ 'Elementor\Compatibility', 'on_templatiq_import_post_meta' ] );
remove_filter( 'templatiq_wxr_importer.pre_process.post_meta', [ 'Elementor\Compatibility', 'on_wxr_importer_pre_process_post_meta' ] );

add_filter( 'templatiq_import_post_meta', [ $this, 'on_templatiq_import_post_meta' ] );
add_filter( 'templatiq_wxr_importer.pre_process.post_meta', [ $this, 'on_wxr_importer_pre_process_post_meta' ] );
}

add_action( 'templatiq_sites_before_delete_imported_posts', [$this, 'force_delete_kit'], 10, 2 );
add_action( 'templatiq_sites_before_sse_import', [$this, 'disable_attachment_metadata'] );
add_action( 'templatiq_sites_after_plugin_activation', [$this, 'disable_elementor_redirect'] );
Expand Down Expand Up @@ -68,7 +76,7 @@ public function force_delete_kit( $post_id = 0, $post_type = '' ) {
* 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.
* Fired by `templatiq_import_post_meta` filter.
*
* @since 1.4.3
* @access public
Expand All @@ -77,7 +85,7 @@ public function force_delete_kit( $post_id = 0, $post_type = '' ) {
*
* @return array Updated post meta.
*/
public function on_wp_import_post_meta( $post_meta ) {
public function on_templatiq_import_post_meta( $post_meta ) {
foreach ( $post_meta as &$meta ) {
if ( '_elementor_data' === $meta['key'] ) {
$meta['value'] = wp_slash( $meta['value'] );
Expand All @@ -94,7 +102,7 @@ public function on_wp_import_post_meta( $post_meta ) {
* 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 `templatiq_wxr_importer.pre_process.post_meta` filter.
* Fired by `templatiq_templatiq_wxr_importer.pre_process.post_meta` filter.
*
* @since 1.4.3
* @access public
Expand All @@ -110,4 +118,27 @@ public function on_templatiq_wxr_importer_pre_process_post_meta( $post_meta ) {

return $post_meta;
}

/**
* 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 `templatiq_wxr_importer.pre_process.post_meta` filter.
*
* @since 1.4.3
* @access public
*
* @param array $post_meta Post meta.
*
* @return array Updated post meta.
*/
public function on_wxr_importer_pre_process_post_meta( $post_meta ) {
if ( '_elementor_data' === $post_meta['key'] ) {
$post_meta['value'] = wp_slash( $post_meta['value'] );
}

return $post_meta;
}
}

0 comments on commit 9783087

Please sign in to comment.