← All changes
|
includes/admin/custom-fields/class-wpsc-cf-settings.php
+38
-0
3.4.9
→
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 |
| @@ -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 |