label ) ) return ''; return '

'.$this->label.'

'; } /** * The description should be uniform for every control - so just lay it out * once and reference it from the render_content callback everywhere. */ public function get_description_markup() { if ( empty( $this->desc ) ) return ''; return '

'.$this->desc.'

'; } /** * Just like the description that comes first, the description that comes after * the main control should be uniform for each of these controls - so just lay * it out once and reference it from the render_content callback everywhere. */ public function get_description_after_markup() { if ( empty( $this->desc_after ) ) return ''; return '

'.$this->desc_after.'

'; } /** * The label and description should be uniform for every control - so just lay it out * once and reference it from the render_content callback everywhere. */ public function get_label_description_markup() { return $this->get_label_markup(). $this->get_description_markup(); } } /** * Dummy control - contains no setting, just for display. * Arg Options: * * @author Dan Suleski * @since 2.0 */ class cz_dummy_ctl extends \WP_Customize_Control { /** * @var integer Utilized and incremented so that each instance of this control has a unique setting */ public static $count = 1; /** * Constructor. To ease the pain on the client code, create a dummy setting here instead. * * @param WP_Customize_Manager $manager * @param string $id * @param array $args */ public function __construct( $manager, $id = '', $args = array() ) { $setting_id = empty( $id ) ? ( 'ski_opt_dummy_'.( string )self::$count++ ) : $id; $manager->add_setting( $setting_id, array( 'sanitize_callback' => array( '\ski\sanitize', 'none' ) ) ); parent::__construct( $manager, $setting_id, $args ); } } /** * Checkbox. * Arg Options: desc, label, option_text * * @author Dan Suleski * @since 2.0 */ class cz_checkbox_ctl extends \WP_Customize_Control { use cz_supplement; /** * @var string Replaces the label for use *NEXT* to the checkbox */ public $option_text = ''; /** * Similar to what came with WP 3.8, but now with a description. */ public function render_content() { echo '
'. $this->get_label_description_markup(). ''. $this->get_description_after_markup(). '
'; } } /** * Color palette. * Arg Options: desc, label * * @author Dan Suleski * @since 2.0 */ class cz_color_palette_ctl extends \WP_Customize_Color_Control { use cz_supplement; /** * Cannot use the default enqueue because this color palette requires a special * control provided by WP. */ public function enqueue() { wp_enqueue_script( 'wp-color-picker' ); wp_enqueue_style( 'wp-color-picker' ); } /** * Similar to what came with WP 3.8, but now with a description. */ public function render_content() { $this_default = $this->setting->default; $default_attr = ''; if ( $this_default ) { if ( false === strpos( $this_default, '#' ) ) { $this_default = '#'.$this_default; } $default_attr = ' data-default-color="'.esc_attr( $this_default ).'"'; } // The input's value gets set by JS. Don't fill it. echo '
'. $this->get_label_description_markup(). '
'. ''. '
'. $this->get_description_after_markup(). '
'; } } /** * Date picker. * Arg Options: desc, label * * @author Dan Suleski * @since 2.0 */ class cz_date_picker_ctl extends \WP_Customize_Control { use cz_supplement; /** * Queue up the scripts and styles necessary for the jQuery UI date picker. Two notes: * 1. The last parameter to wp_enqueue_script forces the inclusion in the footer * instead of the head for faster loading. * 2. WP does not provide an already-registered jQuery UI stylesheet; as a result, * the popular method appears to be using the Google CDN. */ public function enqueue() { // Note: For some reason, the jQueryUI version of the DatePicker // control is not being displayed, but rather the in-built // or WP version of the calendar dropdown is being shown. // Also note that this seems to work for the corresponding // metabox control - so here, we add a type of 'date' in // the render call to get something functional. wp_enqueue_script( 'jquery-ui-datepicker' ); } /** * Similar to what came with WP 3.8, but now with a description. */ public function render_content() { echo '
'. $this->get_label_description_markup(). 'get_link().' />'. $this->get_description_after_markup(). '
'; } } /** * Label and/or description. * Arg Options: desc, label * * @author Dan Suleski * @since 2.0 */ class cz_detail_ctl extends cz_dummy_ctl { use cz_supplement; /** * Simple output. */ public function render_content() { echo $this->get_label_description_markup(). $this->get_description_after_markup(); } } /** * Divider. * Arg Options: * * @author Dan Suleski * @since 2.0 */ class cz_divider_1_ctl extends cz_dummy_ctl { /** * Simple output. */ public function render_content() { echo '
'; } } /** * Divider. * Arg Options: * * @author Dan Suleski * @since 2.0 */ class cz_divider_2_ctl extends cz_dummy_ctl { /** * Simple output. */ public function render_content() { echo '
'; } } /** * Dropdown. * Arg Options: choices, desc, label, none * * @author Dan Suleski * @since 2.0 */ class cz_drop_ctl extends \WP_Customize_Control { use cz_supplement; /** * @var string Set this to a value to show a special 'none' option that is set to a value of 'none'. */ public $none = ''; /** * Similar to what came with WP 3.8, but now with a description. */ public function render_content() { if ( empty( $this->choices ) && ( empty( $this->none ) ) ) { return; } echo '
'. $this->get_label_description_markup(). ''. $this->get_description_after_markup(). '
'; } } /** * Dropdown filled with posts. * Arg Options: desc, label AND any of the arguments listed here: * http://codex.wordpress.org/Function_Reference/get_categories * * @author Dan Suleski * @since 2.0 */ class cz_drop_categories_ctl extends cz_drop_ctl { /** * Constructor. Reusing the regular dropdown control and just sending in * values with which to populate the options - the rendering is the same * * @param WP_Customize_Manager $manager * @param string $id * @param array $args */ public function __construct( $manager, $id, $args = array() ) { $query_args = array( 'type' => isset( $args['type'] ) ? $args['type'] : 'post', 'child_of' => isset( $args['child_of'] ) ? $args['child_of'] : 0, 'parent' => isset( $args['parent'] ) ? $args['parent'] : '', 'orderby' => isset( $args['orderby'] ) ? $args['orderby'] : 'name', 'order' => isset( $args['order'] ) ? $args['order'] : 'ASC', 'hide_empty' => isset( $args['hide_empty'] ) ? $args['hide_empty'] : 0, 'hierarchical' => isset( $args['hierarchical'] ) ? $args['hierarchical'] : 1, 'exclude' => isset( $args['exclude'] ) ? $args['exclude'] : '', 'include' => isset( $args['include'] ) ? $args['include'] : '', 'number' => isset( $args['number'] ) ? $args['number'] : '', 'taxonomy' => isset( $args['taxonomy'] ) ? $args['taxonomy'] : 'category', 'pad_counts' => isset( $args['pad_counts'] ) ? $args['pad_counts'] : false ); $query_result = get_categories( $query_args ); $args['choices'] = array(); if ( !is_wp_error( $query_result ) && ( !empty( $query_result ) ) ) { foreach( $query_result as $entry ) { $args['choices'][$entry->term_id] = $entry->name; } } parent::__construct( $manager, $id, $args ); } } /** * Dropdown filled with registered image sizes. * Arg Options: desc, label * * @author Dan Suleski * @since 2.0 */ class cz_drop_image_sizes_ctl extends cz_drop_ctl { /** * @var boolean Set to true to make entries look like ' width x height' */ public $dimensions = false; /** * Constructor. Reusing the regular dropdown control and just sending in * values with which to populate the options - the rendering is the same * * @param WP_Customize_Manager $manager * @param string $id * @param array $args */ public function __construct( $manager, $id, $args = array() ) { $this->dimensions = ( isset( $args['dimensions'] ) ? $args['dimensions'] : false ); $query_result = media::get_image_sizes( $this->dimensions ); $args['choices'] = array(); if ( !is_wp_error( $query_result ) && ( !empty( $query_result ) ) ) { foreach( $query_result as $entry ) { $short_name = string::truncate( $entry, 1, '' ); $args['choices'][$short_name] = $entry; } } parent::__construct( $manager, $id, $args ); } } /** * Dropdown filled with menu items. * Arg Options: desc, label AND any of the arguments listed here: * http://codex.wordpress.org/Function_Reference/wp_get_nav_menu_items * * @author Dan Suleski * @since 2.0 */ class cz_drop_menu_items_ctl extends cz_drop_ctl { /** * Constructor. Reusing the regular dropdown control and just sending in * values with which to populate the options - the rendering is the same * * @param WP_Customize_Manager $manager * @param string $id * @param array $args */ public function __construct( $manager, $id, $args = array() ) { $menu_arg = isset( $args['menu'] ) ? $args['menu'] : ''; $query_args = array( 'order' => isset( $args['order'] ) ? $args['order'] : 'ASC', 'orderby' => isset( $args['orderby'] ) ? $args['orderby'] : 'menu_order', 'post_type' => isset( $args['post_type'] ) ? $args['post_type'] : 'nav_menu_item', 'post_status' => isset( $args['post_status'] ) ? $args['post_status'] : 'publish', 'output' => isset( $args['output'] ) ? $args['output'] : ARRAY_A, 'output_key' => isset( $args['output_key'] ) ? $args['output_key'] : 'menu_order', 'nopaging' => isset( $args['nopaging'] ) ? $args['nopaging'] : true, 'update_post_term_cache' => isset( $args['update_post_term_cache'] ) ? $args['update_post_term_cache'] : false ); $query_result = wp_get_nav_menu_items( $menu_arg, $query_args ); $args['choices'] = array(); if ( !is_wp_error( $query_result ) && ( !empty( $query_result ) ) ) { foreach( $query_result as $entry ) { $args['choices'][$entry->ID] = $entry->title; } } parent::__construct( $manager, $id, $args ); } } /** * Dropdown filled with pages. * Arg Options: desc, label AND any of the arguments listed here: * http://codex.wordpress.org/Function_Reference/get_pages * * @author Dan Suleski * @since 2.0 */ class cz_drop_pages_ctl extends cz_drop_ctl { /** * Constructor. Reusing the regular dropdown control and just sending in * values with which to populate the options - the rendering is the same * * @param WP_Customize_Manager $manager * @param string $id * @param array $args */ public function __construct( $manager, $id, $args = array() ) { $query_args = array( 'sort_order' => isset( $args['sort_order'] ) ? $args['sort_order'] : 'ASC', 'sort_column' => isset( $args['sort_column'] ) ? $args['sort_column'] : 'post_title', 'hierarchical' => isset( $args['hierarchical'] ) ? $args['hierarchical'] : 1, 'exclude' => isset( $args['exclude'] ) ? $args['exclude'] : '', 'include' => isset( $args['include'] ) ? $args['include'] : '', 'meta_key' => isset( $args['meta_key'] ) ? $args['meta_key'] : '', 'meta_value' => isset( $args['meta_value'] ) ? $args['meta_value'] : '', 'authors' => isset( $args['authors'] ) ? $args['authors'] : '', 'child_of' => isset( $args['child_of'] ) ? $args['child_of'] : 0, 'parent' => isset( $args['parent'] ) ? $args['parent'] : -1, 'exclude_tree' => isset( $args['exclude_tree'] ) ? $args['exclude_tree'] : '', 'number' => isset( $args['number'] ) ? $args['number'] : '', 'offset' => isset( $args['offset'] ) ? $args['offset'] : 0, 'post_type' => isset( $args['post_type'] ) ? $args['post_type'] : 'page', 'post_status' => isset( $args['post_status'] ) ? $args['post_status'] : 'publish' ); $query_result = get_pages( $query_args ); $args['choices'] = array(); if ( !is_wp_error( $query_result ) && ( !empty( $query_result ) ) ) { foreach( $query_result as $entry ) { $args['choices'][$entry->ID] = $entry->post_title; } } parent::__construct( $manager, $id, $args ); } } /** * Dropdown filled with posts. * Arg Options: desc, label AND any of the arguments listed here: * http://codex.wordpress.org/Template_Tags/get_posts * * @author Dan Suleski * @since 2.0 */ class cz_drop_posts_ctl extends cz_drop_ctl { /** * Constructor. Reusing the regular dropdown control and just sending in * values with which to populate the options - the rendering is the same * * @param WP_Customize_Manager $manager * @param string $id * @param array $args */ public function __construct( $manager, $id, $args = array() ) { $query_args = array( 'posts_per_page' => isset( $args['posts_per_page'] ) ? $args['posts_per_page'] : 5, 'offset' => isset( $args['offset'] ) ? $args['offset'] : 0, 'category' => isset( $args['category'] ) ? $args['category'] : '', 'orderby' => isset( $args['orderby'] ) ? $args['orderby'] : 'post_date', 'order' => isset( $args['order'] ) ? $args['order'] : 'DESC', 'include' => isset( $args['include'] ) ? $args['include'] : '', 'exclude' => isset( $args['exclude'] ) ? $args['exclude'] : '', 'meta_key' => isset( $args['meta_key'] ) ? $args['meta_key'] : '', 'meta_value' => isset( $args['meta_value'] ) ? $args['meta_value'] : '', 'post_type' => isset( $args['post_type'] ) ? $args['post_type'] : 'post', 'post_mime_type' => isset( $args['post_mime_type'] ) ? $args['post_mime_type'] : '', 'post_parent' => isset( $args['post_parent'] ) ? $args['post_parent'] : '', 'post_status' => isset( $args['post_status'] ) ? $args['post_status'] : 'publish', 'suppress_filters' => isset( $args['suppress_filters'] ) ? $args['suppress_filters'] : true ); $query_result = get_posts( $query_args ); $args['choices'] = array(); if ( !is_wp_error( $query_result ) && ( !empty( $query_result ) ) ) { foreach( $query_result as $entry ) { $args['choices'][$entry->ID] = $entry->post_title; } } parent::__construct( $manager, $id, $args ); } } /** * Dropdown filled with post types. * Arg Options: desc, label * * @author Dan Suleski * @since 2.0 */ class cz_drop_post_types_ctl extends cz_drop_ctl { /** * Constructor. Reusing the regular dropdown control and just sending in * values with which to populate the options - the rendering is the same * * @param WP_Customize_Manager $manager * @param string $id * @param array $args */ public function __construct( $manager, $id, $args = array() ) { $args['choices'] = get_post_types(); parent::__construct( $manager, $id, $args ); } } /** * Dropdown filled with tags. * Arg Options: desc, label AND any of the arguments listed here: * http://codex.wordpress.org/Template_Tags/get_posts * * @author Dan Suleski * @since 2.0 */ class cz_drop_tags_ctl extends cz_drop_ctl { /** * Constructor. Reusing the regular dropdown control and just sending in * values with which to populate the options - the rendering is the same * * @param WP_Customize_Manager $manager * @param string $id * @param array $args */ public function __construct( $manager, $id, $args = array() ) { $query_args = array( 'orderby' => isset( $args['orderby'] ) ? $args['orderby'] : 'name', 'order' => isset( $args['order'] ) ? $args['order'] : 'ASC', 'hide_empty' => isset( $args['hide_empty'] ) ? $args['hide_empty'] : 0, 'exclude' => isset( $args['exclude'] ) ? $args['exclude'] : '', 'include' => isset( $args['include'] ) ? $args['include'] : '', 'number' => isset( $args['number'] ) ? $args['number'] : '', 'offset ' => isset( $args['offset '] ) ? $args['offset '] : 0, 'fields' => isset( $args['fields'] ) ? $args['fields'] : 'all', 'slug' => isset( $args['slug'] ) ? $args['slug'] : '', 'hierarchical' => isset( $args['hierarchical'] ) ? $args['hierarchical'] : 0, 'search' => isset( $args['search'] ) ? $args['search'] : '', 'name__like' => isset( $args['name__like'] ) ? $args['name__like'] : '', 'pad_counts' => isset( $args['pad_counts'] ) ? $args['pad_counts'] : false, 'get' => isset( $args['get'] ) ? $args['get'] : '', 'child_of' => isset( $args['child_of'] ) ? $args['child_of'] : 0, 'parent' => isset( $args['parent'] ) ? $args['parent'] : '' ); $query_result = get_tags( $query_args ); $args['choices'] = array(); if ( !is_wp_error( $query_result ) && ( !empty( $query_result ) ) ) { foreach( $query_result as $entry ) { $args['choices'][$entry->term_id] = $entry->name; } } parent::__construct( $manager, $id, $args ); } } /** * Dropdown filled with taxonomies. * Arg Options: desc, label * * @author Dan Suleski * @since 2.0 */ class cz_drop_taxonomies_ctl extends cz_drop_ctl { /** * Constructor. Reusing the regular dropdown control and just sending in * values with which to populate the options - the rendering is the same * * @param WP_Customize_Manager $manager * @param string $id * @param array $args */ public function __construct( $manager, $id, $args = array() ) { $args['choices'] = get_taxonomies(); parent::__construct( $manager, $id, $args ); } } /** * Dropdown filled with taxonomy terms. * Arg Options: desc, label, taxonomies AND any of the arguments listed here: * http://codex.wordpress.org/Function_Reference/get_terms * * @author Dan Suleski * @since 2.0 */ class cz_drop_terms_ctl extends cz_drop_ctl { /** * Constructor. Reusing the regular dropdown control and just sending in * values with which to populate the options - the rendering is the same * * @param WP_Customize_Manager $manager * @param string $id * @param array $args */ public function __construct( $manager, $id, $args = array() ) { $tax_args = isset( $args['taxonomies'] ) ? $args['taxonomies'] : array(); $query_args = array( 'orderby' => isset( $args['orderby'] ) ? $args['orderby'] : 'name', 'order' => isset( $args['order'] ) ? $args['order'] : 'ASC', 'hide_empty' => isset( $args['hide_empty'] ) ? $args['hide_empty'] : 0, 'exclude' => isset( $args['exclude'] ) ? $args['exclude'] : array(), 'exclude_tree' => isset( $args['exclude_tree'] ) ? $args['exclude_tree'] : array(), 'include' => isset( $args['include'] ) ? $args['include'] : array(), 'number' => isset( $args['number'] ) ? $args['number'] : '', 'fields' => isset( $args['fields'] ) ? $args['fields'] : 'all', 'slug' => isset( $args['slug'] ) ? $args['slug'] : '', 'parent' => isset( $args['parent'] ) ? $args['parent'] : '', 'hierarchical' => isset( $args['hierarchical'] ) ? $args['hierarchical'] : true, 'child_of' => isset( $args['child_of'] ) ? $args['child_of'] : 0, 'get' => isset( $args['get'] ) ? $args['get'] : '', 'name__like' => isset( $args['name__like'] ) ? $args['name__like'] : '', 'pad_counts' => isset( $args['pad_counts'] ) ? $args['pad_counts'] : false, 'offset' => isset( $args['offset'] ) ? $args['offset'] : '', 'search' => isset( $args['search'] ) ? $args['search'] : '', 'cache_domain' => isset( $args['cache_domain'] ) ? $args['cache_domain'] : 'core' ); $query_result = get_terms( $tax_args, $query_args ); $args['choices'] = array(); if ( !is_wp_error( $query_result ) && ( !empty( $query_result ) ) ) { foreach( $query_result as $entry ) { $args['choices'][$entry->term_id] = $entry->name; } } parent::__construct( $manager, $id, $args ); } } /** * Dropdown filled with menus. * Arg Options: desc, label AND any of the arguments listed here: * http://codex.wordpress.org/Function_Reference/get_terms * * @author Dan Suleski * @since 2.0 */ class cz_drop_menus_ctl extends cz_drop_terms_ctl { /** * Constructor. Reusing the regular dropdown control and just sending in * values with which to populate the options - the rendering is the same * * @param WP_Customize_Manager $manager * @param string $id * @param array $args */ public function __construct( $manager, $id, $args = array() ) { $args['taxonomies'] = 'nav_menu'; parent::__construct( $manager, $id, $args ); } } /** * Dropdown filled with users. * Arg Options: desc, label AND any of the arguments listed here: * http://codex.wordpress.org/Function_Reference/get_users * * @author Dan Suleski * @since 2.0 */ class cz_drop_users_ctl extends cz_drop_ctl { /** * Constructor. Reusing the regular dropdown control and just sending in * values with which to populate the options - the rendering is the same * * @param WP_Customize_Manager $manager * @param string $id * @param array $args */ public function __construct( $manager, $id, $args = array() ) { $query_args = array( 'blog_id' => isset( $args['blog_id'] ) ? $args['blog_id'] : $GLOBALS['blog_id'], 'role' => isset( $args['role'] ) ? $args['role'] : '', 'meta_key' => isset( $args['meta_key'] ) ? $args['meta_key'] : '', 'meta_value' => isset( $args['meta_value'] ) ? $args['meta_value'] : '', 'meta_compare' => isset( $args['meta_compare'] ) ? $args['meta_compare'] : '', 'meta_query' => isset( $args['meta_query'] ) ? $args['meta_query'] : array(), 'include' => isset( $args['include'] ) ? $args['include'] : array(), 'exclude' => isset( $args['exclude'] ) ? $args['exclude'] : array(), 'orderby' => isset( $args['orderby'] ) ? $args['orderby'] : 'login', 'order' => isset( $args['order'] ) ? $args['order'] : 'ASC', 'offset' => isset( $args['offset'] ) ? $args['offset'] : '', 'search' => isset( $args['search'] ) ? $args['search'] : '', 'number' => isset( $args['number'] ) ? $args['number'] : '', 'count_total' => isset( $args['count_total'] ) ? $args['count_total'] : false, 'fields' => isset( $args['fields'] ) ? $args['fields'] : 'all', 'who' => isset( $args['who'] ) ? $args['who'] : '' ); $query_result = get_users( $query_args ); $args['choices'] = array(); if ( !is_wp_error( $query_result ) && ( !empty( $query_result ) ) ) { foreach( $query_result as $entry ) { $args['choices'][$entry->data->ID] = $entry->data->user_nicename; } } parent::__construct( $manager, $id, $args ); } } /** * Media library selector. This one is included because the image control that WP * provides only allows users to upload a file from their local drive - they are not * able to select an existing image already uploaded to their media library. * Arg Options: desc, label * * @author Dan Suleski * @link http://www.webmaster-source.com/2013/02/06/using-the-wordpress-3-5-media-uploader-in-your-plugin-or-theme/ * @since 2.0 */ class cz_media_library_ctl extends \WP_Customize_Control { use cz_supplement; /** * Queue up the scripts and styles necessary for the media library dialog. Note that * the last parameter to wp_enqueue_script forces the inclusion in the footer instead * of the head for faster loading. */ public function enqueue() { wp_enqueue_media(); } /** * Rewriting this function because the images do not display in a local setup. * Note: The base site URL is explicitly called out here (root) so that the * the JS can assign the value of the media without the fully-qualified * URL name; this is important to do because database migrations are * not possible with serialized arrays through SQL. The calling code * for this media is responsible for prepending the base site URL. */ public function render_content() { // The source for the image is put together from two parts - the home URL and the // relative path. Put together this name first, but leave it completely blank if // the second part (with the filename) is blank. The tag can show an ugly // placeholder graphic if only a partial filename is provided. $image_src = ''; $value = $this->value(); if ( !empty( $value ) ) { $image_src = home_url().$this->value(); } echo '
'. $this->get_label_description_markup(). ''. 'get_link().'/>'. ''.__( 'No image currently selected', 'ski' ).''. ''. '
'. ''. ''. '
'. $this->get_description_after_markup(). '
'; } } /** * Given a range of numbers and a step granularity, this control displays a slider * bar (not a slideshow, but an actual bar with a thumb button) that lets the user * choose a value between a given minimum and maximum. * Arg Options: desc, display, label, max, min, step * * @author Dan Suleski * @since 2.0 */ class cz_number_bar_ctl extends \WP_Customize_Control { use cz_supplement; /** * @var integer Minimum value for the slider. */ public $min = 0; /** * @var string Optional text to potentially display */ public $min_text = ''; /** * @var integer Maximum value for the slider. */ public $max = 100; /** * @var string Optional text to potentially display */ public $max_text = ''; /** * @var integer Amount to skip for each press on the bar, outside of the thumb. */ public $step = 1; /** * @var string Indicates which values should be displayed; can be 'value', 'range', 'none', or 'all' */ public $display = 'all'; /** * Queue up the scripts and styles necessary for the jQuery UI slider. Two notes: * 1. The last parameter to wp_enqueue_script forces the inclusion in the footer * instead of the head for faster loading. * 2. WP does not provide an already-registered jQuery UI stylesheet; as a result, * the popular method appears to be using the Google CDN. */ public function enqueue() { wp_enqueue_script( 'jquery-ui-slider' ); } /** * Displays a jQuery UI slider bar and optionally the current value and min/max values. */ public function render_content() { $display_value_class = ( ( $this->display == 'value' ) || ( $this->display == 'all' ) ) ? '' : 'hidden'; $display_range_class = ( ( $this->display == 'range' ) || ( $this->display == 'all' ) ) ? '' : 'hidden'; $min_text = empty( $this->min_text ) ? $this->min : $this->min_text; $max_text = empty( $this->max_text ) ? $this->max : $this->max_text; echo '
'. $this->get_label_description_markup(). 'get_link().'/>'. '
'. ''.$min_text.''. ''.$max_text.''. '
'.$this->value().'
'. $this->get_description_after_markup(). '
'; } } /** * Radio image. * Arg Options: choices, desc, label * * @author Dan Suleski * @since 2.0 */ class cz_radio_image_ctl extends \WP_Customize_Control { use cz_supplement; /** * @var integer Set to 1 or less to force images vertically; set to a super-high number to guarantee wrapping */ public $per_line = true; /** * Similar to what came with WP 3.8, but now with a description and images. */ public function render_content() { if ( empty( $this->choices ) ) { return; } $name = '_customize-radio-'.$this->id; echo '
'. $this->get_label_description_markup(); $i = 1; $this->per_line = max( 1, $this->per_line ); foreach ( $this->choices as $value => $url ) { echo ''; } echo $this->get_description_after_markup(). '
'; } } /** * Radio images for alignment. * Arg Options: desc, label * Values: tl, tc, tr, ml, mc, mr, bl, bc, br (t=top, m=middle, b=bottom, l=left, c=center, r=right) * * @author Dan Suleski * @since 2.0 */ class cz_radio_image_alignment_ctl extends cz_radio_image_ctl { /** * Constructor. If no alignments are passed in, initialize with all alignments. * * @param WP_Customize_Manager $manager * @param string $id * @param array $args */ public function __construct( $manager, $id, $args = array() ) { if ( !isset( $args['alignments'] ) ) $args['alignments'] = array( 'tl', 'tc', 'tr', 'ml', 'mc', 'mr', 'bl', 'bc', 'br' ); $args['per_line'] = 3; foreach ( $args['alignments'] as $alignment ) { $args['choices'][$alignment] = path::get_ski_directory_uri().'/assets/customizer/align-'.$alignment.'.png'; } parent::__construct( $manager, $id, $args ); } } /** * Radio images for horizontal alignment. * Arg Options: desc, label * Values: ml, mc, mr (l=left, c=center, r=right) * * @author Dan Suleski * @since 2.0 */ class cz_radio_image_align_x_ctl extends cz_radio_image_ctl { /** * Converts the symbolic value of the alignment to english words that can be used in CSS. * @param type $symbol A symbol like 'ml', 'mc', or 'mr' * @return string The desired word like 'left', 'center', or 'right' */ static public function convert_symbol( $symbol ) { switch ( $symbol ) { case 'tl': case 'ml': case 'bl': return 'left'; case 'tr': case 'mr': case 'br': return 'right'; } return 'center'; } /** * Constructor. If no alignments are passed in, initialize with all alignments. * * @param WP_Customize_Manager $manager * @param string $id * @param array $args */ public function __construct( $manager, $id, $args = array() ) { if ( !isset( $args['alignments'] ) ) $args['alignments'] = array( 'ml', 'mc', 'mr' ); $args['per_line'] = 3; foreach ( $args['alignments'] as $alignment ) { $args['choices'][$alignment] = path::get_ski_directory_uri().'/assets/customizer/align-'.$alignment.'.png'; } parent::__construct( $manager, $id, $args ); } } /** * Radio images for vertical alignment. * Arg Options: desc, label * Values: tc, mc, bc (t=top, m=middle, b=bottom) * * @author Dan Suleski * @since 2.0 */ class cz_radio_image_align_y_ctl extends cz_radio_image_ctl { /** * Converts the symbolic value of the alignment to english words that can be used in CSS. * @param type $symbol A symbol like 'tc', 'mc', or 'bc' * @return string The desired word like 'top', 'center', or 'bottom' */ static public function convert_symbol( $symbol ) { switch ( $symbol ) { case 'tl': case 'tc': case 'tr': return 'top'; case 'bl': case 'bc': case 'br': return 'bottom'; } return 'center'; // Note the use of 'center' instead of 'middle' } /** * Constructor. If no alignments are passed in, initialize with all alignments. * * @param WP_Customize_Manager $manager * @param string $id * @param array $args */ public function __construct( $manager, $id, $args = array() ) { if ( !isset( $args['alignments'] ) ) $args['alignments'] = array( 'tc', 'mc', 'bc' ); $args['per_line'] = 3; foreach ( $args['alignments'] as $alignment ) { $args['choices'][$alignment] = path::get_ski_directory_uri().'/assets/customizer/align-'.$alignment.'.png'; } parent::__construct( $manager, $id, $args ); } } /** * Radio_images for sidebar layout. * Arg Options: desc, label * Values: 0, l1, l2, l1r1, r2, r1 * * @author Dan Suleski * @since 2.0 */ class cz_radio_image_sidebar_layout_ctl extends cz_radio_image_ctl { /** * Constructor. If no layouts are passed in, initialize with all sidebar layouts. * * @param WP_Customize_Manager $manager * @param string $id * @param array $args */ public function __construct( $manager, $id, $args = array() ) { if ( !isset( $args['layouts'] ) ) $args['layouts'] = array( '0', 'l1', 'l2', 'l1r1', 'r2', 'r1' ); $args['per_line'] = 99; foreach ( $args['layouts'] as $layout ) { $args['choices'][$layout] = path::get_ski_directory_uri().'/assets/customizer/sidebar-'.$layout.'.png'; } parent::__construct( $manager, $id, $args ); } } /** * Radio images for site span layout. * Arg Options: desc, label * Values: bleed-wide, bleed-narrow, boxed-narrow * * @author Dan Suleski * @since 2.0 */ class cz_radio_image_site_span_layout_ctl extends cz_radio_image_ctl { /** * Constructor. If no layouts are passed in, initialize with all site span layouts. * * @param WP_Customize_Manager $manager * @param string $id * @param array $args */ public function __construct( $manager, $id, $args = array() ) { if ( !isset( $args['layouts'] ) ) $args['layouts'] = array( 'bleed-wide', 'bleed-narrow', 'boxed-narrow' ); $args['per_line'] = 99; foreach ( $args['layouts'] as $layout ) { $args['choices'][$layout] = path::get_ski_directory_uri().'/assets/customizer/span-'.$layout.'.png'; } parent::__construct( $manager, $id, $args ); } } /** * Radio text. * Arg Options: choices, desc, label * * @author Dan Suleski * @since 2.0 */ class cz_radio_text_ctl extends \WP_Customize_Control { use cz_supplement; /** * Similar to what came with WP 3.8, but now with a description. */ public function render_content() { if ( empty( $this->choices ) ) { return; } $name = '_customize-radio-'.$this->id; echo '
'. $this->get_label_description_markup(); foreach ( $this->choices as $value => $label ) { echo ''; } echo $this->get_description_after_markup(). '
'; } } /** * Text area. * Arg Options: desc, label, placeholder * * @author Dan Suleski * @link http://ottopress.com/2012/making-a-custom-control-for-the-theme-customizer/ * @since 2.0 */ class cz_text_area_ctl extends \WP_Customize_Control { use cz_supplement; /** * @var integer Determines the height of the textarea element. */ public $rows = 5; /** * @var string Typically shows up as gray text in the control until the user clicks or starts typing. */ public $placeholder = ''; /** * Custom render. */ public function render_content() { echo '
'. $this->get_label_description_markup(). ''. $this->get_description_after_markup(). '
'; } } /** * Textbox. * Arg Options: desc, label, placeholder * * @author Dan Suleski * @since 2.0 */ class cz_textbox_ctl extends \WP_Customize_Control { use cz_supplement; /** * @var string Typically shows up as gray text in the control until the user clicks or starts typing. */ public $placeholder = ''; /** * Similar to what came with WP 3.8, but now with a description. */ public function render_content() { echo '
'. $this->get_label_description_markup(). 'get_link().'/>'. $this->get_description_after_markup(). '
'; } } /** * From your theme, hook into this function like so: * if ( defined( 'WP_DEBUG' ) ) add_action( 'customize_register', 'ski\customize_register_section' ); * * This function will add a new section to your Theme Customizer with examples of each control. Note that doing * this and clicking "Save & Publish" will append these bogus settings to your database. */ function customize_register_section( $wp_customize ) { /** * SECTION: Ski.Web Constrol Tests */ $wp_customize->add_section( 'ski_cz_section_test', array( 'title' => __( 'Ski.Web Control Tests', 'ski' ), 'description' => __( 'Demonstrates each Ski.Web control that can be used in this Customizer.', 'ski' ), 'priority' => 99999 )); // Checkbox $wp_customize->add_setting( 'ski_opt_checkbox', array( 'default' => 0, 'sanitize_callback' => array( '\ski\sanitize', 'none' ) ) ); $wp_customize->add_control( new cz_checkbox_ctl( $wp_customize, 'ski_opt_checkbox', array( 'label' => __( 'checkbox_ctl', 'ski' ), 'desc' => __( 'Select on/off', 'ski' ), 'option_text' => __( 'Yes?', 'ski' ), 'section' => 'ski_cz_section_test', 'priority' => 1000 ))); // Color palette $wp_customize->add_setting( 'ski_opt_color_palette', array( 'default' => '', 'sanitize_callback' => array( '\ski\sanitize', 'none' ) ) ); $wp_customize->add_control( new cz_color_palette_ctl( $wp_customize, 'ski_opt_color_palette', array( 'label' => __( 'color_palette_ctl', 'ski' ), 'desc' => __( 'Select any hex color', 'ski' ), 'section' => 'ski_cz_section_test', 'priority' => 2000 ))); // Date picker $wp_customize->add_setting( 'ski_opt_date_picker', array( 'default' => date( 'Y-m-d' ), 'sanitize_callback' => array( '\ski\sanitize', 'none' ) ) ); $wp_customize->add_control( new cz_date_picker_ctl( $wp_customize, 'ski_opt_date_picker', array( 'label' => __( 'date_picker_ctl', 'ski' ), 'desc' => __( 'Select a date', 'ski' ), 'section' => 'ski_cz_section_test', 'priority' => 3000 ))); // Detail $wp_customize->add_control( new cz_detail_ctl( $wp_customize, '', array( 'label' => __( 'detail_ctl', 'ski' ), 'desc' => __( 'Args: \'label\' is the boldfaced line; \'desc\' is this line', 'ski' ), 'desc_after' => __( 'And this is a \'desc_after\' line - it comes after the main control', 'ski' ), 'section' => 'ski_cz_section_test', 'priority' => 4000 ))); // Divider 1 $wp_customize->add_control( new cz_detail_ctl( $wp_customize, '', array( 'label' => __( 'divider_1_ctl', 'ski' ), 'section' => 'ski_cz_section_test', 'priority' => 4999 ))); $wp_customize->add_control( new cz_divider_1_ctl( $wp_customize, '', array( 'section' => 'ski_cz_section_test', 'priority' => 5000 ))); // Divider 2 $wp_customize->add_control( new cz_detail_ctl( $wp_customize, '', array( 'label' => __( 'divider_2_ctl', 'ski' ), 'section' => 'ski_cz_section_test', 'priority' => 5999 ))); $wp_customize->add_control( new cz_divider_2_ctl( $wp_customize, '', array( 'section' => 'ski_cz_section_test', 'priority' => 6000 ))); // Dropdown $wp_customize->add_setting( 'ski_opt_dropdown', array( 'default' => '', 'sanitize_callback' => array( '\ski\sanitize', 'none' ) ) ); $wp_customize->add_control( new cz_drop_ctl( $wp_customize, 'ski_opt_dropdown', array( 'label' => __( 'drop_ctl', 'ski' ), 'desc' => __( 'Select an item from a list you populate', 'ski' ), 'choices' => array( '1' => 'first', '2' => 'second', '3' => 'third' ), 'section' => 'ski_cz_section_test', 'priority' => 7000 ))); // Dropdown categories $wp_customize->add_setting( 'ski_opt_drop_categories', array( 'default' => '', 'sanitize_callback' => array( '\ski\sanitize', 'none' ) ) ); $wp_customize->add_control( new cz_drop_categories_ctl( $wp_customize, 'ski_opt_drop_categories', array( 'label' => __( 'drop_categories_ctl', 'ski' ), 'desc' => __( 'Select a category', 'ski' ), 'section' => 'ski_cz_section_test', 'priority' => 8000 ))); // Dropdown image sizes $wp_customize->add_setting( 'ski_opt_drop_image_sizes', array( 'default' => '', 'sanitize_callback' => array( '\ski\sanitize', 'none' ) ) ); $wp_customize->add_control( new cz_drop_image_sizes_ctl( $wp_customize, 'ski_opt_drop_image_sizes', array( 'label' => __( 'drop_image_sizes_ctl', 'ski' ), 'desc' => __( 'Select an image size', 'ski' ), 'dimensions' => true, 'section' => 'ski_cz_section_test', 'priority' => 9000 ))); // Dropdown menus $wp_customize->add_setting( 'ski_opt_drop_menus', array( 'default' => '', 'sanitize_callback' => array( '\ski\sanitize', 'none' ) ) ); $wp_customize->add_control( new cz_drop_menus_ctl( $wp_customize, 'ski_opt_drop_menus', array( 'label' => __( 'drop_menus_ctl', 'ski' ), 'desc' => __( 'Select a menu', 'ski' ), 'section' => 'ski_cz_section_test', 'priority' => 10000 ))); // Dropdown menu items $wp_customize->add_setting( 'ski_opt_drop_menu_items', array( 'default' => '', 'sanitize_callback' => array( '\ski\sanitize', 'none' ) ) ); $wp_customize->add_control( new cz_drop_menu_items_ctl( $wp_customize, 'ski_opt_drop_menu_items', array( 'label' => __( 'drop_menu_items_ctl', 'ski' ), 'desc' => __( 'Select an item within a specified menu', 'ski' ), 'menu' => 'Main', 'section' => 'ski_cz_section_test', 'priority' => 11000 ))); // Dropdown pages $wp_customize->add_setting( 'ski_opt_drop_pages', array( 'default' => '', 'sanitize_callback' => array( '\ski\sanitize', 'none' ) ) ); $wp_customize->add_control( new cz_drop_pages_ctl( $wp_customize, 'ski_opt_drop_pages', array( 'label' => __( 'drop_pages_ctl', 'ski' ), 'desc' => __( 'Select a page', 'ski' ), 'section' => 'ski_cz_section_test', 'priority' => 12000 ))); // Dropdown posts $wp_customize->add_setting( 'ski_opt_drop_posts', array( 'default' => '', 'sanitize_callback' => array( '\ski\sanitize', 'none' ) ) ); $wp_customize->add_control( new cz_drop_posts_ctl( $wp_customize, 'ski_opt_drop_posts', array( 'label' => __( 'drop_posts_ctl', 'ski' ), 'desc' => __( 'Select a post', 'ski' ), 'section' => 'ski_cz_section_test', 'priority' => 13000 ))); // Dropdown post types $wp_customize->add_setting( 'ski_opt_drop_post_types', array( 'default' => '', 'sanitize_callback' => array( '\ski\sanitize', 'none' ) ) ); $wp_customize->add_control( new cz_drop_post_types_ctl( $wp_customize, 'ski_opt_drop_post_types', array( 'label' => __( 'drop_post_types_ctl', 'ski' ), 'desc' => __( 'Select a post type', 'ski' ), 'section' => 'ski_cz_section_test', 'priority' => 14000 ))); // Dropdown tags $wp_customize->add_setting( 'ski_opt_drop_tags', array( 'default' => '', 'sanitize_callback' => array( '\ski\sanitize', 'none' ) ) ); $wp_customize->add_control( new cz_drop_tags_ctl( $wp_customize, 'ski_opt_drop_tags', array( 'label' => __( 'drop_tags_ctl', 'ski' ), 'desc' => __( 'Select a tag', 'ski' ), 'section' => 'ski_cz_section_test', 'priority' => 15000 ))); // Dropdown taxonomies $wp_customize->add_setting( 'ski_opt_drop_taxonomies', array( 'default' => '', 'sanitize_callback' => array( '\ski\sanitize', 'none' ) ) ); $wp_customize->add_control( new cz_drop_taxonomies_ctl( $wp_customize, 'ski_opt_drop_taxonomies', array( 'label' => __( 'drop_taxonomies_ctl', 'ski' ), 'desc' => __( 'Select a taxonomy', 'ski' ), 'section' => 'ski_cz_section_test', 'priority' => 16000 ))); // Dropdown terms $wp_customize->add_setting( 'ski_opt_drop_terms', array( 'default' => '', 'sanitize_callback' => array( '\ski\sanitize', 'none' ) ) ); $wp_customize->add_control( new cz_drop_terms_ctl( $wp_customize, 'ski_opt_drop_terms', array( 'label' => __( 'drop_terms_ctl', 'ski' ), 'desc' => __( 'Select a term within a specified taxonomy', 'ski' ), 'taxonomies' => array( 'category' ), 'section' => 'ski_cz_section_test', 'priority' => 17000 ))); // Dropdown users $wp_customize->add_setting( 'ski_opt_drop_users', array( 'default' => '', 'sanitize_callback' => array( '\ski\sanitize', 'none' ) ) ); $wp_customize->add_control( new cz_drop_users_ctl( $wp_customize, 'ski_opt_drop_users', array( 'label' => __( 'drop_users_ctl', 'ski' ), 'desc' => __( 'Select a user', 'ski' ), 'section' => 'ski_cz_section_test', 'priority' => 18000 ))); // Media library $wp_customize->add_setting( 'ski_opt_media_library', array( 'default' => '', 'sanitize_callback' => array( '\ski\sanitize', 'none' ) ) ); $wp_customize->add_control( new cz_media_library_ctl( $wp_customize, 'ski_opt_media_library', array( 'label' => __( 'media_library_ctl', 'ski' ), 'desc' => __( 'Upload and/or select an asset from the Media Library', 'ski' ), 'section' => 'ski_cz_section_test', 'priority' => 19000 ))); // Number bar $wp_customize->add_setting( 'ski_opt_number_bar', array( 'default' => 0, 'sanitize_callback' => array( '\ski\sanitize', 'none' ) ) ); $wp_customize->add_control( new cz_number_bar_ctl( $wp_customize, 'ski_opt_number_bar', array( 'label' => __( 'number_bar_ctl', 'ski' ), 'desc' => __( 'Select a number in a specified range', 'ski' ), 'display' => 'all', 'min' => 10, 'max' => 30, 'step' => 2, 'section' => 'ski_cz_section_test', 'priority' => 20000 ))); // Radio image $wp_customize->add_setting( 'ski_opt_radio_image', array( 'default' => '', 'sanitize_callback' => array( '\ski\sanitize', 'none' ) ) ); $wp_customize->add_control( new cz_radio_image_ctl( $wp_customize, 'ski_opt_radio_image', array( 'label' => __( 'radio_image_ctl', 'ski' ), 'desc' => __( 'Select an image from a list you populate', 'ski' ), 'choices' => array( '4' => path::get_ski_directory_uri().'/assets/customizer/logo-1.png', '5' => path::get_ski_directory_uri().'/assets/customizer/logo-2.png', '6' => path::get_ski_directory_uri().'/assets/customizer/logo-3.png' ), 'section' => 'ski_cz_section_test', 'priority' => 21000 ))); // Radio image alignment $wp_customize->add_setting( 'ski_opt_radio_image_alignment', array( 'default' => 'mc', 'sanitize_callback' => array( '\ski\sanitize', 'none' ) ) ); $wp_customize->add_control( new cz_radio_image_alignment_ctl( $wp_customize, 'ski_opt_radio_image_alignment', array( 'label' => __( 'radio_image_alignment_ctl', 'ski' ), 'desc' => __( 'Select an alignment in any direction', 'ski' ), 'section' => 'ski_cz_section_test', 'priority' => 22000 ))); // Radio image alignment horizontal $wp_customize->add_setting( 'ski_opt_radio_image_align_x', array( 'default' => 'mc', 'sanitize_callback' => array( '\ski\sanitize', 'none' ) ) ); $wp_customize->add_control( new cz_radio_image_align_x_ctl( $wp_customize, 'ski_opt_radio_image_align_x', array( 'label' => __( 'radio_image_align_x_ctl', 'ski' ), 'desc' => __( 'Select an alignment, typically for text', 'ski' ), 'section' => 'ski_cz_section_test', 'priority' => 23000 ))); // Radio image alignment vertical $wp_customize->add_setting( 'ski_opt_radio_image_align_y', array( 'default' => 'mc', 'sanitize_callback' => array( '\ski\sanitize', 'none' ) ) ); $wp_customize->add_control( new cz_radio_image_align_y_ctl( $wp_customize, 'ski_opt_radio_image_align_y', array( 'label' => __( 'radio_image_align_y_ctl', 'ski' ), 'desc' => __( 'Select an alignment, typically for backgrounds', 'ski' ), 'section' => 'ski_cz_section_test', 'priority' => 24000 ))); // Radio image sidebar layout $wp_customize->add_setting( 'ski_opt_radio_image_sidebar_layout', array( 'default' => '0', 'sanitize_callback' => array( '\ski\sanitize', 'none' ) ) ); $wp_customize->add_control( new cz_radio_image_sidebar_layout_ctl( $wp_customize, 'ski_opt_radio_image_sidebar_layout', array( 'label' => __( 'radio_image_sidebar_layout_ctl', 'ski' ), 'desc' => __( 'Select a layout for sidebars', 'ski' ), 'section' => 'ski_cz_section_test', 'priority' => 25000 ))); // Radio image site format $wp_customize->add_setting( 'ski_opt_radio_image_site_span_layout', array( 'default' => 'bleed-narrow', 'sanitize_callback' => array( '\ski\sanitize', 'none' ) ) ); $wp_customize->add_control( new cz_radio_image_site_span_layout_ctl( $wp_customize, 'ski_opt_radio_image_site_span_layout', array( 'label' => __( 'radio_image_site_span_layout_ctl', 'ski' ), 'desc' => __( 'Select a layout for the site', 'ski' ), 'section' => 'ski_cz_section_test', 'priority' => 26000 ))); // Radio text $wp_customize->add_setting( 'ski_opt_radio_text', array( 'default' => '', 'sanitize_callback' => array( '\ski\sanitize', 'none' ) ) ); $wp_customize->add_control( new cz_radio_text_ctl( $wp_customize, 'ski_opt_radio_text', array( 'label' => __( 'radio_text_ctl', 'ski' ), 'desc' => __( 'Select an item from a fully-seen list that you populate', 'ski' ), 'choices' => array( '1' => 'first', '2' => 'second', '3' => 'third' ), 'section' => 'ski_cz_section_test', 'priority' => 27000 ))); // Text area $wp_customize->add_setting( 'ski_opt_text_area', array( 'default' => '', 'sanitize_callback' => array( '\ski\sanitize', 'none' ) ) ); $wp_customize->add_control( new cz_text_area_ctl( $wp_customize, 'ski_opt_text_area', array( 'label' => __( 'text_area_ctl', 'ski' ), 'desc' => __( 'Accept a paragraph of text', 'ski' ), 'placeholder' => __( 'This is placeholder text', 'ski' ), 'section' => 'ski_cz_section_test', 'priority' => 28000 ))); // Textbox $wp_customize->add_setting( 'ski_opt_textbox', array( 'default' => '', 'sanitize_callback' => array( '\ski\sanitize', 'none' ) ) ); $wp_customize->add_control( new cz_textbox_ctl( $wp_customize, 'ski_opt_textbox', array( 'label' => __( 'textbox_ctl', 'ski' ), 'desc' => __( 'Accept a single line of text', 'ski' ), 'placeholder' => __( 'This is placeholder text', 'ski' ), 'section' => 'ski_cz_section_test', 'priority' => 29000 ))); } } ?>