args = $args;
parent::__construct( $manager, $id, $args );
}
/**
* Renders the control wrapper and calls $this->render_content() for the internals.
*
* @since 1.7
* @return void
*/
protected function render() {
$id = 'customize-control-' . str_replace( array( '[', ']' ), array( '-', '' ), $this->id );
$class = 'customize-control customize-control-' . $this->type;
if ( isset( $this->args['classes'] ) ) {
$class .= ' ' . implode( ' ', $this->args['classes'] );
}
printf( '
', esc_attr( $id ), esc_attr( $class ) );
$this->render_content();
echo '';
}
/**
* Renders the content for a control based on the type
* of control specified when this class is initialized.
*
* @since 1.2.0
* @access protected
* @return void
*/
protected function render_content() {
switch ( $this->type ) {
case 'font':
$this->render_font();
break;
case 'font-weight':
$this->render_font_weight();
break;
case 'code':
$this->render_code();
break;
case 'line':
$this->render_line();
break;
case 'export-import':
$this->render_export_import();
break;
case 'slider':
$this->render_slider();
break;
case 'checkbox-multiple':
$this->render_checkbox_multiple();
break;
}
}
/**
* Renders the title and description for a control.
*
* @since 1.2.0
* @access protected
* @return void
*/
protected function render_content_title() {
if ( ! empty( $this->label ) ) {
echo '' . esc_html( $this->label ) . '';
}
if ( ! empty( $this->description ) ) {
echo '' . $this->description . '';
}
}
/**
* Renders the connect attribute for a connected control.
*
* @since 1.2.0
* @access protected
* @return void
*/
protected function render_connect_attribute() {
if ( $this->connect ) {
echo ' data-connected-control="' . $this->connect . '"';
}
}
/**
* Renders a font control.
*
* @since 1.2.0
* @access protected
* @return void
*/
protected function render_font() {
echo '';
}
/**
* Renders a font weight control.
*
* @since 1.2.0
* @access protected
* @return void
*/
protected function render_font_weight() {
echo '';
}
/**
* Renders a code control.
*
* @since 1.2.0
* @access protected
* @return void
*/
protected function render_code() {
$this->render_content_title();
if ( $this->preview_button ) {
echo '';
}
echo '';
}
/**
* Renders a line break control.
*
* @since 1.2.0
* @access protected
* @return void
*/
protected function render_line() {
echo '
';
}
/**
* Renders the export/import control.
*
* @since 1.2.0
* @access protected
* @return void
*/
protected function render_export_import() {
$plugin = 'customizer-export-import';
$nonce = wp_create_nonce( 'install-plugin_' . $plugin );
$url = admin_url( 'update.php?action=install-plugin&plugin=' . $plugin . '&_wpnonce=' . $nonce );
echo '' . __( 'Please install and activate the "Customizer Export/Import" plugin to proceed.', '1io' ) . '
';
echo '' . _x( 'Install & Activate', '...a plugin.', '1io' ) . '';
}
/**
* Renders the slider control.
*
* @since 1.5.0
* @access protected
* @return void
*/
protected function render_slider() {
$this->choices['min'] = ( isset( $this->choices['min'] ) ) ? $this->choices['min'] : '0';
$this->choices['max'] = ( isset( $this->choices['max'] ) ) ? $this->choices['max'] : '100';
$this->choices['step'] = ( isset( $this->choices['step'] ) ) ? $this->choices['step'] : '1';
echo '';
}
/**
* Renders multiple checkbox markup
*
* @since 1.5.3
* @access protected
* @return void
*/
protected function render_checkbox_multiple() {
if ( empty( $this->choices ) ) {
return;
}
$this->render_content_title();
$multi_values = ! is_array( $this->value() ) ? explode( ',', $this->value() ) : $this->value();
if ( isset( $this->choices['custom'] ) && 'post_types' == $this->choices['custom'] ) {
$choices = $this->get_checkbox_choices_post_types();
// Set all post types as default.
if ( 'all' == $this->value() ) {
$multi_values = array_keys( $choices );
}
} else {
$choices = $this->choices;
}
if ( count( $choices ) > 0 ) {
echo '';
}
if ( is_array( $multi_values ) ) {
echo 'get_link() . ' value="' . esc_attr( implode( ',', $multi_values ) ) . '" />';
}
}
/**
* Get post types for multiple checkbox choices
*
* @since 1.6.2
* @access protected
* @return array
*/
protected function get_checkbox_choices_post_types() {
$ptypes = array();
$post_types = get_post_types(array(
'public' => true,
), 'objects');
if ( $post_types ) {
foreach ( $post_types as $key => $post_type ) {
$ptypes[ $post_type->name ] = $post_type->label;
}
// Remove post_type `product` for woocommerce since we have separate sidebar control for WooCommerce
unset( $ptypes['product'] );
// Remove post type `page` since sidebar is set per page where default has no sidebar.
unset( $ptypes['page'] );
// Remove BB plugin templates
unset( $ptypes['fl-builder-template'] );
}
return $ptypes;
}
}