updated plugin GP Premium version 1.11.2

This commit is contained in:
2020-08-13 14:53:39 +00:00
committed by Gitium
parent 3f0f8d3ac9
commit 885bbdd113
151 changed files with 11329 additions and 6954 deletions

View File

@ -1,8 +1,17 @@
<?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.
@ -21,7 +30,7 @@ class GeneratePress_Import_Export {
*/
public static function get_instance() {
if ( ! isset( self::$instance ) ) {
self::$instance = new self;
self::$instance = new self();
}
return self::$instance;
@ -33,9 +42,9 @@ class GeneratePress_Import_Export {
* @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' ) );
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' ) );
}
/**
@ -46,9 +55,10 @@ class GeneratePress_Import_Export {
public static function build_html() {
?>
<div class="postbox generate-metabox" id="generate-ie">
<h3 class="hndle"><?php _e( 'Export Settings', 'gp-premium' );?></h3>
<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>
@ -127,12 +137,8 @@ class GeneratePress_Import_Export {
<?php submit_button( __( 'Export', 'gp-premium' ), 'button-primary', 'submit', false, array( 'id' => '' ) ); ?>
</p>
</form>
</div>
</div>
<div class="postbox generate-metabox" id="generate-ie">
<h3 class="hndle"><?php _e( 'Import Settings', 'gp-premium' );?></h3>
<div class="inside">
<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"/>
@ -143,7 +149,6 @@ class GeneratePress_Import_Export {
<?php submit_button( __( 'Import', 'gp-premium' ), 'button-primary', 'submit', false, array( 'id' => '' ) ); ?>
</p>
</form>
</div>
</div>
<?php
@ -155,7 +160,7 @@ class GeneratePress_Import_Export {
* @since 1.7
*/
public static function export() {
if ( empty( $_POST['generate_action'] ) || 'export_settings' != $_POST['generate_action'] ) {
if ( empty( $_POST['generate_action'] ) || 'export_settings' !== $_POST['generate_action'] ) {
return;
}
@ -174,30 +179,30 @@ class GeneratePress_Import_Export {
$data = array(
'modules' => array(),
'mods' => array(),
'options' => array()
'options' => array(),
);
foreach ( $modules as $name => $value ) {
if ( 'activated' === get_option( $value ) ) {
$data['modules'][$name] = $value;
$data['modules'][ $name ] = $value;
}
}
foreach ( $theme_mods as $theme_mod ) {
if ( 'generate_copyright' == $theme_mod ) {
if ( 'generate_copyright' === $theme_mod ) {
if ( in_array( 'copyright', $_POST['module_group'] ) ) {
$data['mods'][$theme_mod] = get_theme_mod( $theme_mod );
$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 );
$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['options'][ $setting ] = get_option( $setting );
}
}
@ -205,10 +210,10 @@ class GeneratePress_Import_Export {
nocache_headers();
header( 'Content-Type: application/json; charset=utf-8' );
header( 'Content-Disposition: attachment; filename=generate-settings-export-' . date( 'm-d-Y' ) . '.json' );
header( "Expires: 0" );
header( 'Content-Disposition: attachment; filename=generate-settings-export-' . date( 'm-d-Y' ) . '.json' ); // phpcs:ignore -- Prefer date().
header( 'Expires: 0' );
echo json_encode( $data );
echo wp_json_encode( $data );
exit;
}
@ -218,7 +223,7 @@ class GeneratePress_Import_Export {
* @since 1.7
*/
public static function import() {
if ( empty( $_POST['generate_action'] ) || 'import_settings' != $_POST['generate_action'] ) {
if ( empty( $_POST['generate_action'] ) || 'import_settings' !== $_POST['generate_action'] ) {
return;
}
@ -233,7 +238,7 @@ class GeneratePress_Import_Export {
$filename = $_FILES['import_file']['name'];
$extension = end( explode( '.', $_FILES['import_file']['name'] ) );
if ( $extension != 'json' ) {
if ( 'json' !== $extension ) {
wp_die( __( 'Please upload a valid .json file', 'gp-premium' ) );
}
@ -244,30 +249,38 @@ class GeneratePress_Import_Export {
}
// Retrieve the settings from the file and convert the json object to an array.
$settings = json_decode( file_get_contents( $import_file ), true );
$settings = json_decode( file_get_contents( $import_file ), true ); // phpcs:ignore -- file_get_contents() is fine here.
foreach ( ( array ) $settings['modules'] as $key => $val ) {
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 ) {
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 ) {
foreach ( (array) $settings['options'] as $key => $val ) {
if ( in_array( $key, self::get_settings() ) ) {
update_option( $key, $val );
}
}
// Delete existing dynamic CSS cache
// 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;
}