Version Description
- Removed all notices and warnings from the code
Download this release
Release Info
Developer | madalin.ungureanu |
Plugin | Custom Post Types and Custom Fields creator – WCK |
Version | 1.0.3 |
Comparing to | |
See all releases |
Code changes from version 1.0.2 to 1.0.3
- css/wck-cfc.css +57 -43
- js/wck-cfc.js +22 -5
- readme.txt +5 -2
- wck-cfc.php +140 -155
- wck-cptc.php +13 -8
- wck-ctc.php +5 -3
- wck.php +6 -1
- wordpress-creation-kit-api/fields/checkbox.php +33 -31
- wordpress-creation-kit-api/fields/radio.php +4 -1
- wordpress-creation-kit-api/fields/select.php +6 -4
- wordpress-creation-kit-api/fields/text.php +4 -1
- wordpress-creation-kit-api/fields/textarea.php +4 -1
- wordpress-creation-kit-api/fields/upload.php +9 -1
- wordpress-creation-kit-api/readme.txt +134 -134
- wordpress-creation-kit-api/wordpress-creation-kit.css +15 -0
- wordpress-creation-kit-api/wordpress-creation-kit.js +54 -14
- wordpress-creation-kit-api/wordpress-creation-kit.php +418 -225
css/wck-cfc.css
CHANGED
@@ -1,44 +1,58 @@
|
|
1 |
-
#wck_cfc_fields .row-options, #wck_cfc_fields .row-attach-upload-to-post{
|
2 |
-
display:none;
|
3 |
-
}
|
4 |
-
|
5 |
-
#
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
#
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
}
|
26 |
-
|
27 |
-
.
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
background:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
}
|
1 |
+
#wck_cfc_fields .row-options, #wck_cfc_fields .row-attach-upload-to-post, #wck_cfc_fields .row-cpt{
|
2 |
+
display:none;
|
3 |
+
}
|
4 |
+
|
5 |
+
#container_wck_cfc_fields .row-options,
|
6 |
+
#container_wck_cfc_fields .row-attach-upload-to-post,
|
7 |
+
#container_wck_cfc_fields .row-cpt{
|
8 |
+
display:none;
|
9 |
+
}
|
10 |
+
|
11 |
+
#container_wck_cfc_fields .element_type_cpt-select .row-cpt,
|
12 |
+
#container_wck_cfc_fields .element_type_checkbox .row-options,
|
13 |
+
#container_wck_cfc_fields .element_type_select .row-options,
|
14 |
+
#container_wck_cfc_fields .element_type_radio .row-options,
|
15 |
+
#container_wck_cfc_fields .element_type_upload .row-attach-upload-to-post{
|
16 |
+
display:block;
|
17 |
+
}
|
18 |
+
|
19 |
+
#edit-slug-box{
|
20 |
+
display:none;
|
21 |
+
}
|
22 |
+
|
23 |
+
#minor-publishing-actions{
|
24 |
+
display:none;
|
25 |
+
}
|
26 |
+
|
27 |
+
#visibility.misc-pub-section {
|
28 |
+
display:none;
|
29 |
+
}
|
30 |
+
|
31 |
+
li.slug-title{
|
32 |
+
margin-top:-6px;
|
33 |
+
font-size:10px;
|
34 |
+
}
|
35 |
+
|
36 |
+
li.slug-title span{
|
37 |
+
padding:0 3px;
|
38 |
+
background-color:#FFFBCC;
|
39 |
+
}
|
40 |
+
|
41 |
+
.cfc-message{
|
42 |
+
margin: 0 0 15px;
|
43 |
+
background-color: #FFFFE0;
|
44 |
+
border-color: #E6DB55;
|
45 |
+
padding: 0 0.6em;
|
46 |
+
border-radius: 3px 3px 3px 3px;
|
47 |
+
border-style: solid;
|
48 |
+
border-width: 1px;
|
49 |
+
}
|
50 |
+
|
51 |
+
.cfc-message p{
|
52 |
+
margin: 0.5em 0;
|
53 |
+
padding: 2px;
|
54 |
+
}
|
55 |
+
|
56 |
+
#icon-wck-page{
|
57 |
+
background:url( ../images/wck-32x32.png ) 0 0 no-repeat;;
|
58 |
}
|
js/wck-cfc.js
CHANGED
@@ -1,4 +1,7 @@
|
|
1 |
jQuery(function(){
|
|
|
|
|
|
|
2 |
jQuery( '#wck_cfc_fields #field-type' ).live( 'change', function () {
|
3 |
value = jQuery(this).val();
|
4 |
|
@@ -15,22 +18,36 @@ jQuery(function(){
|
|
15 |
else{
|
16 |
jQuery( '#wck_cfc_fields .row-attach-upload-to-post' ).hide();
|
17 |
}
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
jQuery( '#container_wck_cfc_fields #field-type' ).live( 'change', function () {
|
21 |
value = jQuery(this).val();
|
22 |
if( value == 'select' || value == 'checkbox' || value == 'radio' ){
|
23 |
-
jQuery(
|
24 |
}
|
25 |
else{
|
26 |
-
jQuery(
|
27 |
}
|
28 |
|
29 |
if( value == 'upload' ){
|
30 |
-
jQuery(
|
31 |
}
|
32 |
else{
|
33 |
-
jQuery(
|
|
|
|
|
|
|
|
|
34 |
}
|
|
|
|
|
|
|
|
|
35 |
});
|
36 |
});
|
1 |
jQuery(function(){
|
2 |
+
|
3 |
+
|
4 |
+
|
5 |
jQuery( '#wck_cfc_fields #field-type' ).live( 'change', function () {
|
6 |
value = jQuery(this).val();
|
7 |
|
18 |
else{
|
19 |
jQuery( '#wck_cfc_fields .row-attach-upload-to-post' ).hide();
|
20 |
}
|
21 |
+
|
22 |
+
if( value == 'cpt select' ){
|
23 |
+
jQuery( '#wck_cfc_fields .row-cpt' ).show();
|
24 |
+
}
|
25 |
+
else{
|
26 |
+
jQuery( '#wck_cfc_fields .row-cpt' ).hide();
|
27 |
+
} });
|
28 |
|
29 |
jQuery( '#container_wck_cfc_fields #field-type' ).live( 'change', function () {
|
30 |
value = jQuery(this).val();
|
31 |
if( value == 'select' || value == 'checkbox' || value == 'radio' ){
|
32 |
+
jQuery(this).parent().parent().parent().children(".row-options").show();
|
33 |
}
|
34 |
else{
|
35 |
+
jQuery(this).parent().parent().parent().children(".row-options").hide();
|
36 |
}
|
37 |
|
38 |
if( value == 'upload' ){
|
39 |
+
jQuery(this).parent().parent().parent().children(".row-attach-upload-to-post").show();
|
40 |
}
|
41 |
else{
|
42 |
+
jQuery(this).parent().parent().parent().children(".row-attach-upload-to-post").hide();
|
43 |
+
}
|
44 |
+
|
45 |
+
if( value == 'cpt select' ){
|
46 |
+
jQuery(this).parent().parent().parent().children(".row-cpt").show();
|
47 |
}
|
48 |
+
else{
|
49 |
+
jQuery(this).parent().parent().parent().children(".row-cpt").hide();
|
50 |
+
}
|
51 |
+
|
52 |
});
|
53 |
});
|
readme.txt
CHANGED
@@ -5,8 +5,8 @@ Donate link: http://www.cozmoslabs.com/wordpress-creation-kit-sale-page/
|
|
5 |
Tags: custom fields, custom field, wordpress custom fields, advanced custom fields, custom post type, custom post types, post types, repeater fields, repeater, repeatable, meta box, meta boxes, metabox, taxonomy, taxonomies, custom taxonomy, custom taxonomies, custom, custom fields creator, post meta, meta, get_post_meta, post creator, cck, content types, types
|
6 |
|
7 |
Requires at least: 3.1
|
8 |
-
Tested up to: 3.
|
9 |
-
Stable tag: 1.0.
|
10 |
|
11 |
A must have tool for creating custom fields, custom post types and taxonomies, fast and without any programming knowledge.
|
12 |
|
@@ -138,6 +138,9 @@ Creating a taxonomy generally automatically creates a special query variable usi
|
|
138 |
10. Taxonomy listing
|
139 |
|
140 |
== Changelog ==
|
|
|
|
|
|
|
141 |
= 1.0.2 =
|
142 |
* Fixed bug when arguments contained UTF8 characters ( like hebrew, chirilic... )
|
143 |
* Fixed Sortable field in Custom Fields Creator that wasn't clickable
|
5 |
Tags: custom fields, custom field, wordpress custom fields, advanced custom fields, custom post type, custom post types, post types, repeater fields, repeater, repeatable, meta box, meta boxes, metabox, taxonomy, taxonomies, custom taxonomy, custom taxonomies, custom, custom fields creator, post meta, meta, get_post_meta, post creator, cck, content types, types
|
6 |
|
7 |
Requires at least: 3.1
|
8 |
+
Tested up to: 3.6.1
|
9 |
+
Stable tag: 1.0.3
|
10 |
|
11 |
A must have tool for creating custom fields, custom post types and taxonomies, fast and without any programming knowledge.
|
12 |
|
138 |
10. Taxonomy listing
|
139 |
|
140 |
== Changelog ==
|
141 |
+
= 1.0.3 =
|
142 |
+
* Removed all notices and warnings from the code
|
143 |
+
|
144 |
= 1.0.2 =
|
145 |
* Fixed bug when arguments contained UTF8 characters ( like hebrew, chirilic... )
|
146 |
* Fixed Sortable field in Custom Fields Creator that wasn't clickable
|
wck-cfc.php
CHANGED
@@ -4,14 +4,20 @@
|
|
4 |
/* Add Scripts */
|
5 |
add_action('admin_enqueue_scripts', 'wck_cfc_print_scripts' );
|
6 |
function wck_cfc_print_scripts($hook){
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
}
|
16 |
|
17 |
/* hook to create custom post types */
|
@@ -70,10 +76,12 @@ function wck_cfc_create_box(){
|
|
70 |
);
|
71 |
$output = 'objects'; // or objects
|
72 |
$post_types = get_post_types($args,$output);
|
73 |
-
$post_type_names = array();
|
74 |
-
|
75 |
-
|
76 |
-
$
|
|
|
|
|
77 |
}
|
78 |
|
79 |
/* get page templates */
|
@@ -88,6 +96,12 @@ function wck_cfc_create_box(){
|
|
88 |
array( 'type' => 'text', 'title' => __( 'Post ID', 'wck' ), 'description' => __( 'ID of a post on which the meta box should appear.', 'wck' ) )
|
89 |
);
|
90 |
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
if( !empty( $templates ) )
|
92 |
$cfc_box_args_fields[] = array( 'type' => 'select', 'title' => __( 'Page Template', 'wck' ), 'options' => $templates, 'default-option' => true, 'description' => __( 'If post type is "page" you can further select a page templete. The meta box will only appear on the page that has that selected page template.', 'wck' ) );
|
93 |
|
@@ -106,19 +120,23 @@ function wck_cfc_create_box(){
|
|
106 |
new Wordpress_Creation_Kit( $args );
|
107 |
|
108 |
/* set up field types */
|
109 |
-
$field_types = array( 'text', 'textarea', 'select', 'checkbox', 'radio', 'upload', 'wysiwyg editor', 'datepicker', 'country select', 'user select' );
|
110 |
$field_types = apply_filters( 'wck_field_types', $field_types );
|
111 |
|
|
|
|
|
|
|
112 |
/* set up the fields array */
|
113 |
-
$cfc_box_fields_fields = array(
|
114 |
array( 'type' => 'text', 'title' => __( 'Field Title', 'wck' ), 'description' => __( 'Title of the field. A slug will automatically be generated.', 'wck' ), 'required' => true ),
|
115 |
array( 'type' => 'select', 'title' => __( 'Field Type', 'wck' ), 'options' => $field_types, 'default-option' => true, 'description' => __( 'The field type', 'wck' ), 'required' => true ),
|
116 |
array( 'type' => 'textarea', 'title' => __( 'Description', 'wck' ), 'description' => 'The description of the field.' ),
|
117 |
array( 'type' => 'select', 'title' => __( 'Required', 'wck' ), 'options' => array( 'false', 'true' ), 'default' => 'false', 'description' => __( 'Whether the field is required or not', 'wck' ) ),
|
|
|
118 |
array( 'type' => 'text', 'title' => __( 'Default Value', 'wck' ), 'description' => __( 'Default value of the field. For Checkboxes if there are multiple values separete them with a ","', 'wck' ) ),
|
119 |
array( 'type' => 'text', 'title' => __( 'Options', 'wck' ), 'description' => __( 'Options for field types "select", "checkbox" and "radio". For multiple options separete them with a ",". You can use the following structure if you want the label to be different from the value: %LabelOne%valueone,%LabelTwo%valuetwo,%LabelThree%valuethree', 'wck' ) ),
|
120 |
array( 'type' => 'radio', 'title' => __( 'Attach upload to post', 'wck' ), 'description' => __( 'Whether or not the uploads should be attached to the post', 'wck' ), 'options' => array( 'yes', 'no' ) )
|
121 |
-
);
|
122 |
|
123 |
|
124 |
/* set up the box arguments */
|
@@ -140,78 +158,18 @@ function wck_cfc_description_for_args_box(){
|
|
140 |
echo '<div class="cfc-message"><p>'. __( 'Enter below the arguments for the meta box.', 'wck' ) .'</p></div>';
|
141 |
}
|
142 |
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
return $form;
|
149 |
-
}
|
150 |
-
|
151 |
-
add_filter( "wck_before_update_form_wck_cfc_fields_element_5", 'wck_cfc_update_form_option_wrapper_start', 10, 3 );
|
152 |
-
function wck_cfc_update_form_option_wrapper_start( $form, $i, $value ){
|
153 |
-
if( !in_array( $GLOBALS['wck_cfc_update_field_type'], array( 'select', 'checkbox', 'radio' ) ) )
|
154 |
-
$form .= '<div class="hide-options" style="display:none;">';
|
155 |
-
return $form;
|
156 |
}
|
157 |
|
158 |
-
add_filter(
|
159 |
-
function
|
160 |
-
|
161 |
-
|
162 |
-
return $
|
163 |
-
}
|
164 |
-
|
165 |
-
/* attach to post show or hide based on field typr */
|
166 |
-
add_filter( "wck_before_update_form_wck_cfc_fields_element_6", 'wck_cfc_update_form_attach_wrapper_start', 10, 3 );
|
167 |
-
function wck_cfc_update_form_attach_wrapper_start( $form, $i, $value ){
|
168 |
-
if( $GLOBALS['wck_cfc_update_field_type'] != 'upload' )
|
169 |
-
$form .= '<div class="hide-attach" style="display:none;">';
|
170 |
-
return $form;
|
171 |
-
}
|
172 |
-
|
173 |
-
add_filter( "wck_after_update_form_wck_cfc_fields_element_6", 'wck_cfc_update_form_attach_wrapper_end', 10, 3 );
|
174 |
-
function wck_cfc_update_form_attach_wrapper_end( $form, $i, $value ){
|
175 |
-
if( $GLOBALS['wck_cfc_update_field_type'] != 'upload' )
|
176 |
-
$form .= '</div>';
|
177 |
-
return $form;
|
178 |
-
}
|
179 |
-
|
180 |
-
|
181 |
-
/* display or show options based on the field type */
|
182 |
-
add_filter( "wck_before_listed_wck_cfc_fields_element_1", 'wck_cfc_display_label_wrapper_start', 10, 3 );
|
183 |
-
function wck_cfc_display_label_wrapper_start( $form, $i, $value ){
|
184 |
-
$GLOBALS['wck_cfc_field_type'] = $value;
|
185 |
-
return $form;
|
186 |
-
}
|
187 |
-
|
188 |
-
add_filter( "wck_before_listed_wck_cfc_fields_element_5", 'wck_cfc_display_label_wrapper_options_start', 10, 3 );
|
189 |
-
function wck_cfc_display_label_wrapper_options_start( $form, $i, $value ){
|
190 |
-
if( !in_array( $GLOBALS['wck_cfc_field_type'], array( 'select', 'checkbox', 'radio' ) ) )
|
191 |
-
$form .= '<div style="display:none;">';
|
192 |
-
return $form;
|
193 |
-
}
|
194 |
-
|
195 |
-
add_filter( "wck_after_listed_wck_cfc_fields_element_5", 'wck_cfc_display_label_wrapper_options_end', 10, 3 );
|
196 |
-
function wck_cfc_display_label_wrapper_options_end( $form, $i, $value ){
|
197 |
-
if( !in_array( $GLOBALS['wck_cfc_field_type'], array( 'select', 'checkbox', 'radio' ) ) )
|
198 |
-
$form .= '</div>';
|
199 |
-
return $form;
|
200 |
-
}
|
201 |
-
|
202 |
-
/* Show or hide attach field in list view */
|
203 |
-
add_filter( "wck_before_listed_wck_cfc_fields_element_6", 'wck_cfc_display_label_wrapper_attach_start', 10, 3 );
|
204 |
-
function wck_cfc_display_label_wrapper_attach_start( $form, $i, $value ){
|
205 |
-
if( $GLOBALS['wck_cfc_field_type'] != 'upload' )
|
206 |
-
$form .= '<div style="display:none;">';
|
207 |
-
return $form;
|
208 |
-
}
|
209 |
-
|
210 |
-
add_filter( "wck_after_listed_wck_cfc_fields_element_6", 'wck_cfc_display_label_wrapper_attach_end', 10, 3 );
|
211 |
-
function wck_cfc_display_label_wrapper_attach_end( $form, $i, $value ){
|
212 |
-
if( $GLOBALS['wck_cfc_field_type'] != 'upload' )
|
213 |
-
$form .= '</div>';
|
214 |
-
return $form;
|
215 |
}
|
216 |
|
217 |
/* Show the slug for field title */
|
@@ -242,71 +200,79 @@ function wck_cfc_create_boxes_args(){
|
|
242 |
|
243 |
$all_box_args = array();
|
244 |
|
245 |
-
|
246 |
-
$
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
$box_title
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
271 |
}
|
272 |
-
if( !empty( $wck_cfc_field['attach-upload-to-post'] ) )
|
273 |
-
$fields_inner_array['attach_to_post'] = $wck_cfc_field['attach-upload-to-post'] == 'yes' ? true : false;
|
274 |
-
|
275 |
-
$fields_array[] = $fields_inner_array;
|
276 |
}
|
277 |
-
}
|
278 |
-
|
279 |
-
if( !empty( $wck_cfc_args ) ){
|
280 |
-
foreach( $wck_cfc_args as $wck_cfc_arg ){
|
281 |
|
282 |
-
|
283 |
-
$
|
284 |
-
if( $wck_cfc_arg['meta-name'] == $metabox_id )
|
285 |
-
$metabox_id = 'wck-'. $metabox_id;
|
286 |
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
'meta_name' => $wck_cfc_arg['meta-name'],
|
292 |
-
'meta_array' => $fields_array
|
293 |
-
);
|
294 |
-
if( !empty( $wck_cfc_arg['sortable'] ) )
|
295 |
-
$box_args['sortable'] = $wck_cfc_arg['sortable'] == 'false' ? false : true;
|
296 |
-
|
297 |
-
if( !empty( $wck_cfc_arg['repeater'] ) )
|
298 |
-
$box_args['single'] = $wck_cfc_arg['repeater'] == 'false' ? true : false;
|
299 |
-
|
300 |
-
if( !empty( $wck_cfc_arg['post-id'] ) )
|
301 |
-
$box_args['post_id'] = $wck_cfc_arg['post-id'];
|
302 |
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
310 |
}
|
311 |
}
|
312 |
}
|
@@ -331,12 +297,12 @@ function wck_cfc_ceck_meta_name( $bool, $value, $post_id ){
|
|
331 |
|
332 |
if( empty( $wck_cfc_args ) ){
|
333 |
//this is the add case
|
334 |
-
$check_meta_existance = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(meta_key) FROM $wpdb->postmeta WHERE meta_key =
|
335 |
}
|
336 |
else{
|
337 |
//this is the update case
|
338 |
if( $wck_cfc_args[0]['meta-name'] != $value ){
|
339 |
-
$check_meta_existance = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(meta_key) FROM $wpdb->postmeta WHERE meta_key =
|
340 |
}
|
341 |
else
|
342 |
$check_meta_existance = false;
|
@@ -424,15 +390,19 @@ function wck_cfc_change_field_title( $meta, $id, $values, $element_id ){
|
|
424 |
|
425 |
$wck_cfc_args = get_post_meta( $id, 'wck_cfc_args', true );
|
426 |
$meta_name = $wck_cfc_args[0]['meta-name'];
|
427 |
-
$post_id_with_this_meta = $wpdb->get_results( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key =
|
428 |
|
429 |
-
|
430 |
-
$
|
431 |
-
|
432 |
-
|
433 |
-
|
|
|
|
|
|
|
|
|
|
|
434 |
}
|
435 |
-
update_post_meta( $post->post_id, $meta_name, $results );
|
436 |
}
|
437 |
}
|
438 |
}
|
@@ -444,6 +414,12 @@ function wck_cfc_edit_columns($columns){
|
|
444 |
$columns['cfc-id'] = __( "Id", "wck" );
|
445 |
$columns['cfc-post-type'] = __( "Post Type", "wck" );
|
446 |
$columns['cfc-page-template'] = __( "Page Template", "wck" );
|
|
|
|
|
|
|
|
|
|
|
|
|
447 |
return $columns;
|
448 |
}
|
449 |
|
@@ -500,7 +476,16 @@ function wck_cfc_custom_columns( $column_name, $post_id ){
|
|
500 |
if( $column_name == 'cfc-page-template' ){
|
501 |
$page_template_arg = get_post_meta( $post_id, 'wck_cfc_page_template_arg', true );
|
502 |
echo $page_template_arg;
|
503 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
504 |
}
|
505 |
|
506 |
/* Add side metaboxes */
|
4 |
/* Add Scripts */
|
5 |
add_action('admin_enqueue_scripts', 'wck_cfc_print_scripts' );
|
6 |
function wck_cfc_print_scripts($hook){
|
7 |
+
if( isset( $_GET['post_type'] ) || isset( $_GET['post'] ) ){
|
8 |
+
if( isset( $_GET['post_type'] ) )
|
9 |
+
$post_type = $_GET['post_type'];
|
10 |
+
else if( isset( $_GET['post'] ) )
|
11 |
+
$post_type = get_post_type( $_GET['post'] );
|
12 |
+
|
13 |
+
if( 'wck-meta-box' == $post_type ){
|
14 |
+
wp_register_style('wck-cfc-css', plugins_url('/css/wck-cfc.css', __FILE__));
|
15 |
+
wp_enqueue_style('wck-cfc-css');
|
16 |
+
|
17 |
+
wp_register_script('wck-cfc-js', plugins_url('/js/wck-cfc.js', __FILE__), array( 'jquery' ), '1.0' );
|
18 |
+
wp_enqueue_script('wck-cfc-js');
|
19 |
+
}
|
20 |
+
}
|
21 |
}
|
22 |
|
23 |
/* hook to create custom post types */
|
76 |
);
|
77 |
$output = 'objects'; // or objects
|
78 |
$post_types = get_post_types($args,$output);
|
79 |
+
$post_type_names = array();
|
80 |
+
if( !empty( $post_types ) ){
|
81 |
+
foreach ($post_types as $post_type ) {
|
82 |
+
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' )
|
83 |
+
$post_type_names[] = $post_type->name;
|
84 |
+
}
|
85 |
}
|
86 |
|
87 |
/* get page templates */
|
96 |
array( 'type' => 'text', 'title' => __( 'Post ID', 'wck' ), 'description' => __( 'ID of a post on which the meta box should appear.', 'wck' ) )
|
97 |
);
|
98 |
|
99 |
+
/* only in pro version */
|
100 |
+
if( function_exists( 'wck_nr_add_repeater_boxes' ) ){
|
101 |
+
$nested_arg = array( array( 'type' => 'select', 'title' => __( 'Nested', 'wck' ), 'options' => array( 'true', 'false' ), 'default' => 'false', 'description' => __( 'Set to true if you want this metabox to be a nested repeater inside another repeater.', 'wck' ) ) );
|
102 |
+
array_splice( $cfc_box_args_fields, 1, 0, $nested_arg );
|
103 |
+
}
|
104 |
+
|
105 |
if( !empty( $templates ) )
|
106 |
$cfc_box_args_fields[] = array( 'type' => 'select', 'title' => __( 'Page Template', 'wck' ), 'options' => $templates, 'default-option' => true, 'description' => __( 'If post type is "page" you can further select a page templete. The meta box will only appear on the page that has that selected page template.', 'wck' ) );
|
107 |
|
120 |
new Wordpress_Creation_Kit( $args );
|
121 |
|
122 |
/* set up field types */
|
123 |
+
$field_types = array( 'text', 'textarea', 'select', 'checkbox', 'radio', 'upload', 'wysiwyg editor', 'datepicker', 'country select', 'user select', 'cpt select' );
|
124 |
$field_types = apply_filters( 'wck_field_types', $field_types );
|
125 |
|
126 |
+
/* setup post types */
|
127 |
+
$post_types = get_post_types( '', 'names' );
|
128 |
+
|
129 |
/* set up the fields array */
|
130 |
+
$cfc_box_fields_fields = apply_filters( 'wck_cfc_box_fields_fields', array(
|
131 |
array( 'type' => 'text', 'title' => __( 'Field Title', 'wck' ), 'description' => __( 'Title of the field. A slug will automatically be generated.', 'wck' ), 'required' => true ),
|
132 |
array( 'type' => 'select', 'title' => __( 'Field Type', 'wck' ), 'options' => $field_types, 'default-option' => true, 'description' => __( 'The field type', 'wck' ), 'required' => true ),
|
133 |
array( 'type' => 'textarea', 'title' => __( 'Description', 'wck' ), 'description' => 'The description of the field.' ),
|
134 |
array( 'type' => 'select', 'title' => __( 'Required', 'wck' ), 'options' => array( 'false', 'true' ), 'default' => 'false', 'description' => __( 'Whether the field is required or not', 'wck' ) ),
|
135 |
+
array( 'type' => 'select', 'title' => __( 'CPT', 'wck' ), 'options' => $post_types, 'default' => 'post', 'description' => __( 'Select what custom post type should be used in the CPT Select.', 'wck' ) ),
|
136 |
array( 'type' => 'text', 'title' => __( 'Default Value', 'wck' ), 'description' => __( 'Default value of the field. For Checkboxes if there are multiple values separete them with a ","', 'wck' ) ),
|
137 |
array( 'type' => 'text', 'title' => __( 'Options', 'wck' ), 'description' => __( 'Options for field types "select", "checkbox" and "radio". For multiple options separete them with a ",". You can use the following structure if you want the label to be different from the value: %LabelOne%valueone,%LabelTwo%valuetwo,%LabelThree%valuethree', 'wck' ) ),
|
138 |
array( 'type' => 'radio', 'title' => __( 'Attach upload to post', 'wck' ), 'description' => __( 'Whether or not the uploads should be attached to the post', 'wck' ), 'options' => array( 'yes', 'no' ) )
|
139 |
+
) );
|
140 |
|
141 |
|
142 |
/* set up the box arguments */
|
158 |
echo '<div class="cfc-message"><p>'. __( 'Enter below the arguments for the meta box.', 'wck' ) .'</p></div>';
|
159 |
}
|
160 |
|
161 |
+
/* add css classes on update form. Allows us to show/hide elements based on field type select value */
|
162 |
+
add_filter( 'wck_update_container_class_wck_cfc_fields', 'wck_cfc_update_container_class', 10, 4 );
|
163 |
+
function wck_cfc_update_container_class($wck_update_container_css_class, $meta, $results, $element_id) {
|
164 |
+
$wck_element_type = Wordpress_Creation_Kit::wck_generate_slug( $results[$element_id]["field-type"] );
|
165 |
+
return "class='update_container_$meta update_container_$wck_element_type element_type_$wck_element_type'";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
166 |
}
|
167 |
|
168 |
+
add_filter( 'wck_element_class_wck_cfc_fields', 'wck_cfc_element_class', 10, 4 );
|
169 |
+
function wck_cfc_element_class($wck_element_class, $meta, $results, $element_id){
|
170 |
+
$wck_element_type = Wordpress_Creation_Kit::wck_generate_slug( $results[$element_id]["field-type"] );
|
171 |
+
$wck_element_class = "class='element_type_$wck_element_type'";
|
172 |
+
return $wck_element_class;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
173 |
}
|
174 |
|
175 |
/* Show the slug for field title */
|
200 |
|
201 |
$all_box_args = array();
|
202 |
|
203 |
+
if( !empty( $all_meta_boxes ) ){
|
204 |
+
foreach( $all_meta_boxes as $meta_box ){
|
205 |
+
$wck_cfc_args = get_post_meta( $meta_box->ID, 'wck_cfc_args', true );
|
206 |
+
$wck_cfc_fields = get_post_meta( $meta_box->ID, 'wck_cfc_fields', true );
|
207 |
+
|
208 |
+
$box_title = get_the_title( $meta_box->ID );
|
209 |
+
/* treat case where the post has no title */
|
210 |
+
if( empty( $box_title ) )
|
211 |
+
$box_title = '(no title)';
|
212 |
+
|
213 |
+
$fields_array = array();
|
214 |
+
if( !empty( $wck_cfc_fields ) ){
|
215 |
+
foreach( $wck_cfc_fields as $wck_cfc_field ){
|
216 |
+
$fields_inner_array = array( 'type' => $wck_cfc_field['field-type'], 'title' => $wck_cfc_field['field-title'] );
|
217 |
+
|
218 |
+
if( !empty( $wck_cfc_field['description'] ) )
|
219 |
+
$fields_inner_array['description'] = $wck_cfc_field['description'];
|
220 |
+
if( !empty( $wck_cfc_field['required'] ) )
|
221 |
+
$fields_inner_array['required'] = $wck_cfc_field['required'] == 'false' ? false : true;
|
222 |
+
if ( !empty( $wck_cfc_field['cpt'] ) )
|
223 |
+
$fields_inner_array['cpt'] = $wck_cfc_field['cpt'];
|
224 |
+
if( !empty( $wck_cfc_field['default-value'] ) )
|
225 |
+
$fields_inner_array['default'] = $wck_cfc_field['default-value'];
|
226 |
+
if( !empty( $wck_cfc_field['options'] ) ){
|
227 |
+
$fields_inner_array['options'] = explode( ',', $wck_cfc_field['options'] );
|
228 |
+
|
229 |
+
if( !empty( $fields_inner_array['options'] ) ){
|
230 |
+
foreach( $fields_inner_array['options'] as $key => $value ){
|
231 |
+
$fields_inner_array['options'][$key] = trim( $value );
|
232 |
+
}
|
233 |
+
}
|
234 |
+
|
235 |
+
}
|
236 |
+
if( !empty( $wck_cfc_field['attach-upload-to-post'] ) )
|
237 |
+
$fields_inner_array['attach_to_post'] = $wck_cfc_field['attach-upload-to-post'] == 'yes' ? true : false;
|
238 |
+
|
239 |
+
$fields_array[] = $fields_inner_array;
|
240 |
}
|
|
|
|
|
|
|
|
|
241 |
}
|
|
|
|
|
|
|
|
|
242 |
|
243 |
+
if( !empty( $wck_cfc_args ) ){
|
244 |
+
foreach( $wck_cfc_args as $wck_cfc_arg ){
|
|
|
|
|
245 |
|
246 |
+
/* metabox_id must be different from meta_name */
|
247 |
+
$metabox_id = Wordpress_Creation_Kit::wck_generate_slug( $box_title );
|
248 |
+
if( $wck_cfc_arg['meta-name'] == $metabox_id )
|
249 |
+
$metabox_id = 'wck-'. $metabox_id;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
250 |
|
251 |
+
$box_args = array(
|
252 |
+
'metabox_id' => $metabox_id,
|
253 |
+
'metabox_title' => $box_title,
|
254 |
+
'post_type' => $wck_cfc_arg['post-type'],
|
255 |
+
'meta_name' => $wck_cfc_arg['meta-name'],
|
256 |
+
'meta_array' => $fields_array
|
257 |
+
);
|
258 |
+
if( !empty( $wck_cfc_arg['sortable'] ) )
|
259 |
+
$box_args['sortable'] = $wck_cfc_arg['sortable'] == 'false' ? false : true;
|
260 |
+
|
261 |
+
if( !empty( $wck_cfc_arg['repeater'] ) )
|
262 |
+
$box_args['single'] = $wck_cfc_arg['repeater'] == 'false' ? true : false;
|
263 |
+
|
264 |
+
if( !empty( $wck_cfc_arg['post-id'] ) )
|
265 |
+
$box_args['post_id'] = $wck_cfc_arg['post-id'];
|
266 |
+
|
267 |
+
if( !empty( $wck_cfc_arg['page-template'] ) )
|
268 |
+
$box_args['page_template'] = $wck_cfc_arg['page-template'];
|
269 |
+
|
270 |
+
/* nested repeater arg for pro version only */
|
271 |
+
if( !empty( $wck_cfc_arg['nested'] ) )
|
272 |
+
$box_args['nested'] = $wck_cfc_arg['nested'] == 'false' ? false : true;
|
273 |
+
|
274 |
+
$all_box_args[] = apply_filters( "wck_cfc_box_args_".$wck_cfc_arg['meta-name'], $box_args );
|
275 |
+
}
|
276 |
}
|
277 |
}
|
278 |
}
|
297 |
|
298 |
if( empty( $wck_cfc_args ) ){
|
299 |
//this is the add case
|
300 |
+
$check_meta_existance = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(meta_key) FROM $wpdb->postmeta WHERE meta_key = %s", $value ) );
|
301 |
}
|
302 |
else{
|
303 |
//this is the update case
|
304 |
if( $wck_cfc_args[0]['meta-name'] != $value ){
|
305 |
+
$check_meta_existance = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(meta_key) FROM $wpdb->postmeta WHERE meta_key = %s", $value ) );
|
306 |
}
|
307 |
else
|
308 |
$check_meta_existance = false;
|
390 |
|
391 |
$wck_cfc_args = get_post_meta( $id, 'wck_cfc_args', true );
|
392 |
$meta_name = $wck_cfc_args[0]['meta-name'];
|
393 |
+
$post_id_with_this_meta = $wpdb->get_results( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = %s", $meta_name ) );
|
394 |
|
395 |
+
if( !empty( $post_id_with_this_meta ) ){
|
396 |
+
foreach( $post_id_with_this_meta as $post ){
|
397 |
+
$results = get_post_meta( $post->post_id, $meta_name, true );
|
398 |
+
if( !empty( $results ) ){
|
399 |
+
foreach( $results as $key => $result ){
|
400 |
+
$results[$key][ Wordpress_Creation_Kit::wck_generate_slug( $values['field-title'] ) ] = $results[$key][ Wordpress_Creation_Kit::wck_generate_slug( $wck_cfc_fields[$element_id]['field-title'] ) ];
|
401 |
+
unset( $results[$key][ Wordpress_Creation_Kit::wck_generate_slug( $wck_cfc_fields[$element_id]['field-title'] ) ] );
|
402 |
+
}
|
403 |
+
}
|
404 |
+
update_post_meta( $post->post_id, $meta_name, $results );
|
405 |
}
|
|
|
406 |
}
|
407 |
}
|
408 |
}
|
414 |
$columns['cfc-id'] = __( "Id", "wck" );
|
415 |
$columns['cfc-post-type'] = __( "Post Type", "wck" );
|
416 |
$columns['cfc-page-template'] = __( "Page Template", "wck" );
|
417 |
+
|
418 |
+
/* only in pro version */
|
419 |
+
if( function_exists( 'wck_nr_add_repeater_boxes' ) ){
|
420 |
+
$columns['cfc-nested-repeater'] = __( "Nested Repeater", "wck" );
|
421 |
+
}
|
422 |
+
|
423 |
return $columns;
|
424 |
}
|
425 |
|
476 |
if( $column_name == 'cfc-page-template' ){
|
477 |
$page_template_arg = get_post_meta( $post_id, 'wck_cfc_page_template_arg', true );
|
478 |
echo $page_template_arg;
|
479 |
+
}
|
480 |
+
|
481 |
+
/* only in pro version */
|
482 |
+
if( function_exists( 'wck_nr_add_repeater_boxes' ) ){
|
483 |
+
if( $column_name == 'cfc-nested-repeater' ){
|
484 |
+
$box_args = get_post_meta( $post_id, 'wck_cfc_args', true );
|
485 |
+
if( !empty( $box_args[0]['nested'] ) )
|
486 |
+
echo $box_args[0]['nested'];
|
487 |
+
}
|
488 |
+
}
|
489 |
}
|
490 |
|
491 |
/* Add side metaboxes */
|
wck-cptc.php
CHANGED
@@ -36,10 +36,12 @@ function wck_cptc_create_box(){
|
|
36 |
$output = 'objects';
|
37 |
$taxonomies = get_taxonomies($args,$output);
|
38 |
$taxonomie_names = array();
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
$
|
|
|
|
|
43 |
}
|
44 |
|
45 |
/* set up the fields array */
|
@@ -109,11 +111,11 @@ function wck_cptc_create_cpts(){
|
|
109 |
'edit_item' => __( $cpt['edit-item'] ? $cpt['edit-item'] : "Edit ".$cpt['singular-label'], 'wck' ) ,
|
110 |
'new_item' => __( $cpt['new-item'] ? $cpt['new-item'] : "New ".$cpt['singular-label'], 'wck' ),
|
111 |
'all_items' => __( $cpt['all-items'] ? $cpt['all-items'] : "All ".$cpt['plural-label'] , 'wck'),
|
112 |
-
'view_item' => __( $cpt['view-item'] ? $cpt['view-item'] : "View ".$cpt['singular-label'] , 'wck'),
|
113 |
'search_items' => __( $cpt['search-items'] ? $cpt['search-items'] : "Search ".$cpt['plural-label'], 'wck' ),
|
114 |
'not_found' => __( $cpt['not-found'] ? $cpt['not-found'] : "No ". strtolower( $cpt['plural-label'] ) ." found", 'wck' ),
|
115 |
'not_found_in_trash' => __( $cpt['not-found-in-trash'] ? $cpt['not-found-in-trash'] : "No ". strtolower( $cpt['plural-label'] ) ." found in Trash", 'wck' ),
|
116 |
-
'parent_item_colon' => __( $cpt['parent-item-colon'] ? $cpt['parent-item-colon'] : "Parent Page", 'wck' ),
|
117 |
'menu_name' => $cpt['menu-name'] ? $cpt['menu-name'] : $cpt['plural-label']
|
118 |
);
|
119 |
$args = array(
|
@@ -122,13 +124,16 @@ function wck_cptc_create_cpts(){
|
|
122 |
'description' => $cpt['description'],
|
123 |
'publicly_queryable' => true,
|
124 |
'show_ui' => $cpt['show-ui'] == 'false' ? false : true,
|
125 |
-
'show_in_nav_menus' => $cpt['show-in-nav-menus'] == 'false' ? false : true,
|
126 |
-
'show_in_menu' => $cpt['show-in-menu'] == 'true' ? true : $cpt['show-in-menu'],
|
127 |
'has_archive' => $cpt['has-archive'] == 'false' ? false : true,
|
128 |
'hierarchical' => $cpt['hierarchical'] == 'false' ? false : true,
|
129 |
'supports' => explode( ', ', $cpt['supports'] )
|
130 |
);
|
131 |
|
|
|
|
|
|
|
|
|
132 |
if( !empty( $cpt['menu-position'] ) )
|
133 |
$args['menu_position'] = intval( $cpt['menu-position'] );
|
134 |
|
36 |
$output = 'objects';
|
37 |
$taxonomies = get_taxonomies($args,$output);
|
38 |
$taxonomie_names = array();
|
39 |
+
|
40 |
+
if( !empty( $taxonomies ) ){
|
41 |
+
foreach ($taxonomies as $taxonomie ) {
|
42 |
+
if ( $taxonomie->name != 'nav_menu' && $taxonomie->name != 'post_format')
|
43 |
+
$taxonomie_names[] = $taxonomie->name;
|
44 |
+
}
|
45 |
}
|
46 |
|
47 |
/* set up the fields array */
|
111 |
'edit_item' => __( $cpt['edit-item'] ? $cpt['edit-item'] : "Edit ".$cpt['singular-label'], 'wck' ) ,
|
112 |
'new_item' => __( $cpt['new-item'] ? $cpt['new-item'] : "New ".$cpt['singular-label'], 'wck' ),
|
113 |
'all_items' => __( $cpt['all-items'] ? $cpt['all-items'] : "All ".$cpt['plural-label'] , 'wck'),
|
114 |
+
'view_item' => __( !empty( $cpt['view-item'] ) ? $cpt['view-item'] : "View ".$cpt['singular-label'] , 'wck'),
|
115 |
'search_items' => __( $cpt['search-items'] ? $cpt['search-items'] : "Search ".$cpt['plural-label'], 'wck' ),
|
116 |
'not_found' => __( $cpt['not-found'] ? $cpt['not-found'] : "No ". strtolower( $cpt['plural-label'] ) ." found", 'wck' ),
|
117 |
'not_found_in_trash' => __( $cpt['not-found-in-trash'] ? $cpt['not-found-in-trash'] : "No ". strtolower( $cpt['plural-label'] ) ." found in Trash", 'wck' ),
|
118 |
+
'parent_item_colon' => __( !empty( $cpt['parent-item-colon'] ) ? $cpt['parent-item-colon'] : "Parent Page", 'wck' ),
|
119 |
'menu_name' => $cpt['menu-name'] ? $cpt['menu-name'] : $cpt['plural-label']
|
120 |
);
|
121 |
$args = array(
|
124 |
'description' => $cpt['description'],
|
125 |
'publicly_queryable' => true,
|
126 |
'show_ui' => $cpt['show-ui'] == 'false' ? false : true,
|
127 |
+
'show_in_nav_menus' => !empty( $cpt['show-in-nav-menus'] ) && $cpt['show-in-nav-menus'] == 'false' ? false : true,
|
|
|
128 |
'has_archive' => $cpt['has-archive'] == 'false' ? false : true,
|
129 |
'hierarchical' => $cpt['hierarchical'] == 'false' ? false : true,
|
130 |
'supports' => explode( ', ', $cpt['supports'] )
|
131 |
);
|
132 |
|
133 |
+
if( !empty( $cpt['show-in-menu'] ) ){
|
134 |
+
$args['show_in_menu'] = $cpt['show-in-menu'] == 'true' ? true : $cpt['show-in-menu'];
|
135 |
+
}
|
136 |
+
|
137 |
if( !empty( $cpt['menu-position'] ) )
|
138 |
$args['menu_position'] = intval( $cpt['menu-position'] );
|
139 |
|
wck-ctc.php
CHANGED
@@ -25,9 +25,11 @@ function wck_ctc_create_box(){
|
|
25 |
$output = 'objects'; // or objects
|
26 |
$post_types = get_post_types($args,$output);
|
27 |
$post_type_names = array();
|
28 |
-
|
29 |
-
|
30 |
-
$
|
|
|
|
|
31 |
}
|
32 |
|
33 |
|
25 |
$output = 'objects'; // or objects
|
26 |
$post_types = get_post_types($args,$output);
|
27 |
$post_type_names = array();
|
28 |
+
if( !empty( $post_types ) ){
|
29 |
+
foreach ( $post_types as $post_type ) {
|
30 |
+
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' )
|
31 |
+
$post_type_names[] = $post_type->name;
|
32 |
+
}
|
33 |
}
|
34 |
|
35 |
|
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: Reflection Media, Madalin Ungureanu
|
6 |
-
Version: 1.0.
|
7 |
Author URI: http://www.reflectionmedia.ro
|
8 |
|
9 |
License: GPL2
|
@@ -91,4 +91,9 @@ if (file_exists ($wck_premium_update . 'update-checker.php')){
|
|
91 |
$wck_update = new wck_PluginUpdateChecker('http://updatemetadata.cozmoslabs.com/?localSerialNumber='.$wck_serial.'&uniqueproduct=WCKH', __FILE__, 'wck-hobby');
|
92 |
}
|
93 |
}
|
|
|
|
|
|
|
|
|
|
|
94 |
?>
|
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: Reflection Media, Madalin Ungureanu
|
6 |
+
Version: 1.0.3
|
7 |
Author URI: http://www.reflectionmedia.ro
|
8 |
|
9 |
License: GPL2
|
91 |
$wck_update = new wck_PluginUpdateChecker('http://updatemetadata.cozmoslabs.com/?localSerialNumber='.$wck_serial.'&uniqueproduct=WCKH', __FILE__, 'wck-hobby');
|
92 |
}
|
93 |
}
|
94 |
+
|
95 |
+
/* include nested repeaters */
|
96 |
+
if( file_exists( dirname(__FILE__).'/wordpress-creation-kit-api/wck-nested-repeaters/wck-nested-repeaters.php' ) )
|
97 |
+
require_once('wordpress-creation-kit-api/wck-nested-repeaters/wck-nested-repeaters.php');
|
98 |
+
|
99 |
?>
|
wordpress-creation-kit-api/fields/checkbox.php
CHANGED
@@ -5,37 +5,39 @@
|
|
5 |
* @param string $context Context where the function is used. Depending on it some actions are preformed.;
|
6 |
* @return string $element input element html string. */
|
7 |
|
8 |
-
|
9 |
-
$element .= '<div class="wck-checkboxes">';
|
10 |
-
foreach( $details['options'] as $option ){
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
|
|
32 |
}
|
33 |
}
|
|
|
|
|
|
|
|
|
|
|
34 |
}
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
$element .= '</div>';
|
39 |
-
}
|
40 |
-
|
41 |
-
?>
|
5 |
* @param string $context Context where the function is used. Depending on it some actions are preformed.;
|
6 |
* @return string $element input element html string. */
|
7 |
|
8 |
+
if( !empty( $details['options'] ) ){
|
9 |
+
$element .= '<div class="wck-checkboxes">';
|
10 |
+
foreach( $details['options'] as $option ){
|
11 |
+
$found = false;
|
12 |
+
|
13 |
+
if( !is_array( $value ) )
|
14 |
+
$values = explode( ', ', $value );
|
15 |
+
else
|
16 |
+
$values = $value;
|
17 |
+
|
18 |
+
if( strpos( $option, '%' ) === false ){
|
19 |
+
$label = $option;
|
20 |
+
$value_attr = $option;
|
21 |
+
if ( in_array( $option, $values ) )
|
22 |
+
$found = true;
|
23 |
+
}
|
24 |
+
else{
|
25 |
+
$option_parts = explode( '%', $option );
|
26 |
+
if( !empty( $option_parts ) ){
|
27 |
+
if( empty( $option_parts[0] ) && count( $option_parts ) == 3 ){
|
28 |
+
$label = $option_parts[1];
|
29 |
+
$value_attr = $option_parts[2];
|
30 |
+
if ( in_array( $option_parts[2], $values ) )
|
31 |
+
$found = true;
|
32 |
+
}
|
33 |
}
|
34 |
}
|
35 |
+
|
36 |
+
$element .= '<div><label><input type="checkbox" name="'. esc_attr( Wordpress_Creation_Kit::wck_generate_slug( $details['title'] ) ) .'" id="';
|
37 |
+
if( !empty( $frontend_prefix ) )
|
38 |
+
$element .= $frontend_prefix;
|
39 |
+
$element .= esc_attr( Wordpress_Creation_Kit::wck_generate_slug( $details['title'] . '_' . $value_attr ) ) .'" value="'. esc_attr( $value_attr ) .'" '. checked( $found, true, false ) .'class="mb-checkbox mb-field" />'. esc_html( $label ) .'</label></div>' ;
|
40 |
}
|
41 |
+
$element .= '</div>';
|
42 |
+
}
|
43 |
+
?>
|
|
|
|
|
|
|
|
wordpress-creation-kit-api/fields/radio.php
CHANGED
@@ -29,7 +29,10 @@ if( !empty( $details['options'] ) ){
|
|
29 |
}
|
30 |
}
|
31 |
|
32 |
-
$element .= '<div><label><input type="radio" name="'. esc_attr( Wordpress_Creation_Kit::wck_generate_slug( $details['title'] ) ) .'" id="'
|
|
|
|
|
|
|
33 |
}
|
34 |
$element .= '</div>';
|
35 |
}
|
29 |
}
|
30 |
}
|
31 |
|
32 |
+
$element .= '<div><label><input type="radio" name="'. esc_attr( Wordpress_Creation_Kit::wck_generate_slug( $details['title'] ) ) .'" id="';
|
33 |
+
if( !empty( $frontend_prefix ) )
|
34 |
+
$element .= $frontend_prefix;
|
35 |
+
$element .= esc_attr( Wordpress_Creation_Kit::wck_generate_slug( $details['title'] . '_' . $value_attr ) ) .'" value="'. esc_attr( $value_attr ) .'" '. checked( $found, true, false ) .'class="mb-radio mb-field" />'. esc_html( $label ) .'</label></div>';
|
36 |
}
|
37 |
$element .= '</div>';
|
38 |
}
|
wordpress-creation-kit-api/fields/select.php
CHANGED
@@ -5,15 +5,17 @@
|
|
5 |
* @param string $context Context where the function is used. Depending on it some actions are preformed.;
|
6 |
* @return string $element input element html string. */
|
7 |
|
8 |
-
$element .= '<select name="'. esc_attr( Wordpress_Creation_Kit::wck_generate_slug( $details['title'] ) ) .'" id="'
|
|
|
|
|
|
|
9 |
|
10 |
if( !empty( $details['default-option'] ) && $details['default-option'] )
|
11 |
$element .= '<option value="">'. __('...Chose', 'wck') .'</option>';
|
12 |
|
|
|
13 |
if( !empty( $details['options'] ) ){
|
14 |
-
|
15 |
-
$i = 0;
|
16 |
-
$options = '';
|
17 |
foreach( $details['options'] as $option ){
|
18 |
|
19 |
if( strpos( $option, '%' ) === false ){
|
5 |
* @param string $context Context where the function is used. Depending on it some actions are preformed.;
|
6 |
* @return string $element input element html string. */
|
7 |
|
8 |
+
$element .= '<select name="'. esc_attr( Wordpress_Creation_Kit::wck_generate_slug( $details['title'] ) ) .'" id="';
|
9 |
+
if( !empty( $frontend_prefix ) )
|
10 |
+
$element .= $frontend_prefix;
|
11 |
+
$element .= esc_attr( Wordpress_Creation_Kit::wck_generate_slug( $details['title'] ) ) .'" class="mb-select mb-field" >';
|
12 |
|
13 |
if( !empty( $details['default-option'] ) && $details['default-option'] )
|
14 |
$element .= '<option value="">'. __('...Chose', 'wck') .'</option>';
|
15 |
|
16 |
+
$options = '';
|
17 |
if( !empty( $details['options'] ) ){
|
18 |
+
$i = 0;
|
|
|
|
|
19 |
foreach( $details['options'] as $option ){
|
20 |
|
21 |
if( strpos( $option, '%' ) === false ){
|
wordpress-creation-kit-api/fields/text.php
CHANGED
@@ -6,5 +6,8 @@
|
|
6 |
* @return string $element input element html string. */
|
7 |
|
8 |
|
9 |
-
$element .= '<input type="text" name="'. esc_attr( Wordpress_Creation_Kit::wck_generate_slug( $details['title'] ) ) .'" id="'
|
|
|
|
|
|
|
10 |
?>
|
6 |
* @return string $element input element html string. */
|
7 |
|
8 |
|
9 |
+
$element .= '<input type="text" name="'. esc_attr( Wordpress_Creation_Kit::wck_generate_slug( $details['title'] ) ) .'" id="';
|
10 |
+
if( !empty( $frontend_prefix ) )
|
11 |
+
$element .= $frontend_prefix;
|
12 |
+
$element .= esc_attr( Wordpress_Creation_Kit::wck_generate_slug( $details['title'] ) ) .'" value="'. esc_attr( $value ) .'" class="mb-text-input mb-field"/>';
|
13 |
?>
|
wordpress-creation-kit-api/fields/textarea.php
CHANGED
@@ -5,5 +5,8 @@
|
|
5 |
* @param string $context Context where the function is used. Depending on it some actions are preformed.;
|
6 |
* @return string $element input element html string. */
|
7 |
|
8 |
-
$element .= '<textarea name="'. esc_attr( Wordpress_Creation_Kit::wck_generate_slug( $details['title'] ) ) .'" id="'
|
|
|
|
|
|
|
9 |
?>
|
5 |
* @param string $context Context where the function is used. Depending on it some actions are preformed.;
|
6 |
* @return string $element input element html string. */
|
7 |
|
8 |
+
$element .= '<textarea name="'. esc_attr( Wordpress_Creation_Kit::wck_generate_slug( $details['title'] ) ) .'" id="';
|
9 |
+
if( !empty( $frontend_prefix ) )
|
10 |
+
$element .= $frontend_prefix;
|
11 |
+
$element .= esc_attr( Wordpress_Creation_Kit::wck_generate_slug( $details['title'] ) ) .'" style="vertical-align:top;" class="mb-textarea mb-field">'. esc_html( $value ) .'</textarea>';
|
12 |
?>
|
wordpress-creation-kit-api/fields/upload.php
CHANGED
@@ -12,6 +12,9 @@ $upload_info_div_id = str_replace( '-', '_', Wordpress_Creation_Kit::wck_generat
|
|
12 |
/* hidden input that will hold the attachment id */
|
13 |
$element .= '<input id="'. esc_attr( $upload_input_id ) .'" type="hidden" size="36" name="'. esc_attr( Wordpress_Creation_Kit::wck_generate_slug( $details['title'] ) ) .'" value="'. $value .'" class="mb-text-input mb-field"/>';
|
14 |
|
|
|
|
|
|
|
15 |
/* container for the image preview (or file ico) and name and file type */
|
16 |
if( !empty ( $value ) ){
|
17 |
$file_src = wp_get_attachment_url($value);
|
@@ -28,10 +31,15 @@ if( !empty ( $value ) )
|
|
28 |
$element .= '<span class="wck-remove-upload">'.__( 'Remove', 'wck' ).'</span>';
|
29 |
$element .= '</p></div>';
|
30 |
/* the upload link. we send through get the hidden input id, details div id and meta name */
|
31 |
-
if( $details['attach_to_post'] )
|
32 |
$attach_to_post = 'post_id='. get_the_id() .'&';
|
33 |
else
|
34 |
$attach_to_post = '';
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
$media_upload_url = 'media-upload.php?'.$attach_to_post.'type=file&mb_type='. $var_prefix . esc_js(strtolower( $upload_input_id ) ).'&mb_info_div='.$var_prefix . esc_js(strtolower( $upload_info_div_id ) ).'&meta_name='.$meta.'&TB_iframe=1';
|
37 |
|
12 |
/* hidden input that will hold the attachment id */
|
13 |
$element .= '<input id="'. esc_attr( $upload_input_id ) .'" type="hidden" size="36" name="'. esc_attr( Wordpress_Creation_Kit::wck_generate_slug( $details['title'] ) ) .'" value="'. $value .'" class="mb-text-input mb-field"/>';
|
14 |
|
15 |
+
$thumbnail = '';
|
16 |
+
$file_name = '';
|
17 |
+
$file_type = '';
|
18 |
/* container for the image preview (or file ico) and name and file type */
|
19 |
if( !empty ( $value ) ){
|
20 |
$file_src = wp_get_attachment_url($value);
|
31 |
$element .= '<span class="wck-remove-upload">'.__( 'Remove', 'wck' ).'</span>';
|
32 |
$element .= '</p></div>';
|
33 |
/* the upload link. we send through get the hidden input id, details div id and meta name */
|
34 |
+
if( !empty( $details['attach_to_post'] ) )
|
35 |
$attach_to_post = 'post_id='. get_the_id() .'&';
|
36 |
else
|
37 |
$attach_to_post = '';
|
38 |
+
|
39 |
+
if( empty( $var_prefix ) )
|
40 |
+
$var_prefix = '';
|
41 |
+
if( empty( $edit_class ) )
|
42 |
+
$edit_class = '';
|
43 |
|
44 |
$media_upload_url = 'media-upload.php?'.$attach_to_post.'type=file&mb_type='. $var_prefix . esc_js(strtolower( $upload_input_id ) ).'&mb_info_div='.$var_prefix . esc_js(strtolower( $upload_info_div_id ) ).'&meta_name='.$meta.'&TB_iframe=1';
|
45 |
|
wordpress-creation-kit-api/readme.txt
CHANGED
@@ -1,135 +1,135 @@
|
|
1 |
-
Usage Example 1
|
2 |
-
|
3 |
-
<?php
|
4 |
-
|
5 |
-
$fint = array(
|
6 |
-
array( 'type' => 'text', 'title' => 'Title', 'description' => 'Description for this input' ),
|
7 |
-
array( 'type' => 'textarea', 'title' => 'Description' ),
|
8 |
-
array( 'type' => 'upload', 'title' => 'Image', 'description' => 'Upload a image' ),
|
9 |
-
array( 'type' => 'select', 'title' => 'Select This', 'options' => array( 'Option 1', 'Option 2', 'Option 3' ) ),
|
10 |
-
|
11 |
-
array( 'type' => 'checkbox', 'title' => 'Check This', 'options' => array( 'Option 1', 'Option 2', 'Option 3' ) ),
|
12 |
-
|
13 |
-
array( 'type' => 'radio', 'title' => 'Radio This', 'options' => array( 'Radio 1', 'Radio 2', 'Radio 3' ) ),
|
14 |
-
);
|
15 |
-
|
16 |
-
$args = array(
|
17 |
-
'metabox_id' => 'rm_slider_content',
|
18 |
-
'metabox_title' => 'Slideshow Class',
|
19 |
-
'post_type' => 'slideshows',
|
20 |
-
'meta_name' => 'rmscontent',
|
21 |
-
'meta_array' => $fint
|
22 |
-
);
|
23 |
-
|
24 |
-
new Wordpress_Creation_Kit( $args );
|
25 |
-
|
26 |
-
?>
|
27 |
-
|
28 |
-
For Frontend use like this:
|
29 |
-
|
30 |
-
<?php $meta = get_post_meta( $post->ID, 'rmscontent', true ); ?>
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
Default Parameters
|
36 |
-
|
37 |
-
<?php $args = array(
|
38 |
-
'metabox_id' => '',
|
39 |
-
'metabox_title' => 'Meta Box',
|
40 |
-
'post_type' => 'post',
|
41 |
-
'meta_name' => '',
|
42 |
-
'meta_array' => array(),
|
43 |
-
'page_template' => '',
|
44 |
-
'post_id' => '',
|
45 |
-
'single' => false,
|
46 |
-
'unserialize_fields' => false,
|
47 |
-
'sortable' => true,
|
48 |
-
'context' => 'post_meta'
|
49 |
-
)
|
50 |
-
?>
|
51 |
-
|
52 |
-
Parameters
|
53 |
-
|
54 |
-
$metabox_id
|
55 |
-
(string) (required) HTML 'id' attribute of the edit screen section
|
56 |
-
|
57 |
-
Default: None
|
58 |
-
|
59 |
-
$metabox_title
|
60 |
-
(string) (required) Title of the edit screen section, visible to user
|
61 |
-
|
62 |
-
Default: 'Meta Box'
|
63 |
-
|
64 |
-
$post_type
|
65 |
-
(string) (required) The type of Write screen on which to show the edit screen section ('post', 'page', 'link', or 'custom_post_type' where custom_post_type is the custom post type slug)
|
66 |
-
|
67 |
-
Default: 'post'
|
68 |
-
|
69 |
-
$meta_name
|
70 |
-
(string) (required) The name of the meta key used to query for data
|
71 |
-
|
72 |
-
Default: None
|
73 |
-
|
74 |
-
$meta_array
|
75 |
-
(array) (required) The array of fields used to create the form. See example above. Must be array( array() ). Type and Title are required.
|
76 |
-
|
77 |
-
Default: None
|
78 |
-
|
79 |
-
$page_template
|
80 |
-
(string) (optional) The name of the page template on wich you want the meta box to appear. If this is set than $post_type can be omitted.
|
81 |
-
|
82 |
-
Default: None
|
83 |
-
|
84 |
-
$post_id
|
85 |
-
(string) (optional) The id of the post you want the meta box to appear. If this is set than $post_type can be omitted.
|
86 |
-
|
87 |
-
Default: None
|
88 |
-
|
89 |
-
$single
|
90 |
-
(boolean) (optional) Set this to true if you don't want a repeater box and you will be able to enter just one value.
|
91 |
-
|
92 |
-
Default: false
|
93 |
-
|
94 |
-
$unserialize_fields
|
95 |
-
(boolean) (optional) Set this to true if you want to enable wpml compatibility
|
96 |
-
|
97 |
-
$sortable
|
98 |
-
(boolean) (optional) Wheater or not the fields in a repeater box are sortable.
|
99 |
-
|
100 |
-
Default: true
|
101 |
-
|
102 |
-
$context
|
103 |
-
(string) (optional) WCK API can add data as meta or as option depending on the context. Using 'post_meta' will add data as post meta and using 'option' will add data as option
|
104 |
-
|
105 |
-
Default: 'post_meta'
|
106 |
-
|
107 |
-
Parameters for meta_array
|
108 |
-
|
109 |
-
'title' (string) Title of the field.
|
110 |
-
'type' (string) The field type. Possible values: 'text', 'textarea', 'select', 'checkbox', 'radio', 'upload'.
|
111 |
-
'description' (string) The description of the field.
|
112 |
-
'required' (boolean) true if the field is required.
|
113 |
-
'default' (string) If you want the string to have a default value enter it here. For Checkboxes if there are multiple
|
114 |
-
values separete them with a ",".
|
115 |
-
'default-option' (boolean) true if you want Select to have a default option.
|
116 |
-
'options' (array) Options for field types "select", "checkbox" and "radio".
|
117 |
-
|
118 |
-
|
119 |
-
How to add into a plugin:
|
120 |
-
|
121 |
-
1. Copy the foldder "wordpress-creation-kit-api" into the plugin dir
|
122 |
-
2. Change the class name "Wordpress_Creation_Kit" if multiple plugins use wordpress-creation-kit-api on the same site.
|
123 |
-
3. Include "wordpress-creation-kit.php" into the plugin file
|
124 |
-
|
125 |
-
/* include Custom Fields Creator API */
|
126 |
-
require_once('wordpress-creation-kit/wordpress-creation-kit.php');
|
127 |
-
|
128 |
-
4. Use the API as in Exampe 1, in your plugin file or functions or whatever fits the situation.
|
129 |
-
|
130 |
-
|
131 |
-
WPML Compatibility
|
132 |
-
|
133 |
-
When unserialize_fields is true on a meta box, besides saving the contents of the box in one serialized custom field, we create automatically a custom field for every field in every entry. We do this because WPML can't handle serialized custom fields and also we will get good control on what actions we want to perform (don't translate, copy, translate ) on each of the fields.
|
134 |
-
|
135 |
After the fields are translated with Icanlcalize and we have the translated post in our system, we can go on the translated post and press the "Syncronize WCK Translation" button which will create the serialized array from the individual custom fields.
|
1 |
+
Usage Example 1
|
2 |
+
|
3 |
+
<?php
|
4 |
+
|
5 |
+
$fint = array(
|
6 |
+
array( 'type' => 'text', 'title' => 'Title', 'description' => 'Description for this input' ),
|
7 |
+
array( 'type' => 'textarea', 'title' => 'Description' ),
|
8 |
+
array( 'type' => 'upload', 'title' => 'Image', 'description' => 'Upload a image' ),
|
9 |
+
array( 'type' => 'select', 'title' => 'Select This', 'options' => array( 'Option 1', 'Option 2', 'Option 3' ) ),
|
10 |
+
|
11 |
+
array( 'type' => 'checkbox', 'title' => 'Check This', 'options' => array( 'Option 1', 'Option 2', 'Option 3' ) ),
|
12 |
+
|
13 |
+
array( 'type' => 'radio', 'title' => 'Radio This', 'options' => array( 'Radio 1', 'Radio 2', 'Radio 3' ) ),
|
14 |
+
);
|
15 |
+
|
16 |
+
$args = array(
|
17 |
+
'metabox_id' => 'rm_slider_content',
|
18 |
+
'metabox_title' => 'Slideshow Class',
|
19 |
+
'post_type' => 'slideshows',
|
20 |
+
'meta_name' => 'rmscontent',
|
21 |
+
'meta_array' => $fint
|
22 |
+
);
|
23 |
+
|
24 |
+
new Wordpress_Creation_Kit( $args );
|
25 |
+
|
26 |
+
?>
|
27 |
+
|
28 |
+
For Frontend use like this:
|
29 |
+
|
30 |
+
<?php $meta = get_post_meta( $post->ID, 'rmscontent', true ); ?>
|
31 |
+
|
32 |
+
|
33 |
+
|
34 |
+
|
35 |
+
Default Parameters
|
36 |
+
|
37 |
+
<?php $args = array(
|
38 |
+
'metabox_id' => '',
|
39 |
+
'metabox_title' => 'Meta Box',
|
40 |
+
'post_type' => 'post',
|
41 |
+
'meta_name' => '',
|
42 |
+
'meta_array' => array(),
|
43 |
+
'page_template' => '',
|
44 |
+
'post_id' => '',
|
45 |
+
'single' => false,
|
46 |
+
'unserialize_fields' => false,
|
47 |
+
'sortable' => true,
|
48 |
+
'context' => 'post_meta'
|
49 |
+
)
|
50 |
+
?>
|
51 |
+
|
52 |
+
Parameters
|
53 |
+
|
54 |
+
$metabox_id
|
55 |
+
(string) (required) HTML 'id' attribute of the edit screen section
|
56 |
+
|
57 |
+
Default: None
|
58 |
+
|
59 |
+
$metabox_title
|
60 |
+
(string) (required) Title of the edit screen section, visible to user
|
61 |
+
|
62 |
+
Default: 'Meta Box'
|
63 |
+
|
64 |
+
$post_type
|
65 |
+
(string) (required) The type of Write screen on which to show the edit screen section ('post', 'page', 'link', or 'custom_post_type' where custom_post_type is the custom post type slug)
|
66 |
+
|
67 |
+
Default: 'post'
|
68 |
+
|
69 |
+
$meta_name
|
70 |
+
(string) (required) The name of the meta key used to query for data
|
71 |
+
|
72 |
+
Default: None
|
73 |
+
|
74 |
+
$meta_array
|
75 |
+
(array) (required) The array of fields used to create the form. See example above. Must be array( array() ). Type and Title are required.
|
76 |
+
|
77 |
+
Default: None
|
78 |
+
|
79 |
+
$page_template
|
80 |
+
(string) (optional) The name of the page template on wich you want the meta box to appear. If this is set than $post_type can be omitted.
|
81 |
+
|
82 |
+
Default: None
|
83 |
+
|
84 |
+
$post_id
|
85 |
+
(string) (optional) The id of the post you want the meta box to appear. If this is set than $post_type can be omitted.
|
86 |
+
|
87 |
+
Default: None
|
88 |
+
|
89 |
+
$single
|
90 |
+
(boolean) (optional) Set this to true if you don't want a repeater box and you will be able to enter just one value.
|
91 |
+
|
92 |
+
Default: false
|
93 |
+
|
94 |
+
$unserialize_fields
|
95 |
+
(boolean) (optional) Set this to true if you want to enable wpml compatibility
|
96 |
+
|
97 |
+
$sortable
|
98 |
+
(boolean) (optional) Wheater or not the fields in a repeater box are sortable.
|
99 |
+
|
100 |
+
Default: true
|
101 |
+
|
102 |
+
$context
|
103 |
+
(string) (optional) WCK API can add data as meta or as option depending on the context. Using 'post_meta' will add data as post meta and using 'option' will add data as option
|
104 |
+
|
105 |
+
Default: 'post_meta'
|
106 |
+
|
107 |
+
Parameters for meta_array
|
108 |
+
|
109 |
+
'title' (string) Title of the field.
|
110 |
+
'type' (string) The field type. Possible values: 'text', 'textarea', 'select', 'checkbox', 'radio', 'upload'.
|
111 |
+
'description' (string) The description of the field.
|
112 |
+
'required' (boolean) true if the field is required.
|
113 |
+
'default' (string) If you want the string to have a default value enter it here. For Checkboxes if there are multiple
|
114 |
+
values separete them with a ",".
|
115 |
+
'default-option' (boolean) true if you want Select to have a default option.
|
116 |
+
'options' (array) Options for field types "select", "checkbox" and "radio".
|
117 |
+
|
118 |
+
|
119 |
+
How to add into a plugin:
|
120 |
+
|
121 |
+
1. Copy the foldder "wordpress-creation-kit-api" into the plugin dir
|
122 |
+
2. Change the class name "Wordpress_Creation_Kit" if multiple plugins use wordpress-creation-kit-api on the same site.
|
123 |
+
3. Include "wordpress-creation-kit.php" into the plugin file
|
124 |
+
|
125 |
+
/* include Custom Fields Creator API */
|
126 |
+
require_once('wordpress-creation-kit/wordpress-creation-kit.php');
|
127 |
+
|
128 |
+
4. Use the API as in Exampe 1, in your plugin file or functions or whatever fits the situation.
|
129 |
+
|
130 |
+
|
131 |
+
WPML Compatibility
|
132 |
+
|
133 |
+
When unserialize_fields is true on a meta box, besides saving the contents of the box in one serialized custom field, we create automatically a custom field for every field in every entry. We do this because WPML can't handle serialized custom fields and also we will get good control on what actions we want to perform (don't translate, copy, translate ) on each of the fields.
|
134 |
+
|
135 |
After the fields are translated with Icanlcalize and we have the translated post in our system, we can go on the translated post and press the "Syncronize WCK Translation" button which will create the serialized array from the individual custom fields.
|
wordpress-creation-kit-api/wordpress-creation-kit.css
CHANGED
@@ -204,4 +204,19 @@ td.wck-number{
|
|
204 |
border-top-right-radius: 3px;
|
205 |
border-width: 1px;
|
206 |
background-color:#fff;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
207 |
}
|
204 |
border-top-right-radius: 3px;
|
205 |
border-width: 1px;
|
206 |
background-color:#fff;
|
207 |
+
}
|
208 |
+
|
209 |
+
/* nested repeater */
|
210 |
+
.mb-table-container .wck-nested{
|
211 |
+
background:#F5F5F5;
|
212 |
+
border:1px solid #DFDFDF;
|
213 |
+
box-shadow: 0 1px 0 #FFFFFF;
|
214 |
+
}
|
215 |
+
|
216 |
+
.mb-table-container .wck-nested > div{
|
217 |
+
padding:10px;
|
218 |
+
}
|
219 |
+
|
220 |
+
.mb-table-container li[data-type="nested-repeater"]{
|
221 |
+
display:none;
|
222 |
}
|
wordpress-creation-kit-api/wordpress-creation-kit.js
CHANGED
@@ -52,8 +52,14 @@ function addMeta(value, id, nonce){
|
|
52 |
values[key.toString()] = jQuery(this).val().toString();
|
53 |
});
|
54 |
|
|
|
55 |
|
56 |
-
|
|
|
|
|
|
|
|
|
|
|
57 |
|
58 |
jQuery( '#'+value+' .field-label').removeClass('error');
|
59 |
|
@@ -69,7 +75,7 @@ function addMeta(value, id, nonce){
|
|
69 |
}
|
70 |
else{
|
71 |
/* refresh the list */
|
72 |
-
jQuery.post( wckAjaxurl , { action:"wck_refresh_list"+
|
73 |
|
74 |
jQuery('#container_'+value).replaceWith(response);
|
75 |
|
@@ -83,7 +89,7 @@ function addMeta(value, id, nonce){
|
|
83 |
|
84 |
/* restore the add form to the original values */
|
85 |
if( !jQuery( '#'+value ).hasClass('single') ){
|
86 |
-
jQuery.post( wckAjaxurl , { action:"wck_add_form"+
|
87 |
jQuery( '#'+value ).replaceWith( response );
|
88 |
wck_set_to_widest( '.field-label', '#'+value );
|
89 |
});
|
@@ -113,6 +119,7 @@ function addMeta(value, id, nonce){
|
|
113 |
});
|
114 |
}
|
115 |
});
|
|
|
116 |
}
|
117 |
|
118 |
/* remove reccord from the meta */
|
@@ -122,19 +129,26 @@ function removeMeta(value, id, element_id, nonce){
|
|
122 |
|
123 |
if( response == true ){
|
124 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
125 |
jQuery('#'+value).parent().css({'opacity':'0.4', 'position':'relative'}).append('<div id="mb-ajax-loading"></div>');
|
126 |
-
jQuery.post( wckAjaxurl , { action:"wck_remove_meta"+
|
127 |
|
128 |
/* If single add the form */
|
129 |
if( jQuery( '#container_'+value ).hasClass('single') ){
|
130 |
-
jQuery.post( wckAjaxurl , { action:"wck_add_form"+
|
131 |
jQuery( '#container_'+value ).before( response );
|
132 |
jQuery( '#'+value ).addClass('single');
|
133 |
});
|
134 |
}
|
135 |
|
136 |
/* refresh the list */
|
137 |
-
jQuery.post( wckAjaxurl , { action:"wck_refresh_list"+
|
138 |
jQuery('#container_'+value).replaceWith(response);
|
139 |
|
140 |
/* set width of strong label */
|
@@ -182,8 +196,16 @@ function mb_sortable_elements() {
|
|
182 |
|
183 |
jQuery('#'+value).parent().css({'opacity':'0.4', 'position':'relative'}).append('<div id="mb-ajax-loading"></div>');
|
184 |
|
185 |
-
|
186 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
187 |
jQuery('#container_'+value).replaceWith(response);
|
188 |
|
189 |
/* set width of strong label */
|
@@ -212,16 +234,25 @@ jQuery(mb_sortable_elements);
|
|
212 |
|
213 |
|
214 |
/* show the update form */
|
215 |
-
function showUpdateFormMeta(value, id, element_id, nonce){
|
216 |
if( jQuery( '#update_container_' + value + '_' + element_id ).length == 0 ){
|
217 |
jQuery('#container_'+value).parent().css({'opacity':'0.4', 'position':'relative'}).append('<div id="mb-ajax-loading"></div>');
|
218 |
|
219 |
if( jQuery( '#container_' + value + " tbody" ).hasClass('ui-sortable') )
|
220 |
jQuery( '#container_' + value + " tbody" ).sortable("disable");
|
221 |
|
222 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
223 |
//jQuery('#container_'+value+' #element_'+element_id).append(response);
|
224 |
-
jQuery(response).insertAfter('#container_'+value+' #element_'+element_id);
|
225 |
|
226 |
/* set width of field-label */
|
227 |
wck_set_to_widest('.field-label', '#update_container_' + value + '_' + element_id );
|
@@ -276,9 +307,18 @@ function updateMeta(value, id, element_id, nonce){
|
|
276 |
else
|
277 |
values[key.toString()] = jQuery(this).val().toString();
|
278 |
|
279 |
-
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
280 |
|
281 |
-
jQuery.post( wckAjaxurl , { action:"wck_update_meta"+
|
282 |
|
283 |
jQuery( '#update_container_'+value+'_'+element_id + ' .field-label').removeClass('error');
|
284 |
|
@@ -306,7 +346,7 @@ function updateMeta(value, id, element_id, nonce){
|
|
306 |
jQuery('#update_container_'+value+'_'+element_id).remove();
|
307 |
|
308 |
/* refresh the list */
|
309 |
-
jQuery.post( wckAjaxurl , { action:"wck_refresh_entry"+
|
310 |
jQuery('#container_'+value+' #element_'+element_id).replaceWith(response);
|
311 |
|
312 |
/* set width of strong label */
|
52 |
values[key.toString()] = jQuery(this).val().toString();
|
53 |
});
|
54 |
|
55 |
+
meta = value;
|
56 |
|
57 |
+
if( value.indexOf("-wcknested-") != -1 ){
|
58 |
+
metaDetails = value.split("-wcknested-");
|
59 |
+
meta = metaDetails[0];
|
60 |
+
}
|
61 |
+
|
62 |
+
jQuery.post( wckAjaxurl , { action:"wck_add_meta"+meta, meta:value, id:id, values:values, _ajax_nonce:nonce}, function(response) {
|
63 |
|
64 |
jQuery( '#'+value+' .field-label').removeClass('error');
|
65 |
|
75 |
}
|
76 |
else{
|
77 |
/* refresh the list */
|
78 |
+
jQuery.post( wckAjaxurl , { action:"wck_refresh_list"+meta, meta:value, id:id}, function(response) {
|
79 |
|
80 |
jQuery('#container_'+value).replaceWith(response);
|
81 |
|
89 |
|
90 |
/* restore the add form to the original values */
|
91 |
if( !jQuery( '#'+value ).hasClass('single') ){
|
92 |
+
jQuery.post( wckAjaxurl , { action:"wck_add_form"+meta, meta:value, id:id }, function(response) {
|
93 |
jQuery( '#'+value ).replaceWith( response );
|
94 |
wck_set_to_widest( '.field-label', '#'+value );
|
95 |
});
|
119 |
});
|
120 |
}
|
121 |
});
|
122 |
+
|
123 |
}
|
124 |
|
125 |
/* remove reccord from the meta */
|
129 |
|
130 |
if( response == true ){
|
131 |
|
132 |
+
meta = value;
|
133 |
+
|
134 |
+
if( value.indexOf("-wcknested-") != -1 ){
|
135 |
+
metaDetails = value.split("-wcknested-");
|
136 |
+
meta = metaDetails[0];
|
137 |
+
}
|
138 |
+
|
139 |
jQuery('#'+value).parent().css({'opacity':'0.4', 'position':'relative'}).append('<div id="mb-ajax-loading"></div>');
|
140 |
+
jQuery.post( wckAjaxurl , { action:"wck_remove_meta"+meta, meta:value, id:id, element_id:element_id, _ajax_nonce:nonce}, function(response) {
|
141 |
|
142 |
/* If single add the form */
|
143 |
if( jQuery( '#container_'+value ).hasClass('single') ){
|
144 |
+
jQuery.post( wckAjaxurl , { action:"wck_add_form"+meta, meta:value, id:id }, function(response) {
|
145 |
jQuery( '#container_'+value ).before( response );
|
146 |
jQuery( '#'+value ).addClass('single');
|
147 |
});
|
148 |
}
|
149 |
|
150 |
/* refresh the list */
|
151 |
+
jQuery.post( wckAjaxurl , { action:"wck_refresh_list"+meta, meta:value, id:id}, function(response) {
|
152 |
jQuery('#container_'+value).replaceWith(response);
|
153 |
|
154 |
/* set width of strong label */
|
196 |
|
197 |
jQuery('#'+value).parent().css({'opacity':'0.4', 'position':'relative'}).append('<div id="mb-ajax-loading"></div>');
|
198 |
|
199 |
+
meta = value;
|
200 |
+
|
201 |
+
if( value.indexOf("-wcknested-") != -1 ){
|
202 |
+
metaDetails = value.split("-wcknested-");
|
203 |
+
meta = metaDetails[0];
|
204 |
+
}
|
205 |
+
|
206 |
+
|
207 |
+
jQuery.post( wckAjaxurl , { action:"wck_reorder_meta"+meta, meta:value, id:id, values:values}, function(response) {
|
208 |
+
jQuery.post( wckAjaxurl , { action:"wck_refresh_list"+meta, meta:value, id:id}, function(response) {
|
209 |
jQuery('#container_'+value).replaceWith(response);
|
210 |
|
211 |
/* set width of strong label */
|
234 |
|
235 |
|
236 |
/* show the update form */
|
237 |
+
function showUpdateFormMeta(value, id, element_id, nonce){
|
238 |
if( jQuery( '#update_container_' + value + '_' + element_id ).length == 0 ){
|
239 |
jQuery('#container_'+value).parent().css({'opacity':'0.4', 'position':'relative'}).append('<div id="mb-ajax-loading"></div>');
|
240 |
|
241 |
if( jQuery( '#container_' + value + " tbody" ).hasClass('ui-sortable') )
|
242 |
jQuery( '#container_' + value + " tbody" ).sortable("disable");
|
243 |
|
244 |
+
|
245 |
+
meta = value;
|
246 |
+
|
247 |
+
if( value.indexOf("-wcknested-") != -1 ){
|
248 |
+
metaDetails = value.split("-wcknested-");
|
249 |
+
meta = metaDetails[0];
|
250 |
+
}
|
251 |
+
|
252 |
+
|
253 |
+
jQuery.post( wckAjaxurl , { action:"wck_show_update"+meta, meta:value, id:id, element_id:element_id, _ajax_nonce:nonce}, function(response) {
|
254 |
//jQuery('#container_'+value+' #element_'+element_id).append(response);
|
255 |
+
jQuery(response).insertAfter('#container_'+value+' > tbody > #element_'+element_id);
|
256 |
|
257 |
/* set width of field-label */
|
258 |
wck_set_to_widest('.field-label', '#update_container_' + value + '_' + element_id );
|
307 |
else
|
308 |
values[key.toString()] = jQuery(this).val().toString();
|
309 |
|
310 |
+
});
|
311 |
+
|
312 |
+
|
313 |
+
meta = value;
|
314 |
+
|
315 |
+
if( value.indexOf("-wcknested-") != -1 ){
|
316 |
+
metaDetails = value.split("-wcknested-");
|
317 |
+
meta = metaDetails[0];
|
318 |
+
}
|
319 |
+
|
320 |
|
321 |
+
jQuery.post( wckAjaxurl , { action:"wck_update_meta"+meta, meta:value, id:id, element_id:element_id, values:values, _ajax_nonce:nonce}, function(response) {
|
322 |
|
323 |
jQuery( '#update_container_'+value+'_'+element_id + ' .field-label').removeClass('error');
|
324 |
|
346 |
jQuery('#update_container_'+value+'_'+element_id).remove();
|
347 |
|
348 |
/* refresh the list */
|
349 |
+
jQuery.post( wckAjaxurl , { action:"wck_refresh_entry"+meta, meta:value, id:id, element_id:element_id}, function(response) {
|
350 |
jQuery('#container_'+value+' #element_'+element_id).replaceWith(response);
|
351 |
|
352 |
/* set width of strong label */
|
wordpress-creation-kit-api/wordpress-creation-kit.php
CHANGED
@@ -58,7 +58,7 @@ class Wordpress_Creation_Kit{
|
|
58 |
'page_template' => '',
|
59 |
'post_id' => '',
|
60 |
'single' => false,
|
61 |
-
'
|
62 |
'sortable' => true,
|
63 |
'context' => 'post_meta'
|
64 |
);
|
@@ -121,9 +121,15 @@ class Wordpress_Creation_Kit{
|
|
121 |
/* add class to meta box */
|
122 |
add_filter( "postbox_classes_".$this->args['post_type']."_".$this->args['metabox_id'], array( &$this, 'wck_add_metabox_classes' ) );
|
123 |
}
|
124 |
-
else{
|
125 |
-
|
126 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
127 |
if( $this->args['post_id'] != '' && $this->args['page_template'] != '' ){
|
128 |
$template_file = get_post_meta($post_id,'_wp_page_template',TRUE);
|
129 |
if( $this->args['post_id'] == $post_id && $template_file == $this->args['page_template'] )
|
@@ -169,12 +175,17 @@ class Wordpress_Creation_Kit{
|
|
169 |
return $classes;
|
170 |
}
|
171 |
|
172 |
-
function wck_content($post, $metabox){
|
|
|
|
|
|
|
|
|
|
|
173 |
//output the add form
|
174 |
if( $this->args['single'] ){
|
175 |
|
176 |
if( $this->args['context'] == 'post_meta' )
|
177 |
-
$meta_val = get_post_meta( $
|
178 |
else if ( $this->args['context'] == 'option' )
|
179 |
$meta_val = get_option( $metabox['args']['meta_name'] );
|
180 |
|
@@ -185,7 +196,7 @@ class Wordpress_Creation_Kit{
|
|
185 |
self::create_add_form($metabox['args']['meta_array'], $metabox['args']['meta_name'], $post);
|
186 |
|
187 |
//output the entries
|
188 |
-
echo self::wck_output_meta_content($metabox['args']['meta_name'], $
|
189 |
}
|
190 |
|
191 |
/**
|
@@ -217,8 +228,8 @@ class Wordpress_Creation_Kit{
|
|
217 |
}
|
218 |
|
219 |
|
220 |
-
$element .= '<label for="'. esc_attr( Wordpress_Creation_Kit::wck_generate_slug( $details['title'] ) ) .'" class="field-label">'. ucfirst($details['title']) .':';
|
221 |
-
if( $details['required'] )
|
222 |
$element .= '<span class="required">*</span>';
|
223 |
$element .= '</label>';
|
224 |
|
@@ -226,9 +237,17 @@ class Wordpress_Creation_Kit{
|
|
226 |
|
227 |
/*
|
228 |
include actual field type
|
229 |
-
possible field types: text, textarea, select, checkbox, radio, upload, wysiwyg editor, datepicker, country select, user select
|
230 |
*/
|
231 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
232 |
if( file_exists( dirname( __FILE__ ).'/fields/'.$details['type'].'.php' ) ){
|
233 |
require( dirname( __FILE__ ).'/fields/'.$details['type'].'.php' );
|
234 |
}
|
@@ -258,28 +277,35 @@ class Wordpress_Creation_Kit{
|
|
258 |
*/
|
259 |
function create_add_form($fields, $meta, $post){
|
260 |
$nonce = wp_create_nonce( 'wck-add-meta' );
|
|
|
|
|
|
|
|
|
|
|
261 |
?>
|
262 |
<div id="<?php echo $meta ?>" style="padding:10px 0;" <?php if( $this->args['single'] ) echo 'class="single"' ?>>
|
263 |
<ul class="mb-list-entry-fields">
|
264 |
<?php
|
265 |
$element_id = 0;
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
|
|
|
|
279 |
}
|
280 |
?>
|
281 |
<li style="overflow:visible;" class="add-entry-button">
|
282 |
-
<a href="javascript:void(0)" class="button-primary" onclick="addMeta('<?php echo esc_js($meta); ?>', '<?php echo esc_js($
|
283 |
</li>
|
284 |
</ul>
|
285 |
</div>
|
@@ -305,28 +331,37 @@ class Wordpress_Creation_Kit{
|
|
305 |
else if ( $this->args['context'] == 'option' )
|
306 |
$results = get_option( $meta );
|
307 |
|
|
|
|
|
|
|
|
|
308 |
$form = '';
|
309 |
-
$form .= '<tr id="update_container_'.$meta.'_'.$element_id.'"><td colspan="4">';
|
310 |
|
311 |
if($results != null){
|
312 |
$i = 0;
|
313 |
$form .= '<ul class="mb-list-entry-fields">';
|
314 |
|
315 |
-
|
316 |
-
$
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
|
|
|
|
|
|
|
|
|
|
330 |
}
|
331 |
$form .= '<li style="overflow:visible;">';
|
332 |
$form .= '<a href="javascript:void(0)" class="button-primary" onclick=\'updateMeta("'.esc_js($meta).'", "'.esc_js($id).'", "'.esc_js($element_id).'", "'.esc_js($update_nonce).'")\'><span>'. __( 'Save Changes', 'wck' ) .'</span></a>';
|
@@ -386,58 +421,131 @@ class Wordpress_Creation_Kit{
|
|
386 |
$edit_nonce = wp_create_nonce( 'wck-edit-entry' );
|
387 |
$delete_nonce = wp_create_nonce( 'wck-delete-entry' );
|
388 |
$entry_nr = $element_id +1;
|
|
|
|
|
|
|
389 |
|
390 |
$list = '';
|
391 |
-
$list .= '<tr id="element_'.$element_id.'">';
|
392 |
$list .= '<td style="text-align:center;vertical-align:middle;" class="wck-number">'. $entry_nr .'</td>';
|
393 |
$list .= '<td class="wck-content"><ul>';
|
394 |
|
395 |
$j = 0;
|
396 |
|
397 |
-
|
398 |
-
$
|
399 |
-
|
400 |
-
$value = $results[$element_id][Wordpress_Creation_Kit::wck_generate_slug( $details['title'] )];
|
401 |
-
|
402 |
-
/* filter display value */
|
403 |
-
$value = apply_filters( "wck_displayed_value_{$meta}_element_{$j}", $value );
|
404 |
-
|
405 |
-
/* for the upload field display it differently */
|
406 |
-
if( $details['type'] == 'upload' && !empty ( $value ) && is_numeric( $value ) ){
|
407 |
-
$file_src = wp_get_attachment_url($value);
|
408 |
-
$thumbnail = wp_get_attachment_image( $value, array( 80, 60 ), true );
|
409 |
-
$file_name = get_the_title( $value );
|
410 |
|
411 |
-
if (
|
412 |
-
$
|
413 |
else
|
414 |
-
$
|
|
|
|
|
|
|
415 |
|
416 |
-
|
417 |
-
|
418 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
419 |
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
431 |
}
|
432 |
-
|
|
|
|
|
433 |
$list .= '<td style="text-align:center;vertical-align:middle;" class="wck-edit"><a href="javascript:void(0)" class="button-secondary" onclick=\'showUpdateFormMeta("'.esc_js($meta).'", "'.esc_js($id).'", "'.esc_js($element_id).'", "'.esc_js($edit_nonce).'")\' title="'. __( 'Edit this item', 'wck' ) .'">'. __( 'Edit', 'wck' ) .'</a></td>';
|
434 |
$list .= '<td style="text-align:center;vertical-align:middle;" class="wck-delete"><a href="javascript:void(0)" class="mbdelete" onclick=\'removeMeta("'.esc_js($meta).'", "'.esc_js($id).'", "'.esc_js($element_id).'", "'.esc_js($delete_nonce).'")\' title="'. __( 'Delete this item', 'wck' ) .'">'. __( 'Delete', 'wck' ) .'</a></td>';
|
435 |
-
|
436 |
-
$list .= '</tr>';
|
437 |
|
438 |
return $list;
|
439 |
}
|
440 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
441 |
/* enque the js/css */
|
442 |
function wck_print_scripts($hook){
|
443 |
global $wck_pages_hooknames;
|
@@ -482,8 +590,8 @@ class Wordpress_Creation_Kit{
|
|
482 |
wp_enqueue_script( 'wck-tinymce-init' );
|
483 |
|
484 |
//datepicker
|
485 |
-
wp_enqueue_script('jquery-ui-datepicker');
|
486 |
-
wp_enqueue_style('jquery-style', '
|
487 |
|
488 |
}
|
489 |
|
@@ -496,17 +604,21 @@ class Wordpress_Creation_Kit{
|
|
496 |
|
497 |
$errors = '';
|
498 |
|
499 |
-
|
500 |
-
|
501 |
-
|
|
|
|
|
502 |
}
|
503 |
|
504 |
-
|
505 |
-
|
506 |
-
$
|
507 |
-
|
|
|
|
|
508 |
}
|
509 |
-
}
|
510 |
|
511 |
if( $required_message != '' ){
|
512 |
$errors = array( 'error' => $required_message, 'errorfields' => $required_fields_with_errors );
|
@@ -518,10 +630,19 @@ class Wordpress_Creation_Kit{
|
|
518 |
|
519 |
/* ajax add a reccord to the meta */
|
520 |
function wck_add_meta(){
|
521 |
-
check_ajax_referer( "wck-add-meta" );
|
522 |
-
|
523 |
-
|
524 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
525 |
|
526 |
$values = apply_filters( "wck_add_meta_filter_values_{$meta}", $values );
|
527 |
|
@@ -547,14 +668,14 @@ class Wordpress_Creation_Kit{
|
|
547 |
else if ( $this->args['context'] == 'option' )
|
548 |
update_option( $meta, $results );
|
549 |
|
550 |
-
/* if
|
551 |
-
if( $this->args['
|
552 |
|
553 |
$meta_suffix = count( $results );
|
554 |
-
$
|
555 |
-
|
556 |
-
|
557 |
-
|
558 |
}
|
559 |
}
|
560 |
|
@@ -564,10 +685,21 @@ class Wordpress_Creation_Kit{
|
|
564 |
/* ajax update a reccord in the meta */
|
565 |
function wck_update_meta(){
|
566 |
check_ajax_referer( "wck-update-entry" );
|
567 |
-
|
568 |
-
|
569 |
-
|
570 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
571 |
|
572 |
$values = apply_filters( "wck_update_meta_filter_values_{$meta}", $values, $element_id );
|
573 |
|
@@ -592,14 +724,14 @@ class Wordpress_Creation_Kit{
|
|
592 |
else if ( $this->args['context'] == 'option' )
|
593 |
update_option( $meta, $results );
|
594 |
|
595 |
-
/* if
|
596 |
-
if( $this->args['
|
597 |
|
598 |
-
$meta_suffix = $element_id + 1;
|
599 |
-
$
|
600 |
-
|
601 |
-
|
602 |
-
|
603 |
}
|
604 |
}
|
605 |
|
@@ -608,8 +740,14 @@ class Wordpress_Creation_Kit{
|
|
608 |
|
609 |
/* ajax to refresh the meta content */
|
610 |
function wck_refresh_list(){
|
611 |
-
|
612 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
613 |
echo self::wck_output_meta_content($meta, $id, $this->args['meta_array']);
|
614 |
|
615 |
do_action( "wck_refresh_list_{$meta}", $id );
|
@@ -619,9 +757,18 @@ class Wordpress_Creation_Kit{
|
|
619 |
|
620 |
/* ajax to refresh an entry content */
|
621 |
function wck_refresh_entry(){
|
622 |
-
|
623 |
-
|
624 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
625 |
|
626 |
if( $this->args['context'] == 'post_meta' )
|
627 |
$results = get_post_meta($id, $meta, true);
|
@@ -636,9 +783,15 @@ class Wordpress_Creation_Kit{
|
|
636 |
}
|
637 |
|
638 |
/* ajax to add the form for single */
|
639 |
-
function wck_add_form(){
|
640 |
-
|
641 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
642 |
$post = get_post($id);
|
643 |
self::create_add_form($this->args['meta_array'], $meta, $post );
|
644 |
do_action( "wck_ajax_add_form_{$meta}", $id );
|
@@ -649,10 +802,11 @@ class Wordpress_Creation_Kit{
|
|
649 |
|
650 |
/* ajax to show the update form */
|
651 |
function wck_show_update_form(){
|
652 |
-
check_ajax_referer( "wck-edit-entry" );
|
653 |
$meta = $_POST['meta'];
|
654 |
$id = absint($_POST['id']);
|
655 |
$element_id = $_POST['element_id'];
|
|
|
656 |
echo self::mb_update_form($this->args['meta_array'], $meta, $id, $element_id);
|
657 |
exit;
|
658 |
}
|
@@ -660,9 +814,18 @@ class Wordpress_Creation_Kit{
|
|
660 |
/* ajax to remove a reccord from the meta */
|
661 |
function wck_remove_meta(){
|
662 |
check_ajax_referer( "wck-delete-entry" );
|
663 |
-
|
664 |
-
|
665 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
666 |
|
667 |
if( $this->args['context'] == 'post_meta' )
|
668 |
$results = get_post_meta($id, $meta, true);
|
@@ -684,30 +847,30 @@ class Wordpress_Creation_Kit{
|
|
684 |
|
685 |
|
686 |
/* TODO: optimize so that it updates from the deleted element forward */
|
687 |
-
/* if
|
688 |
-
if( $this->args['
|
689 |
|
690 |
$meta_suffix = 1;
|
691 |
-
|
692 |
-
|
693 |
-
$
|
694 |
-
|
695 |
-
|
696 |
-
|
|
|
697 |
}
|
698 |
-
$meta_suffix++;
|
699 |
}
|
700 |
|
701 |
if( count( $results ) == 0 )
|
702 |
$results = $old_results;
|
703 |
|
704 |
-
|
705 |
-
$
|
706 |
-
|
707 |
-
|
708 |
-
|
|
|
709 |
}
|
710 |
-
break;
|
711 |
}
|
712 |
}
|
713 |
|
@@ -717,9 +880,20 @@ class Wordpress_Creation_Kit{
|
|
717 |
|
718 |
/* ajax to reorder records */
|
719 |
function wck_reorder_meta(){
|
720 |
-
|
721 |
-
|
722 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
723 |
|
724 |
if( $this->args['context'] == 'post_meta' )
|
725 |
$results = get_post_meta($id, $meta, true);
|
@@ -727,8 +901,10 @@ class Wordpress_Creation_Kit{
|
|
727 |
$results = get_option( $meta );
|
728 |
|
729 |
$new_results = array();
|
730 |
-
|
731 |
-
$
|
|
|
|
|
732 |
}
|
733 |
|
734 |
$results = $new_results;
|
@@ -739,18 +915,18 @@ class Wordpress_Creation_Kit{
|
|
739 |
update_option( $meta, $results );
|
740 |
|
741 |
|
742 |
-
/* if
|
743 |
-
if( $this->args['
|
744 |
|
745 |
$meta_suffix = 1;
|
746 |
-
|
747 |
-
$
|
748 |
-
|
749 |
-
|
750 |
-
|
|
|
751 |
}
|
752 |
-
|
753 |
-
}
|
754 |
|
755 |
}
|
756 |
|
@@ -760,56 +936,58 @@ class Wordpress_Creation_Kit{
|
|
760 |
/* modify Insert into post button */
|
761 |
function wck_media_upload_popup_head()
|
762 |
{
|
763 |
-
if(
|
764 |
-
if(
|
765 |
-
|
766 |
-
|
767 |
-
|
768 |
-
|
769 |
-
|
770 |
-
|
771 |
-
|
772 |
-
|
773 |
-
|
774 |
-
|
775 |
-
|
776 |
-
|
777 |
-
|
778 |
-
|
779 |
-
|
780 |
-
|
781 |
-
|
782 |
-
|
783 |
-
|
|
|
784 |
|
785 |
-
|
786 |
-
|
787 |
-
|
788 |
-
|
789 |
|
790 |
-
|
791 |
-
|
792 |
-
|
793 |
-
|
794 |
-
$(document).ready(function(){
|
795 |
|
796 |
-
$(
|
797 |
-
$('input[value="Insert into Post"]').each(function(){
|
798 |
-
$(this).attr('value','<?php _e("Select File")?>');
|
799 |
-
});
|
800 |
-
}).trigger('DOMNodeInserted');
|
801 |
|
802 |
-
|
803 |
-
|
804 |
-
|
805 |
-
|
|
|
806 |
|
807 |
-
|
808 |
-
});
|
809 |
|
810 |
-
|
811 |
-
|
812 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
813 |
}
|
814 |
}
|
815 |
}
|
@@ -862,17 +1040,19 @@ class Wordpress_Creation_Kit{
|
|
862 |
|
863 |
if( isset( $_GET['lang'] ) ){
|
864 |
|
865 |
-
$
|
866 |
$custom_field_keys = get_post_custom_keys( $post->ID );
|
867 |
-
|
868 |
-
$
|
869 |
-
|
870 |
-
$
|
871 |
-
|
|
|
|
|
872 |
}
|
873 |
}
|
874 |
|
875 |
-
if($
|
876 |
add_meta_box( 'wck_sync_translation', __( 'Syncronize WCK', 'wck' ), array( &$this, 'wck_add_sync_box' ), $post->post_type, 'side', 'low' );
|
877 |
}
|
878 |
|
@@ -895,7 +1075,10 @@ class Wordpress_Creation_Kit{
|
|
895 |
* Function that recreates the serialized metas from the individual meta fields.
|
896 |
*/
|
897 |
function wck_sync_translation_ajax(){
|
898 |
-
|
|
|
|
|
|
|
899 |
|
900 |
/* get all the custom fields keys for the post */
|
901 |
$custom_field_keys = (array)get_post_custom_keys( $post_id );
|
@@ -904,27 +1087,29 @@ class Wordpress_Creation_Kit{
|
|
904 |
$wck_array = array();
|
905 |
|
906 |
/* go through all the custom fields and if it is a custom field created automaticaly for the translation add it to the $wck_array array*/
|
907 |
-
|
908 |
-
|
909 |
-
$cf_name_array = explode( '_', $cf );
|
910 |
-
|
911 |
-
/* a custom field added for the translation will have this form
|
912 |
-
'wckwpml_{meta name}_{field name}_{entry position}_{field position}'
|
913 |
-
*/
|
914 |
-
if( count( $cf_name_array ) >= 5 ){
|
915 |
|
916 |
-
$
|
917 |
|
918 |
-
|
919 |
-
|
920 |
-
|
921 |
-
|
922 |
-
$wck_field_position = $cf_name_array[ count($cf_name_array) -1 ];
|
923 |
|
924 |
-
|
925 |
-
translation fields start at 1 */
|
926 |
-
$wck_array[$cf_name][$wck_position - 1][$wck_field_position][$wck_key] = get_post_meta($post_id,$cf,true);
|
927 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
928 |
}
|
929 |
}
|
930 |
}
|
@@ -954,9 +1139,11 @@ class Wordpress_Creation_Kit{
|
|
954 |
*/
|
955 |
function deep_ksort(&$arr) {
|
956 |
ksort($arr);
|
957 |
-
|
958 |
-
|
959 |
-
|
|
|
|
|
960 |
}
|
961 |
}
|
962 |
}
|
@@ -965,11 +1152,17 @@ class Wordpress_Creation_Kit{
|
|
965 |
* Function that removes the field position level
|
966 |
*/
|
967 |
function wck_reconstruct_array($wck_array){
|
968 |
-
|
969 |
-
foreach( $
|
970 |
-
|
971 |
-
$
|
972 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
973 |
}
|
974 |
}
|
975 |
}
|
@@ -1176,7 +1369,7 @@ class WCK_Page_Creator{
|
|
1176 |
?>
|
1177 |
<div class="wrap">
|
1178 |
|
1179 |
-
<?php if( $this->args['page_icon']
|
1180 |
<div id="<?php echo $this->args['menu_slug'] ?>-icon" style="background: url('<?php echo $this->args['page_icon']; ?>') no-repeat;" class="icon32">
|
1181 |
<br/>
|
1182 |
</div>
|
58 |
'page_template' => '',
|
59 |
'post_id' => '',
|
60 |
'single' => false,
|
61 |
+
'unserialize_fields' => false,
|
62 |
'sortable' => true,
|
63 |
'context' => 'post_meta'
|
64 |
);
|
121 |
/* add class to meta box */
|
122 |
add_filter( "postbox_classes_".$this->args['post_type']."_".$this->args['metabox_id'], array( &$this, 'wck_add_metabox_classes' ) );
|
123 |
}
|
124 |
+
else{
|
125 |
+
if( !empty( $_GET['post'] ) )
|
126 |
+
$post_id = $_GET['post'];
|
127 |
+
else if( !empty( $_POST['post_ID'] ) )
|
128 |
+
$post_id = $_POST['post_ID'];
|
129 |
+
else
|
130 |
+
$post_id = '';
|
131 |
+
|
132 |
+
|
133 |
if( $this->args['post_id'] != '' && $this->args['page_template'] != '' ){
|
134 |
$template_file = get_post_meta($post_id,'_wp_page_template',TRUE);
|
135 |
if( $this->args['post_id'] == $post_id && $template_file == $this->args['page_template'] )
|
175 |
return $classes;
|
176 |
}
|
177 |
|
178 |
+
function wck_content($post, $metabox){
|
179 |
+
if( !empty( $post->ID ) )
|
180 |
+
$post_id = $post->ID;
|
181 |
+
else
|
182 |
+
$post_id = '';
|
183 |
+
|
184 |
//output the add form
|
185 |
if( $this->args['single'] ){
|
186 |
|
187 |
if( $this->args['context'] == 'post_meta' )
|
188 |
+
$meta_val = get_post_meta( $post_id, $metabox['args']['meta_name'], true );
|
189 |
else if ( $this->args['context'] == 'option' )
|
190 |
$meta_val = get_option( $metabox['args']['meta_name'] );
|
191 |
|
196 |
self::create_add_form($metabox['args']['meta_array'], $metabox['args']['meta_name'], $post);
|
197 |
|
198 |
//output the entries
|
199 |
+
echo self::wck_output_meta_content($metabox['args']['meta_name'], $post_id, $metabox['args']['meta_array']);
|
200 |
}
|
201 |
|
202 |
/**
|
228 |
}
|
229 |
|
230 |
|
231 |
+
$element .= '<label for="'. esc_attr( Wordpress_Creation_Kit::wck_generate_slug( $details['title'] ) ) .'" class="field-label">'. apply_filters( "wck_label_{$meta}_". Wordpress_Creation_Kit::wck_generate_slug( $details['title'] ), ucfirst($details['title']) ) .':';
|
232 |
+
if( !empty( $details['required'] ) && $details['required'] )
|
233 |
$element .= '<span class="required">*</span>';
|
234 |
$element .= '</label>';
|
235 |
|
237 |
|
238 |
/*
|
239 |
include actual field type
|
240 |
+
possible field types: text, textarea, select, checkbox, radio, upload, wysiwyg editor, datepicker, country select, user select, cpt select
|
241 |
*/
|
242 |
+
|
243 |
+
if( function_exists( 'wck_nr_get_repeater_boxes' ) ){
|
244 |
+
$cfc_titles = wck_nr_get_repeater_boxes();
|
245 |
+
if( in_array( $details['type'], $cfc_titles ) ){
|
246 |
+
$details['type'] = 'nested repeater';
|
247 |
+
}
|
248 |
+
}
|
249 |
+
|
250 |
+
|
251 |
if( file_exists( dirname( __FILE__ ).'/fields/'.$details['type'].'.php' ) ){
|
252 |
require( dirname( __FILE__ ).'/fields/'.$details['type'].'.php' );
|
253 |
}
|
277 |
*/
|
278 |
function create_add_form($fields, $meta, $post){
|
279 |
$nonce = wp_create_nonce( 'wck-add-meta' );
|
280 |
+
if( !empty( $post->ID ) )
|
281 |
+
$post_id = $post->ID;
|
282 |
+
else
|
283 |
+
$post_id = '';
|
284 |
+
|
285 |
?>
|
286 |
<div id="<?php echo $meta ?>" style="padding:10px 0;" <?php if( $this->args['single'] ) echo 'class="single"' ?>>
|
287 |
<ul class="mb-list-entry-fields">
|
288 |
<?php
|
289 |
$element_id = 0;
|
290 |
+
if( !empty( $fields ) ){
|
291 |
+
foreach( $fields as $details ){
|
292 |
+
|
293 |
+
do_action( "wck_before_add_form_{$meta}_element_{$element_id}" );
|
294 |
+
|
295 |
+
?>
|
296 |
+
<li class="row-<?php echo esc_attr( Wordpress_Creation_Kit::wck_generate_slug( $details['title'] ) ) ?>">
|
297 |
+
<?php echo self::wck_output_form_field( $meta, $details ); ?>
|
298 |
+
</li>
|
299 |
+
<?php
|
300 |
+
|
301 |
+
do_action( "wck_after_add_form_{$meta}_element_{$element_id}" );
|
302 |
+
|
303 |
+
$element_id++;
|
304 |
+
}
|
305 |
}
|
306 |
?>
|
307 |
<li style="overflow:visible;" class="add-entry-button">
|
308 |
+
<a href="javascript:void(0)" class="button-primary" onclick="addMeta('<?php echo esc_js($meta); ?>', '<?php echo esc_js( $post_id ); ?>', '<?php echo esc_js($nonce); ?>')"><span><?php _e( 'Add Entry', 'wck' ); ?></span></a>
|
309 |
</li>
|
310 |
</ul>
|
311 |
</div>
|
331 |
else if ( $this->args['context'] == 'option' )
|
332 |
$results = get_option( $meta );
|
333 |
|
334 |
+
/* Filter primary used for CFC/OPC fields in order to show/hide fields based on type */
|
335 |
+
$wck_update_container_css_class = " class='update_container_$meta'";
|
336 |
+
$wck_update_container_css_class = apply_filters("wck_update_container_class_{$meta}", $wck_update_container_css_class, $meta, $results, $element_id );
|
337 |
+
|
338 |
$form = '';
|
339 |
+
$form .= '<tr id="update_container_'.$meta.'_'.$element_id.'" ' . $wck_update_container_css_class . '><td colspan="4">';
|
340 |
|
341 |
if($results != null){
|
342 |
$i = 0;
|
343 |
$form .= '<ul class="mb-list-entry-fields">';
|
344 |
|
345 |
+
if( !empty( $fields ) ){
|
346 |
+
foreach( $fields as $field ){
|
347 |
+
$details = $field;
|
348 |
+
if( !empty( $results[$element_id][Wordpress_Creation_Kit::wck_generate_slug( $details['title'] )] ) )
|
349 |
+
$value = $results[$element_id][Wordpress_Creation_Kit::wck_generate_slug( $details['title'] )];
|
350 |
+
else
|
351 |
+
$value = '';
|
352 |
+
|
353 |
+
$form = apply_filters( "wck_before_update_form_{$meta}_element_{$i}", $form, $element_id, $value );
|
354 |
+
|
355 |
+
$form .= '<li class="row-'. esc_attr( Wordpress_Creation_Kit::wck_generate_slug( $details['title'] ) ) .'">';
|
356 |
+
|
357 |
+
$form .= self::wck_output_form_field( $meta, $details, $value, 'edit_form' );
|
358 |
+
|
359 |
+
$form .= '</li>';
|
360 |
+
|
361 |
+
$form = apply_filters( "wck_after_update_form_{$meta}_element_{$i}", $form, $element_id, $value );
|
362 |
+
|
363 |
+
$i++;
|
364 |
+
}
|
365 |
}
|
366 |
$form .= '<li style="overflow:visible;">';
|
367 |
$form .= '<a href="javascript:void(0)" class="button-primary" onclick=\'updateMeta("'.esc_js($meta).'", "'.esc_js($id).'", "'.esc_js($element_id).'", "'.esc_js($update_nonce).'")\'><span>'. __( 'Save Changes', 'wck' ) .'</span></a>';
|
421 |
$edit_nonce = wp_create_nonce( 'wck-edit-entry' );
|
422 |
$delete_nonce = wp_create_nonce( 'wck-delete-entry' );
|
423 |
$entry_nr = $element_id +1;
|
424 |
+
|
425 |
+
$wck_element_class = '';
|
426 |
+
$wck_element_class = apply_filters( "wck_element_class_{$meta}", $wck_element_class, $meta, $results, $element_id );
|
427 |
|
428 |
$list = '';
|
429 |
+
$list .= '<tr id="element_'.$element_id.'" ' . $wck_element_class . '>';
|
430 |
$list .= '<td style="text-align:center;vertical-align:middle;" class="wck-number">'. $entry_nr .'</td>';
|
431 |
$list .= '<td class="wck-content"><ul>';
|
432 |
|
433 |
$j = 0;
|
434 |
|
435 |
+
if( !empty( $fields ) ){
|
436 |
+
foreach( $fields as $field ){
|
437 |
+
$details = $field;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
438 |
|
439 |
+
if( !empty( $results[$element_id][Wordpress_Creation_Kit::wck_generate_slug( $details['title'] )] ) )
|
440 |
+
$value = $results[$element_id][Wordpress_Creation_Kit::wck_generate_slug( $details['title'] )];
|
441 |
else
|
442 |
+
$value ='';
|
443 |
+
|
444 |
+
/* filter display value */
|
445 |
+
$value = apply_filters( "wck_displayed_value_{$meta}_element_{$j}", $value );
|
446 |
|
447 |
+
/* display it differently based on field type*/
|
448 |
+
if( $details['type'] == 'upload' ){
|
449 |
+
$display_value = self::wck_get_entry_field_avatar($value);
|
450 |
+
} elseif ( $details['type'] == 'user select' ) {
|
451 |
+
$display_value = self::wck_get_entry_field_user_select( $value ) . '</pre>';
|
452 |
+
} elseif ( $details['type'] == 'cpt select' ){
|
453 |
+
$display_value = self::wck_get_entry_field_cpt_select( $value ) . '</pre>';
|
454 |
+
} else {
|
455 |
+
$display_value = '<pre>'.htmlspecialchars( $value ) . '</pre>';
|
456 |
+
}
|
457 |
|
458 |
+
|
459 |
+
$list = apply_filters( "wck_before_listed_{$meta}_element_{$j}", $list, $element_id, $value );
|
460 |
+
/*check for nested repeater type and set it acordingly */
|
461 |
+
if( strpos( $details['type'], 'CFC-') === 0 )
|
462 |
+
$details['type'] = 'nested-repeater';
|
463 |
+
|
464 |
+
$list .= '<li class="row-'. esc_attr( Wordpress_Creation_Kit::wck_generate_slug( $details['title'] ) ) .'" data-type="'.$details['type'].'"><strong>'.$details['title'].': </strong>'.$display_value.' </li>';
|
465 |
+
|
466 |
+
$list = apply_filters( "wck_after_listed_{$meta}_element_{$j}", $list, $element_id, $value );
|
467 |
+
|
468 |
+
$j++;
|
469 |
+
|
470 |
+
/* In CFC/OPC we need the field title. Find it out and output it if found */
|
471 |
+
if ($meta == 'wck_cfc_fields') {
|
472 |
+
if( !empty( $results[$element_id][Wordpress_Creation_Kit::wck_generate_slug( $details['title'] )] ) ){
|
473 |
+
$field_title = $results[$element_id][Wordpress_Creation_Kit::wck_generate_slug( $details['title'] )];
|
474 |
+
if ($field_title == "Field Type")
|
475 |
+
$cfc_field_type = $value;
|
476 |
+
}
|
477 |
+
}
|
478 |
+
}
|
479 |
+
}
|
480 |
+
$list .= '</ul>';
|
481 |
+
|
482 |
+
/* check if we have nested repeaters */
|
483 |
+
if( function_exists( 'wck_nr_check_for_nested_repeaters' ) ){
|
484 |
+
if( wck_nr_check_for_nested_repeaters( $fields ) === true ){
|
485 |
+
$list .= wck_nr_handle_repeaters( $meta, $id, $fields, $results, $element_id );
|
486 |
+
}
|
487 |
}
|
488 |
+
|
489 |
+
$list .= '</div>';
|
490 |
+
$list .= '</td>';
|
491 |
$list .= '<td style="text-align:center;vertical-align:middle;" class="wck-edit"><a href="javascript:void(0)" class="button-secondary" onclick=\'showUpdateFormMeta("'.esc_js($meta).'", "'.esc_js($id).'", "'.esc_js($element_id).'", "'.esc_js($edit_nonce).'")\' title="'. __( 'Edit this item', 'wck' ) .'">'. __( 'Edit', 'wck' ) .'</a></td>';
|
492 |
$list .= '<td style="text-align:center;vertical-align:middle;" class="wck-delete"><a href="javascript:void(0)" class="mbdelete" onclick=\'removeMeta("'.esc_js($meta).'", "'.esc_js($id).'", "'.esc_js($element_id).'", "'.esc_js($delete_nonce).'")\' title="'. __( 'Delete this item', 'wck' ) .'">'. __( 'Delete', 'wck' ) .'</a></td>';
|
493 |
+
|
494 |
+
$list .= '</tr>';
|
495 |
|
496 |
return $list;
|
497 |
}
|
498 |
|
499 |
+
/* function to generate output for avatar */
|
500 |
+
function wck_get_entry_field_avatar($id){
|
501 |
+
if( !empty ( $id ) && is_numeric( $id ) ){
|
502 |
+
$file_src = wp_get_attachment_url($id);
|
503 |
+
$thumbnail = wp_get_attachment_image( $id, array( 80, 60 ), true );
|
504 |
+
$file_name = get_the_title( $id );
|
505 |
+
|
506 |
+
if ( preg_match( '/^.*?\.(\w+)$/', get_attached_file( $id ), $matches ) )
|
507 |
+
$file_type = esc_html( strtoupper( $matches[1] ) );
|
508 |
+
else
|
509 |
+
$file_type = strtoupper( str_replace( 'image/', '', get_post_mime_type( $id ) ) );
|
510 |
+
|
511 |
+
return $display_value = '<div class="upload-field-details">'. $thumbnail .'<p><span class="file-name">'. $file_name .'</span><span class="file-type">'. $file_type . '</span></p></div>';
|
512 |
+
} else {
|
513 |
+
return '';
|
514 |
+
}
|
515 |
+
}
|
516 |
+
|
517 |
+
/* function to generate output for user select */
|
518 |
+
function wck_get_entry_field_user_select($id){
|
519 |
+
if( !empty ( $id ) && is_numeric( $id ) ){
|
520 |
+
$user = get_user_by( 'id', $id );
|
521 |
+
if ( $user )
|
522 |
+
return '<pre>'.htmlspecialchars( $user->display_name );
|
523 |
+
else
|
524 |
+
return 'Error - User ID not found in database';
|
525 |
+
|
526 |
+
} else {
|
527 |
+
return '';
|
528 |
+
}
|
529 |
+
}
|
530 |
+
|
531 |
+
/* function to generate output for cpt select */
|
532 |
+
function wck_get_entry_field_cpt_select($id){
|
533 |
+
if( !empty ( $id ) && is_numeric( $id ) ){
|
534 |
+
$post = get_post( $id );
|
535 |
+
|
536 |
+
if ( $post->post_title == '' )
|
537 |
+
$post->post_title = 'No title. ID: ' . $id;
|
538 |
+
|
539 |
+
if ( $post )
|
540 |
+
return '<pre>'.htmlspecialchars( $post->post_title );
|
541 |
+
else
|
542 |
+
return 'Error - Post ID not found in database';
|
543 |
+
|
544 |
+
} else {
|
545 |
+
return '';
|
546 |
+
}
|
547 |
+
}
|
548 |
+
|
549 |
/* enque the js/css */
|
550 |
function wck_print_scripts($hook){
|
551 |
global $wck_pages_hooknames;
|
590 |
wp_enqueue_script( 'wck-tinymce-init' );
|
591 |
|
592 |
//datepicker
|
593 |
+
wp_enqueue_script('jquery-ui-datepicker');
|
594 |
+
wp_enqueue_style('jquery-style', plugins_url( '', dirname(__FILE__) ).'/assets/datepicker/datepicker.css');
|
595 |
|
596 |
}
|
597 |
|
604 |
|
605 |
$errors = '';
|
606 |
|
607 |
+
if( !empty( $fields ) ){
|
608 |
+
foreach( $fields as $field ){
|
609 |
+
if( !empty( $field['required'] ) && $field['required'] )
|
610 |
+
$required_fields[Wordpress_Creation_Kit::wck_generate_slug( $field['title'] )] = $field['title'];
|
611 |
+
}
|
612 |
}
|
613 |
|
614 |
+
if( !empty( $values ) ){
|
615 |
+
foreach( $values as $key => $value ){
|
616 |
+
if( array_key_exists( $key, $required_fields ) && apply_filters( "wck_required_test_{$meta}_{$key}", empty( $value ), $value, $id ) ){
|
617 |
+
$required_message .= apply_filters( "wck_required_message_{$meta}_{$key}", __( "Please enter a value for the required field ", "wck" ) . "$required_fields[$key] \n", $value );
|
618 |
+
$required_fields_with_errors[] = $key;
|
619 |
+
}
|
620 |
}
|
621 |
+
}
|
622 |
|
623 |
if( $required_message != '' ){
|
624 |
$errors = array( 'error' => $required_message, 'errorfields' => $required_fields_with_errors );
|
630 |
|
631 |
/* ajax add a reccord to the meta */
|
632 |
function wck_add_meta(){
|
633 |
+
check_ajax_referer( "wck-add-meta" );
|
634 |
+
if( !empty( $_POST['meta'] ) )
|
635 |
+
$meta = $_POST['meta'];
|
636 |
+
else
|
637 |
+
$meta = '';
|
638 |
+
if( !empty( $_POST['id'] ) )
|
639 |
+
$id = absint($_POST['id']);
|
640 |
+
else
|
641 |
+
$id = '';
|
642 |
+
if( !empty( $_POST['values'] ) )
|
643 |
+
$values = $_POST['values'];
|
644 |
+
else
|
645 |
+
$values = array();
|
646 |
|
647 |
$values = apply_filters( "wck_add_meta_filter_values_{$meta}", $values );
|
648 |
|
668 |
else if ( $this->args['context'] == 'option' )
|
669 |
update_option( $meta, $results );
|
670 |
|
671 |
+
/* if unserialize_fields is true add for each entry separete post meta for every element of the form */
|
672 |
+
if( $this->args['unserialize_fields'] && $this->args['context'] == 'post_meta' ){
|
673 |
|
674 |
$meta_suffix = count( $results );
|
675 |
+
if( !empty( $values ) ){
|
676 |
+
foreach( $values as $name => $value ){
|
677 |
+
update_post_meta($id, $meta.'_'.$name.'_'.$meta_suffix, $value);
|
678 |
+
}
|
679 |
}
|
680 |
}
|
681 |
|
685 |
/* ajax update a reccord in the meta */
|
686 |
function wck_update_meta(){
|
687 |
check_ajax_referer( "wck-update-entry" );
|
688 |
+
if( !empty( $_POST['meta'] ) )
|
689 |
+
$meta = $_POST['meta'];
|
690 |
+
else
|
691 |
+
$meta = '';
|
692 |
+
if( !empty( $_POST['id'] ) )
|
693 |
+
$id = absint($_POST['id']);
|
694 |
+
else
|
695 |
+
$id = '';
|
696 |
+
if( isset( $_POST['element_id'] ) )
|
697 |
+
$element_id = $_POST['element_id'];
|
698 |
+
else
|
699 |
+
$element_id = 0;
|
700 |
+
if( !empty( $_POST['values'] ) )
|
701 |
+
$values = $_POST['values'];
|
702 |
+
|
703 |
|
704 |
$values = apply_filters( "wck_update_meta_filter_values_{$meta}", $values, $element_id );
|
705 |
|
724 |
else if ( $this->args['context'] == 'option' )
|
725 |
update_option( $meta, $results );
|
726 |
|
727 |
+
/* if unserialize_fields is true update the coresponding post metas for every element of the form */
|
728 |
+
if( $this->args['unserialize_fields'] && $this->args['context'] == 'post_meta' ){
|
729 |
|
730 |
+
$meta_suffix = $element_id + 1;
|
731 |
+
if( !empty( $values ) ){
|
732 |
+
foreach( $values as $name => $value ){
|
733 |
+
update_post_meta($id, $meta.'_'.$name.'_'.$meta_suffix, $value);
|
734 |
+
}
|
735 |
}
|
736 |
}
|
737 |
|
740 |
|
741 |
/* ajax to refresh the meta content */
|
742 |
function wck_refresh_list(){
|
743 |
+
if( isset( $_POST['meta'] ) )
|
744 |
+
$meta = $_POST['meta'];
|
745 |
+
else
|
746 |
+
$meta = '';
|
747 |
+
if( isset( $_POST['id'] ) )
|
748 |
+
$id = absint($_POST['id']);
|
749 |
+
else
|
750 |
+
$id = '';
|
751 |
echo self::wck_output_meta_content($meta, $id, $this->args['meta_array']);
|
752 |
|
753 |
do_action( "wck_refresh_list_{$meta}", $id );
|
757 |
|
758 |
/* ajax to refresh an entry content */
|
759 |
function wck_refresh_entry(){
|
760 |
+
if( isset( $_POST['meta'] ) )
|
761 |
+
$meta = $_POST['meta'];
|
762 |
+
else
|
763 |
+
$meta = '';
|
764 |
+
if( isset( $_POST['id'] ) )
|
765 |
+
$id = absint( $_POST['id'] );
|
766 |
+
else
|
767 |
+
$id = '';
|
768 |
+
if( isset( $_POST['element_id'] ) )
|
769 |
+
$element_id = $_POST['element_id'];
|
770 |
+
else
|
771 |
+
$element_id = '';
|
772 |
|
773 |
if( $this->args['context'] == 'post_meta' )
|
774 |
$results = get_post_meta($id, $meta, true);
|
783 |
}
|
784 |
|
785 |
/* ajax to add the form for single */
|
786 |
+
function wck_add_form(){
|
787 |
+
if( !empty( $_POST['meta'] ) )
|
788 |
+
$meta = $_POST['meta'];
|
789 |
+
else
|
790 |
+
$meta = '';
|
791 |
+
if( !empty( $_POST['id'] ) )
|
792 |
+
$id = absint( $_POST['id'] );
|
793 |
+
else
|
794 |
+
$id = '';
|
795 |
$post = get_post($id);
|
796 |
self::create_add_form($this->args['meta_array'], $meta, $post );
|
797 |
do_action( "wck_ajax_add_form_{$meta}", $id );
|
802 |
|
803 |
/* ajax to show the update form */
|
804 |
function wck_show_update_form(){
|
805 |
+
check_ajax_referer( "wck-edit-entry" );
|
806 |
$meta = $_POST['meta'];
|
807 |
$id = absint($_POST['id']);
|
808 |
$element_id = $_POST['element_id'];
|
809 |
+
|
810 |
echo self::mb_update_form($this->args['meta_array'], $meta, $id, $element_id);
|
811 |
exit;
|
812 |
}
|
814 |
/* ajax to remove a reccord from the meta */
|
815 |
function wck_remove_meta(){
|
816 |
check_ajax_referer( "wck-delete-entry" );
|
817 |
+
if( !empty( $_POST['meta'] ) )
|
818 |
+
$meta = $_POST['meta'];
|
819 |
+
else
|
820 |
+
$meta = '';
|
821 |
+
if( !empty( $_POST['id'] ) )
|
822 |
+
$id = absint( $_POST['id'] );
|
823 |
+
else
|
824 |
+
$id = '';
|
825 |
+
if( isset( $_POST['element_id'] ) )
|
826 |
+
$element_id = absint( $_POST['element_id'] );
|
827 |
+
else
|
828 |
+
$element_id = '';
|
829 |
|
830 |
if( $this->args['context'] == 'post_meta' )
|
831 |
$results = get_post_meta($id, $meta, true);
|
847 |
|
848 |
|
849 |
/* TODO: optimize so that it updates from the deleted element forward */
|
850 |
+
/* if unserialize_fields is true delete the coresponding post metas */
|
851 |
+
if( $this->args['unserialize_fields'] && $this->args['context'] == 'post_meta' ){
|
852 |
|
853 |
$meta_suffix = 1;
|
854 |
+
|
855 |
+
if( !empty( $results ) ){
|
856 |
+
foreach( $results as $result ){
|
857 |
+
foreach ( $result as $name => $value){
|
858 |
+
update_post_meta($id, $meta.'_'.$name.'_'.$meta_suffix, $value);
|
859 |
+
}
|
860 |
+
$meta_suffix++;
|
861 |
}
|
|
|
862 |
}
|
863 |
|
864 |
if( count( $results ) == 0 )
|
865 |
$results = $old_results;
|
866 |
|
867 |
+
if( !empty( $results ) ){
|
868 |
+
foreach( $results as $result ){
|
869 |
+
foreach ( $result as $name => $value){
|
870 |
+
delete_post_meta( $id, $meta.'_'.$name.'_'.$meta_suffix );
|
871 |
+
}
|
872 |
+
break;
|
873 |
}
|
|
|
874 |
}
|
875 |
}
|
876 |
|
880 |
|
881 |
/* ajax to reorder records */
|
882 |
function wck_reorder_meta(){
|
883 |
+
if( !empty( $_POST['meta'] ) )
|
884 |
+
$meta = $_POST['meta'];
|
885 |
+
else
|
886 |
+
$meta = '';
|
887 |
+
if( !empty( $_POST['id'] ) )
|
888 |
+
$id = absint($_POST['id']);
|
889 |
+
else
|
890 |
+
$id = '';
|
891 |
+
if( !empty( $_POST['values'] ) )
|
892 |
+
$elements_id = $_POST['values'];
|
893 |
+
else
|
894 |
+
$elements_id = array();
|
895 |
+
|
896 |
+
do_action( 'wck_before_reorder_meta', $meta, $id, $elements_id );
|
897 |
|
898 |
if( $this->args['context'] == 'post_meta' )
|
899 |
$results = get_post_meta($id, $meta, true);
|
901 |
$results = get_option( $meta );
|
902 |
|
903 |
$new_results = array();
|
904 |
+
if( !empty( $elements_id ) ){
|
905 |
+
foreach($elements_id as $element_id){
|
906 |
+
$new_results[] = $results[$element_id];
|
907 |
+
}
|
908 |
}
|
909 |
|
910 |
$results = $new_results;
|
915 |
update_option( $meta, $results );
|
916 |
|
917 |
|
918 |
+
/* if unserialize_fields is true reorder all the coresponding post metas */
|
919 |
+
if( $this->args['unserialize_fields'] && $this->args['context'] == 'post_meta' ){
|
920 |
|
921 |
$meta_suffix = 1;
|
922 |
+
if( !empty( $new_results ) ){
|
923 |
+
foreach( $new_results as $result ){
|
924 |
+
foreach ( $result as $name => $value){
|
925 |
+
update_post_meta($id, $meta.'_'.$name.'_'.$meta_suffix, $value);
|
926 |
+
}
|
927 |
+
$meta_suffix++;
|
928 |
}
|
929 |
+
}
|
|
|
930 |
|
931 |
}
|
932 |
|
936 |
/* modify Insert into post button */
|
937 |
function wck_media_upload_popup_head()
|
938 |
{
|
939 |
+
if( isset( $_GET["meta_name"] ) ){
|
940 |
+
if( $this->args['meta_name'] == $_GET["meta_name"] ){
|
941 |
+
if( ( isset( $_GET["mb_type"] ) ) ){
|
942 |
+
?>
|
943 |
+
<style type="text/css">
|
944 |
+
#media-upload-header #sidemenu li#tab-type_url,
|
945 |
+
#media-upload-header #sidemenu li#tab-gallery {
|
946 |
+
display: none;
|
947 |
+
}
|
948 |
+
|
949 |
+
#media-items tr.url,
|
950 |
+
#media-items tr.align,
|
951 |
+
#media-items tr.image_alt,
|
952 |
+
#media-items tr.image-size,
|
953 |
+
#media-items tr.post_excerpt,
|
954 |
+
#media-items tr.post_content,
|
955 |
+
#media-items tr.image_alt p,
|
956 |
+
#media-items table thead input.button,
|
957 |
+
#media-items table thead img.imgedit-wait-spin,
|
958 |
+
#media-items tr.submit a.wp-post-thumbnail {
|
959 |
+
display: none;
|
960 |
+
}
|
961 |
|
962 |
+
.media-item table thead img {
|
963 |
+
border: #DFDFDF solid 1px;
|
964 |
+
margin-right: 10px;
|
965 |
+
}
|
966 |
|
967 |
+
</style>
|
968 |
+
<script type="text/javascript">
|
969 |
+
(function($){
|
|
|
|
|
970 |
|
971 |
+
$(document).ready(function(){
|
|
|
|
|
|
|
|
|
972 |
|
973 |
+
$('#media-items').bind('DOMNodeInserted',function(){
|
974 |
+
$('input[value="Insert into Post"]').each(function(){
|
975 |
+
$(this).attr('value','<?php _e("Select File")?>');
|
976 |
+
});
|
977 |
+
}).trigger('DOMNodeInserted');
|
978 |
|
979 |
+
$('form#filter').each(function(){
|
|
|
980 |
|
981 |
+
$(this).append('<input type="hidden" name="mb_type" value="<?php echo $_GET['mb_type']; ?>" />');
|
982 |
+
$(this).append('<input type="hidden" name="mb_info_div" value="<?php echo $_GET['mb_info_div']; ?>" />');
|
983 |
+
|
984 |
+
});
|
985 |
+
});
|
986 |
+
|
987 |
+
})(jQuery);
|
988 |
+
</script>
|
989 |
+
<?php
|
990 |
+
}
|
991 |
}
|
992 |
}
|
993 |
}
|
1040 |
|
1041 |
if( isset( $_GET['lang'] ) ){
|
1042 |
|
1043 |
+
$has_wck_with_unserialize_fields = false;
|
1044 |
$custom_field_keys = get_post_custom_keys( $post->ID );
|
1045 |
+
if( !empty( $custom_field_keys ) ){
|
1046 |
+
foreach( $custom_field_keys as $custom_field_key ){
|
1047 |
+
$custom_field_key = explode( '_', $custom_field_key );
|
1048 |
+
if( $custom_field_key[0] == 'wckwpml' ){
|
1049 |
+
$has_wck_with_unserialize_fields = true;
|
1050 |
+
break;
|
1051 |
+
}
|
1052 |
}
|
1053 |
}
|
1054 |
|
1055 |
+
if($has_wck_with_unserialize_fields){
|
1056 |
add_meta_box( 'wck_sync_translation', __( 'Syncronize WCK', 'wck' ), array( &$this, 'wck_add_sync_box' ), $post->post_type, 'side', 'low' );
|
1057 |
}
|
1058 |
|
1075 |
* Function that recreates the serialized metas from the individual meta fields.
|
1076 |
*/
|
1077 |
function wck_sync_translation_ajax(){
|
1078 |
+
if( !empty( $_POST['id'] ) )
|
1079 |
+
$post_id = $_POST['id'];
|
1080 |
+
else
|
1081 |
+
$post_id = '';
|
1082 |
|
1083 |
/* get all the custom fields keys for the post */
|
1084 |
$custom_field_keys = (array)get_post_custom_keys( $post_id );
|
1087 |
$wck_array = array();
|
1088 |
|
1089 |
/* go through all the custom fields and if it is a custom field created automaticaly for the translation add it to the $wck_array array*/
|
1090 |
+
if( !empty( $custom_field_keys ) ){
|
1091 |
+
foreach( $custom_field_keys as $cf ){
|
|
|
|
|
|
|
|
|
|
|
|
|
1092 |
|
1093 |
+
$cf_name_array = explode( '_', $cf );
|
1094 |
|
1095 |
+
/* a custom field added for the translation will have this form
|
1096 |
+
'wckwpml_{meta name}_{field name}_{entry position}_{field position}'
|
1097 |
+
*/
|
1098 |
+
if( count( $cf_name_array ) >= 5 ){
|
|
|
1099 |
|
1100 |
+
$cf_name = implode( '_', array_slice( $cf_name_array, 1, -3 ) );
|
|
|
|
|
1101 |
|
1102 |
+
if( $cf_name_array[0] == 'wckwpml' ){
|
1103 |
+
|
1104 |
+
$wck_key = $cf_name_array[ count($cf_name_array) -3 ];
|
1105 |
+
$wck_position = $cf_name_array[ count($cf_name_array) -2 ];
|
1106 |
+
$wck_field_position = $cf_name_array[ count($cf_name_array) -1 ];
|
1107 |
+
|
1108 |
+
/* "$wck_position - 1" is required because fields in wck by default start at 0 and the additional
|
1109 |
+
translation fields start at 1 */
|
1110 |
+
$wck_array[$cf_name][$wck_position - 1][$wck_field_position][$wck_key] = get_post_meta($post_id,$cf,true);
|
1111 |
+
|
1112 |
+
}
|
1113 |
}
|
1114 |
}
|
1115 |
}
|
1139 |
*/
|
1140 |
function deep_ksort(&$arr) {
|
1141 |
ksort($arr);
|
1142 |
+
if( !empty( $arr ) ){
|
1143 |
+
foreach ($arr as &$a) {
|
1144 |
+
if (is_array($a) && !empty($a)) {
|
1145 |
+
self::deep_ksort($a);
|
1146 |
+
}
|
1147 |
}
|
1148 |
}
|
1149 |
}
|
1152 |
* Function that removes the field position level
|
1153 |
*/
|
1154 |
function wck_reconstruct_array($wck_array){
|
1155 |
+
if( !empty( $wck_array ) ){
|
1156 |
+
foreach( $wck_array as $wck_array_key => $wck_meta ){
|
1157 |
+
if( !empty( $wck_meta ) ){
|
1158 |
+
foreach( $wck_meta as $wck_meta_key => $wck_entry ){
|
1159 |
+
if( !empty( $wck_entry ) ){
|
1160 |
+
foreach( $wck_entry as $wck_entry_key => $wck_field ){
|
1161 |
+
$wck_array[$wck_array_key][$wck_meta_key][key($wck_field)] = current($wck_field);
|
1162 |
+
unset($wck_array[$wck_array_key][$wck_meta_key][$wck_entry_key]);
|
1163 |
+
}
|
1164 |
+
}
|
1165 |
+
}
|
1166 |
}
|
1167 |
}
|
1168 |
}
|
1369 |
?>
|
1370 |
<div class="wrap">
|
1371 |
|
1372 |
+
<?php if( !empty( $this->args['page_icon'] ) ): ?>
|
1373 |
<div id="<?php echo $this->args['menu_slug'] ?>-icon" style="background: url('<?php echo $this->args['page_icon']; ?>') no-repeat;" class="icon32">
|
1374 |
<br/>
|
1375 |
</div>
|