Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,35 @@ $options['example-content'] = array(
);
~~~

### Media

~~~php
$options['example-media'] = array(
'id' => 'example-media',
'label' => __( 'Image Media', 'textdomain' ),
'section' => $section,
'type' => 'media',
'default' => '',
'mime_type' => 'image'
);
~~~

### Crop

~~~php
$options['example-crop'] = array(
'id' => 'example-crop',
'label' => __( 'Custom Header', 'textdomain' ),
'section' => $section,
'type' => 'crop',
'default' => '',
'flex_width' => true,
'flex_height' => true,
'width' => 200,
'height' => 200
);
~~~

### Pass $options to Customizer Library

After all the options and sections are defined, load them with the Customizer Library:
Expand Down Expand Up @@ -363,6 +392,8 @@ Development
===

* Enhancement: Content option (for help text, HTML output, etc.)
* Bugfix: Encode `|` character to fix html5 validation error
* Introduce 2 new Customizer media controls `WP_Customize_Media_Control` and `WP_Customize_Cropped_Image_Control`

1.3.0
===
Expand Down Expand Up @@ -390,4 +421,4 @@ Development
1.0.0
===

* Public Release
* Public Release
4 changes: 2 additions & 2 deletions extensions/fonts.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function customizer_library_get_google_font_uri( $fonts ) {
if ( empty( $family ) ) {
return '';
} else {
$request = '//fonts.googleapis.com/css?family=' . implode( '|', $family );
$request = '//fonts.googleapis.com/css?family=' . implode( '%7C', $family );
}

// Load the font subset
Expand Down Expand Up @@ -7230,4 +7230,4 @@ function customizer_library_get_google_fonts() {
),
) );
}
endif;
endif;
68 changes: 67 additions & 1 deletion extensions/interface.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,31 @@ function customizer_library_register( $wp_customize ) {
$option['active_callback'] = '';
}

// Set default mime_type to image.
if ( ! isset( $option['mime_type'] ) ) {
$option['mime_type'] = 'image';
}

// Set default flex_width to true.
if ( ! isset( $option['flex_width'] ) ) {
$option['flex_width'] = true;
}

// Set default flex_height to true.
if ( ! isset( $option['flex_height'] ) ) {
$option['flex_height'] = true;
}

// Set blank width if one isn't set
if ( ! isset( $option['width'] ) ) {
$option['width'] = '';
}

// Set blank height if one isn't set
if ( ! isset( $option['height'] ) ) {
$option['height'] = '';
}

// Add the setting
customizer_library_add_setting( $option, $wp_customize );

Expand Down Expand Up @@ -132,6 +157,47 @@ function customizer_library_register( $wp_customize ) {

break;

case 'media':

$wp_customize->add_control(
new WP_Customize_Media_Control(
$wp_customize,
$option['id'], array(
'label' => $option['label'],
'section' => $option['section'],
'sanitize_callback' => $option['sanitize_callback'],
'priority' => $option['priority'],
'active_callback' => $option['active_callback'],
'description' => $option['description'],
'mime_type' => $option['mime_type']
)
)
);

break;

case 'crop':

$wp_customize->add_control(
new WP_Customize_Cropped_Image_Control(
$wp_customize,
$option['id'], array(
'label' => $option['label'],
'section' => $option['section'],
'sanitize_callback' => $option['sanitize_callback'],
'priority' => $option['priority'],
'active_callback' => $option['active_callback'],
'description' => $option['description'],
'flex_width' => $option['flex_width'],
'flex_height' => $option['flex_height'],
'width' => $option['width'],
'height' => $option['height'],
)
)
);

break;

case 'textarea':

// Custom control required before WordPress 4.0
Expand Down Expand Up @@ -300,7 +366,7 @@ function customizer_library_get_sanitization( $type ) {
return 'customizer_library_sanitize_range';
}

if ( 'dropdown-pages' == $type ) {
if ( 'dropdown-pages' == $type || 'media' == $type || 'crop' == $type ) {
return 'absint';
}

Expand Down