updated plugin GP Premium
version 2.1.1
This commit is contained in:
384
wp-content/plugins/gp-premium/inc/class-dashboard.php
Normal file
384
wp-content/plugins/gp-premium/inc/class-dashboard.php
Normal file
@ -0,0 +1,384 @@
|
||||
<?php
|
||||
/**
|
||||
* Build our admin dashboard.
|
||||
*
|
||||
* @package GeneratePress Premium
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
/**
|
||||
* This class adds premium sections to our Dashboard.
|
||||
*/
|
||||
class GeneratePress_Pro_Dashboard {
|
||||
/**
|
||||
* Class instance.
|
||||
*
|
||||
* @access private
|
||||
* @var $instance Class instance.
|
||||
*/
|
||||
private static $instance;
|
||||
|
||||
/**
|
||||
* Initiator
|
||||
*/
|
||||
public static function get_instance() {
|
||||
if ( ! isset( self::$instance ) ) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get started.
|
||||
*/
|
||||
public function __construct() {
|
||||
add_action( 'after_setup_theme', array( $this, 'setup' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add our actions and require old Dashboard files if we need them.
|
||||
*/
|
||||
public function setup() {
|
||||
// Load our old dashboard if we're using an old version of GeneratePress.
|
||||
if ( ! class_exists( 'GeneratePress_Dashboard' ) ) {
|
||||
if ( is_admin() ) {
|
||||
require_once GP_PREMIUM_DIR_PATH . 'inc/legacy/dashboard.php';
|
||||
require_once GP_PREMIUM_DIR_PATH . 'inc/legacy/import-export.php';
|
||||
require_once GP_PREMIUM_DIR_PATH . 'inc/legacy/reset.php';
|
||||
require_once GP_PREMIUM_DIR_PATH . 'inc/legacy/activation.php';
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
|
||||
add_action( 'generate_admin_dashboard', array( $this, 'module_list' ), 8 );
|
||||
add_action( 'generate_admin_dashboard', array( $this, 'license_key' ), 5 );
|
||||
add_action( 'generate_admin_dashboard', array( $this, 'import_export' ), 50 );
|
||||
add_action( 'generate_admin_dashboard', array( $this, 'reset' ), 100 );
|
||||
add_filter( 'generate_premium_beta_tester', array( $this, 'set_beta_tester' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get data for all of our pro modules.
|
||||
*/
|
||||
public static function get_modules() {
|
||||
$modules = array(
|
||||
'Backgrounds' => array(
|
||||
'title' => __( 'Backgrounds', 'gp-premium' ),
|
||||
'description' => __( 'Set background images for various HTML elements.', 'gp-premium' ),
|
||||
'key' => 'generate_package_backgrounds',
|
||||
'settings' => 'generate_background_settings',
|
||||
'isActive' => 'activated' === get_option( 'generate_package_backgrounds', false ),
|
||||
'exportable' => true,
|
||||
),
|
||||
'Blog' => array(
|
||||
'title' => __( 'Blog', 'gp-premium' ),
|
||||
'description' => __( 'Set blog options like infinite scroll, masonry layouts and more.', 'gp-premium' ),
|
||||
'key' => 'generate_package_blog',
|
||||
'settings' => 'generate_blog_settings',
|
||||
'isActive' => 'activated' === get_option( 'generate_package_blog', false ),
|
||||
'exportable' => true,
|
||||
),
|
||||
'Colors' => array(
|
||||
'title' => __( 'Colors', 'gp-premium' ),
|
||||
'key' => 'generate_package_colors',
|
||||
'isActive' => 'activated' === get_option( 'generate_package_colors', false ),
|
||||
),
|
||||
'Copyright' => array(
|
||||
'title' => __( 'Copyright', 'gp-premium' ),
|
||||
'description' => __( 'Set a custom copyright message in your footer.', 'gp-premium' ),
|
||||
'key' => 'generate_package_copyright',
|
||||
'settings' => 'copyright',
|
||||
'isActive' => 'activated' === get_option( 'generate_package_copyright', false ),
|
||||
'exportable' => true,
|
||||
),
|
||||
'Disable Elements' => array(
|
||||
'title' => __( 'Disable Elements', 'gp-premium' ),
|
||||
'description' => __( 'Disable default theme elements on specific pages or inside a Layout Element.', 'gp-premium' ),
|
||||
'key' => 'generate_package_disable_elements',
|
||||
'isActive' => 'activated' === get_option( 'generate_package_disable_elements', false ),
|
||||
),
|
||||
'Elements' => array(
|
||||
'title' => __( 'Elements', 'gp-premium' ),
|
||||
'description' => __( 'Use our block editor theme builder, build advanced HTML hooks, and gain more Layout control.', 'gp-premium' ),
|
||||
'key' => 'generate_package_elements',
|
||||
'isActive' => 'activated' === get_option( 'generate_package_elements', false ),
|
||||
),
|
||||
'Hooks' => array(
|
||||
'title' => __( 'Hooks', 'gp-premium' ),
|
||||
'description' => __( 'This module has been deprecated. Please use Elements instead.', 'gp-premium' ),
|
||||
'key' => 'generate_package_hooks',
|
||||
'settings' => 'generate_hooks',
|
||||
'isActive' => 'activated' === get_option( 'generate_package_hooks', false ),
|
||||
'exportable' => true,
|
||||
),
|
||||
'Menu Plus' => array(
|
||||
'title' => __( 'Menu Plus', 'gp-premium' ),
|
||||
'description' => __( 'Set up a mobile header, sticky navigation or off-canvas panel.', 'gp-premium' ),
|
||||
'key' => 'generate_package_menu_plus',
|
||||
'settings' => 'generate_menu_plus_settings',
|
||||
'isActive' => 'activated' === get_option( 'generate_package_menu_plus', false ),
|
||||
'exportable' => true,
|
||||
),
|
||||
'Page Header' => array(
|
||||
'title' => __( 'Page Header', 'gp-premium' ),
|
||||
'description' => __( 'This module has been deprecated. Please use Elements instead.', 'gp-premium' ),
|
||||
'key' => 'generate_package_page_header',
|
||||
'settings' => 'generate_page_header_settings',
|
||||
'isActive' => 'activated' === get_option( 'generate_package_page_header', false ),
|
||||
'exportable' => true,
|
||||
),
|
||||
'Secondary Nav' => array(
|
||||
'title' => __( 'Secondary Nav', 'gp-premium' ),
|
||||
'description' => __( 'Add a fully-featured secondary navigation to your site.', 'gp-premium' ),
|
||||
'key' => 'generate_package_secondary_nav',
|
||||
'settings' => 'generate_secondary_nav_settings',
|
||||
'isActive' => 'activated' === get_option( 'generate_package_secondary_nav', false ),
|
||||
'exportable' => true,
|
||||
),
|
||||
'Sections' => array(
|
||||
'title' => __( 'Sections', 'gp-premium' ),
|
||||
'description' => __( 'This module has been deprecated. Please consider using our GenerateBlocks plugin instead.', 'gp-premium' ),
|
||||
'key' => 'generate_package_sections',
|
||||
'isActive' => 'activated' === get_option( 'generate_package_sections', false ),
|
||||
),
|
||||
'Spacing' => array(
|
||||
'title' => __( 'Spacing', 'gp-premium' ),
|
||||
'description' => __( 'Set the padding and overall spacing of your theme elements.', 'gp-premium' ),
|
||||
'key' => 'generate_package_spacing',
|
||||
'settings' => 'generate_spacing_settings',
|
||||
'isActive' => 'activated' === get_option( 'generate_package_spacing', false ),
|
||||
'exportable' => true,
|
||||
),
|
||||
'Typography' => array(
|
||||
'title' => __( 'Typography', 'gp-premium' ),
|
||||
'description' => __( 'This module has been deprecated. Switch to our dynamic typography system in Customize > General instead.', 'gp-premium' ),
|
||||
'key' => 'generate_package_typography',
|
||||
'isActive' => 'activated' === get_option( 'generate_package_typography', false ),
|
||||
),
|
||||
'WooCommerce' => array(
|
||||
'title' => __( 'WooCommerce', 'gp-premium' ),
|
||||
'description' => __( 'Add colors, typography, and layout options to your WooCommerce store.', 'gp-premium' ),
|
||||
'key' => 'generate_package_woocommerce',
|
||||
'settings' => 'generate_woocommerce_settings',
|
||||
'isActive' => 'activated' === get_option( 'generate_package_woocommerce', false ),
|
||||
'exportable' => true,
|
||||
),
|
||||
);
|
||||
|
||||
if ( version_compare( PHP_VERSION, '5.4', '>=' ) && ! defined( 'GENERATE_DISABLE_SITE_LIBRARY' ) ) {
|
||||
$modules['Site Library'] = array(
|
||||
'title' => __( 'Site Library', 'gp-premium' ),
|
||||
'description' => __( 'Choose from an extensive library of professionally designed starter sites.', 'gp-premium' ),
|
||||
'key' => 'generate_package_site_library',
|
||||
'isActive' => 'activated' === get_option( 'generate_package_site_library', false ),
|
||||
);
|
||||
}
|
||||
|
||||
if ( function_exists( 'generate_is_using_dynamic_typography' ) && generate_is_using_dynamic_typography() ) {
|
||||
unset( $modules['Typography'] );
|
||||
}
|
||||
|
||||
if ( version_compare( generate_premium_get_theme_version(), '3.1.0-alpha.1', '>=' ) ) {
|
||||
unset( $modules['Colors'] );
|
||||
}
|
||||
|
||||
$deprecated_modules = apply_filters(
|
||||
'generate_premium_deprecated_modules',
|
||||
array(
|
||||
'Page Header',
|
||||
'Hooks',
|
||||
'Sections',
|
||||
)
|
||||
);
|
||||
|
||||
foreach ( $deprecated_modules as $deprecated_module ) {
|
||||
if ( isset( $modules[ $deprecated_module ] ) ) {
|
||||
$modules[ $deprecated_module ]['deprecated'] = true;
|
||||
}
|
||||
}
|
||||
|
||||
ksort( $modules );
|
||||
|
||||
return $modules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get modules that can have their settings exported and imported.
|
||||
*/
|
||||
public static function get_exportable_modules() {
|
||||
$modules = array(
|
||||
'Core' => array(
|
||||
'settings' => 'generate_settings',
|
||||
'title' => __( 'Core', 'gp-premium' ),
|
||||
'isActive' => true,
|
||||
),
|
||||
);
|
||||
|
||||
foreach ( self::get_modules() as $key => $data ) {
|
||||
if ( ! empty( $data['exportable'] ) && $data['isActive'] ) {
|
||||
$modules[ $key ] = $data;
|
||||
}
|
||||
}
|
||||
|
||||
return $modules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get options using theme_mods.
|
||||
*/
|
||||
public static function get_theme_mods() {
|
||||
$theme_mods = array(
|
||||
'font_body_variants',
|
||||
'font_body_category',
|
||||
'font_site_title_variants',
|
||||
'font_site_title_category',
|
||||
'font_site_tagline_variants',
|
||||
'font_site_tagline_category',
|
||||
'font_navigation_variants',
|
||||
'font_navigation_category',
|
||||
'font_secondary_navigation_variants',
|
||||
'font_secondary_navigation_category',
|
||||
'font_buttons_variants',
|
||||
'font_buttons_category',
|
||||
'font_heading_1_variants',
|
||||
'font_heading_1_category',
|
||||
'font_heading_2_variants',
|
||||
'font_heading_2_category',
|
||||
'font_heading_3_variants',
|
||||
'font_heading_3_category',
|
||||
'font_heading_4_variants',
|
||||
'font_heading_4_category',
|
||||
'font_heading_5_variants',
|
||||
'font_heading_5_category',
|
||||
'font_heading_6_variants',
|
||||
'font_heading_6_category',
|
||||
'font_widget_title_variants',
|
||||
'font_widget_title_category',
|
||||
'font_footer_variants',
|
||||
'font_footer_category',
|
||||
'generate_copyright',
|
||||
);
|
||||
|
||||
if ( function_exists( 'generate_is_using_dynamic_typography' ) && generate_is_using_dynamic_typography() ) {
|
||||
$theme_mods = array(
|
||||
'generate_copyright',
|
||||
);
|
||||
}
|
||||
|
||||
return $theme_mods;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get our setting keys.
|
||||
*/
|
||||
public static function get_setting_keys() {
|
||||
return array(
|
||||
'generate_settings',
|
||||
'generate_background_settings',
|
||||
'generate_blog_settings',
|
||||
'generate_hooks',
|
||||
'generate_page_header_settings',
|
||||
'generate_secondary_nav_settings',
|
||||
'generate_spacing_settings',
|
||||
'generate_menu_plus_settings',
|
||||
'generate_woocommerce_settings',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add our scripts to the page.
|
||||
*/
|
||||
public function enqueue_scripts() {
|
||||
if ( ! class_exists( 'GeneratePress_Dashboard' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$dashboard_pages = GeneratePress_Dashboard::get_pages();
|
||||
$current_screen = get_current_screen();
|
||||
|
||||
if ( in_array( $current_screen->id, $dashboard_pages ) ) {
|
||||
wp_enqueue_style(
|
||||
'generate-pro-dashboard',
|
||||
GP_PREMIUM_DIR_URL . '/dist/style-dashboard.css',
|
||||
array( 'wp-components' ),
|
||||
GP_PREMIUM_VERSION
|
||||
);
|
||||
|
||||
if ( 'appearance_page_generate-options' === $current_screen->id ) {
|
||||
wp_enqueue_script(
|
||||
'generate-pro-dashboard',
|
||||
GP_PREMIUM_DIR_URL . '/dist/dashboard.js',
|
||||
array(),
|
||||
GP_PREMIUM_VERSION,
|
||||
true
|
||||
);
|
||||
|
||||
wp_set_script_translations( 'generate-pro-dashboard', 'gp-premium', GP_PREMIUM_DIR_PATH . 'langs' );
|
||||
|
||||
wp_localize_script(
|
||||
'generate-pro-dashboard',
|
||||
'generateProDashboard',
|
||||
array(
|
||||
'modules' => self::get_modules(),
|
||||
'exportableModules' => self::get_exportable_modules(),
|
||||
'siteLibraryUrl' => admin_url( 'themes.php?page=generatepress-library' ),
|
||||
'elementsUrl' => admin_url( 'edit.php?post_type=gp_elements' ),
|
||||
'hasWooCommerce' => class_exists( 'WooCommerce' ),
|
||||
'licenseKey' => get_option( 'gen_premium_license_key', '' ),
|
||||
'licenseKeyStatus' => get_option( 'gen_premium_license_key_status', 'deactivated' ),
|
||||
'betaTester' => get_option( 'gp_premium_beta_testing', false ),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable beta testing if our option is set.
|
||||
*
|
||||
* @since 2.1.0
|
||||
* @param boolean $value Whether beta testing is on or not.
|
||||
*/
|
||||
public function set_beta_tester( $value ) {
|
||||
if ( get_option( 'gp_premium_beta_testing', false ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the container for our start customizing app.
|
||||
*/
|
||||
public function module_list() {
|
||||
echo '<div id="generatepress-module-list"></div>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the container for our start customizing app.
|
||||
*/
|
||||
public function license_key() {
|
||||
echo '<div id="generatepress-license-key"></div>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the container for our start customizing app.
|
||||
*/
|
||||
public function import_export() {
|
||||
echo '<div id="generatepress-import-export-pro"></div>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the container for our reset app.
|
||||
*/
|
||||
public function reset() {
|
||||
echo '<div id="generatepress-reset-pro"></div>';
|
||||
}
|
||||
}
|
||||
|
||||
GeneratePress_Pro_Dashboard::get_instance();
|
538
wp-content/plugins/gp-premium/inc/class-rest.php
Normal file
538
wp-content/plugins/gp-premium/inc/class-rest.php
Normal file
@ -0,0 +1,538 @@
|
||||
<?php
|
||||
/**
|
||||
* Rest API functions
|
||||
*
|
||||
* @package GenerateBlocks
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Class GenerateBlocks_Rest
|
||||
*/
|
||||
class GeneratePress_Pro_Rest extends WP_REST_Controller {
|
||||
/**
|
||||
* Instance.
|
||||
*
|
||||
* @access private
|
||||
* @var object Instance
|
||||
*/
|
||||
private static $instance;
|
||||
|
||||
/**
|
||||
* Namespace.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $namespace = 'generatepress-pro/v';
|
||||
|
||||
/**
|
||||
* Version.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $version = '1';
|
||||
|
||||
/**
|
||||
* Initiator.
|
||||
*
|
||||
* @return object initialized object of class.
|
||||
*/
|
||||
public static function get_instance() {
|
||||
if ( ! isset( self::$instance ) ) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* GeneratePress_Pro_Rest constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
add_action( 'rest_api_init', array( $this, 'register_routes' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Register rest routes.
|
||||
*/
|
||||
public function register_routes() {
|
||||
$namespace = $this->namespace . $this->version;
|
||||
|
||||
register_rest_route(
|
||||
$namespace,
|
||||
'/modules/',
|
||||
array(
|
||||
'methods' => WP_REST_Server::EDITABLE,
|
||||
'callback' => array( $this, 'update_module' ),
|
||||
'permission_callback' => array( $this, 'update_settings_permission' ),
|
||||
)
|
||||
);
|
||||
|
||||
register_rest_route(
|
||||
$namespace,
|
||||
'/license/',
|
||||
array(
|
||||
'methods' => WP_REST_Server::EDITABLE,
|
||||
'callback' => array( $this, 'update_licensing' ),
|
||||
'permission_callback' => array( $this, 'update_settings_permission' ),
|
||||
)
|
||||
);
|
||||
|
||||
register_rest_route(
|
||||
$namespace,
|
||||
'/export/',
|
||||
array(
|
||||
'methods' => WP_REST_Server::EDITABLE,
|
||||
'callback' => array( $this, 'export' ),
|
||||
'permission_callback' => array( $this, 'update_settings_permission' ),
|
||||
)
|
||||
);
|
||||
|
||||
register_rest_route(
|
||||
$namespace,
|
||||
'/import/',
|
||||
array(
|
||||
'methods' => WP_REST_Server::EDITABLE,
|
||||
'callback' => array( $this, 'import' ),
|
||||
'permission_callback' => array( $this, 'update_settings_permission' ),
|
||||
)
|
||||
);
|
||||
|
||||
register_rest_route(
|
||||
$namespace,
|
||||
'/reset/',
|
||||
array(
|
||||
'methods' => WP_REST_Server::EDITABLE,
|
||||
'callback' => array( $this, 'reset' ),
|
||||
'permission_callback' => array( $this, 'update_settings_permission' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get edit options permissions.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function update_settings_permission() {
|
||||
return current_user_can( 'manage_options' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Update modules.
|
||||
*
|
||||
* @param WP_REST_Request $request request object.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function update_module( WP_REST_Request $request ) {
|
||||
$module_key = $request->get_param( 'key' );
|
||||
$action = $request->get_param( 'action' );
|
||||
$current_setting = get_option( $module_key, false );
|
||||
$modules = GeneratePress_Pro_Dashboard::get_modules();
|
||||
$safe_module_keys = array();
|
||||
|
||||
foreach ( $modules as $key => $data ) {
|
||||
$safe_module_keys[] = $data['key'];
|
||||
}
|
||||
|
||||
if ( ! in_array( $module_key, $safe_module_keys ) ) {
|
||||
return $this->failed( 'Bad module key.' );
|
||||
}
|
||||
|
||||
$message = '';
|
||||
|
||||
if ( 'activate' === $action ) {
|
||||
update_option( $module_key, 'activated' );
|
||||
$message = __( 'Module activated.', 'gp-premium' );
|
||||
}
|
||||
|
||||
if ( 'deactivate' === $action ) {
|
||||
update_option( $module_key, 'deactivated' );
|
||||
$message = __( 'Module deactivated.', 'gp-premium' );
|
||||
}
|
||||
|
||||
return $this->success( $message );
|
||||
}
|
||||
|
||||
/**
|
||||
* Update licensing.
|
||||
*
|
||||
* @param WP_REST_Request $request request object.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function update_licensing( WP_REST_Request $request ) {
|
||||
$new_license_key = $request->get_param( 'key' );
|
||||
$new_beta_tester = $request->get_param( 'betaTester' );
|
||||
$old_license = get_option( 'gen_premium_license_key', '' );
|
||||
$old_status = get_option( 'gen_premium_license_key_status', 'deactivated' );
|
||||
$new_license = trim( $new_license_key );
|
||||
|
||||
if ( $new_license ) {
|
||||
$api_params = array(
|
||||
'edd_action' => 'activate_license',
|
||||
'license' => sanitize_key( $new_license ),
|
||||
'item_name' => rawurlencode( 'GP Premium' ),
|
||||
'url' => home_url(),
|
||||
);
|
||||
} elseif ( $old_license && 'valid' === $old_status ) {
|
||||
$api_params = array(
|
||||
'edd_action' => 'deactivate_license',
|
||||
'license' => sanitize_key( $old_license ),
|
||||
'item_name' => rawurlencode( 'GP Premium' ),
|
||||
'url' => home_url(),
|
||||
);
|
||||
}
|
||||
|
||||
if ( isset( $api_params ) ) {
|
||||
$response = wp_remote_post(
|
||||
'https://generatepress.com',
|
||||
array(
|
||||
'timeout' => 30,
|
||||
'sslverify' => false,
|
||||
'body' => $api_params,
|
||||
)
|
||||
);
|
||||
|
||||
if ( is_wp_error( $response ) || 200 !== (int) wp_remote_retrieve_response_code( $response ) ) {
|
||||
if ( is_object( $response ) ) {
|
||||
return $this->failed( $response->get_error_message() );
|
||||
} elseif ( is_array( $response ) && isset( $response['response']['message'] ) ) {
|
||||
if ( 'Forbidden' === $response['response']['message'] ) {
|
||||
$message = __( '403 Forbidden. Your server is not able to communicate with generatepress.com in order to activate your license key.', 'gp-premium' );
|
||||
} else {
|
||||
$message = $response['response']['message'];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$license_data = json_decode( wp_remote_retrieve_body( $response ) );
|
||||
|
||||
if ( false === $license_data->success ) {
|
||||
switch ( $license_data->error ) {
|
||||
case 'expired':
|
||||
$message = sprintf(
|
||||
/* translators: License key expiration date. */
|
||||
__( 'Your license key expired on %s.', 'gp-premium' ),
|
||||
date_i18n( get_option( 'date_format' ), strtotime( $license_data->expires, current_time( 'timestamp' ) ) ) // phpcs:ignore
|
||||
);
|
||||
break;
|
||||
|
||||
case 'disabled':
|
||||
case 'revoked':
|
||||
$message = __( 'Your license key has been disabled.', 'gp-premium' );
|
||||
break;
|
||||
|
||||
case 'missing':
|
||||
$message = __( 'Invalid license.', 'gp-premium' );
|
||||
break;
|
||||
|
||||
case 'invalid':
|
||||
case 'site_inactive':
|
||||
$message = __( 'Your license is not active for this URL.', 'gp-premium' );
|
||||
break;
|
||||
|
||||
case 'item_name_mismatch':
|
||||
/* translators: GP Premium */
|
||||
$message = sprintf( __( 'This appears to be an invalid license key for %s.', 'gp-premium' ), __( 'GP Premium', 'gp-premium' ) );
|
||||
break;
|
||||
|
||||
case 'no_activations_left':
|
||||
$message = __( 'Your license key has reached its activation limit.', 'gp-premium' );
|
||||
break;
|
||||
|
||||
default:
|
||||
$message = __( 'An error occurred, please try again.', 'gp-premium' );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
update_option( 'gen_premium_license_key_status', esc_attr( $license_data->license ) );
|
||||
}
|
||||
|
||||
if ( ! empty( $new_beta_tester ) ) {
|
||||
update_option( 'gp_premium_beta_testing', true, false );
|
||||
} else {
|
||||
delete_option( 'gp_premium_beta_testing' );
|
||||
}
|
||||
|
||||
update_option( 'gen_premium_license_key', sanitize_key( $new_license ) );
|
||||
|
||||
if ( ! isset( $api_params ) ) {
|
||||
return $this->success( __( 'Settings saved.', 'gp-premium' ) );
|
||||
}
|
||||
|
||||
if ( ! empty( $message ) ) {
|
||||
return $this->failed( $message );
|
||||
}
|
||||
|
||||
return $this->success( $license_data );
|
||||
}
|
||||
|
||||
/**
|
||||
* Export settings.
|
||||
*
|
||||
* @param WP_REST_Request $request request object.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function export( WP_REST_Request $request ) {
|
||||
$exportable_modules = $request->get_param( 'items' );
|
||||
|
||||
if ( ! $exportable_modules ) {
|
||||
$exportable_modules = GeneratePress_Pro_Dashboard::get_exportable_modules();
|
||||
}
|
||||
|
||||
$export_type = $request->get_param( 'type' );
|
||||
|
||||
if ( 'all' === $export_type ) {
|
||||
$data = array(
|
||||
'modules' => array(),
|
||||
'mods' => array(),
|
||||
'options' => array(),
|
||||
);
|
||||
|
||||
$module_settings = array();
|
||||
|
||||
foreach ( $exportable_modules as $exported_module_key => $exported_module_data ) {
|
||||
if ( isset( $exported_module_data['settings'] ) ) {
|
||||
$module_settings[] = $exported_module_data['settings'];
|
||||
}
|
||||
}
|
||||
|
||||
$modules = GeneratePress_Pro_Dashboard::get_modules();
|
||||
|
||||
// Export module status of the exported options.
|
||||
foreach ( $modules as $module_key => $module_data ) {
|
||||
if ( isset( $module_data['settings'] ) && in_array( $module_data['settings'], $module_settings ) ) {
|
||||
$data['modules'][ $module_key ] = $module_data['key'];
|
||||
}
|
||||
}
|
||||
|
||||
$theme_mods = GeneratePress_Pro_Dashboard::get_theme_mods();
|
||||
|
||||
foreach ( $theme_mods as $theme_mod ) {
|
||||
if ( 'generate_copyright' === $theme_mod ) {
|
||||
if ( in_array( 'copyright', $module_settings ) ) {
|
||||
$data['mods'][ $theme_mod ] = get_theme_mod( $theme_mod );
|
||||
}
|
||||
} else {
|
||||
if ( in_array( 'generate_settings', $module_settings ) ) {
|
||||
$data['mods'][ $theme_mod ] = get_theme_mod( $theme_mod );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$settings = GeneratePress_Pro_Dashboard::get_setting_keys();
|
||||
|
||||
foreach ( $settings as $setting ) {
|
||||
if ( in_array( $setting, $module_settings ) ) {
|
||||
$data['options'][ $setting ] = get_option( $setting );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( 'global-colors' === $export_type ) {
|
||||
$data['global-colors'] = generate_get_option( 'global_colors' );
|
||||
}
|
||||
|
||||
if ( 'typography' === $export_type ) {
|
||||
$data['font-manager'] = generate_get_option( 'font_manager' );
|
||||
$data['typography'] = generate_get_option( 'typography' );
|
||||
}
|
||||
|
||||
$data = apply_filters( 'generate_export_data', $data, $export_type );
|
||||
|
||||
return $this->success( $data );
|
||||
}
|
||||
|
||||
/**
|
||||
* Import settings.
|
||||
*
|
||||
* @param WP_REST_Request $request request object.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function import( WP_REST_Request $request ) {
|
||||
$settings = $request->get_param( 'import' );
|
||||
|
||||
if ( empty( $settings ) ) {
|
||||
$this->failed( __( 'No settings to import.', 'gp-premium' ) );
|
||||
}
|
||||
|
||||
if ( ! empty( $settings['typography'] ) ) {
|
||||
$existing_settings = get_option( 'generate_settings', array() );
|
||||
$existing_settings['typography'] = $settings['typography'];
|
||||
|
||||
if ( ! empty( $settings['font-manager'] ) ) {
|
||||
$existing_settings['font_manager'] = $settings['font-manager'];
|
||||
}
|
||||
|
||||
update_option( 'generate_settings', $existing_settings );
|
||||
} elseif ( ! empty( $settings['global-colors'] ) ) {
|
||||
$existing_settings = get_option( 'generate_settings', array() );
|
||||
$existing_settings['global_colors'] = $settings['global-colors'];
|
||||
|
||||
update_option( 'generate_settings', $existing_settings );
|
||||
} else {
|
||||
$modules = GeneratePress_Pro_Dashboard::get_modules();
|
||||
|
||||
foreach ( (array) $settings['modules'] as $key => $val ) {
|
||||
if ( isset( $modules[ $key ] ) && in_array( $val, $modules[ $key ] ) ) {
|
||||
update_option( $val, 'activated' );
|
||||
}
|
||||
}
|
||||
|
||||
foreach ( (array) $settings['mods'] as $key => $val ) {
|
||||
if ( in_array( $key, GeneratePress_Pro_Dashboard::get_theme_mods() ) ) {
|
||||
set_theme_mod( $key, $val );
|
||||
}
|
||||
}
|
||||
|
||||
foreach ( (array) $settings['options'] as $key => $val ) {
|
||||
if ( in_array( $key, GeneratePress_Pro_Dashboard::get_setting_keys() ) ) {
|
||||
update_option( $key, $val );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Delete existing dynamic CSS cache.
|
||||
delete_option( 'generate_dynamic_css_output' );
|
||||
delete_option( 'generate_dynamic_css_cached_version' );
|
||||
|
||||
$dynamic_css_data = get_option( 'generatepress_dynamic_css_data', array() );
|
||||
|
||||
if ( isset( $dynamic_css_data['updated_time'] ) ) {
|
||||
unset( $dynamic_css_data['updated_time'] );
|
||||
}
|
||||
|
||||
update_option( 'generatepress_dynamic_css_data', $dynamic_css_data );
|
||||
|
||||
return $this->success( __( 'Settings imported.', 'gp-premium' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset settings.
|
||||
*
|
||||
* @param WP_REST_Request $request request object.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function reset( WP_REST_Request $request ) {
|
||||
$reset_items = $request->get_param( 'items' );
|
||||
|
||||
if ( ! $reset_items ) {
|
||||
$reset_items = GeneratePress_Pro_Dashboard::get_exportable_modules();
|
||||
}
|
||||
|
||||
$module_settings = array();
|
||||
|
||||
foreach ( $reset_items as $reset_module_key => $reset_module_data ) {
|
||||
if ( isset( $reset_module_data['settings'] ) ) {
|
||||
$module_settings[] = $reset_module_data['settings'];
|
||||
}
|
||||
}
|
||||
|
||||
$theme_mods = GeneratePress_Pro_Dashboard::get_theme_mods();
|
||||
|
||||
foreach ( $theme_mods as $theme_mod ) {
|
||||
if ( 'generate_copyright' === $theme_mod ) {
|
||||
if ( in_array( 'copyright', $module_settings ) ) {
|
||||
remove_theme_mod( $theme_mod );
|
||||
}
|
||||
} else {
|
||||
if ( in_array( 'generate_settings', $module_settings ) ) {
|
||||
remove_theme_mod( $theme_mod );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$settings = GeneratePress_Pro_Dashboard::get_setting_keys();
|
||||
|
||||
foreach ( $settings as $setting ) {
|
||||
if ( in_array( $setting, $module_settings ) ) {
|
||||
delete_option( $setting );
|
||||
}
|
||||
}
|
||||
|
||||
// Delete our dynamic CSS option.
|
||||
delete_option( 'generate_dynamic_css_output' );
|
||||
delete_option( 'generate_dynamic_css_cached_version' );
|
||||
|
||||
// Reset our dynamic CSS file updated time so it regenerates.
|
||||
$dynamic_css_data = get_option( 'generatepress_dynamic_css_data', array() );
|
||||
|
||||
if ( isset( $dynamic_css_data['updated_time'] ) ) {
|
||||
unset( $dynamic_css_data['updated_time'] );
|
||||
}
|
||||
|
||||
update_option( 'generatepress_dynamic_css_data', $dynamic_css_data );
|
||||
|
||||
// Delete any GeneratePress Site CSS in Additional CSS.
|
||||
$additional_css = wp_get_custom_css_post();
|
||||
|
||||
if ( ! empty( $additional_css ) ) {
|
||||
$additional_css->post_content = preg_replace( '#(/\\* GeneratePress Site CSS \\*/).*?(/\\* End GeneratePress Site CSS \\*/)#s', '', $additional_css->post_content );
|
||||
wp_update_custom_css_post( $additional_css->post_content );
|
||||
}
|
||||
|
||||
return $this->success( __( 'Settings reset.', 'gp-premium' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Success rest.
|
||||
*
|
||||
* @param mixed $response response data.
|
||||
* @return mixed
|
||||
*/
|
||||
public function success( $response ) {
|
||||
return new WP_REST_Response(
|
||||
array(
|
||||
'success' => true,
|
||||
'response' => $response,
|
||||
),
|
||||
200
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Failed rest.
|
||||
*
|
||||
* @param mixed $response response data.
|
||||
* @return mixed
|
||||
*/
|
||||
public function failed( $response ) {
|
||||
return new WP_REST_Response(
|
||||
array(
|
||||
'success' => false,
|
||||
'response' => $response,
|
||||
),
|
||||
200
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Error rest.
|
||||
*
|
||||
* @param mixed $code error code.
|
||||
* @param mixed $response response data.
|
||||
* @return mixed
|
||||
*/
|
||||
public function error( $code, $response ) {
|
||||
return new WP_REST_Response(
|
||||
array(
|
||||
'error' => true,
|
||||
'success' => false,
|
||||
'error_code' => $code,
|
||||
'response' => $response,
|
||||
),
|
||||
401
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
GeneratePress_Pro_Rest::get_instance();
|
@ -85,3 +85,25 @@ function generate_has_active_element( $element, $block_element ) {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check our GeneratePress version.
|
||||
*
|
||||
* @since 2.1.0
|
||||
*/
|
||||
function generate_premium_get_theme_version() {
|
||||
return defined( 'GENERATE_VERSION' ) ? GENERATE_VERSION : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the featured-image-active class if needed.
|
||||
*
|
||||
* @since 2.1.0
|
||||
*/
|
||||
function generate_premium_remove_featured_image_class( $classes, $remove_class ) {
|
||||
if ( $remove_class && in_array( 'featured-image-active', $classes ) ) {
|
||||
$classes = array_diff( $classes, array( 'featured-image-active' ) );
|
||||
}
|
||||
|
||||
return $classes;
|
||||
}
|
||||
|
@ -110,6 +110,14 @@ if ( ! function_exists( 'generate_super_package_addons' ) ) {
|
||||
$addons['Site Library'] = 'generate_package_site_library';
|
||||
}
|
||||
|
||||
if ( function_exists( 'generate_is_using_dynamic_typography' ) && generate_is_using_dynamic_typography() ) {
|
||||
unset( $addons['Typography'] );
|
||||
}
|
||||
|
||||
if ( version_compare( generate_premium_get_theme_version(), '3.1.0-alpha.1', '>=' ) ) {
|
||||
unset( $addons['Colors'] );
|
||||
}
|
||||
|
||||
ksort( $addons );
|
||||
|
||||
$addon_count = 0;
|
||||
@ -494,9 +502,17 @@ function generatepress_premium_process_license_key() {
|
||||
'body' => $api_params
|
||||
) );
|
||||
|
||||
// make sure the response came back okay
|
||||
// Make sure the response came back okay.
|
||||
if ( is_wp_error( $license_response ) || 200 !== wp_remote_retrieve_response_code( $license_response ) ) {
|
||||
$message = $license_response->get_error_message();
|
||||
if ( is_object( $license_response ) ) {
|
||||
$message = $license_response->get_error_message();
|
||||
} elseif ( is_array( $license_response ) && isset( $license_response['response']['message'] ) ) {
|
||||
if ( 'Forbidden' === $license_response['response']['message'] ) {
|
||||
$message = __( '403 Forbidden. Your server is not able to communicate with generatepress.com in order to activate your license key.', 'gp-premium' );
|
||||
} else {
|
||||
$message = $license_response['response']['message'];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
// Still here? Decode our response.
|
@ -13,6 +13,10 @@ add_action( 'generate_before_site_library', 'generate_do_dashboard_tabs', 5 );
|
||||
* @since 1.6
|
||||
*/
|
||||
function generate_do_dashboard_tabs() {
|
||||
if ( ! defined( 'GENERATE_VERSION' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$screen = get_current_screen();
|
||||
|
||||
$tabs = apply_filters( 'generate_dashboard_tabs', array(
|
371
wp-content/plugins/gp-premium/inc/legacy/import-export.php
Normal file
371
wp-content/plugins/gp-premium/inc/legacy/import-export.php
Normal file
@ -0,0 +1,371 @@
|
||||
<?php
|
||||
/**
|
||||
* This file handles the import/export functionality.
|
||||
*
|
||||
* @package GP Premium
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // No direct access, please.
|
||||
}
|
||||
|
||||
/**
|
||||
* Import/export class.
|
||||
*/
|
||||
class GeneratePress_Import_Export {
|
||||
/**
|
||||
* Instance.
|
||||
*
|
||||
* @access private
|
||||
* @var object Instance
|
||||
* @since 1.7
|
||||
*/
|
||||
private static $instance;
|
||||
|
||||
/**
|
||||
* Initiator.
|
||||
*
|
||||
* @since 1.7
|
||||
* @return object initialized object of class.
|
||||
*/
|
||||
public static function get_instance() {
|
||||
if ( ! isset( self::$instance ) ) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add necessary actions.
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
public function __construct() {
|
||||
add_action( 'generate_admin_right_panel', array( $this, 'build_html' ), 15 );
|
||||
add_action( 'admin_init', array( $this, 'export' ) );
|
||||
add_action( 'admin_init', array( $this, 'import' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Build our export and import HTML.
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
public static function build_html() {
|
||||
?>
|
||||
<div class="postbox generate-metabox" id="generate-ie">
|
||||
<h3 class="hndle"><?php esc_html_e( 'Import/Export', 'gp-premium' ); ?></h3>
|
||||
<div class="inside">
|
||||
<form method="post">
|
||||
<h3 style="font-size: 15px;"><?php esc_html_e( 'Export', 'gp-premium' ); ?></h3>
|
||||
<span class="show-advanced"><?php _e( 'Advanced', 'gp-premium' ); ?></span>
|
||||
<div class="export-choices advanced-choices">
|
||||
<label>
|
||||
<input type="checkbox" name="module_group[]" value="generate_settings" checked />
|
||||
<?php _ex( 'Core', 'Module name', 'gp-premium' ); ?>
|
||||
</label>
|
||||
|
||||
<?php if ( generatepress_is_module_active( 'generate_package_backgrounds', 'GENERATE_BACKGROUNDS' ) ) : ?>
|
||||
<label>
|
||||
<input type="checkbox" name="module_group[]" value="generate_background_settings" checked />
|
||||
<?php _ex( 'Backgrounds', 'Module name', 'gp-premium' ); ?>
|
||||
</label>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ( generatepress_is_module_active( 'generate_package_blog', 'GENERATE_BLOG' ) ) : ?>
|
||||
<label>
|
||||
<input type="checkbox" name="module_group[]" value="generate_blog_settings" checked />
|
||||
<?php _ex( 'Blog', 'Module name', 'gp-premium' ); ?>
|
||||
</label>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ( generatepress_is_module_active( 'generate_package_hooks', 'GENERATE_HOOKS' ) ) : ?>
|
||||
<label>
|
||||
<input type="checkbox" name="module_group[]" value="generate_hooks" checked />
|
||||
<?php _ex( 'Hooks', 'Module name', 'gp-premium' ); ?>
|
||||
</label>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ( generatepress_is_module_active( 'generate_package_page_header', 'GENERATE_PAGE_HEADER' ) ) : ?>
|
||||
<label>
|
||||
<input type="checkbox" name="module_group[]" value="generate_page_header_settings" checked />
|
||||
<?php _ex( 'Page Header', 'Module name', 'gp-premium' ); ?>
|
||||
</label>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ( generatepress_is_module_active( 'generate_package_secondary_nav', 'GENERATE_SECONDARY_NAV' ) ) : ?>
|
||||
<label>
|
||||
<input type="checkbox" name="module_group[]" value="generate_secondary_nav_settings" checked />
|
||||
<?php _ex( 'Secondary Navigation', 'Module name', 'gp-premium' ); ?>
|
||||
</label>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ( generatepress_is_module_active( 'generate_package_spacing', 'GENERATE_SPACING' ) ) : ?>
|
||||
<label>
|
||||
<input type="checkbox" name="module_group[]" value="generate_spacing_settings" checked />
|
||||
<?php _ex( 'Spacing', 'Module name', 'gp-premium' ); ?>
|
||||
</label>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ( generatepress_is_module_active( 'generate_package_menu_plus', 'GENERATE_MENU_PLUS' ) ) : ?>
|
||||
<label>
|
||||
<input type="checkbox" name="module_group[]" value="generate_menu_plus_settings" checked />
|
||||
<?php _ex( 'Menu Plus', 'Module name', 'gp-premium' ); ?>
|
||||
</label>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ( generatepress_is_module_active( 'generate_package_woocommerce', 'GENERATE_WOOCOMMERCE' ) ) : ?>
|
||||
<label>
|
||||
<input type="checkbox" name="module_group[]" value="generate_woocommerce_settings" checked />
|
||||
<?php _ex( 'WooCommerce', 'Module name', 'gp-premium' ); ?>
|
||||
</label>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ( generatepress_is_module_active( 'generate_package_copyright', 'GENERATE_COPYRIGHT' ) ) : ?>
|
||||
<label>
|
||||
<input type="checkbox" name="module_group[]" value="copyright" checked />
|
||||
<?php _ex( 'Copyright', 'Module name', 'gp-premium' ); ?>
|
||||
</label>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php do_action( 'generate_export_items' ); ?>
|
||||
</div>
|
||||
<p><input type="hidden" name="generate_action" value="export_settings" /></p>
|
||||
<p style="margin-bottom:0">
|
||||
<?php wp_nonce_field( 'generate_export_nonce', 'generate_export_nonce' ); ?>
|
||||
<?php submit_button( __( 'Export', 'gp-premium' ), 'button-primary', 'submit', false, array( 'id' => '' ) ); ?>
|
||||
</p>
|
||||
</form>
|
||||
|
||||
<h3 style="font-size: 15px;margin-top: 30px;"><?php esc_html_e( 'Import', 'gp-premium' ); ?></h3>
|
||||
<form method="post" enctype="multipart/form-data">
|
||||
<p>
|
||||
<input type="file" name="import_file"/>
|
||||
</p>
|
||||
<p style="margin-bottom:0">
|
||||
<input type="hidden" name="generate_action" value="import_settings" />
|
||||
<?php wp_nonce_field( 'generate_import_nonce', 'generate_import_nonce' ); ?>
|
||||
<?php submit_button( __( 'Import', 'gp-premium' ), 'button-primary', 'submit', false, array( 'id' => '' ) ); ?>
|
||||
</p>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Export our chosen options.
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
public static function export() {
|
||||
if ( empty( $_POST['generate_action'] ) || 'export_settings' !== $_POST['generate_action'] ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! wp_verify_nonce( $_POST['generate_export_nonce'], 'generate_export_nonce' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! current_user_can( 'manage_options' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$modules = self::get_modules();
|
||||
$theme_mods = self::get_theme_mods();
|
||||
$settings = self::get_settings();
|
||||
|
||||
$data = array(
|
||||
'modules' => array(),
|
||||
'mods' => array(),
|
||||
'options' => array(),
|
||||
);
|
||||
|
||||
foreach ( $modules as $name => $value ) {
|
||||
if ( 'activated' === get_option( $value ) ) {
|
||||
$data['modules'][ $name ] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ( $theme_mods as $theme_mod ) {
|
||||
if ( 'generate_copyright' === $theme_mod ) {
|
||||
if ( in_array( 'copyright', $_POST['module_group'] ) ) {
|
||||
$data['mods'][ $theme_mod ] = get_theme_mod( $theme_mod );
|
||||
}
|
||||
} else {
|
||||
if ( in_array( 'generate_settings', $_POST['module_group'] ) ) {
|
||||
$data['mods'][ $theme_mod ] = get_theme_mod( $theme_mod );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ( $settings as $setting ) {
|
||||
if ( in_array( $setting, $_POST['module_group'] ) ) {
|
||||
$data['options'][ $setting ] = get_option( $setting );
|
||||
}
|
||||
}
|
||||
|
||||
$data = apply_filters( 'generate_export_data', $data );
|
||||
|
||||
nocache_headers();
|
||||
header( 'Content-Type: application/json; charset=utf-8' );
|
||||
header( 'Content-Disposition: attachment; filename=generate-settings-export-' . date( 'Ymd' ) . '.json' ); // phpcs:ignore -- Prefer date().
|
||||
header( 'Expires: 0' );
|
||||
|
||||
echo wp_json_encode( $data );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Import our exported file.
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
public static function import() {
|
||||
if ( empty( $_POST['generate_action'] ) || 'import_settings' !== $_POST['generate_action'] ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! wp_verify_nonce( $_POST['generate_import_nonce'], 'generate_import_nonce' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! current_user_can( 'manage_options' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$filename = $_FILES['import_file']['name'];
|
||||
$extension = end( explode( '.', $_FILES['import_file']['name'] ) );
|
||||
|
||||
if ( 'json' !== $extension ) {
|
||||
wp_die( __( 'Please upload a valid .json file', 'gp-premium' ) );
|
||||
}
|
||||
|
||||
$import_file = $_FILES['import_file']['tmp_name'];
|
||||
|
||||
if ( empty( $import_file ) ) {
|
||||
wp_die( __( 'Please upload a file to import', 'gp-premium' ) );
|
||||
}
|
||||
|
||||
// Retrieve the settings from the file and convert the json object to an array.
|
||||
$settings = json_decode( file_get_contents( $import_file ), true ); // phpcs:ignore -- file_get_contents() is fine here.
|
||||
|
||||
foreach ( (array) $settings['modules'] as $key => $val ) {
|
||||
if ( in_array( $val, self::get_modules() ) ) {
|
||||
update_option( $val, 'activated' );
|
||||
}
|
||||
}
|
||||
|
||||
foreach ( (array) $settings['mods'] as $key => $val ) {
|
||||
if ( in_array( $key, self::get_theme_mods() ) ) {
|
||||
set_theme_mod( $key, $val );
|
||||
}
|
||||
}
|
||||
|
||||
foreach ( (array) $settings['options'] as $key => $val ) {
|
||||
if ( in_array( $key, self::get_settings() ) ) {
|
||||
update_option( $key, $val );
|
||||
}
|
||||
}
|
||||
|
||||
// Delete existing dynamic CSS cache.
|
||||
delete_option( 'generate_dynamic_css_output' );
|
||||
delete_option( 'generate_dynamic_css_cached_version' );
|
||||
|
||||
$dynamic_css_data = get_option( 'generatepress_dynamic_css_data', array() );
|
||||
|
||||
if ( isset( $dynamic_css_data['updated_time'] ) ) {
|
||||
unset( $dynamic_css_data['updated_time'] );
|
||||
}
|
||||
|
||||
update_option( 'generatepress_dynamic_css_data', $dynamic_css_data );
|
||||
|
||||
wp_safe_redirect( admin_url( 'admin.php?page=generate-options&status=imported' ) );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* List out our available modules.
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
public static function get_modules() {
|
||||
return array(
|
||||
'Backgrounds' => 'generate_package_backgrounds',
|
||||
'Blog' => 'generate_package_blog',
|
||||
'Colors' => 'generate_package_colors',
|
||||
'Copyright' => 'generate_package_copyright',
|
||||
'Elements' => 'generate_package_elements',
|
||||
'Disable Elements' => 'generate_package_disable_elements',
|
||||
'Hooks' => 'generate_package_hooks',
|
||||
'Menu Plus' => 'generate_package_menu_plus',
|
||||
'Page Header' => 'generate_package_page_header',
|
||||
'Secondary Nav' => 'generate_package_secondary_nav',
|
||||
'Sections' => 'generate_package_sections',
|
||||
'Spacing' => 'generate_package_spacing',
|
||||
'Typography' => 'generate_package_typography',
|
||||
'WooCommerce' => 'generate_package_woocommerce',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* List our our set theme mods.
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
public static function get_theme_mods() {
|
||||
return array(
|
||||
'font_body_variants',
|
||||
'font_body_category',
|
||||
'font_site_title_variants',
|
||||
'font_site_title_category',
|
||||
'font_site_tagline_variants',
|
||||
'font_site_tagline_category',
|
||||
'font_navigation_variants',
|
||||
'font_navigation_category',
|
||||
'font_secondary_navigation_variants',
|
||||
'font_secondary_navigation_category',
|
||||
'font_buttons_variants',
|
||||
'font_buttons_category',
|
||||
'font_heading_1_variants',
|
||||
'font_heading_1_category',
|
||||
'font_heading_2_variants',
|
||||
'font_heading_2_category',
|
||||
'font_heading_3_variants',
|
||||
'font_heading_3_category',
|
||||
'font_heading_4_variants',
|
||||
'font_heading_4_category',
|
||||
'font_heading_5_variants',
|
||||
'font_heading_5_category',
|
||||
'font_heading_6_variants',
|
||||
'font_heading_6_category',
|
||||
'font_widget_title_variants',
|
||||
'font_widget_title_category',
|
||||
'font_footer_variants',
|
||||
'font_footer_category',
|
||||
'generate_copyright',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* List out our available settings.
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
public static function get_settings() {
|
||||
return array(
|
||||
'generate_settings',
|
||||
'generate_background_settings',
|
||||
'generate_blog_settings',
|
||||
'generate_hooks',
|
||||
'generate_page_header_settings',
|
||||
'generate_secondary_nav_settings',
|
||||
'generate_spacing_settings',
|
||||
'generate_menu_plus_settings',
|
||||
'generate_woocommerce_settings',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
GeneratePress_Import_Export::get_instance();
|
Reference in New Issue
Block a user