init
This commit is contained in:
@@ -0,0 +1,206 @@
|
||||
<?php
|
||||
/**
|
||||
* Flatsome_Registration class.
|
||||
*
|
||||
* @package Flatsome
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
/**
|
||||
* Base Flatsome registration.
|
||||
*/
|
||||
class Flatsome_Base_Registration {
|
||||
|
||||
/**
|
||||
* The UX Themes API instance.
|
||||
*
|
||||
* @var UxThemes_API
|
||||
*/
|
||||
protected $api;
|
||||
|
||||
/**
|
||||
* The option name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $option_name;
|
||||
|
||||
/**
|
||||
* Setup instance.
|
||||
*
|
||||
* @param string $api The UX Themes API instance.
|
||||
* @param string $option_name The option name.
|
||||
*/
|
||||
public function __construct( $api, $option_name ) {
|
||||
$this->api = $api;
|
||||
$this->option_name = $option_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register theme.
|
||||
*
|
||||
* @param string $code The purchase code.
|
||||
* @return array|WP_error
|
||||
*/
|
||||
public function register( $code ) {
|
||||
return new WP_Error( 500, __( 'Not allowed.', 'flatsome' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregister theme.
|
||||
*
|
||||
* @return array|WP_error
|
||||
*/
|
||||
public function unregister() {
|
||||
return new WP_Error( 500, __( 'Not allowed.', 'flatsome' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check latest version.
|
||||
*
|
||||
* @return array|WP_error
|
||||
*/
|
||||
public function get_latest_version() {
|
||||
return new WP_Error( 500, __( 'Not allowed.', 'flatsome' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a download URL.
|
||||
*
|
||||
* @param string $version Version number to download.
|
||||
* @return array|WP_error
|
||||
*/
|
||||
public function get_download_url( $version ) {
|
||||
return new WP_Error( 500, __( 'Not allowed.', 'flatsome' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether Flatsome is registered or not.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function is_registered() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the registration has been verified by Envato.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function is_verified() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether registration is public or local.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function is_public() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the registered purchase code.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_code() {
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the options array.
|
||||
*/
|
||||
public function get_options() {
|
||||
return get_option( $this->option_name, array() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the options array.
|
||||
*
|
||||
* @param array $data New data.
|
||||
*/
|
||||
public function set_options( $data ) {
|
||||
update_option( $this->option_name, $data );
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the options array.
|
||||
*/
|
||||
public function delete_options() {
|
||||
delete_option( $this->option_name );
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a value from the option settings array.
|
||||
*
|
||||
* @param string $name Option name.
|
||||
* @param mixed $default The default value if nothing is set.
|
||||
* @return mixed
|
||||
*/
|
||||
public function get_option( $name, $default = null ) {
|
||||
$options = $this->get_options();
|
||||
return isset( $options[ $name ] ) ? $options[ $name ] : $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set option value.
|
||||
*
|
||||
* @param string $name Option name.
|
||||
* @param mixed $option Option data.
|
||||
*/
|
||||
public function set_option( $name, $option ) {
|
||||
$options = $this->get_options();
|
||||
$options[ $name ] = wp_unslash( $option );
|
||||
|
||||
$this->set_options( $options );
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes an option.
|
||||
*
|
||||
* @param string $name Option name.
|
||||
*/
|
||||
public function delete_option( $name ) {
|
||||
$options = $this->get_options();
|
||||
|
||||
if ( isset( $options[ $name ] ) ) {
|
||||
unset( $options[ $name ] );
|
||||
}
|
||||
|
||||
$this->set_options( $options );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set registration errors.
|
||||
*
|
||||
* @param string[] $errors The error messages.
|
||||
* @return void
|
||||
*/
|
||||
public function set_errors( array $errors ) {
|
||||
$errors = array_filter( $errors );
|
||||
$this->set_option( 'errors', $errors );
|
||||
$this->set_option( 'show_notice', ! empty( $errors ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get registration errors.
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function get_errors() {
|
||||
return array_filter( $this->get_option( 'errors', array() ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears errors to hide admin notices etc.
|
||||
*/
|
||||
public function dismiss_notice() {
|
||||
$this->delete_option( 'show_notice' );
|
||||
}
|
||||
}
|
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
/**
|
||||
* Contains flatsome default values, used throughout the whole theme
|
||||
*
|
||||
* @author UX Themes
|
||||
* @category Class
|
||||
* @package Flatsome/Classes
|
||||
* @since 3.4.2
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Class Flatsome_Default
|
||||
*/
|
||||
class Flatsome_Default {
|
||||
|
||||
/** Primary Color */
|
||||
const COLOR_PRIMARY = '#446084';
|
||||
|
||||
/** Secondary Color */
|
||||
const COLOR_SECONDARY = '#d26e4b';
|
||||
|
||||
/** Success Color */
|
||||
const COLOR_SUCCESS = '#7a9c59';
|
||||
|
||||
/** Alert Color */
|
||||
const COLOR_ALERT = '#b20000';
|
||||
|
||||
}
|
@@ -0,0 +1,207 @@
|
||||
<?php
|
||||
/**
|
||||
* Flatsome_Envato_Admin class.
|
||||
*
|
||||
* @package Flatsome
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
/**
|
||||
* The Flatsome Envato.
|
||||
*/
|
||||
final class Flatsome_Envato_Admin {
|
||||
|
||||
/**
|
||||
* The single class instance.
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
private static $instance = null;
|
||||
|
||||
/**
|
||||
* Main Flatsome_Envato_Admin instance
|
||||
*
|
||||
* @return Flatsome_Envato_Admin.
|
||||
*/
|
||||
public static function instance() {
|
||||
if ( is_null( self::$instance ) ) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* The Flatsome_Registration instance.
|
||||
*
|
||||
* @var Flatsome_Registration
|
||||
*/
|
||||
private $registration = null;
|
||||
|
||||
/**
|
||||
* Setup instance properties
|
||||
*
|
||||
* @param Flatsome_Envato $registration The Flatsome_Envato instance.
|
||||
*/
|
||||
public function __construct( $registration ) {
|
||||
$this->registration = $registration;
|
||||
|
||||
add_action( 'admin_menu', array( $this, 'add_pages' ) );
|
||||
add_action( 'current_screen', array( $this, 'render_version_info_iframe' ) );
|
||||
add_action( 'admin_post_flatsome_envato_register', array( $this, 'save_registration_form' ) );
|
||||
add_action( 'wp_ajax_flatsome_registration_dismiss_notice', array( $registration, 'dismiss_notice' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add necessary admin pages.
|
||||
*/
|
||||
public function add_pages() {
|
||||
add_submenu_page( null, '', '', 'manage_options', 'flatsome-version-info', '__return_empty_string' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the update modal iframe.
|
||||
*
|
||||
* @param WP_Screen $screen WordPress admin screen.
|
||||
*/
|
||||
public function render_version_info_iframe( $screen ) {
|
||||
if ( $screen->base === 'admin_page_flatsome-version-info' ) {
|
||||
$version = isset( $_GET['version'] ) ? wp_unslash( $_GET['version'] ) : '';
|
||||
include get_template_directory() . '/template-parts/admin/envato/version-info-iframe.php';
|
||||
die;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders a message for sites with a purchase code.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function render_message_form() {
|
||||
ob_start();
|
||||
include get_template_directory() . '/template-parts/admin/envato/message-form.php';
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders a warning about unusual theme directory name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function render_directory_warning() {
|
||||
$template = get_template();
|
||||
|
||||
ob_start();
|
||||
include get_template_directory() . '/template-parts/admin/envato/directory-warning.php';
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the theme registration form.
|
||||
*
|
||||
* @param string $args Visibility options.
|
||||
* @return string
|
||||
*/
|
||||
public function render_registration_form( $args = array() ) {
|
||||
$registration = $this->registration;
|
||||
$registered = $registration->is_registered();
|
||||
$verified = $registration->is_verified();
|
||||
$code = $registration->get_code();
|
||||
$issues = $registration->get_errors();
|
||||
$args = wp_parse_args( $args, array(
|
||||
'form' => true,
|
||||
'show_intro' => true,
|
||||
'show_terms' => true,
|
||||
'show_submit' => true,
|
||||
) );
|
||||
|
||||
if ( $code ) {
|
||||
$code = flatsome_hide_chars( $code );
|
||||
} else {
|
||||
$code = get_transient( 'flatsome_purchase_code' );
|
||||
$confirmed = (bool) get_transient( 'flatsome_registration_confirmed' );
|
||||
}
|
||||
|
||||
$error = get_transient( 'flatsome_registration_error' );
|
||||
|
||||
if ( is_wp_error( $error ) ) {
|
||||
$data = $error->get_error_data();
|
||||
$message = $error->get_error_message();
|
||||
|
||||
if ( isset( $data['retry-after'] ) ) {
|
||||
$rate_limit = (int) $data['retry-after'];
|
||||
$time_left = $rate_limit - time();
|
||||
$time_left_format = $time_left < 3600 ? 'i:s' : 'H:i:s';
|
||||
$time_left_string = human_readable_duration( gmdate( $time_left_format, $time_left ) );
|
||||
|
||||
// translators: %s: Time left.
|
||||
$error = new WP_Error( 429, $message . ' ' . sprintf( __( 'Please try again in %s.', 'flatsome' ), $time_left_string ) );
|
||||
}
|
||||
}
|
||||
|
||||
delete_transient( 'flatsome_purchase_id' );
|
||||
delete_transient( 'flatsome_purchase_code' );
|
||||
delete_transient( 'flatsome_registration_confirmed' );
|
||||
delete_transient( 'flatsome_registration_error' );
|
||||
|
||||
ob_start();
|
||||
|
||||
include get_template_directory() . '/template-parts/admin/envato/register-form.php';
|
||||
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the theme registration form.
|
||||
*/
|
||||
public function save_registration_form() {
|
||||
check_admin_referer( 'flatsome_envato_register', 'flatsome_envato_register_nonce' );
|
||||
|
||||
if ( isset( $_POST['flatsome_register'] ) ) {
|
||||
$code = isset( $_POST['flatsome_purchase_code'] )
|
||||
? sanitize_text_field( wp_unslash( $_POST['flatsome_purchase_code'] ) )
|
||||
: '';
|
||||
|
||||
$purchase_id = isset( $_POST['flatsome_purchase_id'] )
|
||||
? sanitize_text_field( wp_unslash( $_POST['flatsome_purchase_id'] ) )
|
||||
: '';
|
||||
|
||||
$confirmed = isset( $_POST['flatsome_envato_terms'] )
|
||||
? (bool) $_POST['flatsome_envato_terms']
|
||||
: false;
|
||||
|
||||
set_transient( 'flatsome_purchase_code', $code, 120 );
|
||||
set_transient( 'flatsome_purchase_id', $purchase_id, 120 );
|
||||
set_transient( 'flatsome_registration_confirmed', $confirmed, 120 );
|
||||
|
||||
if ( ! $confirmed ) {
|
||||
$result = new WP_Error( 403, __( 'You must agree to the Envato License Terms.', 'flatsome' ) );
|
||||
} elseif ( $purchase_id ) {
|
||||
$result = $this->registration->register( $purchase_id );
|
||||
} else {
|
||||
$result = $this->registration->register( $code );
|
||||
}
|
||||
} elseif ( isset( $_POST['flatsome_verify'] ) ) {
|
||||
$code = $this->registration->get_code();
|
||||
$result = $this->registration->register( $code );
|
||||
} elseif ( isset( $_POST['flatsome_unregister'] ) ) {
|
||||
$result = $this->registration->unregister();
|
||||
|
||||
delete_option( 'flatsome_update_cache' );
|
||||
}
|
||||
|
||||
if ( is_wp_error( $result ) ) {
|
||||
set_transient( 'flatsome_registration_error', $result, 120 );
|
||||
}
|
||||
|
||||
$referer = isset( $_POST['_wp_http_referer'] )
|
||||
? esc_url_raw( wp_unslash( $_POST['_wp_http_referer'] ) )
|
||||
: '';
|
||||
|
||||
wp_safe_redirect( $referer );
|
||||
|
||||
exit;
|
||||
}
|
||||
}
|
@@ -0,0 +1,192 @@
|
||||
<?php
|
||||
/**
|
||||
* Flatsome_Registration class.
|
||||
*
|
||||
* @package Flatsome
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
/**
|
||||
* The Flatsome registration.
|
||||
*/
|
||||
final class Flatsome_Envato_Registration extends Flatsome_Base_Registration {
|
||||
|
||||
/**
|
||||
* Setup instance.
|
||||
*
|
||||
* @param UxThemes_API $api The UX Themes API instance.
|
||||
*/
|
||||
public function __construct( UxThemes_API $api ) {
|
||||
parent::__construct( $api, 'flatsome_envato' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Register with a purchase ID or code.
|
||||
*
|
||||
* @param string $purchase_id Purchase ID or code.
|
||||
* @return array|WP_error
|
||||
*/
|
||||
public function register( $purchase_id ) {
|
||||
$token = $this->get_token();
|
||||
|
||||
if ( empty( $token ) ) {
|
||||
return new WP_Error( 400, __( 'Missing token.', 'flatsome' ) );
|
||||
} elseif ( empty( $purchase_id ) ) {
|
||||
return new WP_Error( 400, __( 'No purchase code provided.', 'flatsome' ) );
|
||||
}
|
||||
|
||||
$result = $this->api->send_request( '/v1/token/register', 'envato-register', array(
|
||||
'method' => 'POST',
|
||||
'headers' => array(
|
||||
'authorization' => "Bearer $token",
|
||||
),
|
||||
'body' => array(
|
||||
'purchase_id' => $purchase_id,
|
||||
),
|
||||
) );
|
||||
|
||||
if ( ! is_wp_error( $result ) ) {
|
||||
$registration = new Flatsome_Registration( $this->api );
|
||||
$registration->set_options( $result );
|
||||
$this->delete_options();
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters theme.
|
||||
*
|
||||
* @return array|WP_error
|
||||
*/
|
||||
public function unregister() {
|
||||
$this->delete_options();
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get latest Flatsome version.
|
||||
*
|
||||
* @return string|WP_error
|
||||
*/
|
||||
public function get_latest_version() {
|
||||
$token = $this->get_token();
|
||||
|
||||
if ( empty( $token ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$result = $this->api->send_request( '/v1/token/latest-version', 'latest-version', array(
|
||||
'headers' => array(
|
||||
'authorization' => "Bearer $token",
|
||||
),
|
||||
) );
|
||||
|
||||
if ( is_wp_error( $result ) ) {
|
||||
$statuses = array( 403, 404, 409, 410, 423 );
|
||||
if ( in_array( (int) $result->get_error_code(), $statuses, true ) ) {
|
||||
$this->set_errors( array( $result->get_error_message() ) );
|
||||
}
|
||||
return $result;
|
||||
} else {
|
||||
$this->set_errors( array() );
|
||||
}
|
||||
|
||||
if ( empty( $result['version'] ) ) {
|
||||
return new WP_Error( 'missing-version', __( 'No version received.', 'flatsome' ) );
|
||||
}
|
||||
|
||||
if ( ! is_string( $result['version'] ) ) {
|
||||
return new WP_Error( 'invalid-version', __( 'Invalid version received.', 'flatsome' ) );
|
||||
}
|
||||
|
||||
return $result['version'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a temporary download URL.
|
||||
*
|
||||
* @param string $version Version number to download.
|
||||
* @return string|WP_error
|
||||
*/
|
||||
public function get_download_url( $version ) {
|
||||
$token = $this->get_token();
|
||||
|
||||
if ( empty( $token ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$result = $this->api->send_request( "/v1/token/download-url/$version", 'download-url', array(
|
||||
'headers' => array(
|
||||
'authorization' => "Bearer $token",
|
||||
),
|
||||
) );
|
||||
|
||||
if ( is_wp_error( $result ) ) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
if ( empty( $result['url'] ) ) {
|
||||
return new WP_Error( 'missing-url', __( 'No URL received.', 'flatsome' ) );
|
||||
}
|
||||
|
||||
if ( ! is_string( $result['url'] ) ) {
|
||||
return new WP_Error( 'invalid-url', __( 'Invalid URL received.', 'flatsome' ) );
|
||||
}
|
||||
|
||||
return $result['url'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns available purchase codes.
|
||||
*
|
||||
* @return array|WP_error
|
||||
*/
|
||||
public function get_purchase_codes() {
|
||||
$token = $this->get_token();
|
||||
|
||||
if ( empty( $token ) ) {
|
||||
return array( 'available' => array() );
|
||||
}
|
||||
|
||||
return $this->api->send_request( '/v1/token/purchase-codes', null, array(
|
||||
'headers' => array(
|
||||
'authorization' => "Bearer $token",
|
||||
),
|
||||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether Flatsome is registered or not.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function is_registered() {
|
||||
return $this->get_token() !== '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the registration has been verified by Envato.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function is_verified() {
|
||||
return ! empty( $this->get_option( 'is_valid' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the personal Envato token this site was registered with.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function get_token() {
|
||||
$options = $this->get_options();
|
||||
$token = isset( $options['token'] ) ? $options['token'] : '';
|
||||
$valid = isset( $options['is_valid'] ) ? $options['is_valid'] : false;
|
||||
|
||||
return $valid ? $token : '';
|
||||
}
|
||||
}
|
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
/**
|
||||
* Flatsome_Envato class.
|
||||
*
|
||||
* @package Flatsome
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
/**
|
||||
* The Flatsome Envato.
|
||||
*/
|
||||
final class Flatsome_Envato {
|
||||
|
||||
/**
|
||||
* The single class instance.
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
private static $instance = null;
|
||||
|
||||
/**
|
||||
* The registration instance.
|
||||
*
|
||||
* @var Flatsome_Base_Registration
|
||||
*/
|
||||
public $registration;
|
||||
|
||||
/**
|
||||
* Setup instance properties.
|
||||
*/
|
||||
public function __construct() {
|
||||
$api = new UxThemes_API();
|
||||
|
||||
if ( get_option( 'flatsome_envato' ) ) {
|
||||
$this->registration = new Flatsome_Envato_Registration( $api );
|
||||
} elseif ( get_option( flatsome_theme_key() . '_wup_purchase_code' ) ) {
|
||||
$this->registration = new Flatsome_WUpdates_Registration( $api );
|
||||
} else {
|
||||
$this->registration = new Flatsome_Registration( $api );
|
||||
}
|
||||
|
||||
if ( is_admin() ) {
|
||||
$this->admin = new Flatsome_Envato_Admin( $this->registration );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether this site is registered or not.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function is_registered() {
|
||||
return $this->registration->is_registered();
|
||||
}
|
||||
|
||||
/**
|
||||
* Main Flatsome_Envato instance
|
||||
*
|
||||
* @return Flatsome_Envato
|
||||
*/
|
||||
public static function get_instance() {
|
||||
if ( is_null( self::$instance ) ) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
}
|
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
// Exit if accessed directly
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a wrapper class for Kirki.
|
||||
* If the Kirki plugin is installed, then all CSS & Google fonts
|
||||
* will be handled by the plugin.
|
||||
* In case the plugin is not installed, this acts as a fallback
|
||||
* ensuring that all CSS & fonts still work.
|
||||
* It does not handle the customizer options, simply the frontend CSS.
|
||||
*/
|
||||
class Flatsome_Option {
|
||||
|
||||
/**
|
||||
* @static
|
||||
* @access protected
|
||||
* @var array
|
||||
*/
|
||||
protected static $config = array();
|
||||
|
||||
/**
|
||||
* @static
|
||||
* @access protected
|
||||
* @var array
|
||||
*/
|
||||
protected static $fields = array();
|
||||
|
||||
/**
|
||||
* The class constructor
|
||||
*/
|
||||
public function __construct() {
|
||||
// If Kirki exists then there's no reason to procedd
|
||||
if ( class_exists( 'Kirki' ) ) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new panel
|
||||
*
|
||||
* @param string the ID for this panel
|
||||
* @param array the panel arguments
|
||||
*/
|
||||
public static function add_panel( $id = '', $args = array() ) {
|
||||
|
||||
|
||||
if ( class_exists( 'Kirki' ) ) {
|
||||
Kirki::add_panel( $id, $args );
|
||||
}
|
||||
// If Kirki does not exist then there's no reason to add any panels.
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new section
|
||||
*
|
||||
* @param string the ID for this section
|
||||
* @param array the section arguments
|
||||
*/
|
||||
public static function add_section( $id, $args ) {
|
||||
|
||||
if ( class_exists( 'Kirki' ) ) {
|
||||
Kirki::add_section( $id, $args );
|
||||
}
|
||||
// If Kirki does not exist then there's no reason to add any sections.
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the configuration options.
|
||||
*
|
||||
* @param string $config_id The configuration ID
|
||||
* @param array $args The configuration arguments
|
||||
*/
|
||||
public static function add_config( $config_id, $args = array() ) {
|
||||
if ( class_exists( 'Kirki' ) ) {
|
||||
Kirki::add_config( $config_id, $args );
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new field
|
||||
*
|
||||
* @param string $config_id The configuration ID
|
||||
* @param array $args The field's arguments
|
||||
*/
|
||||
public static function add_field( $config_id, $args ) {
|
||||
if($config_id == '') $config_id = $args['settings'];
|
||||
|
||||
// if Kirki exists, use it.
|
||||
if ( class_exists( 'Kirki' ) ) {
|
||||
Kirki::add_field( $config_id, $args );
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
new Flatsome_Option();
|
@@ -0,0 +1,207 @@
|
||||
<?php
|
||||
/**
|
||||
* Flatsome_Registration class.
|
||||
*
|
||||
* @package Flatsome
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
/**
|
||||
* The Flatsome registration.
|
||||
*/
|
||||
final class Flatsome_Registration extends Flatsome_Base_Registration {
|
||||
|
||||
/**
|
||||
* Setup instance.
|
||||
*
|
||||
* @param UxThemes_API $api The UX Themes API instance.
|
||||
*/
|
||||
public function __construct( UxThemes_API $api ) {
|
||||
parent::__construct( $api, 'flatsome_registration' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers Flatsome.
|
||||
*
|
||||
* @param string $code Purchase code.
|
||||
* @return array|WP_error
|
||||
*/
|
||||
public function register( $code ) {
|
||||
if ( empty( $code ) ) {
|
||||
return new WP_Error( 400, __( 'No purchase code provided.', 'flatsome' ) );
|
||||
} elseif ( strlen( $code ) === 32 && strpos( $code, '-' ) === false ) {
|
||||
return new WP_Error( 400, __( 'The provided value seems to be a token. Please register with a purchase code instead.', 'flatsome' ) );
|
||||
} elseif ( strlen( $code ) !== 36 || substr_count( $code, '-' ) !== 4 ) {
|
||||
return new WP_Error( 400, __( 'Invalid purchase code.', 'flatsome' ) );
|
||||
}
|
||||
|
||||
$is_verifying = isset( $_POST['flatsome_verify'] ); // phpcs:ignore WordPress.Security.NonceVerification
|
||||
$id = $is_verifying ? $this->get_option( 'id' ) : 0;
|
||||
|
||||
$result = ! empty( $id )
|
||||
? $this->api->send_request( "/v1/license/$code/$id", 'register', array( 'method' => 'PATCH' ) )
|
||||
: $this->api->send_request( "/v1/license/$code", 'register', array( 'method' => 'POST' ) );
|
||||
|
||||
if ( is_wp_error( $result ) ) {
|
||||
$status = (int) $result->get_error_code();
|
||||
$data = $result->get_error_data();
|
||||
|
||||
// Finish the registration if the request was stopped by an Envato
|
||||
// rate limit. It needs to be verified later in order to receive updates.
|
||||
if ( $status === 429 && isset( $data['id'] ) ) {
|
||||
$result = new WP_Error( $status, __( 'Your site is registered. But the purchase code could not be verified at the moment.', 'flatsome' ), $data );
|
||||
$this->set_options( $data );
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
$this->set_options( $result );
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Revokes the registration.
|
||||
*
|
||||
* @return array|WP_error
|
||||
*/
|
||||
public function unregister() {
|
||||
$code = $this->get_code();
|
||||
$id = $this->get_option( 'id', '0' );
|
||||
$result = $this->api->send_request( "/v1/license/$code/$id", 'unregister', array( 'method' => 'DELETE' ) );
|
||||
|
||||
if ( is_wp_error( $result ) ) {
|
||||
$status = (int) $result->get_error_code();
|
||||
|
||||
if ( $status === 404 ) {
|
||||
// Remove the registration from this site regardless of it was found by the API.
|
||||
$result = new WP_Error( 'warning', $result->get_error_message() );
|
||||
} else {
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
$this->delete_options();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get latest Flatsome version.
|
||||
*
|
||||
* @return string|WP_error
|
||||
*/
|
||||
public function get_latest_version() {
|
||||
$code = $this->get_code();
|
||||
|
||||
if ( empty( $code ) ) {
|
||||
return new WP_Error( 'missing-purchase-code', __( 'No purchase code.', 'flatsome' ) );
|
||||
}
|
||||
|
||||
$id = $this->get_option( 'id', '0' );
|
||||
$result = $this->api->send_request( "/v1/license/$code/$id/latest-version", 'latest-version' );
|
||||
|
||||
if ( is_wp_error( $result ) ) {
|
||||
$statuses = array( 400, 403, 404, 409, 410, 423 );
|
||||
if ( in_array( (int) $result->get_error_code(), $statuses, true ) ) {
|
||||
$this->set_errors( array( $result->get_error_message() ) );
|
||||
}
|
||||
return $result;
|
||||
} else {
|
||||
$this->set_errors( array() );
|
||||
}
|
||||
|
||||
if ( empty( $result['version'] ) ) {
|
||||
return new WP_Error( 'missing-version', __( 'No version received.', 'flatsome' ) );
|
||||
}
|
||||
|
||||
if ( ! is_string( $result['version'] ) ) {
|
||||
return new WP_Error( 'invalid-version', __( 'Invalid version received.', 'flatsome' ) );
|
||||
}
|
||||
|
||||
return $result['version'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a temporary download URL.
|
||||
*
|
||||
* @param string $version Version number to download.
|
||||
* @return string|WP_error
|
||||
*/
|
||||
public function get_download_url( $version ) {
|
||||
$code = $this->get_code();
|
||||
|
||||
if ( empty( $code ) ) {
|
||||
return new WP_Error( 'missing-purchase-code', __( 'No purchase code.', 'flatsome' ) );
|
||||
}
|
||||
|
||||
$id = $this->get_option( 'id', '0' );
|
||||
$result = $this->api->send_request( "/v1/license/$code/$id/download-url/$version", 'download-url' );
|
||||
|
||||
if ( is_wp_error( $result ) ) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
if ( empty( $result['url'] ) ) {
|
||||
return new WP_Error( 'missing-url', __( 'No URL received.', 'flatsome' ) );
|
||||
}
|
||||
|
||||
if ( ! is_string( $result['url'] ) ) {
|
||||
return new WP_Error( 'invalid-url', __( 'Invalid URL received.', 'flatsome' ) );
|
||||
}
|
||||
|
||||
return $result['url'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the options array.
|
||||
*
|
||||
* @param array $data New data.
|
||||
*/
|
||||
public function set_options( $data ) {
|
||||
if ( isset( $data['retry-after'] ) ) {
|
||||
unset( $data['retry-after'] );
|
||||
}
|
||||
parent::set_options( $data );
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether Flatsome is registered or not.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function is_registered() {
|
||||
return $this->get_code() !== '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the purchase code was verified.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function is_verified() {
|
||||
return is_string( $this->get_option( 'licenseType' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether Flatsome is registered or not.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function is_public() {
|
||||
return $this->get_option( 'type' ) === 'PUBLIC';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the registered purchase code.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_code() {
|
||||
return $this->get_option( 'purchaseCode', '' );
|
||||
}
|
||||
}
|
@@ -0,0 +1,232 @@
|
||||
<?php
|
||||
/**
|
||||
* Handles flatsome option upgrades
|
||||
*
|
||||
* @author UX Themes
|
||||
* @category Class
|
||||
* @package Flatsome/Classes
|
||||
* @since 3.4.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Class Flatsome_Upgrade
|
||||
*/
|
||||
class Flatsome_Upgrade {
|
||||
|
||||
/**
|
||||
* Holds flatsome DB version
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $db_version;
|
||||
|
||||
/**
|
||||
* Holds flatsome current running parent theme version
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $running_version;
|
||||
|
||||
/**
|
||||
* Holds is upgrade completed
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $is_upgrade_completed = false;
|
||||
|
||||
/**
|
||||
* Holds update callback that need to be run per version
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $updates = array(
|
||||
'3.4.0' => array(
|
||||
'update_340',
|
||||
),
|
||||
'3.6.0' => array(
|
||||
'update_360',
|
||||
),
|
||||
'3.9.0' => array(
|
||||
'update_390',
|
||||
),
|
||||
'3.12.1' => array(
|
||||
'update_3121',
|
||||
),
|
||||
'3.15.0' => array(
|
||||
'update_3150',
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Flatsome_Upgrade Class constructor
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
add_action( 'init', array( $this, 'check_version' ), 5, 0 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check Flatsome version and run the updater if required.
|
||||
*/
|
||||
public function check_version() {
|
||||
|
||||
$theme = wp_get_theme( get_template() );
|
||||
$this->db_version = get_theme_mod( 'flatsome_db_version', '3.0.0' );
|
||||
$this->running_version = $theme->version;
|
||||
|
||||
// If current version is new and current version has any update run it.
|
||||
if ( version_compare( $this->db_version, $this->running_version, '<' ) && version_compare( $this->db_version, $this->highest_update_version(), '<' ) ) {
|
||||
$this->update();
|
||||
if ( $this->is_upgrade_completed ) {
|
||||
$this->update_db_version();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Push all needed updates
|
||||
*/
|
||||
private function update() {
|
||||
|
||||
foreach ( $this->updates as $version => $update_callbacks ) {
|
||||
if ( version_compare( $this->db_version, $version, '<' ) ) {
|
||||
|
||||
// Run all callbacks.
|
||||
foreach ( $update_callbacks as $update_callback ) {
|
||||
if ( method_exists( $this, $update_callback ) ) {
|
||||
$this->$update_callback();
|
||||
} elseif ( function_exists( $update_callback ) ) {
|
||||
$update_callback();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->is_upgrade_completed = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the version number of highest update available.
|
||||
*
|
||||
* @return string Version number
|
||||
*/
|
||||
private function highest_update_version() {
|
||||
return array_reduce( array_keys( $this->updates ), function ( $highest, $current ) {
|
||||
return version_compare( $highest, $current, '>' ) ? $highest : $current;
|
||||
} );
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs upgrades to Flatsome 3.4.0
|
||||
*/
|
||||
private function update_340() {
|
||||
$portfolio_archive_filter = get_theme_mod( 'portfolio_archive_filter' );
|
||||
if ( empty( $portfolio_archive_filter ) ) {
|
||||
set_theme_mod( 'portfolio_archive_filter', 'left' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs upgrades to Flatsome 3.6.0
|
||||
*/
|
||||
private function update_360() {
|
||||
|
||||
// Set cart layout as checkout layout if its set.
|
||||
if ( get_theme_mod( 'checkout_layout' ) ) {
|
||||
set_theme_mod( 'cart_layout', get_theme_mod( 'checkout_layout' ) );
|
||||
}
|
||||
|
||||
// Fixes old headlines.
|
||||
$fonts = array(
|
||||
'type_headings' => array(
|
||||
'font-family' => 'Lato',
|
||||
'variant' => '700',
|
||||
),
|
||||
'type_texts' => array(
|
||||
'font-family' => 'Lato',
|
||||
'variant' => '400',
|
||||
),
|
||||
'type_nav' => array(
|
||||
'font-family' => 'Lato',
|
||||
'variant' => '700',
|
||||
),
|
||||
'type_alt' => array(
|
||||
'font-family' => 'Dancing Script',
|
||||
'variant' => '400',
|
||||
),
|
||||
);
|
||||
|
||||
// Reset font to default if it contains an empty array.
|
||||
foreach ( $fonts as $font => $default ) {
|
||||
$setting = get_theme_mod( $font );
|
||||
if ( ! $setting ) {
|
||||
set_theme_mod( $font, $default );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs upgrades to Flatsome 3.9.0
|
||||
*/
|
||||
private function update_390() {
|
||||
remove_theme_mod( 'follow_google' );
|
||||
remove_theme_mod( 'lazy_load_google_fonts' );
|
||||
remove_theme_mod( 'lazy_load_icons' );
|
||||
|
||||
set_theme_mod( 'pages_template', 'default' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs upgrades to Flatsome 3.12.1
|
||||
*/
|
||||
private function update_3121() {
|
||||
|
||||
// Change 404_block setting value from post_name to ID if one is chosen.
|
||||
$block = get_theme_mod( '404_block' );
|
||||
if ( ! empty( $block ) && ! is_numeric( $block ) ) {
|
||||
$blocks = flatsome_get_post_type_items( 'blocks' );
|
||||
if ( $blocks ) {
|
||||
foreach ( $blocks as $block_post ) {
|
||||
if ( $block_post->post_name == $block ) {
|
||||
set_theme_mod( '404_block', $block_post->ID );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Set mod to empty string if value is 0.
|
||||
if ( 0 == get_theme_mod( 'site_loader' ) ) {
|
||||
set_theme_mod( 'site_loader', '' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs upgrades to Flatsome 3.15.0
|
||||
*/
|
||||
private function update_3150() {
|
||||
foreach ( array( 'site_logo', 'site_logo_dark', 'site_logo_sticky' ) as $name ) {
|
||||
$value = get_theme_mod( $name );
|
||||
|
||||
if ( empty( $value ) ) continue;
|
||||
if ( is_numeric( $value ) ) continue;
|
||||
|
||||
if ( $post_id = attachment_url_to_postid( $value ) ) {
|
||||
set_theme_mod( $name, $post_id );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the DB version to the current running version.
|
||||
* Should only be called when all upgrades are performed.
|
||||
*/
|
||||
private function update_db_version() {
|
||||
set_theme_mod( 'flatsome_db_version', $this->running_version );
|
||||
}
|
||||
}
|
||||
|
||||
new Flatsome_Upgrade();
|
@@ -0,0 +1,203 @@
|
||||
<?php
|
||||
/**
|
||||
* Flatsome_Registration class.
|
||||
*
|
||||
* @package Flatsome
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
/**
|
||||
* The Flatsome registration.
|
||||
*/
|
||||
final class Flatsome_WUpdates_Registration extends Flatsome_Base_Registration {
|
||||
|
||||
/**
|
||||
* Setup instance.
|
||||
*
|
||||
* @param UxThemes_API $api The UX Themes API instance.
|
||||
*/
|
||||
public function __construct( UxThemes_API $api ) {
|
||||
parent::__construct( $api, 'flatsome_wupdates' );
|
||||
|
||||
add_action( 'flatsome_scheduled_registration', array( $this, 'migrate_registration' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers Flatsome.
|
||||
*
|
||||
* @param string $code Purchase code.
|
||||
* @return array|WP_error
|
||||
*/
|
||||
public function register( $code ) {
|
||||
$registration = new Flatsome_Registration( $this->api );
|
||||
$result = $registration->register( $code );
|
||||
|
||||
if ( is_wp_error( $result ) ) {
|
||||
return $this->api->get_error( $result, 'wupdates-register' );
|
||||
}
|
||||
|
||||
if ( empty( $registration->get_code() ) ) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
$this->delete_options();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters theme.
|
||||
*
|
||||
* @return array|WP_error
|
||||
*/
|
||||
public function unregister() {
|
||||
$this->delete_options();
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get latest Flatsome version.
|
||||
*
|
||||
* @return string|WP_error
|
||||
*/
|
||||
public function get_latest_version() {
|
||||
$code = $this->get_code();
|
||||
|
||||
if ( empty( $code ) ) {
|
||||
return new WP_Error( 'missing-purchase-code', __( 'Missing purchase code.', 'flatsome' ) );
|
||||
}
|
||||
|
||||
$result = $this->api->send_request( "/legacy/license/$code/latest-version", 'wupdates-latest-version' );
|
||||
|
||||
if ( is_wp_error( $result ) ) {
|
||||
$statuses = array( 400, 403, 404, 409, 410, 423 );
|
||||
if ( in_array( (int) $result->get_error_code(), $statuses, true ) ) {
|
||||
$this->set_errors( array( $result->get_error_message() ) );
|
||||
}
|
||||
return $result;
|
||||
} else {
|
||||
wp_clear_scheduled_hook( 'flatsome_scheduled_registration' );
|
||||
wp_schedule_single_event( time() + HOUR_IN_SECONDS, 'flatsome_scheduled_registration' );
|
||||
$this->set_errors( array() );
|
||||
}
|
||||
|
||||
if ( empty( $result['version'] ) ) {
|
||||
return new WP_Error( 'missing-version', __( 'No version received.', 'flatsome' ) );
|
||||
}
|
||||
|
||||
if ( ! is_string( $result['version'] ) ) {
|
||||
return new WP_Error( 'invalid-version', __( 'Invalid version received.', 'flatsome' ) );
|
||||
}
|
||||
|
||||
return $result['version'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a temporary download URL.
|
||||
*
|
||||
* @param string $version Version number to download.
|
||||
* @return string|WP_error
|
||||
*/
|
||||
public function get_download_url( $version ) {
|
||||
$code = $this->get_code();
|
||||
|
||||
if ( empty( $code ) ) {
|
||||
return new WP_Error( 'missing-purchase-code', __( 'Missing purchase code.', 'flatsome' ) );
|
||||
}
|
||||
|
||||
$result = $this->api->send_request( "/legacy/license/$code/download-url/$version", 'download-url' );
|
||||
|
||||
if ( is_wp_error( $result ) ) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
if ( empty( $result['url'] ) ) {
|
||||
return new WP_Error( 'missing-url', __( 'No URL received.', 'flatsome' ) );
|
||||
}
|
||||
|
||||
if ( ! is_string( $result['url'] ) ) {
|
||||
return new WP_Error( 'invalid-url', __( 'Invalid URL received.', 'flatsome' ) );
|
||||
}
|
||||
|
||||
return $result['url'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether Flatsome is registered or not.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function is_registered() {
|
||||
return $this->get_code() !== '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the registration has been verified by Envato.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function is_verified() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete options.
|
||||
*/
|
||||
public function delete_options() {
|
||||
$slug = flatsome_theme_key();
|
||||
|
||||
delete_option( $slug . '_wup_buyer' );
|
||||
delete_option( $slug . '_wup_sold_at' );
|
||||
delete_option( $slug . '_wup_purchase_code' );
|
||||
delete_option( $slug . '_wup_supported_until' );
|
||||
delete_option( $slug . '_wup_errors' );
|
||||
delete_option( $slug . '_wup_attempts' );
|
||||
|
||||
parent::delete_options();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the purchase code was registered with WPUpdates.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function get_code() {
|
||||
return get_option( flatsome_theme_key() . '_wup_purchase_code', '' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the purchase code has been verified and attempts to register the site.
|
||||
*/
|
||||
public function migrate_registration() {
|
||||
$code = $this->get_code();
|
||||
|
||||
if ( empty( $code ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$license = $this->api->send_request( "/v1/license/$code", 'wupdates' );
|
||||
|
||||
if ( is_wp_error( $license ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( empty( $license['status'] ) ) {
|
||||
return; // Wait for a verified license.
|
||||
}
|
||||
|
||||
$result = ( new Flatsome_Registration( $this->api ) )->register( $code );
|
||||
|
||||
if ( is_wp_error( $result ) ) {
|
||||
$error = $this->api->get_error( $result, 'wupdates' );
|
||||
|
||||
if ( in_array( (int) $error->get_error_code(), array( 400, 403, 409, 423 ), true ) ) {
|
||||
$this->set_errors( array( $error->get_error_message() ) );
|
||||
}
|
||||
} else {
|
||||
$this->delete_options();
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
184
wp-content/themes/flatsome/inc/classes/class-uxthemes-api.php
Normal file
184
wp-content/themes/flatsome/inc/classes/class-uxthemes-api.php
Normal file
@@ -0,0 +1,184 @@
|
||||
<?php
|
||||
/**
|
||||
* Flatsome_Registration class.
|
||||
*
|
||||
* @package Flatsome
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
/**
|
||||
* The UX Themes API.
|
||||
*/
|
||||
final class UxThemes_API {
|
||||
|
||||
/**
|
||||
* Setup instance.
|
||||
*/
|
||||
public function __construct() {
|
||||
add_filter( 'http_headers_useragent', array( $this, 'http_headers_useragent' ), 10, 2 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters the user agent value sent with an HTTP request.
|
||||
*
|
||||
* @param string $useragent WordPress user agent string.
|
||||
* @param string $url The request URL.
|
||||
* @return string
|
||||
*/
|
||||
public function http_headers_useragent( $useragent, $url = '' ) {
|
||||
if ( strpos( $url, UXTHEMES_API_URL ) !== false ) {
|
||||
$theme = wp_get_theme( get_template() );
|
||||
return 'Flatsome/' . $theme->get( 'Version' ) . '; ' . $useragent;
|
||||
}
|
||||
return $useragent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a request to the Flatsome Account API.
|
||||
*
|
||||
* @param string $path REST API path.
|
||||
* @param string $context REST API path.
|
||||
* @param array $args Request arguments.
|
||||
* @return array|WP_error
|
||||
*/
|
||||
public function send_request( $path, $context = null, $args = array() ) {
|
||||
$args = array_merge_recursive( $args, array(
|
||||
'timeout' => 60,
|
||||
'headers' => array(
|
||||
'Referer' => $this->get_site_url(),
|
||||
),
|
||||
) );
|
||||
|
||||
$url = esc_url_raw( UXTHEMES_API_URL . $path );
|
||||
$response = wp_remote_request( $url, $args );
|
||||
$status = wp_remote_retrieve_response_code( $response );
|
||||
$headers = wp_remote_retrieve_headers( $response );
|
||||
$body = wp_remote_retrieve_body( $response );
|
||||
$data = (array) json_decode( $body, true );
|
||||
|
||||
if ( is_wp_error( $response ) ) {
|
||||
return $this->get_error( $response, $context, $data );
|
||||
}
|
||||
|
||||
if ( $status === 429 ) {
|
||||
if ( isset( $headers['x-ratelimit-reset'] ) ) {
|
||||
$data['retry-after'] = (int) $headers['x-ratelimit-reset'];
|
||||
} elseif ( isset( $headers['retry-after'] ) ) {
|
||||
$data['retry-after'] = time() + ( (int) $headers['retry-after'] );
|
||||
}
|
||||
}
|
||||
|
||||
if ( $status !== 200 ) {
|
||||
$error = isset( $data['message'] )
|
||||
? new WP_Error( $status, $data['message'], $data )
|
||||
// translators: 1. The status code.
|
||||
: new WP_Error( $status, sprintf( __( 'Sorry, an error occurred while accessing the API. Error %d', 'flatsome' ), $status ), $data );
|
||||
|
||||
return $this->get_error( $error, $context, $data );
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the raw site URL.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function get_site_url() {
|
||||
global $wpdb;
|
||||
|
||||
$row = $wpdb->get_row( "SELECT option_value FROM $wpdb->options WHERE option_name = 'siteurl' LIMIT 1" );
|
||||
|
||||
if ( is_object( $row ) ) {
|
||||
return $row->option_value;
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a proper error for a HTTP status code.
|
||||
*
|
||||
* @param WP_Error $error The original error.
|
||||
* @param string $context A context.
|
||||
* @param array $data Optional data.
|
||||
* @return WP_Error
|
||||
*/
|
||||
public function get_error( $error, $context = null, $data = array() ) {
|
||||
$status = (int) $error->get_error_code();
|
||||
$account_attrs = ' href="' . esc_url_raw( UXTHEMES_ACCOUNT_URL ) . '" target="_blank" rel="noopener noreferrer"';
|
||||
|
||||
switch ( $status ) {
|
||||
case 400:
|
||||
if ( $context === 'register' ) {
|
||||
return new WP_Error( $status, __( 'Your purchase code is malformed.', 'flatsome' ), $data );
|
||||
}
|
||||
if ( $context === 'envato-register' ) {
|
||||
return new WP_Error( $status, __( 'Sorry, an error occurred. Please try again.', 'flatsome' ), $data );
|
||||
}
|
||||
if ( $context === 'latest-version' ) {
|
||||
// translators: %s: License manager link attributes.
|
||||
return new WP_Error( $status, __( 'Flatsome was unable to get the latest version. Your site might have changed domain after you registered it.', 'flatsome' ), $data );
|
||||
}
|
||||
return $error;
|
||||
case 403:
|
||||
if ( $context === 'latest-version' ) {
|
||||
return new WP_Error( $status, __( 'Flatsome was unable to get the latest version because the purchase code has not been verified yet. Please re-register it in order to receive updates.', 'flatsome' ), $data );
|
||||
}
|
||||
return $error;
|
||||
case 404:
|
||||
if ( $context === 'register' || $context === 'envato-register' || $context === 'wupdates-register' ) {
|
||||
return new WP_Error( $status, __( 'The purchase code is malformed or does not belong to a Flatsome sale.', 'flatsome' ), $data );
|
||||
}
|
||||
if ( $context === 'unregister' ) {
|
||||
// translators: %s: License manager link attributes.
|
||||
return new WP_Error( $status, sprintf( __( 'The registration was not found for <a%s>your account</a>. It was only deleted on this site.', 'flatsome' ), $account_attrs ), $data );
|
||||
}
|
||||
if ( $context === 'latest-version' ) {
|
||||
// translators: %s: License manager link attributes.
|
||||
return new WP_Error( $status, sprintf( __( 'Flatsome was unable to get the latest version. Your registration might have been deleted from <a%s>your account</a>.', 'flatsome' ), $account_attrs ), $data );
|
||||
}
|
||||
if ( $context === 'wupdates-latest-version' ) {
|
||||
return new WP_Error( $status, __( 'Flatsome was unable to get the latest version. Your purchase code is malformed.', 'flatsome' ), $data );
|
||||
}
|
||||
return $error;
|
||||
case 409:
|
||||
if ( $context === 'wupdates' ) {
|
||||
// translators: %s: License manager link attributes.
|
||||
return new WP_Error( $status, sprintf( __( 'Your purchase code has been used on too many sites. Please go to <a%s>your account</a> and manage your licenses.', 'flatsome' ), $account_attrs ), $data );
|
||||
}
|
||||
// translators: %s: License manager link attributes.
|
||||
return new WP_Error( $status, sprintf( __( 'The purchase code is already registered on another site. Please go to <a%s>your account</a> and manage your licenses.', 'flatsome' ), $account_attrs ), $data );
|
||||
case 410:
|
||||
if ( $context === 'register' || $context === 'envato-register' || $context === 'latest-version' ) {
|
||||
return new WP_Error( $status, __( 'Your purchase code has been blocked. Please contact support to resolve the issue.', 'flatsome' ), $data );
|
||||
}
|
||||
if ( $context === 'wupdates-register' ) {
|
||||
return new WP_Error( $status, __( 'The purchase code does not belong to a Flatsome sale.', 'flatsome' ), $data );
|
||||
}
|
||||
if ( $context === 'wupdates-latest-version' ) {
|
||||
return new WP_Error( $status, __( 'Flatsome was unable to get the latest version. The purchase code does not belong to a Flatsome sale.', 'flatsome' ), $data );
|
||||
}
|
||||
return new WP_Error( $status, __( 'The requested resource no longer exists.', 'flatsome' ), $data );
|
||||
case 417:
|
||||
return new WP_Error( $status, __( 'No domain was sent with the request.', 'flatsome' ), $data );
|
||||
case 422:
|
||||
return new WP_Error( $status, __( 'Unable to parse the domain for your site.', 'flatsome' ), $data );
|
||||
case 423:
|
||||
if ( $context === 'register' || $context === 'envato-register' || $context === 'latest-version' || $context === 'wupdates-latest-version' || $context === 'wupdates' ) {
|
||||
return new WP_Error( $status, __( 'Your purchase code has been locked. Please contact support to resolve the issue.', 'flatsome' ), $data );
|
||||
}
|
||||
return new WP_Error( $status, __( 'The requested resource has been locked.', 'flatsome' ), $data );
|
||||
case 429:
|
||||
return new WP_Error( $status, __( 'Sorry, the API is overloaded.', 'flatsome' ), $data );
|
||||
case 503:
|
||||
return new WP_Error( $status, __( 'Sorry, the API is unavailable at the moment.', 'flatsome' ), $data );
|
||||
default:
|
||||
return $error;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,655 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
/**
|
||||
* @class WC_Product_Data_Fields
|
||||
* @version 1.0.2
|
||||
* @category Class
|
||||
* @author Kharis Sulistiyono
|
||||
*/
|
||||
|
||||
if(!class_exists('WC_Product_Data_Fields')){
|
||||
|
||||
class WC_Product_Data_Fields {
|
||||
|
||||
public static $plugin_prefix;
|
||||
public static $plugin_url;
|
||||
public static $plugin_path;
|
||||
public static $plugin_basefile;
|
||||
|
||||
private $options_data = false;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct(){
|
||||
|
||||
WC_Product_Data_Fields::$plugin_prefix = 'wc_productdata_options_';
|
||||
WC_Product_Data_Fields::$plugin_basefile = plugin_basename(__FILE__);
|
||||
WC_Product_Data_Fields::$plugin_url = plugin_dir_url(WC_Product_Data_Fields::$plugin_basefile);
|
||||
WC_Product_Data_Fields::$plugin_path = trailingslashit(dirname(__FILE__));
|
||||
add_action('woocommerce_init', array(&$this, 'init'));
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* enqueue_scripts function.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function enqueue_scripts() {
|
||||
|
||||
wp_enqueue_style( 'wcpdf-main-css', plugins_url( 'assets/css/wcpdf-main.css' , __FILE__ ), array(), '1.0.2' );
|
||||
wp_enqueue_style( 'wp-color-picker' );
|
||||
wp_enqueue_script( 'wcpdf-main-js', plugins_url( 'assets/js/wcpdf-main.js' , __FILE__ ), array('jquery', 'wp-color-picker', 'jquery-ui-datepicker'), '', true );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets saved data
|
||||
* It is used for displaying the data value in template file
|
||||
* @return array
|
||||
*/
|
||||
public function get_value($post_id, $field_id){
|
||||
|
||||
$meta = get_post_meta( $post_id, 'wc_productdata_options', true );
|
||||
$value = '';
|
||||
|
||||
if ( is_array( $meta ) ) {
|
||||
$meta = $meta[0];
|
||||
if ( isset( $meta[ $field_id ] ) ) {
|
||||
$value = $meta[ $field_id ];
|
||||
};
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Init WooCommerce Custom Product Data Fields extension once we know WooCommerce is active
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function init(){
|
||||
|
||||
add_action('woocommerce_product_write_panel_tabs', array($this, 'product_write_panel_tab'));
|
||||
add_action('woocommerce_product_data_panels', array($this, 'product_write_panel'));
|
||||
add_action('woocommerce_process_product_meta', array($this, 'product_save_data'), 10, 2);
|
||||
// add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts') );
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create fields via hook
|
||||
* @return null if no hook applied
|
||||
*/
|
||||
public function wc_cpdf_fields(){
|
||||
|
||||
return apply_filters('wc_cpdf_init', null);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds a new tab to the Product Data postbox in the admin product interface
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function product_write_panel_tab(){
|
||||
|
||||
$fields = $this->wc_cpdf_fields();
|
||||
|
||||
if($fields == null){
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($fields as $key => $fields_array){
|
||||
|
||||
foreach ($fields_array as $field) {
|
||||
if(isset($field['tab_name']) && $field['tab_name'] != ''){
|
||||
$href = "#".$key;
|
||||
echo "<li class=".$key."><a href=".$href."><span>".$field['tab_name']."</span></a></li>";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds the panel to the Product Data postbox in the product interface
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function product_write_panel(){
|
||||
|
||||
global $post;
|
||||
|
||||
// Pull the field data out of the database
|
||||
$available_fields = array();
|
||||
$available_fields[] = maybe_unserialize(get_post_meta($post->ID, 'wc_productdata_options', true));
|
||||
|
||||
if($available_fields){
|
||||
|
||||
// Display fields panel
|
||||
foreach($available_fields as $available_field){
|
||||
|
||||
$fields = $this->wc_cpdf_fields();
|
||||
|
||||
if($fields == null){
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
foreach ($fields as $key => $fields_array){
|
||||
|
||||
echo '<div id="'.$key.'" class="panel woocommerce_options_panel wc_cpdf_tab">';
|
||||
|
||||
foreach ($fields_array as $field) {
|
||||
|
||||
if( ! isset( $field['tab_name'] ) ){
|
||||
|
||||
WC_Product_Data_Fields::wc_product_data_options_fields($field);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
echo '</div>';
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create Fields
|
||||
*
|
||||
* @param $field array
|
||||
* @return string
|
||||
*/
|
||||
public function wc_product_data_options_fields($field){
|
||||
global $thepostid, $post, $woocommerce;
|
||||
|
||||
$fieldtype = isset( $field['type'] ) ? $field['type'] : '';
|
||||
$field_id = isset( $field['id'] ) ? $field['id'] : '';
|
||||
|
||||
$thepostid = empty( $thepostid ) ? $post->ID : $thepostid;
|
||||
|
||||
|
||||
$options_data = maybe_unserialize(get_post_meta($thepostid, 'wc_productdata_options', true));
|
||||
|
||||
switch($fieldtype){
|
||||
|
||||
case 'text':
|
||||
$thepostid = empty( $thepostid ) ? $post->ID : $thepostid;
|
||||
$field['placeholder'] = isset( $field['placeholder'] ) ? $field['placeholder'] : '';
|
||||
$field['class'] = isset( $field['class'] ) ? $field['class'] : 'short';
|
||||
$field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
|
||||
$field['value'] = isset( $field['value'] ) ? $field['value'] : get_post_meta( $thepostid, $field['id'], true );
|
||||
$field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id'];
|
||||
$field['type'] = isset( $field['type'] ) ? $field['type'] : 'text';
|
||||
|
||||
$inputval = isset( $options_data[0][$field_id] ) ? $options_data[0][$field_id] : '';
|
||||
|
||||
echo '<p class="form-field '.esc_attr($field['id']).'_field '.esc_attr($field['wrapper_class']).'"><label for="'.esc_attr($field['id']).'">'.wp_kses_post($field['label']).'</label><input type="'.esc_attr($field['type']).'" class="'.esc_attr($field['class']).'" name="'.esc_attr($field['name']).'" id="'.esc_attr($field['id']).'" value="'.esc_attr($inputval).'" placeholder="'.esc_attr($field['placeholder']).'"'.(isset($field['style']) ? ' style="'.$field['style'].'"' : '').' /> ';
|
||||
|
||||
if ( ! empty( $field['description'] ) ) {
|
||||
|
||||
if ( isset( $field['desc_tip'] ) && false !== $field['desc_tip'] ) {
|
||||
echo '<img class="help_tip" data-tip="' . esc_attr( $field['description'] ) . '" src="' . esc_url( WC()->plugin_url() ) . '/assets/images/help.png" height="16" width="16" />';
|
||||
} else {
|
||||
echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
echo '</p>';
|
||||
break;
|
||||
|
||||
case 'number':
|
||||
$thepostid = empty( $thepostid ) ? $post->ID : $thepostid;
|
||||
$field['placeholder'] = isset( $field['placeholder'] ) ? $field['placeholder'] : '';
|
||||
$field['class'] = isset( $field['class'] ) ? $field['class'] : 'short';
|
||||
$field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
|
||||
$field['value'] = isset( $field['value'] ) ? $field['value'] : get_post_meta( $thepostid, $field['id'], true );
|
||||
$field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id'];
|
||||
$field['type'] = isset( $field['type'] ) ? $field['type'] : 'text';
|
||||
|
||||
$inputval = isset( $options_data[0][$field_id] ) ? $options_data[0][$field_id] : '';
|
||||
|
||||
echo '<p class="form-field '.esc_attr($field['id']).'_field '.esc_attr($field['wrapper_class']).'"><label for="'.esc_attr($field['id']).'">'.wp_kses_post($field['label']).'</label><input type="'.esc_attr($field['type']).'" class="'.esc_attr($field['class']).'" name="'.esc_attr($field['name']).'" id="'.esc_attr($field['id']).'" value="'.esc_attr($inputval).'" placeholder="'.esc_attr($field['placeholder']).'"'.(isset($field['style']) ? ' style="'.$field['style'].'"' : '').' /> ';
|
||||
|
||||
if ( ! empty( $field['description'] ) ) {
|
||||
|
||||
if ( isset( $field['desc_tip'] ) && false !== $field['desc_tip'] ) {
|
||||
echo '<img class="help_tip" data-tip="' . esc_attr( $field['description'] ) . '" src="' . esc_url( WC()->plugin_url() ) . '/assets/images/help.png" height="16" width="16" />';
|
||||
} else {
|
||||
echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
echo '</p>';
|
||||
break;
|
||||
|
||||
case 'textarea':
|
||||
if(!$thepostid) $thepostid = $post->ID;
|
||||
if(!isset($field['placeholder'])) $field['placeholder'] = '';
|
||||
if(!isset($field['class'])) $field['class'] = 'short';
|
||||
if(!isset($field['value'])) $field['value'] = get_post_meta($thepostid, $field['id'], true);
|
||||
|
||||
$inputval = isset( $options_data[0][$field_id] ) ? $options_data[0][$field_id] : '';
|
||||
|
||||
echo '<p class="form-field '.$field['id'].'_field"><label for="'.$field['id'].'">'.$field['label'].'</label><textarea class="'.$field['class'].'" name="'.$field['id'].'" id="'.$field['id'].'" placeholder="'.$field['placeholder'].'" rows="2" cols="20"'.(isset($field['style']) ? ' style="'.$field['style'].'"' : '').'">'.esc_textarea($inputval).'</textarea>';
|
||||
|
||||
if ( ! empty( $field['description'] ) ) {
|
||||
|
||||
if ( isset( $field['desc_tip'] ) && false !== $field['desc_tip'] ) {
|
||||
echo '<img class="help_tip" data-tip="' . esc_attr( $field['description'] ) . '" src="' . esc_url( WC()->plugin_url() ) . '/assets/images/help.png" height="16" width="16" />';
|
||||
} else {
|
||||
echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
echo '</p>';
|
||||
break;
|
||||
|
||||
|
||||
case 'checkbox':
|
||||
$thepostid = empty( $thepostid ) ? $post->ID : $thepostid;
|
||||
$field['class'] = isset( $field['class'] ) ? $field['class'] : 'checkbox';
|
||||
$field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
|
||||
$field['value'] = isset( $options_data[0][$field_id] ) ? $options_data[0][$field_id] : '';
|
||||
$field['cbvalue'] = isset( $field['cbvalue'] ) ? $field['cbvalue'] : 'yes';
|
||||
$field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id'];
|
||||
|
||||
echo '<p class="form-field ' . esc_attr( $field['id'] ) . '_field ' . esc_attr( $field['wrapper_class'] ) . '"><label for="' . esc_attr( $field['id'] ) . '">' . wp_kses_post( $field['label'] ) . '</label><input type="checkbox" class="' . esc_attr( $field['class'] ) . '" name="' . esc_attr( $field['name'] ) . '" id="' . esc_attr( $field['id'] ) . '" value="' . esc_attr( $field['cbvalue'] ) . '" ' . checked( $field['value'], $field['cbvalue'], false ) . ' /> ';
|
||||
|
||||
if ( ! empty( $field['description'] ) ) {
|
||||
|
||||
if ( isset( $field['desc_tip'] ) && false !== $field['desc_tip'] ) {
|
||||
echo '<img class="help_tip" data-tip="' . esc_attr( $field['description'] ) . '" src="' . esc_url( WC()->plugin_url() ) . '/assets/images/help.png" height="16" width="16" />';
|
||||
} else {
|
||||
echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
echo '</p>';
|
||||
break;
|
||||
|
||||
case 'select':
|
||||
$thepostid = empty( $thepostid ) ? $post->ID : $thepostid;
|
||||
$field['class'] = isset( $field['class'] ) ? $field['class'] : 'select short';
|
||||
$field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
|
||||
$field['value'] = isset( $options_data[0][$field_id] ) ? $options_data[0][$field_id] : '';
|
||||
|
||||
echo '<p class="form-field ' . esc_attr( $field['id'] ) . '_field ' . esc_attr( $field['wrapper_class'] ) . '"><label for="' . esc_attr( $field['id'] ) . '">' . wp_kses_post( $field['label'] ) . '</label><select id="' . esc_attr( $field['id'] ) . '" name="' . esc_attr( $field['id'] ) . '" class="' . esc_attr( $field['class'] ) . '">';
|
||||
|
||||
foreach ( $field['options'] as $key => $value ) {
|
||||
|
||||
echo '<option value="' . esc_attr( $key ) . '" ' . selected( esc_attr( $field['value'] ), esc_attr( $key ), false ) . '>' . esc_html( $value ) . '</option>';
|
||||
|
||||
}
|
||||
|
||||
echo '</select> ';
|
||||
|
||||
if ( ! empty( $field['description'] ) ) {
|
||||
|
||||
if ( isset( $field['desc_tip'] ) && false !== $field['desc_tip'] ) {
|
||||
echo '<img class="help_tip" data-tip="' . esc_attr( $field['description'] ) . '" src="' . esc_url( WC()->plugin_url() ) . '/assets/images/help.png" height="16" width="16" />';
|
||||
} else {
|
||||
echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>';
|
||||
}
|
||||
|
||||
}
|
||||
echo '</p>';
|
||||
break;
|
||||
|
||||
|
||||
case 'radio':
|
||||
$thepostid = empty( $thepostid ) ? $post->ID : $thepostid;
|
||||
$field['class'] = isset( $field['class'] ) ? $field['class'] : 'select short';
|
||||
$field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
|
||||
$field['value'] = isset( $options_data[0][$field_id] ) ? $options_data[0][$field_id] : '';
|
||||
$field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id'];
|
||||
|
||||
echo '<fieldset class="form-field ' . esc_attr( $field['id'] ) . '_field ' . esc_attr( $field['wrapper_class'] ) . '"><legend style="float:left; width:150px;">' . wp_kses_post( $field['label'] ) . '</legend><ul class="wc-radios" style="width: 25%; float:left;">';
|
||||
|
||||
foreach ( $field['options'] as $key => $value ) {
|
||||
|
||||
echo '<li style="padding-bottom: 3px; margin-bottom: 0;"><label style="float:none; width: auto; margin-left: 0;"><input
|
||||
name="' . esc_attr( $field['name'] ) . '"
|
||||
value="' . esc_attr( $key ) . '"
|
||||
type="radio"
|
||||
class="' . esc_attr( $field['class'] ) . '"
|
||||
' . checked( esc_attr( $field['value'] ), esc_attr( $key ), false ) . '
|
||||
/> ' . esc_html( $value ) . '</label>
|
||||
</li>';
|
||||
}
|
||||
echo '</ul>';
|
||||
|
||||
if ( ! empty( $field['description'] ) ) {
|
||||
|
||||
if ( isset( $field['desc_tip'] ) && false !== $field['desc_tip'] ) {
|
||||
echo '<img class="help_tip" data-tip="' . esc_attr( $field['description'] ) . '" src="' . esc_url( WC()->plugin_url() ) . '/assets/images/help.png" height="16" width="16" />';
|
||||
} else {
|
||||
echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
echo '</fieldset>';
|
||||
break;
|
||||
|
||||
|
||||
case 'hidden':
|
||||
$thepostid = empty( $thepostid ) ? $post->ID : $thepostid;
|
||||
$field['value'] = isset( $field['value'] ) ? $field['value'] : $options_data[0][$field_id];
|
||||
$field['class'] = isset( $field['class'] ) ? $field['class'] : '';
|
||||
|
||||
echo '<input type="hidden" class="' . esc_attr( $field['class'] ) . '" name="' . esc_attr( $field['id'] ) . '" id="' . esc_attr( $field['id'] ) . '" value="' . esc_attr( $field['value'] ) . '" /> ';
|
||||
|
||||
break;
|
||||
|
||||
|
||||
case 'multiselect':
|
||||
|
||||
global $wc_cpdf;
|
||||
|
||||
if(!$thepostid) $thepostid = $post->ID;
|
||||
if(!isset($field['placeholder'])) $field['placeholder'] = '';
|
||||
if(!isset($field['class'])) $field['class'] = 'short';
|
||||
if(!isset($field['value'])) $field['value'] = get_post_meta($thepostid, $field['id'], true);
|
||||
|
||||
$inputval = isset( $options_data[0][$field_id] ) ? $options_data[0][$field_id] : '';
|
||||
|
||||
$html = '<p class="form-field '.$field['id'].'_field"><label for="'.$field['id'].'">'.$field['label'].'</label>';
|
||||
|
||||
$html .= '';
|
||||
|
||||
$html .= '<select multiple="multiple" class="multiselect wc-enhanced-select '.$field['class'].'" name="' . esc_attr( $field['id'] ) . '[]" style="width: 90%;" data-placeholder="'.$field['placeholder'].'">';
|
||||
|
||||
$saved_val = $wc_cpdf->get_value($thepostid, $field['id']) ? $wc_cpdf->get_value($thepostid, $field['id']) : array();
|
||||
|
||||
foreach ( $field['options'] as $key => $value ) {
|
||||
|
||||
$html .= '<option value="' . esc_attr( $key ) . '" '.selected( in_array( $key, $saved_val ), true, false ).'>' . esc_html( $value ) . '</option>';
|
||||
|
||||
}
|
||||
|
||||
$html .= '</select>';
|
||||
|
||||
if ( ! empty( $field['description'] ) ) {
|
||||
|
||||
if ( isset( $field['desc_tip'] ) && false !== $field['desc_tip'] ) {
|
||||
$html .= '<img class="help_tip" data-tip="' . esc_attr( $field['description'] ) . '" src="' . esc_url( WC()->plugin_url() ) . '/assets/images/help.png" height="16" width="16" />';
|
||||
} else {
|
||||
$html .= '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$html .= '</p>';
|
||||
|
||||
echo $html;
|
||||
|
||||
break;
|
||||
|
||||
|
||||
case 'image':
|
||||
|
||||
global $wc_cpdf;
|
||||
|
||||
$saved_image = $wc_cpdf->get_value($thepostid, $field['id']);
|
||||
$saved_image_url = wp_get_attachment_image_src($saved_image);
|
||||
$saved_image_url_thumb = wp_get_attachment_image_src($saved_image, 'thumbnail', true);
|
||||
|
||||
?>
|
||||
|
||||
<div class="image-field-wrapper form-field">
|
||||
|
||||
<div class="image-field-label">
|
||||
|
||||
<?php echo '<span>'.$field['label'].'</span>'; ?>
|
||||
|
||||
</div>
|
||||
|
||||
<div id="image-uploader-meta-box" class="image-field-upload">
|
||||
|
||||
<div class="preview-image-wrapper">
|
||||
|
||||
<?php if($saved_image) :?>
|
||||
|
||||
<img class="wcpdf_saved_image" src="<?php echo esc_url($saved_image_url_thumb[0]); ?>" alt="" />
|
||||
<a href="#" class="remove_image wcpdf-remove-image"><em><?php echo __('Remove', 'wc_cpdf'); ?></em></a>
|
||||
|
||||
<?php endif; ?>
|
||||
|
||||
</div>
|
||||
|
||||
<input class="wcpdf_image_id" type="hidden" name="<?php echo esc_attr($field['id']); ?>" value="<?php echo ($saved_image) ? $saved_image : ''; ?>" />
|
||||
<input class="wcpdf_image_url" type="hidden" name="wcpdf_image_url_<?php echo $field['id']; ?>" value="<?php echo ($saved_image) ? $saved_image_url[0] : ''; ?>" />
|
||||
<a class="wcpdf-uppload-image button" href="#" data-uploader-title="<?php echo __('Choose image', 'wc_cpdf') ?>" data-uploader-button-text="<?php echo __('Choose image', 'wc_cpdf') ?>"><?php echo __('Choose image', 'wc_cpdf') ?></a>
|
||||
|
||||
<?php
|
||||
if ( ! empty( $field['description'] ) ) {
|
||||
|
||||
if ( isset( $field['desc_tip'] ) && false !== $field['desc_tip'] ) {
|
||||
echo '<img class="help_tip" data-tip="' . esc_attr( $field['description'] ) . '" src="' . esc_url( WC()->plugin_url() ) . '/assets/images/help.png" height="16" width="16" />';
|
||||
} else {
|
||||
echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>';
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
|
||||
</div>
|
||||
|
||||
</div><!-- /.image-field-wrapper -->
|
||||
|
||||
<?php
|
||||
|
||||
break;
|
||||
|
||||
case 'gallery':
|
||||
|
||||
global $wc_cpdf;
|
||||
|
||||
$saved_gallery = $wc_cpdf->get_value($thepostid, $field['id']);
|
||||
|
||||
?>
|
||||
|
||||
<div class="image-field-wrapper gallery form-field">
|
||||
|
||||
<div class="image-field-label">
|
||||
|
||||
<?php echo '<span>'.$field['label'].'</span>'; ?>
|
||||
|
||||
</div>
|
||||
|
||||
<div id="image-uploader-meta-box" class="image-field-upload">
|
||||
|
||||
<div class="preview-image-wrapper">
|
||||
|
||||
<?php
|
||||
|
||||
if(is_array($saved_gallery)): foreach ($saved_gallery as $img_id){
|
||||
$saved_image_url = wp_get_attachment_image_src($img_id);
|
||||
$saved_image_url_thumb = wp_get_attachment_image_src($img_id, 'thumbnail', true);
|
||||
|
||||
?>
|
||||
|
||||
<div class="gal-item">
|
||||
<img class="wcpdf_saved_image" src="<?php echo esc_url($saved_image_url_thumb[0]); ?>" alt="" />
|
||||
<a href="#" class="remove_image wcpdf-remove-image"><em><?php echo __('Remove', 'wc_cpdf'); ?></em></a>
|
||||
<input type="hidden" name="<?php echo esc_attr($field['id']); ?>[]" value="<?php echo esc_attr($img_id); ?>" />
|
||||
</div>
|
||||
|
||||
<?php } endif; ?>
|
||||
|
||||
</div>
|
||||
|
||||
<input class="wcpdf_image_id" type="hidden" data-name="<?php echo esc_attr($field['id']); ?>" name="name-needle" value="" />
|
||||
<input class="wcpdf_image_url" type="hidden" name="wcpdf_image_url_<?php echo $field['id']; ?>" value="<?php echo ($saved_image) ? $saved_image_url[0] : ''; ?>" />
|
||||
<a class="wcpdf-uppload-image-gallery button" href="#" data-uploader-title="<?php echo __('Choose images', 'wc_cpdf') ?>" data-uploader-button-text="<?php echo __('Choose images', 'wc_cpdf') ?>"><?php echo __('Choose images', 'wc_cpdf') ?></a>
|
||||
|
||||
<?php
|
||||
if ( ! empty( $field['description'] ) ) {
|
||||
|
||||
if ( isset( $field['desc_tip'] ) && false !== $field['desc_tip'] ) {
|
||||
echo '<img class="help_tip" data-tip="' . esc_attr( $field['description'] ) . '" src="' . esc_url( WC()->plugin_url() ) . '/assets/images/help.png" height="16" width="16" />';
|
||||
} else {
|
||||
echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>';
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
|
||||
</div>
|
||||
|
||||
</div><!-- /.image-field-wrapper -->
|
||||
|
||||
<?php
|
||||
break;
|
||||
|
||||
|
||||
case 'color':
|
||||
|
||||
$thepostid = empty( $thepostid ) ? $post->ID : $thepostid;
|
||||
$field['placeholder'] = isset( $field['placeholder'] ) ? $field['placeholder'] : '';
|
||||
$field['class'] = isset( $field['class'] ) ? $field['class'] : 'short';
|
||||
$field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
|
||||
$field['value'] = isset( $field['value'] ) ? $field['value'] : get_post_meta( $thepostid, $field['id'], true );
|
||||
$field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id'];
|
||||
$field['type'] = isset( $field['type'] ) ? $field['type'] : 'text';
|
||||
|
||||
$inputval = isset( $options_data[0][$field_id] ) ? $options_data[0][$field_id] : '';
|
||||
|
||||
echo '<p class="form-field '.esc_attr($field['id']).'_field '.esc_attr($field['wrapper_class']).'"><label for="'.esc_attr($field['id']).'">'.wp_kses_post($field['label']).'</label><input type="text" class="'.esc_attr($field['class']).' wc_cpdf_colorpicker" name="'.esc_attr($field['name']).'" id="'.esc_attr($field['id']).'" value="'.esc_attr($inputval).'" placeholder="'.esc_attr($field['placeholder']).'"'.(isset($field['style']) ? ' style="'.$field['style'].'"' : '').' /> ';
|
||||
|
||||
if ( ! empty( $field['description'] ) ) {
|
||||
|
||||
if ( isset( $field['desc_tip'] ) && false !== $field['desc_tip'] ) {
|
||||
echo '<img class="help_tip" data-tip="' . esc_attr( $field['description'] ) . '" src="' . esc_url( WC()->plugin_url() ) . '/assets/images/help.png" height="16" width="16" />';
|
||||
} else {
|
||||
echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
echo '</p>';
|
||||
|
||||
break;
|
||||
|
||||
|
||||
case 'datepicker':
|
||||
|
||||
$thepostid = empty( $thepostid ) ? $post->ID : $thepostid;
|
||||
$field['placeholder'] = isset( $field['placeholder'] ) ? $field['placeholder'] : '';
|
||||
$field['class'] = isset( $field['class'] ) ? $field['class'] : 'short';
|
||||
$field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
|
||||
$field['value'] = isset( $field['value'] ) ? $field['value'] : get_post_meta( $thepostid, $field['id'], true );
|
||||
$field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id'];
|
||||
$field['type'] = isset( $field['type'] ) ? $field['type'] : 'text';
|
||||
|
||||
$inputval = isset( $options_data[0][$field_id] ) ? $options_data[0][$field_id] : '';
|
||||
|
||||
echo '<p class="form-field '.esc_attr($field['id']).'_field '.esc_attr($field['wrapper_class']).'"><label for="'.esc_attr($field['id']).'">'.wp_kses_post($field['label']).'</label><input type="text" class="'.esc_attr($field['class']).' wc_cpdf_datepicker" name="'.esc_attr($field['name']).'" id="'.esc_attr($field['id']).'" value="'.esc_attr($inputval).'" placeholder="'.esc_attr($field['placeholder']).'"'.(isset($field['style']) ? ' style="'.$field['style'].'"' : '').' /> ';
|
||||
|
||||
if ( ! empty( $field['description'] ) ) {
|
||||
|
||||
if ( isset( $field['desc_tip'] ) && false !== $field['desc_tip'] ) {
|
||||
echo '<img class="help_tip" data-tip="' . esc_attr( $field['description'] ) . '" src="' . esc_url( WC()->plugin_url() ) . '/assets/images/help.png" height="16" width="16" />';
|
||||
} else {
|
||||
echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
echo '</p>';
|
||||
|
||||
break;
|
||||
|
||||
|
||||
case 'divider':
|
||||
|
||||
echo '<div class="divider" style="border-bottom: 1px solid #eee;"></div>';
|
||||
|
||||
break;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Saves the data inputed into the product boxes, as post meta data
|
||||
* identified by the name 'wc_productdata_options'
|
||||
*
|
||||
* @param int $post_id the post (product) identifier
|
||||
* @param stdClass $post the post (product)
|
||||
* @return void
|
||||
*/
|
||||
public function product_save_data($post_id, $post){
|
||||
|
||||
$options_value = array();
|
||||
|
||||
/** field name in pairs array **/
|
||||
$data_args = array();
|
||||
$fields = $this->wc_cpdf_fields();
|
||||
|
||||
if($fields == null){
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($fields as $key => $fields_array){
|
||||
|
||||
foreach ($fields_array as $data) {
|
||||
|
||||
if ( isset( $data['id'] ) ) {
|
||||
$data_args[ $data['id'] ] = maybe_unserialize( $_POST[ $data['id'] ] );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$options_value[] = $data_args;
|
||||
|
||||
// save the data to the database
|
||||
update_post_meta($post_id, 'wc_productdata_options', $options_value);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Instantiate Class
|
||||
*/
|
||||
|
||||
$GLOBALS['wc_cpdf'] = new WC_Product_Data_Fields();
|
Reference in New Issue
Block a user