first commit
This commit is contained in:
@@ -0,0 +1,151 @@
|
||||
<?php
|
||||
|
||||
namespace Elementor\Core\Schemes;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
abstract class Base_UI extends Base {
|
||||
|
||||
/**
|
||||
* System schemes.
|
||||
*
|
||||
* Holds the list of all the system schemes.
|
||||
*
|
||||
* @since 2.8.0
|
||||
* @access private
|
||||
*
|
||||
* @var array System schemes.
|
||||
*/
|
||||
private $_system_schemes;
|
||||
|
||||
/**
|
||||
* Get scheme title.
|
||||
*
|
||||
* Retrieve the scheme title.
|
||||
*
|
||||
* @since 2.8.0
|
||||
* @access public
|
||||
*/
|
||||
abstract public function get_title();
|
||||
|
||||
/**
|
||||
* Get scheme disabled title.
|
||||
*
|
||||
* Retrieve the scheme disabled title.
|
||||
*
|
||||
* @since 2.8.0
|
||||
* @access public
|
||||
*/
|
||||
abstract public function get_disabled_title();
|
||||
|
||||
/**
|
||||
* Get scheme titles.
|
||||
*
|
||||
* Retrieve the scheme titles.
|
||||
*
|
||||
* @since 2.8.0
|
||||
* @access public
|
||||
*/
|
||||
abstract public function get_scheme_titles();
|
||||
|
||||
/**
|
||||
* Print scheme content template.
|
||||
*
|
||||
* Used to generate the HTML in the editor using Underscore JS template. The
|
||||
* variables for the class are available using `data` JS object.
|
||||
*
|
||||
* @since 2.8.0
|
||||
* @access public
|
||||
*/
|
||||
abstract public function print_template_content();
|
||||
|
||||
/**
|
||||
* Init system schemes.
|
||||
*
|
||||
* Initialize the system schemes.
|
||||
*
|
||||
* @since 2.8.0
|
||||
* @access protected
|
||||
* @abstract
|
||||
*/
|
||||
abstract protected function _init_system_schemes();
|
||||
|
||||
/**
|
||||
* Get system schemes.
|
||||
*
|
||||
* Retrieve the system schemes.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
*
|
||||
* @return array System schemes.
|
||||
*/
|
||||
final public function get_system_schemes() {
|
||||
if ( null === $this->_system_schemes ) {
|
||||
$this->_system_schemes = $this->_init_system_schemes();
|
||||
}
|
||||
|
||||
return $this->_system_schemes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Print scheme template.
|
||||
*
|
||||
* Used to generate the scheme template on the editor using Underscore JS
|
||||
* template.
|
||||
*
|
||||
* @since 2.8.0
|
||||
* @access public
|
||||
*/
|
||||
final public function print_template() {
|
||||
?>
|
||||
<script type="text/template" id="tmpl-elementor-panel-schemes-<?php echo static::get_type(); ?>">
|
||||
<div class="elementor-panel-scheme-buttons">
|
||||
<div class="elementor-panel-scheme-button-wrapper elementor-panel-scheme-reset">
|
||||
<button class="elementor-button">
|
||||
<i class="fa fa-undo" aria-hidden="true"></i>
|
||||
<?php echo __( 'Reset', 'elementor' ); ?>
|
||||
</button>
|
||||
</div>
|
||||
<div class="elementor-panel-scheme-button-wrapper elementor-panel-scheme-discard">
|
||||
<button class="elementor-button">
|
||||
<i class="eicon-close" aria-hidden="true"></i>
|
||||
<?php echo __( 'Discard', 'elementor' ); ?>
|
||||
</button>
|
||||
</div>
|
||||
<div class="elementor-panel-scheme-button-wrapper elementor-panel-scheme-save">
|
||||
<button class="elementor-button elementor-button-success" disabled><?php echo __( 'Apply', 'elementor' ); ?></button>
|
||||
</div>
|
||||
</div>
|
||||
<?php $this->print_template_content(); ?>
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Get scheme.
|
||||
*
|
||||
* Retrieve the scheme.
|
||||
*
|
||||
* @since 2.8.0
|
||||
* @access public
|
||||
*
|
||||
* @return array The scheme.
|
||||
*/
|
||||
public function get_scheme() {
|
||||
$scheme = [];
|
||||
|
||||
$titles = $this->get_scheme_titles();
|
||||
|
||||
foreach ( $this->get_scheme_value() as $scheme_key => $scheme_value ) {
|
||||
$scheme[ $scheme_key ] = [
|
||||
'title' => isset( $titles[ $scheme_key ] ) ? $titles[ $scheme_key ] : '',
|
||||
'value' => $scheme_value,
|
||||
];
|
||||
}
|
||||
|
||||
return $scheme;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
namespace Elementor\Core\Schemes;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
/**
|
||||
* Elementor scheme base.
|
||||
*
|
||||
* An abstract class implementing the scheme interface, responsible for
|
||||
* creating new schemes.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @abstract
|
||||
*/
|
||||
abstract class Base {
|
||||
|
||||
/**
|
||||
* DB option name for the time when the scheme was last updated.
|
||||
*/
|
||||
const LAST_UPDATED_META = '_elementor_scheme_last_updated';
|
||||
|
||||
/**
|
||||
* Get scheme type.
|
||||
*
|
||||
* Retrieve the scheme type.
|
||||
*
|
||||
* @since 2.8.0
|
||||
* @access public
|
||||
* @static
|
||||
*/
|
||||
public static function get_type() {
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default scheme.
|
||||
*
|
||||
* Retrieve the default scheme.
|
||||
*
|
||||
* @since 2.8.0
|
||||
* @access public
|
||||
*/
|
||||
abstract public function get_default_scheme();
|
||||
|
||||
/**
|
||||
* Get description.
|
||||
*
|
||||
* Retrieve the scheme description.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
* @static
|
||||
*
|
||||
* @return string Scheme description.
|
||||
*/
|
||||
public static function get_description() {
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get scheme value.
|
||||
*
|
||||
* Retrieve the scheme value.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
*
|
||||
* @return array Scheme value.
|
||||
*/
|
||||
public function get_scheme_value() {
|
||||
$scheme_value = get_option( 'elementor_scheme_' . static::get_type() );
|
||||
|
||||
if ( ! $scheme_value ) {
|
||||
$scheme_value = $this->get_default_scheme();
|
||||
|
||||
update_option( 'elementor_scheme_' . static::get_type(), $scheme_value );
|
||||
}
|
||||
|
||||
return $scheme_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save scheme.
|
||||
*
|
||||
* Update Elementor scheme in the database, and update the last updated
|
||||
* scheme time.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
*
|
||||
* @param array $posted
|
||||
*/
|
||||
public function save_scheme( array $posted ) {
|
||||
update_option( 'elementor_scheme_' . static::get_type(), $posted );
|
||||
|
||||
update_option( self::LAST_UPDATED_META, time() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get scheme.
|
||||
*
|
||||
* Retrieve the scheme.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
*
|
||||
* @return array The scheme.
|
||||
*/
|
||||
public function get_scheme() {
|
||||
$scheme = [];
|
||||
|
||||
foreach ( $this->get_scheme_value() as $scheme_key => $scheme_value ) {
|
||||
$scheme[ $scheme_key ] = [
|
||||
'value' => $scheme_value,
|
||||
];
|
||||
}
|
||||
|
||||
return $scheme;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
namespace Elementor\Core\Schemes;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
/**
|
||||
* Elementor color picker scheme.
|
||||
*
|
||||
* Elementor color picker scheme class is responsible for initializing a scheme
|
||||
* for color pickers.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Color_Picker extends Base {
|
||||
|
||||
/**
|
||||
* Get color picker scheme type.
|
||||
*
|
||||
* Retrieve the color picker scheme type.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
* @static
|
||||
*
|
||||
* @return string Color picker scheme type.
|
||||
*/
|
||||
public static function get_type() {
|
||||
return 'color-picker';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default color picker scheme.
|
||||
*
|
||||
* Retrieve the default color picker scheme.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
*
|
||||
* @return array Default color picker scheme.
|
||||
*/
|
||||
public function get_default_scheme() {
|
||||
return [
|
||||
1 => '#6ec1e4',
|
||||
2 => '#54595f',
|
||||
3 => '#7a7a7a',
|
||||
4 => '#61ce70',
|
||||
5 => '#4054b2',
|
||||
6 => '#23a455',
|
||||
7 => '#000',
|
||||
8 => '#fff',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,286 @@
|
||||
<?php
|
||||
namespace Elementor\Core\Schemes;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
/**
|
||||
* Elementor color scheme.
|
||||
*
|
||||
* Elementor color scheme class is responsible for initializing a scheme for
|
||||
* colors.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Color extends Base_UI {
|
||||
|
||||
/**
|
||||
* 1st color scheme.
|
||||
*/
|
||||
const COLOR_1 = '1';
|
||||
|
||||
/**
|
||||
* 2nd color scheme.
|
||||
*/
|
||||
const COLOR_2 = '2';
|
||||
|
||||
/**
|
||||
* 3rd color scheme.
|
||||
*/
|
||||
const COLOR_3 = '3';
|
||||
|
||||
/**
|
||||
* 4th color scheme.
|
||||
*/
|
||||
const COLOR_4 = '4';
|
||||
|
||||
/**
|
||||
* Get color scheme type.
|
||||
*
|
||||
* Retrieve the color scheme type.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
* @static
|
||||
*
|
||||
* @return string Color scheme type.
|
||||
*/
|
||||
public static function get_type() {
|
||||
return 'color';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get color scheme title.
|
||||
*
|
||||
* Retrieve the color scheme title.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
*
|
||||
* @return string Color scheme title.
|
||||
*/
|
||||
public function get_title() {
|
||||
return __( 'Colors', 'elementor' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get color scheme disabled title.
|
||||
*
|
||||
* Retrieve the color scheme disabled title.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
*
|
||||
* @return string Color scheme disabled title.
|
||||
*/
|
||||
public function get_disabled_title() {
|
||||
return __( 'Color Palettes', 'elementor' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get color scheme titles.
|
||||
*
|
||||
* Retrieve the color scheme titles.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
*
|
||||
* @return array Color scheme titles.
|
||||
*/
|
||||
public function get_scheme_titles() {
|
||||
return [
|
||||
self::COLOR_1 => __( 'Primary', 'elementor' ),
|
||||
self::COLOR_2 => __( 'Secondary', 'elementor' ),
|
||||
self::COLOR_3 => __( 'Text', 'elementor' ),
|
||||
self::COLOR_4 => __( 'Accent', 'elementor' ),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default color scheme.
|
||||
*
|
||||
* Retrieve the default color scheme.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
*
|
||||
* @return array Default color scheme.
|
||||
*/
|
||||
public function get_default_scheme() {
|
||||
return [
|
||||
self::COLOR_1 => '#6ec1e4',
|
||||
self::COLOR_2 => '#54595f',
|
||||
self::COLOR_3 => '#7a7a7a',
|
||||
self::COLOR_4 => '#61ce70',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Print color scheme content template.
|
||||
*
|
||||
* Used to generate the HTML in the editor using Underscore JS template. The
|
||||
* variables for the class are available using `data` JS object.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
*/
|
||||
public function print_template_content() {
|
||||
?>
|
||||
<div class="elementor-panel-scheme-content elementor-panel-box">
|
||||
<div class="elementor-panel-heading">
|
||||
<div class="elementor-panel-heading-title"><?php echo $this->_get_current_scheme_title(); ?></div>
|
||||
</div>
|
||||
<?php
|
||||
$description = static::get_description();
|
||||
|
||||
if ( $description ) :
|
||||
?>
|
||||
<div class="elementor-panel-scheme-description elementor-descriptor"><?php echo $description; ?></div>
|
||||
<?php endif; ?>
|
||||
<div class="elementor-panel-scheme-items elementor-panel-box-content"></div>
|
||||
</div>
|
||||
<div class="elementor-panel-scheme-colors-more-palettes elementor-panel-box">
|
||||
<div class="elementor-panel-heading">
|
||||
<div class="elementor-panel-heading-title"><?php echo __( 'More Palettes', 'elementor' ); ?></div>
|
||||
</div>
|
||||
<div class="elementor-panel-box-content">
|
||||
<?php foreach ( $this->_get_system_schemes_to_print() as $scheme_name => $scheme ) : ?>
|
||||
<div class="elementor-panel-scheme-color-system-scheme" data-scheme-name="<?php echo esc_attr( $scheme_name ); ?>">
|
||||
<div class="elementor-panel-scheme-color-system-items">
|
||||
<?php foreach ( $scheme['items'] as $color_value ) : ?>
|
||||
<div class="elementor-panel-scheme-color-system-item" style="background-color: <?php echo esc_attr( $color_value ); ?>;"></div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<div class="elementor-title"><?php echo $scheme['title']; ?></div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Init system color schemes.
|
||||
*
|
||||
* Initialize the system color schemes.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access protected
|
||||
*
|
||||
* @return array System color schemes.
|
||||
*/
|
||||
protected function _init_system_schemes() {
|
||||
return [
|
||||
'joker' => [
|
||||
'title' => 'Joker',
|
||||
'items' => [
|
||||
self::COLOR_1 => '#202020',
|
||||
self::COLOR_2 => '#b7b4b4',
|
||||
self::COLOR_3 => '#707070',
|
||||
self::COLOR_4 => '#f6121c',
|
||||
],
|
||||
],
|
||||
'ocean' => [
|
||||
'title' => 'Ocean',
|
||||
'items' => [
|
||||
self::COLOR_1 => '#1569ae',
|
||||
self::COLOR_2 => '#b6c9db',
|
||||
self::COLOR_3 => '#545454',
|
||||
self::COLOR_4 => '#fdd247',
|
||||
],
|
||||
],
|
||||
'royal' => [
|
||||
'title' => 'Royal',
|
||||
'items' => [
|
||||
self::COLOR_1 => '#d5ba7f',
|
||||
self::COLOR_2 => '#902729',
|
||||
self::COLOR_3 => '#ae4848',
|
||||
self::COLOR_4 => '#302a8c',
|
||||
],
|
||||
],
|
||||
'violet' => [
|
||||
'title' => 'Violet',
|
||||
'items' => [
|
||||
self::COLOR_1 => '#747476',
|
||||
self::COLOR_2 => '#ebca41',
|
||||
self::COLOR_3 => '#6f1683',
|
||||
self::COLOR_4 => '#a43cbd',
|
||||
],
|
||||
],
|
||||
'sweet' => [
|
||||
'title' => 'Sweet',
|
||||
'items' => [
|
||||
self::COLOR_1 => '#6ccdd9',
|
||||
self::COLOR_2 => '#763572',
|
||||
self::COLOR_3 => '#919ca7',
|
||||
self::COLOR_4 => '#f12184',
|
||||
],
|
||||
],
|
||||
'urban' => [
|
||||
'title' => 'Urban',
|
||||
'items' => [
|
||||
self::COLOR_1 => '#db6159',
|
||||
self::COLOR_2 => '#3b3b3b',
|
||||
self::COLOR_3 => '#7a7979',
|
||||
self::COLOR_4 => '#2abf64',
|
||||
],
|
||||
],
|
||||
'earth' => [
|
||||
'title' => 'Earth',
|
||||
'items' => [
|
||||
self::COLOR_1 => '#882021',
|
||||
self::COLOR_2 => '#c48e4c',
|
||||
self::COLOR_3 => '#825e24',
|
||||
self::COLOR_4 => '#e8c12f',
|
||||
],
|
||||
],
|
||||
'river' => [
|
||||
'title' => 'River',
|
||||
'items' => [
|
||||
self::COLOR_1 => '#8dcfc8',
|
||||
self::COLOR_2 => '#565656',
|
||||
self::COLOR_3 => '#50656e',
|
||||
self::COLOR_4 => '#dc5049',
|
||||
],
|
||||
],
|
||||
'pastel' => [
|
||||
'title' => 'Pastel',
|
||||
'items' => [
|
||||
self::COLOR_1 => '#f27f6f',
|
||||
self::COLOR_2 => '#f4cd78',
|
||||
self::COLOR_3 => '#a5b3c1',
|
||||
self::COLOR_4 => '#aac9c3',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get system color schemes to print.
|
||||
*
|
||||
* Retrieve the system color schemes
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access protected
|
||||
*
|
||||
* @return array The system color schemes.
|
||||
*/
|
||||
protected function _get_system_schemes_to_print() {
|
||||
return $this->get_system_schemes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current color scheme title.
|
||||
*
|
||||
* Retrieve the current color scheme title.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access protected
|
||||
*
|
||||
* @return string The current color scheme title.
|
||||
*/
|
||||
protected function _get_current_scheme_title() {
|
||||
return __( 'Color Palette', 'elementor' );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,371 @@
|
||||
<?php
|
||||
namespace Elementor\Core\Schemes;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
use Elementor\Core\Common\Modules\Ajax\Module as Ajax;
|
||||
use Elementor\TemplateLibrary\Source_Local;
|
||||
use Elementor\User;
|
||||
|
||||
/**
|
||||
* Elementor scheme manager.
|
||||
*
|
||||
* Elementor scheme manager handler class is responsible for registering and
|
||||
* initializing all the supported schemes.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Manager {
|
||||
|
||||
/**
|
||||
* Registered schemes.
|
||||
*
|
||||
* Holds the list of all the registered schemes.
|
||||
*
|
||||
* @access protected
|
||||
*
|
||||
* @var Base[]
|
||||
*/
|
||||
protected $_registered_schemes = [];
|
||||
|
||||
/**
|
||||
* Enabled schemes.
|
||||
*
|
||||
* Holds the list of all the enabled schemes.
|
||||
*
|
||||
* @access private
|
||||
* @static
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private static $_enabled_schemes;
|
||||
|
||||
/**
|
||||
* Schemes types.
|
||||
*
|
||||
* Holds the list of the schemes types. Default types are `color`,
|
||||
* `typography` and `color-picker`.
|
||||
*
|
||||
* @access private
|
||||
* @static
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private static $_schemes_types = [
|
||||
'color',
|
||||
'typography',
|
||||
'color-picker',
|
||||
];
|
||||
|
||||
/**
|
||||
* Register new scheme.
|
||||
*
|
||||
* Add a new scheme to the schemes list. The method creates a new scheme
|
||||
* instance for any given scheme class and adds the scheme to the registered
|
||||
* schemes list.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
*
|
||||
* @param string $scheme_class Scheme class name.
|
||||
*/
|
||||
public function register_scheme( $scheme_class ) {
|
||||
/** @var Base $scheme_instance */
|
||||
$scheme_instance = new $scheme_class();
|
||||
|
||||
$this->_registered_schemes[ $scheme_instance::get_type() ] = $scheme_instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregister scheme.
|
||||
*
|
||||
* Removes a scheme from the list of registered schemes.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
*
|
||||
* @param string $id Scheme ID.
|
||||
*
|
||||
* @return bool True if the scheme was removed, False otherwise.
|
||||
*/
|
||||
public function unregister_scheme( $id ) {
|
||||
if ( ! isset( $this->_registered_schemes[ $id ] ) ) {
|
||||
return false;
|
||||
}
|
||||
unset( $this->_registered_schemes[ $id ] );
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get registered schemes.
|
||||
*
|
||||
* Retrieve the registered schemes list from the current instance.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
*
|
||||
* @return Base[] Registered schemes.
|
||||
*/
|
||||
public function get_registered_schemes() {
|
||||
return $this->_registered_schemes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get schemes data.
|
||||
*
|
||||
* Retrieve all the registered schemes with data for each scheme.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
*
|
||||
* @return array Registered schemes with each scheme data.
|
||||
*/
|
||||
public function get_registered_schemes_data() {
|
||||
$data = [];
|
||||
|
||||
foreach ( $this->get_registered_schemes() as $scheme ) {
|
||||
$type = $scheme::get_type();
|
||||
|
||||
$data[ $type ] = [
|
||||
'items' => $scheme->get_scheme(),
|
||||
];
|
||||
|
||||
if ( $scheme instanceof Base_UI ) {
|
||||
$data[ $type ]['title'] = $scheme->get_title();
|
||||
$data[ $type ]['disabled_title'] = $scheme->get_disabled_title();
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default schemes.
|
||||
*
|
||||
* Retrieve all the registered schemes with default scheme for each scheme.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
*
|
||||
* @return array Registered schemes with with default scheme for each scheme.
|
||||
*/
|
||||
public function get_schemes_defaults() {
|
||||
$data = [];
|
||||
|
||||
foreach ( $this->get_registered_schemes() as $scheme ) {
|
||||
$type = $scheme::get_type();
|
||||
|
||||
$data[ $type ] = [
|
||||
'items' => $scheme->get_default_scheme(),
|
||||
];
|
||||
|
||||
if ( $scheme instanceof Base_UI ) {
|
||||
$data[ $type ]['title'] = $scheme->get_title();
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get system schemes.
|
||||
*
|
||||
* Retrieve all the registered ui schemes with system schemes for each scheme.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
*
|
||||
* @return array Registered ui schemes with with system scheme for each scheme.
|
||||
*/
|
||||
public function get_system_schemes() {
|
||||
$data = [];
|
||||
|
||||
foreach ( $this->get_registered_schemes() as $scheme ) {
|
||||
if ( $scheme instanceof Base_UI ) {
|
||||
$data[ $scheme::get_type() ] = $scheme->get_system_schemes();
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get scheme.
|
||||
*
|
||||
* Retrieve a single scheme from the list of all the registered schemes in
|
||||
* the current instance.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
*
|
||||
* @param string $id Scheme ID.
|
||||
*
|
||||
* @return false|Base Scheme instance if scheme exist, False otherwise.
|
||||
*/
|
||||
public function get_scheme( $id ) {
|
||||
$schemes = $this->get_registered_schemes();
|
||||
|
||||
if ( ! isset( $schemes[ $id ] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $schemes[ $id ];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get scheme value.
|
||||
*
|
||||
* Retrieve the scheme value from the list of all the registered schemes in
|
||||
* the current instance.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
*
|
||||
* @param string $scheme_type Scheme type.
|
||||
* @param string $scheme_value Scheme value.
|
||||
*
|
||||
* @return false|string Scheme value if scheme exist, False otherwise.
|
||||
*/
|
||||
public function get_scheme_value( $scheme_type, $scheme_value ) {
|
||||
$scheme = $this->get_scheme( $scheme_type );
|
||||
|
||||
if ( ! $scheme ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $scheme->get_scheme_value()[ $scheme_value ];
|
||||
}
|
||||
|
||||
/**
|
||||
* Ajax apply scheme.
|
||||
*
|
||||
* Ajax handler for Elementor apply_scheme.
|
||||
*
|
||||
* Fired by `wp_ajax_elementor_apply_scheme` action.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function ajax_apply_scheme( array $data ) {
|
||||
if ( ! User::is_current_user_can_edit_post_type( Source_Local::CPT ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! isset( $data['scheme_name'] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$scheme_obj = $this->get_scheme( $data['scheme_name'] );
|
||||
|
||||
if ( ! $scheme_obj ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$posted = json_decode( $data['data'], true );
|
||||
|
||||
$scheme_obj->save_scheme( $posted );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Print ui schemes templates.
|
||||
*
|
||||
* Used to generate the scheme templates on the editor using Underscore JS
|
||||
* template, for all the registered ui schemes.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
*/
|
||||
public function print_schemes_templates() {
|
||||
foreach ( $this->get_registered_schemes() as $scheme ) {
|
||||
if ( $scheme instanceof Base_UI ) {
|
||||
$scheme->print_template();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Ajax $ajax
|
||||
*
|
||||
* @since 2.3.0
|
||||
* @access public
|
||||
*/
|
||||
public function register_ajax_actions( Ajax $ajax ) {
|
||||
$ajax->register_ajax_action( 'apply_scheme', [ $this, 'ajax_apply_scheme' ] );
|
||||
}
|
||||
/**
|
||||
* Get enabled schemes.
|
||||
*
|
||||
* Retrieve all enabled schemes from the list of the registered schemes in
|
||||
* the current instance.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
* @static
|
||||
*
|
||||
* @return array Enabled schemes.
|
||||
*/
|
||||
public static function get_enabled_schemes() {
|
||||
if ( null === self::$_enabled_schemes ) {
|
||||
$enabled_schemes = [];
|
||||
|
||||
foreach ( self::$_schemes_types as $schemes_type ) {
|
||||
if ( 'yes' === get_option( 'elementor_disable_' . $schemes_type . '_schemes' ) ) {
|
||||
continue;
|
||||
}
|
||||
$enabled_schemes[] = $schemes_type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enabled schemes.
|
||||
*
|
||||
* Filters the list of enabled schemes.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param array $enabled_schemes The list of enabled schemes.
|
||||
*/
|
||||
$enabled_schemes = apply_filters( 'elementor/schemes/enabled_schemes', $enabled_schemes );
|
||||
|
||||
self::$_enabled_schemes = $enabled_schemes;
|
||||
}
|
||||
return self::$_enabled_schemes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register default schemes.
|
||||
*
|
||||
* Add a default schemes to the register schemes list.
|
||||
*
|
||||
* This method is used to set initial schemes when initializing the class.
|
||||
*
|
||||
* @since 1.7.12
|
||||
* @access private
|
||||
*/
|
||||
private function register_default_schemes() {
|
||||
foreach ( self::$_schemes_types as $scheme_type ) {
|
||||
$this->register_scheme( __NAMESPACE__ . '\\' . str_replace( '-', '_', ucwords( $scheme_type, '-' ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Schemes manager constructor.
|
||||
*
|
||||
* Initializing Elementor schemes manager and register default schemes.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->register_default_schemes();
|
||||
|
||||
add_action( 'elementor/ajax/register_actions', [ $this, 'register_ajax_actions' ] );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
<?php
|
||||
namespace Elementor\Core\Schemes;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
/**
|
||||
* Elementor typography scheme.
|
||||
*
|
||||
* Elementor typography scheme class is responsible for initializing a scheme
|
||||
* for typography.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Typography extends Base_UI {
|
||||
|
||||
/**
|
||||
* 1st typography scheme.
|
||||
*/
|
||||
const TYPOGRAPHY_1 = '1';
|
||||
|
||||
/**
|
||||
* 2nd typography scheme.
|
||||
*/
|
||||
const TYPOGRAPHY_2 = '2';
|
||||
|
||||
/**
|
||||
* 3rd typography scheme.
|
||||
*/
|
||||
const TYPOGRAPHY_3 = '3';
|
||||
|
||||
/**
|
||||
* 4th typography scheme.
|
||||
*/
|
||||
const TYPOGRAPHY_4 = '4';
|
||||
|
||||
/**
|
||||
* Get typography scheme type.
|
||||
*
|
||||
* Retrieve the typography scheme type.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
* @static
|
||||
*
|
||||
* @return string Typography scheme type.
|
||||
*/
|
||||
public static function get_type() {
|
||||
return 'typography';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get typography scheme title.
|
||||
*
|
||||
* Retrieve the typography scheme title.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
*
|
||||
* @return string Typography scheme title.
|
||||
*/
|
||||
public function get_title() {
|
||||
return __( 'Typography', 'elementor' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get typography scheme disabled title.
|
||||
*
|
||||
* Retrieve the typography scheme disabled title.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
*
|
||||
* @return string Typography scheme disabled title.
|
||||
*/
|
||||
public function get_disabled_title() {
|
||||
return __( 'Default Fonts', 'elementor' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get typography scheme titles.
|
||||
*
|
||||
* Retrieve the typography scheme titles.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
*
|
||||
* @return array Typography scheme titles.
|
||||
*/
|
||||
public function get_scheme_titles() {
|
||||
return [
|
||||
self::TYPOGRAPHY_1 => __( 'Primary Headline', 'elementor' ),
|
||||
self::TYPOGRAPHY_2 => __( 'Secondary Headline', 'elementor' ),
|
||||
self::TYPOGRAPHY_3 => __( 'Body Text', 'elementor' ),
|
||||
self::TYPOGRAPHY_4 => __( 'Accent Text', 'elementor' ),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default typography scheme.
|
||||
*
|
||||
* Retrieve the default typography scheme.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
*
|
||||
* @return array Default typography scheme.
|
||||
*/
|
||||
public function get_default_scheme() {
|
||||
return [
|
||||
self::TYPOGRAPHY_1 => [
|
||||
'font_family' => 'Roboto',
|
||||
'font_weight' => '600',
|
||||
],
|
||||
self::TYPOGRAPHY_2 => [
|
||||
'font_family' => 'Roboto Slab',
|
||||
'font_weight' => '400',
|
||||
],
|
||||
self::TYPOGRAPHY_3 => [
|
||||
'font_family' => 'Roboto',
|
||||
'font_weight' => '400',
|
||||
],
|
||||
self::TYPOGRAPHY_4 => [
|
||||
'font_family' => 'Roboto',
|
||||
'font_weight' => '500',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Init system typography schemes.
|
||||
*
|
||||
* Initialize the system typography schemes.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access protected
|
||||
*
|
||||
* @return array System typography schemes.
|
||||
*/
|
||||
protected function _init_system_schemes() {
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Print typography scheme content template.
|
||||
*
|
||||
* Used to generate the HTML in the editor using Underscore JS template. The
|
||||
* variables for the class are available using `data` JS object.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
*/
|
||||
public function print_template_content() {
|
||||
?>
|
||||
<div class="elementor-panel-scheme-items"></div>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user