From afc2f80997387e8b39fc872129d8111f0827857c Mon Sep 17 00:00:00 2001 From: Al Candelario Date: Wed, 26 Aug 2015 13:40:47 -0500 Subject: [PATCH 1/9] added support for getting Media Library URL. if its an image, it'll show a preview, otherwise it'll show the media library URL --- library.php | 126 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) diff --git a/library.php b/library.php index 6891a6c..2c8df0c 100644 --- a/library.php +++ b/library.php @@ -312,4 +312,130 @@ function cap_serialize_export( $data ) { header( 'Content-disposition: attachment; filename=theme-export.txt' ); echo serialize( $data ); exit(); +} + +/** + * Adds support for selecting images + * from media library. + * + * + * + * Class MediaOption + */ +class MediaOption extends Option { + var $options; + + function MediaOption( $_name, $_desc, $_id, $_std = '' ) { + $this->Option( $_name, $_desc, $_id, $_std ); + } + + function WriteHtml() { + + /* Prereqs for loading the WP media-upload modal */ + wp_enqueue_script('jquery'); + wp_enqueue_script('media-upload'); + wp_enqueue_script('thickbox'); + wp_enqueue_style('thickbox'); + + /* Populate the default option or the saved one */ + $stdText = $this->std; + + $stdTextOption = get_option( $this->id ); + + if ( ! empty( $stdTextOption ) ) + $stdText = $stdTextOption; + ?> + + + name ); ?> + + + + + + + + desc ); ?>
+ + + + + id, $this->std ); + if ( strtolower( $value ) == 'disabled' ) + return false; + return $value; + } } \ No newline at end of file From 41d28584a0c4e772dc46a1675721245503e478ab Mon Sep 17 00:00:00 2001 From: Al Candelario Date: Wed, 26 Aug 2015 13:43:39 -0500 Subject: [PATCH 2/9] added example to config --- config.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/config.php b/config.php index e8a1e3f..34b5a39 100644 --- a/config.php +++ b/config.php @@ -19,6 +19,11 @@ function cap_get_options() { return array( new Group( 'First Group', 'firstGroup', array( + new MediaOption( + 'Choose default featured image if none is set', + '', + 'feat_image_default' + ), new BooleanOption( 'Simple Boolean Example', 'This will create a simple true/false switch with default of "true".', From 6ca41acc1b9de9f7d654095e59fcfefa3243fbd2 Mon Sep 17 00:00:00 2001 From: Al Candelario Date: Wed, 26 Aug 2015 13:48:19 -0500 Subject: [PATCH 3/9] updated readme --- README.txt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.txt b/README.txt index 8b7c6f8..3c7a534 100644 --- a/README.txt +++ b/README.txt @@ -77,6 +77,7 @@ are three types of Options available to create: 1. Boolean Option 2. Text Option 3. Dropdown Option + 4. MediaOption ## 1. Boolean Option The simplest form of option...creates a true or false dropdown that can be used to turn features on or off. @@ -112,6 +113,17 @@ Allows you to create a dropdown with custom values by passing the constructor an DefaultIndex = an integer identifying the item in the array that is the default value; if not specified, the default is 0. +## 2. Media Option +Allows you to open a media library modal and get the URL for an item. If it's an image, a preview will display + + new MediaOption(Name, Description, OptionID, Default ) + + Name = a human readable name for the option. + Description = a human readable description for the option. + OptionID = a machine readable option identifier, cannot have spaces and must be unique + Default = a string as the default value for the option; if not specified, the default is "" + + ## ## Usage ## From 79cf65016d3615dac4fbfff685e82c5ffa339c56 Mon Sep 17 00:00:00 2001 From: Al Candelario Date: Wed, 3 Feb 2016 22:25:30 -0600 Subject: [PATCH 4/9] added todo on media option. added support for multi-select option --- README.txt | 14 +- library.php | 365 +++++++++++++++++++++++++++++++--------------------- 2 files changed, 231 insertions(+), 148 deletions(-) diff --git a/README.txt b/README.txt index 3c7a534..50b9141 100644 --- a/README.txt +++ b/README.txt @@ -113,7 +113,7 @@ Allows you to create a dropdown with custom values by passing the constructor an DefaultIndex = an integer identifying the item in the array that is the default value; if not specified, the default is 0. -## 2. Media Option +## 4. Media Option Allows you to open a media library modal and get the URL for an item. If it's an image, a preview will display new MediaOption(Name, Description, OptionID, Default ) @@ -122,6 +122,18 @@ Allows you to open a media library modal and get the URL for an item. If it's an Description = a human readable description for the option. OptionID = a machine readable option identifier, cannot have spaces and must be unique Default = a string as the default value for the option; if not specified, the default is "" + +## 5. Multi Option +Allows you to create a multi-select input with custom values by passing the constructor an array of options. Saves the result as a serialized string. + + new MultiOption(Name, Description, OptionID, OptionsArray, DefaultIndex) + + Name = a human readable name for the option. + Description = a human readable description for the option. + OptionID = a machine readable option identifier, cannot have spaces and must be unique + OptionsArray = an array containing the values for the dropdown menu + DefaultIndex = an integer identifying the item in the array that is the default value; if not specified, + the default is 0. ## diff --git a/library.php b/library.php index 2c8df0c..86e5b8a 100644 --- a/library.php +++ b/library.php @@ -78,6 +78,205 @@ function get() { } } +/** + * Adds support for selecting images + * from media library. + * + * @todo Ability to complete clear the field + * + * Class MediaOption + */ +class MediaOption extends Option { + var $options; + + function MediaOption( $_name, $_desc, $_id, $_std = '' ) { + $this->Option( $_name, $_desc, $_id, $_std ); + } + + function WriteHtml() { + + /* Prereqs for loading the WP media-upload modal */ + wp_enqueue_script('jquery'); + wp_enqueue_script('media-upload'); + wp_enqueue_script('thickbox'); + wp_enqueue_style('thickbox'); + wp_enqueue_media(); + + /* Populate the default option or the saved one */ + $stdText = $this->std; + + $stdTextOption = get_option( $this->id ); + + if ( ! empty( $stdTextOption ) ) + $stdText = $stdTextOption; + ?> + + + name ); ?> + + + + + + + + desc ); ?>
+ + + + + id, $this->std ); + if ( strtolower( $value ) == 'disabled' ) + return false; + return $value; + } +} + +/** + * Adds support for multi-select box option. + * Saved as serialized string + * + */ +class MultiOption extends Option { + var $options; + var $delimter = '&&'; + + function MultiOption( $_name, $_desc, $_id, $_options, $_stdIndex = 0 ) { + $this->Option( $_name, $_desc, $_id, $_stdIndex ); + $this->options = $_options; + } + + function WriteHtml() { + $option = get_option( $this->id ); + $opts = explode( $this->delimter, $option ); ?> + + + name ); ?> + + + + + + + desc ); ?>
+ + + + + + + + + id, $this->std ); + if ( strtolower( $value ) == 'disabled' ) + return false; + return $value; + } +} + class TextOption extends Option { var $useTextArea; @@ -260,27 +459,25 @@ function top_level_settings() {
- -
- WriteHtml(); - ?> -
- + + +
+ WriteHtml(); ?> +
+ +
+

@@ -299,8 +496,8 @@ function top_level_settings() {

-

Preview (updated when options are saved)

- + + Option( $_name, $_desc, $_id, $_std ); - } - - function WriteHtml() { - - /* Prereqs for loading the WP media-upload modal */ - wp_enqueue_script('jquery'); - wp_enqueue_script('media-upload'); - wp_enqueue_script('thickbox'); - wp_enqueue_style('thickbox'); - - /* Populate the default option or the saved one */ - $stdText = $this->std; - - $stdTextOption = get_option( $this->id ); - - if ( ! empty( $stdTextOption ) ) - $stdText = $stdTextOption; - ?> - - - name ); ?> - - - - - - - - desc ); ?>
- - - - - id, $this->std ); - if ( strtolower( $value ) == 'disabled' ) - return false; - return $value; - } } \ No newline at end of file From 746dcbb051042c7f269daaadee89cb6139e1f282 Mon Sep 17 00:00:00 2001 From: Al Candelario Date: Fri, 18 Mar 2016 17:41:51 -0500 Subject: [PATCH 5/9] added delete to media option --- library.php | 54 ++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 49 insertions(+), 5 deletions(-) diff --git a/library.php b/library.php index 86e5b8a..300576b 100644 --- a/library.php +++ b/library.php @@ -111,13 +111,39 @@ function WriteHtml() { $stdText = $stdTextOption; ?> + + name ); ?> -