| 1 |
<?php |
| 2 |
/** |
| 3 |
* Divi Importer |
| 4 |
* |
| 5 |
* @package CartFlows |
| 6 |
* @since 1.1.1 |
| 7 |
*/ |
| 8 |
|
| 9 |
// Exit if accessed directly. |
| 10 |
if ( ! defined( 'ABSPATH' ) ) { |
| 11 |
exit; |
| 12 |
} |
| 13 |
if ( ! class_exists( 'CartFlows_Importer_Divi' ) ) : |
| 14 |
|
| 15 |
/** |
| 16 |
* CartFlows Import Divi |
| 17 |
* |
| 18 |
* @since 1.1.1 |
| 19 |
*/ |
| 20 |
class CartFlows_Importer_Divi { |
| 21 |
|
| 22 |
/** |
| 23 |
* Instance |
| 24 |
* |
| 25 |
* @since 1.1.1 |
| 26 |
* @access private |
| 27 |
* @var object Class object. |
| 28 |
*/ |
| 29 |
private static $instance; |
| 30 |
|
| 31 |
/** |
| 32 |
* Initiator |
| 33 |
* |
| 34 |
* @since 1.1.1 |
| 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.1.1 |
| 49 |
*/ |
| 50 |
public function __construct() {} |
| 51 |
|
| 52 |
/** |
| 53 |
* Allowed tags for the batch update process |
| 54 |
* |
| 55 |
* @since 1.6.15 |
| 56 |
* |
| 57 |
* @param array $allowedposttags Array of default allowable HTML tags. |
| 58 |
* @param string|array $context The context for which to retrieve tags. Allowed values are 'post', |
| 59 |
* 'strip', 'data', 'entities', or the name of a field filter such as |
| 60 |
* 'pre_user_description'. |
| 61 |
* @return array Array of allowed HTML tags and their allowed attributes. |
| 62 |
*/ |
| 63 |
public function allowed_tags_and_attributes( $allowedposttags, $context ) { |
| 64 |
|
| 65 |
// Keep only for 'post' contenxt. |
| 66 |
if ( 'post' === $context ) { |
| 67 |
|
| 68 |
// <style> tag and attributes. |
| 69 |
$allowedposttags['style'] = array(); |
| 70 |
} |
| 71 |
|
| 72 |
return $allowedposttags; |
| 73 |
} |
| 74 |
|
| 75 |
/** |
| 76 |
* Update post meta. |
| 77 |
* |
| 78 |
* @param integer $post_id Post ID. |
| 79 |
* @return void |
| 80 |
*/ |
| 81 |
public function import_single_post( $post_id = 0 ) { |
| 82 |
|
| 83 |
if ( CARTFLOWS_STEP_POST_TYPE !== get_post_type( $post_id ) ) { |
| 84 |
return; |
| 85 |
} |
| 86 |
|
| 87 |
// Allow the SVG tags in batch update process. |
| 88 |
add_filter( 'wp_kses_allowed_html', array( $this, 'allowed_tags_and_attributes' ), 10, 2 ); |
| 89 |
|
| 90 |
// Download and replace images. |
| 91 |
$content = get_post_meta( $post_id, 'divi_content', true ); |
| 92 |
|
| 93 |
if ( empty( $content ) ) { |
| 94 |
wcf()->logger->import_log( '(✕) Not have "Divi" Data. Post content is empty!' ); |
| 95 |
} else { |
| 96 |
|
| 97 |
wcf()->logger->import_log( '(✓) Processing Request..' ); |
| 98 |
|
| 99 |
// Update hotlink images. |
| 100 |
$content = CartFlows_Importer::get_instance()->get_content( $content ); |
| 101 |
|
| 102 |
// Update post content. |
| 103 |
wp_update_post( |
| 104 |
array( |
| 105 |
'ID' => $post_id, |
| 106 |
'post_content' => $content, |
| 107 |
) |
| 108 |
); |
| 109 |
|
| 110 |
// Delete temporary meta key. |
| 111 |
delete_post_meta( $post_id, 'divi_content' ); |
| 112 |
|
| 113 |
wcf()->logger->import_log( '(✓) Process Complete' ); |
| 114 |
} |
| 115 |
} |
| 116 |
|
| 117 |
} |
| 118 |
|
| 119 |
/** |
| 120 |
* Initialize class object with 'get_instance()' method |
| 121 |
*/ |
| 122 |
CartFlows_Importer_Divi::get_instance(); |
| 123 |
|
| 124 |
endif; |
| 125 |
|