PluginProbe
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent / 3.4.9
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent v3.4.9
3.5.4 3.5.3 3.5.2 3.5.1 3.4.9 3.5.0 3.4.8 3.4.7 trunk 2.3.1 3.3.6 3.3.7 3.3.8 3.3.9 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.6
supportcandy / includes / models / class-wpsc-custom-field.php

class-wpsc-custom-field.php in SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent 3.4.9, at includes/models/class-wpsc-custom-field.php

788 lines 20.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit; // Exit if accessed directly!
4 }
5
6 if ( ! class_exists( 'WPSC_Custom_Field' ) ) :
7
8 final class WPSC_Custom_Field {
9
10 /**
11 * Object data in key => val pair.
12 *
13 * @var array
14 */
15 private $data = array();
16
17 /**
18 * Set whether or not current object properties modified
19 *
20 * @var boolean
21 */
22 private $is_modified = false;
23
24 /**
25 * Schema for this model
26 *
27 * @var array
28 */
29 public static $schema = array();
30
31 /**
32 * Prevent fields to modify
33 *
34 * @var array
35 */
36 public static $prevent_modify = array();
37
38 /**
39 * Custom field type
40 *
41 * @var array
42 */
43 public static $cf_types;
44
45 /**
46 * Default Custom field type
47 *
48 * @var array
49 */
50 public static $default_cf_types;
51
52 /**
53 * Custom fields with slug indexing.
54 *
55 * @var array
56 */
57 public static $custom_fields = array();
58
59 /**
60 * DB object caching
61 *
62 * @var array
63 */
64 private static $cache = array();
65
66 /**
67 * Initialize this class
68 *
69 * @return void
70 */
71 public static function init() {
72
73 // Apply schema for this model.
74 add_action( 'init', array( __CLASS__, 'apply_schema' ), 2 );
75
76 // Get object of this class.
77 add_filter( 'wpsc_load_ref_classes', array( __CLASS__, 'load_ref_class' ) );
78
79 // Set custom field types.
80 add_action( 'init', array( __CLASS__, 'set_all_cf_types' ) );
81 }
82
83 /**
84 * Apply schema for this model
85 *
86 * @return void
87 */
88 public static function apply_schema() {
89
90 $schema = array(
91 'id' => array(
92 'has_ref' => false,
93 'ref_class' => '',
94 'has_multiple_val' => false,
95 ),
96 'name' => array(
97 'has_ref' => false,
98 'ref_class' => '',
99 'has_multiple_val' => false,
100 ),
101 'extra_info' => array(
102 'has_ref' => false,
103 'ref_class' => '',
104 'has_multiple_val' => false,
105 ),
106 'slug' => array(
107 'has_ref' => false,
108 'ref_class' => '',
109 'has_multiple_val' => false,
110 ),
111 'field' => array( // Set whether this field is ticket field, customer field or agentonly field.
112 'has_ref' => false,
113 'ref_class' => '',
114 'has_multiple_val' => false,
115 ),
116 'type' => array( // Set custom field type.. e.g. TextFeld, Dropdown, or any default types.
117 'has_ref' => true,
118 'ref_class' => 'wpsc_cft',
119 'has_multiple_val' => false,
120 ),
121 'default_value' => array( // If set, this value will be used if not provided for ticket or customer field types.
122 'has_ref' => false,
123 'ref_class' => '',
124 'has_multiple_val' => true,
125 ),
126 'placeholder_text' => array( // Placeholder on create ticket or edit ticket, customer or agentonly fields where applicable.
127 'has_ref' => false,
128 'ref_class' => '',
129 'has_multiple_val' => false,
130 ),
131 'char_limit' => array( // Number of charaters to accept where applicable.
132 'has_ref' => false,
133 'ref_class' => '',
134 'has_multiple_val' => false,
135 ),
136 'date_display_as' => array( // Used in Date Created, Date Updated and Date Closed to define whether you want to display date string or date difference on ticket list.
137 'has_ref' => false,
138 'ref_class' => '',
139 'has_multiple_val' => false,
140 ),
141 'date_range' => array( // Used in "Date" custom field whether to accept past, future or any dates.
142 'has_ref' => false,
143 'ref_class' => '',
144 'has_multiple_val' => false,
145 ),
146 'date_format' => array( // Used in "Date" custom field to display date in given format.
147 'has_ref' => false,
148 'ref_class' => '',
149 'has_multiple_val' => false,
150 ),
151 'start_range' => array( // Used in "Date Datetime and Time" custom field for start date or start time.
152 'has_ref' => true,
153 'ref_class' => 'datetime',
154 'has_multiple_val' => false,
155 ),
156 'end_range' => array( // Used in "Date Datetime and Time" custom field for end date or end time.
157 'has_ref' => true,
158 'ref_class' => 'datetime',
159 'has_multiple_val' => false,
160 ),
161 'time_format' => array( // Used in "Time" custom field to display time in 12 or 24 hrs.
162 'has_ref' => false,
163 'ref_class' => '',
164 'has_multiple_val' => false,
165 ),
166 'is_personal_info' => array( // Used for GDPR compatibility.
167 'has_ref' => false,
168 'ref_class' => '',
169 'has_multiple_val' => false,
170 ),
171 'load_order' => array(
172 'has_ref' => false,
173 'ref_class' => '',
174 'has_multiple_val' => false,
175 ),
176 'is_auto_fill' => array( // Used for fill value automatically.
177 'has_ref' => false,
178 'ref_class' => '',
179 'has_multiple_val' => false,
180 ),
181 'allow_ticket_form' => array( // Used for customer field are add or not in create ticket form.
182 'has_ref' => false,
183 'ref_class' => '',
184 'has_multiple_val' => false,
185 ),
186 'allow_my_profile' => array( // Used for customer field are show/hide in my profile.
187 'has_ref' => false,
188 'ref_class' => '',
189 'has_multiple_val' => false,
190 ),
191 'tl_width' => array( // Used in ticket list for column width.
192 'has_ref' => false,
193 'ref_class' => '',
194 'has_multiple_val' => false,
195 ),
196 'number_type' => array( // Used to set whether current field is integer or float.
197 'has_ref' => false,
198 'ref_class' => '',
199 'has_multiple_val' => false,
200 ),
201 );
202 self::$schema = apply_filters( 'wpsc_cf_schema', $schema );
203
204 // Prevent modify.
205 $prevent_modify = array( 'id', 'slug' );
206 self::$prevent_modify = apply_filters( 'wpsc_cf_prevent_modify', $prevent_modify );
207
208 // Set custom fields.
209 $custom_fields = self::find( array( 'items_per_page' => 0 ) )['results'];
210 foreach ( $custom_fields as $cf ) {
211 if ( ! class_exists( $cf->type ) ) {
212 continue;
213 }
214 self::$custom_fields[ $cf->slug ] = $cf;
215 self::$cache[ $cf->id ] = $cf;
216 }
217 }
218
219 /**
220 * Model constructor
221 *
222 * @param int $id - Optional. Data record id to retrive object for.
223 */
224 public function __construct( $id = 0 ) {
225
226 global $wpdb;
227
228 $id = intval( $id );
229
230 if ( $id && isset( self::$cache[ $id ] ) ) {
231 $this->data = self::$cache[ $id ]->data;
232 }
233
234 if ( $id > 0 ) {
235 $cf = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}psmsc_custom_fields WHERE id = " . $id, ARRAY_A );
236 if ( ! is_array( $cf ) ) {
237 return;
238 }
239
240 foreach ( $cf as $key => $val ) {
241
242 if ( $key == 'name' ) {
243
244 $this->data[ $key ] = $val !== null ? WPSC_Translations::get( 'wpsc-cf-name-' . $cf['id'], stripslashes( $val ) ) : '';
245
246 } elseif ( $key == 'extra_info' ) {
247
248 $this->data[ $key ] = $val !== null ? WPSC_Translations::get( 'wpsc-cf-exi-' . $cf['id'], stripslashes( $val ) ) : '';
249
250 } elseif ( $key == 'placeholder_text' ) {
251 $this->data[ $key ] = $val !== null ? WPSC_Translations::get( 'wpsc-cf-pl-txt-' . $cf['id'], stripslashes( $val ) ) : '';
252
253 } else {
254
255 $this->data[ $key ] = $val !== null ? $val : '';
256 }
257 }
258 }
259 }
260
261 /**
262 * Convert object into an array
263 *
264 * @return array
265 */
266 public function to_array() {
267
268 return $this->data;
269 }
270
271 /**
272 * Magic get function to use with object arrow function
273 *
274 * @param string $var_name - variable name.
275 * @return mixed
276 */
277 public function __get( $var_name ) {
278
279 if ( ! isset( $this->data[ $var_name ] ) ||
280 $this->data[ $var_name ] == null ||
281 $this->data[ $var_name ] == ''
282 ) {
283 return self::$schema[ $var_name ]['has_multiple_val'] ? array() : '';
284 }
285
286 if ( self::$schema[ $var_name ]['has_multiple_val'] ) {
287
288 $response = array();
289 $values = $this->data[ $var_name ] ? explode( '|', $this->data[ $var_name ] ) : array();
290 foreach ( $values as $val ) {
291 $response[] = self::$schema[ $var_name ]['has_ref'] ?
292 WPSC_Functions::get_object( self::$schema[ $var_name ]['ref_class'], $val ) :
293 $val;
294 }
295 return $response;
296
297 } else {
298
299 return self::$schema[ $var_name ]['has_ref'] && $this->data[ $var_name ] ?
300 WPSC_Functions::get_object( self::$schema[ $var_name ]['ref_class'], $this->data[ $var_name ] ) :
301 $this->data[ $var_name ];
302 }
303 }
304
305 /**
306 * Magic function to use setting object field with arrow function
307 *
308 * @param string $var_name - (Required) property slug.
309 * @param mixed $value - (Required) value to set for a property.
310 * @return void
311 */
312 public function __set( $var_name, $value ) {
313
314 if ( in_array( $var_name, self::$prevent_modify ) ) {
315 return;
316 }
317
318 $data_val = '';
319 if ( self::$schema[ $var_name ]['has_multiple_val'] ) {
320
321 $data_vals = array_map(
322 fn( $val ) => is_object( $val ) ? WPSC_Functions::set_object( self::$schema[ $var_name ]['ref_class'], $val ) : $val,
323 $value
324 );
325
326 $data_val = $data_vals ? implode( '|', $data_vals ) : '';
327
328 } else {
329
330 $data_val = is_object( $value ) ? WPSC_Functions::set_object( self::$schema[ $var_name ]['ref_class'], $value ) : $value;
331 }
332
333 if ( isset( $this->data[ $var_name ] ) && $this->data[ $var_name ] == $data_val ) {
334 return;
335 }
336
337 $this->data[ $var_name ] = $data_val;
338 $this->is_modified = true;
339 }
340
341 /**
342 * Save changes made
343 *
344 * @return boolean
345 */
346 public function save() {
347
348 global $wpdb;
349
350 if ( ! $this->is_modified ) {
351 return true;
352 }
353
354 $data = $this->data;
355 $success = true;
356
357 if ( ! isset( $data['id'] ) ) {
358
359 $cf = self::insert( $data );
360 if ( $cf ) {
361 $this->data = $cf->data;
362 $success = true;
363 } else {
364 $success = false;
365 }
366 } else {
367
368 unset( $data['id'] );
369 $success = $wpdb->update(
370 $wpdb->prefix . 'psmsc_custom_fields',
371 $data,
372 array( 'id' => $this->id )
373 );
374
375 WPSC_Translations::add( 'wpsc-cf-name-' . $this->id, $data['name'] );
376 $data['extra_info'] ? WPSC_Translations::add( 'wpsc-cf-exi-' . $this->id, $data['extra_info'] ) : WPSC_Translations::remove( 'wpsc-cf-exi-' . $this->id );
377 $data['placeholder_text'] ? WPSC_Translations::add( 'wpsc-cf-pl-txt-' . $this->id, $data['placeholder_text'] ) : WPSC_Translations::remove( 'wpsc-cf-pl-txt-' . $this->id );
378
379 if ( $success ) {
380 self::$custom_fields[ $this->slug ] = $this;
381 self::$cache[ $this->id ] = $this;
382 }
383 }
384 $this->is_modified = false;
385 return $success ? true : false;
386 }
387
388 /**
389 * Insert new record
390 *
391 * @param array $data - insert data.
392 * @return WPSC_Custom_Field
393 */
394 public static function insert( $data ) {
395
396 global $wpdb;
397
398 if ( ! isset( $data['load_order'] ) ) {
399 $max_order = $wpdb->get_var( "SELECT MAX(load_order) FROM {$wpdb->prefix}psmsc_custom_fields" );
400 $data['load_order'] = intval( $max_order ) + 1;
401 }
402
403 $success = $wpdb->insert(
404 $wpdb->prefix . 'psmsc_custom_fields',
405 $data
406 );
407
408 if ( ! $success ) {
409 return false;
410 }
411
412 $id = $wpdb->insert_id;
413
414 // string translation.
415 WPSC_Translations::add( 'wpsc-cf-name-' . $id, $data['name'] );
416 if ( isset( $data['extra_info'] ) ) {
417 WPSC_Translations::add( 'wpsc-cf-exi-' . $id, $data['extra_info'] );
418 }
419 if ( isset( $data['placeholder_text'] ) ) {
420 WPSC_Translations::add( 'wpsc-cf-pl-txt-' . $id, $data['placeholder_text'] );
421 }
422
423 $cf = new WPSC_Custom_Field( $id );
424
425 // Save slug if not already set. Reasone we have to do it here because slug is in $prevent_modify.
426 if ( ! $cf->slug ) {
427 $slug = 'cust_' . $cf->id;
428 $wpdb->update(
429 $wpdb->prefix . 'psmsc_custom_fields',
430 array( 'slug' => $slug ),
431 array( 'id' => $cf->id )
432 );
433 $cf->data['slug'] = $slug;
434 }
435
436 // Check if user has privileges to change innodb_strict_mode.
437 $has_privileges = $wpdb->get_var( 'SELECT @@innodb_strict_mode' ) !== null;
438 if ( $has_privileges ) {
439 // Disable InnoDB strict mode if enabled to avoid limit of number of columns in tables.
440 $strict_mode = $wpdb->get_var( "SHOW VARIABLES LIKE 'innodb_strict_mode'", 1 );
441 if ( $strict_mode == 'ON' ) {
442 $wpdb->query( "SET innodb_strict_mode = 'OFF'" );
443 }
444 }
445
446 // Add column to tickets table if field is either ticket or agentonly.
447 if ( in_array( $cf->field, array( 'ticket', 'agentonly' ) ) && $cf->type::$slug != 'cf_html' ) {
448 $success = $cf->create_ticket_tbl_col();
449 }
450
451 // Add column to customer table if field is customer.
452 if ( $cf->field === 'customer' ) {
453 $success = $cf->create_customer_tbl_col();
454 }
455
456 $success = apply_filters( 'wpsc_add_cf_table_column', $success, $cf );
457
458 self::$custom_fields[ $cf->slug ] = $cf;
459 self::$cache[ $cf->id ] = $cf;
460
461 if ( ! $success ) {
462 return false;
463 }
464 return $cf;
465 }
466
467 /**
468 * Delete record of given ID
469 *
470 * @param int $id - category id.
471 * @return boolean
472 */
473 public static function destroy( $id ) {
474
475 global $wpdb;
476
477 $cf = new WPSC_Custom_Field( $id );
478 if ( $cf->type::$is_default ) {
479 return false;
480 }
481
482 if ( in_array( $cf->field, array( 'ticket', 'agentonly' ) ) && $cf->type::$slug != 'cf_html' ) {
483 $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_tickets DROP {$cf->slug}" );
484 $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_archived_tickets DROP {$cf->slug}" );
485 }
486
487 if ( $cf->field === 'customer' ) {
488 $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_customers DROP {$cf->slug}" );
489 }
490
491 do_action( 'wpsc_custom_field_before_destroy', $cf );
492
493 // Remove from DB.
494 $success = $wpdb->delete(
495 $wpdb->prefix . 'psmsc_custom_fields',
496 array( 'id' => $cf->id )
497 );
498 if ( ! $success ) {
499 return false;
500 }
501
502 // Remove options if any.
503 if ( $cf->type::$has_options ) {
504 $cf->delete_options();
505 }
506
507 unset( self::$custom_fields[ $cf->slug ] );
508 unset( self::$cache[ $cf->id ] );
509
510 // remove string translations.
511 WPSC_Translations::remove( 'wpsc-cf-name-' . $cf->id );
512 WPSC_Translations::remove( 'wpsc-cf-exi-' . $cf->id );
513 WPSC_Translations::remove( 'wpsc-cf-pl-txt-' . $cf->id );
514
515 return true;
516 }
517
518 /**
519 * Set data to create new object using direct data. Used in find method
520 *
521 * @param array $data - data to set for object.
522 * @return void
523 */
524 private function set_data( $data ) {
525
526 foreach ( $data as $var_name => $val ) {
527
528 if ( $var_name == 'name' ) {
529
530 $this->data[ $var_name ] = $val !== null ? WPSC_Translations::get( 'wpsc-cf-name-' . $data['id'], stripslashes( $val ) ) : '';
531
532 } elseif ( $var_name == 'extra_info' ) {
533
534 $this->data[ $var_name ] = $val !== null ? WPSC_Translations::get( 'wpsc-cf-exi-' . $data['id'], stripslashes( $val ) ) : '';
535
536 } elseif ( $var_name == 'placeholder_text' ) {
537
538 $this->data[ $var_name ] = $val !== null ? WPSC_Translations::get( 'wpsc-cf-pl-txt-' . $data['id'], stripslashes( $val ) ) : '';
539
540 } else {
541
542 $this->data[ $var_name ] = $val !== null ? $val : '';
543 }
544 }
545 }
546
547 /**
548 * Find records based on given filters
549 *
550 * @param array $filter - array containing array items like search, where, orderby, order, page_no, items_per_page, etc.
551 * @param boolean $is_object - return data as array or object. Default object.
552 * @return mixed
553 */
554 public static function find( $filter = array(), $is_object = true ) {
555
556 global $wpdb;
557
558 $sql = 'SELECT * FROM ' . $wpdb->prefix . 'psmsc_custom_fields ';
559 $where = self::get_where( $filter );
560
561 $filter['items_per_page'] = isset( $filter['items_per_page'] ) ? $filter['items_per_page'] : 0;
562 $filter['page_no'] = isset( $filter['page_no'] ) ? $filter['page_no'] : 1;
563 $filter['orderby'] = isset( $filter['orderby'] ) ? $filter['orderby'] : 'load_order';
564 $filter['order'] = isset( $filter['order'] ) ? $filter['order'] : 'ASC';
565
566 $order = WPSC_Functions::parse_order( $filter );
567 $limit = WPSC_Functions::parse_limit( $filter );
568 $sql = $sql . $where . $order . $limit;
569 $results = $wpdb->get_results( $sql, ARRAY_A );
570
571 // total results.
572 $sql = 'SELECT count(id) FROM ' . $wpdb->prefix . 'psmsc_custom_fields ';
573 $total_items = $wpdb->get_var( $sql . $where );
574
575 $response = WPSC_Functions::parse_response( $results, $total_items, $filter );
576
577 // Return array.
578 if ( ! $is_object ) {
579 return $response;
580 }
581
582 // create and return array of objects.
583 $temp_results = array();
584 foreach ( $response['results'] as $cf ) {
585
586 $ob = new WPSC_Custom_Field();
587 $data = array();
588 foreach ( $cf as $key => $val ) {
589 $data[ $key ] = $val;
590 }
591 $ob->set_data( $data );
592 $temp_results[] = $ob;
593 }
594 $response['results'] = $temp_results;
595
596 return $response;
597 }
598
599 /**
600 * Get where for find method
601 *
602 * @param array $filter - user filter.
603 * @return array
604 */
605 private static function get_where( $filter ) {
606
607 $where = '';
608
609 // Set user defined filters.
610 $meta_query = isset( $filter['meta_query'] ) && $filter['meta_query'] ? $filter['meta_query'] : array();
611 $meta_query = apply_filters( 'wpsc_cf_meta_query', $meta_query, $filter );
612 if ( $meta_query ) {
613
614 $meta_query = WPSC_Functions::parse_user_filters( __CLASS__, $meta_query );
615 $where = $meta_query . ' ';
616 }
617
618 return $where ? 'WHERE ' . $where : '';
619 }
620
621 /**
622 * Load current class to reference classes
623 *
624 * @param array $classes - Associative array of class names indexed by its slug.
625 * @return array
626 */
627 public static function load_ref_class( $classes ) {
628
629 $classes['wpsc_cf'] = array(
630 'class' => __CLASS__,
631 'save-key' => 'id',
632 );
633 return $classes;
634 }
635
636 /**
637 * Create column for custom field in ticket table
638 *
639 * @return boolean
640 */
641 public function create_ticket_tbl_col() {
642
643 global $wpdb;
644 $result_archived = $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_archived_tickets ADD {$this->slug} {$this->type::$data_type}" );
645 $result_tickets = $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_tickets ADD {$this->slug} {$this->type::$data_type}" );
646
647 // Both queries must succeed.
648 if ( $result_archived === false || $result_tickets === false ) {
649 // Optionally, you could log or handle the error here.
650 return false;
651 }
652 return true;
653 }
654
655 /**
656 * Create column for custom field in customer table
657 *
658 * @return boolean
659 */
660 public function create_customer_tbl_col() {
661
662 global $wpdb;
663 return $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_customers ADD {$this->slug} {$this->type::$data_type}" );
664 }
665
666 /**
667 * Set all custom field types
668 */
669 public static function set_all_cf_types() {
670
671 self::set_default_cf_types();
672 self::set_cf_types();
673 }
674
675 /**
676 * Set default custom field types
677 */
678 public static function set_default_cf_types() {
679
680 self::$default_cf_types = apply_filters( 'wpsc_default_cf_types', array() );
681 }
682
683 /**
684 * Set custom field types
685 */
686 public static function set_cf_types() {
687
688 self::$cf_types = apply_filters( 'wpsc_cf_types', array() );
689 }
690
691 /**
692 * Reset options for the field
693 *
694 * @param array $options - option ids.
695 * @param boolean $is_edit - set whether it is called from edit custom field.
696 * @return void
697 */
698 public function set_options( $options, $is_edit = false ) {
699
700 global $wpdb;
701
702 if ( $is_edit ) {
703 $wpdb->update(
704 $wpdb->prefix . 'psmsc_options',
705 array( 'custom_field' => 0 ),
706 array( 'custom_field' => $this->id )
707 );
708 }
709
710 if ( $this->type::$has_options ) {
711 $count = 1;
712 foreach ( $options as $option_id ) {
713 $option = new WPSC_Option( $option_id );
714 if ( ! $option->id ) {
715 continue;
716 }
717 $option->custom_field = $this->id;
718 $option->load_order = $count++;
719 $option->save();
720 }
721 }
722 }
723
724 /**
725 * Get options for this field
726 */
727 public function get_options() {
728
729 $filter = array(
730 'meta_query' => array(
731 'relation' => 'AND',
732 array(
733 'slug' => 'custom_field',
734 'compare' => '=',
735 'val' => $this->id,
736 ),
737 ),
738 );
739 return WPSC_Option::find( $filter )['results'];
740 }
741
742 /**
743 * Delete all options for this custom field
744 */
745 public function delete_options() {
746
747 global $wpdb;
748 $wpdb->delete(
749 $wpdb->prefix . 'psmsc_options',
750 array( 'custom_field' => $this->id )
751 );
752 }
753
754 /**
755 * Return CF object by slug
756 *
757 * @param string $slug - custom field slug.
758 * @return WPSC_Custom_Field
759 */
760 public static function get_cf_by_slug( $slug ) {
761
762 $cf = isset( self::$custom_fields[ $slug ] ) ? self::$custom_fields[ $slug ] : false;
763 return $cf;
764 }
765
766 /**
767 * Set load order for ids given
768 *
769 * @param array $ids - custom field ids.
770 * @return void
771 */
772 public static function set_load_order( $ids ) {
773
774 $count = 1;
775 foreach ( $ids as $id ) {
776 $cf = new WPSC_Custom_Field( $id );
777 if ( ! $cf ) {
778 wp_send_json_error( __( 'Bad request!', 'supportcandy' ), 400 );
779 }
780 $cf->load_order = $count++;
781 $cf->save();
782 }
783 }
784 }
785 endif;
786
787 WPSC_Custom_Field::init();
788