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

Version Description

  • Gutenberg compatibility
  • Php 7 compatibility
Download this release

Release Info

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

Code changes from version 2.2.0 to 2.2.1

readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: cozmoslabs, reflectionmedia, madalin.ungureanu, sareiodata, adispi
3
  Donate link: http://www.cozmoslabs.com/wordpress-creation-kit/
4
  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
5
  Requires at least: 3.1
6
- Tested up to: 4.9.8
7
- Stable tag: 2.2.0
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -137,6 +137,10 @@ Creating a taxonomy generally automatically creates a special query variable usi
137
  10. Taxonomy listing
138
 
139
  == Changelog ==
 
 
 
 
140
  = 2.2.0 =
141
  * Fixed a notice with default value in colorpicker field
142
  * Updated translation files
3
  Donate link: http://www.cozmoslabs.com/wordpress-creation-kit/
4
  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
5
  Requires at least: 3.1
6
+ Tested up to: 5.0.0
7
+ Stable tag: 2.2.1
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
137
  10. Taxonomy listing
138
 
139
  == Changelog ==
140
+ = 2.2.1 =
141
+ * Gutenberg compatibility
142
+ * Php 7 compatibility
143
+
144
  = 2.2.0 =
145
  * Fixed a notice with default value in colorpicker field
146
  * Updated translation files
wck-cfc.php CHANGED
@@ -972,22 +972,59 @@ function wck_number_field_error( $bool, $value, $id, $field, $meta, $fields ) {
972
  $field_slug = Wordpress_Creation_Kit::wck_generate_slug( $field_array['title'], $field_array );
973
  if( $field_slug == $field ) {
974
  if( ! empty( $value ) && ! is_numeric( $value ) ) {
975
- add_filter( "wck_required_message_{$meta}_{$field_slug}", create_function( '$message, $value, $required_field', '$message = apply_filters( "wck_number_error_message", __( "Please enter numbers only for field ", "wck" ) . "$required_field \n" ); return $message;' ), 10, 3 );
 
 
 
 
 
 
 
 
976
  return true;
977
  }
978
 
979
  if( ! empty( $field_array['number-step-value'] ) && ! empty( $value ) && ( sprintf( round( $value / $field_array['number-step-value'] ) ) != sprintf( $value / $field_array['number-step-value'] ) ) ) {
980
- add_filter( "wck_required_message_{$meta}_{$field_slug}", create_function( '$message, $value, $required_field', '$number_step = '. $field_array['number-step-value'] .'; $message = apply_filters( "wck_number_error_message", "$required_field" . __( " field value must be a multiplier of ", "wck" ) . "$number_step \n" ); return $message;' ), 10, 3 );
 
 
 
 
 
 
 
 
 
 
981
  return true;
982
  }
983
 
984
  if( ( ! empty( $field_array['min-number-value'] ) || (isset($field_array['min-number-value']) && $field_array['min-number-value'] == '0' )) && ( ! empty( $value ) || $value == '0' ) && $value < $field_array['min-number-value'] ) {
985
- add_filter( "wck_required_message_{$meta}_{$field_slug}", create_function( '$message, $value, $required_field', '$number_min = '. $field_array['min-number-value'] .'; $message = apply_filters( "wck_number_error_message", "$required_field" . __( " field value must be greater than or equal to ", "wck" ) . "$number_min \n" ); return $message;' ), 10, 3 );
 
 
 
 
 
 
 
 
 
 
986
  return true;
987
  }
988
 
989
  if( ( ! empty( $field_array['max-number-value'] ) || (isset($field_array['max-number-value']) && $field_array['max-number-value'] == '0' )) && ( ! empty( $value ) || $value == '0' ) && $value > $field_array['max-number-value'] ) {
990
- add_filter( "wck_required_message_{$meta}_{$field_slug}", create_function( '$message, $value, $required_field', '$number_max = '. $field_array['max-number-value'] .'; $message = apply_filters( "wck_number_error_message", "$required_field" . __( " field value must be less than or equal to ", "wck" ) . "$number_max \n" ); return $message;' ), 10, 3 );
 
 
 
 
 
 
 
 
 
991
  return true;
992
  }
993
 
@@ -1289,6 +1326,12 @@ function wck_serialized_update_from_unserialized( $replace, $object_id, $meta_ke
1289
  add_filter( 'is_protected_meta', 'wck_cfc_protect_meta_keys', 10, 3 );
1290
  function wck_cfc_protect_meta_keys( $protected, $meta_key, $meta_type ){
1291
  global $wck_objects, $post;
 
 
 
 
 
 
1292
  if( !empty( $wck_objects ) ){
1293
  foreach( $wck_objects as $wck_object ){
1294
  if( !empty( $wck_object['meta_array'] ) ){
972
  $field_slug = Wordpress_Creation_Kit::wck_generate_slug( $field_array['title'], $field_array );
973
  if( $field_slug == $field ) {
974
  if( ! empty( $value ) && ! is_numeric( $value ) ) {
975
+
976
+ if ( version_compare( phpversion(), '5.4.0', '<' ) )
977
+ add_filter( "wck_required_message_{$meta}_{$field_slug}", create_function( '$message, $value, $required_field', '$message = apply_filters( "wck_number_error_message", __( "Please enter numbers only for field ", "wck" ) . "$required_field \n" ); return $message;' ), 10, 3 );
978
+ else {
979
+ add_filter( "wck_required_message_{$meta}_{$field_slug}", function ( $message, $value, $required_field ) {
980
+ return apply_filters( "wck_number_error_message", __( "Please enter numbers only for field ", "wck" ) . "$required_field \n" );
981
+ }, 10, 3 );
982
+ }
983
+
984
  return true;
985
  }
986
 
987
  if( ! empty( $field_array['number-step-value'] ) && ! empty( $value ) && ( sprintf( round( $value / $field_array['number-step-value'] ) ) != sprintf( $value / $field_array['number-step-value'] ) ) ) {
988
+
989
+ if ( version_compare( phpversion(), '5.4.0', '<' ) )
990
+ add_filter( "wck_required_message_{$meta}_{$field_slug}", create_function( '$message, $value, $required_field', '$number_step = '. $field_array['number-step-value'] .'; $message = apply_filters( "wck_number_error_message", "$required_field" . __( " field value must be a multiplier of ", "wck" ) . "$number_step \n" ); return $message;' ), 10, 3 );
991
+ else {
992
+ add_filter( "wck_required_message_{$meta}_{$field_slug}", function ( $message, $value, $required_field ) use ( $field_array ) {
993
+ $number_step = $field_array['number-step-value'];
994
+
995
+ return apply_filters( "wck_number_error_message", "$required_field" . __( " field value must be a multiplier of ", "wck" ) . "$number_step \n" );
996
+ }, 10, 3 );
997
+ }
998
+
999
  return true;
1000
  }
1001
 
1002
  if( ( ! empty( $field_array['min-number-value'] ) || (isset($field_array['min-number-value']) && $field_array['min-number-value'] == '0' )) && ( ! empty( $value ) || $value == '0' ) && $value < $field_array['min-number-value'] ) {
1003
+
1004
+ if ( version_compare( phpversion(), '5.4.0', '<' ) )
1005
+ add_filter( "wck_required_message_{$meta}_{$field_slug}", create_function( '$message, $value, $required_field', '$number_min = '. $field_array['min-number-value'] .'; $message = apply_filters( "wck_number_error_message", "$required_field" . __( " field value must be greater than or equal to ", "wck" ) . "$number_min \n" ); return $message;' ), 10, 3 );
1006
+ else {
1007
+ add_filter( "wck_required_message_{$meta}_{$field_slug}", function ( $message, $value, $required_field ) use ( $field_array ) {
1008
+ $number_min = $field_array['min-number-value'];
1009
+
1010
+ return apply_filters( "wck_number_error_message", "$required_field" . __( " field value must be greater than or equal to ", "wck" ) . "$number_min \n" );
1011
+ }, 10, 3 );
1012
+ }
1013
+
1014
  return true;
1015
  }
1016
 
1017
  if( ( ! empty( $field_array['max-number-value'] ) || (isset($field_array['max-number-value']) && $field_array['max-number-value'] == '0' )) && ( ! empty( $value ) || $value == '0' ) && $value > $field_array['max-number-value'] ) {
1018
+ if ( version_compare( phpversion(), '5.4.0', '<' ) )
1019
+ add_filter( "wck_required_message_{$meta}_{$field_slug}", create_function( '$message, $value, $required_field', '$number_max = '. $field_array['max-number-value'] .'; $message = apply_filters( "wck_number_error_message", "$required_field" . __( " field value must be less than or equal to ", "wck" ) . "$number_max \n" ); return $message;' ), 10, 3 );
1020
+ else {
1021
+ add_filter( "wck_required_message_{$meta}_{$field_slug}", function ( $message, $value, $required_field ) use ( $field_array ) {
1022
+ $number_max = $field_array['max-number-value'];
1023
+
1024
+ return apply_filters( "wck_number_error_message", "$required_field" . __( " field value must be less than or equal to ", "wck" ) . "$number_max \n" );
1025
+ }, 10, 3 );
1026
+ }
1027
+
1028
  return true;
1029
  }
1030
 
1326
  add_filter( 'is_protected_meta', 'wck_cfc_protect_meta_keys', 10, 3 );
1327
  function wck_cfc_protect_meta_keys( $protected, $meta_key, $meta_type ){
1328
  global $wck_objects, $post;
1329
+
1330
+ //they should be available on frontend and customizer
1331
+ if( is_customize_preview() || !is_admin() ){
1332
+ return $protected;
1333
+ }
1334
+
1335
  if( !empty( $wck_objects ) ){
1336
  foreach( $wck_objects as $wck_object ){
1337
  if( !empty( $wck_object['meta_array'] ) ){
wck-cptc.php CHANGED
@@ -27,7 +27,7 @@ function wck_cptc_print_scripts($hook){
27
  /* create the meta box only for admins ( 'capability' => 'edit_theme_options' ) */
28
  add_action( 'init', 'wck_cptc_create_box', 11 );
29
  function wck_cptc_create_box(){
30
- global $wp_version;
31
  if( is_admin() && current_user_can( 'edit_theme_options' ) ){
32
  /* get registered taxonomies */
33
  $args = array(
@@ -66,53 +66,54 @@ function wck_cptc_create_box(){
66
  array( 'type' => 'text', 'title' => __( 'Not Found In Trash', 'wck' ), 'slug' => 'not-found-in-trash', 'description' => __( 'ex. No Books found in Trash', 'wck' ) ),
67
  array( 'type' => 'text', 'title' => __( 'Parent Item Colon', 'wck' ), 'slug' => 'parent-item-colon', 'description' => __( 'the parent text. This string isn\'t used on non-hierarchical types. In hierarchical ones the default is Parent Page ', 'wck' ) ),
68
  array( 'type' => 'text', 'title' => __( 'Menu Name', 'wck' ), 'slug' => 'menu-name' ),
69
- );
70
-
71
- if( version_compare( $wp_version, '4.3', '>=' ) ) {
72
- $labels_v43 = array(
73
- array( 'type' => 'text', 'title' => __( 'Featured Image', 'wck' ), 'slug' => 'featured_image', 'description' => __( 'ex. Featured Image', 'wck' ) ),
74
- array( 'type' => 'text', 'title' => __( 'Set Featured Image', 'wck' ), 'slug' => 'set_featured_image', 'description' => __( 'ex. Set Featured Image', 'wck' ) ),
75
- array( 'type' => 'text', 'title' => __( 'Remove Featured Image', 'wck' ), 'slug' => 'remove_featured_image', 'description' => __( 'ex. Remove Featured Image', 'wck' ) ),
76
- array( 'type' => 'text', 'title' => __( 'Use Featured Image', 'wck' ), 'slug' => 'use_featured_image', 'description' => __( 'ex. Use Featured Image', 'wck' ) )
77
- );
78
-
79
- foreach( $labels_v43 as $label_v43 ) {
80
- array_push( $cpt_creation_fields, $label_v43 );
81
- }
82
- }
83
-
84
- if( version_compare( $wp_version, '4.4', '>=' ) ) {
85
- $labels_v44 = array(
86
- array( 'type' => 'text', 'title' => __( 'Archives', 'wck' ), 'slug' => 'archives', 'description' => __( 'ex. Archives', 'wck' ) ),
87
- array( 'type' => 'text', 'title' => __( 'Inser Into Item', 'wck' ), 'slug' => 'insert_into_item', 'description' => __( 'ex. Inser Into Item', 'wck' ) ),
88
- array( 'type' => 'text', 'title' => __( 'Uploaded to this Item', 'wck' ), 'slug' => 'uploaded_to_this_item', 'description' => __( 'ex. Uploaded to this Item', 'wck' ) ),
89
- array( 'type' => 'text', 'title' => __( 'Filter Items List', 'wck' ), 'slug' => 'filter_items_list', 'description' => __( 'ex. Filter Items List', 'wck' ) ),
90
- array( 'type' => 'text', 'title' => __( 'Items List Navigation', 'wck' ), 'slug' => 'items_list_navigation', 'description' => __( 'ex. Items List Navigation', 'wck' ) ),
91
- array( 'type' => 'text', 'title' => __( 'Items List', 'wck' ), 'slug' => 'items_list', 'description' => __( 'ex. Items List', 'wck' ) ),
92
- );
93
-
94
- foreach( $labels_v44 as $label_v44 ) {
95
- array_push( $cpt_creation_fields, $label_v44 );
96
- }
97
- }
98
-
99
- $cpt_creation_fields2 = array(
100
- array( 'type' => 'select', 'title' => __( 'Public', 'wck' ), 'slug' => 'public', 'options' => array( 'false', 'true' ), 'default' => 'true', 'description' => __( 'Meta argument used to define default values for publicly_queriable, show_ui, show_in_nav_menus and exclude_from_search', 'wck' ) ),
101
- array( 'type' => 'select', 'title' => __( 'Show UI', 'wck' ), 'slug' => 'show-ui', 'options' => array( 'false', 'true' ), 'default' => 'true', 'description' => __( 'Whether to generate a default UI for managing this post type.', 'wck' ) ),
102
- array( 'type' => 'select', 'title' => __( 'Show In Nav Menus', 'wck' ), 'slug' => 'show-in-nav-menus', 'options' => array( 'false', 'true' ), 'default' => 'true', 'description' => __( 'Whether post_type is available for selection in navigation menus.', 'wck' ) ),
103
- array( 'type' => 'text', 'title' => __( 'Show In Menu', 'wck' ), 'slug' => 'show-in-menu', 'default' => 'true', 'description' => __( 'Whether to show the post type in the admin menu. show_ui must be true. "false" - do not display in the admin menu, "true" - display as a top level menu, "some string" - If an existing top level page such as "tools.php" or "edit.php?post_type=page", the post type will be placed as a sub menu of that.', 'wck' ) ),
104
- array( 'type' => 'text', 'title' => __( 'Menu Position', 'wck' ), 'slug' => 'menu-position', 'description' => __( 'The position in the menu order the post type should appear.', 'wck' ) ),
105
- array( 'type' => 'text', 'title' => __( 'Menu Icon', 'wck' ), 'slug' => 'menu-icon', 'description' => __( 'The url to the icon to be used for this menu.', 'wck' ) ),
106
- array( 'type' => 'text', 'title' => __( 'Capability Type', 'wck' ), 'slug' => 'capability-type', 'description' => __( 'The string to use to build the read, edit, and delete capabilities.', 'wck' ), 'default' => 'post' ),
107
- array( 'type' => 'checkbox', 'title' => __( 'Taxonomies', 'wck' ), 'slug' => 'taxonomies', 'options' => $taxonomie_names ),
108
- array( 'type' => 'select', 'title' => __( 'Rewrite', 'wck' ), 'slug' => 'rewrite', 'options' => array( 'false', 'true' ), 'default' => 'true', 'description' => __( 'Rewrite permalinks.', 'wck' ) ),
109
- array( 'type' => 'text', 'title' => __( 'Rewrite Slug', 'wck' ), 'slug' => 'rewrite-slug', 'description' => __( 'Defaults to post type name.', 'wck' ) ),
110
- array( 'type' => 'select', 'title' => __( 'Show in REST API', 'wck'), 'slug' => 'show-in-rest', 'options' => array( 'false', 'true'), 'default' => 'false', 'description' => __('Make this post type available via WP REST API ', 'wck' ) )
111
- );
112
-
113
- foreach( $cpt_creation_fields2 as $cpt_creation_field ) {
114
- array_push( $cpt_creation_fields, $cpt_creation_field );
115
- }
 
116
 
117
  /* set up the box arguments */
118
  $args = array(
@@ -134,7 +135,7 @@ function wck_cptc_create_box(){
134
  add_action( 'init', 'wck_cptc_create_cpts', 8 );
135
 
136
  function wck_cptc_create_cpts(){
137
- global $wp_version;
138
 
139
  $cpts = get_option('wck_cptc');
140
 
@@ -157,33 +158,33 @@ function wck_cptc_create_cpts(){
157
  'menu_name' => $cpt['menu-name'] ? $cpt['menu-name'] : $cpt['plural-label']
158
  );
159
 
160
- if( version_compare( $wp_version, '4.3', '>=' ) ) {
161
- $labels_v43 = array(
162
- 'featured_image' => __( !empty( $cpt['featured_image'] ) ? $cpt['featured_image'] : "Featured Image" ),
163
- 'set_featured_image' => __( !empty( $cpt['set_featured_image'] ) ? $cpt['set_featured_image'] : "Set featured image" ),
164
- 'remove_featured_image' => __( !empty( $cpt['remove_featured_image'] ) ? $cpt['remove_featured_image'] : "Remove featured image" ),
165
- 'use_featured_image' => __( !empty( $cpt['use_featured_image'] ) ? $cpt['use_featured_image'] : "Use as featured image" )
166
- );
167
-
168
- foreach( $labels_v43 as $label_v43 ) {
169
- array_push( $labels, $label_v43 );
170
- }
171
- }
172
-
173
- if( version_compare( $wp_version, '4.4', '>=' ) ) {
174
- $labels_v44 = array(
175
- 'archives' => __( !empty( $cpt['archives'] ) ? $cpt['archives'] : $cpt['singular-label'] . " Archives" ),
176
- 'insert_into_item' => __( !empty( $cpt['insert_into_item'] ) ? $cpt['insert_into_item'] : "Insert Into " . $cpt['singular-label'] ),
177
- 'uploaded_to_this_item' => __( !empty( $cpt['uploaded_to_this_item'] ) ? $cpt['uploaded_to_this_item'] : "Uploaded to this " . $cpt['singular-label'] ),
178
- 'filter_items_list' => __( !empty( $cpt['filter_items_list'] ) ? $cpt['filter_items_list'] : "Filter Items List" ),
179
- 'items_list_navigation' => __( !empty( $cpt['items_list_navigation'] ) ? $cpt['items_list_navigation'] : "Items List Navigation" ),
180
- 'items_list' => __( !empty( $cpt['items_list'] ) ? $cpt['items_list'] : "Items List" )
181
- );
182
-
183
- foreach( $labels_v44 as $label_v44 ) {
184
- array_push( $labels, $label_v44 );
185
- }
186
- }
187
 
188
  $args = array(
189
  'labels' => $labels,
@@ -218,8 +219,17 @@ function wck_cptc_create_cpts(){
218
  if( $cpt['rewrite'] == 'false' )
219
  $args['rewrite'] = $cpt['rewrite'] == 'false' ? false : true;
220
  else{
 
 
221
  if( !empty( $cpt['rewrite-slug'] ) )
222
- $args['rewrite'] = array('slug' => $cpt['rewrite-slug']);
 
 
 
 
 
 
 
223
  }
224
 
225
  register_post_type( $cpt['post-type'], apply_filters( 'wck_cptc_register_post_type_args', $args, $cpt['post-type'] ) );
@@ -334,9 +344,9 @@ if( !file_exists( dirname(__FILE__).'/wck-stp.php' ) ) {
334
  {
335
  ?>
336
  <a href="http://www.cozmoslabs.com/wck-custom-fields-custom-post-types-plugin/?utm_source=wpbackend&utm_medium=clientsite&utm_campaign=WCKFree"><img
337
- src="<?php echo plugins_url('/images/banner_pro.png', __FILE__) ?>?v=1" width="254" height="448"
338
- alt="WCK-PRO"/></a>
339
- <?php
340
  }
341
  }
342
 
@@ -491,4 +501,4 @@ function wck_cpt_get_reserved_names(){
491
  return $reserved_vars;
492
  }
493
 
494
- ?>
27
  /* create the meta box only for admins ( 'capability' => 'edit_theme_options' ) */
28
  add_action( 'init', 'wck_cptc_create_box', 11 );
29
  function wck_cptc_create_box(){
30
+ global $wp_version;
31
  if( is_admin() && current_user_can( 'edit_theme_options' ) ){
32
  /* get registered taxonomies */
33
  $args = array(
66
  array( 'type' => 'text', 'title' => __( 'Not Found In Trash', 'wck' ), 'slug' => 'not-found-in-trash', 'description' => __( 'ex. No Books found in Trash', 'wck' ) ),
67
  array( 'type' => 'text', 'title' => __( 'Parent Item Colon', 'wck' ), 'slug' => 'parent-item-colon', 'description' => __( 'the parent text. This string isn\'t used on non-hierarchical types. In hierarchical ones the default is Parent Page ', 'wck' ) ),
68
  array( 'type' => 'text', 'title' => __( 'Menu Name', 'wck' ), 'slug' => 'menu-name' ),
69
+ );
70
+
71
+ if( version_compare( $wp_version, '4.3', '>=' ) ) {
72
+ $labels_v43 = array(
73
+ array( 'type' => 'text', 'title' => __( 'Featured Image', 'wck' ), 'slug' => 'featured_image', 'description' => __( 'ex. Featured Image', 'wck' ) ),
74
+ array( 'type' => 'text', 'title' => __( 'Set Featured Image', 'wck' ), 'slug' => 'set_featured_image', 'description' => __( 'ex. Set Featured Image', 'wck' ) ),
75
+ array( 'type' => 'text', 'title' => __( 'Remove Featured Image', 'wck' ), 'slug' => 'remove_featured_image', 'description' => __( 'ex. Remove Featured Image', 'wck' ) ),
76
+ array( 'type' => 'text', 'title' => __( 'Use Featured Image', 'wck' ), 'slug' => 'use_featured_image', 'description' => __( 'ex. Use Featured Image', 'wck' ) )
77
+ );
78
+
79
+ foreach( $labels_v43 as $label_v43 ) {
80
+ array_push( $cpt_creation_fields, $label_v43 );
81
+ }
82
+ }
83
+
84
+ if( version_compare( $wp_version, '4.4', '>=' ) ) {
85
+ $labels_v44 = array(
86
+ array( 'type' => 'text', 'title' => __( 'Archives', 'wck' ), 'slug' => 'archives', 'description' => __( 'ex. Archives', 'wck' ) ),
87
+ array( 'type' => 'text', 'title' => __( 'Inser Into Item', 'wck' ), 'slug' => 'insert_into_item', 'description' => __( 'ex. Inser Into Item', 'wck' ) ),
88
+ array( 'type' => 'text', 'title' => __( 'Uploaded to this Item', 'wck' ), 'slug' => 'uploaded_to_this_item', 'description' => __( 'ex. Uploaded to this Item', 'wck' ) ),
89
+ array( 'type' => 'text', 'title' => __( 'Filter Items List', 'wck' ), 'slug' => 'filter_items_list', 'description' => __( 'ex. Filter Items List', 'wck' ) ),
90
+ array( 'type' => 'text', 'title' => __( 'Items List Navigation', 'wck' ), 'slug' => 'items_list_navigation', 'description' => __( 'ex. Items List Navigation', 'wck' ) ),
91
+ array( 'type' => 'text', 'title' => __( 'Items List', 'wck' ), 'slug' => 'items_list', 'description' => __( 'ex. Items List', 'wck' ) ),
92
+ );
93
+
94
+ foreach( $labels_v44 as $label_v44 ) {
95
+ array_push( $cpt_creation_fields, $label_v44 );
96
+ }
97
+ }
98
+
99
+ $cpt_creation_fields2 = array(
100
+ array( 'type' => 'select', 'title' => __( 'Public', 'wck' ), 'slug' => 'public', 'options' => array( 'false', 'true' ), 'default' => 'true', 'description' => __( 'Meta argument used to define default values for publicly_queriable, show_ui, show_in_nav_menus and exclude_from_search', 'wck' ) ),
101
+ array( 'type' => 'select', 'title' => __( 'Show UI', 'wck' ), 'slug' => 'show-ui', 'options' => array( 'false', 'true' ), 'default' => 'true', 'description' => __( 'Whether to generate a default UI for managing this post type.', 'wck' ) ),
102
+ array( 'type' => 'select', 'title' => __( 'Show In Nav Menus', 'wck' ), 'slug' => 'show-in-nav-menus', 'options' => array( 'false', 'true' ), 'default' => 'true', 'description' => __( 'Whether post_type is available for selection in navigation menus.', 'wck' ) ),
103
+ array( 'type' => 'text', 'title' => __( 'Show In Menu', 'wck' ), 'slug' => 'show-in-menu', 'default' => 'true', 'description' => __( 'Whether to show the post type in the admin menu. show_ui must be true. "false" - do not display in the admin menu, "true" - display as a top level menu, "some string" - If an existing top level page such as "tools.php" or "edit.php?post_type=page", the post type will be placed as a sub menu of that.', 'wck' ) ),
104
+ array( 'type' => 'text', 'title' => __( 'Menu Position', 'wck' ), 'slug' => 'menu-position', 'description' => __( 'The position in the menu order the post type should appear.', 'wck' ) ),
105
+ array( 'type' => 'text', 'title' => __( 'Menu Icon', 'wck' ), 'slug' => 'menu-icon', 'description' => __( 'The url to the icon to be used for this menu.', 'wck' ) ),
106
+ array( 'type' => 'text', 'title' => __( 'Capability Type', 'wck' ), 'slug' => 'capability-type', 'description' => __( 'The string to use to build the read, edit, and delete capabilities.', 'wck' ), 'default' => 'post' ),
107
+ array( 'type' => 'checkbox', 'title' => __( 'Taxonomies', 'wck' ), 'slug' => 'taxonomies', 'options' => $taxonomie_names ),
108
+ array( 'type' => 'select', 'title' => __( 'Rewrite', 'wck' ), 'slug' => 'rewrite', 'options' => array( 'false', 'true' ), 'default' => 'true', 'description' => __( 'Rewrite permalinks.', 'wck' ) ),
109
+ array( 'type' => 'select', 'title' => __( 'With Front', 'wck' ), 'slug' => 'with_front', 'options' => array( 'true', 'false' ), 'default' => 'true', 'description' => __( 'Use the defined base for permalinks.', 'wck' ) ),
110
+ array( 'type' => 'text', 'title' => __( 'Rewrite Slug', 'wck' ), 'slug' => 'rewrite-slug', 'description' => __( 'Defaults to post type name.', 'wck' ) ),
111
+ array( 'type' => 'select', 'title' => __( 'Show in REST API', 'wck'), 'slug' => 'show-in-rest', 'options' => array( 'false', 'true'), 'default' => 'false', 'description' => __('Make this post type available via WP REST API ', 'wck' ) )
112
+ );
113
+
114
+ foreach( $cpt_creation_fields2 as $cpt_creation_field ) {
115
+ array_push( $cpt_creation_fields, $cpt_creation_field );
116
+ }
117
 
118
  /* set up the box arguments */
119
  $args = array(
135
  add_action( 'init', 'wck_cptc_create_cpts', 8 );
136
 
137
  function wck_cptc_create_cpts(){
138
+ global $wp_version;
139
 
140
  $cpts = get_option('wck_cptc');
141
 
158
  'menu_name' => $cpt['menu-name'] ? $cpt['menu-name'] : $cpt['plural-label']
159
  );
160
 
161
+ if( version_compare( $wp_version, '4.3', '>=' ) ) {
162
+ $labels_v43 = array(
163
+ 'featured_image' => __( !empty( $cpt['featured_image'] ) ? $cpt['featured_image'] : "Featured Image" ),
164
+ 'set_featured_image' => __( !empty( $cpt['set_featured_image'] ) ? $cpt['set_featured_image'] : "Set featured image" ),
165
+ 'remove_featured_image' => __( !empty( $cpt['remove_featured_image'] ) ? $cpt['remove_featured_image'] : "Remove featured image" ),
166
+ 'use_featured_image' => __( !empty( $cpt['use_featured_image'] ) ? $cpt['use_featured_image'] : "Use as featured image" )
167
+ );
168
+
169
+ foreach( $labels_v43 as $label_v43 ) {
170
+ array_push( $labels, $label_v43 );
171
+ }
172
+ }
173
+
174
+ if( version_compare( $wp_version, '4.4', '>=' ) ) {
175
+ $labels_v44 = array(
176
+ 'archives' => __( !empty( $cpt['archives'] ) ? $cpt['archives'] : $cpt['singular-label'] . " Archives" ),
177
+ 'insert_into_item' => __( !empty( $cpt['insert_into_item'] ) ? $cpt['insert_into_item'] : "Insert Into " . $cpt['singular-label'] ),
178
+ 'uploaded_to_this_item' => __( !empty( $cpt['uploaded_to_this_item'] ) ? $cpt['uploaded_to_this_item'] : "Uploaded to this " . $cpt['singular-label'] ),
179
+ 'filter_items_list' => __( !empty( $cpt['filter_items_list'] ) ? $cpt['filter_items_list'] : "Filter Items List" ),
180
+ 'items_list_navigation' => __( !empty( $cpt['items_list_navigation'] ) ? $cpt['items_list_navigation'] : "Items List Navigation" ),
181
+ 'items_list' => __( !empty( $cpt['items_list'] ) ? $cpt['items_list'] : "Items List" )
182
+ );
183
+
184
+ foreach( $labels_v44 as $label_v44 ) {
185
+ array_push( $labels, $label_v44 );
186
+ }
187
+ }
188
 
189
  $args = array(
190
  'labels' => $labels,
219
  if( $cpt['rewrite'] == 'false' )
220
  $args['rewrite'] = $cpt['rewrite'] == 'false' ? false : true;
221
  else{
222
+ $rewrite_array = array();
223
+
224
  if( !empty( $cpt['rewrite-slug'] ) )
225
+ $rewrite_array['slug'] = $cpt['rewrite-slug'];
226
+
227
+ if( !empty( $cpt['with_front'] ) && $cpt['with_front'] == 'false' )
228
+ $rewrite_array['with_front'] = false;
229
+
230
+ if ( count( $rewrite_array ) > 0 ) {
231
+ $args['rewrite'] = $rewrite_array;
232
+ }
233
  }
234
 
235
  register_post_type( $cpt['post-type'], apply_filters( 'wck_cptc_register_post_type_args', $args, $cpt['post-type'] ) );
344
  {
345
  ?>
346
  <a href="http://www.cozmoslabs.com/wck-custom-fields-custom-post-types-plugin/?utm_source=wpbackend&utm_medium=clientsite&utm_campaign=WCKFree"><img
347
+ src="<?php echo plugins_url('/images/banner_pro.png', __FILE__) ?>?v=1" width="254" height="448"
348
+ alt="WCK-PRO"/></a>
349
+ <?php
350
  }
351
  }
352
 
501
  return $reserved_vars;
502
  }
503
 
504
+ ?>
wck-ctc.php CHANGED
@@ -17,7 +17,7 @@ new WCK_Page_Creator( $args );
17
  /* create the meta box only for admins ( 'capability' => 'edit_theme_options' ) */
18
  add_action( 'init', 'wck_ctc_create_box', 11 );
19
  function wck_ctc_create_box(){
20
- global $wp_version;
21
  if( is_admin() && current_user_can( 'edit_theme_options' ) ){
22
  $args = array(
23
  'public' => true
@@ -55,38 +55,39 @@ function wck_ctc_create_box(){
55
  array( 'type' => 'text', 'title' => __( 'Menu Name', 'wck' ), 'slug' => 'menu-name' ),
56
  );
57
 
58
- if( version_compare( $wp_version, '4.3', '>=' ) ) {
59
- $label_v43 = array( 'type' => 'text', 'title' => __( 'No Terms', 'wck' ), 'slug' => 'no_terms', 'description' => __( 'ex. No Terms', 'wck' ) );
60
-
61
- array_push( $ct_creation_fields, $label_v43 );
62
- }
63
-
64
- if( version_compare( $wp_version, '4.4', '>=' ) ) {
65
- $labels_v44 = array(
66
- array( 'type' => 'text', 'title' => __( 'Items List Navigation', 'wck' ), 'slug' => 'items_list_navigation', 'description' => __( 'ex. Items List Navigation', 'wck' ) ),
67
- array( 'type' => 'text', 'title' => __( 'Items List', 'wck' ), 'slug' => 'items_list', 'description' => __( 'ex. Items List', 'wck' ) ),
68
- );
69
-
70
- foreach( $labels_v44 as $label_v44 ) {
71
- array_push( $ct_creation_fields, $label_v44 );
72
- }
73
- }
74
-
75
- $ct_creation_fields2 = array(
76
- array( 'type' => 'select', 'title' => __( 'Public', 'wck' ), 'slug' => 'public', 'options' => array( 'false', 'true' ), 'default' => 'true', 'description' => __( 'Meta argument used to define default values for publicly_queriable, show_ui, show_in_nav_menus and exclude_from_search', 'wck' ) ),
77
- array( 'type' => 'select', 'title' => __( 'Show UI', 'wck' ), 'slug' => 'show-ui', 'options' => array( 'false', 'true' ), 'default' => 'true', 'description' => __( 'Whether to generate a default UI for managing this post type.', 'wck' ) ),
78
- array( 'type' => 'select', 'title' => __( 'Show Tagcloud', 'wck' ), 'slug' => 'show-tagcloud', 'options' => array( 'false', 'true' ), 'default' => 'true', 'description' => __( 'Whether to allow the Tag Cloud widget to use this taxonomy.', 'wck' ) ),
79
- array( 'type' => 'select', 'title' => __( 'Show Admin Column', 'wck' ), 'slug' => 'show-admin-column', 'options' => array( 'false', 'true' ), 'default' => 'false', 'description' => __( 'Whether to allow automatic creation of taxonomy columns on associated post-types.', 'wck' ) ),
80
- array( 'type' => 'select', 'title' => __( 'Sortable Admin Column', 'wck' ), 'slug' => 'sortable-admin-column', 'options' => array( 'false', 'true' ), 'default' => 'false', 'description' => __( 'Whether to make the columns sortable or not. WARNING: on a large number of posts the performance can be severely affected', 'wck' ) ),
81
- array( 'type' => 'select', 'title' => __( 'Show in Quick Edit', 'wck' ), 'slug' => 'show-in-quick-edit', 'options' => array( 'false', 'true' ), 'default' => 'false', 'description' => __( 'Whether to show the taxonomy in the quick/bulk edit panel.', 'wck' ) ),
82
- array( 'type' => 'select', 'title' => __( 'Show in REST API', 'wck'), 'slug' => 'show-in-rest', 'options' => array( 'false', 'true'), 'default' => 'false', 'description' => __('Make this taxonomy available via WP REST API ', 'wck' ) ),
83
  array( 'type' => 'select', 'title' => __( 'Rewrite', 'wck' ), 'slug' => 'rewrite', 'options' => array( 'true', 'false' ), 'default' => 'true', 'description' => __( 'Rewrite permalinks.', 'wck' ) ),
 
84
  array( 'type' => 'text', 'title' => __( 'Rewrite Slug', 'wck' ), 'slug' => 'rewrite-slug', 'description' => __( 'Defaults to post type name.', 'wck' ) ),
85
- );
86
 
87
- foreach( $ct_creation_fields2 as $ct_creation_field ) {
88
- array_push( $ct_creation_fields, $ct_creation_field );
89
- }
90
 
91
  $args = array(
92
  'metabox_id' => 'ctc_creation_box',
@@ -106,7 +107,7 @@ function wck_ctc_create_box(){
106
  add_action( 'init', 'wck_ctc_create_taxonomy', 8 );
107
 
108
  function wck_ctc_create_taxonomy(){
109
- global $wp_version;
110
  $cts = get_option('wck_ctc');
111
  if( !empty( $cts ) ){
112
  foreach( $cts as $ct ){
@@ -129,22 +130,22 @@ function wck_ctc_create_taxonomy(){
129
  'menu_name' => $ct['menu-name'] ? $ct['menu-name'] : $ct['plural-label']
130
  );
131
 
132
- if( version_compare( $wp_version, '4.3', '>=' ) ) {
133
- $labels_v43 = array( 'no_terms' => __( !empty( $ct['no_terms'] ) ? $ct['no_terms'] : "No Terms" ) );
134
 
135
- array_push( $labels, $labels_v43 );
136
- }
137
 
138
- if( version_compare( $wp_version, '4.4', '>=' ) ) {
139
- $labels_v44 = array(
140
- 'items_list_navigation' => __( !empty( $ct['items_list_navigation'] ) ? $ct['items_list_navigation'] : "Items List Navigation" ),
141
- 'items_list' => __( !empty( $ct['items_list'] ) ? $ct['items_list'] : "Items List" )
142
- );
143
 
144
- foreach( $labels_v44 as $label_v44 ) {
145
- array_push( $labels, $label_v44 );
146
- }
147
- }
148
 
149
  $args = array(
150
  'labels' => $labels,
@@ -174,33 +175,74 @@ function wck_ctc_create_taxonomy(){
174
  $args['rewrite'] = $ct['rewrite'] == 'false' ? false : true;
175
  }
176
  else {
177
- if (!empty($ct['rewrite-slug'])) {
178
- $args['rewrite'] = array('slug' => $ct['rewrite-slug']);
 
 
 
 
 
 
 
 
179
  }
180
  }
181
  }
182
 
183
  register_taxonomy( $ct['taxonomy'], $object_type, apply_filters( 'wck_ctc_register_taxonomy_args', $args, $ct['taxonomy'] ) );
184
 
185
- if( !empty( $object_type ) && !empty( $args['show_admin_column'] ) && $args['show_admin_column'] == true && !empty( $ct['sortable-admin-column'] ) && $ct['sortable-admin-column'] === 'true' ){
186
- foreach( $object_type as $post_type ) {
187
- add_filter("manage_edit-{$post_type}_sortable_columns", create_function('$columns', '$columns["taxonomy-' . $ct["taxonomy"] . '"] = "taxonomy-' . $ct["taxonomy"] . '";return $columns;'));
 
 
 
 
 
188
  add_filter( 'posts_clauses', create_function( '$clauses, $wp_query', 'global $wpdb;
189
- if ( is_admin() && isset( $wp_query->query[\'orderby\'] ) && \'taxonomy-'.$ct["taxonomy"].'\' == $wp_query->query[\'orderby\'] ) {
190
 
191
- $clauses[\'join\'] .= <<<SQL
192
- LEFT OUTER JOIN {$wpdb->term_relationships} ON {$wpdb->posts}.ID={$wpdb->term_relationships}.object_id
193
- LEFT OUTER JOIN {$wpdb->term_taxonomy} USING (term_taxonomy_id)
194
- LEFT OUTER JOIN {$wpdb->terms} USING (term_id)
195
- SQL;
196
 
197
  $clauses[\'where\'] .= " AND (taxonomy = \''.$ct["taxonomy"].'\' OR taxonomy IS NULL)";
198
  $clauses[\'groupby\'] = "object_id";
199
  $clauses[\'orderby\'] = "GROUP_CONCAT({$wpdb->terms}.name ORDER BY name ASC) ";
200
  $clauses[\'orderby\'] .= ( \'ASC\' == strtoupper( $wp_query->get(\'order\') ) ) ? \'ASC\' : \'DESC\';
201
  }
202
-
203
  return $clauses;' ), 10, 2 );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
204
  }
205
  }
206
  }
@@ -367,9 +409,9 @@ if( !file_exists( dirname(__FILE__).'/wck-stp.php' ) ) {
367
  {
368
  ?>
369
  <a href="http://www.cozmoslabs.com/wck-custom-fields-custom-post-types-plugin/?utm_source=wpbackend&utm_medium=clientsite&utm_campaign=WCKFree"><img
370
- src="<?php echo plugins_url('/images/banner_pro.png', __FILE__) ?>?v=1" width="254" height="448"
371
- alt="WCK-PRO"/></a>
372
- <?php
373
  }
374
  }
375
 
@@ -448,5 +490,3 @@ function wck_ctc_update_taxonomies( $meta, $id, $values, $element_id ){
448
  }
449
  }
450
  }
451
-
452
-
17
  /* create the meta box only for admins ( 'capability' => 'edit_theme_options' ) */
18
  add_action( 'init', 'wck_ctc_create_box', 11 );
19
  function wck_ctc_create_box(){
20
+ global $wp_version;
21
  if( is_admin() && current_user_can( 'edit_theme_options' ) ){
22
  $args = array(
23
  'public' => true
55
  array( 'type' => 'text', 'title' => __( 'Menu Name', 'wck' ), 'slug' => 'menu-name' ),
56
  );
57
 
58
+ if( version_compare( $wp_version, '4.3', '>=' ) ) {
59
+ $label_v43 = array( 'type' => 'text', 'title' => __( 'No Terms', 'wck' ), 'slug' => 'no_terms', 'description' => __( 'ex. No Terms', 'wck' ) );
60
+
61
+ array_push( $ct_creation_fields, $label_v43 );
62
+ }
63
+
64
+ if( version_compare( $wp_version, '4.4', '>=' ) ) {
65
+ $labels_v44 = array(
66
+ array( 'type' => 'text', 'title' => __( 'Items List Navigation', 'wck' ), 'slug' => 'items_list_navigation', 'description' => __( 'ex. Items List Navigation', 'wck' ) ),
67
+ array( 'type' => 'text', 'title' => __( 'Items List', 'wck' ), 'slug' => 'items_list', 'description' => __( 'ex. Items List', 'wck' ) ),
68
+ );
69
+
70
+ foreach( $labels_v44 as $label_v44 ) {
71
+ array_push( $ct_creation_fields, $label_v44 );
72
+ }
73
+ }
74
+
75
+ $ct_creation_fields2 = array(
76
+ array( 'type' => 'select', 'title' => __( 'Public', 'wck' ), 'slug' => 'public', 'options' => array( 'false', 'true' ), 'default' => 'true', 'description' => __( 'Meta argument used to define default values for publicly_queriable, show_ui, show_in_nav_menus and exclude_from_search', 'wck' ) ),
77
+ array( 'type' => 'select', 'title' => __( 'Show UI', 'wck' ), 'slug' => 'show-ui', 'options' => array( 'false', 'true' ), 'default' => 'true', 'description' => __( 'Whether to generate a default UI for managing this post type.', 'wck' ) ),
78
+ array( 'type' => 'select', 'title' => __( 'Show Tagcloud', 'wck' ), 'slug' => 'show-tagcloud', 'options' => array( 'false', 'true' ), 'default' => 'true', 'description' => __( 'Whether to allow the Tag Cloud widget to use this taxonomy.', 'wck' ) ),
79
+ array( 'type' => 'select', 'title' => __( 'Show Admin Column', 'wck' ), 'slug' => 'show-admin-column', 'options' => array( 'false', 'true' ), 'default' => 'false', 'description' => __( 'Whether to allow automatic creation of taxonomy columns on associated post-types.', 'wck' ) ),
80
+ array( 'type' => 'select', 'title' => __( 'Sortable Admin Column', 'wck' ), 'slug' => 'sortable-admin-column', 'options' => array( 'false', 'true' ), 'default' => 'false', 'description' => __( 'Whether to make the columns sortable or not. WARNING: on a large number of posts the performance can be severely affected', 'wck' ) ),
81
+ array( 'type' => 'select', 'title' => __( 'Show in Quick Edit', 'wck' ), 'slug' => 'show-in-quick-edit', 'options' => array( 'false', 'true' ), 'default' => 'false', 'description' => __( 'Whether to show the taxonomy in the quick/bulk edit panel.', 'wck' ) ),
82
+ array( 'type' => 'select', 'title' => __( 'Show in REST API', 'wck'), 'slug' => 'show-in-rest', 'options' => array( 'false', 'true'), 'default' => 'false', 'description' => __('Make this taxonomy available via WP REST API ', 'wck' ) ),
83
  array( 'type' => 'select', 'title' => __( 'Rewrite', 'wck' ), 'slug' => 'rewrite', 'options' => array( 'true', 'false' ), 'default' => 'true', 'description' => __( 'Rewrite permalinks.', 'wck' ) ),
84
+ array( 'type' => 'select', 'title' => __( 'With Front', 'wck' ), 'slug' => 'with_front', 'options' => array( 'true', 'false' ), 'default' => 'true', 'description' => __( 'Use the defined base for permalinks.', 'wck' ) ),
85
  array( 'type' => 'text', 'title' => __( 'Rewrite Slug', 'wck' ), 'slug' => 'rewrite-slug', 'description' => __( 'Defaults to post type name.', 'wck' ) ),
86
+ );
87
 
88
+ foreach( $ct_creation_fields2 as $ct_creation_field ) {
89
+ array_push( $ct_creation_fields, $ct_creation_field );
90
+ }
91
 
92
  $args = array(
93
  'metabox_id' => 'ctc_creation_box',
107
  add_action( 'init', 'wck_ctc_create_taxonomy', 8 );
108
 
109
  function wck_ctc_create_taxonomy(){
110
+ global $wp_version;
111
  $cts = get_option('wck_ctc');
112
  if( !empty( $cts ) ){
113
  foreach( $cts as $ct ){
130
  'menu_name' => $ct['menu-name'] ? $ct['menu-name'] : $ct['plural-label']
131
  );
132
 
133
+ if( version_compare( $wp_version, '4.3', '>=' ) ) {
134
+ $labels_v43 = array( 'no_terms' => __( !empty( $ct['no_terms'] ) ? $ct['no_terms'] : "No Terms" ) );
135
 
136
+ array_push( $labels, $labels_v43 );
137
+ }
138
 
139
+ if( version_compare( $wp_version, '4.4', '>=' ) ) {
140
+ $labels_v44 = array(
141
+ 'items_list_navigation' => __( !empty( $ct['items_list_navigation'] ) ? $ct['items_list_navigation'] : "Items List Navigation" ),
142
+ 'items_list' => __( !empty( $ct['items_list'] ) ? $ct['items_list'] : "Items List" )
143
+ );
144
 
145
+ foreach( $labels_v44 as $label_v44 ) {
146
+ array_push( $labels, $label_v44 );
147
+ }
148
+ }
149
 
150
  $args = array(
151
  'labels' => $labels,
175
  $args['rewrite'] = $ct['rewrite'] == 'false' ? false : true;
176
  }
177
  else {
178
+ $rewrite_array = array();
179
+
180
+ if( !empty( $ct['rewrite-slug'] ) )
181
+ $rewrite_array['slug'] = $ct['rewrite-slug'];
182
+
183
+ if( !empty( $ct['with_front']) && $ct['with_front'] == 'false' )
184
+ $rewrite_array['with_front'] = false;
185
+
186
+ if ( count( $rewrite_array ) > 0 ) {
187
+ $args['rewrite'] = $rewrite_array;
188
  }
189
  }
190
  }
191
 
192
  register_taxonomy( $ct['taxonomy'], $object_type, apply_filters( 'wck_ctc_register_taxonomy_args', $args, $ct['taxonomy'] ) );
193
 
194
+ if( !empty( $object_type ) && !empty( $args['show_admin_column'] ) && $args['show_admin_column'] == true && !empty( $ct['sortable-admin-column'] ) && $ct['sortable-admin-column'] === 'true' ) {
195
+
196
+ if ( version_compare( phpversion(), '5.4.0', '<' ) ) {
197
+
198
+ foreach( $object_type as $post_type ) {
199
+ add_filter("manage_edit-{$post_type}_sortable_columns", create_function('$columns', '$columns["taxonomy-' . $ct["taxonomy"] . '"] = "taxonomy-' . $ct["taxonomy"] . '";return $columns;'));
200
+ }
201
+
202
  add_filter( 'posts_clauses', create_function( '$clauses, $wp_query', 'global $wpdb;
203
+ if ( is_admin() && isset( $wp_query->query[\'orderby\'] ) && \'taxonomy-'.$ct["taxonomy"].'\' == $wp_query->query[\'orderby\'] ) {
204
 
205
+ $clauses[\'join\'] .= <<<SQL
206
+ LEFT OUTER JOIN {$wpdb->term_relationships} ON {$wpdb->posts}.ID={$wpdb->term_relationships}.object_id
207
+ LEFT OUTER JOIN {$wpdb->term_taxonomy} USING (term_taxonomy_id)
208
+ LEFT OUTER JOIN {$wpdb->terms} USING (term_id)
209
+ SQL;
210
 
211
  $clauses[\'where\'] .= " AND (taxonomy = \''.$ct["taxonomy"].'\' OR taxonomy IS NULL)";
212
  $clauses[\'groupby\'] = "object_id";
213
  $clauses[\'orderby\'] = "GROUP_CONCAT({$wpdb->terms}.name ORDER BY name ASC) ";
214
  $clauses[\'orderby\'] .= ( \'ASC\' == strtoupper( $wp_query->get(\'order\') ) ) ? \'ASC\' : \'DESC\';
215
  }
216
+
217
  return $clauses;' ), 10, 2 );
218
+
219
+ } else {
220
+
221
+ foreach( $object_type as $post_type ) {
222
+ add_filter("manage_edit-{$post_type}_sortable_columns", function ( $columns ) use ( $ct ) {
223
+ $columns['taxonomy-' . $ct['taxonomy']] = 'taxonomy-' . $ct['taxonomy'];
224
+
225
+ return $columns;
226
+ });
227
+ }
228
+
229
+ add_filter( 'posts_clauses', function ( $clauses, $wp_query ) use ( $ct ) {
230
+ global $wpdb;
231
+
232
+ if ( is_admin() && isset( $wp_query->query['orderby']) && 'taxonomy-' . $ct['taxonomy'] == $wp_query->query['orderby'] ) {
233
+ $clauses['join'] .= 'LEFT OUTER JOIN '.$wpdb->term_relationships.' ON '.$wpdb->posts.'.ID='.$wpdb->term_relationships.'.object_id';
234
+ $clauses['join'] .= ' LEFT OUTER JOIN '.$wpdb->term_taxonomy.' USING (term_taxonomy_id)';
235
+ $clauses['join'] .= ' LEFT OUTER JOIN '.$wpdb->terms.' USING (term_id)';
236
+
237
+ $clauses['where'] .= ' AND (taxonomy = \'' . $ct["taxonomy"] . '\' OR taxonomy IS NULL)';
238
+ $clauses['groupby'] = 'object_id';
239
+ $clauses['orderby'] = 'GROUP_CONCAT('.$wpdb->terms.'.name ORDER BY name ASC) ';
240
+ $clauses['orderby'] .= ( 'ASC' == strtoupper( $wp_query->get('order') ) ) ? 'ASC' : 'DESC';
241
+ }
242
+
243
+ return $clauses;
244
+ }, 10, 2);
245
+
246
  }
247
  }
248
  }
409
  {
410
  ?>
411
  <a href="http://www.cozmoslabs.com/wck-custom-fields-custom-post-types-plugin/?utm_source=wpbackend&utm_medium=clientsite&utm_campaign=WCKFree"><img
412
+ src="<?php echo plugins_url('/images/banner_pro.png', __FILE__) ?>?v=1" width="254" height="448"
413
+ alt="WCK-PRO"/></a>
414
+ <?php
415
  }
416
  }
417
 
490
  }
491
  }
492
  }
 
 
wck-template-api/wck-field-preprocess.php CHANGED
@@ -1,4 +1,4 @@
1
- <?php
2
  /* Copyright 2013 cozmoslabs.com (email : hello@cozmoslabs.com)
3
  This program is free software; you can redistribute it and/or modify
4
  it under the terms of the GNU General Public License as published by
@@ -19,7 +19,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
  * We're converting new lines to <br /> tags
20
  *
21
  * @since 1.1.5
22
- *
23
  * @param string $field The actual field content
24
  * @return string $field The processed field
25
  */
@@ -33,7 +33,7 @@ function wck_preprocess_field_textarea( $field ){
33
  * We're returnig an array with the selected checkboxes
34
  *
35
  * @since 1.1.5
36
- *
37
  * @param string $field The actual field content
38
  * @return string $checkbox The processed field
39
  */
@@ -51,12 +51,12 @@ function wck_preprocess_field_checkbox( $field ){
51
  * We're returnig a coma separated list with the selected values - not labels
52
  *
53
  * @since 1.1.5
54
- *
55
  * @param string $field The actual field content
56
  * @return string $checkbox The processed field
57
  */
58
  add_filter( 'wck_output_the_field_checkbox', 'wck_preprocess_the_field_checkbox', 10 );
59
- function wck_preprocess_the_field_checkbox( $field ){
60
  if( !empty( $field ) ){
61
  $checkbox_list = implode( ', ', $field );
62
  return $checkbox_list;
@@ -69,7 +69,7 @@ function wck_preprocess_the_field_checkbox( $field ){
69
  * We're returning an array for images and an object for normal files
70
  *
71
  * @since 1.1.5
72
- *
73
  * @param string $field The actual field content
74
  * @return string $upload The processed field
75
  */
@@ -82,52 +82,43 @@ function wck_preprocess_field_upload( $field ){
82
  if ( is_null( get_post( $field ) ) )
83
  return false;
84
 
 
 
 
 
 
 
 
 
 
 
 
85
  if ( wp_attachment_is_image( $field ) ) {
86
-
87
- $attachment = get_post( $field );
88
 
89
- // create array to hold value data
90
  $src = wp_get_attachment_image_src( $attachment->ID, 'full' );
91
-
92
- $value = array(
93
- 'id' => $attachment->ID,
94
- 'alt' => get_post_meta($attachment->ID, '_wp_attachment_image_alt', true),
95
- 'title' => $attachment->post_title,
96
- 'caption' => $attachment->post_excerpt,
97
- 'description' => $attachment->post_content,
98
- 'url' => $src[0],
99
- 'width' => $src[1],
100
- 'height' => $src[2],
101
- 'sizes' => array(),
102
- );
103
-
104
  // find all image sizes
105
  $image_sizes = get_intermediate_image_sizes();
106
-
107
- if( $image_sizes )
108
- {
109
- foreach( $image_sizes as $image_size )
110
- {
111
  // find src
112
  $src = wp_get_attachment_image_src( $attachment->ID, $image_size );
113
-
114
  // add src
115
  $value[ 'sizes' ][ $image_size ] = $src[0];
116
  $value[ 'sizes' ][ $image_size . '-width' ] = $src[1];
117
  $value[ 'sizes' ][ $image_size . '-height' ] = $src[2];
118
  }
119
- }
120
-
121
- return $value;
122
-
123
- } else {
124
-
125
- $attachement = get_post( $field );
126
-
127
- return $attachement;
128
-
129
- }
130
-
131
  }
132
 
133
  /**
@@ -135,7 +126,7 @@ function wck_preprocess_field_upload( $field ){
135
  * We're returnig an url.
136
  *
137
  * @since 1.1.5
138
- *
139
  */
140
  add_filter( 'wck_output_the_field_upload', 'wck_preprocess_the_field_upload', 10 );
141
  function wck_preprocess_the_field_upload( $field ){
@@ -143,15 +134,15 @@ function wck_preprocess_the_field_upload( $field ){
143
  if( $field === false ){
144
  return;
145
  }
146
-
147
  if ( is_object( $field ) ){
148
  return $field->guid;
149
  }
150
-
151
  if ( is_array( $field ) ){
152
  return $field['url'];
153
  }
154
-
155
  }
156
 
157
 
@@ -160,14 +151,14 @@ function wck_preprocess_the_field_upload( $field ){
160
  * We're returnig an array with user related information
161
  *
162
  * @since 1.1.5
163
- *
164
  * @param string $field The actual field content
165
  * @return string $user The processed field
166
  */
167
  add_filter( 'wck_output_get_field_user-select', 'wck_preprocess_field_user_select', 10 );
168
  function wck_preprocess_field_user_select( $uid ){
169
  $user_data = get_userdata( $uid );
170
-
171
  if ( $user_data ){
172
  $user_array = array();
173
  $user_array['ID'] = $uid;
@@ -181,13 +172,13 @@ function wck_preprocess_field_user_select( $uid ){
181
  $user_array['user_registered'] = $user_data->user_registered;
182
  $user_array['user_description'] = $user_data->user_description;
183
  $user_array['user_avatar'] = get_avatar( $uid );
184
-
185
  return $user_array;
186
-
187
  } else {
188
-
189
  return false;
190
-
191
  }
192
  }
193
 
@@ -196,7 +187,7 @@ function wck_preprocess_field_user_select( $uid ){
196
  * We're returnig the Display Name
197
  *
198
  * @since 1.1.5
199
- *
200
  */
201
  add_filter( 'wck_output_the_field_user-select', 'wck_preprocess_the_field_user_select', 10 );
202
  function wck_preprocess_the_field_user_select( $user ){
@@ -204,7 +195,7 @@ function wck_preprocess_the_field_user_select( $user ){
204
  if( $user === false ){
205
  return;
206
  }
207
-
208
  if( is_array( $user ) ){
209
  return $user['display_name'];
210
  }
@@ -216,20 +207,20 @@ function wck_preprocess_the_field_user_select( $user ){
216
  * We're returnig a post object
217
  *
218
  * @since 1.1.5
219
- *
220
  * @param string $field The actual field content
221
  * @return string $user The processed field
222
  */
223
  add_filter( 'wck_output_get_field_cpt-select', 'wck_preprocess_field_cpt_select', 10 );
224
  function wck_preprocess_field_cpt_select( $id ){
225
-
226
  if ( $id == '' || !is_numeric( $id ) )
227
  return false;
228
-
229
  $post = get_post( $id );
230
  if( is_null( $post ) )
231
  return false;
232
-
233
  return $post;
234
  }
235
 
@@ -238,15 +229,15 @@ function wck_preprocess_field_cpt_select( $id ){
238
  * We're returnig the post title.
239
  *
240
  * @since 1.1.5
241
- *
242
  */
243
  add_filter( 'wck_output_the_field_cpt-select', 'wck_preprocess_the_field_cpt_select', 10 );
244
  function wck_preprocess_the_field_cpt_select( $post ){
245
-
246
  if( $post == false ){
247
  return;
248
  }
249
-
250
  if( is_object( $post ) ){
251
  return $post->post_title;
252
  }
1
+ <?php
2
  /* Copyright 2013 cozmoslabs.com (email : hello@cozmoslabs.com)
3
  This program is free software; you can redistribute it and/or modify
4
  it under the terms of the GNU General Public License as published by
19
  * We're converting new lines to <br /> tags
20
  *
21
  * @since 1.1.5
22
+ *
23
  * @param string $field The actual field content
24
  * @return string $field The processed field
25
  */
33
  * We're returnig an array with the selected checkboxes
34
  *
35
  * @since 1.1.5
36
+ *
37
  * @param string $field The actual field content
38
  * @return string $checkbox The processed field
39
  */
51
  * We're returnig a coma separated list with the selected values - not labels
52
  *
53
  * @since 1.1.5
54
+ *
55
  * @param string $field The actual field content
56
  * @return string $checkbox The processed field
57
  */
58
  add_filter( 'wck_output_the_field_checkbox', 'wck_preprocess_the_field_checkbox', 10 );
59
+ function wck_preprocess_the_field_checkbox( $field ){
60
  if( !empty( $field ) ){
61
  $checkbox_list = implode( ', ', $field );
62
  return $checkbox_list;
69
  * We're returning an array for images and an object for normal files
70
  *
71
  * @since 1.1.5
72
+ *
73
  * @param string $field The actual field content
74
  * @return string $upload The processed field
75
  */
82
  if ( is_null( get_post( $field ) ) )
83
  return false;
84
 
85
+ $attachment = get_post( $field );
86
+
87
+ // create array to hold value data
88
+ $value = array(
89
+ 'id' => $attachment->ID,
90
+ 'alt' => get_post_meta($attachment->ID, '_wp_attachment_image_alt', true),
91
+ 'title' => $attachment->post_title,
92
+ 'caption' => $attachment->post_excerpt,
93
+ 'description' => $attachment->post_content
94
+ );
95
+
96
  if ( wp_attachment_is_image( $field ) ) {
 
 
97
 
 
98
  $src = wp_get_attachment_image_src( $attachment->ID, 'full' );
99
+
100
+ $value['url'] = $src[0];
101
+ $value['width'] = $src[1];
102
+ $value['height'] = $src[2];
103
+
 
 
 
 
 
 
 
 
104
  // find all image sizes
105
  $image_sizes = get_intermediate_image_sizes();
106
+
107
+ if( $image_sizes ) {
108
+ foreach( $image_sizes as $image_size ) {
 
 
109
  // find src
110
  $src = wp_get_attachment_image_src( $attachment->ID, $image_size );
111
+
112
  // add src
113
  $value[ 'sizes' ][ $image_size ] = $src[0];
114
  $value[ 'sizes' ][ $image_size . '-width' ] = $src[1];
115
  $value[ 'sizes' ][ $image_size . '-height' ] = $src[2];
116
  }
117
+ }
118
+ } else
119
+ $value['url'] = wp_get_attachment_url( $attachment->ID );
120
+
121
+ return $value;
 
 
 
 
 
 
 
122
  }
123
 
124
  /**
126
  * We're returnig an url.
127
  *
128
  * @since 1.1.5
129
+ *
130
  */
131
  add_filter( 'wck_output_the_field_upload', 'wck_preprocess_the_field_upload', 10 );
132
  function wck_preprocess_the_field_upload( $field ){
134
  if( $field === false ){
135
  return;
136
  }
137
+
138
  if ( is_object( $field ) ){
139
  return $field->guid;
140
  }
141
+
142
  if ( is_array( $field ) ){
143
  return $field['url'];
144
  }
145
+
146
  }
147
 
148
 
151
  * We're returnig an array with user related information
152
  *
153
  * @since 1.1.5
154
+ *
155
  * @param string $field The actual field content
156
  * @return string $user The processed field
157
  */
158
  add_filter( 'wck_output_get_field_user-select', 'wck_preprocess_field_user_select', 10 );
159
  function wck_preprocess_field_user_select( $uid ){
160
  $user_data = get_userdata( $uid );
161
+
162
  if ( $user_data ){
163
  $user_array = array();
164
  $user_array['ID'] = $uid;
172
  $user_array['user_registered'] = $user_data->user_registered;
173
  $user_array['user_description'] = $user_data->user_description;
174
  $user_array['user_avatar'] = get_avatar( $uid );
175
+
176
  return $user_array;
177
+
178
  } else {
179
+
180
  return false;
181
+
182
  }
183
  }
184
 
187
  * We're returnig the Display Name
188
  *
189
  * @since 1.1.5
190
+ *
191
  */
192
  add_filter( 'wck_output_the_field_user-select', 'wck_preprocess_the_field_user_select', 10 );
193
  function wck_preprocess_the_field_user_select( $user ){
195
  if( $user === false ){
196
  return;
197
  }
198
+
199
  if( is_array( $user ) ){
200
  return $user['display_name'];
201
  }
207
  * We're returnig a post object
208
  *
209
  * @since 1.1.5
210
+ *
211
  * @param string $field The actual field content
212
  * @return string $user The processed field
213
  */
214
  add_filter( 'wck_output_get_field_cpt-select', 'wck_preprocess_field_cpt_select', 10 );
215
  function wck_preprocess_field_cpt_select( $id ){
216
+
217
  if ( $id == '' || !is_numeric( $id ) )
218
  return false;
219
+
220
  $post = get_post( $id );
221
  if( is_null( $post ) )
222
  return false;
223
+
224
  return $post;
225
  }
226
 
229
  * We're returnig the post title.
230
  *
231
  * @since 1.1.5
232
+ *
233
  */
234
  add_filter( 'wck_output_the_field_cpt-select', 'wck_preprocess_the_field_cpt_select', 10 );
235
  function wck_preprocess_the_field_cpt_select( $post ){
236
+
237
  if( $post == false ){
238
  return;
239
  }
240
+
241
  if( is_object( $post ) ){
242
  return $post->post_title;
243
  }
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: 2.2.0
7
  Author URI: http://www.cozmoslabs.com
8
  Text Domain: wck
9
  Domain Path: /languages
@@ -28,7 +28,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28
 
29
  define( 'WCK_PLUGIN_DIR', WP_PLUGIN_DIR . '/' . dirname( plugin_basename( __FILE__ ) ) );
30
  define( 'WCK_PLUGIN_DIR_URL', plugin_dir_url( __FILE__ ) );
31
- define( 'WCK_PLUGIN_VERSION', '2.5.3' );
32
 
33
  /* ready for localization */
34
  $current_theme = wp_get_theme();
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.2.1
7
  Author URI: http://www.cozmoslabs.com
8
  Text Domain: wck
9
  Domain Path: /languages
28
 
29
  define( 'WCK_PLUGIN_DIR', WP_PLUGIN_DIR . '/' . dirname( plugin_basename( __FILE__ ) ) );
30
  define( 'WCK_PLUGIN_DIR_URL', plugin_dir_url( __FILE__ ) );
31
+ define( 'WCK_PLUGIN_VERSION', '2.2.1' );
32
 
33
  /* ready for localization */
34
  $current_theme = wp_get_theme();
wordpress-creation-kit-api/wck-fep/wck-fep.php CHANGED
@@ -3,44 +3,44 @@
3
 
4
  class WCK_FrontEnd_Posting extends Wordpress_Creation_Kit{
5
 
6
- private $defaults = array(
7
  'form_title' => 'Form',
8
  'post_type' => 'post',
9
  'form_name' => '',
10
  'admin_approval' => 'no',
11
- 'anonymous_posting' => 'no',
12
  'assign_to_user' => 1,
13
  'meta_array' => array(),
14
  'taxonomies' => array(),
15
  'single_cfcs' => array()
16
  );
17
  private $args;
18
-
19
  /* this will hold the meta_arrays for any single CFCs */
20
  private $single_cfcs;
21
-
22
-
23
- static $wck_fep_add_scripts;
24
-
25
  /* Constructor method for the class. */
26
- function __construct( $args ) {
27
-
28
  /* Merge the input arguments and the defaults. */
29
- $this->args = wp_parse_args( $args, $this->defaults );
30
 
31
- /* populate single_cfcs arg with the meta_array of any single CFCs that are added to the form.
32
  the meta_name will be used as the key */
33
  if( function_exists( 'wck_cfc_create_boxes_args' ) ){
34
  if( !empty( $this->args['meta_array'] ) ){
35
  foreach ( $this->args['meta_array'] as $details ){
36
  $all_box_args = wck_cfc_create_boxes_args();
37
- /* add single CFCs */
38
  if( !empty( $all_box_args ) ){
39
- foreach( $all_box_args as $box_args ){
40
- if( ( $box_args['post_type'] == $this->args['post_type'] ) && ( $box_args['metabox_title'] == $details['title'] ) ){
41
  /* treat single cfcs case */
42
  if( $box_args['single'] )
43
- $this->single_cfcs[$box_args['meta_name']] = $box_args['meta_array'];
44
  $this->single_cfcs[$box_args['meta_name'].'_unserialize_fields'] = $box_args['unserialize_fields'];
45
  }
46
  }
@@ -48,35 +48,35 @@ class WCK_FrontEnd_Posting extends Wordpress_Creation_Kit{
48
  }
49
  }
50
  }
51
-
52
  /* register the shortcode */
53
  add_shortcode( 'fep', array( &$this, 'wck_fep_form_in_frontend') );
54
-
55
  /*print scripts*/
56
  add_action( 'get_header', array( &$this, 'wck_fep_register_script' ), 12 );
57
  add_action( 'wp_footer', array( &$this, 'wck_fep_print_script' ) );
58
  add_action( 'wp_head', array( &$this, 'wck_fep_print_ajax_url' ) );
59
  add_action( 'wp_enqueue_scripts', array( &$this, 'wck_fep_enqueue_scripts' ) );
60
-
61
  // Set up the AJAX hooks
62
  add_action( "wp_ajax_wck_fep_add_post".$this->args['form_name'], array( &$this, 'wck_fep_add_post') );
63
  add_action( "wp_ajax_nopriv_wck_fep_add_post".$this->args['form_name'], array( &$this, 'wck_fep_add_post') );
64
-
65
  add_action("wp_ajax_wck_add_meta".$this->args['form_name'], array( &$this, 'wck_add_meta') );
66
  add_action("wp_ajax_nopriv_wck_add_meta".$this->args['form_name'], array( &$this, 'wck_add_meta') );
67
-
68
  add_action("wp_ajax_wck_fep_create_frontend_form_".$this->args['form_name'], array( &$this, 'wck_fep_create_frontend_form') );
69
- add_action("wp_ajax_nopriv_wck_fep_create_frontend_form_".$this->args['form_name'], array( &$this, 'wck_fep_create_frontend_form') );
70
- }
71
-
72
  /**
73
  * The function used to register scripts used by FEP
74
  *
75
- * @since 1.0.0
76
  */
77
  static function wck_fep_register_script(){
78
  //datepicker
79
- wp_enqueue_script('jquery-ui-datepicker');
80
  wp_enqueue_style('jquery-style', plugins_url( '', dirname(__FILE__) ).'/assets/datepicker/datepicker.css');
81
 
82
  //colorpicker
@@ -97,104 +97,104 @@ class WCK_FrontEnd_Posting extends Wordpress_Creation_Kit{
97
  wp_enqueue_style( 'wck-google-maps-style', plugin_dir_url( __FILE__ ) . '../assets/map/map.css' );
98
  }
99
 
100
- /* FEP script */
101
  wp_register_script( 'wck-fep', plugins_url('wck-fep.js', __FILE__ ), array('jquery'), '1.0', true );
102
  wp_register_style( 'wck-fep-css', plugins_url('wck-fep.css', __FILE__ ) );
103
- /* register WCK script for frontend */
104
  wp_register_script( 'wck-js', plugins_url( '', dirname(__FILE__) ).'/wordpress-creation-kit.js', array('jquery', 'jquery-ui-datepicker'), '1.0', true );
105
-
106
- // wysiwyg
107
- wp_register_script( 'wck-ckeditor', plugins_url( '', dirname(__FILE__) ).'/assets/js/ckeditor/ckeditor.js', array(), '1.0', true );
108
-
109
- /* media upload wck script */
110
  wp_register_script('wck-upload-field', plugins_url('/../fields/upload.js', __FILE__), array('jquery') );
111
  }
112
-
113
  /**
114
  * The function used to print scripts used by FEP in the footer of the page
115
  *
116
- * @since 1.0.0
117
  */
118
  static function wck_fep_print_script() {
119
  /* if the static var set by the shortcode isn't true do nothing */
120
  if ( ! self::$wck_fep_add_scripts )
121
  return;
122
-
123
  wp_print_scripts('wck-fep');
124
  wp_print_styles('wck-fep-css');
125
  wp_print_scripts('wck-js');
126
-
127
  wp_print_scripts( 'jquery-ui-draggable' );
128
  wp_print_scripts( 'jquery-ui-droppable' );
129
  wp_print_scripts( 'jquery-ui-sortable' );
130
- wp_print_styles( 'thickbox' );
131
- wp_print_scripts( 'thickbox' );
132
-
133
- // wysiwyg
134
  wp_print_scripts( 'wck-ckeditor' );
135
 
136
  /* media upload wck script */
137
  wp_print_scripts( 'wck-upload-field' );
138
  }
139
-
140
  /**
141
  * The function used to print ajax url used by FEP in the header of the page
142
  *
143
- * @since 1.0.0
144
  */
145
  static function wck_fep_print_ajax_url() {
146
  /* ajax url for frontend */
147
  echo '<script type="text/javascript">var wckAjaxurl = "'. admin_url('admin-ajax.php') .'";</script>';
148
  }
149
-
150
  /**
151
  * The function to enqueue jquery in header of the theme
152
  *
153
- * @since 1.0.0
154
  */
155
  static function wck_fep_enqueue_scripts(){
156
  wp_enqueue_script( 'jquery' );
157
  }
158
-
159
-
160
  /**
161
  * Shortcode Function
162
  *
163
- * @since 1.0.0
164
- *
165
- * @param array $atts Shortcode attributes
166
  * @return string $output form container and js ajax call to load the actual form.
167
- */
168
- function wck_fep_form_in_frontend( $atts ){
169
-
170
  /* extract shortcode args */
171
  extract( shortcode_atts( array(
172
- 'form_name' => ''
173
  ), $atts ) );
174
-
175
- /* the login form can't get the $_GET['loginerror'] from the url because it is loaded with ajax and we need to send it through post */
176
  if( isset( $_GET['loginerror'] ) )
177
  $loginerror = ', loginerror:\''. $_GET['loginerror'].'\'' ;
178
  else
179
  $loginerror = '';
180
-
181
  /* set the static var to true */
182
  self::$wck_fep_add_scripts = true;
183
-
184
  /* media upload add here */
185
  wp_enqueue_media();
186
-
187
  $output = "<div class='". $form_name ." fep-container";
188
  if( isset( $_GET['action'] ) && $_GET['action'] == 'edit' )
189
  $output .= " fep-edit";
190
  $output .= "'><div id='fep-ajax-loading'></div></div>";
191
-
192
-
193
  if( !empty( $_GET['action'] ) )
194
  $action = sanitize_text_field( $_GET['action'] );
195
  else
196
  $action = '';
197
-
198
  if( !empty( $_GET['post_id'] ) )
199
  $post_id = absint( $_GET['post_id'] );
200
  else
@@ -215,27 +215,27 @@ class WCK_FrontEnd_Posting extends Wordpress_Creation_Kit{
215
  jQuery('.fep-container.".$form_name."').html(response);
216
  jQuery( '#fep-ajax-loading' ).remove();
217
  jQuery(mb_sortable_elements);
218
- });
219
- </script>";
220
-
221
-
222
  return $output;
223
  }
224
-
225
  /**
226
  * Function that builds the form
227
  *
228
- * @since 1.0.0
229
- */
230
  function wck_fep_create_frontend_form( ){
231
-
232
  /* check for anonymous posting */
233
  if( $this->args['anonymous_posting'] == 'no' && !is_user_logged_in() ){
234
  /* get login logout form */
235
- $lilo_form = wck_fep_output_lilo_form();
236
  die( $lilo_form );
237
  }
238
-
239
  if( !empty( $_POST['action_type'] ) )
240
  $action = sanitize_text_field( $_POST['action_type'] );
241
  else
@@ -244,7 +244,7 @@ class WCK_FrontEnd_Posting extends Wordpress_Creation_Kit{
244
  $post_id = absint( $_POST['post_id'] );
245
  else
246
  $post_id = '';
247
-
248
  /* take care of auto_drafts only when adding posts ( the default case ) */
249
  if( $action == '' ){
250
  /* delete auto drafts older than 12 hours */
@@ -252,30 +252,30 @@ class WCK_FrontEnd_Posting extends Wordpress_Creation_Kit{
252
  'post_status' => 'auto-draft',
253
  'numberposts' => -1,
254
  'suppress_filters' => false,
255
- 'post_type' => 'any'
256
  );
257
-
258
  add_filter( 'posts_where', array( &$this, 'wck_fep_filter_auto_drafts_where' ) );
259
  $auto_drafts = get_posts( $args );
260
  remove_filter( 'posts_where', array( &$this, 'wck_fep_filter_auto_drafts_where' ) );
261
-
262
-
263
  if( !empty($auto_drafts) ){
264
  foreach( $auto_drafts as $auto_draft ){
265
-
266
  /* also delete all post meta for the auto-draft post */
267
- $meta_keys = get_post_custom_keys( $auto_draft->ID );
268
  if( !empty($meta_keys) ){
269
  foreach( $meta_keys as $meta_key ){
270
-
271
  delete_post_meta( $auto_draft->ID, $meta_key );
272
  }
273
  }
274
-
275
  /* delete attachemnts for the auto draft */
276
- $args = array(
277
  'post_parent' => $auto_draft->ID,
278
- 'post_type' => 'attachment',
279
  'numberposts' => -1
280
  );
281
  $attachments = get_children( $args );
@@ -284,46 +284,46 @@ class WCK_FrontEnd_Posting extends Wordpress_Creation_Kit{
284
  wp_delete_attachment( $attachment->ID );
285
  }
286
  }
287
-
288
  /* delete the post */
289
  wp_delete_post( $auto_draft->ID, true );
290
  }
291
  }
292
  }
293
-
294
- /* create a new post? not if we allready have a $post_id ( probabily edit case )*/
295
  if ( !$post_id ) {
296
  global $post;
297
  $post_id = wp_insert_post( array( 'post_title' => __( 'Auto Draft' ), 'post_type' => $this->args['post_type'], 'post_status' => 'auto-draft' ) );
298
- $post = get_post( $post_id );
299
  }
300
-
301
  /* create default post elements */
302
  $form = self::create_add_form( $this->args['meta_array'], $this->args['form_name'], $post_id, $action );
303
 
304
  echo $form;
305
-
306
  exit();
307
  }
308
-
309
  /**
310
  * Filtering function that will add our where clause to the query
311
  *
312
- * @since 1.0.0
313
- */
314
  function wck_fep_filter_auto_drafts_where( $where = '' ){
315
- // posts older than 12 hours
316
  $where .= " AND post_date <= '" . date('Y-m-d H:i:s', strtotime('-12 hours')) . "'";
317
  return $where;
318
- }
319
-
320
-
321
  /**
322
  * Function that creates the add form with the default fields
323
  *
324
- * @since 1.0.0
325
- *
326
- * @param array $fields array of default fields
327
  * @param string $form_name the name of the form
328
  * @param int $post_id the post ID
329
  * @return string $output form container and js ajax call to load the actual form.
@@ -350,48 +350,48 @@ class WCK_FrontEnd_Posting extends Wordpress_Creation_Kit{
350
  }
351
 
352
  $form = '<form id="'. $form_name .'" method="post" action="">';
353
-
354
- $element_id = 0;
355
-
356
  if( function_exists( 'wck_cfc_create_boxes_args' ) )
357
  $all_box_args = wck_cfc_create_boxes_args();
358
-
359
  if( !empty( $fields ) ){
360
  foreach( $fields as $details ){
361
 
362
- do_action( "wck_fep_before_form_{$form_name}_element_{$element_id}" );
363
 
364
  $form .= apply_filters( "wck_fep_filter_before_form_{$form_name}_element_{$element_id}", '<div id="fep-'. Wordpress_Creation_Kit::wck_generate_slug( $details['title'] ) .'" class="fep-element-wrap">', $details );
365
-
366
- if( empty( $details['cfc'] ) ){
367
-
368
  if( $action == 'edit' ){
369
  /* build edit values depending on the field */
370
- $value = self::wck_fep_get_edit_value( $post_id, $details );
371
  }
372
  else
373
  $value = apply_filters('wck_fep_default_value_' . $form_name . '_' . Wordpress_Creation_Kit::wck_generate_slug($details['title']), '');
374
 
375
  $form .= parent::wck_output_form_field( $form_name, $details, $value, 'fep', $post_id );
376
-
377
  }
378
-
379
  else{
380
-
381
- /* add CFC boxes created with Custom Fields Creator */
382
  if( !empty( $all_box_args ) ){
383
- foreach( $all_box_args as $box_args ){
384
- if( ( $box_args['post_type'] == $this->args['post_type'] ) && ( $box_args['metabox_title'] == $details['title'] ) ){
385
-
386
  /* treat single cfcs case */
387
- if( $box_args['single'] ){
388
- $form .= '<div id="'. $box_args['meta_name'].'" class="single-cfc">';
389
  if( !empty( $box_args['meta_array'] ) ){
390
  foreach( $box_args['meta_array'] as $details ){
391
-
392
- if( $action == 'edit' ){
393
  /* build edit values depending on the field */
394
- $value = self::wck_fep_get_edit_value( $post_id, $details, $box_args['meta_name'] );
395
  }
396
  else {
397
  if( isset( $details['default'] ) )
@@ -405,33 +405,33 @@ class WCK_FrontEnd_Posting extends Wordpress_Creation_Kit{
405
  }
406
  }
407
  $form .= '</div>';
408
- }
409
- else{
410
  ob_start();
411
  parent::create_add_form( $box_args['meta_array'], $box_args['meta_name'], get_post($post_id), 'fep' );
412
  $parent_form = ob_get_contents();
413
  ob_end_clean();
414
-
415
- $form .= $parent_form;
416
- $form .= parent::wck_output_meta_content( $box_args['meta_name'], $post_id, $box_args['meta_array'], $box_args );
417
- }
418
- }
419
  }
420
- }
421
-
422
  }
423
  $form .= apply_filters( "wck_fep_filter_after_form_{$form_name}_element_{$element_id}", '</div>' );
424
-
425
  do_action( "wck_after_form_{$form_name}_element_{$element_id}" );
426
-
427
  $element_id++;
428
  }
429
  }
430
-
431
-
432
- if( $action == 'edit' )
433
  $submit_text = apply_filters( 'wck_fep_form_button_update', __( 'Update Post', 'wck' ), $form_name );
434
- else
435
  $submit_text = apply_filters( 'wck_fep_form_button_add', __( 'Add Post', 'wck' ), $form_name );
436
 
437
  if (function_exists('icl_register_string') && function_exists('icl_translate') ) {
@@ -440,26 +440,26 @@ class WCK_FrontEnd_Posting extends Wordpress_Creation_Kit{
440
  }
441
 
442
  $form .= '<input type="submit" id="submit_'.$form_name.'" value="'. $submit_text .'" onclick="wckFepAddPost(\''. $form_name .'\', '. $post_id .', \''. $action .'\', \''. $nonce .'\');return false;"/>';
443
-
444
- $form .= '</form>';
445
-
446
- return $form;
447
  }
448
-
449
-
450
  /**
451
  * calls parrent function. till I figure out how to call parent function on ajax hook set up in child class
452
  */
453
  function wck_add_meta(){
454
  parent::wck_add_meta();
455
  }
456
-
457
  /* function that gets the values of the default post fields for editing purpouses */
458
  function wck_fep_get_edit_value( $post_id, $details, $meta_name = '' ){
459
  $value = '';
460
-
461
  if( $meta_name == '' ){
462
- $post = get_post( $post_id );
463
  switch ( $details['title'] ) {
464
  case 'Post Title':
465
  $value = get_the_title( $post->ID );
@@ -480,7 +480,7 @@ class WCK_FrontEnd_Posting extends Wordpress_Creation_Kit{
480
 
481
  if( $details['title'] == $taxonomy->label || $details['slug'] == $taxonomy->name ){
482
  $object_terms = wp_get_object_terms( $post->ID, $taxonomy->name );
483
-
484
  if(!empty($object_terms)){
485
  if(!is_wp_error( $object_terms )){
486
  foreach($object_terms as $term){
@@ -496,9 +496,9 @@ class WCK_FrontEnd_Posting extends Wordpress_Creation_Kit{
496
  }
497
  }
498
  }
499
- }
500
  }
501
- }
502
  }
503
  }
504
  else{
@@ -506,42 +506,42 @@ class WCK_FrontEnd_Posting extends Wordpress_Creation_Kit{
506
  if( isset( $meta_values[0][Wordpress_Creation_Kit::wck_generate_slug( $details['title'], $details )] ) )
507
  $value = $meta_values[0][Wordpress_Creation_Kit::wck_generate_slug( $details['title'], $details )];
508
  }
509
-
510
  return $value;
511
  }
512
-
513
-
514
  /**
515
  * AJAX Function that ads the post
516
  *
517
- * @since 1.0.0
518
  */
519
  function wck_fep_add_post(){
520
  check_ajax_referer( 'wck-fep-add-post' );
521
-
522
  $meta = sanitize_text_field( $_POST['meta'] );
523
  $post_ID = absint( $_POST['postid'] );
524
  if( !empty( $_POST['values'] ) )
525
- $values = $_POST['values'];
526
  else
527
  $values = array();
528
  $single_cfcs = (!empty( $_POST['single_cfcs'] )) ? $_POST['single_cfcs'] : array() ;
529
  $action_type = sanitize_text_field( $_POST['action_type'] );
530
-
531
- /* check required fields */
532
  $errors = array();
533
-
534
- /* check required fields of single cfcs */
535
  if( !empty( $single_cfcs ) ){
536
  foreach( $single_cfcs as $meta_name => $single_values ){
537
  /* check required fields */
538
- $errors[$meta_name] = self::wck_test_required( $this->single_cfcs[$meta_name], $meta_name, $single_values, 0 );
539
- }
540
  }
541
-
542
  /* check required fields for default post fields */
543
  $errors[$meta] = self::wck_test_required( $this->args['meta_array'], $meta, $values, 0 );
544
-
545
  /* combine the errors from the default fields with single cfcs */
546
  $errors_json = array( 'error' => '', 'errorfields' => array() );
547
  if( !empty( $errors ) ){
@@ -552,12 +552,12 @@ class WCK_FrontEnd_Posting extends Wordpress_Creation_Kit{
552
  }
553
  }
554
  }
555
-
556
  if( !empty( $errors_json['error']) ){
557
  header( 'Content-type: application/json' );
558
  die( json_encode( $errors_json ) );
559
- }
560
-
561
  /* if any single cfcs update the post meta */
562
  if( !empty( $single_cfcs ) ){
563
  foreach( $single_cfcs as $meta_name => $single_values ){
@@ -570,9 +570,9 @@ class WCK_FrontEnd_Posting extends Wordpress_Creation_Kit{
570
  update_post_meta($post_ID, $name, $value);
571
  }
572
  }
573
-
574
- /* if unserialize_fields is true add for each entry separate post meta for every element of the form */
575
- if( $this->single_cfcs[$meta_name.'_unserialize_fields'] ){
576
  $meta_suffix = 1;
577
  if( !empty( $single_values ) ){
578
  foreach( $single_values as $name => $value ){
@@ -580,10 +580,10 @@ class WCK_FrontEnd_Posting extends Wordpress_Creation_Kit{
580
  }
581
  }
582
  }
583
-
584
  }
585
  }
586
-
587
  /* treat empty keys in our $_POST values */
588
  $expected_keys = array('post-title', 'post-content', 'post-excerpt');
589
  foreach( $expected_keys as $expected_key ){
@@ -591,7 +591,7 @@ class WCK_FrontEnd_Posting extends Wordpress_Creation_Kit{
591
  $values[$expected_key] = '';
592
  }
593
  }
594
-
595
  $wck_fep_new_post = array(
596
  'ID' => $post_ID,
597
  'post_content' => $values['post-content'],
@@ -635,52 +635,52 @@ class WCK_FrontEnd_Posting extends Wordpress_Creation_Kit{
635
 
636
  /* post status */
637
  if( $this->args['admin_approval'] == 'yes' )
638
- $wck_fep_new_post['post_status'] = 'draft';
639
- else
640
  $wck_fep_new_post['post_status'] = 'publish';
641
 
642
  /* post author */
643
  if( $this->args['anonymous_posting'] == 'yes' )
644
- $wck_fep_new_post['post_author'] = $this->args['assign_to_user'];
645
- else
646
  $wck_fep_new_post['post_author'] = get_current_user_id();
647
-
648
-
649
  if( !empty( $values['featured-image'] ) ){
650
  set_post_thumbnail( $post_ID, $values['featured-image'] );
651
- }
652
-
653
  /* set comments status of the posts according to the default comment status */
654
  $comments_status = get_option( 'default_comment_status' );
655
  if( empty( $comments_status ) )
656
- $comments_status = 'closed';
657
  $wck_fep_new_post['comment_status'] = $comments_status;
658
 
659
  // Insert the post into the database
660
- $post_id = wp_insert_post( $wck_fep_new_post );
661
-
662
-
663
  /* take care of taxonomies */
664
  if( !empty( $this->args['taxonomies'] ) ){
665
  foreach( $this->args['taxonomies'] as $taxonomy ){
666
-
667
  $tax_names = $values[ Wordpress_Creation_Kit::wck_generate_slug( $taxonomy->label, array( 'slug' => $taxonomy->name ) ) ];
668
-
669
- if( !empty( $tax_names ) ){
670
- $tax_names = explode( ',', $tax_names );
671
-
672
- /* strip white spaces */
673
  if( !empty( $tax_names ) ){
674
  foreach( $tax_names as $key => $tax_name ){
675
  $tax_names[$key] = trim( $tax_name );
676
  }
677
  }
678
-
679
  /* get term ids by name and build the terms array */
680
  $terms = array();
681
  if( !empty( $tax_names ) ){
682
  foreach( $tax_names as $tax_name ){
683
- $idObj = get_term_by( 'name', htmlspecialchars( $tax_name ), $taxonomy->name );
684
  if( $idObj != false )
685
  $terms[] = $idObj->term_id;
686
  else{
@@ -696,23 +696,23 @@ class WCK_FrontEnd_Posting extends Wordpress_Creation_Kit{
696
  }
697
  }
698
  }
699
-
700
- if( !empty( $terms ) ){
701
  //to make sure the terms IDs are integers:
702
  $terms = array_map('intval', $terms);
703
- $terms = array_unique( $terms );
704
- $set_result = wp_set_object_terms( intval($post_ID), $terms, $taxonomy->name );
705
  }
706
  }
707
  }
708
  }
709
-
710
  if( $action_type == '' )
711
  do_action( 'wck_fep_add_post', $wck_fep_new_post, get_current_user_id() );
712
  else if( $action_type == 'edit' )
713
  do_action( 'wck_fep_update_post', $wck_fep_new_post, get_current_user_id() );
714
-
715
- if( $action_type == '' )
716
  $message = apply_filters( 'wck_fep_post_added_message', __( 'Post Added', 'wck' ), $meta );
717
  else if( $action_type == 'edit' )
718
  $message = apply_filters( 'wck_fep_post_updated_message', __( 'Post Updated', 'wck' ), $meta );
@@ -723,69 +723,69 @@ class WCK_FrontEnd_Posting extends Wordpress_Creation_Kit{
723
  }
724
 
725
  echo $message;
726
-
727
  die();
728
- }
729
  }
730
 
731
- class WCK_FEP_Dashboard{
732
-
733
  static $wck_fep_dashboard_add_scripts;
734
-
735
  /* Constructor method for the class. */
736
- function __construct( ) {
737
-
738
  /* register the shortcode */
739
- add_shortcode( 'fep-dashboard', array( &$this, 'wck_fep_dashboard') );
740
-
741
  /*print scripts*/
742
  add_action( 'init', array( &$this, 'wck_fep_dashboard_register_script' ) );
743
  add_action( 'wp_footer', array( &$this, 'wck_fep_dashboard_print_script' ) );
744
-
745
  // Set up the AJAX hooks
746
- add_action( "wp_ajax_wck_fep_delete_entry", array( &$this, 'wck_fep_dashboard_delete_post' ) );
747
  add_action( 'wp_ajax_wck_fep_register_user', array( &$this, 'wck_fep_register_user' ) );
748
  add_action( 'wp_ajax_nopriv_wck_fep_register_user', array( &$this, 'wck_fep_register_user' ) );
749
  add_action( 'wp_ajax_wck_fep_update_user', array( &$this, 'wck_fep_update_user' ) );
750
- add_action( 'wp_ajax_nopriv_wck_fep_update_user', array( &$this, 'wck_fep_update_user' ) );
751
  }
752
-
753
  static function wck_fep_dashboard_register_script(){
754
- /* FEP script */
755
  wp_register_script( 'wck-fep', plugins_url('wck-fep.js', __FILE__ ), array('jquery'), '1.0', true );
756
- wp_register_style( 'wck-fep-css', plugins_url('wck-fep.css', __FILE__ ) );
757
  }
758
-
759
  /**
760
  * The function used to print scripts used by FEP in the footer of the page
761
  *
762
- * @since 1.0.0
763
  */
764
  static function wck_fep_dashboard_print_script() {
765
  /* if the static var set by the shortcode isn't true do nothing */
766
  if ( ! self::$wck_fep_dashboard_add_scripts )
767
  return;
768
-
769
  wp_print_scripts('jquery-ui-tabs');
770
- wp_print_scripts('wck-fep');
771
- wp_print_styles('wck-fep-css');
772
-
773
  /* ajax url for frontend */
774
- echo '<script type="text/javascript">var wckAjaxurl = "'. admin_url('admin-ajax.php') .'";</script>';
775
  }
776
-
777
 
778
- /* FEP Dashboard */
 
779
  function wck_fep_dashboard(){
780
-
781
  /* set the static var to true */
782
- self::$wck_fep_dashboard_add_scripts = true;
783
-
784
  if( !is_user_logged_in() ){
785
  return wck_fep_output_lilo_form();
786
  }
787
-
788
-
789
  $user_id = get_current_user_id();
790
  /* get post types */
791
  $args = array(
@@ -793,17 +793,17 @@ class WCK_FEP_Dashboard{
793
  );
794
  $output = 'objects'; // or objects
795
  $post_types = get_post_types($args,$output);
796
-
797
- $dashboard = "";
798
-
799
  $dashboard .= '<div id="fep-dashboard">';
800
 
801
- $dashboard .= '<ul id="wck-fep-tabs">';
802
  $dashboard .= apply_filters( 'wck_fep_dashboard_profile_tab', '<li><a href="#wck-fep-update-form">'. __( 'My Profile', 'wck' ) .'</a></li>' );
803
  if( !empty( $post_types ) ){
804
  foreach ($post_types as $post_type ) {
805
  if ( $post_type->name != 'attachment' && $post_type->name != 'wck-meta-box' && $post_type->name != 'wck-frontend-posting' && $post_type->name != 'wck-option-page' && $post_type->name != 'wck-option-field' ){
806
-
807
  $args = array(
808
  'numberposts' => -1,
809
  'author' => $user_id,
@@ -811,16 +811,16 @@ class WCK_FEP_Dashboard{
811
  );
812
  $posts = get_posts( apply_filters( 'wck_fep_dashbord_get_posts_args', $args ) );
813
 
814
- if( !empty( $posts ) )
815
  $dashboard .= '<li><a href="#fep-'. $post_type->name .'">'. __( 'My ', 'wck' ) .$post_type->label.'</a></li>';
816
  }
817
  }
818
  }
819
  $dashboard .= '</ul>';
820
-
821
  $dashboard .= wck_fep_output_user_profile();
822
-
823
- if( !empty( $post_types ) ){
824
  foreach ($post_types as $post_type ) {
825
  if ( $post_type->name != 'attachment' && $post_type->name != 'wck-meta-box' && $post_type->name != 'wck-frontend-posting' ){
826
  $args = array(
@@ -832,16 +832,16 @@ class WCK_FEP_Dashboard{
832
  if( !empty( $posts ) ){
833
  $dashboard .= '<div id="fep-'. $post_type->name .'">';
834
  $dashboard .= '<h3 class="fep-'. $post_type->name .'">'. __( 'My ', 'wck' ) . $post_type->label .'</h3>';
835
- $dashboard .= '<ul id="fep-'. $post_type->name .'">';
836
-
837
  foreach( $posts as $post ){
838
-
839
  /* build edit link */
840
  $args = array(
841
  'post_type' => 'wck-frontend-posting',
842
  'numberposts' => -1
843
  );
844
-
845
  $all_forms = get_posts( $args );
846
  $shortcode_page_id ='';
847
  $edit_link='';
@@ -858,50 +858,50 @@ class WCK_FEP_Dashboard{
858
  }
859
  }
860
  }
861
-
862
  if( !empty( $shortcode_page_id ) ){
863
  $arr_params = array ( 'action' => 'edit', 'post_id' => $post->ID, '_wpnonce' => wp_create_nonce( 'wck-fep-dashboard-edit-'.$post->ID.'-'.$user_id ) );
864
  $edit_link = add_query_arg( $arr_params, get_permalink( $shortcode_page_id ) );
865
  }
866
-
867
-
868
  $dashboard .= '<li id="'. $post->ID .'"><a href="'. get_permalink( $post->ID ) .'">'. get_the_title( $post->ID ) .'</a>';
869
  if( !empty( $edit_link ) )
870
  $dashboard .= ' <a class="wck-edit-post" href="'.esc_url( $edit_link ).'">'. __( 'Edit', 'wck' ) .'</a> ';
871
-
872
  $delete_nonce = wp_create_nonce( 'wck-fep-delete-entry' );
873
  $dashboard .= ' <a class="wck-delete-post" href="javascript:void(0)" onclick="wckFepDeletePost(\''.$post->ID.'\', \''. $delete_nonce .'\')">'. __( 'Delete', 'wck' ) .'</a> </li>';
874
  }
875
-
876
- $dashboard .= '</ul></div>';
877
  }
878
  }
879
-
880
  }
881
  }
882
-
883
  $dashboard .= '</div>';
884
-
885
- return $dashboard;
886
  }
887
-
888
  static function wck_fep_dashboard_delete_post(){
889
  check_ajax_referer( "wck-fep-delete-entry" );
890
  if( !empty( $_POST['id'] ) )
891
  $id = absint($_POST['id']);
892
  else
893
  $id = '';
894
-
895
  if( wp_trash_post( $id ) !== false )
896
  die( 'Deleted' );
897
- else
898
  die( 'Error Deleting' );
899
  }
900
-
901
  static function wck_fep_register_user(){
902
  wck_fep_handle_user_action();
903
  }
904
-
905
  static function wck_fep_update_user(){
906
  wck_fep_handle_user_action();
907
  }
@@ -917,7 +917,7 @@ function wck_fep_login_redirect( $redirect_to, $redirect_url, $user ){
917
  $error_string = $user->get_error_message();
918
  $arr_params = array ( 'loginerror' => urlencode( base64_encode( $error_string ) ) );
919
  $redirect_to = add_query_arg( $arr_params, $redirect_to );
920
- wp_safe_redirect( $redirect_to );
921
  }
922
  else{
923
  $redirect_to = remove_query_arg( 'loginerror', $redirect_to );
@@ -933,27 +933,27 @@ function wck_fep_cur_page_url() {
933
  $pageURL .= "://";
934
  if ($_SERVER["SERVER_PORT"] != "80") {
935
  $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
936
- } else {
937
  $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
938
  }
939
-
940
  /* make sure if the function is called through ajax */
941
  if( $pageURL == admin_url('admin-ajax.php') )
942
  $pageURL = $_SERVER['HTTP_REFERER'];
943
-
944
  return $pageURL;
945
  }
946
 
947
  /**
948
- * Outputs login/register/logout
949
  */
950
  function wck_fep_output_lilo_form(){
951
  $lilo_form = '';
952
- if( !is_user_logged_in() ){
953
  $nonce = wp_create_nonce( 'wck-fep-user-action' );
954
-
955
  $lilo_form .= '<div id="wck-fep-login-form">';
956
-
957
  $lilo_form .= '<div id="wck-fep-login-messages">';
958
  if ( isset( $_GET['loginerror'] ) || isset( $_POST['loginerror'] ) ){
959
  $loginerror = isset( $_GET['loginerror'] ) ? $_GET['loginerror'] : $_POST['loginerror'];
@@ -961,9 +961,9 @@ function wck_fep_output_lilo_form(){
961
  $lilo_form .= wp_kses_post( urldecode( base64_decode( $loginerror ) ) );
962
  $lilo_form .= '</span>';
963
  }
964
-
965
  $lilo_form .= '</div>';
966
-
967
  $lilo_form .= '<form action="'. get_option('home') .'/wp-login.php" method="post"><ul>';
968
  $lilo_form .= '<li><label for="log">'. __('User:', 'wck').'</label>';
969
  $lilo_form .= '<input type="text" name="log" id="log" class="text-input" value="" /></li>';
@@ -972,30 +972,30 @@ function wck_fep_output_lilo_form(){
972
  $lilo_form .= '<li><input type="submit" name="submit" value="'. __('Log in', 'wck') .'" /></li>';
973
  $lilo_form .= '<li><div id="remember">
974
  <input class="remember-me checkbox" name="rememberme" id="rememberme" type="checkbox" checked="checked" value="forever" />
975
- <label for="rememberme" id="label-remember-me">'. __('Remember', 'wck').'</label>
976
  </div>';
977
- $lilo_form .= '<input type="hidden" value="'. wck_fep_cur_page_url() .'" name="redirect_to"/>';
978
- $lilo_form .= '<input type="hidden" value="wck-fep-login" name="wck-fep-login"/></li>';
979
  $lilo_form .= '</ul></form>';
980
-
981
  /* check if we have user registration opened */
982
  $registration_status = get_option( 'users_can_register' );
983
- if( $registration_status ){
984
- $lilo_form .= '<span class="wck-fep-message">' . __( 'Don\'t have a user account? ', 'wck' ) . '</span>';
985
  $lilo_form .= '<a href="javascript:void(0)" id="wck-fep-show-register-form">'. __('Register.', 'wck') .'</a>';
986
  $lilo_form .= '</div>';
987
-
988
  $lilo_form .= '<div id="wck-fep-register-form" style="display:none">';
989
  $lilo_form .= '<div id="wck-fep-registration-errors"></div>';
990
  $lilo_form .= '<ul>';
991
  $lilo_form .= '<li><label for="user-name">'. __('Username:', 'wck').'</label>';
992
  $lilo_form .= '<input type="text" name="user-name" id="user-name" class="text-input" value="" /></li>';
993
  $lilo_form .= '<li><label for="email">'. __('Email:', 'wck').'</label>';
994
- $lilo_form .= '<input type="text" name="email" id="email" class="text-input" value="" /></li>';
995
  $lilo_form .= '<li><label for="password">'. __('Password:', 'wck').'</label>';
996
  $lilo_form .= '<input type="password" name="password" id="password" value="" /></li>';
997
  $lilo_form .= '<li><label for="confirm-password">'. __('Confirm Password:', 'wck').'</label>';
998
- $lilo_form .= '<input type="password" name="confirm-password" id="confirm-password" value="" /></li>';
999
  $lilo_form .= '<li><input type="submit" onclick="wckFepRegisterUser(\''. $nonce .'\')" name="register" id="register" value="'. __('Register.', 'wck') .'" /></li>';
1000
  $lilo_form .= '</ul>';
1001
  $lilo_form .= '<a href="javascript:void(0)" id="wck-fep-back-to-login">'. __( 'Back to login.', 'wck' ) .'</a></div>';
@@ -1005,11 +1005,11 @@ function wck_fep_output_lilo_form(){
1005
  }
1006
  else{
1007
  $current_user = wp_get_current_user();
1008
-
1009
  $lilo_form .= '<span class="wck-welcome">'. sprintf( __( 'Welcome %1$s! ', 'wck' ), $current_user->display_name ) . '</span>';
1010
  $lilo_form .= '<a href="'. wp_logout_url( wck_fep_cur_page_url() ).'" class="wck-logout">'. __( 'Logout', 'wck' ) .'</a>';
1011
  }
1012
-
1013
  return apply_filters( 'wck_fep_lilo_form', $lilo_form );
1014
  }
1015
 
@@ -1017,34 +1017,34 @@ function wck_fep_output_lilo_form(){
1017
  * Outputs the user profile update form
1018
  */
1019
  function wck_fep_output_user_profile(){
1020
-
1021
  $nonce = wp_create_nonce( 'wck-fep-user-action' );
1022
-
1023
  $current_user = wp_get_current_user();
1024
  $user_data = get_userdata( $current_user->ID );
1025
-
1026
  $user_profile = '<div id="wck-fep-update-form">';
1027
  $user_profile .= '<p><span class="wck-welcome">'. sprintf( __( 'Welcome %1$s! ', 'wck' ), $current_user->display_name ) .'</span><a href="'. wp_logout_url( wck_fep_cur_page_url() ).'" class="wck-logout">'. __( 'Logout', 'wck' ) .'</a></p>';
1028
-
1029
  $user_profile .= '<p id="wck-fep-update-messages"></p>';
1030
  $user_profile .= '<p id="wck-fep-update-errors"></p>';
1031
-
1032
- $user_profile .= '<ul>';
1033
  $user_profile .= '<li><label for="email">'. __( 'Email:', 'wck' ) .'</label>';
1034
  $user_profile .= '<input type="text" id="email" name="email" value="'. esc_attr( $current_user->user_email ) .'" /></li>';
1035
-
1036
  $user_profile .= '<li><label for="password">'. __( 'Password:', 'wck' ) .'</label>';
1037
  $user_profile .= '<input type="password" id="password" name="password"/></li>';
1038
-
1039
  $user_profile .= '<li><label for="confirm-password">'. __( 'Password Confirm:', 'wck' ) .'</label>';
1040
  $user_profile .= '<input type="password" id="confirm-password" name="confirm-password"/></li>';
1041
-
1042
  $user_profile .= '<li><label for="description">'. __( 'Description', 'wck' ) .'</label>';
1043
  $user_profile .= '<textarea id="description" name="description">'. esc_textarea( $user_data->user_description ) .'</textarea></li>';
1044
-
1045
  $user_profile .= '<li><input type="submit" value="'. __( 'Update', 'wck' ) .'" onclick="wckFepUpdateUser(\''. $nonce .'\')" /></li>';
1046
  $user_profile .= '</ul></div>';
1047
-
1048
  return apply_filters( 'wck_fep_user_profile', $user_profile );
1049
  }
1050
 
@@ -1052,36 +1052,36 @@ function wck_fep_output_user_profile(){
1052
  * Ajax callback for handling user register or update
1053
  */
1054
  function wck_fep_handle_user_action(){
1055
-
1056
  check_ajax_referer( 'wck-fep-user-action' );
1057
-
1058
  if( !empty( $_POST['action_type'] ) )
1059
  $action = sanitize_text_field( $_POST['action_type'] );
1060
  else
1061
  $action = '';
1062
  if( !empty( $_POST['username'] ) )
1063
  $username = sanitize_user( $_POST['username'] );
1064
- else
1065
  $username = '';
1066
  if( !empty( $_POST['email'] ) )
1067
  $email = sanitize_email( $_POST['email'] );
1068
- else
1069
  $email = '';
1070
  if( !empty( $_POST['password'] ) )
1071
  $password = $_POST['password'];
1072
- else
1073
  $password = '';
1074
  if( !empty( $_POST['confirm_password'] ) )
1075
  $confirm_password = $_POST['confirm_password'];
1076
- else
1077
  $confirm_password = '';
1078
  if( !empty( $_POST['description'] ) )
1079
  $description = wp_kses_post( $_POST['description'] );
1080
- else
1081
  $description = '';
1082
-
1083
- $registration_errors = new WP_Error();
1084
-
1085
  if( $action == 'register' ){
1086
  $username = sanitize_user( $username );
1087
  // Check the username
@@ -1104,8 +1104,8 @@ function wck_fep_handle_user_action(){
1104
  } elseif ( email_exists( $email ) && $action== "register" ) {
1105
  $registration_errors->add( 'email_exists', __( 'This email is already registered, please choose another one.', 'wck' ) );
1106
  }
1107
-
1108
- // Check the password
1109
  if( empty( $password ) && $action== "register" )
1110
  $registration_errors->add('password_error', __( 'Please enter a password.', 'wck' ) );
1111
  else if( $password != $confirm_password )
@@ -1121,7 +1121,7 @@ function wck_fep_handle_user_action(){
1121
  $userdata = array(
1122
  'user_login' => $username,
1123
  'user_email' => $email,
1124
- 'user_pass' => $password
1125
  );
1126
  $user = wp_insert_user( $userdata );
1127
  }
@@ -1130,7 +1130,7 @@ function wck_fep_handle_user_action(){
1130
  $userdata = array(
1131
  'ID' => $current_user->ID,
1132
  'user_login' => $current_user->user_login,
1133
- 'user_email' => $email,
1134
  'description' => $description
1135
  );
1136
  if( !empty( $password ) )
@@ -1138,10 +1138,10 @@ function wck_fep_handle_user_action(){
1138
 
1139
  $user = wp_update_user( $userdata );
1140
  }
1141
-
1142
 
1143
  }
1144
-
1145
  if( is_wp_error( $user ) ){
1146
  $error_messages = '';
1147
  $user_error_messages = $user->get_error_messages();
@@ -1152,12 +1152,12 @@ function wck_fep_handle_user_action(){
1152
  }
1153
  die( $error_messages );
1154
  }
1155
- else die( 'User added successfully!' );
1156
  }
1157
 
1158
  /* basic redirect subscribers from admin to frontend */
1159
  add_action('admin_head', 'wck_fep_redirect_to_front_end');
1160
- function wck_fep_redirect_to_front_end() {
1161
  global $current_user;
1162
  $user = new WP_User( $current_user->ID );
1163
  if ( !empty( $user->roles ) && is_array( $user->roles ) ) {
@@ -1167,7 +1167,7 @@ function wck_fep_redirect_to_front_end() {
1167
  wp_redirect(get_option('siteurl'));
1168
  }
1169
  }
1170
- }
1171
  }
1172
 
1173
 
@@ -1179,7 +1179,7 @@ if( strpos( wp_get_referer(), 'wp-admin' ) === false && isset( $_REQUEST['action
1179
  return true;
1180
  }
1181
  }
1182
-
1183
  if( !function_exists( 'auth_redirect' ) ){
1184
  function auth_redirect() {
1185
  return true;
@@ -1193,7 +1193,7 @@ function wck_create_fake_user_when_uploading_and_not_logged_in(){
1193
  if( strpos( wp_get_referer(), 'wp-admin' ) === false && isset( $_REQUEST['action'] ) && 'upload-attachment' == $_REQUEST['action'] ){
1194
  if( !is_user_logged_in() || !current_user_can('upload_files') || !current_user_can( 'edit_posts' ) ){
1195
  global $current_user;
1196
- $current_user = new WP_User( 0, 'frontend_uploader' );
1197
  $current_user->allcaps = array( "upload_files" => true, "edit_posts" => true, "edit_others_posts" => true, "edit_pages" => true, "edit_others_pages" => true );
1198
  }
1199
  }
@@ -1208,12 +1208,12 @@ function wck_modify_query_attachements_when_not_logged_in(){
1208
  function wck_wp_ajax_not_loggedin_query_attachments(){
1209
  wp_send_json_success( );
1210
  }
1211
- }
1212
  }
1213
 
1214
  /* restrict file types of the upload field functionality */
1215
  add_filter('wp_handle_upload_prefilter', 'wck_upload_file_type');
1216
- function wck_upload_file_type($file) {
1217
  if (isset($_POST['allowed_type']) && !empty($_POST['allowed_type'])){
1218
  //this allows you to set multiple types seperated by a pipe "|"
1219
  $allowed = explode("|", sanitize_text_field( $_POST['allowed_type'] ) );
@@ -1225,7 +1225,7 @@ function wck_upload_file_type($file) {
1225
  return $file;
1226
  }
1227
  //check if the type is allowed at all by WordPress
1228
- foreach (get_allowed_mime_types() as $key => $value) {
1229
  if (strpos($key, $ext) !== false || $key == $ext)
1230
  return $file;
1231
  }
@@ -1233,4 +1233,4 @@ function wck_upload_file_type($file) {
1233
  }
1234
  return $file;
1235
  }
1236
- ?>
3
 
4
  class WCK_FrontEnd_Posting extends Wordpress_Creation_Kit{
5
 
6
+ private $defaults = array(
7
  'form_title' => 'Form',
8
  'post_type' => 'post',
9
  'form_name' => '',
10
  'admin_approval' => 'no',
11
+ 'anonymous_posting' => 'no',
12
  'assign_to_user' => 1,
13
  'meta_array' => array(),
14
  'taxonomies' => array(),
15
  'single_cfcs' => array()
16
  );
17
  private $args;
18
+
19
  /* this will hold the meta_arrays for any single CFCs */
20
  private $single_cfcs;
21
+
22
+
23
+ static $wck_fep_add_scripts;
24
+
25
  /* Constructor method for the class. */
26
+ function __construct( $args ) {
27
+
28
  /* Merge the input arguments and the defaults. */
29
+ $this->args = wp_parse_args( $args, $this->defaults );
30
 
31
+ /* populate single_cfcs arg with the meta_array of any single CFCs that are added to the form.
32
  the meta_name will be used as the key */
33
  if( function_exists( 'wck_cfc_create_boxes_args' ) ){
34
  if( !empty( $this->args['meta_array'] ) ){
35
  foreach ( $this->args['meta_array'] as $details ){
36
  $all_box_args = wck_cfc_create_boxes_args();
37
+ /* add single CFCs */
38
  if( !empty( $all_box_args ) ){
39
+ foreach( $all_box_args as $box_args ){
40
+ if( ( $box_args['post_type'] == $this->args['post_type'] ) && ( $box_args['metabox_title'] == $details['title'] ) ){
41
  /* treat single cfcs case */
42
  if( $box_args['single'] )
43
+ $this->single_cfcs[$box_args['meta_name']] = $box_args['meta_array'];
44
  $this->single_cfcs[$box_args['meta_name'].'_unserialize_fields'] = $box_args['unserialize_fields'];
45
  }
46
  }
48
  }
49
  }
50
  }
51
+
52
  /* register the shortcode */
53
  add_shortcode( 'fep', array( &$this, 'wck_fep_form_in_frontend') );
54
+
55
  /*print scripts*/
56
  add_action( 'get_header', array( &$this, 'wck_fep_register_script' ), 12 );
57
  add_action( 'wp_footer', array( &$this, 'wck_fep_print_script' ) );
58
  add_action( 'wp_head', array( &$this, 'wck_fep_print_ajax_url' ) );
59
  add_action( 'wp_enqueue_scripts', array( &$this, 'wck_fep_enqueue_scripts' ) );
60
+
61
  // Set up the AJAX hooks
62
  add_action( "wp_ajax_wck_fep_add_post".$this->args['form_name'], array( &$this, 'wck_fep_add_post') );
63
  add_action( "wp_ajax_nopriv_wck_fep_add_post".$this->args['form_name'], array( &$this, 'wck_fep_add_post') );
64
+
65
  add_action("wp_ajax_wck_add_meta".$this->args['form_name'], array( &$this, 'wck_add_meta') );
66
  add_action("wp_ajax_nopriv_wck_add_meta".$this->args['form_name'], array( &$this, 'wck_add_meta') );
67
+
68
  add_action("wp_ajax_wck_fep_create_frontend_form_".$this->args['form_name'], array( &$this, 'wck_fep_create_frontend_form') );
69
+ add_action("wp_ajax_nopriv_wck_fep_create_frontend_form_".$this->args['form_name'], array( &$this, 'wck_fep_create_frontend_form') );
70
+ }
71
+
72
  /**
73
  * The function used to register scripts used by FEP
74
  *
75
+ * @since 1.0.0
76
  */
77
  static function wck_fep_register_script(){
78
  //datepicker
79
+ wp_enqueue_script('jquery-ui-datepicker');
80
  wp_enqueue_style('jquery-style', plugins_url( '', dirname(__FILE__) ).'/assets/datepicker/datepicker.css');
81
 
82
  //colorpicker
97
  wp_enqueue_style( 'wck-google-maps-style', plugin_dir_url( __FILE__ ) . '../assets/map/map.css' );
98
  }
99
 
100
+ /* FEP script */
101
  wp_register_script( 'wck-fep', plugins_url('wck-fep.js', __FILE__ ), array('jquery'), '1.0', true );
102
  wp_register_style( 'wck-fep-css', plugins_url('wck-fep.css', __FILE__ ) );
103
+ /* register WCK script for frontend */
104
  wp_register_script( 'wck-js', plugins_url( '', dirname(__FILE__) ).'/wordpress-creation-kit.js', array('jquery', 'jquery-ui-datepicker'), '1.0', true );
105
+
106
+ // wysiwyg
107
+ wp_register_script( 'wck-ckeditor', plugins_url( '', dirname(__FILE__) ).'/assets/js/ckeditor/ckeditor.js', array(), '1.0', true );
108
+
109
+ /* media upload wck script */
110
  wp_register_script('wck-upload-field', plugins_url('/../fields/upload.js', __FILE__), array('jquery') );
111
  }
112
+
113
  /**
114
  * The function used to print scripts used by FEP in the footer of the page
115
  *
116
+ * @since 1.0.0
117
  */
118
  static function wck_fep_print_script() {
119
  /* if the static var set by the shortcode isn't true do nothing */
120
  if ( ! self::$wck_fep_add_scripts )
121
  return;
122
+
123
  wp_print_scripts('wck-fep');
124
  wp_print_styles('wck-fep-css');
125
  wp_print_scripts('wck-js');
126
+
127
  wp_print_scripts( 'jquery-ui-draggable' );
128
  wp_print_scripts( 'jquery-ui-droppable' );
129
  wp_print_scripts( 'jquery-ui-sortable' );
130
+ wp_print_styles( 'thickbox' );
131
+ wp_print_scripts( 'thickbox' );
132
+
133
+ // wysiwyg
134
  wp_print_scripts( 'wck-ckeditor' );
135
 
136
  /* media upload wck script */
137
  wp_print_scripts( 'wck-upload-field' );
138
  }
139
+
140
  /**
141
  * The function used to print ajax url used by FEP in the header of the page
142
  *
143
+ * @since 1.0.0
144
  */
145
  static function wck_fep_print_ajax_url() {
146
  /* ajax url for frontend */
147
  echo '<script type="text/javascript">var wckAjaxurl = "'. admin_url('admin-ajax.php') .'";</script>';
148
  }
149
+
150
  /**
151
  * The function to enqueue jquery in header of the theme
152
  *
153
+ * @since 1.0.0
154
  */
155
  static function wck_fep_enqueue_scripts(){
156
  wp_enqueue_script( 'jquery' );
157
  }
158
+
159
+
160
  /**
161
  * Shortcode Function
162
  *
163
+ * @since 1.0.0
164
+ *
165
+ * @param array $atts Shortcode attributes
166
  * @return string $output form container and js ajax call to load the actual form.
167
+ */
168
+ function wck_fep_form_in_frontend( $atts ){
169
+
170
  /* extract shortcode args */
171
  extract( shortcode_atts( array(
172
+ 'form_name' => ''
173
  ), $atts ) );
174
+
175
+ /* the login form can't get the $_GET['loginerror'] from the url because it is loaded with ajax and we need to send it through post */
176
  if( isset( $_GET['loginerror'] ) )
177
  $loginerror = ', loginerror:\''. $_GET['loginerror'].'\'' ;
178
  else
179
  $loginerror = '';
180
+
181
  /* set the static var to true */
182
  self::$wck_fep_add_scripts = true;
183
+
184
  /* media upload add here */
185
  wp_enqueue_media();
186
+
187
  $output = "<div class='". $form_name ." fep-container";
188
  if( isset( $_GET['action'] ) && $_GET['action'] == 'edit' )
189
  $output .= " fep-edit";
190
  $output .= "'><div id='fep-ajax-loading'></div></div>";
191
+
192
+
193
  if( !empty( $_GET['action'] ) )
194
  $action = sanitize_text_field( $_GET['action'] );
195
  else
196
  $action = '';
197
+
198
  if( !empty( $_GET['post_id'] ) )
199
  $post_id = absint( $_GET['post_id'] );
200
  else
215
  jQuery('.fep-container.".$form_name."').html(response);
216
  jQuery( '#fep-ajax-loading' ).remove();
217
  jQuery(mb_sortable_elements);
218
+ });
219
+ </script>";
220
+
221
+
222
  return $output;
223
  }
224
+
225
  /**
226
  * Function that builds the form
227
  *
228
+ * @since 1.0.0
229
+ */
230
  function wck_fep_create_frontend_form( ){
231
+
232
  /* check for anonymous posting */
233
  if( $this->args['anonymous_posting'] == 'no' && !is_user_logged_in() ){
234
  /* get login logout form */
235
+ $lilo_form = wck_fep_output_lilo_form();
236
  die( $lilo_form );
237
  }
238
+
239
  if( !empty( $_POST['action_type'] ) )
240
  $action = sanitize_text_field( $_POST['action_type'] );
241
  else
244
  $post_id = absint( $_POST['post_id'] );
245
  else
246
  $post_id = '';
247
+
248
  /* take care of auto_drafts only when adding posts ( the default case ) */
249
  if( $action == '' ){
250
  /* delete auto drafts older than 12 hours */
252
  'post_status' => 'auto-draft',
253
  'numberposts' => -1,
254
  'suppress_filters' => false,
255
+ 'post_type' => 'any'
256
  );
257
+
258
  add_filter( 'posts_where', array( &$this, 'wck_fep_filter_auto_drafts_where' ) );
259
  $auto_drafts = get_posts( $args );
260
  remove_filter( 'posts_where', array( &$this, 'wck_fep_filter_auto_drafts_where' ) );
261
+
262
+
263
  if( !empty($auto_drafts) ){
264
  foreach( $auto_drafts as $auto_draft ){
265
+
266
  /* also delete all post meta for the auto-draft post */
267
+ $meta_keys = get_post_custom_keys( $auto_draft->ID );
268
  if( !empty($meta_keys) ){
269
  foreach( $meta_keys as $meta_key ){
270
+
271
  delete_post_meta( $auto_draft->ID, $meta_key );
272
  }
273
  }
274
+
275
  /* delete attachemnts for the auto draft */
276
+ $args = array(
277
  'post_parent' => $auto_draft->ID,
278
+ 'post_type' => 'attachment',
279
  'numberposts' => -1
280
  );
281
  $attachments = get_children( $args );
284
  wp_delete_attachment( $attachment->ID );
285
  }
286
  }
287
+
288
  /* delete the post */
289
  wp_delete_post( $auto_draft->ID, true );
290
  }
291
  }
292
  }
293
+
294
+ /* create a new post? not if we allready have a $post_id ( probabily edit case )*/
295
  if ( !$post_id ) {
296
  global $post;
297
  $post_id = wp_insert_post( array( 'post_title' => __( 'Auto Draft' ), 'post_type' => $this->args['post_type'], 'post_status' => 'auto-draft' ) );
298
+ $post = get_post( $post_id );
299
  }
300
+
301
  /* create default post elements */
302
  $form = self::create_add_form( $this->args['meta_array'], $this->args['form_name'], $post_id, $action );
303
 
304
  echo $form;
305
+
306
  exit();
307
  }
308
+
309
  /**
310
  * Filtering function that will add our where clause to the query
311
  *
312
+ * @since 1.0.0
313
+ */
314
  function wck_fep_filter_auto_drafts_where( $where = '' ){
315
+ // posts older than 12 hours
316
  $where .= " AND post_date <= '" . date('Y-m-d H:i:s', strtotime('-12 hours')) . "'";
317
  return $where;
318
+ }
319
+
320
+
321
  /**
322
  * Function that creates the add form with the default fields
323
  *
324
+ * @since 1.0.0
325
+ *
326
+ * @param array $fields array of default fields
327
  * @param string $form_name the name of the form
328
  * @param int $post_id the post ID
329
  * @return string $output form container and js ajax call to load the actual form.
350
  }
351
 
352
  $form = '<form id="'. $form_name .'" method="post" action="">';
353
+
354
+ $element_id = 0;
355
+
356
  if( function_exists( 'wck_cfc_create_boxes_args' ) )
357
  $all_box_args = wck_cfc_create_boxes_args();
358
+
359
  if( !empty( $fields ) ){
360
  foreach( $fields as $details ){
361
 
362
+ do_action( "wck_fep_before_form_{$form_name}_element_{$element_id}" );
363
 
364
  $form .= apply_filters( "wck_fep_filter_before_form_{$form_name}_element_{$element_id}", '<div id="fep-'. Wordpress_Creation_Kit::wck_generate_slug( $details['title'] ) .'" class="fep-element-wrap">', $details );
365
+
366
+ if( empty( $details['cfc'] ) ){
367
+
368
  if( $action == 'edit' ){
369
  /* build edit values depending on the field */
370
+ $value = self::wck_fep_get_edit_value( $post_id, $details );
371
  }
372
  else
373
  $value = apply_filters('wck_fep_default_value_' . $form_name . '_' . Wordpress_Creation_Kit::wck_generate_slug($details['title']), '');
374
 
375
  $form .= parent::wck_output_form_field( $form_name, $details, $value, 'fep', $post_id );
376
+
377
  }
378
+
379
  else{
380
+
381
+ /* add CFC boxes created with Custom Fields Creator */
382
  if( !empty( $all_box_args ) ){
383
+ foreach( $all_box_args as $box_args ){
384
+ if( ( $box_args['post_type'] == $this->args['post_type'] ) && ( $box_args['metabox_title'] == $details['title'] ) ){
385
+
386
  /* treat single cfcs case */
387
+ if( $box_args['single'] ){
388
+ $form .= '<div id="'. $box_args['meta_name'].'" class="single-cfc">';
389
  if( !empty( $box_args['meta_array'] ) ){
390
  foreach( $box_args['meta_array'] as $details ){
391
+
392
+ if( $action == 'edit' ){
393
  /* build edit values depending on the field */
394
+ $value = self::wck_fep_get_edit_value( $post_id, $details, $box_args['meta_name'] );
395
  }
396
  else {
397
  if( isset( $details['default'] ) )
405
  }
406
  }
407
  $form .= '</div>';
408
+ }
409
+ else{
410
  ob_start();
411
  parent::create_add_form( $box_args['meta_array'], $box_args['meta_name'], get_post($post_id), 'fep' );
412
  $parent_form = ob_get_contents();
413
  ob_end_clean();
414
+
415
+ $form .= $parent_form;
416
+ $form .= parent::wck_output_meta_content( $box_args['meta_name'], $post_id, $box_args['meta_array'], $box_args );
417
+ }
418
+ }
419
  }
420
+ }
421
+
422
  }
423
  $form .= apply_filters( "wck_fep_filter_after_form_{$form_name}_element_{$element_id}", '</div>' );
424
+
425
  do_action( "wck_after_form_{$form_name}_element_{$element_id}" );
426
+
427
  $element_id++;
428
  }
429
  }
430
+
431
+
432
+ if( $action == 'edit' )
433
  $submit_text = apply_filters( 'wck_fep_form_button_update', __( 'Update Post', 'wck' ), $form_name );
434
+ else
435
  $submit_text = apply_filters( 'wck_fep_form_button_add', __( 'Add Post', 'wck' ), $form_name );
436
 
437
  if (function_exists('icl_register_string') && function_exists('icl_translate') ) {
440
  }
441
 
442
  $form .= '<input type="submit" id="submit_'.$form_name.'" value="'. $submit_text .'" onclick="wckFepAddPost(\''. $form_name .'\', '. $post_id .', \''. $action .'\', \''. $nonce .'\');return false;"/>';
443
+
444
+ $form .= '</form>';
445
+
446
+ return $form;
447
  }
448
+
449
+
450
  /**
451
  * calls parrent function. till I figure out how to call parent function on ajax hook set up in child class
452
  */
453
  function wck_add_meta(){
454
  parent::wck_add_meta();
455
  }
456
+
457
  /* function that gets the values of the default post fields for editing purpouses */
458
  function wck_fep_get_edit_value( $post_id, $details, $meta_name = '' ){
459
  $value = '';
460
+
461
  if( $meta_name == '' ){
462
+ $post = get_post( $post_id );
463
  switch ( $details['title'] ) {
464
  case 'Post Title':
465
  $value = get_the_title( $post->ID );
480
 
481
  if( $details['title'] == $taxonomy->label || $details['slug'] == $taxonomy->name ){
482
  $object_terms = wp_get_object_terms( $post->ID, $taxonomy->name );
483
+
484
  if(!empty($object_terms)){
485
  if(!is_wp_error( $object_terms )){
486
  foreach($object_terms as $term){
496
  }
497
  }
498
  }
499
+ }
500
  }
501
+ }
502
  }
503
  }
504
  else{
506
  if( isset( $meta_values[0][Wordpress_Creation_Kit::wck_generate_slug( $details['title'], $details )] ) )
507
  $value = $meta_values[0][Wordpress_Creation_Kit::wck_generate_slug( $details['title'], $details )];
508
  }
509
+
510
  return $value;
511
  }
512
+
513
+
514
  /**
515
  * AJAX Function that ads the post
516
  *
517
+ * @since 1.0.0
518
  */
519
  function wck_fep_add_post(){
520
  check_ajax_referer( 'wck-fep-add-post' );
521
+
522
  $meta = sanitize_text_field( $_POST['meta'] );
523
  $post_ID = absint( $_POST['postid'] );
524
  if( !empty( $_POST['values'] ) )
525
+ $values = $_POST['values'];
526
  else
527
  $values = array();
528
  $single_cfcs = (!empty( $_POST['single_cfcs'] )) ? $_POST['single_cfcs'] : array() ;
529
  $action_type = sanitize_text_field( $_POST['action_type'] );
530
+
531
+ /* check required fields */
532
  $errors = array();
533
+
534
+ /* check required fields of single cfcs */
535
  if( !empty( $single_cfcs ) ){
536
  foreach( $single_cfcs as $meta_name => $single_values ){
537
  /* check required fields */
538
+ $errors[$meta_name] = self::wck_test_required( $this->single_cfcs[$meta_name], $meta_name, $single_values, 0 );
539
+ }
540
  }
541
+
542
  /* check required fields for default post fields */
543
  $errors[$meta] = self::wck_test_required( $this->args['meta_array'], $meta, $values, 0 );
544
+
545
  /* combine the errors from the default fields with single cfcs */
546
  $errors_json = array( 'error' => '', 'errorfields' => array() );
547
  if( !empty( $errors ) ){
552
  }
553
  }
554
  }
555
+
556
  if( !empty( $errors_json['error']) ){
557
  header( 'Content-type: application/json' );
558
  die( json_encode( $errors_json ) );
559
+ }
560
+
561
  /* if any single cfcs update the post meta */
562
  if( !empty( $single_cfcs ) ){
563
  foreach( $single_cfcs as $meta_name => $single_values ){
570
  update_post_meta($post_ID, $name, $value);
571
  }
572
  }
573
+
574
+ /* if unserialize_fields is true add for each entry separate post meta for every element of the form */
575
+ if( $this->single_cfcs[$meta_name.'_unserialize_fields'] ){
576
  $meta_suffix = 1;
577
  if( !empty( $single_values ) ){
578
  foreach( $single_values as $name => $value ){
580
  }
581
  }
582
  }
583
+
584
  }
585
  }
586
+
587
  /* treat empty keys in our $_POST values */
588
  $expected_keys = array('post-title', 'post-content', 'post-excerpt');
589
  foreach( $expected_keys as $expected_key ){
591
  $values[$expected_key] = '';
592
  }
593
  }
594
+
595
  $wck_fep_new_post = array(
596
  'ID' => $post_ID,
597
  'post_content' => $values['post-content'],
635
 
636
  /* post status */
637
  if( $this->args['admin_approval'] == 'yes' )
638
+ $wck_fep_new_post['post_status'] = 'draft';
639
+ else
640
  $wck_fep_new_post['post_status'] = 'publish';
641
 
642
  /* post author */
643
  if( $this->args['anonymous_posting'] == 'yes' )
644
+ $wck_fep_new_post['post_author'] = $this->args['assign_to_user'];
645
+ else
646
  $wck_fep_new_post['post_author'] = get_current_user_id();
647
+
648
+
649
  if( !empty( $values['featured-image'] ) ){
650
  set_post_thumbnail( $post_ID, $values['featured-image'] );
651
+ }
652
+
653
  /* set comments status of the posts according to the default comment status */
654
  $comments_status = get_option( 'default_comment_status' );
655
  if( empty( $comments_status ) )
656
+ $comments_status = 'closed';
657
  $wck_fep_new_post['comment_status'] = $comments_status;
658
 
659
  // Insert the post into the database
660
+ $post_id = wp_insert_post( apply_filters( 'wck_fep_new_post_args', $wck_fep_new_post, $action_type ) );
661
+
662
+
663
  /* take care of taxonomies */
664
  if( !empty( $this->args['taxonomies'] ) ){
665
  foreach( $this->args['taxonomies'] as $taxonomy ){
666
+
667
  $tax_names = $values[ Wordpress_Creation_Kit::wck_generate_slug( $taxonomy->label, array( 'slug' => $taxonomy->name ) ) ];
668
+
669
+ if( !empty( $tax_names ) ){
670
+ $tax_names = explode( ',', $tax_names );
671
+
672
+ /* strip white spaces */
673
  if( !empty( $tax_names ) ){
674
  foreach( $tax_names as $key => $tax_name ){
675
  $tax_names[$key] = trim( $tax_name );
676
  }
677
  }
678
+
679
  /* get term ids by name and build the terms array */
680
  $terms = array();
681
  if( !empty( $tax_names ) ){
682
  foreach( $tax_names as $tax_name ){
683
+ $idObj = get_term_by( 'name', htmlspecialchars( $tax_name ), $taxonomy->name );
684
  if( $idObj != false )
685
  $terms[] = $idObj->term_id;
686
  else{
696
  }
697
  }
698
  }
699
+
700
+ if( !empty( $terms ) ){
701
  //to make sure the terms IDs are integers:
702
  $terms = array_map('intval', $terms);
703
+ $terms = array_unique( $terms );
704
+ $set_result = wp_set_object_terms( intval($post_ID), $terms, $taxonomy->name );
705
  }
706
  }
707
  }
708
  }
709
+
710
  if( $action_type == '' )
711
  do_action( 'wck_fep_add_post', $wck_fep_new_post, get_current_user_id() );
712
  else if( $action_type == 'edit' )
713
  do_action( 'wck_fep_update_post', $wck_fep_new_post, get_current_user_id() );
714
+
715
+ if( $action_type == '' )
716
  $message = apply_filters( 'wck_fep_post_added_message', __( 'Post Added', 'wck' ), $meta );
717
  else if( $action_type == 'edit' )
718
  $message = apply_filters( 'wck_fep_post_updated_message', __( 'Post Updated', 'wck' ), $meta );
723
  }
724
 
725
  echo $message;
726
+
727
  die();
728
+ }
729
  }
730
 
731
+ class WCK_FEP_Dashboard{
732
+
733
  static $wck_fep_dashboard_add_scripts;
734
+
735
  /* Constructor method for the class. */
736
+ function __construct( ) {
737
+
738
  /* register the shortcode */
739
+ add_shortcode( 'fep-dashboard', array( &$this, 'wck_fep_dashboard') );
740
+
741
  /*print scripts*/
742
  add_action( 'init', array( &$this, 'wck_fep_dashboard_register_script' ) );
743
  add_action( 'wp_footer', array( &$this, 'wck_fep_dashboard_print_script' ) );
744
+
745
  // Set up the AJAX hooks
746
+ add_action( "wp_ajax_wck_fep_delete_entry", array( &$this, 'wck_fep_dashboard_delete_post' ) );
747
  add_action( 'wp_ajax_wck_fep_register_user', array( &$this, 'wck_fep_register_user' ) );
748
  add_action( 'wp_ajax_nopriv_wck_fep_register_user', array( &$this, 'wck_fep_register_user' ) );
749
  add_action( 'wp_ajax_wck_fep_update_user', array( &$this, 'wck_fep_update_user' ) );
750
+ add_action( 'wp_ajax_nopriv_wck_fep_update_user', array( &$this, 'wck_fep_update_user' ) );
751
  }
752
+
753
  static function wck_fep_dashboard_register_script(){
754
+ /* FEP script */
755
  wp_register_script( 'wck-fep', plugins_url('wck-fep.js', __FILE__ ), array('jquery'), '1.0', true );
756
+ wp_register_style( 'wck-fep-css', plugins_url('wck-fep.css', __FILE__ ) );
757
  }
758
+
759
  /**
760
  * The function used to print scripts used by FEP in the footer of the page
761
  *
762
+ * @since 1.0.0
763
  */
764
  static function wck_fep_dashboard_print_script() {
765
  /* if the static var set by the shortcode isn't true do nothing */
766
  if ( ! self::$wck_fep_dashboard_add_scripts )
767
  return;
768
+
769
  wp_print_scripts('jquery-ui-tabs');
770
+ wp_print_scripts('wck-fep');
771
+ wp_print_styles('wck-fep-css');
772
+
773
  /* ajax url for frontend */
774
+ echo '<script type="text/javascript">var wckAjaxurl = "'. admin_url('admin-ajax.php') .'";</script>';
775
  }
 
776
 
777
+
778
+ /* FEP Dashboard */
779
  function wck_fep_dashboard(){
780
+
781
  /* set the static var to true */
782
+ self::$wck_fep_dashboard_add_scripts = true;
783
+
784
  if( !is_user_logged_in() ){
785
  return wck_fep_output_lilo_form();
786
  }
787
+
788
+
789
  $user_id = get_current_user_id();
790
  /* get post types */
791
  $args = array(
793
  );
794
  $output = 'objects'; // or objects
795
  $post_types = get_post_types($args,$output);
796
+
797
+ $dashboard = "";
798
+
799
  $dashboard .= '<div id="fep-dashboard">';
800
 
801
+ $dashboard .= '<ul id="wck-fep-tabs">';
802
  $dashboard .= apply_filters( 'wck_fep_dashboard_profile_tab', '<li><a href="#wck-fep-update-form">'. __( 'My Profile', 'wck' ) .'</a></li>' );
803
  if( !empty( $post_types ) ){
804
  foreach ($post_types as $post_type ) {
805
  if ( $post_type->name != 'attachment' && $post_type->name != 'wck-meta-box' && $post_type->name != 'wck-frontend-posting' && $post_type->name != 'wck-option-page' && $post_type->name != 'wck-option-field' ){
806
+
807
  $args = array(
808
  'numberposts' => -1,
809
  'author' => $user_id,
811
  );
812
  $posts = get_posts( apply_filters( 'wck_fep_dashbord_get_posts_args', $args ) );
813
 
814
+ if( !empty( $posts ) )
815
  $dashboard .= '<li><a href="#fep-'. $post_type->name .'">'. __( 'My ', 'wck' ) .$post_type->label.'</a></li>';
816
  }
817
  }
818
  }
819
  $dashboard .= '</ul>';
820
+
821
  $dashboard .= wck_fep_output_user_profile();
822
+
823
+ if( !empty( $post_types ) ){
824
  foreach ($post_types as $post_type ) {
825
  if ( $post_type->name != 'attachment' && $post_type->name != 'wck-meta-box' && $post_type->name != 'wck-frontend-posting' ){
826
  $args = array(
832
  if( !empty( $posts ) ){
833
  $dashboard .= '<div id="fep-'. $post_type->name .'">';
834
  $dashboard .= '<h3 class="fep-'. $post_type->name .'">'. __( 'My ', 'wck' ) . $post_type->label .'</h3>';
835
+ $dashboard .= '<ul id="fep-'. $post_type->name .'">';
836
+
837
  foreach( $posts as $post ){
838
+
839
  /* build edit link */
840
  $args = array(
841
  'post_type' => 'wck-frontend-posting',
842
  'numberposts' => -1
843
  );
844
+
845
  $all_forms = get_posts( $args );
846
  $shortcode_page_id ='';
847
  $edit_link='';
858
  }
859
  }
860
  }
861
+
862
  if( !empty( $shortcode_page_id ) ){
863
  $arr_params = array ( 'action' => 'edit', 'post_id' => $post->ID, '_wpnonce' => wp_create_nonce( 'wck-fep-dashboard-edit-'.$post->ID.'-'.$user_id ) );
864
  $edit_link = add_query_arg( $arr_params, get_permalink( $shortcode_page_id ) );
865
  }
866
+
867
+
868
  $dashboard .= '<li id="'. $post->ID .'"><a href="'. get_permalink( $post->ID ) .'">'. get_the_title( $post->ID ) .'</a>';
869
  if( !empty( $edit_link ) )
870
  $dashboard .= ' <a class="wck-edit-post" href="'.esc_url( $edit_link ).'">'. __( 'Edit', 'wck' ) .'</a> ';
871
+
872
  $delete_nonce = wp_create_nonce( 'wck-fep-delete-entry' );
873
  $dashboard .= ' <a class="wck-delete-post" href="javascript:void(0)" onclick="wckFepDeletePost(\''.$post->ID.'\', \''. $delete_nonce .'\')">'. __( 'Delete', 'wck' ) .'</a> </li>';
874
  }
875
+
876
+ $dashboard .= '</ul></div>';
877
  }
878
  }
879
+
880
  }
881
  }
882
+
883
  $dashboard .= '</div>';
884
+
885
+ return $dashboard;
886
  }
887
+
888
  static function wck_fep_dashboard_delete_post(){
889
  check_ajax_referer( "wck-fep-delete-entry" );
890
  if( !empty( $_POST['id'] ) )
891
  $id = absint($_POST['id']);
892
  else
893
  $id = '';
894
+
895
  if( wp_trash_post( $id ) !== false )
896
  die( 'Deleted' );
897
+ else
898
  die( 'Error Deleting' );
899
  }
900
+
901
  static function wck_fep_register_user(){
902
  wck_fep_handle_user_action();
903
  }
904
+
905
  static function wck_fep_update_user(){
906
  wck_fep_handle_user_action();
907
  }
917
  $error_string = $user->get_error_message();
918
  $arr_params = array ( 'loginerror' => urlencode( base64_encode( $error_string ) ) );
919
  $redirect_to = add_query_arg( $arr_params, $redirect_to );
920
+ wp_safe_redirect( $redirect_to );
921
  }
922
  else{
923
  $redirect_to = remove_query_arg( 'loginerror', $redirect_to );
933
  $pageURL .= "://";
934
  if ($_SERVER["SERVER_PORT"] != "80") {
935
  $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
936
+ } else {
937
  $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
938
  }
939
+
940
  /* make sure if the function is called through ajax */
941
  if( $pageURL == admin_url('admin-ajax.php') )
942
  $pageURL = $_SERVER['HTTP_REFERER'];
943
+
944
  return $pageURL;
945
  }
946
 
947
  /**
948
+ * Outputs login/register/logout
949
  */
950
  function wck_fep_output_lilo_form(){
951
  $lilo_form = '';
952
+ if( !is_user_logged_in() ){
953
  $nonce = wp_create_nonce( 'wck-fep-user-action' );
954
+
955
  $lilo_form .= '<div id="wck-fep-login-form">';
956
+
957
  $lilo_form .= '<div id="wck-fep-login-messages">';
958
  if ( isset( $_GET['loginerror'] ) || isset( $_POST['loginerror'] ) ){
959
  $loginerror = isset( $_GET['loginerror'] ) ? $_GET['loginerror'] : $_POST['loginerror'];
961
  $lilo_form .= wp_kses_post( urldecode( base64_decode( $loginerror ) ) );
962
  $lilo_form .= '</span>';
963
  }
964
+
965
  $lilo_form .= '</div>';
966
+
967
  $lilo_form .= '<form action="'. get_option('home') .'/wp-login.php" method="post"><ul>';
968
  $lilo_form .= '<li><label for="log">'. __('User:', 'wck').'</label>';
969
  $lilo_form .= '<input type="text" name="log" id="log" class="text-input" value="" /></li>';
972
  $lilo_form .= '<li><input type="submit" name="submit" value="'. __('Log in', 'wck') .'" /></li>';
973
  $lilo_form .= '<li><div id="remember">
974
  <input class="remember-me checkbox" name="rememberme" id="rememberme" type="checkbox" checked="checked" value="forever" />
975
+ <label for="rememberme" id="label-remember-me">'. __('Remember', 'wck').'</label>
976
  </div>';
977
+ $lilo_form .= '<input type="hidden" value="'. wck_fep_cur_page_url() .'" name="redirect_to"/>';
978
+ $lilo_form .= '<input type="hidden" value="wck-fep-login" name="wck-fep-login"/></li>';
979
  $lilo_form .= '</ul></form>';
980
+
981
  /* check if we have user registration opened */
982
  $registration_status = get_option( 'users_can_register' );
983
+ if( $registration_status ){
984
+ $lilo_form .= '<span class="wck-fep-message">' . __( 'Don\'t have a user account? ', 'wck' ) . '</span>';
985
  $lilo_form .= '<a href="javascript:void(0)" id="wck-fep-show-register-form">'. __('Register.', 'wck') .'</a>';
986
  $lilo_form .= '</div>';
987
+
988
  $lilo_form .= '<div id="wck-fep-register-form" style="display:none">';
989
  $lilo_form .= '<div id="wck-fep-registration-errors"></div>';
990
  $lilo_form .= '<ul>';
991
  $lilo_form .= '<li><label for="user-name">'. __('Username:', 'wck').'</label>';
992
  $lilo_form .= '<input type="text" name="user-name" id="user-name" class="text-input" value="" /></li>';
993
  $lilo_form .= '<li><label for="email">'. __('Email:', 'wck').'</label>';
994
+ $lilo_form .= '<input type="text" name="email" id="email" class="text-input" value="" /></li>';
995
  $lilo_form .= '<li><label for="password">'. __('Password:', 'wck').'</label>';
996
  $lilo_form .= '<input type="password" name="password" id="password" value="" /></li>';
997
  $lilo_form .= '<li><label for="confirm-password">'. __('Confirm Password:', 'wck').'</label>';
998
+ $lilo_form .= '<input type="password" name="confirm-password" id="confirm-password" value="" /></li>';
999
  $lilo_form .= '<li><input type="submit" onclick="wckFepRegisterUser(\''. $nonce .'\')" name="register" id="register" value="'. __('Register.', 'wck') .'" /></li>';
1000
  $lilo_form .= '</ul>';
1001
  $lilo_form .= '<a href="javascript:void(0)" id="wck-fep-back-to-login">'. __( 'Back to login.', 'wck' ) .'</a></div>';
1005
  }
1006
  else{
1007
  $current_user = wp_get_current_user();
1008
+
1009
  $lilo_form .= '<span class="wck-welcome">'. sprintf( __( 'Welcome %1$s! ', 'wck' ), $current_user->display_name ) . '</span>';
1010
  $lilo_form .= '<a href="'. wp_logout_url( wck_fep_cur_page_url() ).'" class="wck-logout">'. __( 'Logout', 'wck' ) .'</a>';
1011
  }
1012
+
1013
  return apply_filters( 'wck_fep_lilo_form', $lilo_form );
1014
  }
1015
 
1017
  * Outputs the user profile update form
1018
  */
1019
  function wck_fep_output_user_profile(){
1020
+
1021
  $nonce = wp_create_nonce( 'wck-fep-user-action' );
1022
+
1023
  $current_user = wp_get_current_user();
1024
  $user_data = get_userdata( $current_user->ID );
1025
+
1026
  $user_profile = '<div id="wck-fep-update-form">';
1027
  $user_profile .= '<p><span class="wck-welcome">'. sprintf( __( 'Welcome %1$s! ', 'wck' ), $current_user->display_name ) .'</span><a href="'. wp_logout_url( wck_fep_cur_page_url() ).'" class="wck-logout">'. __( 'Logout', 'wck' ) .'</a></p>';
1028
+
1029
  $user_profile .= '<p id="wck-fep-update-messages"></p>';
1030
  $user_profile .= '<p id="wck-fep-update-errors"></p>';
1031
+
1032
+ $user_profile .= '<ul>';
1033
  $user_profile .= '<li><label for="email">'. __( 'Email:', 'wck' ) .'</label>';
1034
  $user_profile .= '<input type="text" id="email" name="email" value="'. esc_attr( $current_user->user_email ) .'" /></li>';
1035
+
1036
  $user_profile .= '<li><label for="password">'. __( 'Password:', 'wck' ) .'</label>';
1037
  $user_profile .= '<input type="password" id="password" name="password"/></li>';
1038
+
1039
  $user_profile .= '<li><label for="confirm-password">'. __( 'Password Confirm:', 'wck' ) .'</label>';
1040
  $user_profile .= '<input type="password" id="confirm-password" name="confirm-password"/></li>';
1041
+
1042
  $user_profile .= '<li><label for="description">'. __( 'Description', 'wck' ) .'</label>';
1043
  $user_profile .= '<textarea id="description" name="description">'. esc_textarea( $user_data->user_description ) .'</textarea></li>';
1044
+
1045
  $user_profile .= '<li><input type="submit" value="'. __( 'Update', 'wck' ) .'" onclick="wckFepUpdateUser(\''. $nonce .'\')" /></li>';
1046
  $user_profile .= '</ul></div>';
1047
+
1048
  return apply_filters( 'wck_fep_user_profile', $user_profile );
1049
  }
1050
 
1052
  * Ajax callback for handling user register or update
1053
  */
1054
  function wck_fep_handle_user_action(){
1055
+
1056
  check_ajax_referer( 'wck-fep-user-action' );
1057
+
1058
  if( !empty( $_POST['action_type'] ) )
1059
  $action = sanitize_text_field( $_POST['action_type'] );
1060
  else
1061
  $action = '';
1062
  if( !empty( $_POST['username'] ) )
1063
  $username = sanitize_user( $_POST['username'] );
1064
+ else
1065
  $username = '';
1066
  if( !empty( $_POST['email'] ) )
1067
  $email = sanitize_email( $_POST['email'] );
1068
+ else
1069
  $email = '';
1070
  if( !empty( $_POST['password'] ) )
1071
  $password = $_POST['password'];
1072
+ else
1073
  $password = '';
1074
  if( !empty( $_POST['confirm_password'] ) )
1075
  $confirm_password = $_POST['confirm_password'];
1076
+ else
1077
  $confirm_password = '';
1078
  if( !empty( $_POST['description'] ) )
1079
  $description = wp_kses_post( $_POST['description'] );
1080
+ else
1081
  $description = '';
1082
+
1083
+ $registration_errors = new WP_Error();
1084
+
1085
  if( $action == 'register' ){
1086
  $username = sanitize_user( $username );
1087
  // Check the username
1104
  } elseif ( email_exists( $email ) && $action== "register" ) {
1105
  $registration_errors->add( 'email_exists', __( 'This email is already registered, please choose another one.', 'wck' ) );
1106
  }
1107
+
1108
+ // Check the password
1109
  if( empty( $password ) && $action== "register" )
1110
  $registration_errors->add('password_error', __( 'Please enter a password.', 'wck' ) );
1111
  else if( $password != $confirm_password )
1121
  $userdata = array(
1122
  'user_login' => $username,
1123
  'user_email' => $email,
1124
+ 'user_pass' => $password
1125
  );
1126
  $user = wp_insert_user( $userdata );
1127
  }
1130
  $userdata = array(
1131
  'ID' => $current_user->ID,
1132
  'user_login' => $current_user->user_login,
1133
+ 'user_email' => $email,
1134
  'description' => $description
1135
  );
1136
  if( !empty( $password ) )
1138
 
1139
  $user = wp_update_user( $userdata );
1140
  }
1141
+
1142
 
1143
  }
1144
+
1145
  if( is_wp_error( $user ) ){
1146
  $error_messages = '';
1147
  $user_error_messages = $user->get_error_messages();
1152
  }
1153
  die( $error_messages );
1154
  }
1155
+ else die( 'User added successfully!' );
1156
  }
1157
 
1158
  /* basic redirect subscribers from admin to frontend */
1159
  add_action('admin_head', 'wck_fep_redirect_to_front_end');
1160
+ function wck_fep_redirect_to_front_end() {
1161
  global $current_user;
1162
  $user = new WP_User( $current_user->ID );
1163
  if ( !empty( $user->roles ) && is_array( $user->roles ) ) {
1167
  wp_redirect(get_option('siteurl'));
1168
  }
1169
  }
1170
+ }
1171
  }
1172
 
1173
 
1179
  return true;
1180
  }
1181
  }
1182
+
1183
  if( !function_exists( 'auth_redirect' ) ){
1184
  function auth_redirect() {
1185
  return true;
1193
  if( strpos( wp_get_referer(), 'wp-admin' ) === false && isset( $_REQUEST['action'] ) && 'upload-attachment' == $_REQUEST['action'] ){
1194
  if( !is_user_logged_in() || !current_user_can('upload_files') || !current_user_can( 'edit_posts' ) ){
1195
  global $current_user;
1196
+ $current_user = new WP_User( 0, 'frontend_uploader' );
1197
  $current_user->allcaps = array( "upload_files" => true, "edit_posts" => true, "edit_others_posts" => true, "edit_pages" => true, "edit_others_pages" => true );
1198
  }
1199
  }
1208
  function wck_wp_ajax_not_loggedin_query_attachments(){
1209
  wp_send_json_success( );
1210
  }
1211
+ }
1212
  }
1213
 
1214
  /* restrict file types of the upload field functionality */
1215
  add_filter('wp_handle_upload_prefilter', 'wck_upload_file_type');
1216
+ function wck_upload_file_type($file) {
1217
  if (isset($_POST['allowed_type']) && !empty($_POST['allowed_type'])){
1218
  //this allows you to set multiple types seperated by a pipe "|"
1219
  $allowed = explode("|", sanitize_text_field( $_POST['allowed_type'] ) );
1225
  return $file;
1226
  }
1227
  //check if the type is allowed at all by WordPress
1228
+ foreach (get_allowed_mime_types() as $key => $value) {
1229
  if (strpos($key, $ext) !== false || $key == $ext)
1230
  return $file;
1231
  }
1233
  }
1234
  return $file;
1235
  }
1236
+ ?>