$current_hash ] ); } $document = ElementorPlugin::$instance->documents->get( $post_id ); if ( ! $document ) { return new WP_Error( 'platform_mismatch', __( 'The target post is not an Elementor document.', 'templately' ) ); } $tree = array_merge( $document->get_elements_data(), $elements ); $saved = $document->save( [ 'elements' => $tree ] ); if ( ! $saved ) { return new WP_Error( 'import_failed', __( 'Failed to save Elementor content into the target post.', 'templately' ) ); } update_post_meta( $post_id, '_elementor_edit_mode', 'builder' ); self::regenerate_css( $post_id ); return [ 'target' => 'post', 'status' => 'success', 'post_id' => $post_id, ]; } /** * @param int $post_id * @return string */ public static function hash( int $post_id ): string { return md5( (string) get_post_meta( $post_id, '_elementor_data', true ) ); } private static function regenerate_css( int $post_id ): void { delete_post_meta( $post_id, '_elementor_css' ); if ( class_exists( ElementorPostCSS::class ) ) { ElementorPostCSS::create( $post_id )->update(); } } }