updated plugin GP Premium
version 2.0.3
This commit is contained in:
@ -7,7 +7,7 @@ if ( ! defined( 'ABSPATH' ) ) exit;
|
||||
* Allows plugins to use their own update API.
|
||||
*
|
||||
* @author Easy Digital Downloads
|
||||
* @version 1.7.1
|
||||
* @version 1.8.0
|
||||
*/
|
||||
class EDD_SL_Plugin_Updater {
|
||||
|
||||
@ -106,47 +106,50 @@ class EDD_SL_Plugin_Updater {
|
||||
return $_transient_data;
|
||||
}
|
||||
|
||||
$current = $this->get_repo_api_data();
|
||||
if ( false !== $current && is_object( $current ) && isset( $current->new_version ) ) {
|
||||
if ( version_compare( $this->version, $current->new_version, '<' ) ) {
|
||||
$_transient_data->response[ $this->name ] = $current;
|
||||
} else {
|
||||
// Populating the no_update information is required to support auto-updates in WordPress 5.5.
|
||||
$_transient_data->no_update[ $this->name ] = $current;
|
||||
}
|
||||
}
|
||||
$_transient_data->last_checked = time();
|
||||
$_transient_data->checked[ $this->name ] = $this->version;
|
||||
|
||||
return $_transient_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get repo API data from store.
|
||||
* Save to cache.
|
||||
*
|
||||
* @return \stdClass
|
||||
*/
|
||||
public function get_repo_api_data() {
|
||||
$version_info = $this->get_cached_version_info();
|
||||
|
||||
if ( false === $version_info ) {
|
||||
$version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug, 'beta' => $this->beta ) );
|
||||
$version_info = $this->api_request(
|
||||
'plugin_latest_version',
|
||||
array(
|
||||
'slug' => $this->slug,
|
||||
'beta' => $this->beta,
|
||||
)
|
||||
);
|
||||
if ( ! $version_info ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// This is required for your plugin to support auto-updates in WordPress 5.5.
|
||||
$version_info->plugin = $this->name;
|
||||
$version_info->id = $this->name;
|
||||
|
||||
$this->set_version_info_cache( $version_info );
|
||||
|
||||
}
|
||||
|
||||
if ( false !== $version_info && is_object( $version_info ) && isset( $version_info->new_version ) ) {
|
||||
|
||||
$no_update = false;
|
||||
if ( version_compare( $this->version, $version_info->new_version, '<' ) ) {
|
||||
|
||||
$_transient_data->response[ $this->name ] = $version_info;
|
||||
|
||||
// Make sure the plugin property is set to the plugin's name/location. See issue 1463 on Software Licensing's GitHub repo.
|
||||
$_transient_data->response[ $this->name ]->plugin = $this->name;
|
||||
|
||||
} else {
|
||||
$no_update = new stdClass();
|
||||
$no_update->id = '';
|
||||
$no_update->slug = $this->slug;
|
||||
$no_update->plugin = $this->name;
|
||||
$no_update->new_version = $version_info->new_version;
|
||||
$no_update->url = $version_info->homepage;
|
||||
$no_update->package = $version_info->package;
|
||||
$no_update->icons = $version_info->icons;
|
||||
$no_update->banners = $version_info->banners;
|
||||
$no_update->banners_rtl = array();
|
||||
}
|
||||
|
||||
$_transient_data->last_checked = time();
|
||||
$_transient_data->checked[ $this->name ] = $this->version;
|
||||
|
||||
if ( $no_update ) {
|
||||
$_transient_data->no_update[ $this->name ] = $no_update;
|
||||
}
|
||||
}
|
||||
|
||||
return $_transient_data;
|
||||
return $version_info;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -182,7 +185,7 @@ class EDD_SL_Plugin_Updater {
|
||||
|
||||
if ( empty( $update_cache->response ) || empty( $update_cache->response[ $this->name ] ) ) {
|
||||
|
||||
$version_info = $this->get_cached_version_info();
|
||||
$version_info = $this->get_repo_api_data();
|
||||
|
||||
if ( false === $version_info ) {
|
||||
$version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug, 'beta' => $this->beta ) );
|
||||
@ -211,29 +214,14 @@ class EDD_SL_Plugin_Updater {
|
||||
return;
|
||||
}
|
||||
|
||||
$no_update = false;
|
||||
if ( version_compare( $this->version, $version_info->new_version, '<' ) ) {
|
||||
|
||||
$update_cache->response[ $this->name ] = $version_info;
|
||||
|
||||
} else {
|
||||
$no_update = new stdClass();
|
||||
$no_update->id = '';
|
||||
$no_update->slug = $this->slug;
|
||||
$no_update->plugin = $this->name;
|
||||
$no_update->new_version = $version_info->new_version;
|
||||
$no_update->url = $version_info->homepage;
|
||||
$no_update->package = $version_info->package;
|
||||
$no_update->icons = $version_info->icons;
|
||||
$no_update->banners = $version_info->banners;
|
||||
$no_update->banners_rtl = array();
|
||||
$update_cache->no_update[ $this->name ] = $version_info;
|
||||
}
|
||||
|
||||
$update_cache->last_checked = time();
|
||||
$update_cache->checked[ $this->name ] = $this->version;
|
||||
if ( $no_update ) {
|
||||
$update_cache->no_update[ $this->name ] = $no_update;
|
||||
}
|
||||
|
||||
set_site_transient( 'update_plugins', $update_cache );
|
||||
|
||||
@ -437,16 +425,16 @@ class EDD_SL_Plugin_Updater {
|
||||
}
|
||||
|
||||
if ( false === $edd_plugin_url_available[ $store_hash ] ) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
$data = array_merge( $this->api_data, $_data );
|
||||
|
||||
if ( $data['slug'] != $this->slug ) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
if( $this->api_url == trailingslashit ( home_url() ) ) {
|
||||
if ( $this->api_url == trailingslashit ( home_url() ) ) {
|
||||
return false; // Don't allow a plugin to ping itself
|
||||
}
|
||||
|
||||
@ -482,7 +470,7 @@ class EDD_SL_Plugin_Updater {
|
||||
$request->icons = maybe_unserialize( $request->icons );
|
||||
}
|
||||
|
||||
if( ! empty( $request->sections ) ) {
|
||||
if ( ! empty( $request->sections ) ) {
|
||||
foreach( $request->sections as $key => $section ) {
|
||||
$request->$key = (array) $section;
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
@ -1,163 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* WP Async Request
|
||||
*
|
||||
* @package WP-Background-Processing
|
||||
*/
|
||||
|
||||
if ( ! class_exists( 'WP_Async_Request' ) ) {
|
||||
|
||||
/**
|
||||
* Abstract WP_Async_Request class.
|
||||
*
|
||||
* @abstract
|
||||
*/
|
||||
abstract class WP_Async_Request {
|
||||
|
||||
/**
|
||||
* Prefix
|
||||
*
|
||||
* (default value: 'wp')
|
||||
*
|
||||
* @var string
|
||||
* @access protected
|
||||
*/
|
||||
protected $prefix = 'wp';
|
||||
|
||||
/**
|
||||
* Action
|
||||
*
|
||||
* (default value: 'async_request')
|
||||
*
|
||||
* @var string
|
||||
* @access protected
|
||||
*/
|
||||
protected $action = 'async_request';
|
||||
|
||||
/**
|
||||
* Identifier
|
||||
*
|
||||
* @var mixed
|
||||
* @access protected
|
||||
*/
|
||||
protected $identifier;
|
||||
|
||||
/**
|
||||
* Data
|
||||
*
|
||||
* (default value: array())
|
||||
*
|
||||
* @var array
|
||||
* @access protected
|
||||
*/
|
||||
protected $data = array();
|
||||
|
||||
/**
|
||||
* Initiate new async request
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->identifier = $this->prefix . '_' . $this->action;
|
||||
|
||||
add_action( 'wp_ajax_' . $this->identifier, array( $this, 'maybe_handle' ) );
|
||||
add_action( 'wp_ajax_nopriv_' . $this->identifier, array( $this, 'maybe_handle' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set data used during the request
|
||||
*
|
||||
* @param array $data Data.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function data( $data ) {
|
||||
$this->data = $data;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatch the async request
|
||||
*
|
||||
* @return array|WP_Error
|
||||
*/
|
||||
public function dispatch() {
|
||||
$url = add_query_arg( $this->get_query_args(), $this->get_query_url() );
|
||||
$args = $this->get_post_args();
|
||||
|
||||
return wp_remote_post( esc_url_raw( $url ), $args );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get query args
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function get_query_args() {
|
||||
if ( property_exists( $this, 'query_args' ) ) {
|
||||
return $this->query_args;
|
||||
}
|
||||
|
||||
return array(
|
||||
'action' => $this->identifier,
|
||||
'nonce' => wp_create_nonce( $this->identifier ),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get query URL
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function get_query_url() {
|
||||
if ( property_exists( $this, 'query_url' ) ) {
|
||||
return $this->query_url;
|
||||
}
|
||||
|
||||
return admin_url( 'admin-ajax.php' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get post args
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function get_post_args() {
|
||||
if ( property_exists( $this, 'post_args' ) ) {
|
||||
return $this->post_args;
|
||||
}
|
||||
|
||||
return array(
|
||||
'timeout' => 0.01,
|
||||
'blocking' => false,
|
||||
'body' => $this->data,
|
||||
'cookies' => $_COOKIE,
|
||||
'sslverify' => apply_filters( 'https_local_ssl_verify', false ),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Maybe handle
|
||||
*
|
||||
* Check for correct nonce and pass to handler.
|
||||
*/
|
||||
public function maybe_handle() {
|
||||
// Don't lock up other requests while processing
|
||||
session_write_close();
|
||||
|
||||
check_ajax_referer( $this->identifier, 'nonce' );
|
||||
|
||||
$this->handle();
|
||||
|
||||
wp_die();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle
|
||||
*
|
||||
* Override this method to perform any actions required
|
||||
* during the async request.
|
||||
*/
|
||||
abstract protected function handle();
|
||||
|
||||
}
|
||||
}
|
@ -1,506 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* WP Background Process
|
||||
*
|
||||
* @package WP-Background-Processing
|
||||
*/
|
||||
|
||||
if ( ! class_exists( 'WP_Background_Process' ) ) {
|
||||
|
||||
/**
|
||||
* Abstract WP_Background_Process class.
|
||||
*
|
||||
* @abstract
|
||||
* @extends WP_Async_Request
|
||||
*/
|
||||
abstract class WP_Background_Process extends WP_Async_Request {
|
||||
|
||||
/**
|
||||
* Action
|
||||
*
|
||||
* (default value: 'background_process')
|
||||
*
|
||||
* @var string
|
||||
* @access protected
|
||||
*/
|
||||
protected $action = 'background_process';
|
||||
|
||||
/**
|
||||
* Start time of current process.
|
||||
*
|
||||
* (default value: 0)
|
||||
*
|
||||
* @var int
|
||||
* @access protected
|
||||
*/
|
||||
protected $start_time = 0;
|
||||
|
||||
/**
|
||||
* Cron_hook_identifier
|
||||
*
|
||||
* @var mixed
|
||||
* @access protected
|
||||
*/
|
||||
protected $cron_hook_identifier;
|
||||
|
||||
/**
|
||||
* Cron_interval_identifier
|
||||
*
|
||||
* @var mixed
|
||||
* @access protected
|
||||
*/
|
||||
protected $cron_interval_identifier;
|
||||
|
||||
/**
|
||||
* Initiate new background process
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
|
||||
$this->cron_hook_identifier = $this->identifier . '_cron';
|
||||
$this->cron_interval_identifier = $this->identifier . '_cron_interval';
|
||||
|
||||
add_action( $this->cron_hook_identifier, array( $this, 'handle_cron_healthcheck' ) );
|
||||
add_filter( 'cron_schedules', array( $this, 'schedule_cron_healthcheck' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatch
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function dispatch() {
|
||||
// Schedule the cron healthcheck.
|
||||
$this->schedule_event();
|
||||
|
||||
// Perform remote post.
|
||||
return parent::dispatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Push to queue
|
||||
*
|
||||
* @param mixed $data Data.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function push_to_queue( $data ) {
|
||||
$this->data[] = $data;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save queue
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function save() {
|
||||
$key = $this->generate_key();
|
||||
|
||||
if ( ! empty( $this->data ) ) {
|
||||
update_site_option( $key, $this->data );
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update queue
|
||||
*
|
||||
* @param string $key Key.
|
||||
* @param array $data Data.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function update( $key, $data ) {
|
||||
if ( ! empty( $data ) ) {
|
||||
update_site_option( $key, $data );
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete queue
|
||||
*
|
||||
* @param string $key Key.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function delete( $key ) {
|
||||
delete_site_option( $key );
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate key
|
||||
*
|
||||
* Generates a unique key based on microtime. Queue items are
|
||||
* given a unique key so that they can be merged upon save.
|
||||
*
|
||||
* @param int $length Length.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function generate_key( $length = 64 ) {
|
||||
$unique = md5( microtime() . rand() );
|
||||
$prepend = $this->identifier . '_batch_';
|
||||
|
||||
return substr( $prepend . $unique, 0, $length );
|
||||
}
|
||||
|
||||
/**
|
||||
* Maybe process queue
|
||||
*
|
||||
* Checks whether data exists within the queue and that
|
||||
* the process is not already running.
|
||||
*/
|
||||
public function maybe_handle() {
|
||||
// Don't lock up other requests while processing
|
||||
session_write_close();
|
||||
|
||||
if ( $this->is_process_running() ) {
|
||||
// Background process already running.
|
||||
wp_die();
|
||||
}
|
||||
|
||||
if ( $this->is_queue_empty() ) {
|
||||
// No data to process.
|
||||
wp_die();
|
||||
}
|
||||
|
||||
check_ajax_referer( $this->identifier, 'nonce' );
|
||||
|
||||
$this->handle();
|
||||
|
||||
wp_die();
|
||||
}
|
||||
|
||||
/**
|
||||
* Is queue empty
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function is_queue_empty() {
|
||||
global $wpdb;
|
||||
|
||||
$table = $wpdb->options;
|
||||
$column = 'option_name';
|
||||
|
||||
if ( is_multisite() ) {
|
||||
$table = $wpdb->sitemeta;
|
||||
$column = 'meta_key';
|
||||
}
|
||||
|
||||
$key = $wpdb->esc_like( $this->identifier . '_batch_' ) . '%';
|
||||
|
||||
$count = $wpdb->get_var( $wpdb->prepare( "
|
||||
SELECT COUNT(*)
|
||||
FROM {$table}
|
||||
WHERE {$column} LIKE %s
|
||||
", $key ) );
|
||||
|
||||
return ( $count > 0 ) ? false : true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is process running
|
||||
*
|
||||
* Check whether the current process is already running
|
||||
* in a background process.
|
||||
*/
|
||||
protected function is_process_running() {
|
||||
if ( get_site_transient( $this->identifier . '_process_lock' ) ) {
|
||||
// Process already running.
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lock process
|
||||
*
|
||||
* Lock the process so that multiple instances can't run simultaneously.
|
||||
* Override if applicable, but the duration should be greater than that
|
||||
* defined in the time_exceeded() method.
|
||||
*/
|
||||
protected function lock_process() {
|
||||
$this->start_time = time(); // Set start time of current process.
|
||||
|
||||
$lock_duration = ( property_exists( $this, 'queue_lock_time' ) ) ? $this->queue_lock_time : 60; // 1 minute
|
||||
$lock_duration = apply_filters( $this->identifier . '_queue_lock_time', $lock_duration );
|
||||
|
||||
set_site_transient( $this->identifier . '_process_lock', microtime(), $lock_duration );
|
||||
}
|
||||
|
||||
/**
|
||||
* Unlock process
|
||||
*
|
||||
* Unlock the process so that other instances can spawn.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
protected function unlock_process() {
|
||||
delete_site_transient( $this->identifier . '_process_lock' );
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get batch
|
||||
*
|
||||
* @return stdClass Return the first batch from the queue
|
||||
*/
|
||||
protected function get_batch() {
|
||||
global $wpdb;
|
||||
|
||||
$table = $wpdb->options;
|
||||
$column = 'option_name';
|
||||
$key_column = 'option_id';
|
||||
$value_column = 'option_value';
|
||||
|
||||
if ( is_multisite() ) {
|
||||
$table = $wpdb->sitemeta;
|
||||
$column = 'meta_key';
|
||||
$key_column = 'meta_id';
|
||||
$value_column = 'meta_value';
|
||||
}
|
||||
|
||||
$key = $wpdb->esc_like( $this->identifier . '_batch_' ) . '%';
|
||||
|
||||
$query = $wpdb->get_row( $wpdb->prepare( "
|
||||
SELECT *
|
||||
FROM {$table}
|
||||
WHERE {$column} LIKE %s
|
||||
ORDER BY {$key_column} ASC
|
||||
LIMIT 1
|
||||
", $key ) );
|
||||
|
||||
$batch = new stdClass();
|
||||
$batch->key = $query->$column;
|
||||
$batch->data = maybe_unserialize( $query->$value_column );
|
||||
|
||||
return $batch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle
|
||||
*
|
||||
* Pass each queue item to the task handler, while remaining
|
||||
* within server memory and time limit constraints.
|
||||
*/
|
||||
protected function handle() {
|
||||
$this->lock_process();
|
||||
|
||||
do {
|
||||
$batch = $this->get_batch();
|
||||
|
||||
foreach ( $batch->data as $key => $value ) {
|
||||
$task = $this->task( $value );
|
||||
|
||||
if ( false !== $task ) {
|
||||
$batch->data[ $key ] = $task;
|
||||
} else {
|
||||
unset( $batch->data[ $key ] );
|
||||
}
|
||||
|
||||
if ( $this->time_exceeded() || $this->memory_exceeded() ) {
|
||||
// Batch limits reached.
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Update or delete current batch.
|
||||
if ( ! empty( $batch->data ) ) {
|
||||
$this->update( $batch->key, $batch->data );
|
||||
} else {
|
||||
$this->delete( $batch->key );
|
||||
}
|
||||
} while ( ! $this->time_exceeded() && ! $this->memory_exceeded() && ! $this->is_queue_empty() );
|
||||
|
||||
$this->unlock_process();
|
||||
|
||||
// Start next batch or complete process.
|
||||
if ( ! $this->is_queue_empty() ) {
|
||||
$this->dispatch();
|
||||
} else {
|
||||
$this->complete();
|
||||
}
|
||||
|
||||
wp_die();
|
||||
}
|
||||
|
||||
/**
|
||||
* Memory exceeded
|
||||
*
|
||||
* Ensures the batch process never exceeds 90%
|
||||
* of the maximum WordPress memory.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function memory_exceeded() {
|
||||
$memory_limit = $this->get_memory_limit() * 0.9; // 90% of max memory
|
||||
$current_memory = memory_get_usage( true );
|
||||
$return = false;
|
||||
|
||||
if ( $current_memory >= $memory_limit ) {
|
||||
$return = true;
|
||||
}
|
||||
|
||||
return apply_filters( $this->identifier . '_memory_exceeded', $return );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get memory limit
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
protected function get_memory_limit() {
|
||||
if ( function_exists( 'ini_get' ) ) {
|
||||
$memory_limit = ini_get( 'memory_limit' );
|
||||
} else {
|
||||
// Sensible default.
|
||||
$memory_limit = '128M';
|
||||
}
|
||||
|
||||
if ( ! $memory_limit || -1 === intval( $memory_limit ) ) {
|
||||
// Unlimited, set to 32GB.
|
||||
$memory_limit = '32000M';
|
||||
}
|
||||
|
||||
return intval( $memory_limit ) * 1024 * 1024;
|
||||
}
|
||||
|
||||
/**
|
||||
* Time exceeded.
|
||||
*
|
||||
* Ensures the batch never exceeds a sensible time limit.
|
||||
* A timeout limit of 30s is common on shared hosting.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function time_exceeded() {
|
||||
$finish = $this->start_time + apply_filters( $this->identifier . '_default_time_limit', 20 ); // 20 seconds
|
||||
$return = false;
|
||||
|
||||
if ( time() >= $finish ) {
|
||||
$return = true;
|
||||
}
|
||||
|
||||
return apply_filters( $this->identifier . '_time_exceeded', $return );
|
||||
}
|
||||
|
||||
/**
|
||||
* Complete.
|
||||
*
|
||||
* Override if applicable, but ensure that the below actions are
|
||||
* performed, or, call parent::complete().
|
||||
*/
|
||||
protected function complete() {
|
||||
// Unschedule the cron healthcheck.
|
||||
$this->clear_scheduled_event();
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule cron healthcheck
|
||||
*
|
||||
* @access public
|
||||
* @param mixed $schedules Schedules.
|
||||
* @return mixed
|
||||
*/
|
||||
public function schedule_cron_healthcheck( $schedules ) {
|
||||
$interval = apply_filters( $this->identifier . '_cron_interval', 5 );
|
||||
|
||||
if ( property_exists( $this, 'cron_interval' ) ) {
|
||||
$interval = apply_filters( $this->identifier . '_cron_interval', $this->cron_interval );
|
||||
}
|
||||
|
||||
// Adds every 5 minutes to the existing schedules.
|
||||
$schedules[ $this->identifier . '_cron_interval' ] = array(
|
||||
'interval' => MINUTE_IN_SECONDS * $interval,
|
||||
'display' => sprintf( __( 'Every %d Minutes' ), $interval ),
|
||||
);
|
||||
|
||||
return $schedules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle cron healthcheck
|
||||
*
|
||||
* Restart the background process if not already running
|
||||
* and data exists in the queue.
|
||||
*/
|
||||
public function handle_cron_healthcheck() {
|
||||
if ( $this->is_process_running() ) {
|
||||
// Background process already running.
|
||||
exit;
|
||||
}
|
||||
|
||||
if ( $this->is_queue_empty() ) {
|
||||
// No data to process.
|
||||
$this->clear_scheduled_event();
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->handle();
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule event
|
||||
*/
|
||||
protected function schedule_event() {
|
||||
if ( ! wp_next_scheduled( $this->cron_hook_identifier ) ) {
|
||||
wp_schedule_event( time(), $this->cron_interval_identifier, $this->cron_hook_identifier );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear scheduled event
|
||||
*/
|
||||
protected function clear_scheduled_event() {
|
||||
$timestamp = wp_next_scheduled( $this->cron_hook_identifier );
|
||||
|
||||
if ( $timestamp ) {
|
||||
wp_unschedule_event( $timestamp, $this->cron_hook_identifier );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel Process
|
||||
*
|
||||
* Stop processing queue items, clear cronjob and delete batch.
|
||||
*
|
||||
*/
|
||||
public function cancel_process() {
|
||||
if ( ! $this->is_queue_empty() ) {
|
||||
$batch = $this->get_batch();
|
||||
|
||||
$this->delete( $batch->key );
|
||||
|
||||
wp_clear_scheduled_hook( $this->cron_hook_identifier );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Task
|
||||
*
|
||||
* Override this method to perform any actions required on each
|
||||
* queue item. Return the modified item for further processing
|
||||
* in the next pass through. Or, return false to remove the
|
||||
* item from the queue.
|
||||
*
|
||||
* @param mixed $item Queue item to iterate over.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
abstract protected function task( $item );
|
||||
|
||||
}
|
||||
}
|
@ -215,6 +215,227 @@ function generate_premium_customizer_shortcut_controls( $wp_customize ) {
|
||||
);
|
||||
}
|
||||
|
||||
add_action( 'customize_register', 'generate_premium_layout_block_element_messages', 1000 );
|
||||
/**
|
||||
* Add shortcuts to sections we don't control in this plugin.
|
||||
*
|
||||
* @since 1.8
|
||||
*/
|
||||
function generate_premium_layout_block_element_messages( $wp_customize ) {
|
||||
if ( ! class_exists( 'WP_Customize_Panel' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( method_exists( $wp_customize, 'register_control_type' ) ) {
|
||||
$wp_customize->register_control_type( 'GeneratePress_Information_Customize_Control' );
|
||||
}
|
||||
|
||||
if ( version_compare( PHP_VERSION, '5.6', '>=' ) ) {
|
||||
$footer_sections = array(
|
||||
'generate_layout_footer',
|
||||
'footer_color_section',
|
||||
'font_footer_section',
|
||||
'generate_backgrounds_footer',
|
||||
);
|
||||
|
||||
foreach ( $footer_sections as $section ) {
|
||||
if ( $wp_customize->get_section( $section ) ) {
|
||||
$wp_customize->add_control(
|
||||
new GeneratePress_Information_Customize_Control(
|
||||
$wp_customize,
|
||||
'generate_using_site_footer_element_' . $section,
|
||||
array(
|
||||
'section' => $section,
|
||||
'description' => sprintf(
|
||||
/* translators: URL to the Elements dashboard. */
|
||||
__( 'This page is using a <a href="%s">Site Footer Element</a>. Some of the options below may not apply.', 'gp-premium' ),
|
||||
admin_url( 'edit.php?post_type=gp_elements' )
|
||||
),
|
||||
'notice' => true,
|
||||
'settings' => ( isset( $wp_customize->selective_refresh ) ) ? array() : 'blogname',
|
||||
'active_callback' => function() {
|
||||
$has_block_element = generate_has_active_element( 'site-footer', true );
|
||||
|
||||
if ( $has_block_element ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
'priority' => 0,
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$header_sections = array(
|
||||
'generate_layout_header',
|
||||
'header_color_section',
|
||||
'font_header_section',
|
||||
'generate_backgrounds_header',
|
||||
);
|
||||
|
||||
foreach ( $header_sections as $section ) {
|
||||
if ( $wp_customize->get_section( $section ) ) {
|
||||
$wp_customize->add_control(
|
||||
new GeneratePress_Information_Customize_Control(
|
||||
$wp_customize,
|
||||
'generate_using_site_header_element_' . $section,
|
||||
array(
|
||||
'section' => $section,
|
||||
'description' => sprintf(
|
||||
/* translators: URL to the Elements dashboard. */
|
||||
__( 'This page is using a <a href="%s">Site Header Element</a>. Some of the options below may not apply.', 'gp-premium' ),
|
||||
admin_url( 'edit.php?post_type=gp_elements' )
|
||||
),
|
||||
'notice' => true,
|
||||
'settings' => ( isset( $wp_customize->selective_refresh ) ) ? array() : 'blogname',
|
||||
'active_callback' => function() {
|
||||
$has_block_element = generate_has_active_element( 'site-header', true );
|
||||
|
||||
if ( $has_block_element ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
'priority' => 0,
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$sidebar_sections = array(
|
||||
'generate_layout_sidebars',
|
||||
'sidebar_widget_color_section',
|
||||
'font_widget_section',
|
||||
'generate_backgrounds_sidebars',
|
||||
);
|
||||
|
||||
foreach ( $sidebar_sections as $section ) {
|
||||
if ( $wp_customize->get_section( $section ) ) {
|
||||
$wp_customize->add_control(
|
||||
new GeneratePress_Information_Customize_Control(
|
||||
$wp_customize,
|
||||
'generate_using_sidebar_element_' . $section,
|
||||
array(
|
||||
'section' => $section,
|
||||
'description' => sprintf(
|
||||
/* translators: URL to the Elements dashboard. */
|
||||
__( 'This page is using a <a href="%s">Sidebar Element</a>. Some of the options below may not apply.', 'gp-premium' ),
|
||||
admin_url( 'edit.php?post_type=gp_elements' )
|
||||
),
|
||||
'notice' => true,
|
||||
'settings' => ( isset( $wp_customize->selective_refresh ) ) ? array() : 'blogname',
|
||||
'active_callback' => function() {
|
||||
$has_right_sidebar_block_element = generate_has_active_element( 'right-sidebar', true );
|
||||
|
||||
if ( $has_right_sidebar_block_element ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$has_left_sidebar_block_element = generate_has_active_element( 'left-sidebar', true );
|
||||
|
||||
if ( $has_left_sidebar_block_element ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
'priority' => 0,
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if ( $wp_customize->get_section( 'generate_blog_section' ) ) {
|
||||
$wp_customize->add_control(
|
||||
new GeneratePress_Information_Customize_Control(
|
||||
$wp_customize,
|
||||
'generate_using_post_loop_item_element',
|
||||
array(
|
||||
'section' => 'generate_blog_section',
|
||||
'description' => sprintf(
|
||||
/* translators: URL to the Elements dashboard. */
|
||||
__( 'This page is using a <a href="%s">Content Template Element</a>. Some of the options below may not apply.', 'gp-premium' ),
|
||||
admin_url( 'edit.php?post_type=gp_elements' )
|
||||
),
|
||||
'notice' => true,
|
||||
'settings' => ( isset( $wp_customize->selective_refresh ) ) ? array() : 'blogname',
|
||||
'active_callback' => function() {
|
||||
$has_block_element = generate_has_active_element( 'content-template', true );
|
||||
|
||||
if ( $has_block_element ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
'priority' => 0,
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
new GeneratePress_Information_Customize_Control(
|
||||
$wp_customize,
|
||||
'generate_using_page_hero_element',
|
||||
array(
|
||||
'section' => 'generate_blog_section',
|
||||
'description' => sprintf(
|
||||
/* translators: URL to the Elements dashboard. */
|
||||
__( 'This page is using a <a href="%s">Page Hero Element</a>. Some of the options below may not apply.', 'gp-premium' ),
|
||||
admin_url( 'edit.php?post_type=gp_elements' )
|
||||
),
|
||||
'notice' => true,
|
||||
'settings' => ( isset( $wp_customize->selective_refresh ) ) ? array() : 'blogname',
|
||||
'active_callback' => function() {
|
||||
$has_block_element = generate_has_active_element( 'page-hero', true );
|
||||
|
||||
if ( $has_block_element ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
'priority' => 0,
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
new GeneratePress_Information_Customize_Control(
|
||||
$wp_customize,
|
||||
'generate_using_post_meta_area_element',
|
||||
array(
|
||||
'section' => 'generate_blog_section',
|
||||
'description' => sprintf(
|
||||
/* translators: URL to the Elements dashboard. */
|
||||
__( 'This page is using a <a href="%s">Post Meta Template Element</a>. Some of the options below may not apply.', 'gp-premium' ),
|
||||
admin_url( 'edit.php?post_type=gp_elements' )
|
||||
),
|
||||
'notice' => true,
|
||||
'settings' => ( isset( $wp_customize->selective_refresh ) ) ? array() : 'blogname',
|
||||
'active_callback' => function() {
|
||||
$has_block_element = generate_has_active_element( 'post-meta-template', true );
|
||||
|
||||
if ( $has_block_element ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
'priority' => 0,
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
add_action( 'customize_controls_print_styles', 'generate_premium_customize_print_styles' );
|
||||
/**
|
||||
* Print control styles for the Customizer.
|
||||
|
@ -10,22 +10,33 @@ if ( class_exists( 'WP_Customize_Control' ) && ! class_exists( 'GeneratePress_In
|
||||
*/
|
||||
class GeneratePress_Information_Customize_Control extends WP_Customize_Control {
|
||||
public $type = 'gp_information_control';
|
||||
|
||||
|
||||
public $description = '';
|
||||
public $notice = '';
|
||||
|
||||
public function to_json() {
|
||||
parent::to_json();
|
||||
$this->json[ 'description' ] = $this->description;
|
||||
$this->json['description'] = $this->description;
|
||||
$this->json['notice'] = $this->notice;
|
||||
}
|
||||
|
||||
|
||||
public function content_template() {
|
||||
?>
|
||||
<# if ( data.notice ) { #>
|
||||
<div class="notice notice-info">
|
||||
<# } #>
|
||||
|
||||
<# if ( data.label ) { #>
|
||||
<span class="customize-control-title">{{ data.label }}</span>
|
||||
<# } #>
|
||||
<# if ( data.description ) { #>
|
||||
<p>{{{ data.description }}}</p>
|
||||
<# } #>
|
||||
|
||||
<# if ( data.notice ) { #>
|
||||
</div>
|
||||
<# } #>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
endif;
|
||||
endif;
|
||||
|
@ -1,34 +1,31 @@
|
||||
( function( api ) {
|
||||
|
||||
api.controlConstructor['gp-background-images'] = api.Control.extend( {
|
||||
ready: function() {
|
||||
api.controlConstructor[ 'gp-background-images' ] = api.Control.extend( {
|
||||
ready() {
|
||||
var control = this;
|
||||
|
||||
|
||||
control.container.on( 'change', '.generatepress-backgrounds-repeat select',
|
||||
function() {
|
||||
control.settings['repeat'].set( jQuery( this ).val() );
|
||||
control.settings.repeat.set( jQuery( this ).val() );
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
control.container.on( 'change', '.generatepress-backgrounds-size select',
|
||||
function() {
|
||||
control.settings['size'].set( jQuery( this ).val() );
|
||||
control.settings.size.set( jQuery( this ).val() );
|
||||
}
|
||||
);
|
||||
|
||||
control.container.on( 'change', '.generatepress-backgrounds-attachment select',
|
||||
function() {
|
||||
control.settings['attachment'].set( jQuery( this ).val() );
|
||||
control.settings.attachment.set( jQuery( this ).val() );
|
||||
}
|
||||
);
|
||||
|
||||
control.container.on( 'input', '.generatepress-backgrounds-position input',
|
||||
function() {
|
||||
control.settings['position'].set( jQuery( this ).val() );
|
||||
control.settings.position.set( jQuery( this ).val() );
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
},
|
||||
} );
|
||||
|
||||
} )( wp.customize );
|
||||
}( wp.customize ) );
|
||||
|
@ -1,7 +1,8 @@
|
||||
jQuery( document ).ready( function( $ ) {
|
||||
jQuery( function( $ ) {
|
||||
$( '[data-type="overlay_design"]' ).on( 'click', function( e ) {
|
||||
e.preventDefault();
|
||||
|
||||
// eslint-disable-next-line no-alert
|
||||
if ( ! confirm( gpButtonActions.warning ) ) {
|
||||
return;
|
||||
}
|
||||
@ -23,11 +24,9 @@ jQuery( document ).ready( function( $ ) {
|
||||
api.instance( 'generate_settings[slideout_font_size]' ).set( gpButtonActions.styling.fontSize );
|
||||
|
||||
$( '.wp-color-picker' ).wpColorPicker().change();
|
||||
|
||||
}( wp.customize ) );
|
||||
} );
|
||||
|
||||
|
||||
$( '[data-type="regenerate_external_css"]' ).on( 'click', function( e ) {
|
||||
var $thisButton = $( this ); // eslint-disable-line no-var
|
||||
e.preventDefault();
|
||||
|
@ -1,4 +1,4 @@
|
||||
jQuery( document ).ready( function($) {
|
||||
jQuery( function( $ ) {
|
||||
$( '.generatepress-control-toggles' ).each( function() {
|
||||
$( this ).find( 'button' ).first().addClass( 'active' );
|
||||
} );
|
||||
@ -7,7 +7,7 @@ jQuery( document ).ready( function($) {
|
||||
e.preventDefault();
|
||||
var button = $( this ),
|
||||
target = button.data( 'target' ),
|
||||
other_targets = button.siblings();
|
||||
otherTargets = button.siblings();
|
||||
|
||||
button.addClass( 'active' );
|
||||
button.siblings().removeClass( 'active' );
|
||||
@ -20,9 +20,10 @@ jQuery( document ).ready( function($) {
|
||||
overflow: '',
|
||||
} );
|
||||
|
||||
$.each( other_targets, function( index, value ) {
|
||||
var other_target = $( this ).data( 'target' );
|
||||
$( 'li[data-control-section="' + other_target + '"]' ).css( {
|
||||
$.each( otherTargets, function() {
|
||||
var otherTarget = $( this ).data( 'target' );
|
||||
|
||||
$( 'li[data-control-section="' + otherTarget + '"]' ).css( {
|
||||
visibility: 'hidden',
|
||||
height: '0',
|
||||
width: '0',
|
||||
@ -31,4 +32,4 @@ jQuery( document ).ready( function($) {
|
||||
} );
|
||||
} );
|
||||
} );
|
||||
});
|
||||
} );
|
||||
|
@ -1,12 +1,12 @@
|
||||
( function( $, api ) {
|
||||
api.controlConstructor['gp-copyright'] = api.Control.extend( {
|
||||
ready: function() {
|
||||
api.controlConstructor[ 'gp-copyright' ] = api.Control.extend( {
|
||||
ready() {
|
||||
var control = this;
|
||||
$( '.gp-copyright-area', control.container ).on( 'change keyup',
|
||||
function() {
|
||||
control.setting.set( $( this ).val() );
|
||||
}
|
||||
);
|
||||
}
|
||||
},
|
||||
} );
|
||||
} )( jQuery, wp.customize );
|
||||
}( jQuery, wp.customize ) );
|
||||
|
@ -1,10 +1,9 @@
|
||||
( function( $, api ) {
|
||||
|
||||
/**
|
||||
* Set some controls when we're using the navigation as a header.
|
||||
*
|
||||
* @since 1.8
|
||||
*/
|
||||
*/
|
||||
api( 'generate_menu_plus_settings[navigation_as_header]', function( value ) {
|
||||
value.bind( function( newval ) {
|
||||
var navAlignmentSetting = api.instance( 'generate_settings[nav_alignment_setting]' ),
|
||||
@ -67,13 +66,12 @@
|
||||
} );
|
||||
|
||||
var showRegularHeader,
|
||||
showRegularHeaderCallback,
|
||||
showNavHeader;
|
||||
showRegularHeaderCallback;
|
||||
|
||||
/**
|
||||
* Determine whether we should display our header controls.
|
||||
*
|
||||
* @returns {boolean}
|
||||
* @return {boolean} Whether we should show the regular header.
|
||||
*/
|
||||
showRegularHeader = function() {
|
||||
if ( value.get() ) {
|
||||
@ -83,23 +81,10 @@
|
||||
return true;
|
||||
};
|
||||
|
||||
/**
|
||||
* Determine whether our navigation is our header.
|
||||
*
|
||||
* @returns {boolean}
|
||||
*/
|
||||
showNavHeader = function() {
|
||||
if ( value.get() ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
* Update a control's active state according to the navigation as header option.
|
||||
*
|
||||
* @param {wp.customize.Control} control
|
||||
* @param {wp.customize.Control} control The current control.
|
||||
*/
|
||||
showRegularHeaderCallback = function( control ) {
|
||||
var setActiveState = function() {
|
||||
@ -131,7 +116,7 @@
|
||||
* Set the navigation branding font size label on mobile header branding change.
|
||||
*
|
||||
* @since 1.8
|
||||
*/
|
||||
*/
|
||||
api( 'generate_menu_plus_settings[mobile_header_branding]', function( value ) {
|
||||
value.bind( function( newval ) {
|
||||
if ( api.instance( 'generate_settings[mobile_site_title_font_size]' ) && 'title' === newval ) {
|
||||
@ -144,7 +129,7 @@
|
||||
* Set the navigation branding font size label on mobile header change.
|
||||
*
|
||||
* @since 1.8
|
||||
*/
|
||||
*/
|
||||
api( 'generate_menu_plus_settings[mobile_header]', function( value ) {
|
||||
value.bind( function( newval ) {
|
||||
var mobileSiteTitleFontSizeSetting = api.instance( 'generate_settings[mobile_site_title_font_size]' ),
|
||||
@ -163,5 +148,4 @@
|
||||
}
|
||||
} );
|
||||
} );
|
||||
|
||||
} )( jQuery, wp.customize );
|
||||
}( jQuery, wp.customize ) );
|
||||
|
@ -1,4 +1,4 @@
|
||||
jQuery( document ).ready( function( $ ) {
|
||||
jQuery( function( $ ) {
|
||||
$( '.generatepress-shortcuts a' ).on( 'click', function( e ) {
|
||||
e.preventDefault();
|
||||
var section = $( this ).attr( 'data-section' ),
|
||||
@ -14,7 +14,7 @@ jQuery( document ).ready( function( $ ) {
|
||||
}
|
||||
} );
|
||||
|
||||
$( '.return-shortcut .dashicons' ).on( 'click', function( e ) {
|
||||
$( '.return-shortcut .dashicons' ).on( 'click', function() {
|
||||
var container = $( this ).closest( '.generatepress-shortcuts' );
|
||||
|
||||
container.find( '.show-shortcuts' ).show();
|
||||
|
@ -1,134 +1,137 @@
|
||||
wp.customize.controlConstructor['generatepress-pro-range-slider'] = wp.customize.Control.extend({
|
||||
|
||||
ready: function() {
|
||||
|
||||
wp.customize.controlConstructor[ 'generatepress-pro-range-slider' ] = wp.customize.Control.extend( {
|
||||
ready() {
|
||||
'use strict';
|
||||
|
||||
var control = this,
|
||||
value,
|
||||
thisInput,
|
||||
inputDefault,
|
||||
changeAction,
|
||||
value,
|
||||
controlClass = '.customize-control-generatepress-pro-range-slider',
|
||||
footerActions = jQuery( '#customize-footer-actions' );
|
||||
|
||||
|
||||
// Set up the sliders
|
||||
jQuery( '.generatepress-slider' ).each( function() {
|
||||
var _this = jQuery( this );
|
||||
var _input = _this.closest( 'label' ).find( 'input[type="number"]' );
|
||||
var _text = _input.next( '.value' );
|
||||
_this.slider({
|
||||
|
||||
_this.slider( {
|
||||
value: _input.val(),
|
||||
min: _this.data( 'min' ),
|
||||
max: _this.data( 'max' ),
|
||||
step: _this.data( 'step' ),
|
||||
slide: function( event, ui ) {
|
||||
slide( event, ui ) {
|
||||
_input.val( ui.value ).change();
|
||||
_text.text( ui.value );
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
},
|
||||
} );
|
||||
} );
|
||||
|
||||
// Update the range value based on the input value
|
||||
jQuery( controlClass + ' .gp_range_value input[type=number]' ).on( 'input', function() {
|
||||
value = jQuery( this ).attr( 'value' );
|
||||
|
||||
if ( '' == value ) {
|
||||
value = -1;
|
||||
}
|
||||
jQuery( this ).closest( 'label' ).find( '.generatepress-slider' ).slider( 'value', parseFloat(value)).change();
|
||||
});
|
||||
|
||||
jQuery( this ).closest( 'label' ).find( '.generatepress-slider' ).slider( 'value', parseFloat( value ) ).change();
|
||||
} );
|
||||
|
||||
// Handle the reset button
|
||||
jQuery( controlClass + ' .generatepress-reset' ).on( 'click', function() {
|
||||
var icon = jQuery( this ),
|
||||
visible_area = icon.closest( '.gp-range-title-area' ).next( '.gp-range-slider-areas' ).children( 'label:visible' ),
|
||||
input = visible_area.find( 'input[type=number]' ),
|
||||
slider_value = visible_area.find( '.generatepress-slider' ),
|
||||
visual_value = visible_area.find( '.gp_range_value' ),
|
||||
reset_value = input.attr( 'data-reset_value' );
|
||||
|
||||
input.val( reset_value ).change();
|
||||
visual_value.find( 'input' ).val( reset_value );
|
||||
visual_value.find( '.value' ).text( reset_value );
|
||||
|
||||
if ( '' == reset_value ) {
|
||||
reset_value = -1;
|
||||
visibleArea = icon.closest( '.gp-range-title-area' ).next( '.gp-range-slider-areas' ).children( 'label:visible' ),
|
||||
input = visibleArea.find( 'input[type=number]' ),
|
||||
sliderValue = visibleArea.find( '.generatepress-slider' ),
|
||||
visualValue = visibleArea.find( '.gp_range_value' ),
|
||||
resetValue = input.attr( 'data-reset_value' );
|
||||
|
||||
input.val( resetValue ).change();
|
||||
visualValue.find( 'input' ).val( resetValue );
|
||||
visualValue.find( '.value' ).text( resetValue );
|
||||
|
||||
if ( '' == resetValue ) {
|
||||
resetValue = -1;
|
||||
}
|
||||
|
||||
slider_value.slider( 'value', parseFloat( reset_value ) );
|
||||
});
|
||||
|
||||
|
||||
sliderValue.slider( 'value', parseFloat( resetValue ) );
|
||||
} );
|
||||
|
||||
// Figure out which device icon to make active on load
|
||||
jQuery( controlClass + ' .generatepress-range-slider-control' ).each( function() {
|
||||
var _this = jQuery( this );
|
||||
|
||||
_this.find( '.gp-device-controls' ).children( 'span:first-child' ).addClass( 'selected' );
|
||||
_this.find( '.range-option-area:first-child' ).show();
|
||||
});
|
||||
|
||||
} );
|
||||
|
||||
// Do stuff when device icons are clicked
|
||||
jQuery( controlClass + ' .gp-device-controls > span' ).on( 'click', function( event ) {
|
||||
var device = jQuery( this ).data( 'option' );
|
||||
|
||||
|
||||
jQuery( controlClass + ' .gp-device-controls span' ).each( function() {
|
||||
var _this = jQuery( this );
|
||||
if ( device == _this.attr( 'data-option' ) ) {
|
||||
|
||||
if ( device === _this.attr( 'data-option' ) ) {
|
||||
_this.addClass( 'selected' );
|
||||
_this.siblings().removeClass( 'selected' );
|
||||
}
|
||||
});
|
||||
|
||||
} );
|
||||
|
||||
jQuery( controlClass + ' .gp-range-slider-areas label' ).each( function() {
|
||||
var _this = jQuery( this );
|
||||
if ( device == _this.attr( 'data-option' ) ) {
|
||||
|
||||
if ( device === _this.attr( 'data-option' ) ) {
|
||||
_this.show();
|
||||
_this.siblings().hide();
|
||||
}
|
||||
});
|
||||
|
||||
} );
|
||||
|
||||
// Set the device we're currently viewing
|
||||
wp.customize.previewedDevice.set( jQuery( event.currentTarget ).data( 'option' ) );
|
||||
} );
|
||||
|
||||
|
||||
// Set the selected devices in our control when the Customizer devices are clicked
|
||||
footerActions.find( '.devices button' ).on( 'click', function() {
|
||||
var device = jQuery( this ).data( 'device' );
|
||||
|
||||
jQuery( controlClass + ' .gp-device-controls span' ).each( function() {
|
||||
var _this = jQuery( this );
|
||||
if ( device == _this.attr( 'data-option' ) ) {
|
||||
|
||||
if ( device === _this.attr( 'data-option' ) ) {
|
||||
_this.addClass( 'selected' );
|
||||
_this.siblings().removeClass( 'selected' );
|
||||
}
|
||||
});
|
||||
|
||||
} );
|
||||
|
||||
jQuery( controlClass + ' .gp-range-slider-areas label' ).each( function() {
|
||||
var _this = jQuery( this );
|
||||
if ( device == _this.attr( 'data-option' ) ) {
|
||||
|
||||
if ( device === _this.attr( 'data-option' ) ) {
|
||||
_this.show();
|
||||
_this.siblings().hide();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
} );
|
||||
} );
|
||||
|
||||
// Apply changes when desktop slider is changed
|
||||
control.container.on( 'input change', '.desktop-range',
|
||||
function() {
|
||||
control.settings['desktop'].set( jQuery( this ).val() );
|
||||
control.settings.desktop.set( jQuery( this ).val() );
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
// Apply changes when tablet slider is changed
|
||||
control.container.on( 'input change', '.tablet-range',
|
||||
function() {
|
||||
control.settings['tablet'].set( jQuery( this ).val() );
|
||||
control.settings.tablet.set( jQuery( this ).val() );
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
// Apply changes when mobile slider is changed
|
||||
control.container.on( 'input change', '.mobile-range',
|
||||
function() {
|
||||
control.settings['mobile'].set( jQuery( this ).val() );
|
||||
control.settings.mobile.set( jQuery( this ).val() );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
});
|
||||
},
|
||||
} );
|
||||
|
@ -1,30 +1,30 @@
|
||||
( function( $, api ) {
|
||||
// No longer needed as of 1.2.95
|
||||
// Keeping it here just in case
|
||||
api.controlConstructor['spacing'] = api.Control.extend( {
|
||||
ready: function() {
|
||||
api.controlConstructor.spacing = api.Control.extend( {
|
||||
ready() {
|
||||
var control = this;
|
||||
$( '.generate-number-control', control.container ).on( 'change keyup',
|
||||
function() {
|
||||
control.setting.set( $( this ).val() );
|
||||
}
|
||||
);
|
||||
}
|
||||
},
|
||||
} );
|
||||
|
||||
api.controlConstructor['gp-spacing-slider'] = api.Control.extend( {
|
||||
ready: function() {
|
||||
api.controlConstructor[ 'gp-spacing-slider' ] = api.Control.extend( {
|
||||
ready() {
|
||||
var control = this;
|
||||
$( '.slider-input', control.container ).on( 'change keyup',
|
||||
function() {
|
||||
control.setting.set( $( this ).val() );
|
||||
}
|
||||
);
|
||||
}
|
||||
},
|
||||
} );
|
||||
|
||||
api.controlConstructor['generatepress-spacing'] = api.Control.extend( {
|
||||
ready: function() {
|
||||
api.controlConstructor[ 'generatepress-spacing' ] = api.Control.extend( {
|
||||
ready() {
|
||||
var control = this,
|
||||
controlClass = '.customize-control-generatepress-spacing',
|
||||
footerActions = jQuery( '#customize-footer-actions' );
|
||||
@ -34,7 +34,7 @@
|
||||
var _this = jQuery( this );
|
||||
_this.find( '.gp-device-controls' ).children( 'span:first-child' ).addClass( 'selected' );
|
||||
_this.find( '.spacing-values-area:first-child' ).show();
|
||||
});
|
||||
} );
|
||||
|
||||
// Do stuff when device icons are clicked
|
||||
jQuery( controlClass + ' .gp-device-controls > span' ).on( 'click', function( event ) {
|
||||
@ -42,19 +42,21 @@
|
||||
|
||||
jQuery( controlClass + ' .gp-device-controls span' ).each( function() {
|
||||
var _this = jQuery( this );
|
||||
if ( device == _this.attr( 'data-option' ) ) {
|
||||
|
||||
if ( device === _this.attr( 'data-option' ) ) {
|
||||
_this.addClass( 'selected' );
|
||||
_this.siblings().removeClass( 'selected' );
|
||||
}
|
||||
});
|
||||
} );
|
||||
|
||||
jQuery( controlClass + ' .spacing-values-container .spacing-values-area' ).each( function() {
|
||||
var _this = jQuery( this );
|
||||
if ( device == _this.attr( 'data-option' ) ) {
|
||||
|
||||
if ( device === _this.attr( 'data-option' ) ) {
|
||||
_this.show();
|
||||
_this.siblings().hide();
|
||||
}
|
||||
});
|
||||
} );
|
||||
|
||||
// Set the device we're currently viewing
|
||||
wp.customize.previewedDevice.set( jQuery( event.currentTarget ).data( 'option' ) );
|
||||
@ -65,125 +67,127 @@
|
||||
var device = jQuery( this ).data( 'device' );
|
||||
jQuery( controlClass + ' .gp-device-controls span' ).each( function() {
|
||||
var _this = jQuery( this );
|
||||
if ( device == _this.attr( 'data-option' ) ) {
|
||||
|
||||
if ( device === _this.attr( 'data-option' ) ) {
|
||||
_this.addClass( 'selected' );
|
||||
_this.siblings().removeClass( 'selected' );
|
||||
}
|
||||
});
|
||||
} );
|
||||
|
||||
jQuery( controlClass + ' .spacing-values-container .spacing-values-area' ).each( function() {
|
||||
var _this = jQuery( this );
|
||||
if ( device == _this.attr( 'data-option' ) ) {
|
||||
|
||||
if ( device === _this.attr( 'data-option' ) ) {
|
||||
_this.show();
|
||||
_this.siblings().hide();
|
||||
}
|
||||
});
|
||||
});
|
||||
} );
|
||||
} );
|
||||
|
||||
control.container.on( 'change keyup', '.spacing-top',
|
||||
function() {
|
||||
control.settings['desktop_top'].set( jQuery( this ).val() );
|
||||
control.settings.desktop_top.set( jQuery( this ).val() );
|
||||
}
|
||||
);
|
||||
|
||||
control.container.on( 'change keyup', '.spacing-right',
|
||||
function() {
|
||||
control.settings['desktop_right'].set( jQuery( this ).val() );
|
||||
control.settings.desktop_right.set( jQuery( this ).val() );
|
||||
}
|
||||
);
|
||||
|
||||
control.container.on( 'change keyup', '.spacing-bottom',
|
||||
function() {
|
||||
control.settings['desktop_bottom'].set( jQuery( this ).val() );
|
||||
control.settings.desktop_bottom.set( jQuery( this ).val() );
|
||||
}
|
||||
);
|
||||
|
||||
control.container.on( 'change keyup', '.spacing-left',
|
||||
function() {
|
||||
control.settings['desktop_left'].set( jQuery( this ).val() );
|
||||
control.settings.desktop_left.set( jQuery( this ).val() );
|
||||
}
|
||||
);
|
||||
|
||||
control.container.on( 'change keyup', '.tablet-spacing-top',
|
||||
function() {
|
||||
control.settings['tablet_top'].set( jQuery( this ).val() );
|
||||
control.settings.tablet_top.set( jQuery( this ).val() );
|
||||
}
|
||||
);
|
||||
|
||||
control.container.on( 'change keyup', '.tablet-spacing-right',
|
||||
function() {
|
||||
control.settings['tablet_right'].set( jQuery( this ).val() );
|
||||
control.settings.tablet_right.set( jQuery( this ).val() );
|
||||
}
|
||||
);
|
||||
|
||||
control.container.on( 'change keyup', '.tablet-spacing-bottom',
|
||||
function() {
|
||||
control.settings['tablet_bottom'].set( jQuery( this ).val() );
|
||||
control.settings.tablet_bottom.set( jQuery( this ).val() );
|
||||
}
|
||||
);
|
||||
|
||||
control.container.on( 'change keyup', '.tablet-spacing-left',
|
||||
function() {
|
||||
control.settings['tablet_left'].set( jQuery( this ).val() );
|
||||
control.settings.tablet_left.set( jQuery( this ).val() );
|
||||
}
|
||||
);
|
||||
|
||||
control.container.on( 'change keyup', '.mobile-spacing-top',
|
||||
function() {
|
||||
control.settings['mobile_top'].set( jQuery( this ).val() );
|
||||
control.settings.mobile_top.set( jQuery( this ).val() );
|
||||
}
|
||||
);
|
||||
|
||||
control.container.on( 'change keyup', '.mobile-spacing-right',
|
||||
function() {
|
||||
control.settings['mobile_right'].set( jQuery( this ).val() );
|
||||
control.settings.mobile_right.set( jQuery( this ).val() );
|
||||
}
|
||||
);
|
||||
|
||||
control.container.on( 'change keyup', '.mobile-spacing-bottom',
|
||||
function() {
|
||||
control.settings['mobile_bottom'].set( jQuery( this ).val() );
|
||||
control.settings.mobile_bottom.set( jQuery( this ).val() );
|
||||
}
|
||||
);
|
||||
|
||||
control.container.on( 'change keyup', '.mobile-spacing-left',
|
||||
function() {
|
||||
control.settings['mobile_left'].set( jQuery( this ).val() );
|
||||
control.settings.mobile_left.set( jQuery( this ).val() );
|
||||
}
|
||||
);
|
||||
}
|
||||
},
|
||||
} );
|
||||
} )( jQuery, wp.customize );
|
||||
}( jQuery, wp.customize ) );
|
||||
|
||||
jQuery( document ).ready( function($) {
|
||||
$( '.gp-link-spacing' ).on( 'click', function(e) {
|
||||
jQuery( function( $ ) {
|
||||
$( '.gp-link-spacing' ).on( 'click', function( e ) {
|
||||
e.preventDefault();
|
||||
|
||||
// Set up variables
|
||||
var _this = $( this ),
|
||||
element = _this.data( 'element' );
|
||||
element = _this.data( 'element' );
|
||||
|
||||
// Add our linked-values class to the next 4 elements
|
||||
_this.parent( '.gp-spacing-section' ).prevAll().slice(0,4).find( 'input' ).addClass( 'linked-values' ).attr( 'data-element', element );
|
||||
_this.parent( '.gp-spacing-section' ).prevAll().slice( 0, 4 ).find( 'input' ).addClass( 'linked-values' ).attr( 'data-element', element );
|
||||
|
||||
// Change our link icon class
|
||||
_this.hide();
|
||||
_this.next( 'span' ).show();
|
||||
});
|
||||
} );
|
||||
|
||||
$( '.gp-unlink-spacing' ).on( 'click', function(e) {
|
||||
$( '.gp-unlink-spacing' ).on( 'click', function( e ) {
|
||||
e.preventDefault();
|
||||
|
||||
// Set up variables
|
||||
var _this = $( this );
|
||||
|
||||
// Remove our linked-values class to the next 4 elements
|
||||
_this.parent( '.gp-spacing-section' ).prevAll().slice(0,4).find( 'input' ).removeClass( 'linked-values' ).attr( 'data-element', '' );
|
||||
_this.parent( '.gp-spacing-section' ).prevAll().slice( 0, 4 ).find( 'input' ).removeClass( 'linked-values' ).attr( 'data-element', '' );
|
||||
|
||||
// Change our link icon class
|
||||
_this.hide();
|
||||
_this.prev( 'span' ).show();
|
||||
});
|
||||
} );
|
||||
|
||||
$( '.gp-spacing-section' ).on( 'input', '.linked-values', function() {
|
||||
var _this = $( this ),
|
||||
@ -191,10 +195,9 @@ jQuery( document ).ready( function($) {
|
||||
val = _this.val(),
|
||||
targetElements = _this.closest( '.spacing-values-area' ).find( '.linked-values[ data-element="' + data + '" ]' );
|
||||
|
||||
|
||||
targetElements.each( function( key, value ) {
|
||||
targetElements.each( function() {
|
||||
var element = $( this );
|
||||
element.val( val ).change();
|
||||
});
|
||||
});
|
||||
});
|
||||
} );
|
||||
} );
|
||||
} );
|
||||
|
@ -1,7 +1,6 @@
|
||||
( function( api ) {
|
||||
|
||||
api.controlConstructor['gp-pro-customizer-typography'] = api.Control.extend( {
|
||||
ready: function() {
|
||||
api.controlConstructor[ 'gp-pro-customizer-typography' ] = api.Control.extend( {
|
||||
ready() {
|
||||
var control = this;
|
||||
|
||||
control.container.on( 'change', '.generatepress-font-family select',
|
||||
@ -12,35 +11,34 @@
|
||||
_variantsID = _this.attr( 'data-variants' );
|
||||
|
||||
// Set our font family
|
||||
control.settings['family'].set( _this.val() );
|
||||
control.settings.family.set( _this.val() );
|
||||
|
||||
// Bail if our controls don't exist
|
||||
if ( 'undefined' == typeof control.settings['category'] || 'undefined' == typeof control.settings['variant'] ) {
|
||||
if ( 'undefined' === typeof control.settings.category || 'undefined' === typeof control.settings.variant ) {
|
||||
return;
|
||||
}
|
||||
|
||||
setTimeout( function() {
|
||||
// Send our request to the generate_get_all_google_fonts_ajax function
|
||||
var response = jQuery.getJSON({
|
||||
var response = jQuery.getJSON( {
|
||||
type: 'POST',
|
||||
url: ajaxurl,
|
||||
data: {
|
||||
action: 'generate_get_all_google_fonts_ajax',
|
||||
gp_customize_nonce: gp_customize.nonce
|
||||
gp_customize_nonce: gp_customize.nonce,
|
||||
},
|
||||
async: false,
|
||||
dataType: 'json',
|
||||
});
|
||||
} );
|
||||
|
||||
// Get our response
|
||||
var fonts = response.responseJSON;
|
||||
|
||||
// Create an ID from our selected font
|
||||
var id = _value.split(' ').join('_').toLowerCase();
|
||||
var id = _value.split( ' ' ).join( '_' ).toLowerCase();
|
||||
|
||||
// Set our values if we have them
|
||||
if ( id in fonts ) {
|
||||
|
||||
// Get existing variants if this font is already selected
|
||||
var got_variants = false;
|
||||
jQuery( '.generatepress-font-family select' ).not( _this ).each( function( key, select ) {
|
||||
@ -67,18 +65,18 @@
|
||||
|
||||
// Set our variants
|
||||
if ( ! got_variants ) {
|
||||
control.settings[ 'variant' ].set( fonts[ id ].variants );
|
||||
control.settings.variant.set( fonts[ id ].variants );
|
||||
} else {
|
||||
control.settings[ 'variant' ].set( updated_variants );
|
||||
control.settings.variant.set( updated_variants );
|
||||
}
|
||||
|
||||
// Set our font category
|
||||
control.settings[ 'category' ].set( fonts[ id ].category );
|
||||
control.settings.category.set( fonts[ id ].category );
|
||||
jQuery( 'input[name="' + _categoryID + '"' ).val( fonts[ id ].category );
|
||||
} else {
|
||||
_this.closest( '.generatepress-font-family' ).next( 'div' ).hide();
|
||||
control.settings[ 'category' ].set( '' )
|
||||
control.settings[ 'variant' ].set( '' )
|
||||
control.settings.category.set( '' );
|
||||
control.settings.variant.set( '' );
|
||||
jQuery( 'input[name="' + _categoryID + '"' ).val( '' );
|
||||
jQuery( 'select[name="' + _variantsID + '"]' ).find( 'option' ).remove();
|
||||
}
|
||||
@ -91,16 +89,16 @@
|
||||
var _this = jQuery( this );
|
||||
var variants = _this.val();
|
||||
|
||||
control.settings['variant'].set( variants );
|
||||
control.settings.variant.set( variants );
|
||||
|
||||
jQuery( '.generatepress-font-variant select' ).each( function( key, value ) {
|
||||
var this_control = jQuery( this ).closest( 'li' ).attr( 'id' ).replace( 'customize-control-', '' );
|
||||
var parent = jQuery( this ).closest( '.generatepress-font-variant' );
|
||||
var font_val = api.control( this_control ).settings['family'].get();
|
||||
var font_val = api.control( this_control ).settings.family.get();
|
||||
|
||||
if ( font_val == control.settings['family'].get() && _this.attr( 'name' ) !== jQuery( value ).attr( 'name' ) ) {
|
||||
if ( font_val == control.settings.family.get() && _this.attr( 'name' ) !== jQuery( value ).attr( 'name' ) ) {
|
||||
jQuery( parent.find( 'select' ) ).not( _this ).val( variants ).triggerHandler( 'change' );
|
||||
api.control( this_control ).settings['variant'].set( variants );
|
||||
api.control( this_control ).settings.variant.set( variants );
|
||||
}
|
||||
} );
|
||||
}
|
||||
@ -108,44 +106,43 @@
|
||||
|
||||
control.container.on( 'change', '.generatepress-font-category input',
|
||||
function() {
|
||||
control.settings['category'].set( jQuery( this ).val() );
|
||||
control.settings.category.set( jQuery( this ).val() );
|
||||
}
|
||||
);
|
||||
|
||||
control.container.on( 'change', '.generatepress-font-weight select',
|
||||
function() {
|
||||
control.settings['weight'].set( jQuery( this ).val() );
|
||||
control.settings.weight.set( jQuery( this ).val() );
|
||||
}
|
||||
);
|
||||
|
||||
control.container.on( 'change', '.generatepress-font-transform select',
|
||||
function() {
|
||||
control.settings['transform'].set( jQuery( this ).val() );
|
||||
control.settings.transform.set( jQuery( this ).val() );
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
},
|
||||
} );
|
||||
}( wp.customize ) );
|
||||
|
||||
} )( wp.customize );
|
||||
|
||||
jQuery( document ).ready( function($) {
|
||||
|
||||
jQuery( document ).ready( function( $ ) {
|
||||
jQuery( '.generatepress-font-family select' ).selectWoo();
|
||||
jQuery( '.generatepress-font-variant' ).each( function( key, value ) {
|
||||
var _this = $( this );
|
||||
var value = _this.data( 'saved-value' );
|
||||
value = _this.data( 'saved-value' );
|
||||
|
||||
if ( value ) {
|
||||
value = value.toString().split( ',' );
|
||||
}
|
||||
|
||||
_this.find( 'select' ).selectWoo().val( value ).trigger( 'change.select2' );
|
||||
} );
|
||||
|
||||
$( ".generatepress-font-family" ).each( function( key, value ) {
|
||||
$( '.generatepress-font-family' ).each( function( key, value ) {
|
||||
var _this = $( this );
|
||||
|
||||
if ( $.inArray( _this.find( 'select' ).val(), typography_defaults ) !== -1 ) {
|
||||
_this.next( '.generatepress-font-variant' ).hide();
|
||||
}
|
||||
});
|
||||
|
||||
} );
|
||||
} );
|
||||
|
Reference in New Issue
Block a user