Custom Post Types and Custom Fields creator – WCK - Version 2.0.0

Version Description

  • We now save every custom field in it's own separate post meta with an editable meta_key
  • UI improvements to repeater sortable table
Download this release

Release Info

Developer madalin.ungureanu
Plugin Icon 128x128 Custom Post Types and Custom Fields creator – WCK
Version 2.0.0
Comparing to
See all releases

Code changes from version 1.3.3 to 2.0.0

css/wck-cfc.css CHANGED
@@ -112,4 +112,36 @@ li.slug-title span{
112
 
113
  #icon-wck-page{
114
  background:url( ../images/wck-32x32.png ) 0 0 no-repeat;;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
  }
112
 
113
  #icon-wck-page{
114
  background:url( ../images/wck-32x32.png ) 0 0 no-repeat;;
115
+ }
116
+
117
+
118
+ .button.wck-cfc-edit-slug{
119
+ margin: 2px 0 0 5px;
120
+ }
121
+
122
+ #wck_cfc_fields #field-slug.doing-ajax{
123
+ -webkit-animation-name: ajax-input; /* Chrome, Safari, Opera */
124
+ -webkit-animation-duration: 0.5s; /* Chrome, Safari, Opera */
125
+ -webkit-animation-iteration-count: infinite; /* Chrome, Safari, Opera */
126
+ animation-name: ajax-input;
127
+ animation-duration: 0.5s;
128
+ animation-iteration-count: infinite;
129
+ }
130
+ /* Chrome, Safari, Opera */
131
+ @-webkit-keyframes ajax-input {
132
+ 0% {opacity: 1;}
133
+ 50% {opacity: 0.7;}
134
+ 100% {opacity: 1;}
135
+ }
136
+
137
+ /* Standard syntax */
138
+ @keyframes ajax-input {
139
+ 0% {opacity: 1;}
140
+ 50% {opacity: 0.7;}
141
+ 100% {opacity: 1;}
142
+ }
143
+
144
+ .wck-overwrite-slug{
145
+ display:inline-block;
146
+ padding-left:20px;
147
  }
js/wck-cfc.js CHANGED
@@ -186,4 +186,35 @@ jQuery(function(){
186
  }
187
 
188
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
189
  });
186
  }
187
 
188
  });
189
+
190
+ /* edit slug functionality */
191
+ jQuery( "#wck-cfc-fields" ).on( "click", ".wck-cfc-edit-slug", function(){
192
+ jQuery(this).prev( "input[type='text']" ).removeAttr( "readonly" );
193
+ });
194
+
195
+ jQuery( "#wck-cfc-fields" ).on( "blur", "#wck_cfc_fields.wck-add-form #field-title", function(e){
196
+
197
+ fieldTitle = jQuery(this).val();
198
+ titleField = jQuery(this);
199
+ slugField = jQuery( '#field-slug', titleField.closest( ".mb-list-entry-fields" ) );
200
+ addButton = jQuery( '.button-primary', titleField.closest( ".mb-list-entry-fields" ) );
201
+
202
+ if( slugField[0].hasAttribute("readonly") ) {
203
+ addButton.attr( 'disabled', 'disabled' );
204
+ addButton.css( 'pointer-events', 'none' )
205
+ slugField.addClass( 'doing-ajax' );
206
+ jQuery.post(wckAjaxurl, {action: "wck_generate_slug", field_title: fieldTitle}, function (response) {
207
+ if (response != 'failed') {
208
+ slugField.val(response);
209
+ slugField.removeClass( 'doing-ajax' );
210
+ }
211
+ addButton.removeAttr( 'disabled' );
212
+ addButton.css( 'pointer-events', 'auto' );
213
+ });
214
+ }
215
+
216
+
217
+
218
+ });
219
+
220
  });
readme.txt CHANGED
@@ -5,8 +5,8 @@ Donate link: http://www.cozmoslabs.com/wordpress-creation-kit/
5
  Tags: custom fields, custom field, wordpress custom fields, custom post type, custom post types, post types, repeater fields, meta box, metabox, custom taxonomy, custom fields creator, post meta
6
 
7
  Requires at least: 3.1
8
- Tested up to: 4.6
9
- Stable tag: 1.3.3
10
  License: GPLv2 or later
11
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
12
 
@@ -139,6 +139,10 @@ Creating a taxonomy generally automatically creates a special query variable usi
139
  10. Taxonomy listing
140
 
141
  == Changelog ==
 
 
 
 
142
  = 1.3.3 =
143
  * Added date format option for Datepicker Field
144
  * Fixed notices when multiple single boxes were present and the first one had a required error
5
  Tags: custom fields, custom field, wordpress custom fields, custom post type, custom post types, post types, repeater fields, meta box, metabox, custom taxonomy, custom fields creator, post meta
6
 
7
  Requires at least: 3.1
8
+ Tested up to: 4.6.1
9
+ Stable tag: 2.0.0
10
  License: GPLv2 or later
11
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
12
 
139
  10. Taxonomy listing
140
 
141
  == Changelog ==
142
+ = 2.0.0 =
143
+ * We now save every custom field in it's own separate post meta with an editable meta_key
144
+ * UI improvements to repeater sortable table
145
+
146
  = 1.3.3 =
147
  * Added date format option for Datepicker Field
148
  * Fixed notices when multiple single boxes were present and the first one had a required error
wck-cfc.php CHANGED
@@ -118,7 +118,7 @@ function wck_cfc_create_box(){
118
 
119
  /* set up the fields array */
120
  $cfc_box_args_fields = array(
121
- array( 'type' => 'text', 'title' => __( 'Meta name', 'wck' ), 'slug' => 'meta-name', 'description' => __( 'The name of the meta field. It is the name by which you will query the data in the frontend. Must be unique, only lowercase letters, no spaces and no special characters.', 'wck' ), 'required' => true ),
122
  array( 'type' => 'select', 'title' => __( 'Post Type', 'wck' ), 'slug' => 'post-type', 'options' => $post_type_names, 'default-option' => true, 'description' => __( 'What post type the meta box should be attached to', 'wck' ), 'required' => true ),
123
  array( 'type' => 'select', 'title' => __( 'Repeater', 'wck' ), 'slug' => 'repeater', 'options' => array( 'false', 'true' ), 'default' => 'false', 'description' => __( 'Whether the box supports just one entry or if it is a repeater field. By default it is a single field.', 'wck' ) ),
124
  array( 'type' => 'select', 'title' => __( 'Sortable', 'wck' ), 'slug' => 'sortable', 'options' => array( 'true', 'false' ), 'default' => 'false', 'description' => __( 'Whether the entries are sortable or not. This is valid for repeater fields.', 'wck' ) ),
@@ -161,6 +161,7 @@ function wck_cfc_create_box(){
161
  $cfc_box_fields_fields = apply_filters( 'wck_cfc_box_fields_fields', array(
162
  array( 'type' => 'text', 'title' => __( 'Field Title', 'wck' ), 'slug' => 'field-title', 'description' => __( 'Title of the field. A slug will automatically be generated.', 'wck' ), 'required' => true ),
163
  array( 'type' => 'select', 'title' => __( 'Field Type', 'wck' ), 'slug' => 'field-type', 'options' => $field_types, 'default-option' => true, 'description' => __( 'The field type', 'wck' ), 'required' => true ),
 
164
  array( 'type' => 'textarea', 'title' => __( 'Description', 'wck' ), 'slug' => 'description', 'description' => 'The description of the field.' ),
165
  array( 'type' => 'select', 'title' => __( 'Required', 'wck' ), 'slug' => 'required', 'options' => array( 'false', 'true' ), 'default' => 'false', 'description' => __( 'Whether the field is required or not', 'wck' ) ),
166
  array( 'type' => 'select', 'title' => __( 'CPT', 'wck' ), 'slug' => 'cpt', 'options' => $post_types, 'default' => 'post', 'description' => __( 'Select what custom post type should be used in the CPT Select.', 'wck' ) ),
@@ -217,13 +218,6 @@ function wck_cfc_element_class($wck_element_class, $meta, $results, $element_id)
217
  return $wck_element_class;
218
  }
219
 
220
- /* Show the slug for field title */
221
- add_filter( "wck_after_listed_wck_cfc_fields_element_0", 'wck_cfc_display_field_title_slug', 10, 3 );
222
- function wck_cfc_display_field_title_slug( $form, $i, $value ){
223
- $form .= '<li class="slug-title"><em>'. __( 'Slug:', 'wck' ) .'</em><span>'. Wordpress_Creation_Kit::wck_generate_slug( $value ) .'</span> '. __( '(Note:changing the slug when you already have a lot of existing entries may result in unexpected behavior.)', 'wck' ) .' </li>';
224
- return $form;
225
- }
226
-
227
  /* add refresh to page */
228
  add_action("wck_refresh_list_wck_cfc", "wck_cfc_after_refresh_list");
229
  function wck_cfc_after_refresh_list(){
@@ -258,6 +252,11 @@ function wck_cfc_create_boxes_args(){
258
  foreach( $wck_cfc_fields as $wck_cfc_field ){
259
  $fields_inner_array = array( 'type' => $wck_cfc_field['field-type'], 'title' => $wck_cfc_field['field-title'] );
260
 
 
 
 
 
 
261
  if( !empty( $wck_cfc_field['description'] ) )
262
  $fields_inner_array['description'] = $wck_cfc_field['description'];
263
  if( !empty( $wck_cfc_field['required'] ) )
@@ -393,23 +392,45 @@ function wck_cfc_create_boxes(){
393
  }
394
 
395
  /* Meta Name Verification */
396
- add_filter( 'wck_required_test_wck_cfc_args_meta-name', 'wck_cfc_ceck_meta_name', 10, 6 );
397
- function wck_cfc_ceck_meta_name( $bool, $value, $post_id, $field, $meta, $fields ){
 
398
  global $wpdb;
399
 
400
- $wck_cfc_args = get_post_meta( $post_id, 'wck_cfc_args', true );
 
401
 
402
- if( empty( $wck_cfc_args ) ){
403
- //this is the add case
404
- $check_meta_existance = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(meta_key) FROM $wpdb->postmeta WHERE meta_key = %s", $value ) );
405
- }
406
- else{
407
- //this is the update case
408
- if( $wck_cfc_args[0]['meta-name'] != $value ){
409
  $check_meta_existance = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(meta_key) FROM $wpdb->postmeta WHERE meta_key = %s", $value ) );
410
  }
411
- else
 
 
 
 
 
 
 
 
 
 
412
  $check_meta_existance = false;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
413
  }
414
 
415
  if( strpos( $value, ' ' ) === false )
@@ -431,17 +452,24 @@ function wck_cfc_ceck_meta_name( $bool, $value, $post_id, $field, $meta, $fields
431
  }
432
 
433
  add_filter( 'wck_required_message_wck_cfc_args_meta-name', 'wck_cfc_change_meta_message', 10, 3 );
 
434
  function wck_cfc_change_meta_message( $message, $value, $required_field ){
 
 
 
 
 
 
435
  if( empty( $value ) )
436
  return $message;
437
  else if( strpos( $value, ' ' ) !== false )
438
- return __( "Choose a different Meta Name as this one contains spaces\n", "wck" );
439
  else if( trim( strtolower( $value ) ) === 'content' || trim( strtolower( $value ) ) === 'action' )
440
- return __( "Choose a different Meta Name as this one is reserved\n", "wck" );
441
  else if ( strtolower($value) != $value )
442
- return __( "Choose a different Meta Name as this one contains uppercase letters\n", "wck" );
443
  else
444
- return __( "Choose a different Meta Name as this one already exists\n", "wck" );
445
  }
446
 
447
 
@@ -528,7 +556,13 @@ function wck_cfc_change_field_title( $meta, $id, $values, $element_id ){
528
  if( $meta == 'wck_cfc_fields' ){
529
  $wck_cfc_fields = get_post_meta( $id, 'wck_cfc_fields', true );
530
  if( !empty( $wck_cfc_fields ) ) {
531
- if ($wck_cfc_fields[$element_id]['field-title'] != $values['field-title']) {
 
 
 
 
 
 
532
 
533
  $wck_cfc_args = get_post_meta($id, 'wck_cfc_args', true);
534
  $meta_name = $wck_cfc_args[0]['meta-name'];
@@ -539,8 +573,18 @@ function wck_cfc_change_field_title( $meta, $id, $values, $element_id ){
539
  $results = get_post_meta($post->post_id, $meta_name, true);
540
  if (!empty($results)) {
541
  foreach ($results as $key => $result) {
542
- $results[$key][Wordpress_Creation_Kit::wck_generate_slug($values['field-title'])] = $results[$key][Wordpress_Creation_Kit::wck_generate_slug($wck_cfc_fields[$element_id]['field-title'])];
543
- unset($results[$key][Wordpress_Creation_Kit::wck_generate_slug($wck_cfc_fields[$element_id]['field-title'])]);
 
 
 
 
 
 
 
 
 
 
544
  }
545
  }
546
  update_post_meta($post->post_id, $meta_name, $results);
@@ -757,6 +801,35 @@ function wck_cfc_make_options_required( $meta_array, $meta, $values, $id ) {
757
  return $meta_array;
758
  }
759
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
760
  function wck_phone_field_error( $bool, $value, $id, $field, $meta, $fields ) {
761
  foreach( $fields as $key => $field_array ) {
762
  $field_slug = Wordpress_Creation_Kit::wck_generate_slug( $field_array['title'], $field_array );
@@ -817,4 +890,172 @@ function wck_number_field_error( $bool, $value, $id, $field, $meta, $fields ) {
817
  }
818
  }
819
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
820
  ?>
118
 
119
  /* set up the fields array */
120
  $cfc_box_args_fields = array(
121
+ array( 'type' => 'text', 'title' => __( 'Group Name', 'wck' ), 'slug' => 'meta-name', 'description' => __( 'The name of the group. Must be unique, only lowercase letters, no spaces and no special characters.', 'wck' ), 'required' => true ),
122
  array( 'type' => 'select', 'title' => __( 'Post Type', 'wck' ), 'slug' => 'post-type', 'options' => $post_type_names, 'default-option' => true, 'description' => __( 'What post type the meta box should be attached to', 'wck' ), 'required' => true ),
123
  array( 'type' => 'select', 'title' => __( 'Repeater', 'wck' ), 'slug' => 'repeater', 'options' => array( 'false', 'true' ), 'default' => 'false', 'description' => __( 'Whether the box supports just one entry or if it is a repeater field. By default it is a single field.', 'wck' ) ),
124
  array( 'type' => 'select', 'title' => __( 'Sortable', 'wck' ), 'slug' => 'sortable', 'options' => array( 'true', 'false' ), 'default' => 'false', 'description' => __( 'Whether the entries are sortable or not. This is valid for repeater fields.', 'wck' ) ),
161
  $cfc_box_fields_fields = apply_filters( 'wck_cfc_box_fields_fields', array(
162
  array( 'type' => 'text', 'title' => __( 'Field Title', 'wck' ), 'slug' => 'field-title', 'description' => __( 'Title of the field. A slug will automatically be generated.', 'wck' ), 'required' => true ),
163
  array( 'type' => 'select', 'title' => __( 'Field Type', 'wck' ), 'slug' => 'field-type', 'options' => $field_types, 'default-option' => true, 'description' => __( 'The field type', 'wck' ), 'required' => true ),
164
+ array( 'type' => 'text', 'title' => __( 'Field Slug', 'wck' ), 'slug' => 'field-slug', 'readonly' => true, 'description' => __( 'The meta name of the field, generated automatically from the title, by which you can query. Can be changed. Must be unique, only lowercase letters, no spaces and no special characters.', 'wck' ), 'required' => true ),
165
  array( 'type' => 'textarea', 'title' => __( 'Description', 'wck' ), 'slug' => 'description', 'description' => 'The description of the field.' ),
166
  array( 'type' => 'select', 'title' => __( 'Required', 'wck' ), 'slug' => 'required', 'options' => array( 'false', 'true' ), 'default' => 'false', 'description' => __( 'Whether the field is required or not', 'wck' ) ),
167
  array( 'type' => 'select', 'title' => __( 'CPT', 'wck' ), 'slug' => 'cpt', 'options' => $post_types, 'default' => 'post', 'description' => __( 'Select what custom post type should be used in the CPT Select.', 'wck' ) ),
218
  return $wck_element_class;
219
  }
220
 
 
 
 
 
 
 
 
221
  /* add refresh to page */
222
  add_action("wck_refresh_list_wck_cfc", "wck_cfc_after_refresh_list");
223
  function wck_cfc_after_refresh_list(){
252
  foreach( $wck_cfc_fields as $wck_cfc_field ){
253
  $fields_inner_array = array( 'type' => $wck_cfc_field['field-type'], 'title' => $wck_cfc_field['field-title'] );
254
 
255
+ if( !empty( $wck_cfc_field['field-slug'] ) )
256
+ $fields_inner_array['slug'] = $wck_cfc_field['field-slug'];
257
+ else
258
+ $fields_inner_array['slug'] = Wordpress_Creation_Kit::wck_generate_slug( $wck_cfc_field['field-title'] );
259
+
260
  if( !empty( $wck_cfc_field['description'] ) )
261
  $fields_inner_array['description'] = $wck_cfc_field['description'];
262
  if( !empty( $wck_cfc_field['required'] ) )
392
  }
393
 
394
  /* Meta Name Verification */
395
+ add_filter( 'wck_required_test_wck_cfc_args_meta-name', 'wck_cfc_check_meta_name', 10, 8 );
396
+ add_filter( 'wck_required_test_wck_cfc_fields_field-slug', 'wck_cfc_check_meta_name', 10, 8 );
397
+ function wck_cfc_check_meta_name( $bool, $value, $post_id, $field, $meta, $fields, $values, $elemet_id ){
398
  global $wpdb;
399
 
400
+ if( current_filter() == 'wck_required_test_wck_cfc_args_meta-name' ){
401
+ $wck_cfc_args = get_post_meta( $post_id, 'wck_cfc_args', true );
402
 
403
+ if( empty( $wck_cfc_args ) ){
404
+ //this is the add case
 
 
 
 
 
405
  $check_meta_existance = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(meta_key) FROM $wpdb->postmeta WHERE meta_key = %s", $value ) );
406
  }
407
+ else{
408
+ //this is the update case
409
+ if( $wck_cfc_args[0]['meta-name'] != $value ){
410
+ $check_meta_existance = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(meta_key) FROM $wpdb->postmeta WHERE meta_key = %s", $value ) );
411
+ }
412
+ else
413
+ $check_meta_existance = false;
414
+ }
415
+ }
416
+ else if( current_filter() == 'wck_required_test_wck_cfc_fields_field-slug' ){
417
+ if( !empty( $values['wck-overwrite-slug'] ) && $values['wck-overwrite-slug'] == 'overwrite' )
418
  $check_meta_existance = false;
419
+ else{
420
+ $wck_cfc_fields = get_post_meta( $post_id, 'wck_cfc_fields', true );
421
+ if( empty( $wck_cfc_fields ) || $elemet_id === false ){
422
+ //this is the add case
423
+ $check_meta_existance = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(meta_key) FROM $wpdb->postmeta WHERE meta_key = %s", $value ) );
424
+ }
425
+ else if( $elemet_id !== false ){
426
+ //this is the update case
427
+ if( !empty( $wck_cfc_fields[$elemet_id]['field-slug'] ) && $wck_cfc_fields[$elemet_id]['field-slug'] != $value ){
428
+ $check_meta_existance = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(meta_key) FROM $wpdb->postmeta WHERE meta_key = %s", $value ) );
429
+ }
430
+ else
431
+ $check_meta_existance = false;
432
+ }
433
+ }
434
  }
435
 
436
  if( strpos( $value, ' ' ) === false )
452
  }
453
 
454
  add_filter( 'wck_required_message_wck_cfc_args_meta-name', 'wck_cfc_change_meta_message', 10, 3 );
455
+ add_filter( 'wck_required_message_wck_cfc_fields_field-slug', 'wck_cfc_change_meta_message', 10, 3 );
456
  function wck_cfc_change_meta_message( $message, $value, $required_field ){
457
+
458
+ if( current_filter() == 'wck_required_message_wck_cfc_args_meta-name' )
459
+ $field_name = __( "Group Name", 'wck' );
460
+ else if( current_filter() == 'wck_required_message_wck_cfc_fields_field-slug' )
461
+ $field_name = __( "Field Slug", 'wck' );
462
+
463
  if( empty( $value ) )
464
  return $message;
465
  else if( strpos( $value, ' ' ) !== false )
466
+ return sprintf( __( "Choose a different %s as this one contains spaces\n", "wck" ), $field_name );
467
  else if( trim( strtolower( $value ) ) === 'content' || trim( strtolower( $value ) ) === 'action' )
468
+ return sprintf( __( "Choose a different %s as this one is reserved\n", "wck" ), $field_name );
469
  else if ( strtolower($value) != $value )
470
+ return sprintf( __( "Choose a different %s as this one contains uppercase letters\n", "wck" ), $field_name );
471
  else
472
+ return sprintf( __( "Choose a different %s as this one already exists\n", "wck" ), $field_name );
473
  }
474
 
475
 
556
  if( $meta == 'wck_cfc_fields' ){
557
  $wck_cfc_fields = get_post_meta( $id, 'wck_cfc_fields', true );
558
  if( !empty( $wck_cfc_fields ) ) {
559
+
560
+ if( !empty( $wck_cfc_fields[$element_id]['field-slug'] ) )
561
+ $old_slug = $wck_cfc_fields[$element_id]['field-slug'];
562
+ else
563
+ $old_slug = Wordpress_Creation_Kit::wck_generate_slug( $wck_cfc_fields[$element_id]['field-title'] );
564
+
565
+ if ( $old_slug != $values['field-slug']) {
566
 
567
  $wck_cfc_args = get_post_meta($id, 'wck_cfc_args', true);
568
  $meta_name = $wck_cfc_args[0]['meta-name'];
573
  $results = get_post_meta($post->post_id, $meta_name, true);
574
  if (!empty($results)) {
575
  foreach ($results as $key => $result) {
576
+ $results[$key][$values['field-slug']] = $results[$key][$old_slug];
577
+
578
+ /* unserialized */
579
+ if( $key == 0 )
580
+ $suffix = '';
581
+ else
582
+ $suffix = '_'.$key;
583
+ add_post_meta( $post->post_id, $values['field-slug'].$suffix, $results[$key][$old_slug] );
584
+ delete_post_meta( $post->post_id, $old_slug.$suffix );
585
+
586
+
587
+ unset($results[$key][$old_slug]);
588
  }
589
  }
590
  update_post_meta($post->post_id, $meta_name, $results);
801
  return $meta_array;
802
  }
803
 
804
+ /* handle Field Slug backwards compatibility */
805
+ add_filter( "wck_displayed_value_wck_cfc_fields_field-slug", "wck_cfc_handle_empty_field_slug", 10, 3 );
806
+ add_filter( "wck_cfc_filter_edit_form_value_wck_cfc_fields_field-slug", "wck_cfc_handle_empty_field_slug", 10, 3 );
807
+ function wck_cfc_handle_empty_field_slug( $value, $results, $element_id ){
808
+ if( empty( $value ) ){
809
+ $value = Wordpress_Creation_Kit::wck_generate_slug( $results[$element_id]['field-title'] );
810
+ }
811
+
812
+ return $value;
813
+ }
814
+
815
+ add_filter( "wck_field_before_description", "wck_edit_button_for_field_slug", 10, 3 );
816
+ function wck_edit_button_for_field_slug( $element, $meta, $details ){
817
+ if( $meta == 'wck_cfc_fields' && $details['slug'] == 'field-slug' ){
818
+ $element .= '<button type="button" class="wck-cfc-edit-slug button button-small">'. __( "Edit", "wck" ).'</button>';
819
+ $element .= '<span class="wck-overwrite-slug"><input type="checkbox" name="wck-overwrite-slug" value="overwrite" class="mb-field">'. __( "Overwrite Existing", "wck" ).'</span>';
820
+ }
821
+ return $element;
822
+ }
823
+
824
+ add_action( 'wp_ajax_wck_generate_slug', 'wck_generate_slug' );
825
+ function wck_generate_slug(){
826
+ if( !empty( $_POST['field_title'] ) ){
827
+ $slug = Wordpress_Creation_Kit::wck_generate_slug( $_POST['field_title'] );
828
+ die( $slug );
829
+ }
830
+ die('failed');
831
+ }
832
+
833
  function wck_phone_field_error( $bool, $value, $id, $field, $meta, $fields ) {
834
  foreach( $fields as $key => $field_array ) {
835
  $field_slug = Wordpress_Creation_Kit::wck_generate_slug( $field_array['title'], $field_array );
890
  }
891
  }
892
 
893
+ /* output a notice that asks the user to go and unserialize the fields */
894
+ $wck_update_unserialized = get_option( 'wck_update_to_unserialized', 'yes' );
895
+ if( $wck_update_unserialized == 'yes' ) {
896
+ new WCK_Add_Notices('wck_update_unserialized_notice',
897
+ sprintf(__('To update the meta information on posts to the new unserialized structure go to %1$sthis page%2$s and follow the instructions. %3$sDismiss%4$s', 'wck'), "<a href='" . admin_url('admin.php?page=wck-unserialized') . "'>", "</a>", "<a href='" . esc_url(add_query_arg('wck_update_unserialized_notice_dismiss_notification', '0')) . "'>", "</a>"),
898
+ 'update-nag');
899
+ }
900
+
901
+ /* add an admin page for the unserialized process */
902
+ add_action('admin_menu', 'wck_register_update_unserialized_submenu_page');
903
+ function wck_register_update_unserialized_submenu_page() {
904
+ add_submenu_page( null, 'WCK Unserialized', 'WCK Unserialized', 'manage_options', 'wck-unserialized', 'wck_unserialized_page_callback' );
905
+ }
906
+
907
+ /**
908
+ * Function callback for the unserilized page
909
+ */
910
+ function wck_unserialized_page_callback(){
911
+
912
+ /* set number of posts that are processed in a batch !IMPORTANT IT IS ALSO SET IN THE wck_cfc_process_unserialized_batch() FUNCTION */
913
+ $per_batch = 100;
914
+ $step = isset( $_GET['step'] ) ? absint( $_GET['step'] ) : 0;
915
+ $total = isset( $_GET['total'] ) ? absint( $_GET['total'] ) : false;
916
+ $finish = isset( $_GET['wckbatch-complete'] ) ? esc_url( $_GET['wckbatch-complete'] ) : false;
917
+ $processed = round( ( $step * $per_batch ), 0 );
918
+ if( $processed > $total )
919
+ $processed = $total;
920
+ ?>
921
+ <div class="wrap">
922
+ <h2><?php _e( 'Processing Unserialized Fields', 'wck' ); ?></h2>
923
+
924
+ <?php if( !$finish ): ?>
925
+ <div id="wck-unserialized-processing">
926
+ <p><?php _e( 'The process has started, please be patient. This could take several minutes. You will be automatically redirected when the process is finished.', 'wck' ); ?></p>
927
+ <?php if( ! empty( $total ) ) : ?>
928
+ <p><strong><?php printf( __( '%d posts of %d processed', 'wck' ), $processed, $total ); ?></strong></p>
929
+ <?php endif; ?>
930
+ </div>
931
+ <script type="text/javascript">
932
+ document.location.href = "edit.php?action=wck_unbatch_process&step=<?php echo $step; ?>&total=<?php echo $total; ?>&_wpnonce=<?php echo wp_create_nonce( 'wck-unbatch-nonce' ); ?>";
933
+ </script>
934
+ <?php else: ?>
935
+ <p><?php _e( 'The process has finished.', 'wck' ); ?></p>
936
+ <?php update_option( 'wck_update_to_unserialized', 'no' ) ?>
937
+ <?php endif; ?>
938
+ </div>
939
+ <?php
940
+ }
941
+
942
+ /**
943
+ * hook to process each bach on the admin_init
944
+ */
945
+ add_action( 'admin_init', 'wck_cfc_process_unserialized_batch' );
946
+
947
+ /**
948
+ * the function that process each batch
949
+ */
950
+ function wck_cfc_process_unserialized_batch() {
951
+
952
+ if( empty( $_REQUEST['action'] ) || 'wck_unbatch_process' != $_REQUEST['action'] ) {
953
+ return;
954
+ }
955
+
956
+ if( ! current_user_can( 'manage_options' ) ) {
957
+ return;
958
+ }
959
+
960
+ if( ! wp_verify_nonce( $_GET['_wpnonce'], 'wck-unbatch-nonce' ) ) {
961
+ return;
962
+ }
963
+
964
+ ignore_user_abort( true );
965
+
966
+ if (! ini_get( 'safe_mode' ) ) {
967
+ @set_time_limit( 0 );
968
+ }
969
+
970
+ /* set number of posts that are processed in a batch !IMPORTANT IT IS ALSO SET IN THE wck_unserialized_page_callback() FUNCTION */
971
+ $per_batch = 100;
972
+ $step = isset( $_GET['step'] ) ? absint( $_GET['step'] ) : 0;
973
+ $total = isset( $_GET['total'] ) ? absint( $_GET['total'] ) : false;
974
+
975
+ /* an array with the post types that have metaboxes */
976
+ $post_types_with_metaboxes = array();
977
+ /* an array that contains all the existing meta names */
978
+ $meta_names = array();
979
+
980
+ /* get all metaboxes */
981
+ $args = array(
982
+ 'posts_per_page' => -1,
983
+ 'numberposts' => -1,
984
+ 'post_type' => 'wck-meta-box',
985
+ 'post_status' => 'any'
986
+ );
987
+ $meta_boxes = get_posts( $args );
988
+ if( !empty( $meta_boxes ) ){
989
+ foreach( $meta_boxes as $meta_box ){
990
+ $cfc_args = get_post_meta( $meta_box->ID, 'wck_cfc_args', true );
991
+ $meta_names[] = $cfc_args[0]['meta-name'];
992
+ if( !in_array( $cfc_args[0]['post-type'], $post_types_with_metaboxes ) ){
993
+ $post_types_with_metaboxes[] = $cfc_args[0]['post-type'];
994
+ }
995
+ }
996
+ }
997
+
998
+ /* if we don't have a total let's count the posts */
999
+ if( empty( $total ) || $total <= 1 ){
1000
+ $total = 0;
1001
+ if( !empty( $post_types_with_metaboxes ) ){
1002
+ foreach( $post_types_with_metaboxes as $post_type ){
1003
+ $posts_count = wp_count_posts( $post_type );
1004
+ $posts_count = array_sum( get_object_vars( $posts_count ) );
1005
+ $total += $posts_count;
1006
+ }
1007
+ }
1008
+ }
1009
+
1010
+
1011
+ global $wpdb;
1012
+ /* turn the arrays into strings to use in mysql */
1013
+ $post_types_with_metaboxes = join( "','", $post_types_with_metaboxes );
1014
+ $meta_names = join( "','", $meta_names );
1015
+ $offset = $step*$per_batch;
1016
+ /* mysql query to get all post ids that potentially have meta boxes on them */
1017
+ $posts = $wpdb->get_results( "SELECT ID FROM $wpdb->posts WHERE post_type IN ('$post_types_with_metaboxes') LIMIT $per_batch OFFSET $offset" );
1018
+
1019
+ /* go through all the post ids */
1020
+ if( $posts ) {
1021
+ foreach( $posts as $post ) {
1022
+ /* get all the meta names associated to the post id */
1023
+ $meta_boxes = $wpdb->get_results( "SELECT meta_value FROM $wpdb->postmeta WHERE post_id = '$post->ID' AND meta_key IN ('$meta_names')", ARRAY_A );
1024
+ /* transform them in unserialized */
1025
+ if( !empty( $meta_boxes ) ){
1026
+ foreach( $meta_boxes as $meta_box ){
1027
+ if( !empty( $meta_box ) ){
1028
+ $meta_value = $meta_box['meta_value'];
1029
+ $meta_value = maybe_unserialize( $meta_value );
1030
+ foreach( $meta_value as $key => $values ){
1031
+ if( !empty( $values ) ){
1032
+ foreach( $values as $meta_key => $value ){
1033
+ if( $key == 0 )
1034
+ $suffix = '';
1035
+ else
1036
+ $suffix = '_'.$key;
1037
+
1038
+ update_post_meta( $post->ID, $meta_key.$suffix, $value );
1039
+ }
1040
+ }
1041
+ }
1042
+ }
1043
+ }
1044
+ }
1045
+ }
1046
+
1047
+ // comments found so delete them
1048
+ $step++;
1049
+ $redirect = add_query_arg( array(
1050
+ 'page' => 'wck-unserialized',
1051
+ 'step' => $step,
1052
+ 'total' => $total
1053
+ ), admin_url( 'admin.php' ) );
1054
+ wp_redirect( $redirect ); exit;
1055
+
1056
+ } else {
1057
+ // No more comments found, finish up
1058
+ wp_redirect( admin_url( 'admin.php?page=wck-unserialized&wckbatch-complete=true' ) ); exit;
1059
+ }
1060
+ }
1061
  ?>
wck.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: WCK - Custom Fields and Custom Post Types Creator
4
  Description: WordPress Creation Kit consists of three tools that can help you create and maintain custom post types, custom taxonomies and most importantly, custom fields and metaboxes for your posts, pages or CPT's.
5
  Author: Cozmoslabs, Madalin Ungureanu, Cristian Antohe
6
- Version: 1.3.3
7
  Author URI: http://www.cozmoslabs.com
8
 
9
  License: GPL2
@@ -136,6 +136,30 @@ function wck_deactivate_function() {
136
  }
137
  }
138
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
139
  /* check for updates */
140
  $wck_premium_update = WCK_PLUGIN_DIR.'/update/';
141
  if (file_exists ($wck_premium_update . 'update-checker.php')){
3
  Plugin Name: WCK - Custom Fields and Custom Post Types Creator
4
  Description: WordPress Creation Kit consists of three tools that can help you create and maintain custom post types, custom taxonomies and most importantly, custom fields and metaboxes for your posts, pages or CPT's.
5
  Author: Cozmoslabs, Madalin Ungureanu, Cristian Antohe
6
+ Version: 2.0.0
7
  Author URI: http://www.cozmoslabs.com
8
 
9
  License: GPL2
136
  }
137
  }
138
 
139
+ /* activation hook */
140
+ add_action( 'admin_init', 'wck_maybe_unserialize' );
141
+ function wck_maybe_unserialize() {
142
+ /* we need to see if there already are cfcs present so we can update them to the new unserialized structure introduced in wck 2.3.4 */
143
+
144
+ $option_already_exists = get_option( 'wck_update_to_unserialized' );
145
+ if( empty( $option_already_exists ) ){
146
+ $args = array(
147
+ 'posts_per_page' => -1,
148
+ 'numberposts' => -1,
149
+ 'post_type' => 'wck-meta-box',
150
+ 'post_status' => 'any'
151
+ );
152
+ $meta_boxes = get_posts( $args );
153
+ /* we don't have metaboxes created */
154
+ if( empty( $meta_boxes ) ){
155
+ add_option( 'wck_update_to_unserialized', 'no' );
156
+ }
157
+ else{
158
+ add_option( 'wck_update_to_unserialized', 'yes' );
159
+ }
160
+ }
161
+ }
162
+
163
  /* check for updates */
164
  $wck_premium_update = WCK_PLUGIN_DIR.'/update/';
165
  if (file_exists ($wck_premium_update . 'update-checker.php')){
wordpress-creation-kit-api/wordpress-creation-kit.css CHANGED
@@ -93,6 +93,10 @@ td.wck-number{
93
  list-style:none;
94
  }
95
 
 
 
 
 
96
  .mb-table-container tr:nth-child(2n+1) {
97
  background-color:#FCFCFC;
98
  }
@@ -101,6 +105,10 @@ td.wck-number{
101
  border-bottom: 0 none;
102
  }
103
 
 
 
 
 
104
  .mb-table-container tr td {
105
  background: none repeat scroll 0 0 transparent;
106
  border-bottom: 1px solid #EDEDED;
93
  list-style:none;
94
  }
95
 
96
+ .mb-table-container tr{
97
+ background-color:#FFFFFF;
98
+ }
99
+
100
  .mb-table-container tr:nth-child(2n+1) {
101
  background-color:#FCFCFC;
102
  }
105
  border-bottom: 0 none;
106
  }
107
 
108
+ .mb-table-container tr.wck-ui-state-highlight{
109
+ min-height:100px;
110
+ }
111
+
112
  .mb-table-container tr td {
113
  background: none repeat scroll 0 0 transparent;
114
  border-bottom: 1px solid #EDEDED;
wordpress-creation-kit-api/wordpress-creation-kit.js CHANGED
@@ -190,8 +190,11 @@ function removeMeta(value, id, element_id, nonce){
190
  /* reorder elements through drag and drop */
191
  function mb_sortable_elements() {
192
  jQuery( ".mb-table-container tbody" ).not( jQuery( ".mb-table-container.single tbody, .mb-table-container.not-sortable tbody" ) ).sortable({
 
 
 
193
  update: function(event, ui){
194
-
195
  var value = jQuery(this).parent().siblings('.wck-add-form').attr('id');
196
  var id = jQuery(this).parent().attr('post');
197
 
@@ -229,7 +232,8 @@ function mb_sortable_elements() {
229
 
230
  });
231
  },
232
- items: "> tr"
 
233
  });
234
  /*I don't know if this is necessary. Remove when I have more time for tests */
235
  jQuery( "#sortable:not(select)" ).disableSelection();
190
  /* reorder elements through drag and drop */
191
  function mb_sortable_elements() {
192
  jQuery( ".mb-table-container tbody" ).not( jQuery( ".mb-table-container.single tbody, .mb-table-container.not-sortable tbody" ) ).sortable({
193
+ start: function(event, ui){
194
+ jQuery( ui.placeholder ).height(jQuery( ui.item ).height());
195
+ },
196
  update: function(event, ui){
197
+
198
  var value = jQuery(this).parent().siblings('.wck-add-form').attr('id');
199
  var id = jQuery(this).parent().attr('post');
200
 
232
 
233
  });
234
  },
235
+ items: "> tr",
236
+ placeholder: "wck-ui-state-highlight"
237
  });
238
  /*I don't know if this is necessary. Remove when I have more time for tests */
239
  jQuery( "#sortable:not(select)" ).disableSelection();
wordpress-creation-kit-api/wordpress-creation-kit.php CHANGED
@@ -65,6 +65,7 @@ class Wordpress_Creation_Kit{
65
  'post_id' => '',
66
  'single' => false,
67
  'unserialize_fields' => false,
 
68
  'sortable' => true,
69
  'context' => 'post_meta'
70
  );
@@ -315,6 +316,8 @@ class Wordpress_Creation_Kit{
315
  require( dirname( __FILE__ ) . '/fields/' . $details['type'] . '.php' );
316
  }
317
 
 
 
318
  if( ! empty( $details['description'] ) ) {
319
  $element .= '<p class="description">' . $details['description'] . '</p>';
320
  }
@@ -449,7 +452,7 @@ class Wordpress_Creation_Kit{
449
 
450
  $form .= '<li class="row-'. esc_attr( Wordpress_Creation_Kit::wck_generate_slug( $details['title'], $details ) ) .'">';
451
 
452
- $form .= self::wck_output_form_field( $meta, $details, $value, 'edit_form', $id );
453
 
454
  $form .= '</li>';
455
 
@@ -543,7 +546,7 @@ class Wordpress_Creation_Kit{
543
  /* filter display value */
544
  /* keep this one for backwards compatibility */
545
  $value = apply_filters( "wck_displayed_value_{$meta}_element_{$j}", $value );
546
- $value = apply_filters( "wck_displayed_value_{$meta}_".Wordpress_Creation_Kit::wck_generate_slug( $details['title'], $details ), $value );
547
 
548
  /* display it differently based on field type*/
549
  if( $details['type'] == 'upload' ){
@@ -765,7 +768,7 @@ class Wordpress_Creation_Kit{
765
  }
766
 
767
  /* Helper function for required fields */
768
- function wck_test_required( $meta_array, $meta, $values, $id ){
769
  $fields = apply_filters( 'wck_before_test_required', $meta_array, $meta, $values, $id );
770
  $required_fields = array();
771
  $required_fields_with_errors = array();
@@ -782,7 +785,7 @@ class Wordpress_Creation_Kit{
782
 
783
  if( !empty( $values ) ){
784
  foreach( $required_fields as $key => $title ){
785
- if( !array_key_exists( $key, $values ) || ( array_key_exists( $key, $values ) && apply_filters( "wck_required_test_{$meta}_{$key}", empty( $values[$key] ), $values[$key], $id, $key, $meta, $fields ) ) ) {
786
  $required_message .= apply_filters( "wck_required_message_{$meta}_{$key}", __( "Please enter a value for the required field ", "wck" ) . "$required_fields[$key] \n", ( isset($values[$key]) ? $values[$key] : '' ), $required_fields[$key] );
787
  $required_fields_with_errors[] = $key;
788
  }
@@ -888,7 +891,23 @@ class Wordpress_Creation_Kit{
888
  update_post_meta($id, $meta, $results);
889
  else if ( $this->args['context'] == 'option' )
890
  update_option( $meta, wp_unslash( $results ) );
891
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
892
  /* if unserialize_fields is true add for each entry separate post meta for every element of the form */
893
  if( $this->args['unserialize_fields'] && $this->args['context'] == 'post_meta' ){
894
 
@@ -932,7 +951,7 @@ class Wordpress_Creation_Kit{
932
  $values = apply_filters( "wck_update_meta_filter_values_{$meta}", $values, $element_id );
933
 
934
  /* check required fields */
935
- $errors = self::wck_test_required( $this->args['meta_array'], $meta, $values, $id );
936
  if( $errors != '' ){
937
  header( 'Content-type: application/json' );
938
  die( json_encode( $errors ) );
@@ -951,7 +970,23 @@ class Wordpress_Creation_Kit{
951
  update_post_meta($id, $meta, $results);
952
  else if ( $this->args['context'] == 'option' )
953
  update_option( $meta, wp_unslash( $results ) );
954
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
955
  /* if unserialize_fields is true update the corresponding post metas for every element of the form */
956
  if( $this->args['unserialize_fields'] && $this->args['context'] == 'post_meta' ){
957
 
@@ -1083,9 +1118,41 @@ class Wordpress_Creation_Kit{
1083
  update_post_meta($id, $meta, $results);
1084
  else if ( $this->args['context'] == 'option' )
1085
  update_option( $meta, wp_unslash( $results ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1086
 
1087
-
1088
-
1089
  /* TODO: optimize so that it updates from the deleted element forward */
1090
  /* if unserialize_fields is true delete the corresponding post metas */
1091
  if( $this->args['unserialize_fields'] && $this->args['context'] == 'post_meta' ){
@@ -1159,8 +1226,26 @@ class Wordpress_Creation_Kit{
1159
  update_post_meta($id, $meta, $results);
1160
  else if ( $this->args['context'] == 'option' )
1161
  update_option( $meta, wp_unslash( $results ) );
1162
-
1163
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1164
  /* if unserialize_fields is true reorder all the coresponding post metas */
1165
  if( $this->args['unserialize_fields'] && $this->args['context'] == 'post_meta' ){
1166
 
@@ -1251,7 +1336,18 @@ class Wordpress_Creation_Kit{
1251
 
1252
  /* no errors so we can save */
1253
  update_post_meta($post_id, $meta_name, array($meta_values));
1254
- /* handle unserialized fields */
 
 
 
 
 
 
 
 
 
 
 
1255
  if ($this->args['unserialize_fields']) {
1256
  if (!empty($this->args['meta_array'])) {
1257
  foreach ($this->args['meta_array'] as $meta_field) {
65
  'post_id' => '',
66
  'single' => false,
67
  'unserialize_fields' => false,
68
+ 'unserialize' => true,
69
  'sortable' => true,
70
  'context' => 'post_meta'
71
  );
316
  require( dirname( __FILE__ ) . '/fields/' . $details['type'] . '.php' );
317
  }
318
 
319
+ $element = apply_filters( "wck_field_before_description", $element, $meta, $details );
320
+
321
  if( ! empty( $details['description'] ) ) {
322
  $element .= '<p class="description">' . $details['description'] . '</p>';
323
  }
452
 
453
  $form .= '<li class="row-'. esc_attr( Wordpress_Creation_Kit::wck_generate_slug( $details['title'], $details ) ) .'">';
454
 
455
+ $form .= self::wck_output_form_field( $meta, $details, apply_filters( "wck_cfc_filter_edit_form_value_{$meta}_".Wordpress_Creation_Kit::wck_generate_slug( $details['title'], $details ) , $value, $results, $element_id ), 'edit_form', $id );
456
 
457
  $form .= '</li>';
458
 
546
  /* filter display value */
547
  /* keep this one for backwards compatibility */
548
  $value = apply_filters( "wck_displayed_value_{$meta}_element_{$j}", $value );
549
+ $value = apply_filters( "wck_displayed_value_{$meta}_".Wordpress_Creation_Kit::wck_generate_slug( $details['title'], $details ), $value, $results, $element_id );
550
 
551
  /* display it differently based on field type*/
552
  if( $details['type'] == 'upload' ){
768
  }
769
 
770
  /* Helper function for required fields */
771
+ function wck_test_required( $meta_array, $meta, $values, $id, $elemet_id = false ){
772
  $fields = apply_filters( 'wck_before_test_required', $meta_array, $meta, $values, $id );
773
  $required_fields = array();
774
  $required_fields_with_errors = array();
785
 
786
  if( !empty( $values ) ){
787
  foreach( $required_fields as $key => $title ){
788
+ if( !array_key_exists( $key, $values ) || ( array_key_exists( $key, $values ) && apply_filters( "wck_required_test_{$meta}_{$key}", empty( $values[$key] ), $values[$key], $id, $key, $meta, $fields, $values, $elemet_id ) ) ) {
789
  $required_message .= apply_filters( "wck_required_message_{$meta}_{$key}", __( "Please enter a value for the required field ", "wck" ) . "$required_fields[$key] \n", ( isset($values[$key]) ? $values[$key] : '' ), $required_fields[$key] );
790
  $required_fields_with_errors[] = $key;
791
  }
891
  update_post_meta($id, $meta, $results);
892
  else if ( $this->args['context'] == 'option' )
893
  update_option( $meta, wp_unslash( $results ) );
894
+
895
+ if( $this->args['unserialize'] && $this->args['context'] == 'post_meta' ){
896
+ /* first entry doesn't have a suffix bus starting from the second entry we have a 0 based index */
897
+ $number_of_entries = count( $results );
898
+ if( $number_of_entries == 1 )
899
+ $meta_suffix = '';
900
+ else
901
+ $meta_suffix = '_'.( $number_of_entries-1);
902
+
903
+ if( !empty( $values ) ){
904
+ foreach( $values as $name => $value ){
905
+ update_post_meta($id, $name.$meta_suffix, $value);
906
+ }
907
+ }
908
+ }
909
+
910
+ /* backwards compatibility */
911
  /* if unserialize_fields is true add for each entry separate post meta for every element of the form */
912
  if( $this->args['unserialize_fields'] && $this->args['context'] == 'post_meta' ){
913
 
951
  $values = apply_filters( "wck_update_meta_filter_values_{$meta}", $values, $element_id );
952
 
953
  /* check required fields */
954
+ $errors = self::wck_test_required( $this->args['meta_array'], $meta, $values, $id, $element_id );
955
  if( $errors != '' ){
956
  header( 'Content-type: application/json' );
957
  die( json_encode( $errors ) );
970
  update_post_meta($id, $meta, $results);
971
  else if ( $this->args['context'] == 'option' )
972
  update_option( $meta, wp_unslash( $results ) );
973
+
974
+ if( $this->args['unserialize'] && $this->args['context'] == 'post_meta' ){
975
+ /* first entry doesn't have a suffix bus starting from the second entry we have a 0 based index */
976
+
977
+ if( $element_id == 0 )
978
+ $meta_suffix = '';
979
+ else
980
+ $meta_suffix = '_'.$element_id;
981
+
982
+ if( !empty( $values ) ){
983
+ foreach( $values as $name => $value ){
984
+ update_post_meta($id, $name.$meta_suffix, $value);
985
+ }
986
+ }
987
+ }
988
+
989
+ /* backwards compatibility */
990
  /* if unserialize_fields is true update the corresponding post metas for every element of the form */
991
  if( $this->args['unserialize_fields'] && $this->args['context'] == 'post_meta' ){
992
 
1118
  update_post_meta($id, $meta, $results);
1119
  else if ( $this->args['context'] == 'option' )
1120
  update_option( $meta, wp_unslash( $results ) );
1121
+
1122
+
1123
+ /* TODO: optimize so that it updates from the deleted element forward */
1124
+ /* if unserialize_fields is true delete the corresponding post metas */
1125
+ if( $this->args['unserialize'] && $this->args['context'] == 'post_meta' ){
1126
+
1127
+ /* delete all the unserialized meta so we can add them again */
1128
+ $meta_suffix = '';
1129
+ $meta_counter = 0;
1130
+ if( !empty( $old_results ) ) {
1131
+ foreach ( $old_results as $result ) {
1132
+ foreach ( $result as $name => $value ) {
1133
+ delete_post_meta( $id, $name . $meta_suffix );
1134
+ }
1135
+ $meta_counter ++;
1136
+ $meta_suffix = '_'.$meta_counter;
1137
+ }
1138
+ }
1139
+
1140
+ /* now add the remaining values as unserialized */
1141
+ $meta_suffix = '';
1142
+ $meta_counter = 0;
1143
+ if( !empty( $results ) && count( $results ) != 0 ){
1144
+ foreach( $results as $result ){
1145
+ foreach ( $result as $name => $value){
1146
+ update_post_meta($id, $name.$meta_suffix, $value);
1147
+ }
1148
+ $meta_counter ++;
1149
+ $meta_suffix = '_'.$meta_counter;
1150
+ }
1151
+ }
1152
+
1153
+ }
1154
 
1155
+ /* backwards compatibility */
 
1156
  /* TODO: optimize so that it updates from the deleted element forward */
1157
  /* if unserialize_fields is true delete the corresponding post metas */
1158
  if( $this->args['unserialize_fields'] && $this->args['context'] == 'post_meta' ){
1226
  update_post_meta($id, $meta, $results);
1227
  else if ( $this->args['context'] == 'option' )
1228
  update_option( $meta, wp_unslash( $results ) );
1229
+
1230
+
1231
+ if( $this->args['unserialize'] && $this->args['context'] == 'post_meta' ){
1232
+
1233
+ $meta_suffix = '';
1234
+ $meta_counter = 0;
1235
+ if( !empty( $new_results ) ){
1236
+ foreach( $new_results as $result ){
1237
+ foreach ( $result as $name => $value){
1238
+ update_post_meta($id, $name.$meta_suffix, $value);
1239
+ }
1240
+ $meta_counter++;
1241
+ $meta_suffix = '_'.$meta_counter;
1242
+ }
1243
+ }
1244
+
1245
+ }
1246
+
1247
+
1248
+ /* backwards compatibility */
1249
  /* if unserialize_fields is true reorder all the coresponding post metas */
1250
  if( $this->args['unserialize_fields'] && $this->args['context'] == 'post_meta' ){
1251
 
1336
 
1337
  /* no errors so we can save */
1338
  update_post_meta($post_id, $meta_name, array($meta_values));
1339
+
1340
+
1341
+ if ($this->args['unserialize']) {
1342
+ if (!empty($this->args['meta_array'])) {
1343
+ foreach ($this->args['meta_array'] as $meta_field) {
1344
+ update_post_meta($post_id, Wordpress_Creation_Kit::wck_generate_slug( $meta_field['title'], $meta_field ), $_POST[$this->args['meta_name'] . '_' . Wordpress_Creation_Kit::wck_generate_slug( $meta_field['title'], $meta_field )]);
1345
+ }
1346
+ }
1347
+ }
1348
+
1349
+ /* backwards compatibility */
1350
+ /* handle unserialized fields */
1351
  if ($this->args['unserialize_fields']) {
1352
  if (!empty($this->args['meta_array'])) {
1353
  foreach ($this->args['meta_array'] as $meta_field) {