From 9313ec723f9d16bcc2ff31c1c6a85da8763ac4ce Mon Sep 17 00:00:00 2001 From: cramdesign Date: Wed, 28 Aug 2013 15:39:24 -0400 Subject: [PATCH 1/8] Changed field display and updated readme --- README.md | 14 +++---- dev7_meta_box_framework.php | 73 ++++++++++++++++++++++++++++++------- 2 files changed, 66 insertions(+), 21 deletions(-) mode change 100644 => 100755 README.md diff --git a/README.md b/README.md old mode 100644 new mode 100755 index d6f0e45..7704ca2 --- a/README.md +++ b/README.md @@ -20,21 +20,21 @@ function add_custom_meta_boxes() { 'fields' => array( array( 'id' => 'text', - 'title' => 'Text', + 'label' => 'Text', 'desc' => 'This is a description.', 'type' => 'text', 'std' => 'This is std' ), array( 'id' => 'textarea', - 'title' => 'Textarea', + 'label' => 'Textarea', 'desc' => 'This is a description.', 'type' => 'textarea', 'std' => 'This is std' ), array( 'id' => 'select', - 'title' => 'Select', + 'label' => 'Select', 'desc' => 'This is a description.', 'type' => 'select', 'std' => 'green', @@ -46,7 +46,7 @@ function add_custom_meta_boxes() { ), array( 'id' => 'radio', - 'title' => 'Radio', + 'label' => 'Radio', 'desc' => 'This is a description.', 'type' => 'radio', 'std' => 'green', @@ -58,14 +58,14 @@ function add_custom_meta_boxes() { ), array( 'id' => 'checkbox', - 'title' => 'Checkbox', + 'label' => 'Checkbox', 'desc' => 'This is a description.', 'type' => 'checkbox', 'std' => 1 ), array( 'id' => 'checkboxes', - 'title' => 'Checkboxes', + 'label' => 'Checkboxes', 'desc' => 'This is a description.', 'type' => 'checkboxes', 'std' => array( @@ -94,7 +94,7 @@ $my_field = get_post_meta(get_the_ID(), 'my_field_id', true); A field has the following structure: * `id` (required) - The ID of the field (must be unique) -* `title` - The title of the field +* `label` - The label of the field * `desc` - The field description * `type` (required) - The type of field (see list below) * `std` - The default value of the field diff --git a/dev7_meta_box_framework.php b/dev7_meta_box_framework.php index 1785a97..7e89ff8 100644 --- a/dev7_meta_box_framework.php +++ b/dev7_meta_box_framework.php @@ -4,8 +4,10 @@ * * @author Gilbert Pellegrom * @link https://github.com/Dev7studios/Dev7studios-Meta-Box-Framework - * @version 1.0 + * @version 1.0.1 * @license MIT + * @updates Matt Cram + * @link https://github.com/cramdesign/dev7_meta_box_framework */ if( !class_exists( 'Dev7_Meta_Box_Framework' ) ) { @@ -33,7 +35,7 @@ function add_meta_boxes() { foreach( $dev7_meta_boxes as $meta_box ){ if( is_array($meta_box['pages']) ){ foreach( $meta_box['pages'] as $page ){ - add_meta_box( $meta_box['id'], $meta_box['title'], array(&$this, 'meta_box_output'), $page, $meta_box['context'], $meta_box['priority'], array('dev7_meta_box' => $meta_box) ); + add_meta_box( $meta_box['id'].'_mb', $meta_box['title'], array(&$this, 'meta_box_output'), $page, $meta_box['context'], $meta_box['priority'], array('dev7_meta_box' => $meta_box) ); } } else { add_meta_box( $meta_box['id'], $meta_box['title'], array(&$this, 'meta_box_output'), $meta_box['pages'], $meta_box['context'], $meta_box['priority'], array('dev7_meta_box' => $meta_box) ); @@ -88,6 +90,44 @@ function meta_box_output( $post, $args ) { foreach( $dev7_meta_boxes as $meta_box ){ if( isset($args['args']['dev7_meta_box']['id']) && $args['args']['dev7_meta_box']['id'] == $meta_box['id'] ){ if( isset($meta_box['fields']) && is_array($meta_box['fields']) ){ + + ?> + + + + '; + foreach( $meta_box['fields'] as $field ){ if( isset($field['id']) && isset($field['type']) ){ $value = get_post_meta( $post->ID, $field['id'], true ); @@ -100,25 +140,22 @@ function meta_box_output( $post, $args ) { } } - echo '

'; + echo ''; - if( isset($field['name']) && $field['name'] ){ - echo ' '; - } - if( isset($field['desc']) && $field['desc'] ){ - echo ''. $field['desc'] .''; + if( isset($field['label']) && $field['label'] ){ + echo ' '; } - echo '
'; + echo ''; switch( $field['type'] ){ case 'text': $value = esc_attr(stripslashes($value)); - echo ''; + echo ''; break; case 'textarea': $value = esc_html(stripslashes($value)); - echo ''; + echo ''; break; case 'select': $value = esc_html(esc_attr($value)); @@ -141,7 +178,7 @@ function meta_box_output( $post, $args ) { case 'checkbox': $value = esc_attr(stripslashes($value)); echo ''; - echo ''; + echo ''; break; case 'checkboxes': if( isset($field['choices']) ){ @@ -159,9 +196,17 @@ function meta_box_output( $post, $args ) { break; } - echo '

'; + if( isset($field['desc']) && $field['desc'] ){ + echo '

'. $field['desc'] .'

'; + } + + echo ''; + } - } + } // end foreach field + + echo ''; + } } } From 61c5956e563fe21929fbea5c440cc5a03d64946c Mon Sep 17 00:00:00 2001 From: cramdesign Date: Wed, 28 Aug 2013 15:42:11 -0400 Subject: [PATCH 2/8] removed my credits Not sure how git works and all. I don't need credit for some simple changes. --- dev7_meta_box_framework.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/dev7_meta_box_framework.php b/dev7_meta_box_framework.php index 7e89ff8..9be844d 100644 --- a/dev7_meta_box_framework.php +++ b/dev7_meta_box_framework.php @@ -6,8 +6,6 @@ * @link https://github.com/Dev7studios/Dev7studios-Meta-Box-Framework * @version 1.0.1 * @license MIT - * @updates Matt Cram - * @link https://github.com/cramdesign/dev7_meta_box_framework */ if( !class_exists( 'Dev7_Meta_Box_Framework' ) ) { From e44ed66823dd2f88a3a561c147f9bb9a653e4b9a Mon Sep 17 00:00:00 2001 From: cramdesign Date: Wed, 28 Aug 2013 22:36:34 -0400 Subject: [PATCH 3/8] Fixed single checkbox label --- dev7_meta_box_framework.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dev7_meta_box_framework.php b/dev7_meta_box_framework.php index 9be844d..a274dfa 100644 --- a/dev7_meta_box_framework.php +++ b/dev7_meta_box_framework.php @@ -4,7 +4,7 @@ * * @author Gilbert Pellegrom * @link https://github.com/Dev7studios/Dev7studios-Meta-Box-Framework - * @version 1.0.1 + * @version 1.0.2 * @license MIT */ @@ -176,7 +176,7 @@ function meta_box_output( $post, $args ) { case 'checkbox': $value = esc_attr(stripslashes($value)); echo ''; - echo ''; + echo ''; break; case 'checkboxes': if( isset($field['choices']) ){ @@ -194,7 +194,7 @@ function meta_box_output( $post, $args ) { break; } - if( isset($field['desc']) && $field['desc'] ){ + if( isset($field['desc']) && $field['desc'] && 'checkbox' != $field['type'] ){ echo '

'. $field['desc'] .'

'; } From f49b9ae5045ef25c37d7134fd4810149fe8d4d21 Mon Sep 17 00:00:00 2001 From: cramdesign Date: Fri, 30 Aug 2013 00:32:05 -0400 Subject: [PATCH 4/8] Tidy up formatting. --- README.md | 130 +++++++++++++++++++++++++++--------------------------- 1 file changed, 65 insertions(+), 65 deletions(-) diff --git a/README.md b/README.md index 7704ca2..b3d807c 100755 --- a/README.md +++ b/README.md @@ -12,72 +12,72 @@ include('dev7_meta_box_framework.php'); function add_custom_meta_boxes() { $meta_box = array( - 'id' => 'dev7_page_settings', // Meta box ID - 'title' => 'Page Settings', // Meta box title - 'pages' => array('post', 'page'), // Post types this meta box should be shown on - 'context' => 'normal', // Meta box context - 'priority' => 'high', // Meta box priority - 'fields' => array( + 'id' => 'dev7_page_settings', // Meta box ID + 'title' => 'Page Settings', // Meta box title + 'pages' => array('post', 'page'), // Post types this meta box should be shown on + 'context' => 'normal', // Meta box context + 'priority' => 'high', // Meta box priority + 'fields' => array( array( - 'id' => 'text', - 'label' => 'Text', - 'desc' => 'This is a description.', - 'type' => 'text', - 'std' => 'This is std' - ), - array( - 'id' => 'textarea', - 'label' => 'Textarea', - 'desc' => 'This is a description.', - 'type' => 'textarea', - 'std' => 'This is std' - ), - array( - 'id' => 'select', - 'label' => 'Select', - 'desc' => 'This is a description.', - 'type' => 'select', - 'std' => 'green', - 'choices' => array( - 'red' => 'Red', - 'green' => 'Green', - 'blue' => 'Blue' - ) - ), - array( - 'id' => 'radio', - 'label' => 'Radio', - 'desc' => 'This is a description.', - 'type' => 'radio', - 'std' => 'green', - 'choices' => array( - 'red' => 'Red', - 'green' => 'Green', - 'blue' => 'Blue' - ) - ), - array( - 'id' => 'checkbox', - 'label' => 'Checkbox', - 'desc' => 'This is a description.', - 'type' => 'checkbox', - 'std' => 1 - ), - array( - 'id' => 'checkboxes', - 'label' => 'Checkboxes', - 'desc' => 'This is a description.', - 'type' => 'checkboxes', - 'std' => array( - 'red', - 'blue' - ), - 'choices' => array( - 'red' => 'Red', - 'green' => 'Green', - 'blue' => 'Blue' - ) - ) + 'label' => 'Text', + 'desc' => 'This is a description.', + 'id' => 'text', + 'type' => 'text', + 'std' => 'This is std' + ), + array( + 'label' => 'Textarea', + 'desc' => 'This is a description.', + 'id' => 'textarea', + 'type' => 'textarea', + 'std' => 'This is std' + ), + array( + 'label' => 'Select', + 'desc' => 'This is a description.', + 'id' => 'select', + 'type' => 'select', + 'std' => 'green', + 'choices' => array( + 'red' => 'Red', + 'green' => 'Green', + 'blue' => 'Blue' + ) + ), + array( + 'label' => 'Radio', + 'desc' => 'This is a description.', + 'id' => 'radio', + 'type' => 'radio', + 'std' => 'green', + 'choices' => array( + 'red' => 'Red', + 'green' => 'Green', + 'blue' => 'Blue' + ) + ), + array( + 'label' => 'Checkbox', + 'desc' => 'This is a description.', + 'id' => 'checkbox', + 'type' => 'checkbox', + 'std' => 1 + ), + array( + 'label' => 'Checkboxes', + 'desc' => 'This is a description.', + 'id' => 'checkboxes', + 'type' => 'checkboxes', + 'std' => array( + 'red', + 'blue' + ), + 'choices' => array( + 'red' => 'Red', + 'green' => 'Green', + 'blue' => 'Blue' + ) + ) ) ); dev7_add_meta_box( $meta_box ); From 21662e1f59d1400a487cf84960b87f824d40fd9f Mon Sep 17 00:00:00 2001 From: cramdesign Date: Mon, 21 Jul 2014 20:19:51 -0400 Subject: [PATCH 5/8] small fix Fixed table css if no label is specified. Added a small helper function. --- dev7_meta_box_framework.php | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/dev7_meta_box_framework.php b/dev7_meta_box_framework.php index a274dfa..ee8e5e5 100644 --- a/dev7_meta_box_framework.php +++ b/dev7_meta_box_framework.php @@ -4,7 +4,7 @@ * * @author Gilbert Pellegrom * @link https://github.com/Dev7studios/Dev7studios-Meta-Box-Framework - * @version 1.0.2 + * @version 1.0.3 * @license MIT */ @@ -142,9 +142,11 @@ function meta_box_output( $post, $args ) { if( isset($field['label']) && $field['label'] ){ echo ' '; + echo ''; + } else { + echo ''; } - echo ''; switch( $field['type'] ){ case 'text': @@ -220,10 +222,17 @@ function meta_box_output( $post, $args ) { function dev7_add_meta_box( $meta_box ) { global $dev7_meta_boxes; - if( !is_array($dev7_meta_boxes) ) - $dev7_meta_boxes = array(); + if( !is_array($dev7_meta_boxes) ) $dev7_meta_boxes = array(); $dev7_meta_boxes[] = $meta_box; } -} \ No newline at end of file +} + +// simple way to return the value +function get_metabox( $key = "" ) { + + return get_post_meta( get_the_ID(), $key, true ); + +} + From 82f88df062615d436f37fa491485bf7e877ab009 Mon Sep 17 00:00:00 2001 From: cramdesign Date: Tue, 22 Jul 2014 09:26:07 -0400 Subject: [PATCH 6/8] small fix I was getting a php error from line 45. --- dev7_meta_box_framework.php | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/dev7_meta_box_framework.php b/dev7_meta_box_framework.php index ee8e5e5..be9db5b 100644 --- a/dev7_meta_box_framework.php +++ b/dev7_meta_box_framework.php @@ -42,20 +42,15 @@ function add_meta_boxes() { } function meta_box_save( $post_id ) { - if ( 'page' == $_REQUEST['post_type'] ) { - if ( !current_user_can( 'edit_page', $post_id ) ) - return; - } else { - if ( !current_user_can( 'edit_post', $post_id ) ) - return; - } + + if ( !current_user_can( 'edit_page', $post_id ) || !current_user_can( 'edit_post', $post_id ) ) return; if ( !isset( $_POST['dev7_meta_box_nonce'] ) || !wp_verify_nonce( $_POST['dev7_meta_box_nonce'], plugin_basename( __FILE__ ) ) ) return; global $dev7_meta_boxes; - if( !is_array($dev7_meta_boxes) ) - return; + + if( !is_array($dev7_meta_boxes) ) return; foreach( $dev7_meta_boxes as $meta_box ){ if( isset($meta_box['fields']) && is_array($meta_box['fields']) ){ @@ -213,6 +208,7 @@ function meta_box_output( $post, $args ) { } } + new Dev7_Meta_Box_Framework(); } From 8a0359a8843fb2adacab3a34343e5b7118c8e692 Mon Sep 17 00:00:00 2001 From: cramdesign Date: Wed, 27 Aug 2014 23:21:50 -0400 Subject: [PATCH 7/8] Update README.md added wysiwyg settings --- README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/README.md b/README.md index b3d807c..3367f9a 100755 --- a/README.md +++ b/README.md @@ -77,6 +77,19 @@ function add_custom_meta_boxes() { 'green' => 'Green', 'blue' => 'Blue' ) + ), + array( + 'label' => 'WYSIWYG', + 'desc' => 'This is a rich content editor.', + 'type' => 'wysiwyg', + 'id' => 'wysiwyg', + 'args' => array( + 'media_buttons' => false, + 'tinymce' => array( + 'theme_advanced_buttons1' => 'bold,italic,underline' + ), + 'teeny' => true + ) ) ) ); From 11b452e36ac20beda541b26c0cd5e90b0752de28 Mon Sep 17 00:00:00 2001 From: cramdesign Date: Thu, 28 Aug 2014 14:02:04 -0400 Subject: [PATCH 8/8] Update README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3367f9a..abc3b85 100755 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ function add_custom_meta_boxes() { 'id' => 'select', 'type' => 'select', 'std' => 'green', - 'choices' => array( + 'args' => array( 'red' => 'Red', 'green' => 'Green', 'blue' => 'Blue' @@ -50,7 +50,7 @@ function add_custom_meta_boxes() { 'id' => 'radio', 'type' => 'radio', 'std' => 'green', - 'choices' => array( + 'args' => array( 'red' => 'Red', 'green' => 'Green', 'blue' => 'Blue' @@ -72,7 +72,7 @@ function add_custom_meta_boxes() { 'red', 'blue' ), - 'choices' => array( + 'args' => array( 'red' => 'Red', 'green' => 'Green', 'blue' => 'Blue'