Skip to content
This repository has been archived by the owner on Dec 17, 2018. It is now read-only.

Commit

Permalink
Merge branch 'master' into trunk
Browse files Browse the repository at this point in the history
  • Loading branch information
JPry committed May 6, 2012
2 parents f21e666 + ac031c1 commit bd5888f
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions init.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/

/**
Expand Down Expand Up @@ -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__ ) ) ) ) );

Expand Down Expand Up @@ -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>';
Expand All @@ -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>';
Expand Down Expand Up @@ -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':
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit bd5888f

Please sign in to comment.