From d5222c704f92feff9cc415388cf205724b578890 Mon Sep 17 00:00:00 2001 From: Matth_eu Date: Mon, 31 Mar 2014 22:01:49 +0100 Subject: [PATCH 001/148] Checkbox multi --- classes.fields.php | 33 +++++++++++++++++++++++++++++++++ example-functions.php | 38 ++++++++++++++++++++------------------ 2 files changed, 53 insertions(+), 18 deletions(-) diff --git a/classes.fields.php b/classes.fields.php index d1fcc411..b30d06ed 100644 --- a/classes.fields.php +++ b/classes.fields.php @@ -812,6 +812,39 @@ public function html() { ?> } +class Checkbox_Multi extends CMB_Field { + + public function html() { + + if ( $this->has_data_delegate() ) { + $this->args['options'] = $this->get_delegate_data(); + } + + foreach ( $this->args['options'] as $key => $value ) : ?> + +
+ + id_attr( 'item-' . $key ); ?> + boolean_attr(); ?> + class_attr(); ?> + name_attr( '[item-' . $key . ']' ); ?> + get_value()[ 'item-' . $key ] )); ?> + /> + + + +
+ + 'field-1', 'name' => 'Text input field', 'type' => 'text' ), array( 'id' => 'field-2', 'name' => 'Read-only text input field', 'type' => 'text', 'readonly' => true, 'default' => 'READ ONLY' ), array( 'id' => 'field-3', 'name' => 'Repeatable text input field', 'type' => 'text', 'desc' => 'Add up to 5 fields.', 'repeatable' => true, 'repeatable_max' => 5, 'sortable' => true ), array( 'id' => 'field-4', 'name' => 'Small text input field', 'type' => 'text_small' ), array( 'id' => 'field-5', 'name' => 'URL field', 'type' => 'url' ), - - array( 'id' => 'field-6', 'name' => 'Radio input field', 'type' => 'radio', 'options' => array( 'Option 1', 'Option 2' ) ), - array( 'id' => 'field-7', 'name' => 'Checkbox field', 'type' => 'checkbox' ), - + + array( 'id' => 'field-6', 'name' => 'Radio input field', 'type' => 'radio', 'options' => array( 'Option with a really long label', 'Option 1', 'Option 2', 'Option 3', 'Option 4' ) ), + array( 'id' => 'field-7a', 'name' => 'Checkbox-Multi field', 'type' => 'checkbox_multi', 'options' => array( 'Option with a really long label', 'Option 1', 'Option 2', 'Option 3', 'Option 4' ) ), + array( 'id' => 'field-7b', 'name' => 'Checkbox field', 'type' => 'checkbox' ), + array( 'id' => 'field-8', 'name' => 'WYSIWYG field', 'type' => 'wysiwyg', 'options' => array( 'editor_height' => '100' ), 'repeatable' => true, 'sortable' => true ), array( 'id' => 'field-9', 'name' => 'Textarea field', 'type' => 'textarea' ), @@ -28,30 +29,32 @@ function cmb_sample_metaboxes( array $meta_boxes ) { array( 'id' => 'field-11', 'name' => 'File field', 'type' => 'file', 'file_type' => 'image', 'repeatable' => 1, 'sortable' => 1 ), array( 'id' => 'field-12', 'name' => 'Image upload field', 'type' => 'image', 'repeatable' => true, 'show_size' => true ), - + array( 'id' => 'field-13', 'name' => 'Select field', 'type' => 'select', 'options' => array( 'option-1' => 'Option 1', 'option-2' => 'Option 2', 'option-3' => 'Option 3' ), 'allow_none' => true, 'sortable' => true, 'repeatable' => true ), array( 'id' => 'field-14', 'name' => 'Select field', 'type' => 'select', 'options' => array( 'option-1' => 'Option 1', 'option-2' => 'Option 2', 'option-3' => 'Option 3' ), 'multiple' => true ), array( 'id' => 'field-15', 'name' => 'Select taxonomy field', 'type' => 'taxonomy_select', 'taxonomy' => 'category' ), array( 'id' => 'field-15b', 'name' => 'Select taxonomy field', 'type' => 'taxonomy_select', 'taxonomy' => 'category', 'multiple' => true ), - array( 'id' => 'field-16', 'name' => 'Post select field', 'type' => 'post_select', 'use_ajax' => false, 'query' => array( 'cat' => 1 ) ), + array( 'id' => 'field-16', 'name' => 'Post select field', 'type' => 'post_select', 'use_ajax' => false, 'query' => array( 'cat' => 1 ) ), array( 'id' => 'field-17', 'name' => 'Post select field (AJAX)', 'type' => 'post_select', 'use_ajax' => true ), array( 'id' => 'field-17b', 'name' => 'Post select field (AJAX)', 'type' => 'post_select', 'use_ajax' => true, 'query' => array( 'posts_per_page' => 8 ), 'multiple' => true ), - + array( 'id' => 'field-18', 'name' => 'Date input field', 'type' => 'date' ), array( 'id' => 'field-19', 'name' => 'Time input field', 'type' => 'time' ), array( 'id' => 'field-20', 'name' => 'Date (unix) input field', 'type' => 'date_unix' ), array( 'id' => 'field-21', 'name' => 'Date & Time (unix) input field', 'type' => 'datetime_unix' ), - + array( 'id' => 'field-22', 'name' => 'Color', 'type' => 'colorpicker' ), array( 'id' => 'field-24', 'name' => 'Title Field', 'type' => 'title' ), - + ); $meta_boxes[] = array( 'title' => 'CMB Test - all fields', 'pages' => 'post', - 'fields' => $fields + 'fields' => $fields, + 'capability' => 'edit_user', + 'capability_args' => 'current' ); // Examples of Groups and Columns @@ -86,10 +89,10 @@ function cmb_sample_metaboxes( array $meta_boxes ) { 'title' => 'CMB Test - group (all fields)', 'pages' => 'post', 'fields' => array( - array( - 'id' => 'gp', - 'name' => 'My Repeatable Group', - 'type' => 'group', + array( + 'id' => 'gp', + 'name' => 'My Repeatable Group', + 'type' => 'group', 'repeatable' => true, 'sortable' => true, 'fields' => $group_fields, @@ -100,5 +103,4 @@ function cmb_sample_metaboxes( array $meta_boxes ) { return $meta_boxes; -} -add_filter( 'cmb_meta_boxes', 'cmb_sample_metaboxes' ); +}add_filter( 'cmb_meta_boxes', 'cmb_sample_metaboxes' ); From aa97f31edaf39c67a665039a294d5a721127fb37 Mon Sep 17 00:00:00 2001 From: Matth_eu Date: Mon, 31 Mar 2014 22:07:35 +0100 Subject: [PATCH 002/148] Checkbox multi field type --- classes.fields.php | 14 +++++++------- custom-meta-boxes.php | 3 ++- example-functions.php | 4 ++-- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/classes.fields.php b/classes.fields.php index b30d06ed..1c259231 100644 --- a/classes.fields.php +++ b/classes.fields.php @@ -812,7 +812,7 @@ public function html() { ?> } -class Checkbox_Multi extends CMB_Field { +class CMB_Checkbox_Multi extends CMB_Field { public function html() { @@ -820,21 +820,21 @@ public function html() { $this->args['options'] = $this->get_delegate_data(); } - foreach ( $this->args['options'] as $key => $value ) : ?> + foreach ( $this->args['options'] as $i => $label ) : ?>
id_attr( 'item-' . $key ); ?> + id_attr( 'item-' . $i ); ?> boolean_attr(); ?> class_attr(); ?> - name_attr( '[item-' . $key . ']' ); ?> - get_value()[ 'item-' . $key ] )); ?> + name_attr( '[item-' . $i . ']' ); ?> + get_value()[ 'item-' . $i ] )); ?> /> -
diff --git a/custom-meta-boxes.php b/custom-meta-boxes.php index deca7f9a..da00b3ae 100755 --- a/custom-meta-boxes.php +++ b/custom-meta-boxes.php @@ -51,7 +51,7 @@ // Make it possible to add fields in locations other than post edit screen. include_once( CMB_PATH . '/fields-anywhere.php' ); -// include_once( CMB_PATH . '/example-functions.php' ); +include_once( CMB_PATH . '/example-functions.php' ); /** * Get all the meta boxes on init @@ -97,6 +97,7 @@ function _cmb_available_fields() { 'url' => 'CMB_URL_Field', 'radio' => 'CMB_Radio_Field', 'checkbox' => 'CMB_Checkbox', + 'checkbox_multi' => 'CMB_Checkbox_Multi', 'file' => 'CMB_File_Field', 'image' => 'CMB_Image_Field', 'wysiwyg' => 'CMB_wysiwyg', diff --git a/example-functions.php b/example-functions.php index 42d448d1..53ad901b 100644 --- a/example-functions.php +++ b/example-functions.php @@ -19,8 +19,8 @@ function cmb_sample_metaboxes( array $meta_boxes ) { array( 'id' => 'field-5', 'name' => 'URL field', 'type' => 'url' ), array( 'id' => 'field-6', 'name' => 'Radio input field', 'type' => 'radio', 'options' => array( 'Option with a really long label', 'Option 1', 'Option 2', 'Option 3', 'Option 4' ) ), - array( 'id' => 'field-7a', 'name' => 'Checkbox-Multi field', 'type' => 'checkbox_multi', 'options' => array( 'Option with a really long label', 'Option 1', 'Option 2', 'Option 3', 'Option 4' ) ), - array( 'id' => 'field-7b', 'name' => 'Checkbox field', 'type' => 'checkbox' ), + array( 'id' => 'field-7a', 'name' => 'Checkbox field', 'type' => 'checkbox' ), + array( 'id' => 'field-7b', 'name' => 'Checkbox-Multi field', 'type' => 'checkbox_multi', 'options' => array( 'Option with a really long label', 'Option 1', 'Option 2', 'Option 3', 'Option 4' ) ), array( 'id' => 'field-8', 'name' => 'WYSIWYG field', 'type' => 'wysiwyg', 'options' => array( 'editor_height' => '100' ), 'repeatable' => true, 'sortable' => true ), From ef7ae7fee9a3df8dd3b81fd9e5dbade129e06519 Mon Sep 17 00:00:00 2001 From: Matth_eu Date: Mon, 31 Mar 2014 22:57:10 +0100 Subject: [PATCH 003/148] fix php notice. Props TravisCI --- classes.fields.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/classes.fields.php b/classes.fields.php index 1c259231..aaa101e2 100644 --- a/classes.fields.php +++ b/classes.fields.php @@ -820,7 +820,11 @@ public function html() { $this->args['options'] = $this->get_delegate_data(); } - foreach ( $this->args['options'] as $i => $label ) : ?> + foreach ( $this->args['options'] as $i => $label ) : + + $value = $this->get_value(); + + ?>
@@ -830,7 +834,7 @@ public function html() { boolean_attr(); ?> class_attr(); ?> name_attr( '[item-' . $i . ']' ); ?> - get_value()[ 'item-' . $i ] )); ?> + />