Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'master' into trunk

  • Loading branch information...
commit bd5888f44d2b227ac9eb918e15ea60e0d42b0f04 2 parents f21e666 + ac031c1
@JPry JPry authored
Showing with 15 additions and 5 deletions.
  1. +15 −5 init.php
View
20 init.php
@@ -5,7 +5,7 @@
Jared Atchison (@jaredatch / jaredatchison.com)
Bill Erickson (@billerickson / billerickson.net)
Description: This will create metaboxes with custom fields that will blow your mind.
-Version: 0.8
+Version: 0.9
*/
/**
@@ -55,7 +55,7 @@ function check_text( $text ) {
/**
* Defines the url to which is used to load local resources.
* This may need to be filtered for local Window installations.
- * If resources to not load, please check the wiki for details.
+ * If resources do not load, please check the wiki for details.
*/
define( 'CMB_META_BOX_URL', apply_filters( 'cmb_meta_box_url', trailingslashit( str_replace( WP_CONTENT_DIR, WP_CONTENT_URL, dirname( __FILE__ ) ) ) ) );
@@ -223,7 +223,13 @@ function show() {
echo '$ <input class="cmb_text_money" type="text" name="', $field['id'], '" id="', $field['id'], '" value="', '' !== $meta ? $meta : $field['std'], '" /><span class="cmb_metabox_description">', $field['desc'], '</span>';
break;
case 'colorpicker':
- echo '<input class="cmb_colorpicker cmb_text_small" type="text" name="', $field['id'], '" id="', $field['id'], '" value="', '' !== $meta ? $meta : $field['std'], '" /><span class="cmb_metabox_description">', $field['desc'], '</span>';
+ $meta = '' !== $meta ? $meta : $field['std'];
+ $hex_color = '(([a-fA-F0-9]){3}){1,2}$';
+ if ( preg_match( '/^' . $hex_color . '/i', $meta ) ) // Value is just 123abc, so prepend #.
+ $meta = '#' . $meta;
+ elseif ( ! preg_match( '/^#' . $hex_color . '/i', $meta ) ) // Value doesn't match #123abc, so sanitize to just #.
+ $meta = "#";
+ echo '<input class="cmb_colorpicker cmb_text_small" type="text" name="', $field['id'], '" id="', $field['id'], '" value="', $meta, '" /><span class="cmb_metabox_description">', $field['desc'], '</span>';
break;
case 'textarea':
echo '<textarea name="', $field['id'], '" id="', $field['id'], '" cols="60" rows="10">', '' !== $meta ? $meta : $field['std'], '</textarea>','<p class="cmb_metabox_description">', $field['desc'], '</p>';
@@ -235,6 +241,7 @@ function show() {
echo '<textarea name="', $field['id'], '" id="', $field['id'], '" cols="60" rows="10" class="cmb_textarea_code">', '' !== $meta ? $meta : $field['std'], '</textarea>','<p class="cmb_metabox_description">', $field['desc'], '</p>';
break;
case 'select':
+ if( empty( $meta ) && !empty( $field['std'] ) ) $meta = $field['std'];
echo '<select name="', $field['id'], '" id="', $field['id'], '">';
foreach ($field['options'] as $option) {
echo '<option value="', $option['value'], '"', $meta == $option['value'] ? ' selected="selected"' : '', '>', $option['name'], '</option>';
@@ -265,7 +272,7 @@ function show() {
echo '<p class="cmb_metabox_description">', $field['desc'], '</p>';
break;
case 'checkbox':
- echo '<input type="checkbox" name="', $field['id'], '" id="', $field['id'], '"', $meta ? ' checked="checked"' : '', ' />';
+ echo '<input type="checkbox" name="', $field['id'], '" id="', $field['id'], '"', checked( ( $meta == true || $field['std'] ), true, false ), ' />';
echo '<span class="cmb_metabox_description">', $field['desc'], '</span>';
break;
case 'multicheck':
@@ -409,7 +416,10 @@ function save( $post_id) {
foreach ( $this->_meta_box['fields'] as $field ) {
$name = $field['id'];
- if ( 'multicheck' == $field['type'] ? $field['multiple'] = true : $field['multiple'] = false );
+
+ if ( ! isset( $field['multiple'] ) )
+ $field['multiple'] = ( 'multicheck' == $field['type'] ) ? true : false;
+
$old = get_post_meta( $post_id, $name, !$field['multiple'] /* If multicheck this can be multiple values */ );
$new = isset( $_POST[$field['id']] ) ? $_POST[$field['id']] : null;
Please sign in to comment.
Something went wrong with that request. Please try again.