From f0e1ae9a3ade2ceb5484990973d42f5269f4bdb1 Mon Sep 17 00:00:00 2001 From: Jami Gibbs Date: Thu, 14 May 2015 09:26:42 -0500 Subject: [PATCH 1/4] Fixes code wrap for dropdown example --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 8fa3589..ed046a6 100755 --- a/README.md +++ b/README.md @@ -146,6 +146,7 @@ $options['example-select'] = array( ### Drop Down Pages +~~~php $options['example-dropdown-pages'] = array( 'id' => 'example-dropdown-pages', 'label' => __( 'Example Drop Down Pages', 'textdomain' ), From 9de6c357261e5f78af98139c53d3e791440516e2 Mon Sep 17 00:00:00 2001 From: Jami Gibbs Date: Wed, 1 Jul 2015 10:04:44 -0500 Subject: [PATCH 2/4] Adding arbitrary text option --- README.md | 15 +++++++++++++++ custom-controls/help-text.php | 23 +++++++++++++++++++++++ customizer-library.php | 1 + extensions/interface.php | 19 ++++++++++++++++++- 4 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 custom-controls/help-text.php diff --git a/README.md b/README.md index ed046a6..0160657 100755 --- a/README.md +++ b/README.md @@ -35,6 +35,7 @@ The Customizer Library currently supports these options: * Text * URL * Range +* Arbitrary Text * Textarea * Select (Typography) @@ -254,6 +255,20 @@ $customizer_library = Customizer_Library::Instance(); $customizer_library->add_options( $options ); ~~~ +### Arbitary Text + +Adding arbitary text can be helpful for including additional instructions or notation for a control, panel, or section. + +~~~php +$options['example-arbitrary-text'] = array( + 'id' => 'example-arbitrary-text', + 'section' => $section, + 'label' => __( 'Text Label', 'demo' ), + 'type' => 'helptext', + 'description' => __( 'Example of more decription text', 'demo' ) +); +~~~ + ### Demo A full working example can be found here: diff --git a/custom-controls/help-text.php b/custom-controls/help-text.php new file mode 100644 index 0000000..0899ef1 --- /dev/null +++ b/custom-controls/help-text.php @@ -0,0 +1,23 @@ +' . esc_html( $this->label ) . ''; + echo '

' . $this->description . '

'; + echo '
'; + + } + +} \ No newline at end of file diff --git a/customizer-library.php b/customizer-library.php index 93fcaf0..b210a1b 100755 --- a/customizer-library.php +++ b/customizer-library.php @@ -37,6 +37,7 @@ if ( version_compare( $GLOBALS['wp_version'], '4.0', '<' ) ) { require plugin_dir_path( __FILE__ ) . 'custom-controls/textarea.php'; } + require plugin_dir_path( __FILE__ ) . 'custom-controls/help-text.php'; /** * Class wrapper with useful methods for interacting with the theme customizer. diff --git a/extensions/interface.php b/extensions/interface.php index 9b4763f..92b83be 100755 --- a/extensions/interface.php +++ b/extensions/interface.php @@ -155,6 +155,23 @@ function customizer_library_register( $wp_customize ) { break; + case 'helptext': + + $wp_customize->add_control( + new Customizer_Library_Help_Text( + $wp_customize, + $option['id'], array( + 'label' => $option['label'], + 'section' => $option['section'], + 'priority' => $option['priority'], + 'description' => $option['description'], + 'sanitize_callback' => $option['sanitize_callback'] + ) + ) + ); + + break; + } } } @@ -275,7 +292,7 @@ function customizer_library_get_sanitization( $type ) { return 'customizer_library_sanitize_file_url'; } - if ( 'text' == $type || 'textarea' == $type ) { + if ( 'text' == $type || 'textarea' == $type || 'helptext' == $type ) { return 'customizer_library_sanitize_text'; } From 2b0042ff853ee64dd0e2b6ee227db5e2a943627e Mon Sep 17 00:00:00 2001 From: Jami Gibbs Date: Wed, 1 Jul 2015 10:05:52 -0500 Subject: [PATCH 3/4] Moving position of arbitrary text settings example --- README.md | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 0160657..71288ce 100755 --- a/README.md +++ b/README.md @@ -243,18 +243,6 @@ $options['example-range'] = array( ); ~~~ -### Pass $options to Customizer Library - -After all the options and sections are defined, load them with the Customizer Library: - -~~~php -// Adds the sections to the $options array -$options['sections'] = $sections; - -$customizer_library = Customizer_Library::Instance(); -$customizer_library->add_options( $options ); -~~~ - ### Arbitary Text Adding arbitary text can be helpful for including additional instructions or notation for a control, panel, or section. @@ -269,6 +257,18 @@ $options['example-arbitrary-text'] = array( ); ~~~ +### Pass $options to Customizer Library + +After all the options and sections are defined, load them with the Customizer Library: + +~~~php +// Adds the sections to the $options array +$options['sections'] = $sections; + +$customizer_library = Customizer_Library::Instance(); +$customizer_library->add_options( $options ); +~~~ + ### Demo A full working example can be found here: From 825805cbf9fd1a32abefa6edc420716892272ae9 Mon Sep 17 00:00:00 2001 From: Jami Gibbs Date: Wed, 1 Jul 2015 10:34:48 -0500 Subject: [PATCH 4/4] Adding radio images option --- README.md | 30 +++++++++++++ custom-controls/radio-image.php | 80 +++++++++++++++++++++++++++++++++ customizer-library.php | 1 + extensions/interface.php | 26 +++++++++-- 4 files changed, 134 insertions(+), 3 deletions(-) create mode 100644 custom-controls/radio-image.php diff --git a/README.md b/README.md index 71288ce..5d90669 100755 --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ The Customizer Library currently supports these options: * Checkbox * Select * Radio +* Radio Images * Upload * Image * Color @@ -176,6 +177,35 @@ $options['example-radio'] = array( ); ~~~ +### Radio Images + +The radio images will need to be placed in the theme's images folder or adjut the image path accordingly. + +~~~php + +$imagepath = get_template_directory_uri() . '/img/'; + +$image_choices = array( + 'choice-1' => array( + 'url' => $imagepath .'example-1.png', + 'label' => 'Left' + ), + 'choice-2' => array( + 'url' => $imagepath .'example-2.png', + 'label' => 'Right' + ), +); + +$options['example-radio-images'] = array( + 'id' => 'example-radio-images', + 'label' => __( 'Example Radio Images', 'demo' ), + 'section' => $section, + 'type' => 'radio-image', + 'choices' => $image_choices, + 'default' => 'choice-2' +); +~~~ + ### Upload ~~~php diff --git a/custom-controls/radio-image.php b/custom-controls/radio-image.php new file mode 100644 index 0000000..6d2f754 --- /dev/null +++ b/custom-controls/radio-image.php @@ -0,0 +1,80 @@ +choices ) ) + return; ?> + + label ) ) : ?> + label ); ?> + + + description ) ) : ?> + description; ?> + + +
id}" ); ?>"> + + choices as $value => $args ) : ?> + + id}" ); ?>" id="id}-{$value}" ); ?>" link(); ?> value(), $value ); ?> /> + + + + + +
+ + + + + + add_control( + new Customizer_Library_Control_Radio_Image( + $wp_customize, + $option['id'], array( + 'label' => $option['label'], + 'section' => $option['section'], + 'priority' => $option['priority'], + 'description' => $option['description'], + 'sanitize_callback' => $option['sanitize_callback'], + 'choices' => $option['choices'] + ) + ) + ); + + break; + } } } @@ -245,7 +263,8 @@ function customizer_library_add_setting( $option, $wp_customize ) { 'theme_supports' => NULL, 'transport' => NULL, 'sanitize_callback' => 'wp_kses_post', - 'sanitize_js_callback' => NULL + 'sanitize_js_callback' => NULL, + 'choices' => NULL ); // Settings defaults @@ -259,7 +278,8 @@ function customizer_library_add_setting( $option, $wp_customize ) { 'theme_supports' => $settings['theme_supports'], 'transport' => $settings['transport'], 'sanitize_callback' => $settings['sanitize_callback'], - 'sanitize_js_callback' => $settings['sanitize_js_callback'] + 'sanitize_js_callback' => $settings['sanitize_js_callback'], + 'choices' => $settings['choices'] ) ); @@ -276,7 +296,7 @@ function customizer_library_add_setting( $option, $wp_customize ) { */ function customizer_library_get_sanitization( $type ) { - if ( 'select' == $type || 'radio' == $type ) { + if ( 'select' == $type || 'radio' == $type || 'radio-image' == $type ) { return 'customizer_library_sanitize_choices'; }