Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add - Support for MagazineX Pro theme. #88

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
115 changes: 111 additions & 4 deletions includes/class-demo-importer.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ private function get_demo_packages() {
$template = strtolower( str_replace( '-pro', '', get_option( 'template' ) ) );

if ( false === $packages || ( isset( $packages->slug ) && $template !== $packages->slug ) ) {
$raw_packages = wp_safe_remote_get( "https://d1sb0nhp4t2db4.cloudfront.net/configs/{$template}.json" );
$raw_packages = wp_safe_remote_get( "https://raw.githubusercontent.com/themegrill/themegrill-demo-pack/magazinex/configs/magazinex.json" );

if ( ! is_wp_error( $raw_packages ) ) {
$packages = json_decode( wp_remote_retrieve_body( $raw_packages ) );
Expand Down Expand Up @@ -351,6 +351,16 @@ public function zakra_is_premium_theme_plan() {

}

public function magazinex_is_premium_theme_plan() {

if ( is_plugin_active( 'magazinex-pro/magazinex-pro.php' ) && is_plugin_active( 'magazine-blocks-pro/magazine-blocks-pro.php' ) ) {
return true;
}

return false;

}

/**
* Check for ThemeGrill All Themes Plan
*
Expand Down Expand Up @@ -382,6 +392,10 @@ public function ajax_query_demos( $return = true ) {
$zakra_pro_plugin_version = is_plugin_active( 'zakra-pro/zakra-pro.php' ) ? ZAKRA_PRO_VERSION : false;
$companion_elementor_plugin_name = is_plugin_active( 'companion-elementor/companion-elementor.php' ) ? COMPANION_ELEMENTOR_VERSION : false;

// Condition for MagazineX Pro.
$magazinex_pro_plugin_version = is_plugin_active( 'magazinex-pro/magazinex-pro.php' ) ? MAGAZINEX_PRO_VERSION : false;
$magazine_blocks_plugin_name = is_plugin_active( 'magazine-blocks-pro/magazine-blocks-pro.php' ) ? MAGAZINE_BLOCKS_VERSION : false;

// Condition if child theme is being used.
if ( is_child_theme() ) {
$current_theme_name = wp_get_theme()->parent()->get( 'Name' );
Expand Down Expand Up @@ -417,7 +431,7 @@ public function ajax_query_demos( $return = true ) {
if ( isset( $available_packages->demos ) ) {
foreach ( $available_packages->demos as $package_slug => $package_data ) {
$plugins_list = isset( $package_data->plugins_list ) ? $package_data->plugins_list : array();
$screenshot_url = "https://d1sb0nhp4t2db4.cloudfront.net/resources/{$available_packages->slug}/{$package_slug}/screenshot.jpg";
$screenshot_url = "https://raw.githubusercontent.com/themegrill/themegrill-demo-pack/magazinex/resources/{$available_packages->slug}/{$package_slug}/screenshot.jpg";

if ( isset( $request['browse'], $package_data->category ) && ! in_array( $request['browse'], $package_data->category, true ) ) {
continue;
Expand Down Expand Up @@ -447,6 +461,9 @@ public function ajax_query_demos( $return = true ) {
$required_version = false;
$zakra_pro_required_version = false;
$companion_elementor_required_version = false;
$magazinex_pro_required_version = false;
$magazine_blocks_pro_required_version = false;

if ( isset( $package_data->minimum_version ) && is_object( $package_data->minimum_version ) ) {
foreach ( $package_data->minimum_version as $theme => $minimum_version ) {
if ( 'zakra' === $current_template ) {
Expand All @@ -469,6 +486,26 @@ public function ajax_query_demos( $return = true ) {
$companion_elementor_required_version = $minimum_version;
}
}
} elseif ( 'magazinex' === $current_template ) {
if (
version_compare( $minimum_version, $current_theme_version, '>' ) ||
( 'magazinex-pro' === $theme && version_compare( $minimum_version, $magazinex_pro_plugin_version, '>' ) ) ||
( 'magazine-blocks-pro' === $theme && version_compare( $minimum_version, $magazine_blocks_plugin_name, '>' ) )
) {
$required_version_installed = true;

if ( 'magazinex' === $theme ) {
$required_version = $minimum_version;
}

if ( 'magazinex-pro' === $theme ) {
$magazinex_pro_required_version = $minimum_version;
}

if ( 'magazine-blocks-pro' === $theme ) {
$magazine_blocks_pro_required_version = $minimum_version;
}
}
} else {
if (
$current_template === $theme && version_compare( $minimum_version, $current_theme_version, '>' ) ||
Expand Down Expand Up @@ -560,6 +597,76 @@ public function ajax_query_demos( $return = true ) {
esc_html__( 'Companion Elementor', 'themegrill-demo-importer' )
);
}
} else if ( 'magazinex' === $current_template ) {
if ( $required_version ) {
$required_message = sprintf( esc_html__( 'This demo requires %1$s version of %2$s theme to get imported', 'themegrill-demo-importer' ), $required_version, $current_theme_name );
}

if ( $magazinex_pro_required_version ) {
if ( $required_version && $magazine_blocks_pro_required_version ) {
$required_message = sprintf(
esc_html__( 'This demo requires %1$s version of %2$s theme and %3$s version of %4$s as well as %5$s version of %6$s plugins to get imported', 'themegrill-demo-importer' ),
$required_version,
$current_theme_name,
$magazinex_pro_required_version,
esc_html__( 'MagazineX Pro', 'themegrill-demo-importer' ),
$magazine_blocks_pro_required_version,
esc_html__( 'Magazine Blocks Pro', 'themegrill-demo-importer' )
);
} elseif ( $required_version ) {
$required_message = sprintf(
esc_html__( 'This demo requires %1$s version of %2$s theme and %3$s version of %4$s plugin to get imported', 'themegrill-demo-importer' ),
$required_version,
$current_theme_name,
$magazinex_pro_required_version,
esc_html__( 'MagazineX Pro', 'themegrill-demo-importer' )
);
} else {
$required_message = sprintf(
esc_html__( 'This demo requires %1$s version of %2$s plugin to get imported', 'themegrill-demo-importer' ),
$magazinex_pro_required_version,
esc_html__( 'MagazineX', 'themegrill-demo-importer' )
);
}
}

if ( $magazine_blocks_pro_required_version ) {
if ( $required_version && $magazinex_pro_required_version ) {
$required_message = sprintf(
esc_html__( 'This demo requires %1$s version of %2$s theme and %3$s version of %4$s as well as %5$s version of %6$s plugins to get imported', 'themegrill-demo-importer' ),
$required_version,
$current_theme_name,
$magazinex_pro_required_version,
esc_html__( 'MagazineX Pro', 'themegrill-demo-importer' ),
$magazine_blocks_pro_required_version,
esc_html__( 'Magazine Blocks', 'themegrill-demo-importer' )
);
} elseif ( $required_version ) {
$required_message = sprintf(
esc_html__( 'This demo requires %1$s version of %2$s theme and %3$s version of %4$s plugin to get imported', 'themegrill-demo-importer' ),
$required_version,
$current_theme_name,
$magazine_blocks_pro_required_version,
esc_html__( 'Magazine Blocks Pro', 'themegrill-demo-importer' )
);
} else {
$required_message = sprintf(
esc_html__( 'This demo requires %1$s version of %2$s plugin to get imported', 'themegrill-demo-importer' ),
$magazine_blocks_pro_required_version,
esc_html__( 'Magazine Blocks Pro', 'themegrill-demo-importer' )
);
}
}

if ( ! $required_version && ( $magazinex_pro_required_version && $magazine_blocks_pro_required_version ) ) {
$required_message = sprintf(
esc_html__( 'This demo requires %1$s version of %2$s as well as %3$s version of %4$s plugins to get imported', 'themegrill-demo-importer' ),
$magazinex_pro_required_version,
esc_html__( 'MagazineX Pro', 'themegrill-demo-importer' ),
$magazine_blocks_pro_required_version,
esc_html__( 'Magazine Blocks Pro', 'themegrill-demo-importer' )
);
}
} else {
if ( $required_version ) {
$required_message = sprintf(
Expand Down Expand Up @@ -594,7 +701,7 @@ public function ajax_query_demos( $return = true ) {
'name' => $package_data->title,
'theme' => $is_pro_theme_demo ? sprintf( esc_html__( '%s Pro', 'themegrill-demo-importer' ), $available_packages->name ) : $available_packages->name,
'isPro' => $is_pro_theme_demo ? false : isset( $package_data->isPro ),
'isPremium' => $this->zakra_is_premium_theme_plan() ? false : isset( $package_data->isPremium ),
'isPremium' => $this->magazinex_is_premium_theme_plan() || $this->zakra_is_premium_theme_plan() ? false : isset( $package_data->isPremium ),
'isAllThemePlan' => $this->themegrill_is_all_themes_plan() ? false : isset( $package_data->isAllThemePlan ),
'active' => $package_slug === $demo_activated_id,
'author' => isset( $package_data->author ) ? $package_data->author : __( 'ThemeGrill', 'themegrill-demo-importer' ),
Expand Down Expand Up @@ -684,7 +791,7 @@ public function ajax_import_demo() {
$upgrader = new TG_Demo_Pack_Upgrader( $skin );
$template = strtolower( str_replace( '-pro', '', get_option( 'template' ) ) );
$packages = isset( $this->demo_packages->demos ) ? json_decode( wp_json_encode( $this->demo_packages->demos ), true ) : array();
$result = $upgrader->install( "https://d1sb0nhp4t2db4.cloudfront.net/packages/{$template}/{$slug}.zip" );
$result = $upgrader->install( "https://raw.githubusercontent.com/themegrill/themegrill-demo-pack/magazinex/packages/{$template}/{$slug}.zip" );

if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
$status['debug'] = $skin->get_upgrade_messages();
Expand Down