first commit
This commit is contained in:
@@ -0,0 +1,839 @@
|
||||
<?php
|
||||
/**
|
||||
* Customizer actions and filters
|
||||
* Loaded if hu_is_customizing()
|
||||
*
|
||||
* @package Hueman
|
||||
* @since 3.0+
|
||||
* @author Nicolas GUILLAUME <nicolas@presscustomizr.com>
|
||||
* @copyright Copyright (c) 2016, Nicolas GUILLAUME
|
||||
* @link http://presscustomizr.com/hueman
|
||||
* @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||
*/
|
||||
if ( ! class_exists( 'HU_customize' ) ) :
|
||||
class HU_customize {
|
||||
static $instance;
|
||||
public $control_translations;
|
||||
public $css_attr;
|
||||
|
||||
function __construct () {
|
||||
self::$instance =& $this;
|
||||
|
||||
//v3.1.2 option update : registered sidebar names have changed
|
||||
$this -> hu_update_widget_database_option();
|
||||
|
||||
//load custom customizer classes
|
||||
//=> will be instantiated on "customize_register"
|
||||
$this -> hu_load_customizer_custom_classes();
|
||||
|
||||
//add control class
|
||||
add_action( 'customize_register' , array( $this , 'hu_augment_customizer' ),10,1);
|
||||
|
||||
//add the customizer built with the builder below
|
||||
add_action( 'customize_register' , array( $this , 'hu_customize_register' ), 20, 1 );
|
||||
//add the customizer built with the builder below
|
||||
add_action( 'customize_register' , array( $this , 'hu_schedule_register_sidebar_section' ), 1000, 1 );
|
||||
//modify some WP built-in settings / controls / sections
|
||||
add_action( 'customize_register' , array( $this , 'hu_alter_wp_customizer_settings' ), 1000, 1 );
|
||||
|
||||
//Partial refreshs
|
||||
add_action( 'customize_register' , array( $this, 'hu_register_partials' ) );
|
||||
//Clean some deprecated options (header-image for example, now handled with wp header_image theme mod)
|
||||
add_action( 'customize_save_after' , array( $this, 'hu_clean_deprecated_options' ) );
|
||||
|
||||
//custom logo compatibility option for WP version < WP 4.5
|
||||
//the Hueman theme has switched to the WP custom_logo theme mod since v3.2.4
|
||||
//for older version, the previous control is used
|
||||
if ( ! function_exists( 'the_custom_logo' ) ) {
|
||||
add_filter( 'hu_site_identity_sec', array( $this, 'hu_register_old_custom_logo') );
|
||||
}
|
||||
|
||||
|
||||
//Print modules and inputs templates
|
||||
$this -> hu_load_tmpl();
|
||||
|
||||
//Add the module data server side generated + additional resources (like the WP text editor)
|
||||
// DEPRECATED SINCE JUNE 2018
|
||||
//$this -> hu_load_module_data_resources();
|
||||
|
||||
locate_template( 'functions/czr/czr-resources.php', true, true );
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------- *
|
||||
* DEPRECATED OPTIONS
|
||||
/* ------------------------------------------------------------------------- */
|
||||
//hook : customize_save_after
|
||||
//When the users modifies the header_image, check if the old option exists and remove it if needed
|
||||
function hu_clean_deprecated_options( $manager_inst ) {
|
||||
//can we do things ?
|
||||
if ( ! $manager_inst->is_preview() ) {
|
||||
return;
|
||||
}
|
||||
$action = 'save-customize_' . $manager_inst->get_stylesheet();
|
||||
if ( ! check_ajax_referer( $action, 'nonce', false ) ) {
|
||||
return;
|
||||
}
|
||||
//only attempt to update option when header_image is modified
|
||||
$setting_validities = $manager_inst->validate_setting_values( $manager_inst->unsanitized_post_values() );
|
||||
if ( ! is_array( $setting_validities ) || ! isset($setting_validities['header_image'] ) )
|
||||
return;
|
||||
//clean old option if exists
|
||||
$_options = get_option( HU_THEME_OPTIONS );
|
||||
if ( isset($_options['header-image']) ) {
|
||||
unset( $_options['header-image']);
|
||||
update_option( HU_THEME_OPTIONS, $_options );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//hook : hu_site_identity_sec
|
||||
//Registers the custom logo for WP version < 4.5
|
||||
function hu_register_old_custom_logo( $settings ) {
|
||||
global $wp_version;
|
||||
return array_merge(
|
||||
$settings,
|
||||
array(
|
||||
'custom-logo' => array(
|
||||
'control' => version_compare( $wp_version, '4.3', '>=' ) ? 'HU_Customize_Cropped_Image_Control' : 'HU_Customize_Upload_Control',
|
||||
'label' => __( 'Custom Header Logo' , 'hueman' ),
|
||||
'section' => 'title_tagline' ,
|
||||
'sanitize_callback' => array( HU_utils_settings_map::$instance , 'hu_sanitize_number' ),
|
||||
//we can define suggested cropping area and allow it to be flexible (def 150x150 and not flexible)
|
||||
'width' => 250,
|
||||
'height' => 100,
|
||||
'flex_width' => true,
|
||||
'flex_height' => true,
|
||||
//to keep the selected cropped size
|
||||
'dst_width' => false,
|
||||
'dst_height' => false,
|
||||
'notice' => __('Upload your custom logo image. Supported formats : .jpg, .png, .gif, svg, svgz' , 'hueman'),
|
||||
'priority' => 7
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------- *
|
||||
* LOAD CUSTOM CUSTOMIZER CLASSES FOR CONTROLS / SETTINGS / SECTIONS / PANELS
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/**
|
||||
* hook : 'init'
|
||||
* Augments wp customize controls and settings classes
|
||||
* @package Hueman
|
||||
* @since Hueman 3.0
|
||||
*/
|
||||
function hu_load_customizer_custom_classes() {
|
||||
$_classes = array(
|
||||
'controls/class-base-control.php',
|
||||
'controls/class-cropped-image-control.php',
|
||||
|
||||
'controls/class-layout-control.php',
|
||||
'controls/class-multipicker-control.php',
|
||||
'controls/class-modules-control.php',
|
||||
|
||||
'controls/class-upload-control.php',
|
||||
|
||||
'controls/class-code-editor-control.php',
|
||||
|
||||
'controls/class-color-alpha-control.php',
|
||||
|
||||
'panels/class-panels.php',
|
||||
|
||||
'sections/class-sections.php',
|
||||
'sections/class-pro-section.php',
|
||||
'sections/class-widgets-section.php',
|
||||
|
||||
'settings/class-settings.php'
|
||||
);
|
||||
foreach ($_classes as $_path) {
|
||||
locate_template( 'functions/czr/' . $_path , $load = true, $require_once = true );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------- *
|
||||
* AUGMENT CUSTOMIZER SERVER SIDE
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/**
|
||||
* hook : 'customize_register'
|
||||
* Augments wp customize controls and settings classes
|
||||
* @package Hueman
|
||||
* @since Hueman 3.0
|
||||
*/
|
||||
function hu_augment_customizer( $manager ) {
|
||||
//Registered types are eligible to be rendered via JS and created dynamically.
|
||||
if ( class_exists('HU_Customize_Cropped_Image_Control') )
|
||||
$manager -> register_control_type( 'HU_Customize_Cropped_Image_Control' );
|
||||
if ( class_exists('HU_Customize_Panels') )
|
||||
$manager -> register_panel_type( 'HU_Customize_Panels');
|
||||
if ( class_exists('HU_Customize_Sections') )
|
||||
$manager -> register_panel_type( 'HU_Customize_Sections');
|
||||
if ( hu_is_pro_section_on() ) {
|
||||
$manager -> register_section_type( 'HU_Customize_Section_Pro');
|
||||
}
|
||||
if ( class_exists('HU_Customize_Code_Editor_Control') )
|
||||
$manager -> register_control_type( 'HU_Customize_Code_Editor_Control' );
|
||||
if ( class_exists('HU_Customize_Color_Alpha_Control') )
|
||||
$manager -> register_control_type( 'HU_Customize_Color_Alpha_Control' );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------- *
|
||||
* PARTIALS
|
||||
/* ------------------------------------------------------------------------- */
|
||||
//hook : customize_register
|
||||
function hu_register_partials( WP_Customize_Manager $wp_customize ) {
|
||||
//Bail if selective refresh is not available (old versions) or disabled (for skope for example)
|
||||
if ( ! isset( $wp_customize->selective_refresh ) || ! hu_is_partial_refreshed_on() ) {
|
||||
return;
|
||||
}
|
||||
$wp_customize->selective_refresh->add_partial( 'social_links', array(
|
||||
'selector' => '.social-links',
|
||||
'settings' => array( 'hu_theme_options[social-links]' ),
|
||||
'render_callback' => 'hu_print_social_links',
|
||||
) );
|
||||
|
||||
$wp_customize->selective_refresh->add_partial( 'header_image', array(
|
||||
'selector' => '#header-image-wrap',
|
||||
'settings' => array( 'header_image' ),
|
||||
'render_callback' => 'hu_render_header_image',
|
||||
) );
|
||||
//if ( ! function_exists( 'HU_AD') || ! HU_AD() -> ha_is_skop_on() ) {
|
||||
$wp_customize->selective_refresh->add_partial( 'site_title', array(
|
||||
'selector' => '.site-title',
|
||||
'settings' => array( 'blogname' ),
|
||||
'render_callback' => 'hu_do_render_logo_site_tite',
|
||||
) );
|
||||
//}
|
||||
$wp_customize->selective_refresh->add_partial( 'site_description', array(
|
||||
'selector' => '.site-description',
|
||||
'settings' => array( 'blogdescription' ),
|
||||
'render_callback' => 'hu_render_blog_description',
|
||||
) );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------- *
|
||||
* LOAD MODULES AND INPUTS TEMPLATES
|
||||
/* ------------------------------------------------------------------------- */
|
||||
function hu_load_tmpl() {
|
||||
$_tmpl = array(
|
||||
//'tmpl/modules/all-modules-tmpl.php',
|
||||
'tmpl/modules/slide-module-tmpl.php',
|
||||
|
||||
//'tmpl/inputs/img-uploader-tmpl.php',
|
||||
|
||||
'tmpl/modules/text_editor-module-tmpl.php',
|
||||
//'tmpl/inputs/text_editor-input-tmpl.php'
|
||||
);
|
||||
foreach ($_tmpl as $_path) {
|
||||
locate_template( 'functions/czr/' . $_path , $load = true, $require_once = true );
|
||||
}
|
||||
}
|
||||
|
||||
// DEPRECATED SINCE JUNE 2018
|
||||
// function hu_load_module_data_resources() {
|
||||
// locate_template( 'functions/czr/modules/modules-data.php' , $load = true, $require_once = true );
|
||||
// //locate_template( 'functions/czr/modules/modules-resources.php' , $load = true, $require_once = true );
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------- *
|
||||
* MODIFY SETTINGS, CONTROLS, SECTIONS, PANELS SERVER SIDE
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/*
|
||||
* Since the WP_Customize_Manager::$controls and $settings are protected properties, one way to alter them is to use the get_setting and get_control methods
|
||||
* Another way is to remove the control and add it back as an instance of a custom class and with new properties
|
||||
* and set new property values
|
||||
* hook : hu_customize_register:30
|
||||
* @return void()
|
||||
*/
|
||||
function hu_alter_wp_customizer_settings( $wp_customize ) {
|
||||
//SOME SETTINGS TRANSPORT
|
||||
if ( is_object( $wp_customize -> get_setting( 'blogname' ) ) ) {
|
||||
$wp_customize -> get_setting( 'blogname' )->transport = 'postMessage';
|
||||
}
|
||||
if ( is_object( $wp_customize -> get_setting( 'blogdescription' ) ) ) {
|
||||
$wp_customize -> get_setting( 'blogdescription' )->transport = 'postMessage';
|
||||
}
|
||||
|
||||
//ONLY IF SELECTIVE REFRESH IS SUPPORTED
|
||||
if ( isset( $wp_customize->selective_refresh ) && is_object( $wp_customize -> get_setting( 'header_image' ) ) ) {
|
||||
$wp_customize -> get_setting( 'header_image' )->transport = 'postMessage';
|
||||
}
|
||||
if ( isset( $wp_customize->selective_refresh ) && is_object( $wp_customize -> get_setting( 'header_image_data' ) ) ) {
|
||||
$wp_customize -> get_setting( 'header_image_data' )->transport = 'postMessage';
|
||||
}
|
||||
|
||||
//MOVE WP FRONT PAGE SECTION TO ROOT PANEL
|
||||
if ( is_object( $wp_customize -> get_section( 'static_front_page' ) ) ) {
|
||||
$wp_customize -> get_section( 'static_front_page' ) -> panel = '';//'hu-content-panel';
|
||||
$wp_customize -> get_section( 'static_front_page' ) -> title = __( 'Front Page Content', 'hueman' );
|
||||
$wp_customize -> get_section( 'static_front_page' ) -> priority = 10;
|
||||
//$wp_customize -> get_section( 'static_front_page' ) -> active_callback = 'hu_is_home';
|
||||
}
|
||||
|
||||
//CHANGE THE STATIC FRONT PAGE WP CONTROLS
|
||||
if ( is_object( $wp_customize -> get_control( 'show_on_front' ) ) ) {
|
||||
$wp_customize -> get_control( 'show_on_front' ) -> type = 'select';
|
||||
$wp_customize -> get_control( 'show_on_front' ) -> choices = array(
|
||||
'__nothing__' => __( 'Don\'t show any posts or page' , 'hueman'),
|
||||
'posts' => __( 'Your latest posts' , 'hueman'),
|
||||
'page' => __( 'A static page' , 'hueman' )
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
//IF WP VERSION >= 4.3 AND SITE_ICON SETTING EXISTS
|
||||
//=> REMOVE OLD FAV ICON CONTROL
|
||||
//=> CHANGE SITE ICON DEFAULT WP SECTION TO LOGO SECTION
|
||||
global $wp_version;
|
||||
if ( version_compare( $wp_version, '4.3', '>=' ) && is_object( $wp_customize -> get_control( 'site_icon' ) ) ) {
|
||||
$hu_option_group = HU_THEME_OPTIONS;
|
||||
$wp_customize -> remove_control( "{$hu_option_group}[favicon]" );
|
||||
//note : the setting is kept because used in the customizer js api to handle the transition between Hueman favicon to WP site icon.
|
||||
$wp_customize -> get_control( 'site_icon' ) -> section = 'title_tagline';
|
||||
|
||||
//add a favicon title after the logo upload
|
||||
//@todo : update the callback
|
||||
//add_action( '__after_setting_control' , array( $this , 'hu_add_favicon_title') );
|
||||
}//end ALTER SITE ICON
|
||||
|
||||
|
||||
//CHANGE MENUS PROPERTIES
|
||||
// $locations = get_registered_nav_menus();
|
||||
// $menus = wp_get_nav_menus();
|
||||
// $choices = array( '' => __( '— Select —', 'hueman' ) );
|
||||
// foreach ( $menus as $menu ) {
|
||||
// $choices[ $menu->term_id ] = wp_html_excerpt( $menu->name, 40, '…' );
|
||||
// }
|
||||
// $_priorities = array(
|
||||
// 'topbar' => 10,
|
||||
// 'header' => 20,
|
||||
// 'footer' => 30
|
||||
// );
|
||||
|
||||
// //WP only adds the menu(s) settings and controls if the user has created at least one menu.
|
||||
// //1) if no menus yet, we still want to display the menu picker + add a notice with a link to the admin menu creation panel
|
||||
// //=> add_setting and add_control for each menu location. Check if they are set first by security
|
||||
// //2) if user has already created a menu, the settings are already created, we just need to update the controls.
|
||||
// $_priority = 0;
|
||||
// //assign new priorities to the menus controls
|
||||
// foreach ( $locations as $location => $description ) {
|
||||
// $menu_setting_id = "nav_menu_locations[{$location}]";
|
||||
|
||||
// //create the settings if they don't exist
|
||||
// //=> in the condition, make sure that the setting has really not been created yet (maybe over secured)
|
||||
// if ( ! $menus && ! is_object( $wp_customize->get_setting($menu_setting_id ) ) ) {
|
||||
// $wp_customize -> add_setting( $menu_setting_id, array(
|
||||
// 'sanitize_callback' => 'absint',
|
||||
// 'theme_supports' => 'menus',
|
||||
// ) );
|
||||
// }
|
||||
|
||||
// //remove the controls if they exists
|
||||
// if ( is_object( $wp_customize->get_control( $menu_setting_id ) ) ) {
|
||||
// $wp_customize -> remove_control( $menu_setting_id );
|
||||
// }
|
||||
|
||||
// //replace the controls by our custom controls
|
||||
// $_control_properties = array(
|
||||
// 'label' => $description,
|
||||
// 'section' => 'menu_locations',
|
||||
// 'title' => "main" == $location ? __( 'Assign menus to locations' , 'hueman') : false,
|
||||
// 'type' => 'select',
|
||||
// 'choices' => $choices,
|
||||
// 'priority' => isset($_priorities[$location]) ? $_priorities[$location] : $_priority
|
||||
// );
|
||||
|
||||
// //add a notice property if no menu created yet.
|
||||
// if ( ! $menus ) {
|
||||
// //adapt the nav section description for v4.3 (menu in the customizer from now on)
|
||||
// $_create_menu_link = version_compare( $GLOBALS['wp_version'], '4.3', '<' ) ? admin_url('nav-menus.php') : "javascript:wp.customize.section('nav').container.find('.customize-section-back').trigger('click'); wp.customize.panel('nav_menus').focus();";
|
||||
// $_control_properties['notice'] = sprintf( __("You haven't created any menu yet. %s or check the %s to learn more about menus.", "hueman"),
|
||||
// sprintf( '<strong><a href="%1$s" title="%2$s">%2$s</a></strong>', $_create_menu_link, __("Create a new menu now" , "hueman") ),
|
||||
// sprintf( '<a href="%1$s" title="%2$s" target="_blank">%2$s</a>', esc_url('codex.wordpress.org/WordPress_Menu_User_Guide'), __("WordPress documentation" , "hueman") )
|
||||
// );
|
||||
// }
|
||||
|
||||
// $wp_customize -> add_control( new HU_controls( $wp_customize, $menu_setting_id, $_control_properties ) );
|
||||
|
||||
// $_priority = $_priority + 10;
|
||||
// }//foreach
|
||||
|
||||
|
||||
//MOVE THE HEADER IMAGE CONTROL INTO THE HEADER DESIGN SECTION
|
||||
if ( is_object( $wp_customize -> get_control( 'header_image' ) ) ) {
|
||||
$wp_customize -> get_control( 'header_image' ) -> section = 'header_image_sec';
|
||||
$wp_customize -> get_control( 'header_image' ) -> priority = 100;
|
||||
}
|
||||
|
||||
//CHANGE THE CUSTOM LOGO PRIORITY
|
||||
//check if custom_logo is registered first for backward compatibility => custom_logo was introduced in WP 4.5.
|
||||
if ( is_object( $wp_customize->get_control( 'custom_logo' ) ) ) {
|
||||
$wp_customize -> get_control( 'custom_logo' ) -> priority = 7;
|
||||
}
|
||||
|
||||
//The selective refresh support will be added later to the custom logo
|
||||
if ( isset( $wp_customize->selective_refresh ) && is_object($wp_customize->get_setting( 'custom_logo' ) ) ) {
|
||||
$wp_customize -> selective_refresh -> remove_partial( 'custom_logo' );
|
||||
$wp_customize -> get_setting( 'custom_logo' ) -> transport = 'refresh';
|
||||
}
|
||||
|
||||
//MOVE THE CUSTOM CSS SECTION (introduced in 4.7) INTO THE GLOBAL SETTINGS PANEL
|
||||
if ( is_object( $wp_customize->get_section( 'custom_css' ) ) ) {
|
||||
$wp_customize -> get_section( 'custom_css' ) -> panel = 'hu-advanced-panel';
|
||||
$wp_customize -> get_section( 'custom_css' ) -> priority = 40;
|
||||
}
|
||||
|
||||
}//end of hu_alter_wp_customizer_settings()
|
||||
|
||||
|
||||
/*
|
||||
* hook : '__after_setting_control' (declared in class-controls-settings.php)
|
||||
* Display a title for the favicon control, after the logo
|
||||
*/
|
||||
function hu_add_favicon_title($set_id) {
|
||||
printf( '<h3 class="czr-hueman-title">%s</h3>', __( 'SITE ICON' , 'hueman') );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------- *
|
||||
* WIDGETS SPECIFICS
|
||||
/* ------------------------------------------------------------------------- */
|
||||
//updates the names of the built-in widget zones for users who installed the theme before v3.1.2
|
||||
function hu_update_widget_database_option() {
|
||||
if ( ! hu_user_started_before_version('3.1.2') )
|
||||
return;
|
||||
|
||||
$_options = get_option('hu_theme_options');
|
||||
$_update_widget_areas = array();
|
||||
|
||||
if ( ! isset($_options['sidebar-areas']) || ! is_array($_options['sidebar-areas']) )
|
||||
return;
|
||||
|
||||
$_zones = hu_get_default_widget_zones();
|
||||
foreach ( $_options['sidebar-areas'] as $key => $data ) {
|
||||
if ( ! array_key_exists($data['id'], $_zones) )
|
||||
continue;
|
||||
$_id = $data['id'];
|
||||
$_options['sidebar-areas'][$key]['title'] = $_zones[$_id]['name'];
|
||||
}
|
||||
|
||||
update_option('hu_theme_options', $_options );
|
||||
}
|
||||
|
||||
/**
|
||||
* Why this ?
|
||||
* Unlike the other panels, which are all added on customize_register, the Widgets panel is added on 2 different hooks
|
||||
* 1) customize_register for the left panel
|
||||
* 2) 'wp' for the preview frame.
|
||||
* @see WP_Customize_Widgets::schedule_customize_register()
|
||||
*
|
||||
* Therefore to add a section and a control to the Widgets panel, we have to follow the same logic
|
||||
* if not, the added section will always be deactivated.
|
||||
*
|
||||
* Note that the related setting added in this section must always be registered early in customize_register
|
||||
*/
|
||||
function hu_schedule_register_sidebar_section( $wp_customize ) {
|
||||
$this -> hu_customize_factory (
|
||||
$wp_customize,
|
||||
$this -> hu_customize_arguments(),
|
||||
array(
|
||||
'add_setting' => array(
|
||||
'sidebar-areas' => array(
|
||||
'registered_dynamically' => true,
|
||||
'default' => array(),//empty array by default
|
||||
'control' => 'HU_Customize_Modules',
|
||||
'label' => __('Create And Order Widget Areas', 'hueman'),
|
||||
'section' => HU_DYN_WIDGETS_SECTION,
|
||||
'type' => 'czr_module',
|
||||
'module_type' => 'czr_widget_areas_module',
|
||||
'notice' => __('You must save changes for the new areas to appear below. <br /><i>Warning: Make sure each area has a unique ID.</i>' , 'hueman'),
|
||||
'transport' => 'postMessage',
|
||||
'skoped' => false,
|
||||
|
||||
)
|
||||
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
//$this->hu_customize_register( $wp_customize );
|
||||
if ( is_admin() ) {
|
||||
$this -> hu_register_sidebar_section( $wp_customize );
|
||||
} else {
|
||||
add_action( 'wp', array( $this, 'hu_register_sidebar_section' ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function hu_register_sidebar_section( $wp_customize ) {
|
||||
$_widget_section_name = HU_DYN_WIDGETS_SECTION;
|
||||
$_map = array(
|
||||
'add_control' => array(
|
||||
'sidebar-areas' => array(
|
||||
'registered_dynamically' => true,
|
||||
'default' => array(),//empty array by default
|
||||
'control' => 'HU_Customize_Modules',
|
||||
'label' => __('Create And Manage Widget Areas', 'hueman'),
|
||||
'section' => $_widget_section_name,
|
||||
'type' => 'czr_module',
|
||||
'module_type' => 'czr_widget_areas_module',
|
||||
'notice' => __('You must save changes for the new areas to appear below. <br /><i>Warning: Make sure each area has a unique ID.</i>' , 'hueman'),
|
||||
'transport' => 'postMessage'
|
||||
)
|
||||
|
||||
),//'add_control'
|
||||
'add_section' => array(
|
||||
"{$_widget_section_name}" => array(
|
||||
'title' => __( 'Create and manage widget zones', 'hueman' ),
|
||||
'priority' => 1000,
|
||||
'panel' => 'widgets',
|
||||
'section_class' => 'HU_Customize_Manage_Widgets_Section',
|
||||
'type' => 'widget_zones_management'
|
||||
)
|
||||
|
||||
)//add_section
|
||||
);//map
|
||||
|
||||
|
||||
//wp_customize is not defined when hooked on wp
|
||||
if ( 'wp' == current_filter() )
|
||||
global $wp_customize;
|
||||
|
||||
$this -> hu_customize_factory (
|
||||
$wp_customize,
|
||||
$this -> hu_customize_arguments(),
|
||||
$_map
|
||||
);
|
||||
|
||||
$wp_customize -> get_panel('widgets') -> title = __('Dynamic Sidebars and Widgets', 'hueman');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------- *
|
||||
* FACTORY
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Generates customizer sections, settings and controls
|
||||
* @package Hueman
|
||||
* @since Hueman 3.0
|
||||
*/
|
||||
function hu_customize_register( $wp_customize) {
|
||||
return $this -> hu_customize_factory(
|
||||
$wp_customize,
|
||||
$this -> hu_customize_arguments(),
|
||||
HU_utils_settings_map::$instance -> hu_get_customizer_map()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Defines authorized arguments for panels, sections, settings and controls
|
||||
* @package Hueman
|
||||
* @since Hueman 3.0
|
||||
*/
|
||||
function hu_customize_arguments() {
|
||||
$args = array(
|
||||
'panels' => array(
|
||||
'title',
|
||||
'czr_subtitle',
|
||||
'description',
|
||||
'priority' ,
|
||||
'theme_supports',
|
||||
'capability',
|
||||
'type'
|
||||
),
|
||||
'sections' => array(
|
||||
'title' ,
|
||||
'priority' ,
|
||||
'description',
|
||||
'panel',
|
||||
'theme_supports',
|
||||
'type',
|
||||
'active_callback',
|
||||
'pro_text',
|
||||
'pro_url',
|
||||
|
||||
'ubq_panel'
|
||||
),
|
||||
'settings' => array(
|
||||
'default' => null,
|
||||
'capability' => 'manage_options' ,
|
||||
'setting_type' => 'option' ,
|
||||
'sanitize_callback' => null,
|
||||
'sanitize_js_callback' => null,
|
||||
'transport' => null
|
||||
),
|
||||
'controls' => array(
|
||||
'title' ,
|
||||
'label' ,
|
||||
'description',
|
||||
'section' ,
|
||||
'settings',
|
||||
'type' ,
|
||||
|
||||
'module_type',
|
||||
'syncCollection',
|
||||
|
||||
'choices' ,
|
||||
'priority' ,
|
||||
'sanitize_callback',
|
||||
'sanitize_js_callback',
|
||||
'notice' ,
|
||||
'buttontext' ,//button specific
|
||||
'link' ,//button specific
|
||||
'step' ,//number specific
|
||||
'min' ,//number specific
|
||||
'range-input' ,
|
||||
'max',
|
||||
'cssid',
|
||||
'slider_default',
|
||||
'active_callback',
|
||||
'content_after',
|
||||
'content_before',
|
||||
'icon',
|
||||
'width',
|
||||
'height',
|
||||
'flex_width',
|
||||
'flex_height',
|
||||
'dst_width',
|
||||
'dst_height',
|
||||
|
||||
'ubq_section',
|
||||
|
||||
//for the code editor
|
||||
'code_type',
|
||||
'input_attrs'
|
||||
)
|
||||
);
|
||||
return apply_filters( 'hu_customizer_arguments', $args );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Generates customizer
|
||||
* @package Hueman
|
||||
* @since Hueman 3.0
|
||||
*/
|
||||
function hu_customize_factory ( $wp_customize , $args, $setup ) {
|
||||
global $wp_version;
|
||||
//add panels if current WP version >= 4.0
|
||||
if ( isset( $setup['add_panel']) && version_compare( $wp_version, '4.0', '>=' ) ) {
|
||||
foreach ( $setup['add_panel'] as $p_key => $p_options ) {
|
||||
//declares the clean section option array
|
||||
$panel_options = array();
|
||||
//checks authorized panel args
|
||||
foreach( $args['panels'] as $p_set) {
|
||||
$panel_options[$p_set] = isset( $p_options[$p_set]) ? $p_options[$p_set] : null;
|
||||
}
|
||||
$wp_customize -> add_panel( new HU_Customize_Panels( $wp_customize, $p_key, $panel_options ) );
|
||||
}
|
||||
}
|
||||
|
||||
//remove sections
|
||||
if ( isset( $setup['remove_section'])) {
|
||||
foreach ( $setup['remove_section'] as $section) {
|
||||
$wp_customize -> remove_section( $section);
|
||||
}
|
||||
}
|
||||
|
||||
//add sections
|
||||
if ( isset( $setup['add_section'])) {
|
||||
foreach ( $setup['add_section'] as $key => $options) {
|
||||
//generate section array
|
||||
$option_section = array();
|
||||
|
||||
foreach( $args['sections'] as $sec) {
|
||||
$option_section[$sec] = isset( $options[$sec]) ? $options[$sec] : null;
|
||||
}
|
||||
|
||||
//instanciate a custom class if defined
|
||||
if( ! isset( $options['section_class']) )
|
||||
$wp_customize -> add_section( $key,$option_section);
|
||||
else if ( isset( $options['section_class']) && class_exists( $options['section_class'] ) )
|
||||
$wp_customize -> add_section( new $options['section_class']( $wp_customize, $key, $option_section ));
|
||||
}//end foreach
|
||||
}//end if
|
||||
|
||||
|
||||
//add setting alone
|
||||
if ( isset( $setup['add_setting'])) {
|
||||
|
||||
foreach ( $setup['add_setting'] as $key => $options) {
|
||||
//isolates the option name for the setting's filter
|
||||
$f_option = preg_match_all( '/\[(.*?)\]/' , $key , $match );
|
||||
$f_option_name = isset( $match[1][0] ) ? $match[1][0] : 'setting';
|
||||
|
||||
$hu_option_group = HU_THEME_OPTIONS;
|
||||
|
||||
$_opt_name = "{$hu_option_group}[{$key}]";
|
||||
|
||||
//declares settings array
|
||||
$option_settings = array();
|
||||
foreach( $args['settings'] as $set => $set_value) {
|
||||
if ( $set == 'setting_type' ) {
|
||||
$option_settings['type'] = isset( $options['setting_type']) ? $options['setting_type'] : $args['settings'][$set];
|
||||
$option_settings['type'] = apply_filters( "{$f_option_name}_customizer_set", $option_settings['type'] , $set );
|
||||
}
|
||||
else {
|
||||
$option_settings[$set] = isset( $options[$set]) ? $options[$set] : $args['settings'][$set];
|
||||
$option_settings[$set] = apply_filters( "{$f_option_name}_customizer_set" , $option_settings[$set] , $set );
|
||||
}
|
||||
}
|
||||
|
||||
//add setting
|
||||
if ( class_exists('HU_Customize_Setting') )
|
||||
$wp_customize -> add_setting( new HU_Customize_Setting ( $wp_customize, $_opt_name, $option_settings ) );
|
||||
else
|
||||
$wp_customize -> add_setting( $_opt_name, $option_settings );
|
||||
}//end for each
|
||||
}//end if isset
|
||||
|
||||
|
||||
//add control alone
|
||||
if ( isset( $setup['add_control'])) {
|
||||
|
||||
foreach ( $setup['add_control'] as $key => $options) {
|
||||
//isolates the option name for the setting's filter
|
||||
$f_option = preg_match_all( '/\[(.*?)\]/' , $key , $match );
|
||||
$f_option_name = isset( $match[1][0] ) ? $match[1][0] : 'setting';
|
||||
|
||||
$hu_option_group = HU_THEME_OPTIONS;
|
||||
|
||||
$_opt_name = "{$hu_option_group}[{$key}]";
|
||||
|
||||
//generate controls array
|
||||
$option_controls = array();
|
||||
foreach( $args['controls'] as $con) {
|
||||
$option_controls[$con] = isset( $options[$con]) ? $options[$con] : null;
|
||||
}
|
||||
|
||||
//add control with a class instanciation if not default
|
||||
if( ! isset( $options['control']) )
|
||||
$wp_customize -> add_control( $_opt_name, $option_controls );
|
||||
else
|
||||
$wp_customize -> add_control( new $options['control']( $wp_customize, $_opt_name, $option_controls ));
|
||||
|
||||
}//end for each
|
||||
}//end if isset
|
||||
|
||||
|
||||
|
||||
//add settings and controls
|
||||
if ( isset( $setup['add_setting_control'])) {
|
||||
|
||||
foreach ( $setup['add_setting_control'] as $key => $options) {
|
||||
//isolates the option name for the setting's filter
|
||||
$f_option = preg_match_all( '/\[(.*?)\]/' , $key , $match );
|
||||
$f_option_name = isset( $match[1][0] ) ? $match[1][0] : 'setting';
|
||||
|
||||
$hu_option_group = HU_THEME_OPTIONS;
|
||||
|
||||
$_opt_name = "{$hu_option_group}[{$key}]";
|
||||
|
||||
//declares settings array
|
||||
$option_settings = array();
|
||||
|
||||
// bail here if the setting is registered dynamically
|
||||
// since June 2018
|
||||
if ( array_key_exists( 'registered_dynamically', $options ) && true === $options[ 'registered_dynamically' ] )
|
||||
continue;
|
||||
|
||||
foreach( $args['settings'] as $set => $set_value) {
|
||||
if ( $set == 'setting_type' ) {
|
||||
$option_settings['type'] = isset( $options['setting_type']) ? $options['setting_type'] : $args['settings'][$set];
|
||||
$option_settings['type'] = apply_filters( "{$f_option_name}_customizer_set", $option_settings['type'] , $set );
|
||||
}
|
||||
else {
|
||||
$option_settings[$set] = isset( $options[$set]) ? $options[$set] : $args['settings'][$set];
|
||||
$option_settings[$set] = apply_filters( "{$f_option_name}_customizer_set" , $option_settings[$set] , $set );
|
||||
}
|
||||
}
|
||||
|
||||
//add setting
|
||||
if ( class_exists('HU_Customize_Setting') )
|
||||
$wp_customize -> add_setting( new HU_Customize_Setting ( $wp_customize, $_opt_name, $option_settings ) );
|
||||
else
|
||||
$wp_customize -> add_setting( $_opt_name, $option_settings );
|
||||
|
||||
//generate controls array
|
||||
$option_controls = array();
|
||||
foreach( $args['controls'] as $con) {
|
||||
$option_controls[$con] = isset( $options[$con]) ? $options[$con] : null;
|
||||
}
|
||||
|
||||
//add control with a class instanciation if not default
|
||||
if( ! isset( $options['control']) )
|
||||
$wp_customize -> add_control( $_opt_name, $option_controls );
|
||||
else
|
||||
$wp_customize -> add_control( new $options['control']( $wp_customize, $_opt_name, $option_controls ));
|
||||
|
||||
}//end for each
|
||||
}//end if isset
|
||||
}//end of customize generator function
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------- *
|
||||
* HELPERS
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
|
||||
|
||||
//@return array of WP builtin settings
|
||||
function hu_get_wp_builtin_settings() {
|
||||
return array(
|
||||
'blogname',
|
||||
'blogdescription',
|
||||
'site_icon',
|
||||
'custom_logo',
|
||||
'background_color',
|
||||
'show_on_front',
|
||||
'page_on_front',
|
||||
'page_for_posts',
|
||||
'header_image',
|
||||
'header_image_data'
|
||||
);
|
||||
}
|
||||
}//end of class
|
||||
endif;
|
||||
@@ -0,0 +1,248 @@
|
||||
<?php
|
||||
/**
|
||||
* Add controls to customizer
|
||||
*
|
||||
*/
|
||||
if ( ! class_exists( 'HU_controls' ) ) :
|
||||
class HU_controls extends WP_Customize_Control {
|
||||
public $type;
|
||||
public $link;
|
||||
public $title;
|
||||
public $label;
|
||||
public $buttontext;
|
||||
public $settings;
|
||||
public $hr_after;
|
||||
public $notice;
|
||||
//number vars
|
||||
public $step;
|
||||
public $min;
|
||||
public $icon;
|
||||
|
||||
public $ubq_section;
|
||||
|
||||
static $enqueued_resources;
|
||||
|
||||
public function render_content() {
|
||||
do_action( '__before_setting_control' , $this -> id );
|
||||
|
||||
switch ( $this -> type) {
|
||||
case 'hr':
|
||||
echo '<hr class="czr-customizer-separator" />';
|
||||
break;
|
||||
|
||||
|
||||
case 'title' :
|
||||
?>
|
||||
<?php if (isset( $this->title)) : ?>
|
||||
<h3 class="czr-customizr-title"><?php echo esc_html( $this->title); ?></h3>
|
||||
<?php endif; ?>
|
||||
<?php if (isset( $this->notice)) : ?>
|
||||
<i class="czr-notice"><?php echo $this -> notice ?></i>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php
|
||||
break;
|
||||
|
||||
case 'select':
|
||||
if ( empty( $this->choices ) )
|
||||
return;
|
||||
?>
|
||||
<?php if (!empty( $this->title)) : ?>
|
||||
<h3 class="czr-customizr-title"><?php echo esc_html( $this->title); ?></h3>
|
||||
<?php endif; ?>
|
||||
<label>
|
||||
<span class="customize-control-title"><?php echo $this->label; ?></span>
|
||||
<?php $this -> hu_print_select_control( '' ) ?>
|
||||
<?php if(!empty( $this -> notice)) : ?>
|
||||
<span class="czr-notice"><?php echo $this -> notice ?></span>
|
||||
<?php endif; ?>
|
||||
</label>
|
||||
<?php
|
||||
|
||||
break;
|
||||
|
||||
|
||||
case 'number':
|
||||
?>
|
||||
<?php if (isset( $this->title)) : ?>
|
||||
<h3 class="czr-customizr-title"><?php echo esc_html( $this->title); ?></h3>
|
||||
<?php endif; ?>
|
||||
<label>
|
||||
<span class="czr-number-label customize-control-title"><?php echo $this->label ?></span>
|
||||
<input <?php $this->link() ?> type="number" step="<?php echo $this-> step ?>" min="<?php echo $this-> min ?>" id="posts_per_page" value="<?php echo $this->value() ?>" class="czr-number-input small-text">
|
||||
<?php if(!empty( $this -> notice)) : ?>
|
||||
<span class="czr-notice"><?php echo $this-> notice ?></span>
|
||||
<?php endif; ?>
|
||||
</label>
|
||||
<?php
|
||||
break;
|
||||
|
||||
case 'checkbox':
|
||||
case 'nimblecheck':
|
||||
?>
|
||||
<?php if (isset( $this->title)) : ?>
|
||||
<h3 class="czr-customizr-title"><?php echo esc_html( $this->title); ?></h3>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ( 'checkbox' === $this->type ) : ?>
|
||||
<?php
|
||||
printf('<div class="czr-check-label"><label><span class="customize-control-title">%1$s</span></label></div>',
|
||||
$this->label
|
||||
);
|
||||
?>
|
||||
<input <?php $this->link(); ?> type="checkbox" value="<?php echo esc_attr( $this->value() ); ?>" <?php checked( $this->value() ); ?> />
|
||||
<?php elseif ( 'nimblecheck' === $this->type ) : ?>
|
||||
<div class="czr-control-nimblecheck">
|
||||
<?php
|
||||
printf('<div class="czr-check-label"><label><span class="customize-control-title">%1$s</span></label></div>',
|
||||
$this->label
|
||||
);
|
||||
?>
|
||||
<div class="nimblecheck-wrap">
|
||||
<input id="nimblecheck-<?php echo $this -> id; ?>" <?php $this->link(); ?> type="checkbox" value="<?php echo esc_attr( $this->value() ); ?>" <?php checked( $this->value() ); ?> class="nimblecheck-input">
|
||||
<label for="nimblecheck-<?php echo $this -> id; ?>" class="nimblecheck-label">Switch</label>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if(!empty( $this -> notice)) : ?>
|
||||
<span class="czr-notice"><?php echo $this-> notice ?></span>
|
||||
<?php endif; ?>
|
||||
<?php
|
||||
break;
|
||||
|
||||
case 'textarea':
|
||||
?>
|
||||
<?php if (isset( $this->title)) : ?>
|
||||
<h3 class="czr-customizr-title"><?php echo esc_html( $this->title); ?></h3>
|
||||
<?php endif; ?>
|
||||
<label>
|
||||
<span class="customize-control-title"><?php echo $this->label; ?></span>
|
||||
<?php if(!empty( $this -> notice)) : ?>
|
||||
<span class="czr-notice"><?php echo $this-> notice; ?></span>
|
||||
<?php endif; ?>
|
||||
<textarea class="widefat" rows="3" cols="10" <?php $this->link(); ?>><?php echo esc_html( $this->value() ); ?></textarea>
|
||||
</label>
|
||||
<?php
|
||||
break;
|
||||
|
||||
case 'url':
|
||||
case 'email':
|
||||
?>
|
||||
<?php if (isset( $this->title)) : ?>
|
||||
<h3 class="czr-customizr-title"><?php echo esc_html( $this->title); ?></h3>
|
||||
<?php endif; ?>
|
||||
<?php
|
||||
printf('<label><span class="customize-control-title %1$s">%2$s</span><input type="text" value="%3$s" %4$s /></label>',
|
||||
! empty( $this -> icon) ? $this -> icon : '',
|
||||
$this->label,
|
||||
call_user_func( array( HU_utils_settings_map::$instance, 'hu_sanitize_' . $this -> type), $this->value() ),
|
||||
call_user_func( array( $this, 'get'.'_'.'link' ) )
|
||||
);
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
global $wp_version;
|
||||
?>
|
||||
<?php if (isset( $this->title)) : ?>
|
||||
<h3 class="czr-customizr-title"><?php echo esc_html( $this->title); ?></h3>
|
||||
<?php endif; ?>
|
||||
<label>
|
||||
<?php if ( ! empty( $this->label ) ) : ?>
|
||||
<span class="customize-control-title"><?php echo $this->label; ?></span>
|
||||
<?php endif; ?>
|
||||
<?php if ( ! empty( $this->description ) ) : ?>
|
||||
<span class="description customize-control-description"><?php echo $this->description; ?></span>;;;
|
||||
<?php endif; ?>
|
||||
<?php if ( ! version_compare( $wp_version, '4.0', '>=' ) ) : ?>
|
||||
<input type="<?php echo esc_attr( $this->type ); ?>" value="<?php echo esc_attr( $this->value() ); ?>" <?php $this->link(); ?> />
|
||||
<?php else : ?>
|
||||
<input type="<?php echo esc_attr( $this->type ); ?>" <?php $this->input_attrs(); ?> value="<?php echo esc_attr( $this->value() ); ?>" <?php $this->link(); ?> />
|
||||
<?php endif; ?>
|
||||
<?php if(!empty( $this -> notice)) : ?>
|
||||
<span class="czr-notice"><?php echo $this-> notice; ?></span>
|
||||
<?php endif; ?>
|
||||
</label>
|
||||
<?php
|
||||
break;
|
||||
}//end switch
|
||||
do_action( '__after_setting_control' , $this -> id );
|
||||
}//end function
|
||||
|
||||
|
||||
|
||||
|
||||
private function hu_print_select_control($class) {
|
||||
printf('<select %1$s class="%2$s">%3$s</select>',
|
||||
call_user_func( array( $this, 'get'.'_'.'link' ) ),
|
||||
$class,
|
||||
$this -> hu_get_select_options()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
private function hu_get_select_options() {
|
||||
$_options_html = '';
|
||||
switch ( $this -> id ) {
|
||||
default:
|
||||
foreach ( $this->choices as $value => $label ) {
|
||||
$_options_html .= sprintf('<option value="%1$s" %2$s>%3$s</option>',
|
||||
esc_attr( $value ),
|
||||
selected( $this->value(), $value, false ),
|
||||
$label
|
||||
);
|
||||
}
|
||||
break;
|
||||
}//end switch
|
||||
return $_options_html;
|
||||
}//end of fn
|
||||
|
||||
|
||||
/**
|
||||
* Enqueue scripts/styles
|
||||
* fired by the parent Control class constructor
|
||||
*
|
||||
*/
|
||||
// public function enqueue() {
|
||||
// if ( ! empty( self::$enqueued_resources ) )
|
||||
// return;
|
||||
|
||||
// self::$enqueued_resources = true;
|
||||
|
||||
// wp_enqueue_script( 'wp-color-picker' );
|
||||
// wp_enqueue_style( 'wp-color-picker' );
|
||||
|
||||
// wp_enqueue_style(
|
||||
// 'font-awesome',
|
||||
// sprintf('%1$s/assets/front/css/font-awesome.min.css', get_template_directory_uri() ),
|
||||
// array(),
|
||||
// HUEMAN_VER,
|
||||
// $media = 'all'
|
||||
// );
|
||||
|
||||
// //select2 stylesheet
|
||||
// //overriden by some specific style in theme-customzer-control.css
|
||||
// wp_enqueue_style(
|
||||
// 'select2-css',
|
||||
// sprintf('%1$s/assets/czr/css/lib/select2.min.css', get_template_directory_uri() ),
|
||||
// array( 'customize-controls' ),
|
||||
// HUEMAN_VER,
|
||||
// $media = 'all'
|
||||
// );
|
||||
// }
|
||||
|
||||
/**
|
||||
* Refresh the parameters passed to the JavaScript via JSON.
|
||||
*
|
||||
*
|
||||
* @Override
|
||||
* @see WP_Customize_Control::to_json()
|
||||
*/
|
||||
public function to_json() {
|
||||
parent::to_json();
|
||||
if ( is_array( $this->ubq_section ) && array_key_exists( 'section', $this->ubq_section ) )
|
||||
$this->json['ubq_section'] = $this->ubq_section;
|
||||
}
|
||||
}//end of class
|
||||
endif;
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
/*
|
||||
*/
|
||||
if ( class_exists('WP_Customize_Code_Editor_Control') && ! class_exists( 'HU_Customize_Code_Editor_Control' ) ) :
|
||||
class HU_Customize_Code_Editor_Control extends WP_Customize_Code_Editor_Control {
|
||||
|
||||
public $type = 'czr_code_editor';
|
||||
public $title;
|
||||
public $notice;
|
||||
|
||||
/**
|
||||
* Refresh the parameters passed to the JavaScript via JSON.
|
||||
*
|
||||
* @see WP_Customize_Control::json()
|
||||
*
|
||||
* @return array Array of parameters passed to the JavaScript.
|
||||
*/
|
||||
public function json() {
|
||||
$json = parent::json();
|
||||
if ( is_array( $json ) ) {
|
||||
$json['title'] = !empty( $this -> title ) ? esc_html( $this -> title ) : '';
|
||||
$json['notice'] = !empty( $this -> notice ) ? $this -> notice : '';
|
||||
}
|
||||
|
||||
return $json;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Render a JS template for the content of the media control.
|
||||
*
|
||||
* @since 3.4.19
|
||||
* @package Customizr
|
||||
*
|
||||
* @Override
|
||||
* @see WP_Customize_Control::content_template()
|
||||
*/
|
||||
public function content_template() {
|
||||
?>
|
||||
<# if ( data.title ) { #>
|
||||
<h3 class="czr-customizr-title">{{{ data.title }}}</h3>
|
||||
<# } #>
|
||||
<?php parent::content_template(); ?>
|
||||
<# if ( data.notice ) { #>
|
||||
<span class="czr-notice">{{{ data.notice }}}</span>
|
||||
<# } #>
|
||||
<?php
|
||||
}
|
||||
}//end class
|
||||
endif;
|
||||
?>
|
||||
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
/*
|
||||
*/
|
||||
if ( ! class_exists( 'HU_Customize_Color_Alpha_Control' ) ) :
|
||||
class HU_Customize_Color_Alpha_Control extends HU_controls {
|
||||
|
||||
public $type = 'wp_color_alpha';
|
||||
public $title;
|
||||
public $notice;
|
||||
|
||||
public $statuses;
|
||||
|
||||
public $mode = 'full';
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 3.4.0
|
||||
* @uses WP_Customize_Control::__construct()
|
||||
*
|
||||
* @param WP_Customize_Manager $manager Customizer bootstrap instance.
|
||||
* @param string $id Control ID.
|
||||
* @param array $args Optional. Arguments to override class property defaults.
|
||||
*/
|
||||
public function __construct( $manager, $id, $args = array() ) {
|
||||
$this->statuses = array( '' => __('Default', 'hueman') );
|
||||
parent::__construct( $manager, $id, $args );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Refresh the parameters passed to the JavaScript via JSON.
|
||||
*
|
||||
* @see WP_Customize_Control::json()
|
||||
*
|
||||
* @return array Array of parameters passed to the JavaScript.
|
||||
*/
|
||||
public function to_json() {
|
||||
parent::to_json();
|
||||
$this->json['statuses'] = $this->statuses;
|
||||
$this->json['defaultValue'] = $this->setting->default;
|
||||
$this->json['mode'] = $this->mode;
|
||||
$this->json['title'] = !empty( $this -> title ) ? esc_html( $this -> title ) : '';
|
||||
$this->json['notice'] = !empty( $this -> notice ) ? $this -> notice : '';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function content_template() {
|
||||
?>
|
||||
<# var defaultValue = '#RRGGBB', defaultValueAttr = '',
|
||||
isHueSlider = data.mode === 'hue';
|
||||
if ( data.defaultValue && _.isString( data.defaultValue ) && ! isHueSlider ) {
|
||||
if ( '#' !== data.defaultValue.substring( 0, 1 ) ) {
|
||||
defaultValue = '#' + data.defaultValue;
|
||||
} else {
|
||||
defaultValue = data.defaultValue;
|
||||
}
|
||||
defaultValueAttr = ' data-default-color=' + defaultValue; // Quotes added automatically.
|
||||
} #>
|
||||
<# if ( data.label ) { #>
|
||||
<span class="customize-control-title">{{{ data.label }}}</span>
|
||||
<# } #>
|
||||
<# if ( data.description ) { #>
|
||||
<span class="description customize-control-description">{{{ data.description }}}</span>
|
||||
<# } #>
|
||||
<div class="customize-control-content">
|
||||
<label><span class="screen-reader-text">{{{ data.label }}}</span>
|
||||
<# if ( isHueSlider ) { #>
|
||||
<input data-alpha="true" class="color-picker-hue" type="text" data-type="hue" />
|
||||
<# } else { #>
|
||||
<input data-alpha="true" class="color-picker-hex" type="text" maxlength="7" placeholder="{{ defaultValue }}" {{ defaultValueAttr }} />
|
||||
<# } #>
|
||||
</label>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
}//end class
|
||||
endif;
|
||||
?>
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
/*
|
||||
*/
|
||||
if ( class_exists('WP_Customize_Cropped_Image_Control') && ! class_exists( 'HU_Customize_Cropped_Image_Control' ) ) :
|
||||
class HU_Customize_Cropped_Image_Control extends WP_Customize_Cropped_Image_Control {
|
||||
public $type = 'czr_cropped_image';
|
||||
public $title;
|
||||
public $notice;
|
||||
public $dst_width;
|
||||
public $dst_height;
|
||||
|
||||
|
||||
/**
|
||||
* Refresh the parameters passed to the JavaScript via JSON.
|
||||
*
|
||||
*
|
||||
* @Override
|
||||
* @see WP_Customize_Control::to_json()
|
||||
*/
|
||||
public function to_json() {
|
||||
parent::to_json();
|
||||
$this->json['title'] = !empty( $this -> title ) ? esc_html( $this -> title ) : '';
|
||||
$this->json['notice'] = !empty( $this -> notice ) ? $this -> notice : '';
|
||||
|
||||
$this->json['dst_width'] = isset( $this -> dst_width ) ? $this -> dst_width : $this -> width;
|
||||
$this->json['dst_height'] = isset( $this -> dst_height ) ? $this -> dst_height : $this -> height;
|
||||
//overload WP_Customize_Upload_Control
|
||||
//we need to re-build the absolute url of the logo src set in old Customizr
|
||||
$value = $this->value();
|
||||
if ( $value ) {
|
||||
//re-build the absolute url if the value isn't an attachment id before retrieving the id
|
||||
if ( (int) esc_attr( $value ) < 1 ) {
|
||||
$upload_dir = wp_upload_dir();
|
||||
$value = false !== strpos( $value , '/wp-content/' ) ? $value : $upload_dir['baseurl'] . $value;
|
||||
}
|
||||
// Get the attachment model for the existing file.
|
||||
$attachment_id = attachment_url_to_postid( $value );
|
||||
if ( $attachment_id ) {
|
||||
$this->json['attachment'] = wp_prepare_attachment_for_js( $attachment_id );
|
||||
}
|
||||
}//end overload
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a JS template for the content of the media control.
|
||||
*
|
||||
* @since 3.4.19
|
||||
* @package Customizr
|
||||
*
|
||||
* @Override
|
||||
* @see WP_Customize_Control::content_template()
|
||||
*/
|
||||
public function content_template() {
|
||||
?>
|
||||
<# if ( data.title ) { #>
|
||||
<h3 class="czr-customizr-title">{{{ data.title }}}</h3>
|
||||
<# } #>
|
||||
<?php parent::content_template(); ?>
|
||||
<# if ( data.notice ) { #>
|
||||
<span class="czr-notice">{{{ data.notice }}}</span>
|
||||
<# } #>
|
||||
<?php
|
||||
}
|
||||
}//end class
|
||||
endif;
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
/**************************************************************************************************
|
||||
* LAYOUT SELECT
|
||||
***************************************************************************************************/
|
||||
if ( ! class_exists( 'HU_Customize_Layout_Control' ) ) :
|
||||
/**
|
||||
* Customize Multi-picker Control Class
|
||||
*
|
||||
* @package WordPress
|
||||
* @subpackage Customize
|
||||
* @since 3.4.10
|
||||
*/
|
||||
class HU_Customize_Layout_Control extends HU_controls {
|
||||
|
||||
public function render_content() {
|
||||
if ( empty( $this->choices ) )
|
||||
return;
|
||||
|
||||
?>
|
||||
<?php if (!empty( $this->title)) : ?>
|
||||
<h3 class="czr-customizr-title"><?php echo esc_html( $this->title); ?></h3>
|
||||
<?php endif; ?>
|
||||
<label>
|
||||
<span class="customize-control-title"><?php echo $this->label; ?></span>
|
||||
<?php $this -> hu_print_select_control( 'no-selecter-js' ); //no-selecter-js : we don't want the default selecter $ plugin fired for this control ?>
|
||||
<?php if(!empty( $this -> notice)) : ?>
|
||||
<span class="czr-notice"><?php echo $this -> notice ?></span>
|
||||
<?php endif; ?>
|
||||
</label>
|
||||
<?php
|
||||
}
|
||||
|
||||
|
||||
private function hu_print_select_control($class) {
|
||||
printf('<select %1$s class="%2$s">%3$s</select>',
|
||||
call_user_func( array( $this, 'get'.'_'.'link' ) ),
|
||||
$class,
|
||||
$this -> hu_get_select_options()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
private function hu_get_select_options() {
|
||||
$_options_html = '';
|
||||
switch ( $this -> id ) {
|
||||
default:
|
||||
foreach ( $this->choices as $value => $data ) {
|
||||
$_options_html .= sprintf('<option value="%1$s" %2$s>%3$s</option>',
|
||||
esc_attr( $value ),
|
||||
selected( $this->value(), $value, false ),
|
||||
$data['label']
|
||||
);
|
||||
}
|
||||
break;
|
||||
}//end switch
|
||||
return $_options_html;
|
||||
}//end of fn
|
||||
|
||||
//the layouts are turned into a js object
|
||||
//{ 'col-1c' : { src: ..., label : ... }, ... }
|
||||
public function to_json() {
|
||||
parent::to_json();
|
||||
$this->json['layouts'] = $this->choices;
|
||||
}
|
||||
}//end class
|
||||
endif;
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/*
|
||||
* @since 4.0
|
||||
*/
|
||||
if ( ! class_exists( 'HU_Customize_Modules' ) ) :
|
||||
class HU_Customize_Modules extends HU_controls {
|
||||
public $module_type;
|
||||
public $syncCollection;
|
||||
public $syncSektion;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
*/
|
||||
public function __construct($manager, $id, $args = array()) {
|
||||
//let the parent do what it has to
|
||||
parent::__construct($manager, $id, $args );
|
||||
}
|
||||
|
||||
public function render_content(){}
|
||||
|
||||
public function to_json() {
|
||||
parent::to_json();
|
||||
$this->json['syncCollection'] = $this->syncCollection;
|
||||
$this->json['syncSektion'] = $this->syncSektion;
|
||||
$this->json['module_type'] = $this->module_type;
|
||||
}
|
||||
|
||||
}
|
||||
endif;
|
||||
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
/**************************************************************************************************
|
||||
* MULTIPICKER CLASSES
|
||||
***************************************************************************************************/
|
||||
if ( ! class_exists( 'HU_Customize_Multipicker_Control' ) ) :
|
||||
/**
|
||||
* Customize Multi-picker Control Class
|
||||
*
|
||||
* @package WordPress
|
||||
* @subpackage Customize
|
||||
* @since 3.4.10
|
||||
*/
|
||||
abstract class HU_Customize_Multipicker_Control extends HU_controls {
|
||||
|
||||
public function render_content() {
|
||||
|
||||
if ( ! $this -> type ) return;
|
||||
do_action( '__before_setting_control' , $this -> id );
|
||||
|
||||
$dropdown = $this -> hu_get_dropdown_multipicker();
|
||||
|
||||
if ( empty( $dropdown ) ) return;
|
||||
|
||||
$dropdown = str_replace( '<select', '<select multiple="multiple"' . $this->get_link(), $dropdown );
|
||||
//start rendering
|
||||
if (!empty( $this->title)) :
|
||||
?>
|
||||
<h3 class="czr-customizr-title"><?php echo esc_html( $this->title); ?></h3>
|
||||
<?php endif; ?>
|
||||
|
||||
<label>
|
||||
<span class="customize-control-title"><?php echo $this->label; ?></span>
|
||||
<?php echo $dropdown; ?>
|
||||
<?php if(!empty( $this -> notice)) : ?>
|
||||
<span class="czr-notice"><?php echo $this -> notice ?></span>
|
||||
<?php endif; ?>
|
||||
</label>
|
||||
<?php
|
||||
do_action( '__after_setting_control' , $this -> id );
|
||||
}
|
||||
|
||||
//to define in the extended classes
|
||||
abstract public function hu_get_dropdown_multipicker();
|
||||
}//end class
|
||||
endif;
|
||||
|
||||
if ( ! class_exists( 'HU_Customize_Multipicker_Categories_Control' ) ) :
|
||||
class HU_Customize_Multipicker_Categories_Control extends HU_Customize_Multipicker_Control {
|
||||
|
||||
public function hu_get_dropdown_multipicker() {
|
||||
$cats_dropdown = wp_dropdown_categories(
|
||||
array(
|
||||
'name' => '_customize-'.$this->type,
|
||||
'id' => $this -> id,
|
||||
//hide empty, set it to false to avoid complains
|
||||
'hide_empty' => 0 ,
|
||||
'echo' => 0 ,
|
||||
'walker' => new HU_Walker_CategoryDropdown_Multipicker(),
|
||||
'hierarchical' => 1,
|
||||
'class' => 'czrSelect2 no-selecter-js '.$this->type,
|
||||
'selected' => implode(',', $this->value() )
|
||||
)
|
||||
);
|
||||
|
||||
return $cats_dropdown;
|
||||
}
|
||||
}
|
||||
endif;
|
||||
|
||||
|
||||
/**
|
||||
* @ dropdown multi-select walker
|
||||
* Create HTML dropdown list of Categories.
|
||||
*
|
||||
* @package WordPress
|
||||
* @since 2.1.0
|
||||
* @uses Walker
|
||||
*
|
||||
* we need to allow more than one "selected" attribute
|
||||
*/
|
||||
|
||||
if ( ! class_exists( 'HU_Walker_CategoryDropdown_Multipicker' ) ) :
|
||||
class HU_Walker_CategoryDropdown_Multipicker extends Walker_CategoryDropdown {
|
||||
/**
|
||||
* Start the element output.
|
||||
*
|
||||
* @Override
|
||||
*
|
||||
* @see Walker::start_el()
|
||||
*
|
||||
* @param string $output Passed by reference. Used to append additional content.
|
||||
* @param object $category Category data object.
|
||||
* @param int $depth Depth of category. Used for padding.
|
||||
* @param array $args Uses 'selected', 'show_count', and 'value_field' keys, if they exist.
|
||||
* See {@see wp_dropdown_categories()}.
|
||||
*/
|
||||
public function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) {
|
||||
$pad = str_repeat('—', $depth );
|
||||
/** This filter is documented in wp-includes/category-template.php */
|
||||
$cat_name = apply_filters( 'list_cats', $category->name, $category );
|
||||
|
||||
$value_field = 'term_id';
|
||||
|
||||
$output .= "\t<option class=\"level-$depth\" value=\"" . esc_attr( $category->{$value_field} ) . "\"";
|
||||
//Treat selected arg as array
|
||||
if ( in_array( (string) $category->{$value_field}, explode( ',', $args['selected'] ) ) )
|
||||
$output .= ' selected="selected"';
|
||||
|
||||
$output .= '>';
|
||||
$output .= $pad.$cat_name;
|
||||
if ( $args['show_count'] )
|
||||
$output .= ' ('. number_format_i18n( $category->count ) .')';
|
||||
$output .= "</option>\n";
|
||||
}
|
||||
}
|
||||
endif;
|
||||
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
/*********************************************************************************
|
||||
* Old upload control used until v3.4.18, still used if current version of WP is < 4.3
|
||||
**********************************************************************************/
|
||||
if ( ! class_exists( 'HU_Customize_Upload_Control' ) ) :
|
||||
/**
|
||||
* Customize Upload Control Class
|
||||
*
|
||||
* @package WordPress
|
||||
* @subpackage Customize
|
||||
* @since 3.4.0
|
||||
*/
|
||||
class HU_Customize_Upload_Control extends WP_Customize_Control {
|
||||
public $type = 'czr_upload';
|
||||
public $removed = '';
|
||||
public $context;
|
||||
public $extensions = array();
|
||||
public $title;
|
||||
public $notice;
|
||||
|
||||
/**
|
||||
* Enqueue control related scripts/styles.
|
||||
*
|
||||
* @since 3.4.0
|
||||
*/
|
||||
public function enqueue() {
|
||||
wp_enqueue_script( 'wp-plupload' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh the parameters passed to the JavaScript via JSON.
|
||||
*
|
||||
* @since 3.4.0
|
||||
* @uses WP_Customize_Control::to_json()
|
||||
*/
|
||||
public function to_json() {
|
||||
parent::to_json();
|
||||
|
||||
$this->json['removed'] = $this->removed;
|
||||
|
||||
if ( $this->context )
|
||||
$this->json['context'] = $this->context;
|
||||
|
||||
if ( $this->extensions )
|
||||
$this->json['extensions'] = implode( ',', $this->extensions );
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the control's content.
|
||||
*
|
||||
* @since 3.4.0
|
||||
*/
|
||||
public function render_content() {
|
||||
do_action( '__before_setting_control' , $this -> id );
|
||||
?>
|
||||
<?php if ( isset( $this->title) ) : ?>
|
||||
<h3 class="czr-customizr-title"><?php echo esc_html( $this->title); ?></h3>
|
||||
<?php endif; ?>
|
||||
<label>
|
||||
<?php if ( ! empty( $this->label ) ) : ?>
|
||||
<span class="customize-control-title"><?php echo $this->label; ?></span>
|
||||
<?php endif;
|
||||
if ( ! empty( $this->description ) ) : ?>
|
||||
<span class="description customize-control-description"><?php echo $this->description; ?></span>
|
||||
<?php endif; ?>
|
||||
<div>
|
||||
<a href="#" class="button-secondary czr-upload"><?php _e( 'Upload' , 'hueman' ); ?></a>
|
||||
<a href="#" class="remove"><?php _e( 'Remove' , 'hueman' ); ?></a>
|
||||
</div>
|
||||
<?php if(!empty( $this -> notice)) : ?>
|
||||
<span class="czr-notice"><?php echo $this -> notice; ?></span>
|
||||
<?php endif; ?>
|
||||
</label>
|
||||
<?php
|
||||
do_action( '__after_setting_control' , $this -> id );
|
||||
}
|
||||
}
|
||||
endif;
|
||||
@@ -0,0 +1,260 @@
|
||||
<?php
|
||||
|
||||
//control scripts and style
|
||||
//Note that the 'czr-theme-customizer-fmk' is loaded @priority 10
|
||||
add_action( 'customize_controls_enqueue_scripts' , 'hu_customize_controls_js_css', 20 );
|
||||
//preview scripts
|
||||
//set with priority 20 to be fired after hu_customize_store_db_opt in HU_utils
|
||||
add_action( 'customize_preview_init' , 'hu_customize_preview_js', 20 );
|
||||
//exports some wp_query informations. Updated on each preview refresh.
|
||||
add_action( 'customize_preview_init' , 'hu_add_preview_footer_action', 20 );
|
||||
|
||||
//hook : customize_preview_init
|
||||
function hu_customize_preview_js() {
|
||||
global $wp_version;
|
||||
|
||||
wp_enqueue_script(
|
||||
'hu-preview-reactions',
|
||||
HU_BASE_URL . 'assets/czr/js/_customize_preview_reactions.js',//src
|
||||
'czr-customizer-preview',
|
||||
( defined('WP_DEBUG') && true === WP_DEBUG ) ? time() : HUEMAN_VER,
|
||||
true//$in_footer = false
|
||||
);
|
||||
|
||||
|
||||
//localizes
|
||||
wp_localize_script(
|
||||
'czr-customizer-preview', // this is the handle of the base czr fmk
|
||||
'themeServerPreviewParams',
|
||||
apply_filters('hu_js_customizer_preview_params' ,
|
||||
array(
|
||||
'wpBuiltinSettings' => HU_customize::$instance -> hu_get_wp_builtin_settings(),
|
||||
'themeOptionsPrefix' => HU_THEME_OPTIONS,
|
||||
'fonts' => array( 'src' => hu_get_fonts( array( 'all' => true, 'request' => 'src' ) ), 'family' => hu_get_fonts( array( 'all' => true, 'request' => 'family' ) ) ),
|
||||
|
||||
'copyright' => sprintf('%1$s © %2$s. %3$s',
|
||||
get_bloginfo('name'),
|
||||
date( 'Y' ),
|
||||
__( 'All Rights Reserved.', 'hueman' )
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Add script to controls
|
||||
* Dependency : customize-controls located in wp-includes/script-loader.php
|
||||
* Hooked on customize_controls_enqueue_scripts located in wp-admin/customize.php
|
||||
* @package Hueman
|
||||
* @since Hueman 3.3.0
|
||||
*/
|
||||
function hu_customize_controls_js_css() {
|
||||
wp_enqueue_script(
|
||||
'hu-control-dependencies',
|
||||
HU_BASE_URL . 'assets/czr/js/_customize_control_dependencies_and_dom_ready_actions.js',//src
|
||||
'czr-theme-customizer-fmk',
|
||||
( defined('WP_DEBUG') && true === WP_DEBUG ) ? time() : HUEMAN_VER,
|
||||
true//$in_footer = false
|
||||
);
|
||||
|
||||
|
||||
$_front_page_content_notice = esc_js( sprintf( __( "Jump to the %s.", 'hueman'),
|
||||
sprintf('<a href="%1$s" title="%2$s">%2$s</a>',
|
||||
"javascript:wp.customize.section(\'content_blog_sec\').focus();",
|
||||
__('blog design panel', 'hueman')
|
||||
)
|
||||
) );
|
||||
$_header_menu_notice = esc_js( sprintf( __( "The menu currently displayed in your header is a default page menu, you can disable it in the %s.", 'hueman'),
|
||||
sprintf('<a href="%1$s" title="%2$s">%2$s</a>',
|
||||
"javascript:wp.customize.section(\'header_design_sec\').focus();",
|
||||
__('Header Panel', 'hueman')
|
||||
)
|
||||
) );
|
||||
//localizes
|
||||
wp_localize_script(
|
||||
'czr-theme-customizer-fmk', // this is the handle of the base czr fmk
|
||||
'themeServerControlParams',
|
||||
apply_filters('czr_js_customizer_control_params' ,
|
||||
array(
|
||||
//should be included in all themes
|
||||
'wpBuiltinSettings' => HU_customize::$instance -> hu_get_wp_builtin_settings(),
|
||||
'isThemeSwitchOn' => ! (bool)HU_IS_PRO,
|
||||
'themeSettingList' => HU_utils::$_theme_setting_list,
|
||||
'themeOptions' => HU_THEME_OPTIONS,
|
||||
'HUNonce' => wp_create_nonce( 'hu-customizer-nonce' ),
|
||||
|
||||
'themeName' => THEMENAME,// <= do we need this ?
|
||||
|
||||
//'optionAjaxAction' => HU_OPT_AJAX_ACTION,//DEPRECATED
|
||||
'faviconOptionName' => 'favicon',
|
||||
'i18n' => hu_get_czr_translated_strings(),
|
||||
|
||||
// For the control dependencies js file
|
||||
'isMultisite' => is_multisite(),
|
||||
'frontPageContentNotice' => html_entity_decode( $_front_page_content_notice ),
|
||||
'headerMenuNotice' => html_entity_decode( $_header_menu_notice )
|
||||
|
||||
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
//hook : customize_preview_init
|
||||
function hu_add_preview_footer_action() {
|
||||
//Add the postMessages actions
|
||||
add_action( 'wp_footer', 'hu_add_customize_preview_data' , 20 );
|
||||
}
|
||||
|
||||
//hook : wp_footer in the preview
|
||||
function hu_add_customize_preview_data() {
|
||||
global $wp_query, $wp_customize;
|
||||
$current_obj = get_queried_object();
|
||||
$query_data = array(
|
||||
'post_id' => false,
|
||||
'post_thumbnail_id' => false,
|
||||
'post_title' => false
|
||||
);
|
||||
//post, custom post types, page
|
||||
if ( is_singular() && ! hu_is_real_home() && isset($current_obj -> post_type) ) {
|
||||
$query_data['post_id'] = $current_obj -> ID;
|
||||
$query_data['post_title'] = $current_obj -> post_title;
|
||||
$query_data['post_thumbnail_id'] = has_post_thumbnail( $current_obj -> ID ) ? get_post_thumbnail_id( $current_obj -> ID ) : false;
|
||||
}
|
||||
|
||||
$_wp_query_infos = array(
|
||||
'conditional_tags' => array(),
|
||||
'query_data' => $query_data
|
||||
);
|
||||
$_available_locations = hu_get_available_widget_loc();
|
||||
|
||||
//Populates the conditional tags
|
||||
foreach( (array)$wp_query as $prop => $val ) {
|
||||
if ( false === strpos($prop, 'is_') )
|
||||
continue;
|
||||
if ( 'is_home' == $prop )
|
||||
$val = hu_is_real_home();
|
||||
|
||||
$_wp_query_infos['conditional_tags'][$prop] = $val;
|
||||
}
|
||||
$_wp_query_infos = apply_filters( 'czr-preview-query-data', $_wp_query_infos );
|
||||
|
||||
?>
|
||||
<script id="czr-customizer-data">
|
||||
(function ( _export ){
|
||||
_export.czr_wpQueryInfos = <?php echo wp_json_encode( $_wp_query_infos ) ?>;
|
||||
_export.availableWidgetLocations = <?php echo wp_json_encode( $_available_locations ) ?>;
|
||||
})( _wpCustomizeSettings );
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
|
||||
|
||||
|
||||
function hu_get_czr_translated_strings() {
|
||||
return apply_filters( 'controls_translated_strings',
|
||||
array(
|
||||
'edit' => __('Edit', 'hueman'),
|
||||
'close' => __('Close', 'hueman'),
|
||||
'faviconNote' => __( "Your favicon is currently handled with an old method and will not be properly displayed on all devices. You might consider to re-upload your favicon with the new control below." , 'hueman'),
|
||||
'locations' => __('Location(s)', 'hueman'),
|
||||
'contexts' => __('Context(s)', 'hueman'),
|
||||
'notset' => __('Not set', 'hueman'),
|
||||
'rss' => __('Rss', 'hueman'),
|
||||
'selectSocialIcon' => __('Select a social icon', 'hueman'),
|
||||
'followUs' => __('Follow us on', 'hueman'),
|
||||
'successMessage' => __('Done !', 'hueman'),
|
||||
'socialLinkAdded' => __('New Social Link created ! Scroll down to edit it.', 'hueman'),
|
||||
|
||||
'selectBgRepeat' => __('Select repeat property', 'hueman'),
|
||||
'selectBgAttachment' => __('Select attachment property', 'hueman'),
|
||||
'selectBgPosition' => __('Select position property', 'hueman'),
|
||||
|
||||
// 'widgetZone' => __('Widget Zone', 'hueman'),
|
||||
// 'widgetZoneAdded' => __('New Widget Zone created ! Scroll down to edit it.', 'hueman'),
|
||||
// 'inactiveWidgetZone' => __('Inactive in current context/location', 'hueman'),
|
||||
// 'unavailableLocation' => __('Unavailable location. Some settings must be changed.', 'hueman'),
|
||||
// 'locationWarning' => __('A selected location is not available with the current settings.', 'hueman'),
|
||||
|
||||
'readDocumentation' => __('Learn more about this in the documentation', 'hueman'),
|
||||
'Settings' => __('Settings', 'hueman'),
|
||||
'Options for' => __('Options for', 'hueman'),
|
||||
|
||||
'skope' => array(
|
||||
//skope reset
|
||||
'Reset the current customizations for' => __('Reset the current customizations for','hueman'),
|
||||
'Reset the theme options published sitewide' => __('Reset the theme options published sitewide','hueman'),
|
||||
'Reset your website published options for' => __('Reset your website published options for','hueman'),
|
||||
'Please confirm that you want to reset your current ( not published ) customizations for' => __('Please confirm that you want to reset your current ( not published ) customizations for','hueman'),
|
||||
'Your customizations have been reset for' => __('Your customizations have been reset for','hueman'),
|
||||
'Please confirm that you want to reset your sitewide published customizations. Note : this will not reset the customizations made in other option scopes' => __('Please confirm that you want to reset your sitewide published customizations. Note : this will not reset the customizations made in other option scopes', 'hueman'),
|
||||
'Please confirm that you want to reset your published customizations for' => __('Please confirm that you want to reset your published customizations for','hueman'),
|
||||
'Your published customizations have been reset for' => __('Your published customizations have been reset for','hueman'),
|
||||
|
||||
//control reset
|
||||
'Reset your customized ( and published ) value' => __('Reset your customized ( and published ) value', 'hueman'),
|
||||
'Reset your customized ( but not yet published ) value' => __('Reset your customized ( but not yet published ) value', 'hueman'),
|
||||
'Not customized yet, nothing to reset' => __('Not customized yet, nothing to reset', 'hueman'),
|
||||
'Reset your customized ( but not yet published ) value' => __('Reset your customized ( but not yet published ) value', 'hueman'),
|
||||
'Please confirm that you want to reset your current customizations for this option' => __( 'Please confirm that you want to reset your current customizations for this option', 'hueman' ),
|
||||
'Please confirm that you want to reset your current customizations for this option in' => __('Please confirm that you want to reset your current customizations for this option in', 'hueman'),
|
||||
'sitewide' => __('sitewide', 'hueman'),
|
||||
'Your customizations have been reset' => __('Your customizations have been reset', 'hueman'),
|
||||
'This WordPress setting can not be reset sitewide' => __('This WordPress setting can not be reset sitewide', 'hueman'),
|
||||
'Please confirm that you want to reset this option' => __('Please confirm that you want to reset this option', 'hueman'),
|
||||
'Please confirm that you want to reset this option in' => __('Please confirm that you want to reset this option in', 'hueman'),
|
||||
'The option has been reset' => __('The option has been reset', 'hueman'),
|
||||
|
||||
//control notices
|
||||
'Display informations about the scope of this option.' => __('Display informations about the scope of this option.', 'hueman'),
|
||||
'This option is always customized sitewide and cannot be reset.' => __('This option is always customized sitewide and cannot be reset.', 'hueman'),
|
||||
'Customized. Will be applied sitewide once published.' => __('Customized. Will be applied sitewide once published.','hueman'),
|
||||
'Customized. Will be applied to' => __('Customized. Will be applied to', 'hueman'),
|
||||
'once published.' => __('once published.', 'hueman'),
|
||||
'Customized and applied sitewide.' => __('Customized and applied sitewide.', 'hueman'),
|
||||
'Customized and applied to' => __('Customized and applied to','hueman'),
|
||||
'Default website value applied sitewide.' => __('Default website value applied sitewide.','hueman'),
|
||||
'Default website value.' => __('Default sitewide value.','hueman'),
|
||||
'You can customize this specifically for' => __('You can customize this specifically for', 'hueman'),
|
||||
'Currently inherited from' => __('Currently inherited from','hueman'),
|
||||
'You can customize this specifically for' => __('You can customize this specifically for','hueman'),
|
||||
'The value currently applied to' => __('The value currently applied to','hueman'),
|
||||
'The value that will be applied to' => __('The value that will be applied to','hueman'),
|
||||
'is set in' => __('is set in','hueman'),
|
||||
'is customized in' => __('is customized in','hueman'),
|
||||
|
||||
//various skope
|
||||
'is always customized sitewide.' => __('is always customized sitewide.', 'hueman'),
|
||||
'Menus are created sitewide.' => __('Menus are created sitewide.', 'hueman'),
|
||||
'Widgets are created sitewide.' => __('Widgets are created sitewide.', 'hueman'),
|
||||
'and' => __('and', 'hueman'),
|
||||
'Switch to scope' => __('Switch to scope', 'hueman'),
|
||||
'In this context :' => __('In this context :', 'hueman'),
|
||||
'inherits from' => __('inherits from', 'hueman'),
|
||||
'overridden by' => __('overridden by', 'hueman'),
|
||||
|
||||
//error when loading
|
||||
'There was a problem when trying to load the customizer.' => __('There was a problem when trying to load the customizer.','hueman'),
|
||||
'Please refer to' => __('Please refer to','hueman'),
|
||||
'this documentation page' => __('this documentation page','hueman'),
|
||||
'to understand how to fix the problem.' => __('to understand how to fix the problem.','hueman'),
|
||||
|
||||
//skope preview bottom informations
|
||||
'The customizations made site wide are inherited by all other levels of customization.' => __('The customizations made site wide are inherited by all other levels of customization.', 'hueman'),
|
||||
'The current context' => __('The current context', 'hueman'),
|
||||
'can be customized more specifically at the following level' => __('can be customized more specifically at the following level', 'hueman'),
|
||||
'The current customizations will be applied to' => __('The current customizations will be applied to', 'hueman'),
|
||||
'The options not customized at this level will inherit their value from' => __('The options not customized at this level will inherit their value from', 'hueman'),
|
||||
'can be customized more specifically at the following level' => __('can be customized more specifically at the following level', 'hueman'),
|
||||
'can be customized with a specific set of options.' => __('can be customized with a specific set of options.', 'hueman'),
|
||||
'The options not customized at this level will inherit their value from' => __('The options not customized at this level will inherit their value from', 'hueman')
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
/***************************************************
|
||||
* AUGMENTS WP CUSTOMIZE PANELS
|
||||
***************************************************/
|
||||
if ( ! class_exists( 'HU_Customize_Panels') ) :
|
||||
class HU_Customize_Panels extends WP_Customize_Panel {
|
||||
public $czr_subtitle = '';
|
||||
|
||||
// function __construct( $manager, $id, $args = array() ) {
|
||||
// $keys = array_keys( get_object_vars( $this ) );
|
||||
// foreach ( $keys as $key ) {
|
||||
// if ( isset( $args[ $key ] ) ) {
|
||||
// $this->$key = $args[ $key ];
|
||||
// }
|
||||
// }
|
||||
// parent::__construct( $manager, $id, $args );
|
||||
|
||||
|
||||
// }
|
||||
|
||||
public function json() {
|
||||
$array = parent::json();
|
||||
$array['czr_subtitle'] = html_entity_decode( $this->czr_subtitle, ENT_QUOTES, get_bloginfo( 'charset' ) );
|
||||
return $array;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Render the panel's JS templates.
|
||||
*
|
||||
* This function is only run for panel types that have been registered with
|
||||
* WP_Customize_Manager::register_panel_type().
|
||||
*
|
||||
* @since 4.3.0
|
||||
*
|
||||
* @see WP_Customize_Manager::register_panel_type()
|
||||
*/
|
||||
public function print_template() {
|
||||
?>
|
||||
<script type="text/html" id="tmpl-customize-panel-hu_panel">
|
||||
<?php $this->hu_render_template(); ?>
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* An Underscore (JS) template for rendering this panel's container.
|
||||
*
|
||||
* Class variables for this panel class are available in the `data` JS object;
|
||||
* export custom variables by overriding WP_Customize_Panel::json().
|
||||
*
|
||||
* @see WP_Customize_Panel::print_template()
|
||||
*
|
||||
* @since 4.3.0
|
||||
* @access protected
|
||||
*/
|
||||
protected function hu_render_template() {
|
||||
?>
|
||||
<li id="accordion-panel-{{ data.id }}" class="accordion-section control-section control-panel control-panel-{{ data.type }}">
|
||||
<h3 class="accordion-section-title" tabindex="0">
|
||||
{{ data.title }}
|
||||
<span class="czr-panel-subtitle">{{ data.czr_subtitle }}</span>
|
||||
<span class="screen-reader-text"><?php _e( 'Press return or enter to open this panel', 'hueman' ); ?></span>
|
||||
</h3>
|
||||
<ul class="accordion-sub-container control-panel-content"></ul>
|
||||
</li>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
endif;
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
/**
|
||||
* Pro customizer section.
|
||||
* highly based on
|
||||
* https://github.com/justintadlock/trt-customizer-pro/blob/master/example-1/section-pro.php
|
||||
*/
|
||||
class HU_Customize_Section_Pro extends WP_Customize_Section {
|
||||
|
||||
/**
|
||||
* The type of customize section being rendered.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $type ='czr-customize-section-pro';
|
||||
|
||||
/**
|
||||
* Custom button text to output.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
|
||||
public $pro_text = '';
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $pro_url = '';
|
||||
|
||||
|
||||
/**
|
||||
* Add custom parameters to pass to the JS via JSON.
|
||||
*
|
||||
* @return void
|
||||
* @override
|
||||
*/
|
||||
public function json() {
|
||||
$json = parent::json();
|
||||
$json['pro_text'] = $this->pro_text;
|
||||
$json['pro_url'] = $this->pro_url;
|
||||
return $json;
|
||||
}
|
||||
|
||||
//overrides the default template
|
||||
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 }}
|
||||
<# if ( data.pro_text && data.pro_url ) { #>
|
||||
<a href="{{ data.pro_url }}" title="{{ data.title }}" class="button button-secondary alignright" target="_blank">{{ data.pro_text }}</a>
|
||||
<# } #>
|
||||
</h3>
|
||||
</li>
|
||||
<?php }
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* Base customizer section.
|
||||
*/
|
||||
class HU_Customize_Sections extends WP_Customize_Section {
|
||||
|
||||
/**
|
||||
* The type of customize section being rendered.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $type = 'czr-customize-sections';
|
||||
|
||||
public $ubq_panel;
|
||||
|
||||
|
||||
/**
|
||||
* Add custom parameters to pass to the JS via JSON.
|
||||
*
|
||||
* @return void
|
||||
* @override
|
||||
*/
|
||||
public function json() {
|
||||
$json = parent::json();
|
||||
if ( is_array( $this->ubq_panel ) && array_key_exists( 'panel', $this->ubq_panel ) ) {
|
||||
$json['ubq_panel'] = $this->ubq_panel;
|
||||
}
|
||||
return $json;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
/***************************************************
|
||||
* AUGMENTS WP CUSTOMIZE SECTIONS
|
||||
***************************************************/
|
||||
if ( ! class_exists( 'HU_Customize_Manage_Widgets_Section' ) ) :
|
||||
class HU_Customize_Manage_Widgets_Section extends WP_Customize_Section {
|
||||
|
||||
/**
|
||||
* type of this section.
|
||||
*
|
||||
* @since 4.3.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
public $type = 'widget_zones_management';
|
||||
|
||||
|
||||
public function __construct( $manager, $id, $args = array() ) {
|
||||
//let the parent say what he needs to. We need to hear that sometimes.
|
||||
parent::__construct($manager, $id, $args );
|
||||
//add_action( 'customize_controls_print_footer_scripts', array( $this, 'hu_render_widget_zone_template' ), 1 );
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Render the section, and the controls that have been added to it.
|
||||
* hook : customize_controls_print_footer_scripts
|
||||
*/
|
||||
public function hu_render_widget_zone_template() {
|
||||
?>
|
||||
<script type="text/html" id="tmpl-customize-section-<?php echo $this->type; ?>">
|
||||
<li id="accordion-section-{{ data.id }}" class="czr-widget-zone-section accordion-section control-section control-section-{{ data.type }}">
|
||||
<h3 class="accordion-section-title" tabindex="0">
|
||||
{{ data.title }}
|
||||
<span class="screen-reader-text"><?php _e( 'Press return or enter to open this section', 'hueman' ); ?></span>
|
||||
</h3>
|
||||
<ul class="accordion-section-content"></ul>
|
||||
</li>
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
}//class
|
||||
|
||||
endif;
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
/***************************************************
|
||||
* AUGMENTS WP CUSTOMIZE SETTINGS
|
||||
***************************************************/
|
||||
if ( ! class_exists( 'HU_Customize_Setting') ) :
|
||||
class HU_Customize_Setting extends WP_Customize_Setting {
|
||||
/**
|
||||
* Fetch the value of the setting.
|
||||
*
|
||||
* @since 3.4.0
|
||||
*
|
||||
* @return mixed The value.
|
||||
*/
|
||||
public function value() {
|
||||
// Get the callback that corresponds to the setting type.
|
||||
switch( $this->type ) {
|
||||
case 'theme_mod' :
|
||||
$function = 'get_theme_mod';
|
||||
break;
|
||||
case 'option' :
|
||||
$function = 'get_option';
|
||||
break;
|
||||
default :
|
||||
|
||||
/**
|
||||
* Filter a Customize setting value not handled as a theme_mod or option.
|
||||
*
|
||||
* The dynamic portion of the hook name, `$this->id_date['base']`, refers to
|
||||
* the base slug of the setting name.
|
||||
*
|
||||
* For settings handled as theme_mods or options, see those corresponding
|
||||
* functions for available hooks.
|
||||
*
|
||||
* @since 3.4.0
|
||||
*
|
||||
* @param mixed $default The setting default value. Default empty.
|
||||
*/
|
||||
return apply_filters( 'customize_value_' . $this->id_data[ 'base' ], $this->default );
|
||||
}
|
||||
|
||||
// Handle non-array value
|
||||
if ( empty( $this->id_data[ 'keys' ] ) )
|
||||
return $function( $this->id_data[ 'base' ], $this->default );
|
||||
|
||||
// Handle array-based value
|
||||
$values = $function( $this->id_data[ 'base' ] );
|
||||
|
||||
//Ctx future backward compat
|
||||
$_maybe_array = $this->multidimensional_get( $values, $this->id_data[ 'keys' ], $this->default );
|
||||
if ( ! is_array( $_maybe_array ) )
|
||||
return $_maybe_array;
|
||||
if ( isset($_maybe_array['all_ctx']) )
|
||||
return $_maybe_array['all_ctx'];
|
||||
if ( isset($_maybe_array['all_ctx_over']) )
|
||||
return $_maybe_array['all_ctx_over'];
|
||||
|
||||
return $_maybe_array;
|
||||
//$this->default;
|
||||
}
|
||||
}
|
||||
endif;
|
||||
Reference in New Issue
Block a user