← All changes
|
includes/admin/custom-fields/class-wpsc-cf-settings.php
+44
-6
3.4.1
→
3.5.4
View file →
| @@ -78,8 +78,11 @@ | ||
| 78 | 78 | add_action( 'wp_ajax_wpsc_set_edit_custom_field', array( __CLASS__, 'set_edit_custom_field' ) ); |
| 79 | 79 | |
| 80 | 80 | // Delete. |
| 81 | 81 | add_action( 'wp_ajax_wpsc_delete_custom_field', array( __CLASS__, 'delete_custom_field' ) ); |
| 82 | + | |
| 83 | + // Sorting. | |
| 84 | + add_action( 'wp_ajax_wpsc_set_custom_field_load_order', array( __CLASS__, 'set_custom_field_load_order' ) ); | |
| 82 | 85 | } |
| 83 | 86 | |
| 84 | 87 | /** |
| 85 | 88 | * Load section (nav elements) for this screen |
| @@ -301,9 +304,9 @@ | ||
| 301 | 304 | */ |
| 302 | 305 | public static function get_add_new_custom_field() { |
| 303 | 306 | |
| 304 | 307 | if ( check_ajax_referer( 'wpsc_get_add_new_custom_field', '_ajax_nonce', false ) !== 1 ) { |
| 305 | - wp_send_json_error( 'Unauthorised request!', 401 ); | |
| 308 | + wp_send_json_error( 'Unauthorized request!', 401 ); | |
| 306 | 309 | } |
| 307 | 310 | |
| 308 | 311 | if ( ! WPSC_Functions::is_site_admin() ) { |
| 309 | 312 | wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 ); |
| @@ -424,9 +427,9 @@ | ||
| 424 | 427 | */ |
| 425 | 428 | public static function get_add_new_custom_field_properties() { |
| 426 | 429 | |
| 427 | 430 | if ( check_ajax_referer( 'wpsc_get_add_new_custom_field_properties', '_ajax_nonce', false ) != 1 ) { |
| 428 | - wp_send_json_error( 'Unauthorised request!', 401 ); | |
| 431 | + wp_send_json_error( 'Unauthorized request!', 401 ); | |
| 429 | 432 | } |
| 430 | 433 | |
| 431 | 434 | if ( ! WPSC_Functions::is_site_admin() ) { |
| 432 | 435 | wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 ); |
| @@ -460,9 +463,9 @@ | ||
| 460 | 463 | */ |
| 461 | 464 | public static function set_add_new_custom_field() { |
| 462 | 465 | |
| 463 | 466 | if ( check_ajax_referer( 'wpsc_set_add_new_custom_field', '_ajax_nonce', false ) != 1 ) { |
| 464 | - wp_send_json_error( 'Unauthorised request!', 401 ); | |
| 467 | + wp_send_json_error( 'Unauthorized request!', 401 ); | |
| 465 | 468 | } |
| 466 | 469 | |
| 467 | 470 | if ( ! WPSC_Functions::is_site_admin() ) { |
| 468 | 471 | wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 ); |
| @@ -527,9 +530,9 @@ | ||
| 527 | 530 | |
| 528 | 531 | global $wpdb; |
| 529 | 532 | |
| 530 | 533 | if ( check_ajax_referer( 'wpsc_get_edit_custom_field', '_ajax_nonce', false ) != 1 ) { |
| 531 | - wp_send_json_error( 'Unauthorised request!', 401 ); | |
| 534 | + wp_send_json_error( 'Unauthorized request!', 401 ); | |
| 532 | 535 | } |
| 533 | 536 | |
| 534 | 537 | if ( ! WPSC_Functions::is_site_admin() ) { |
| 535 | 538 | wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 ); |
| @@ -632,9 +635,9 @@ | ||
| 632 | 635 | |
| 633 | 636 | global $wpdb; |
| 634 | 637 | |
| 635 | 638 | if ( check_ajax_referer( 'wpsc_set_edit_custom_field', '_ajax_nonce', false ) != 1 ) { |
| 636 | - wp_send_json_error( 'Unauthorised request!', 401 ); | |
| 639 | + wp_send_json_error( 'Unauthorized request!', 401 ); | |
| 637 | 640 | } |
| 638 | 641 | |
| 639 | 642 | if ( ! WPSC_Functions::is_site_admin() ) { |
| 640 | 643 | wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 ); |
| @@ -697,9 +700,9 @@ | ||
| 697 | 700 | */ |
| 698 | 701 | public static function delete_custom_field() { |
| 699 | 702 | |
| 700 | 703 | if ( check_ajax_referer( 'wpsc_delete_custom_field', '_ajax_nonce', false ) != 1 ) { |
| 701 | - wp_send_json_error( 'Unauthorised request!', 401 ); | |
| 704 | + wp_send_json_error( 'Unauthorized request!', 401 ); | |
| 702 | 705 | } |
| 703 | 706 | |
| 704 | 707 | if ( ! WPSC_Functions::is_site_admin() ) { |
| 705 | 708 | wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 ); |
| @@ -718,8 +721,43 @@ | ||
| 718 | 721 | do_action( 'wpsc_delete_custom_field', $cf ); |
| 719 | 722 | |
| 720 | 723 | WPSC_Custom_Field::destroy( $id ); |
| 721 | 724 | wp_die(); |
| 725 | + } | |
| 726 | + | |
| 727 | + /** | |
| 728 | + * Set load order for custom fields | |
| 729 | + * | |
| 730 | + * @return void | |
| 731 | + */ | |
| 732 | + public static function set_custom_field_load_order() { | |
| 733 | + | |
| 734 | + if ( check_ajax_referer( 'wpsc_set_custom_field_load_order', '_ajax_nonce', false ) != 1 ) { | |
| 735 | + wp_send_json_error( 'Unauthorized request!', 400 ); | |
| 736 | + } | |
| 737 | + | |
| 738 | + if ( ! WPSC_Functions::is_site_admin() ) { | |
| 739 | + wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 ); | |
| 740 | + } | |
| 741 | + | |
| 742 | + $ids = isset( $_POST['ids'] ) ? array_map( 'intval', wp_unslash( $_POST['ids'] ) ) : array(); | |
| 743 | + if ( ! $ids ) { | |
| 744 | + wp_send_json_error( 'Bad Request', 400 ); | |
| 745 | + } | |
| 746 | + | |
| 747 | + $count = 1; | |
| 748 | + foreach ( $ids as $id ) { | |
| 749 | + | |
| 750 | + $cf = new WPSC_Custom_Field( $id ); | |
| 751 | + if ( ! $cf->id ) { | |
| 752 | + continue; | |
| 753 | + } | |
| 754 | + | |
| 755 | + $cf->load_order = $count++; | |
| 756 | + $cf->save(); | |
| 757 | + } | |
| 758 | + | |
| 759 | + wp_send_json( array( 'success' => true ), 200 ); | |
| 722 | 760 | } |
| 723 | 761 | |
| 724 | 762 | /** |
| 725 | 763 | * Static snippets for this page |