| 1 |
<?php |
| 2 |
/** |
| 3 |
* Divi 5 template source / importer. |
| 4 |
* |
| 5 |
* Divi 5 stores page content as JSON blocks (WordPress block grammar) rather |
| 6 |
* than shortcode strings. This class handles importing templates in that |
| 7 |
* format and falls back to the plain-string path used by the D4 importer. |
| 8 |
* |
| 9 |
* @package WPFunnels\Batch\DiviV5 |
| 10 |
* @since 2.9.1 |
| 11 |
*/ |
| 12 |
|
| 13 |
namespace WPFunnels\Batch\DiviV5; |
| 14 |
|
| 15 |
if ( ! defined( 'ABSPATH' ) ) { |
| 16 |
die( 'Direct access forbidden.' ); |
| 17 |
} |
| 18 |
|
| 19 |
class Wpfnl_Divi5_Source { |
| 20 |
|
| 21 |
/** |
| 22 |
* Import a single Divi 5 template into a step post. |
| 23 |
* |
| 24 |
* @param int $step_id The wpfunnel_steps post ID to update. |
| 25 |
* @param string|array $content Raw template content (JSON string or decoded array). |
| 26 |
*/ |
| 27 |
public function import_single_template( int $step_id, $content ): void { |
| 28 |
// Decode if JSON string |
| 29 |
if ( is_string( $content ) ) { |
| 30 |
$decoded = json_decode( $content, true ); |
| 31 |
if ( json_last_error() === JSON_ERROR_NONE && is_array( $decoded ) ) { |
| 32 |
$content = $decoded; |
| 33 |
} |
| 34 |
} |
| 35 |
|
| 36 |
// Re-encode arrays back to JSON for storage |
| 37 |
$post_content = is_array( $content ) |
| 38 |
? wp_json_encode( $content ) |
| 39 |
: (string) $content; |
| 40 |
|
| 41 |
wp_update_post( |
| 42 |
[ |
| 43 |
'ID' => $step_id, |
| 44 |
'post_content' => $post_content, |
| 45 |
] |
| 46 |
); |
| 47 |
|
| 48 |
// Clean up temp meta keys |
| 49 |
delete_post_meta( $step_id, 'divi5_content' ); |
| 50 |
delete_post_meta( $step_id, 'divi_content' ); |
| 51 |
} |
| 52 |
} |
| 53 |
|