Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions assets/src/Components/ImportModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,7 @@ const ImportModal = ( {
source: 'remote',
frontPage: importData.front_page,
shopPages: importData.shop_pages,
paymentForms: importData.payment_forms,
demoSlug: importData.slug,
editor,
} )
Expand Down
14 changes: 7 additions & 7 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 16 additions & 14 deletions includes/Importers/Cleanup/Active_State.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,21 @@
*/
class Active_State {

const STATE_NAME = 'neve_last_imports';
const HOUR_IN_SECONDS = 3600;
const PLUGINS_NSP = 'plugins';
const CATEGORY_NSP = 'category';
const TAGS_NSP = 'tags';
const TERMS_NSP = 'terms';
const POSTS_NSP = 'posts';
const COMMENTS_NSP = 'comments';
const ATTACHMENT_NSP = 'attachment';
const FRONT_PAGE_NSP = 'front_page_options';
const SHOP_PAGE_NSP = 'shop_page_options';
const THEME_MODS_NSP = 'theme_mods';
const MENUS_NSP = 'menus';
const WIDGETS_NSP = 'widgets';
const STATE_NAME = 'neve_last_imports';
const HOUR_IN_SECONDS = 3600;
const PLUGINS_NSP = 'plugins';
const CATEGORY_NSP = 'category';
const TAGS_NSP = 'tags';
const TERMS_NSP = 'terms';
const POSTS_NSP = 'posts';
const COMMENTS_NSP = 'comments';
const ATTACHMENT_NSP = 'attachment';
const FRONT_PAGE_NSP = 'front_page_options';
const SHOP_PAGE_NSP = 'shop_page_options';
const PAYMENT_FORM_NSP = 'payment_form_options';
const THEME_MODS_NSP = 'theme_mods';
const MENUS_NSP = 'menus';
const WIDGETS_NSP = 'widgets';
/**
* @var array $state
*/
Expand Down Expand Up @@ -64,6 +65,7 @@ private function is_allowed_property( $property_key ) {
self::WIDGETS_NSP,
self::FRONT_PAGE_NSP,
self::SHOP_PAGE_NSP,
self::PAYMENT_FORM_NSP,
),
true
);
Expand Down
39 changes: 39 additions & 0 deletions includes/Importers/Cleanup/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,44 @@ private function cleanup_options( $namespace, $state ) {
}
}

/**
* Handles form cleanup.
* @param array $state The cleanup state.
*/
private function cleanup_forms( $namespace, $state ) {
if ( ! class_exists( 'MM_WPFS_Database' ) ) {
return;
}

$db = new \MM_WPFS_Database();

if ( isset( $state[ $namespace ] ) ) {
foreach ( $state[ $namespace ] as $name => $form ) {
$get = 'get' . ucfirst( $form['layout'] ) . ucfirst( $form['type'] ) . 'FormByName';
$method = 'delete' . ucfirst( $form['layout'] ) . ucfirst( $form['type'] ) . 'Form';
$id = null;

if ( method_exists( 'MM_WPFS_Database', $get ) ) {
$item = $db->$get( $name );
foreach ( $item as $key => $value ) {
if ( strpos( $key, 'FormID' ) !== false ) {
$id = $value;
break;
}
}
}

if ( empty( $id ) ) {
continue;
}

if ( method_exists( 'MM_WPFS_Database', $method ) ) {
$db->$method( $id );
}
}
}
}

final public function do_cleanup() {
$active_state = new Active_State();
$state = $active_state->get();
Expand All @@ -250,6 +288,7 @@ final public function do_cleanup() {
$this->cleanup_terms( $state );
$this->cleanup_options( Active_State::FRONT_PAGE_NSP, $state );
$this->cleanup_options( Active_State::SHOP_PAGE_NSP, $state );
$this->cleanup_forms( Active_State::PAYMENT_FORM_NSP, $state );
$this->cleanup_posts( $state );
$this->cleanup_attachments( $state );
$this->cleanup_widgets( $state );
Expand Down
62 changes: 62 additions & 0 deletions includes/Importers/Content_Importer.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@ public function import_remote_xml( WP_REST_Request $request ) {
}
do_action( 'themeisle_ob_after_shop_pages_setup' );

// Set payment forms.
if ( isset( $body['paymentForms'] ) ) {
$this->setup_payment_forms( $body['paymentForms'] );
}
do_action( 'themeisle_ob_after_payment_forms_setup' );

if ( empty( $frontpage_id ) ) {
$this->logger->log( 'No front page ID.' );
}
Expand Down Expand Up @@ -265,6 +271,62 @@ public function setup_shop_pages( $pages, $demo_slug ) {
$this->logger->log( 'Shop pages set up.', 'success' );
}

public function setup_payment_forms( $forms ) {
$this->logger->log( 'Setting up payment forms.', 'progress' );
if ( ! class_exists( 'MM_WPFS_Database' ) ) {
$this->logger->log( 'No WP Full Stripe.', 'success' );
return;
}

if ( ! is_array( $forms ) ) {
$this->logger->log( 'No Payment Forms.', 'success' );
return;
}

$db = new \MM_WPFS_Database();

$payment_form_options = array();
foreach ( $forms as $key => $form ) {
if ( ! in_array( $form['type'], array( 'payment', 'subscription', 'donation' ) ) || ! in_array( $form['layout'], array( 'inline', 'checkout' ) ) ) {
continue;
}

$check = 'get' . ucfirst( $form['layout'] ) . ucfirst( $form['type'] ) . 'FormByName';
$insert = 'insert' . ucfirst( $form['layout'] ) . ucfirst( $form['type'] ) . 'Form';

if ( method_exists( $db, $check ) ) {
$existing_form = $db->$check( $form['name'] );
if ( $existing_form ) {
$this->logger->log( "Form {$form['name']} already exists.", 'success' );
continue;
}
}

if ( method_exists( $db, $insert ) ) {
$form['data'] = array_filter(
$form['data'],
function ( $key ) {
return strpos( $key, 'FormID' ) === false;
},
ARRAY_FILTER_USE_KEY
);

$db->$insert( $form['data'] );

$payment_form_options[ $form['data']['name'] ] = array(
'layout' => $form['layout'],
'type' => $form['type'],
);
} else {
$this->logger->log( "Method {$insert} does not exist.", 'error' );
}
}

do_action( 'themeisle_cl_add_property_state', Active_State::PAYMENT_FORM_NSP, $payment_form_options );

$this->logger->log( 'Payment forms set up.', 'success' );
}

/**
* Maybe bust cache for elementor plugin.
*/
Expand Down
1 change: 1 addition & 0 deletions includes/Importers/Plugin_Importer.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class Plugin_Importer {
'recipe-card-blocks-by-wpzoom' => 'wpzoom-recipe-card.php',
'restrict-content' => 'restrictcontent.php',
'pods' => 'init.php',
'wp-full-stripe-free' => 'wp-full-stripe.php',
);

public function __construct() {
Expand Down
1 change: 1 addition & 0 deletions onboarding/src/Components/Steps/Import.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ const Import = ( {
source: 'remote',
frontPage: importData.front_page,
shopPages: importData.shop_pages,
paymentForms: importData.payment_forms,
demoSlug: importData.slug,
editor,
} )
Expand Down
Loading