Update to Kirki 4.2.0

This commit is contained in:
AlxMedia 2023-08-04 15:41:48 +02:00
parent cbfd4f27e4
commit 77ecd4ca69
440 changed files with 6230 additions and 5211 deletions

View file

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2019 Kirki Framework
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View file

@ -0,0 +1,180 @@
<?php
/**
* Creates a new Section.
*
* @package kirki-framework/module-sections
* @copyright Copyright (c) 2023, Themeum
* @license https://opensource.org/licenses/MIT
* @since 1.0.0
*/
namespace Kirki;
/**
* Section.
*/
class Section {
/**
* The section ID.
*
* @access protected
* @since 1.0.0
* @var string
*/
protected $id;
/**
* The section arguments.
*
* @access protected
* @since 1.0.0
* @var array
*/
protected $args;
/**
* An array of our section types.
*
* @access private
* @var array
*/
private $section_types = [
'kirki-expanded' => '\Kirki\Section_Types\Expanded',
'kirki-nested' => '\Kirki\Section_Types\Nested',
'kirki-link' => '\Kirki\Section_Types\Link',
'kirki-outer' => '\Kirki\Section_Types\Outer',
];
/**
* Constructor.
*
* @access public
* @since 1.0.0
* @param string $id The section ID.
* @param array $args The section args.
*/
public function __construct( $id, $args = [] ) {
$this->id = $id;
$this->args = $args;
$this->section_types = apply_filters( 'kirki_section_types', $this->section_types );
do_action( 'kirki_section_init', $id, $args );
add_action( 'customize_register', [ $this, 'register_section_types' ] );
if ( $this->args ) {
add_action( 'customize_register', [ $this, 'add_section' ] );
}
add_action( 'customize_controls_enqueue_scripts', [ $this, 'enqueue_scrips' ] );
add_action( 'customize_controls_print_footer_scripts', [ $this, 'outer_sections_css' ] );
}
/**
* Register section types.
*
* @access public
* @since 1.0.0
* @param object $wp_customize The customizer object.
* @return void
*/
public function register_section_types( $wp_customize ) {
foreach ( $this->section_types as $section_type ) {
$wp_customize->register_section_type( $section_type );
}
}
/**
* Add the section using the Customizer API.
*
* @access public
* @since 1.0.0
* @param object $wp_customize The customizer object.
*/
public function add_section( $wp_customize ) {
// Figure out the type of this section.
$this->args['type'] = isset( $this->args['type'] ) ? $this->args['type'] : 'default';
if ( isset( $this->args['section'] ) && ! empty( $this->args['section'] ) ) {
$this->args['type'] = 'kirki-nested';
// We need to check if the parent section is nested inside a panel.
$parent_section = $wp_customize->get_section( $this->args['section'] );
if ( $parent_section && isset( $parent_section->panel ) ) {
$this->args['panel'] = $parent_section->panel;
}
}
$this->args['type'] = false === strpos( $this->args['type'], 'kirki-' ) ? 'kirki-' . $this->args['type'] : $this->args['type'];
// Get the class we'll be using to create this section.
$section_classname = '\WP_Customize_Section';
if ( isset( $this->section_types[ $this->args['type'] ] ) ) {
$section_classname = $this->section_types[ $this->args['type'] ];
}
if ( isset( $this->args['type'] ) && 'kirki-outer' === $this->args['type'] ) {
$this->args['type'] = 'outer';
$section_classname = 'WP_Customize_Section'; // ? Bagus: we should be using `\` (backslash) right? Lookk at above.
}
// Add the section.
$wp_customize->add_section(
new $section_classname(
$wp_customize,
$this->id,
apply_filters( 'kirki_section_args', $this->args, $this->id )
)
);
// Run an action after the section has been added.
do_action( 'kirki_section_added', $this->id, $this->args );
}
/**
* Removes the section.
*
* @access public
* @since 1.0.0
* @return void
*/
public function remove() {
add_action( 'customize_register', [ $this, 'remove_section' ], 9999 );
}
/**
* Add the section using the Customizer API.
*
* @access public
* @since 1.0.0
* @param object $wp_customize The customizer object.
*/
public function remove_section( $wp_customize ) {
$wp_customize->remove_section( $this->id );
}
/**
* Enqueues any necessary scripts and styles.
*
* @access public
* @since 1.0.0
*/
public function enqueue_scrips() {
wp_enqueue_style( 'kirki-sections', URL::get_from_path( __DIR__ . '/styles.css' ), [], '1.0' );
wp_enqueue_script( 'kirki-sections', URL::get_from_path( __DIR__ . '/script.js' ), [ 'jquery', 'customize-base', 'customize-controls' ], '1.0', false );
}
/**
* Generate CSS for the outer sections.
* These are by default hidden, we need to expose them.
*
* @access public
* @since 1.0.0
* @return void
*/
public function outer_sections_css() {
if ( isset( $this->args['type'] ) && ( 'outer' === $this->args['type'] || 'kirki-outer' === $this->args['type'] ) ) {
echo '<style>#customize-theme-controls li#accordion-section-' . esc_html( $this->id ) . ',li#sub-accordion-section-' . esc_html( $this->id ) . '{display:list-item!important;}</style>';
}
}
}

View file

@ -0,0 +1,26 @@
<?php
/**
* An expanded section.
*
* @package kirki-framework/module-sections
* @copyright Copyright (c) 2023, Themeum
* @license https://opensource.org/licenses/MIT
* @since 1.0.0
*/
namespace Kirki\Section_Types;
/**
* Expanded Section.
*/
class Expanded extends \WP_Customize_Section {
/**
* The section type.
*
* @access public
* @since 1.0.0
* @var string
*/
public $type = 'kirki-expanded';
}

View file

@ -0,0 +1,79 @@
<?php
/**
* The default section.
* Inspired from https://github.com/justintadlock/trt-customizer-pro
*
* @package kirki-framework/module-sections
* @copyright Copyright (c) 2023, Themeum
* @license https://opensource.org/licenses/MIT
* @since 1.0.0
*/
namespace Kirki\Section_Types;
/**
* Link Section.
*/
class Link extends \WP_Customize_Section {
/**
* The section type.
*
* @access public
* @since 1.0.0
* @var string
*/
public $type = 'kirki-link';
/**
* Button Text
*
* @access public
* @since 1.0.0
* @var string
*/
public $button_text = '';
/**
* Button URL.
*
* @access public
* @since 1.0.0
* @var string
*/
public $button_url = '';
/**
* Gather the parameters passed to client JavaScript via JSON.
*
* @access public
* @since 1.0.0
* @return array The array to be exported to the client as JSON.
*/
public function json() {
$json = parent::json();
$json['button_text'] = $this->button_text;
$json['button_url'] = $this->button_url;
return $json;
}
/**
* Outputs the Underscore.js template.
*
* @access public
* @since 1.0.0
* @return void
*/
protected function render_template() {
?>
<li id="accordion-section-{{ data.id }}" class="accordion-section control-section control-section-{{ data.type }} cannot-expand">
<h3 class="accordion-section-title">
{{ data.title }}
<a href="{{ data.button_url }}" class="button alignright" target="_blank" rel="nofollow">{{ data.button_text }}</a>
</h3>
</li>
<?php
}
}

View file

@ -0,0 +1,69 @@
<?php
/**
* Nested section.
*
* @package kirki-framework/module-sections
* @copyright Copyright (c) 2023, Themeum
* @license https://opensource.org/licenses/MIT
* @since 1.0.0
*/
namespace Kirki\Section_Types;
/**
* Nested section.
*/
class Nested extends \WP_Customize_Section {
/**
* The parent section.
*
* @access public
* @since 1.0.0
* @var string
*/
public $section;
/**
* The section type.
*
* @access public
* @since 1.0.0
* @var string
*/
public $type = 'kirki-nested';
/**
* Gather the parameters passed to client JavaScript via JSON.
*
* @access public
* @since 1.0.0
* @return array The array to be exported to the client as JSON.
*/
public function json() {
$array = wp_array_slice_assoc(
(array) $this,
[
'id',
'description',
'priority',
'panel',
'type',
'description_hidden',
'section',
]
);
$array['title'] = html_entity_decode( $this->title, ENT_QUOTES, get_bloginfo( 'charset' ) );
$array['content'] = $this->get_content();
$array['active'] = $this->active();
$array['instanceNumber'] = $this->instance_number;
$array['customizeAction'] = esc_html__( 'Customizing', 'kirki' );
if ( $this->panel ) {
/* translators: The title. */
$array['customizeAction'] = sprintf( esc_html__( 'Customizing &#9656; %s', 'kirki' ), esc_html( $this->manager->get_panel( $this->panel )->title ) );
}
return $array;
}
}

View file

@ -0,0 +1,26 @@
<?php
/**
* An outer section.
*
* @package kirki-framework/module-sections
* @copyright Copyright (c) 2019, Themeum
* @license https://opensource.org/licenses/MIT
* @since 1.0.0
*/
namespace Kirki\Section_Types;
/**
* Outer Section.
*/
class Outer extends \WP_Customize_Section {
/**
* The section type.
*
* @access public
* @since 1.0.0
* @var string
*/
public $type = 'kirki-outer';
}

View file

@ -0,0 +1,156 @@
jQuery( document ).ready( function() {
wp.customize.section.each( function( section ) {
// Get the pane element.
var pane = jQuery( '#sub-accordion-section-' + section.id ),
sectionLi = jQuery( '#accordion-section-' + section.id );
// Check if the section is expanded.
if ( sectionLi.hasClass( 'control-section-kirki-expanded' ) ) {
// Move element.
pane.appendTo( sectionLi );
}
} );
} );
/**
* See https://github.com/justintadlock/trt-customizer-pro
*/
( function() {
wp.customize.sectionConstructor['kirki-link'] = wp.customize.Section.extend( {
attachEvents: function() {}, // eslint-disable-line no-empty-function
isContextuallyActive: function() {
return true;
}
} );
}() );
/**
* @see https://wordpress.stackexchange.com/a/256103/17078
*/
( function() {
var _sectionEmbed,
_sectionIsContextuallyActive,
_sectionAttachEvents;
wp.customize.bind( 'pane-contents-reflowed', function() {
var sections = [];
// Reflow Sections.
wp.customize.section.each( function( section ) {
if ( 'kirki-nested' !== section.params.type || _.isUndefined( section.params.section ) ) {
return;
}
sections.push( section );
} );
sections.sort( wp.customize.utils.prioritySort ).reverse();
jQuery.each( sections, function( i, section ) {
var parentContainer = jQuery( '#sub-accordion-section-' + section.params.section );
parentContainer.children( '.section-meta' ).after( section.headContainer );
} );
} );
// Extend Section.
_sectionEmbed = wp.customize.Section.prototype.embed;
_sectionIsContextuallyActive = wp.customize.Section.prototype.isContextuallyActive;
_sectionAttachEvents = wp.customize.Section.prototype.attachEvents;
wp.customize.Section = wp.customize.Section.extend( {
attachEvents: function() {
var section = this;
if ( 'kirki-nested' !== this.params.type || _.isUndefined( this.params.section ) ) {
_sectionAttachEvents.call( section );
return;
}
_sectionAttachEvents.call( section );
section.expanded.bind( function( expanded ) {
var parent = wp.customize.section( section.params.section );
if ( expanded ) {
parent.contentContainer.addClass( 'current-section-parent' );
} else {
parent.contentContainer.removeClass( 'current-section-parent' );
}
} );
section.container.find( '.customize-section-back' ).off( 'click keydown' ).on( 'click keydown', function( event ) {
if ( wp.customize.utils.isKeydownButNotEnterEvent( event ) ) {
return;
}
event.preventDefault(); // Keep this AFTER the key filter above
if ( section.expanded() ) {
wp.customize.section( section.params.section ).expand();
}
} );
},
embed: function() {
var section = this,
parentContainer;
if ( 'kirki-nested' !== this.params.type || _.isUndefined( this.params.section ) ) {
_sectionEmbed.call( section );
return;
}
_sectionEmbed.call( section );
parentContainer = jQuery( '#sub-accordion-section-' + this.params.section );
parentContainer.append( section.headContainer );
},
isContextuallyActive: function() {
var section = this,
children,
activeCount = 0;
if ( 'kirki-nested' !== this.params.type ) {
return _sectionIsContextuallyActive.call( this );
}
children = this._children( 'section', 'control' );
wp.customize.section.each( function( child ) {
if ( ! child.params.section ) {
return;
}
if ( child.params.section !== section.id ) {
return;
}
children.push( child );
} );
children.sort( wp.customize.utils.prioritySort );
_( children ).each( function( child ) {
if ( 'undefined' !== typeof child.isContextuallyActive ) {
if ( child.active() && child.isContextuallyActive() ) {
activeCount += 1;
}
} else {
if ( child.active() ) {
activeCount += 1;
}
}
} );
return ( 0 !== activeCount );
}
} );
}( jQuery ) );

View file

@ -0,0 +1,40 @@
#customize-theme-controls .control-section-kirki-expanded .accordion-section-title {
display: none;
}
#customize-theme-controls .control-section-kirki-expanded .customize-section-back {
display: none;
}
#customize-theme-controls .customize-pane-child.control-section-kirki-expanded {
position: relative;
visibility: visible;
height: auto;
margin-left: -100%;
}
#customize-theme-controls .customize-pane-child.control-section-kirki-expanded h3 .customize-action {
display: none;
}
#customize-theme-controls .control-section-kirki-link .accordion-section-title {
padding-right: 10px !important
}
#customize-theme-controls .control-section-kirki-link .button {
margin-top: -3px;
}
#customize-theme-controls .customize-pane-child.current-section-parent,
.in-sub-panel #customize-theme-controls .customize-pane-child.current-panel-parent {
transform: translateX(-100%);
}
.control-section-kirki-nested {
margin: 0 -12px;
}
.control-section-kirki-outer {
display: list-item !important;
}