| 1 |
<?php |
| 2 |
/** |
| 3 |
* Gutenberg Importer |
| 4 |
* |
| 5 |
* @package CartFlows |
| 6 |
* @since 1.6.15 |
| 7 |
*/ |
| 8 |
|
| 9 |
// Exit if accessed directly. |
| 10 |
if ( ! defined( 'ABSPATH' ) ) { |
| 11 |
exit; |
| 12 |
} |
| 13 |
if ( ! class_exists( 'CartFlows_Importer_Gutenberg' ) ) : |
| 14 |
|
| 15 |
/** |
| 16 |
* CartFlows Import Gutenberg |
| 17 |
* |
| 18 |
* @since 1.6.15 |
| 19 |
*/ |
| 20 |
class CartFlows_Importer_Gutenberg { |
| 21 |
|
| 22 |
/** |
| 23 |
* Instance |
| 24 |
* |
| 25 |
* @since 1.6.15 |
| 26 |
* @access private |
| 27 |
* @var object Class object. |
| 28 |
*/ |
| 29 |
private static $instance; |
| 30 |
|
| 31 |
/** |
| 32 |
* Initiator |
| 33 |
* |
| 34 |
* @since 1.6.15 |
| 35 |
* @return object initialized object of class. |
| 36 |
*/ |
| 37 |
public static function get_instance() { |
| 38 |
|
| 39 |
if ( ! isset( self::$instance ) ) { |
| 40 |
self::$instance = new self(); |
| 41 |
} |
| 42 |
return self::$instance; |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* Constructor |
| 47 |
* |
| 48 |
* @since 1.6.15 |
| 49 |
*/ |
| 50 |
public function __construct() {} |
| 51 |
|
| 52 |
/** |
| 53 |
* Update post meta. |
| 54 |
* |
| 55 |
* @param integer $post_id Post ID. |
| 56 |
* @return void |
| 57 |
*/ |
| 58 |
public function import_single_post( $post_id = 0 ) { |
| 59 |
|
| 60 |
if ( CARTFLOWS_STEP_POST_TYPE !== get_post_type( $post_id ) ) { |
| 61 |
return; |
| 62 |
} |
| 63 |
|
| 64 |
// Download and replace images. |
| 65 |
$content = get_post_field( 'post_content', $post_id ); |
| 66 |
|
| 67 |
if ( empty( $content ) ) { |
| 68 |
wcf()->logger->import_log( '(✕) Not have "Gutenberg" Data. Post content is empty!' ); |
| 69 |
} else { |
| 70 |
|
| 71 |
wcf()->logger->import_log( '(✓) Processing Request..' ); |
| 72 |
|
| 73 |
// Update hotlink images. |
| 74 |
$content = CartFlows_Importer::get_instance()->get_content( $content ); |
| 75 |
|
| 76 |
// Update post content. |
| 77 |
wp_update_post( |
| 78 |
array( |
| 79 |
'ID' => $post_id, |
| 80 |
'post_content' => $content, |
| 81 |
) |
| 82 |
); |
| 83 |
|
| 84 |
wcf()->logger->import_log( '(✓) Process Complete' ); |
| 85 |
} |
| 86 |
} |
| 87 |
|
| 88 |
} |
| 89 |
|
| 90 |
/** |
| 91 |
* Initialize class object with 'get_instance()' method |
| 92 |
*/ |
| 93 |
CartFlows_Importer_Gutenberg::get_instance(); |
| 94 |
|
| 95 |
endif; |
| 96 |
|