Passed
Push — master ( 039fc1...a932b5 )
by Brian
05:54
created
includes/admin/views/html-gateways-edit.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -44,9 +44,9 @@  discard block
 block discarded – undo
44 44
                         <?php
45 45
 
46 46
                             if ( wpinv_is_gateway_active( $id ) ) {
47
-							echo "<i class='text-success fa fa-check'></i>";
47
+                            echo "<i class='text-success fa fa-check'></i>";
48 48
                             } else {
49
-							echo "<i class='text-dark fa fa-times'></i>";
49
+                            echo "<i class='text-dark fa fa-times'></i>";
50 50
                             }
51 51
 
52 52
                         ?>
@@ -58,9 +58,9 @@  discard block
 block discarded – undo
58 58
                             $supports = apply_filters( 'getapid_gateway_supports_subscription', $supports, $id );
59 59
 
60 60
                             if ( $supports ) {
61
-							echo "<i class='text-success fa fa-check'></i>";
61
+                            echo "<i class='text-success fa fa-check'></i>";
62 62
                             } else {
63
-							echo "<i class='text-dark fa fa-times'></i>";
63
+                            echo "<i class='text-dark fa fa-times'></i>";
64 64
                             }
65 65
 
66 66
                         ?>
Please login to merge, or discard this patch.
includes/admin/views/wizard-plugins.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@
 block discarded – undo
27 27
 						<input type="checkbox" name="plugins[<?php echo esc_attr( $plugin['slug'] ); ?>]" value="<?php echo esc_attr( $plugin['file'] ); ?>" class="custom-control-input"  
28 28
                                                                         <?php
29 29
                         if ( is_plugin_active( $plugin['slug'] ) ) {
30
-																								echo 'checked';}
30
+                                                                                                echo 'checked';}
31 31
 ?>
32 32
 >
33 33
 						<label class="custom-control-label" for="ac-setting-updates"></label>
Please login to merge, or discard this patch.
admin/meta-boxes/class-getpaid-meta-box-invoice-shipping-address.php 1 patch
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
  */
8 8
 
9 9
 if ( ! defined( 'ABSPATH' ) ) {
10
-	exit; // Exit if accessed directly
10
+    exit; // Exit if accessed directly
11 11
 }
12 12
 
13 13
 /**
@@ -15,22 +15,22 @@  discard block
 block discarded – undo
15 15
  */
16 16
 class GetPaid_Meta_Box_Invoice_Shipping_Address {
17 17
 
18
-	/**
19
-	 * Output the metabox.
20
-	 *
21
-	 * @param WP_Post $post
22
-	 */
23
-	public static function output( $post ) {
18
+    /**
19
+     * Output the metabox.
20
+     *
21
+     * @param WP_Post $post
22
+     */
23
+    public static function output( $post ) {
24 24
 
25
-		// Retrieve shipping address.
26
-		$shipping_address = get_post_meta( $post->ID, 'shipping_address', true );
25
+        // Retrieve shipping address.
26
+        $shipping_address = get_post_meta( $post->ID, 'shipping_address', true );
27 27
 
28
-		// Abort if it is invalid.
29
-		if ( ! is_array( $shipping_address ) ) {
30
-			return;
31
-		}
28
+        // Abort if it is invalid.
29
+        if ( ! is_array( $shipping_address ) ) {
30
+            return;
31
+        }
32 32
 
33
-		?>
33
+        ?>
34 34
 
35 35
 		<div class="bsui">
36 36
 
@@ -68,31 +68,31 @@  discard block
 block discarded – undo
68 68
 
69 69
 		<?php
70 70
 
71
-	}
71
+    }
72 72
 
73
-	/**
74
-	 * Prepares a value.
75
-	 *
76
-	 * @param array $address
77
-	 * @param string $key
78
-	 * @return string
79
-	 */
80
-	public static function prepare_for_display( $address, $key ) {
73
+    /**
74
+     * Prepares a value.
75
+     *
76
+     * @param array $address
77
+     * @param string $key
78
+     * @return string
79
+     */
80
+    public static function prepare_for_display( $address, $key ) {
81 81
 
82
-		// Prepare the value.
83
-		$value = $address[ $key ];
82
+        // Prepare the value.
83
+        $value = $address[ $key ];
84 84
 
85
-		if ( $key == 'country' ) {
86
-			$value = wpinv_country_name( $value );
87
-		}
85
+        if ( $key == 'country' ) {
86
+            $value = wpinv_country_name( $value );
87
+        }
88 88
 
89
-		if ( $key == 'state' ) {
90
-			$country = isset( $address['country'] ) ? $address['country'] : wpinv_get_default_country();
91
-			$value = wpinv_state_name( $value, $country );
92
-		}
89
+        if ( $key == 'state' ) {
90
+            $country = isset( $address['country'] ) ? $address['country'] : wpinv_get_default_country();
91
+            $value = wpinv_state_name( $value, $country );
92
+        }
93 93
 
94
-		return esc_html( $value );
94
+        return esc_html( $value );
95 95
 
96
-	}
96
+    }
97 97
 
98 98
 }
Please login to merge, or discard this patch.
includes/admin/meta-boxes/class-getpaid-meta-box-discount-details.php 1 patch
Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  */
9 9
 
10 10
 if ( ! defined( 'ABSPATH' ) ) {
11
-	exit; // Exit if accessed directly
11
+    exit; // Exit if accessed directly
12 12
 }
13 13
 
14 14
 /**
@@ -17,10 +17,10 @@  discard block
 block discarded – undo
17 17
 class GetPaid_Meta_Box_Discount_Details {
18 18
 
19 19
     /**
20
-	 * Output the metabox.
21
-	 *
22
-	 * @param WP_Post $post
23
-	 */
20
+     * Output the metabox.
21
+     *
22
+     * @param WP_Post $post
23
+     */
24 24
     public static function output( $post ) {
25 25
 
26 26
         // Prepare the discount.
@@ -396,35 +396,35 @@  discard block
 block discarded – undo
396 396
     }
397 397
 
398 398
     /**
399
-	 * Save meta box data.
400
-	 *
401
-	 * @param int $post_id
402
-	 */
403
-	public static function save( $post_id ) {
399
+     * Save meta box data.
400
+     *
401
+     * @param int $post_id
402
+     */
403
+    public static function save( $post_id ) {
404 404
 
405 405
         // Prepare the discount.
406 406
         $discount = new WPInv_Discount( $post_id );
407 407
 
408 408
         // Load new data.
409 409
         $discount->set_props(
410
-			array(
411
-				'code'           => isset( $_POST['wpinv_discount_code'] ) ? wpinv_clean( $_POST['wpinv_discount_code'] ) : null,
412
-				'amount'         => isset( $_POST['wpinv_discount_amount'] ) ? floatval( $_POST['wpinv_discount_amount'] ) : null,
413
-				'start'          => isset( $_POST['wpinv_discount_start'] ) ? wpinv_clean( $_POST['wpinv_discount_start'] ) : null,
414
-				'expiration'     => isset( $_POST['wpinv_discount_expiration'] ) ? wpinv_clean( $_POST['wpinv_discount_expiration'] ) : null,
415
-				'is_single_use'  => ! empty( $_POST['wpinv_discount_single_use'] ),
410
+            array(
411
+                'code'           => isset( $_POST['wpinv_discount_code'] ) ? wpinv_clean( $_POST['wpinv_discount_code'] ) : null,
412
+                'amount'         => isset( $_POST['wpinv_discount_amount'] ) ? floatval( $_POST['wpinv_discount_amount'] ) : null,
413
+                'start'          => isset( $_POST['wpinv_discount_start'] ) ? wpinv_clean( $_POST['wpinv_discount_start'] ) : null,
414
+                'expiration'     => isset( $_POST['wpinv_discount_expiration'] ) ? wpinv_clean( $_POST['wpinv_discount_expiration'] ) : null,
415
+                'is_single_use'  => ! empty( $_POST['wpinv_discount_single_use'] ),
416 416
                 'type'           => isset( $_POST['wpinv_discount_type'] ) ? wpinv_clean( $_POST['wpinv_discount_type'] ) : null,
417
-				'is_recurring'   => ! empty( $_POST['wpinv_discount_recurring'] ),
418
-				'items'          => isset( $_POST['wpinv_discount_items'] ) ? wpinv_clean( $_POST['wpinv_discount_items'] ) : array(),
419
-				'excluded_items' => isset( $_POST['wpinv_discount_excluded_items'] ) ? wpinv_clean( $_POST['wpinv_discount_excluded_items'] ) : array(),
417
+                'is_recurring'   => ! empty( $_POST['wpinv_discount_recurring'] ),
418
+                'items'          => isset( $_POST['wpinv_discount_items'] ) ? wpinv_clean( $_POST['wpinv_discount_items'] ) : array(),
419
+                'excluded_items' => isset( $_POST['wpinv_discount_excluded_items'] ) ? wpinv_clean( $_POST['wpinv_discount_excluded_items'] ) : array(),
420 420
                 'required_items' => isset( $_POST['wpinv_discount_required_items'] ) ? wpinv_clean( $_POST['wpinv_discount_required_items'] ) : array(),
421
-				'max_uses'       => isset( $_POST['wpinv_discount_max_uses'] ) ? intval( $_POST['wpinv_discount_max_uses'] ) : null,
422
-				'min_total'      => isset( $_POST['wpinv_discount_min_total'] ) ? floatval( $_POST['wpinv_discount_min_total'] ) : null,
423
-				'max_total'      => isset( $_POST['wpinv_discount_max_total'] ) ? floatval( $_POST['wpinv_discount_max_total'] ) : null,
424
-			)
421
+                'max_uses'       => isset( $_POST['wpinv_discount_max_uses'] ) ? intval( $_POST['wpinv_discount_max_uses'] ) : null,
422
+                'min_total'      => isset( $_POST['wpinv_discount_min_total'] ) ? floatval( $_POST['wpinv_discount_min_total'] ) : null,
423
+                'max_total'      => isset( $_POST['wpinv_discount_max_total'] ) ? floatval( $_POST['wpinv_discount_max_total'] ) : null,
424
+            )
425 425
         );
426 426
 
427
-		$discount->save();
428
-		do_action( 'getpaid_discount_metabox_save', $post_id, $discount );
429
-	}
427
+        $discount->save();
428
+        do_action( 'getpaid_discount_metabox_save', $post_id, $discount );
429
+    }
430 430
 }
Please login to merge, or discard this patch.
includes/admin/class-getpaid-admin-profile.php 1 patch
Indentation   +149 added lines, -149 removed lines patch added patch discarded remove patch
@@ -5,110 +5,110 @@  discard block
 block discarded – undo
5 5
  */
6 6
 
7 7
 if ( ! defined( 'ABSPATH' ) ) {
8
-	exit; // Exit if accessed directly
8
+    exit; // Exit if accessed directly
9 9
 }
10 10
 
11 11
 if ( ! class_exists( 'GetPaid_Admin_Profile', false ) ) :
12 12
 
13
-	/**
14
-	 * GetPaid_Admin_Profile Class.
15
-	 */
16
-	class GetPaid_Admin_Profile {
17
-
18
-		/**
19
-		 * Hook in tabs.
20
-		 */
21
-		public function __construct() {
22
-			add_action( 'show_user_profile', array( $this, 'add_customer_meta_fields' ), 100 );
23
-			add_action( 'edit_user_profile', array( $this, 'add_customer_meta_fields' ), 100 );
24
-
25
-			add_action( 'personal_options_update', array( $this, 'save_customer_meta_fields' ) );
26
-			add_action( 'edit_user_profile_update', array( $this, 'save_customer_meta_fields' ) );
27
-		}
28
-
29
-		/**
30
-		 * Get Address Fields for the edit user pages.
31
-		 *
32
-		 * @return array Fields to display which are filtered through invoicing_customer_meta_fields before being returned
33
-		 */
34
-		public function get_customer_meta_fields() {
35
-
36
-			$show_fields = apply_filters(
37
-				'getpaid_customer_meta_fields',
38
-				array(
39
-					'billing' => array(
40
-						'title'  => __( 'Billing Details (GetPaid)', 'invoicing' ),
41
-						'fields' => array(
42
-							'_wpinv_first_name' => array(
43
-								'label'       => __( 'First name', 'invoicing' ),
44
-								'description' => '',
45
-							),
46
-							'_wpinv_last_name'  => array(
47
-								'label'       => __( 'Last name', 'invoicing' ),
48
-								'description' => '',
49
-							),
50
-							'_wpinv_company'    => array(
51
-								'label'       => __( 'Company', 'invoicing' ),
52
-								'description' => '',
53
-							),
54
-							'_wpinv_company_id' => array(
55
-								'label'       => __( 'Company ID', 'invoicing' ),
56
-								'description' => '',
57
-							),
58
-							'_wpinv_address'    => array(
59
-								'label'       => __( 'Address', 'invoicing' ),
60
-								'description' => '',
61
-							),
62
-							'_wpinv_city'       => array(
63
-								'label'       => __( 'City', 'invoicing' ),
64
-								'description' => '',
65
-							),
66
-							'_wpinv_zip'        => array(
67
-								'label'       => __( 'Postcode / ZIP', 'invoicing' ),
68
-								'description' => '',
69
-							),
70
-							'_wpinv_country'    => array(
71
-								'label'       => __( 'Country / Region', 'invoicing' ),
72
-								'description' => '',
73
-								'class'       => 'getpaid_js_field-country',
74
-								'type'        => 'select',
75
-								'options'     => array( '' => __( 'Select a country / region&hellip;', 'invoicing' ) ) + wpinv_get_country_list(),
76
-							),
77
-							'_wpinv_state'      => array(
78
-								'label'       => __( 'State / County', 'invoicing' ),
79
-								'description' => __( 'State / County or state code', 'invoicing' ),
80
-								'class'       => 'getpaid_js_field-state regular-text',
81
-							),
82
-							'_wpinv_phone'      => array(
83
-								'label'       => __( 'Phone', 'invoicing' ),
84
-								'description' => '',
85
-							),
86
-							'_wpinv_vat_number' => array(
87
-								'label'       => __( 'VAT Number', 'invoicing' ),
88
-								'description' => '',
89
-							),
90
-						),
91
-					),
92
-				)
93
-			);
94
-			return $show_fields;
95
-		}
96
-
97
-		/**
98
-		 * Show Address Fields on edit user pages.
99
-		 *
100
-		 * @param WP_User $user
101
-		 */
102
-		public function add_customer_meta_fields( $user ) {
103
-
104
-			if ( ! apply_filters( 'getpaid_current_user_can_edit_customer_meta_fields', current_user_can( 'manage_options' ), $user->ID ) ) {
105
-				return;
106
-			}
107
-
108
-			$show_fields = $this->get_customer_meta_fields();
109
-
110
-			foreach ( $show_fields as $fieldset_key => $fieldset ) :
111
-				?>
13
+    /**
14
+     * GetPaid_Admin_Profile Class.
15
+     */
16
+    class GetPaid_Admin_Profile {
17
+
18
+        /**
19
+         * Hook in tabs.
20
+         */
21
+        public function __construct() {
22
+            add_action( 'show_user_profile', array( $this, 'add_customer_meta_fields' ), 100 );
23
+            add_action( 'edit_user_profile', array( $this, 'add_customer_meta_fields' ), 100 );
24
+
25
+            add_action( 'personal_options_update', array( $this, 'save_customer_meta_fields' ) );
26
+            add_action( 'edit_user_profile_update', array( $this, 'save_customer_meta_fields' ) );
27
+        }
28
+
29
+        /**
30
+         * Get Address Fields for the edit user pages.
31
+         *
32
+         * @return array Fields to display which are filtered through invoicing_customer_meta_fields before being returned
33
+         */
34
+        public function get_customer_meta_fields() {
35
+
36
+            $show_fields = apply_filters(
37
+                'getpaid_customer_meta_fields',
38
+                array(
39
+                    'billing' => array(
40
+                        'title'  => __( 'Billing Details (GetPaid)', 'invoicing' ),
41
+                        'fields' => array(
42
+                            '_wpinv_first_name' => array(
43
+                                'label'       => __( 'First name', 'invoicing' ),
44
+                                'description' => '',
45
+                            ),
46
+                            '_wpinv_last_name'  => array(
47
+                                'label'       => __( 'Last name', 'invoicing' ),
48
+                                'description' => '',
49
+                            ),
50
+                            '_wpinv_company'    => array(
51
+                                'label'       => __( 'Company', 'invoicing' ),
52
+                                'description' => '',
53
+                            ),
54
+                            '_wpinv_company_id' => array(
55
+                                'label'       => __( 'Company ID', 'invoicing' ),
56
+                                'description' => '',
57
+                            ),
58
+                            '_wpinv_address'    => array(
59
+                                'label'       => __( 'Address', 'invoicing' ),
60
+                                'description' => '',
61
+                            ),
62
+                            '_wpinv_city'       => array(
63
+                                'label'       => __( 'City', 'invoicing' ),
64
+                                'description' => '',
65
+                            ),
66
+                            '_wpinv_zip'        => array(
67
+                                'label'       => __( 'Postcode / ZIP', 'invoicing' ),
68
+                                'description' => '',
69
+                            ),
70
+                            '_wpinv_country'    => array(
71
+                                'label'       => __( 'Country / Region', 'invoicing' ),
72
+                                'description' => '',
73
+                                'class'       => 'getpaid_js_field-country',
74
+                                'type'        => 'select',
75
+                                'options'     => array( '' => __( 'Select a country / region&hellip;', 'invoicing' ) ) + wpinv_get_country_list(),
76
+                            ),
77
+                            '_wpinv_state'      => array(
78
+                                'label'       => __( 'State / County', 'invoicing' ),
79
+                                'description' => __( 'State / County or state code', 'invoicing' ),
80
+                                'class'       => 'getpaid_js_field-state regular-text',
81
+                            ),
82
+                            '_wpinv_phone'      => array(
83
+                                'label'       => __( 'Phone', 'invoicing' ),
84
+                                'description' => '',
85
+                            ),
86
+                            '_wpinv_vat_number' => array(
87
+                                'label'       => __( 'VAT Number', 'invoicing' ),
88
+                                'description' => '',
89
+                            ),
90
+                        ),
91
+                    ),
92
+                )
93
+            );
94
+            return $show_fields;
95
+        }
96
+
97
+        /**
98
+         * Show Address Fields on edit user pages.
99
+         *
100
+         * @param WP_User $user
101
+         */
102
+        public function add_customer_meta_fields( $user ) {
103
+
104
+            if ( ! apply_filters( 'getpaid_current_user_can_edit_customer_meta_fields', current_user_can( 'manage_options' ), $user->ID ) ) {
105
+                return;
106
+            }
107
+
108
+            $show_fields = $this->get_customer_meta_fields();
109
+
110
+            foreach ( $show_fields as $fieldset_key => $fieldset ) :
111
+                ?>
112 112
 				<h2><?php echo esc_html( $fieldset['title'] ); ?></h2>
113 113
 				<table class="form-table" id="<?php echo esc_attr( 'getpaid-fieldset-' . $fieldset_key ); ?>">
114 114
 					<?php foreach ( $fieldset['fields'] as $key => $field ) : ?>
@@ -120,9 +120,9 @@  discard block
 block discarded – undo
120 120
 								<?php if ( ! empty( $field['type'] ) && 'select' === $field['type'] ) : ?>
121 121
 									<select name="<?php echo esc_attr( $key ); ?>" id="<?php echo esc_attr( $key ); ?>" class="<?php echo esc_attr( $field['class'] ); ?> wpi_select2" style="width: 25em;">
122 122
 										<?php
123
-											$selected = esc_attr( get_user_meta( $user->ID, $key, true ) );
124
-										foreach ( $field['options'] as $option_key => $option_value ) :
125
-											?>
123
+                                            $selected = esc_attr( get_user_meta( $user->ID, $key, true ) );
124
+                                        foreach ( $field['options'] as $option_key => $option_value ) :
125
+                                            ?>
126 126
 											<option value="<?php echo esc_attr( $option_key ); ?>" <?php selected( $selected, $option_key, true ); ?>><?php echo esc_html( $option_value ); ?></option>
127 127
 										<?php endforeach; ?>
128 128
 									</select>
@@ -137,52 +137,52 @@  discard block
 block discarded – undo
137 137
 					<?php endforeach; ?>
138 138
 				</table>
139 139
 				<?php
140
-			endforeach;
141
-		}
142
-
143
-		/**
144
-		 * Save Address Fields on edit user pages.
145
-		 *
146
-		 * @param int $user_id User ID of the user being saved
147
-		 */
148
-		public function save_customer_meta_fields( $user_id ) {
149
-			if ( ! apply_filters( 'getpaid_current_user_can_edit_customer_meta_fields', current_user_can( 'manage_options' ), $user_id ) ) {
150
-				return;
151
-			}
152
-
153
-			$save_fields = $this->get_customer_meta_fields();
154
-
155
-			foreach ( $save_fields as $fieldset ) {
156
-
157
-				foreach ( $fieldset['fields'] as $key => $field ) {
158
-
159
-					if ( isset( $field['type'] ) && 'checkbox' === $field['type'] ) {
160
-						update_user_meta( $user_id, $key, ! empty( $_POST[ $key ] ) );
161
-					} elseif ( isset( $_POST[ $key ] ) ) {
162
-						update_user_meta( $user_id, $key, wpinv_clean( $_POST[ $key ] ) );
163
-					}
164
-				}
165
-			}
166
-		}
167
-
168
-		/**
169
-		 * Get user meta for a given key, with fallbacks to core user info for pre-existing fields.
170
-		 *
171
-		 * @since 3.1.0
172
-		 * @param int    $user_id User ID of the user being edited
173
-		 * @param string $key     Key for user meta field
174
-		 * @return string
175
-		 */
176
-		protected function get_user_meta( $user_id, $key ) {
177
-			$value           = get_user_meta( $user_id, $key, true );
178
-			$existing_fields = array( '_wpinv_first_name', '_wpinv_last_name' );
179
-			if ( ! $value && in_array( $key, $existing_fields ) ) {
180
-				$value = get_user_meta( $user_id, str_replace( '_wpinv_', '', $key ), true );
181
-			}
182
-
183
-			return $value;
184
-		}
185
-	}
140
+            endforeach;
141
+        }
142
+
143
+        /**
144
+         * Save Address Fields on edit user pages.
145
+         *
146
+         * @param int $user_id User ID of the user being saved
147
+         */
148
+        public function save_customer_meta_fields( $user_id ) {
149
+            if ( ! apply_filters( 'getpaid_current_user_can_edit_customer_meta_fields', current_user_can( 'manage_options' ), $user_id ) ) {
150
+                return;
151
+            }
152
+
153
+            $save_fields = $this->get_customer_meta_fields();
154
+
155
+            foreach ( $save_fields as $fieldset ) {
156
+
157
+                foreach ( $fieldset['fields'] as $key => $field ) {
158
+
159
+                    if ( isset( $field['type'] ) && 'checkbox' === $field['type'] ) {
160
+                        update_user_meta( $user_id, $key, ! empty( $_POST[ $key ] ) );
161
+                    } elseif ( isset( $_POST[ $key ] ) ) {
162
+                        update_user_meta( $user_id, $key, wpinv_clean( $_POST[ $key ] ) );
163
+                    }
164
+                }
165
+            }
166
+        }
167
+
168
+        /**
169
+         * Get user meta for a given key, with fallbacks to core user info for pre-existing fields.
170
+         *
171
+         * @since 3.1.0
172
+         * @param int    $user_id User ID of the user being edited
173
+         * @param string $key     Key for user meta field
174
+         * @return string
175
+         */
176
+        protected function get_user_meta( $user_id, $key ) {
177
+            $value           = get_user_meta( $user_id, $key, true );
178
+            $existing_fields = array( '_wpinv_first_name', '_wpinv_last_name' );
179
+            if ( ! $value && in_array( $key, $existing_fields ) ) {
180
+                $value = get_user_meta( $user_id, str_replace( '_wpinv_', '', $key ), true );
181
+            }
182
+
183
+            return $value;
184
+        }
185
+    }
186 186
 
187 187
 endif;
188 188
 
Please login to merge, or discard this patch.
includes/admin/admin-pages.php 1 patch
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -57,8 +57,8 @@  discard block
 block discarded – undo
57 57
             'getpaid-nonce',
58 58
             'getpaid-nonce'
59 59
         );
60
-		$anchor = __( 'Deactivate', 'invoicing' );
61
-		$title  = esc_attr__( 'Are you sure you want to deactivate this discount?', 'invoicing' );
60
+        $anchor = __( 'Deactivate', 'invoicing' );
61
+        $title  = esc_attr__( 'Are you sure you want to deactivate this discount?', 'invoicing' );
62 62
         $row_actions['deactivate'] = "<a href='$url' onclick='return confirm(\"$title\")'>$anchor</a>";
63 63
 
64 64
     } elseif ( in_array( strtolower( $discount->post_status ), array( 'pending', 'draft' ) ) ) {
@@ -73,8 +73,8 @@  discard block
 block discarded – undo
73 73
             'getpaid-nonce',
74 74
             'getpaid-nonce'
75 75
         );
76
-		$anchor = __( 'Activate', 'invoicing' );
77
-		$title  = esc_attr__( 'Are you sure you want to activate this discount?', 'invoicing' );
76
+        $anchor = __( 'Activate', 'invoicing' );
77
+        $title  = esc_attr__( 'Are you sure you want to activate this discount?', 'invoicing' );
78 78
         $row_actions['activate'] = "<a href='$url' onclick='return confirm(\"$title\")'>$anchor</a>";
79 79
 
80 80
     }
@@ -91,8 +91,8 @@  discard block
 block discarded – undo
91 91
             'getpaid-nonce'
92 92
         )
93 93
     );
94
-	$anchor = __( 'Delete', 'invoicing' );
95
-	$title  = esc_attr__( 'Are you sure you want to delete this discount?', 'invoicing' );
94
+    $anchor = __( 'Delete', 'invoicing' );
95
+    $title  = esc_attr__( 'Are you sure you want to delete this discount?', 'invoicing' );
96 96
     $row_actions['delete'] = "<a href='$url' onclick='return confirm(\"$title\")'>$anchor</a>";
97 97
 
98 98
     $row_actions = apply_filters( 'wpinv_discount_row_actions', $row_actions, $discount );
@@ -118,13 +118,13 @@  discard block
 block discarded – undo
118 118
             $types = wpinv_get_discount_types();
119 119
 
120 120
             foreach ( $types as $name => $type ) {
121
-			echo '<option value="' . esc_attr( $name ) . '"';
121
+            echo '<option value="' . esc_attr( $name ) . '"';
122 122
 
123
-			if ( isset( $_GET['discount_type'] ) ) {
124
-				selected( $name, sanitize_text_field( $_GET['discount_type'] ) );
123
+            if ( isset( $_GET['discount_type'] ) ) {
124
+                selected( $name, sanitize_text_field( $_GET['discount_type'] ) );
125 125
                 }
126 126
 
127
-			echo '>' . esc_html__( $type, 'invoicing' ) . '</option>';
127
+            echo '>' . esc_html__( $type, 'invoicing' ) . '</option>';
128 128
             }
129 129
         ?>
130 130
     </select>
@@ -151,15 +151,15 @@  discard block
 block discarded – undo
151 151
         // Filter vat rule type
152 152
         if ( isset( $_GET['discount_type'] ) && $_GET['discount_type'] !== '' ) {
153 153
             $meta_query[] = array(
154
-				'key'     => '_wpi_discount_type',
155
-				'value'   => sanitize_key( urldecode( $_GET['discount_type'] ) ),
156
-				'compare' => '=',
157
-			);
158
-			}
154
+                'key'     => '_wpi_discount_type',
155
+                'value'   => sanitize_key( urldecode( $_GET['discount_type'] ) ),
156
+                'compare' => '=',
157
+            );
158
+            }
159 159
 
160 160
         if ( ! empty( $meta_query ) ) {
161 161
             $vars['meta_query'] = $meta_query;
162
-			}
162
+            }
163 163
     }
164 164
 
165 165
     return $vars;
Please login to merge, or discard this patch.
includes/admin/class-wpinv-admin-menus.php 1 patch
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -24,14 +24,14 @@  discard block
 block discarded – undo
24 24
     }
25 25
 
26 26
     /**
27
-	 * Highlights sub menus.
28
-	 */
29
-	public function set_admin_menu_class() {
30
-		global $current_screen, $parent_file, $submenu_file;
27
+     * Highlights sub menus.
28
+     */
29
+    public function set_admin_menu_class() {
30
+        global $current_screen, $parent_file, $submenu_file;
31 31
 
32 32
         if ( ! empty( $current_screen->id ) && in_array( $current_screen->id, array( 'wpi_discount', 'wpi_payment_form', 'wpi_invoice' ) ) ) {
33
-			$parent_file = 'wpinv';
34
-			$submenu_file = 'edit.php?post_type=' . $current_screen->id;
33
+            $parent_file = 'wpinv';
34
+            $submenu_file = 'edit.php?post_type=' . $current_screen->id;
35 35
         }
36 36
 
37 37
     }
@@ -165,8 +165,8 @@  discard block
 block discarded – undo
165 165
                 foreach ( wpinv_get_settings_tabs() as $tab_id => $tab_name ) {
166 166
                     $tab_url = add_query_arg(
167 167
                         array(
168
-							'settings-updated' => false,
169
-							'tab'              => $tab_id,
168
+                            'settings-updated' => false,
169
+                            'tab'              => $tab_id,
170 170
                         ),
171 171
                         'admin.php?page=wpinv-settings'
172 172
                     );
@@ -193,9 +193,9 @@  discard block
 block discarded – undo
193 193
                     $number++;
194 194
                     $tab_url = add_query_arg(
195 195
                         array(
196
-							'settings-updated' => false,
197
-							'tab'              => $active_tab,
198
-							'section'          => $section_id,
196
+                            'settings-updated' => false,
197
+                            'tab'              => $active_tab,
198
+                            'section'          => $section_id,
199 199
                         ),
200 200
                         admin_url( 'admin.php?page=wpinv-settings' )
201 201
                     );
Please login to merge, or discard this patch.
includes/class-wpinv-addons.php 1 patch
Indentation   +210 added lines, -210 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  *
7 7
  */
8 8
 if ( ! defined( 'ABSPATH' ) ) {
9
-	exit;
9
+    exit;
10 10
 }
11 11
 
12 12
 /**
@@ -15,92 +15,92 @@  discard block
 block discarded – undo
15 15
 class WPInv_Admin_Addons extends Ayecode_Addons {
16 16
 
17 17
 
18
-	/**
19
-	 * Get the extensions page tabs.
20
-	 *
21
-	 * @return array of tabs.
22
-	 */
23
-	public function get_tabs() {
24
-		$tabs = array(
25
-			'addons'              => __( 'Addons', 'invoicing' ),
18
+    /**
19
+     * Get the extensions page tabs.
20
+     *
21
+     * @return array of tabs.
22
+     */
23
+    public function get_tabs() {
24
+        $tabs = array(
25
+            'addons'              => __( 'Addons', 'invoicing' ),
26 26
             'gateways'            => __( 'Payment Gateways', 'invoicing' ),
27 27
             'recommended_plugins' => __( 'Recommended plugins', 'invoicing' ),
28 28
             'membership'          => __( 'Membership', 'invoicing' ),
29
-		);
30
-
31
-		return $tabs;
32
-	}
33
-
34
-	/**
35
-	 * Get section content for the addons screen.
36
-	 *
37
-	 * @param  string $section_id
38
-	 *
39
-	 * @return array
40
-	 */
41
-	public function get_section_data( $section_id ) {
42
-		$section      = self::get_tab( $section_id );
43
-		$api_url = 'https://wpinvoicing.com/edd-api/v2/products/';
44
-		$section_data = new stdClass();
45
-
46
-		if ( $section_id == 'recommended_plugins' ) {
47
-			$section_data->products = self::get_recommend_wp_plugins_edd_formatted();
48
-		} elseif ( ! empty( $section ) ) {
49
-			if ( false === ( $section_data = get_transient( 'wpi_addons_section_' . $section_id ) ) ) { //@todo restore after testing
50
-			//if ( 1==1) {
51
-
52
-				$query_args = array(
53
-					'category' => $section_id,
54
-					'number'   => 100,
55
-				);
56
-				$query_args = apply_filters( 'wpeu_edd_api_query_args', $query_args, $api_url, $section_id );
57
-
58
-				$raw_section = wp_safe_remote_get(
29
+        );
30
+
31
+        return $tabs;
32
+    }
33
+
34
+    /**
35
+     * Get section content for the addons screen.
36
+     *
37
+     * @param  string $section_id
38
+     *
39
+     * @return array
40
+     */
41
+    public function get_section_data( $section_id ) {
42
+        $section      = self::get_tab( $section_id );
43
+        $api_url = 'https://wpinvoicing.com/edd-api/v2/products/';
44
+        $section_data = new stdClass();
45
+
46
+        if ( $section_id == 'recommended_plugins' ) {
47
+            $section_data->products = self::get_recommend_wp_plugins_edd_formatted();
48
+        } elseif ( ! empty( $section ) ) {
49
+            if ( false === ( $section_data = get_transient( 'wpi_addons_section_' . $section_id ) ) ) { //@todo restore after testing
50
+            //if ( 1==1) {
51
+
52
+                $query_args = array(
53
+                    'category' => $section_id,
54
+                    'number'   => 100,
55
+                );
56
+                $query_args = apply_filters( 'wpeu_edd_api_query_args', $query_args, $api_url, $section_id );
57
+
58
+                $raw_section = wp_safe_remote_get(
59 59
                     esc_url_raw( add_query_arg( $query_args, $api_url ) ),
60 60
                     array(
61
-						'user-agent' => 'Invoicing Addons Page',
62
-						'timeout'    => 15,
61
+                        'user-agent' => 'Invoicing Addons Page',
62
+                        'timeout'    => 15,
63 63
                     )
64 64
                 );
65 65
 
66
-				if ( ! is_wp_error( $raw_section ) ) {
67
-					$section_data = json_decode( wp_remote_retrieve_body( $raw_section ) );
66
+                if ( ! is_wp_error( $raw_section ) ) {
67
+                    $section_data = json_decode( wp_remote_retrieve_body( $raw_section ) );
68 68
 
69
-					if ( ! empty( $section_data->products ) ) {
70
-						set_transient( 'wpi_addons_section_' . $section_id, $section_data, DAY_IN_SECONDS );
71
-					}
72
-				}
73
-			}
69
+                    if ( ! empty( $section_data->products ) ) {
70
+                        set_transient( 'wpi_addons_section_' . $section_id, $section_data, DAY_IN_SECONDS );
71
+                    }
72
+                }
73
+            }
74 74
 }
75 75
 
76
-		$products = isset( $section_data->products ) ? $section_data->products : array();
77
-		if ( 'addons' == $section_id ) {
78
-
79
-			$quotes = new stdClass();
80
-			$quotes->info = new stdClass();
81
-			$quotes->info->id = '';
82
-			$quotes->info->slug = 'invoicing-quotes';
83
-			$quotes->info->title = __( 'Quotes', 'invoicing' );
84
-			$quotes->info->excerpt = __( 'Create quotes and estimates', 'invoicing' );
85
-			$quotes->info->link = 'https://wordpress.org/plugins/invoicing-quotes/';
86
-			$quotes->info->thumbnail = WPINV_PLUGIN_URL . 'assets/images/Quotes-1-768x384.png';
87
-
88
-			$products[] = $quotes;
89
-		}
90
-
91
-		return apply_filters( 'wpi_addons_section_data', $products, $section_id );
92
-	}
93
-
94
-	/**
95
-	 * Outputs a button.
96
-	 *ccc
97
-	 * @param string $url
98
-	 * @param string $text
99
-	 * @param string $theme
100
-	 * @param string $plugin
101
-	 */
102
-	public function output_button( $addon ) {
103
-		$current_tab     = empty( $_GET['tab'] ) ? 'addons' : sanitize_title( $_GET['tab'] );
76
+        $products = isset( $section_data->products ) ? $section_data->products : array();
77
+        if ( 'addons' == $section_id ) {
78
+
79
+            $quotes = new stdClass();
80
+            $quotes->info = new stdClass();
81
+            $quotes->info->id = '';
82
+            $quotes->info->slug = 'invoicing-quotes';
83
+            $quotes->info->title = __( 'Quotes', 'invoicing' );
84
+            $quotes->info->excerpt = __( 'Create quotes and estimates', 'invoicing' );
85
+            $quotes->info->link = 'https://wordpress.org/plugins/invoicing-quotes/';
86
+            $quotes->info->thumbnail = WPINV_PLUGIN_URL . 'assets/images/Quotes-1-768x384.png';
87
+
88
+            $products[] = $quotes;
89
+        }
90
+
91
+        return apply_filters( 'wpi_addons_section_data', $products, $section_id );
92
+    }
93
+
94
+    /**
95
+     * Outputs a button.
96
+     *ccc
97
+     * @param string $url
98
+     * @param string $text
99
+     * @param string $theme
100
+     * @param string $plugin
101
+     */
102
+    public function output_button( $addon ) {
103
+        $current_tab     = empty( $_GET['tab'] ) ? 'addons' : sanitize_title( $_GET['tab'] );
104 104
 //		$button_text = __('Free','invoicing');
105 105
 //		$licensing = false;
106 106
 //		$installed = false;
@@ -112,128 +112,128 @@  discard block
 block discarded – undo
112 112
 //		$install_status = 'get';
113 113
 //		$onclick = '';
114 114
 
115
-		$wp_org_themes = array( 'supreme-directory', 'directory-starter' );
116
-
117
-		$button_args = array(
118
-			'type'           => ($current_tab == 'addons' || $current_tab == 'gateways') ? 'addons' : $current_tab,
119
-			'id'             => isset( $addon->info->id ) ? absint( $addon->info->id ) : '',
120
-			'title'          => isset( $addon->info->title ) ? $addon->info->title : '',
121
-			'button_text'    => __( 'Free', 'invoicing' ),
122
-			'price_text'     => __( 'Free', 'invoicing' ),
123
-			'link'           => isset( $addon->info->link ) ? $addon->info->link : '', // link to product
124
-			'url'            => isset( $addon->info->link ) ? $addon->info->link : '', // button url
125
-			'class'          => 'button-primary',
126
-			'install_status' => 'get',
127
-			'installed'      => false,
128
-			'price'          => '',
129
-			'licensing'      => isset( $addon->licensing->enabled ) && $addon->licensing->enabled ? true : false,
130
-			'license'        => isset( $addon->licensing->license ) && $addon->licensing->license ? $addon->licensing->license : '',
131
-			'onclick'        => '',
132
-			'slug'           => isset( $addon->info->slug ) ? $addon->info->slug : '',
133
-			'active'         => false,
134
-			'file'           => '',
135
-			'update_url'     => '',
136
-		);
137
-
138
-		if ( 'invoicing-quotes' == $addon->info->slug || 'getpaid-stripe-payments' == $addon->info->slug || ( $current_tab == 'recommended_plugins' && isset( $addon->info->slug ) && $addon->info->slug ) ) {
139
-			include_once ABSPATH . 'wp-admin/includes/plugin-install.php'; //for plugins_api..
140
-			$status = install_plugin_install_status(
115
+        $wp_org_themes = array( 'supreme-directory', 'directory-starter' );
116
+
117
+        $button_args = array(
118
+            'type'           => ($current_tab == 'addons' || $current_tab == 'gateways') ? 'addons' : $current_tab,
119
+            'id'             => isset( $addon->info->id ) ? absint( $addon->info->id ) : '',
120
+            'title'          => isset( $addon->info->title ) ? $addon->info->title : '',
121
+            'button_text'    => __( 'Free', 'invoicing' ),
122
+            'price_text'     => __( 'Free', 'invoicing' ),
123
+            'link'           => isset( $addon->info->link ) ? $addon->info->link : '', // link to product
124
+            'url'            => isset( $addon->info->link ) ? $addon->info->link : '', // button url
125
+            'class'          => 'button-primary',
126
+            'install_status' => 'get',
127
+            'installed'      => false,
128
+            'price'          => '',
129
+            'licensing'      => isset( $addon->licensing->enabled ) && $addon->licensing->enabled ? true : false,
130
+            'license'        => isset( $addon->licensing->license ) && $addon->licensing->license ? $addon->licensing->license : '',
131
+            'onclick'        => '',
132
+            'slug'           => isset( $addon->info->slug ) ? $addon->info->slug : '',
133
+            'active'         => false,
134
+            'file'           => '',
135
+            'update_url'     => '',
136
+        );
137
+
138
+        if ( 'invoicing-quotes' == $addon->info->slug || 'getpaid-stripe-payments' == $addon->info->slug || ( $current_tab == 'recommended_plugins' && isset( $addon->info->slug ) && $addon->info->slug ) ) {
139
+            include_once ABSPATH . 'wp-admin/includes/plugin-install.php'; //for plugins_api..
140
+            $status = install_plugin_install_status(
141 141
                 array(
142
-					'slug'    => $button_args['slug'],
143
-					'version' => '',
142
+                    'slug'    => $button_args['slug'],
143
+                    'version' => '',
144 144
                 )
145 145
             );
146
-			$button_args['install_status'] = isset( $status['status'] ) ? $status['status'] : 'install';
147
-			$button_args['file'] = isset( $status['file'] ) ? $status['file'] : '';
148
-		} elseif ( ($current_tab == 'addons' || $current_tab == 'gateways') && isset( $addon->info->id ) && $addon->info->id ) {
149
-			include_once ABSPATH . 'wp-admin/includes/plugin-install.php'; //for plugins_api..
150
-			if ( ! empty( $addon->licensing->edd_slug ) ) {
146
+            $button_args['install_status'] = isset( $status['status'] ) ? $status['status'] : 'install';
147
+            $button_args['file'] = isset( $status['file'] ) ? $status['file'] : '';
148
+        } elseif ( ($current_tab == 'addons' || $current_tab == 'gateways') && isset( $addon->info->id ) && $addon->info->id ) {
149
+            include_once ABSPATH . 'wp-admin/includes/plugin-install.php'; //for plugins_api..
150
+            if ( ! empty( $addon->licensing->edd_slug ) ) {
151 151
 $button_args['slug'] = $addon->licensing->edd_slug;}
152
-			$status = self::install_plugin_install_status( $addon );
153
-			$button_args['file'] = isset( $status['file'] ) ? $status['file'] : '';
154
-			if ( isset( $status['status'] ) ) {
152
+            $status = self::install_plugin_install_status( $addon );
153
+            $button_args['file'] = isset( $status['file'] ) ? $status['file'] : '';
154
+            if ( isset( $status['status'] ) ) {
155 155
 $button_args['install_status'] = $status['status'];}
156
-			$button_args['update_url'] = 'https://wpinvoicing.com';
157
-		} elseif ( $current_tab == 'themes' && isset( $addon->info->id ) && $addon->info->id ) {
158
-			if ( ! empty( $addon->licensing->edd_slug ) ) {
156
+            $button_args['update_url'] = 'https://wpinvoicing.com';
157
+        } elseif ( $current_tab == 'themes' && isset( $addon->info->id ) && $addon->info->id ) {
158
+            if ( ! empty( $addon->licensing->edd_slug ) ) {
159 159
 $button_args['slug'] = $addon->licensing->edd_slug;}
160
-			$button_args['installed'] = self::is_theme_installed( $addon );
161
-			if ( ! in_array( $button_args['slug'], $wp_org_themes ) ) {
162
-				$button_args['update_url'] = 'https://wpinvoicing.com';
163
-			}
164
-		}
165
-
166
-		// set price
167
-		if ( isset( $addon->pricing ) && ! empty( $addon->pricing ) ) {
168
-			if ( is_object( $addon->pricing ) ) {
169
-				$prices = (array)$addon->pricing;
170
-				$button_args['price'] = reset( $prices );
171
-			} elseif ( isset( $addon->pricing ) ) {
172
-				$button_args['price'] = $addon->pricing;
173
-			}
174
-		}
175
-
176
-		// set price text
177
-		if ( $button_args['price'] && $button_args['price'] != '0.00' ) {
178
-			$button_args['price_text'] = sprintf( __( 'From: $%d', 'invoicing' ), $button_args['price'] );
179
-		}
180
-
181
-		// set if installed
182
-		if ( in_array( $button_args['install_status'], array( 'installed', 'latest_installed', 'update_available', 'newer_installed' ) ) ) {
183
-			$button_args['installed'] = true;
184
-		}
160
+            $button_args['installed'] = self::is_theme_installed( $addon );
161
+            if ( ! in_array( $button_args['slug'], $wp_org_themes ) ) {
162
+                $button_args['update_url'] = 'https://wpinvoicing.com';
163
+            }
164
+        }
165
+
166
+        // set price
167
+        if ( isset( $addon->pricing ) && ! empty( $addon->pricing ) ) {
168
+            if ( is_object( $addon->pricing ) ) {
169
+                $prices = (array)$addon->pricing;
170
+                $button_args['price'] = reset( $prices );
171
+            } elseif ( isset( $addon->pricing ) ) {
172
+                $button_args['price'] = $addon->pricing;
173
+            }
174
+        }
175
+
176
+        // set price text
177
+        if ( $button_args['price'] && $button_args['price'] != '0.00' ) {
178
+            $button_args['price_text'] = sprintf( __( 'From: $%d', 'invoicing' ), $button_args['price'] );
179
+        }
180
+
181
+        // set if installed
182
+        if ( in_array( $button_args['install_status'], array( 'installed', 'latest_installed', 'update_available', 'newer_installed' ) ) ) {
183
+            $button_args['installed'] = true;
184
+        }
185 185
 
186 186
 //		print_r($button_args);
187
-		// set if active
188
-		if ( $button_args['installed'] && ($button_args['file'] || $button_args['type'] == 'themes') ) {
189
-			if ( $button_args['type'] != 'themes' ) {
190
-				$button_args['active'] = is_plugin_active( $button_args['file'] );
191
-			} else {
192
-				$button_args['active'] = self::is_theme_active( $addon );
193
-			}
194
-		}
195
-
196
-		// set button text and class
197
-		if ( $button_args['active'] ) {
198
-			$button_args['button_text'] = __( 'Active', 'invoicing' );
199
-			$button_args['class'] = ' button-secondary disabled ';
200
-		} elseif ( $button_args['installed'] ) {
201
-			$button_args['button_text'] = __( 'Activate', 'invoicing' );
202
-
203
-			if ( $button_args['type'] != 'themes' ) {
204
-				if ( current_user_can( 'manage_options' ) ) {
205
-					$button_args['url'] = wp_nonce_url( admin_url( 'plugins.php?action=activate&plugin=' . $button_args['file'] ), 'activate-plugin_' . $button_args['file'] );
206
-				} else {
207
-					$button_args['url'] = '#';
208
-				}
209
-			} else {
210
-				if ( current_user_can( 'switch_themes' ) ) {
211
-					$button_args['url'] = self::get_theme_activation_url( $addon );
212
-				} else {
213
-					$button_args['url'] = '#';
214
-				}
215
-			}
187
+        // set if active
188
+        if ( $button_args['installed'] && ($button_args['file'] || $button_args['type'] == 'themes') ) {
189
+            if ( $button_args['type'] != 'themes' ) {
190
+                $button_args['active'] = is_plugin_active( $button_args['file'] );
191
+            } else {
192
+                $button_args['active'] = self::is_theme_active( $addon );
193
+            }
194
+        }
195
+
196
+        // set button text and class
197
+        if ( $button_args['active'] ) {
198
+            $button_args['button_text'] = __( 'Active', 'invoicing' );
199
+            $button_args['class'] = ' button-secondary disabled ';
200
+        } elseif ( $button_args['installed'] ) {
201
+            $button_args['button_text'] = __( 'Activate', 'invoicing' );
202
+
203
+            if ( $button_args['type'] != 'themes' ) {
204
+                if ( current_user_can( 'manage_options' ) ) {
205
+                    $button_args['url'] = wp_nonce_url( admin_url( 'plugins.php?action=activate&plugin=' . $button_args['file'] ), 'activate-plugin_' . $button_args['file'] );
206
+                } else {
207
+                    $button_args['url'] = '#';
208
+                }
209
+            } else {
210
+                if ( current_user_can( 'switch_themes' ) ) {
211
+                    $button_args['url'] = self::get_theme_activation_url( $addon );
212
+                } else {
213
+                    $button_args['url'] = '#';
214
+                }
215
+            }
216 216
 } else {
217
-			if ( $button_args['type'] == 'recommended_plugins' ) {
218
-				$button_args['button_text'] = __( 'Install', 'invoicing' );
219
-					} else {
220
-				$button_args['button_text'] = __( 'Get it', 'invoicing' );
217
+            if ( $button_args['type'] == 'recommended_plugins' ) {
218
+                $button_args['button_text'] = __( 'Install', 'invoicing' );
219
+                    } else {
220
+                $button_args['button_text'] = __( 'Get it', 'invoicing' );
221 221
 
222
-				/*if($button_args['type'] == 'themes' && in_array($button_args['slug'],$wp_org_themes) ){
222
+                /*if($button_args['type'] == 'themes' && in_array($button_args['slug'],$wp_org_themes) ){
223 223
 			$button_args['button_text'] = __('Install','invoicing');
224 224
 			$button_args['url'] = self::get_theme_install_url($button_args['slug']);
225 225
 			$button_args['onclick'] = 'gd_set_button_installing(this);';
226 226
 				}*/
227 227
 
228
-					}
229
-		}
228
+                    }
229
+        }
230 230
 
231
-		// filter the button arguments
232
-		$button_args = apply_filters( 'edd_api_button_args', $button_args );
231
+        // filter the button arguments
232
+        $button_args = apply_filters( 'edd_api_button_args', $button_args );
233 233
 //		print_r($button_args);
234
-		// set price text
235
-		if ( isset( $button_args['price_text'] ) ) {
236
-			?>
234
+        // set price text
235
+        if ( isset( $button_args['price_text'] ) ) {
236
+            ?>
237 237
 			<a
238 238
 				target="_blank"
239 239
 				class="addons-price-text"
@@ -241,9 +241,9 @@  discard block
 block discarded – undo
241 241
 				<?php echo esc_html( $button_args['price_text'] ); ?>
242 242
 			</a>
243 243
 			<?php
244
-		}
244
+        }
245 245
 
246
-		?>
246
+        ?>
247 247
 		<a
248 248
 			data-licence="<?php echo esc_attr( $button_args['license'] ); ?>"
249 249
 			data-licensing="<?php echo $button_args['licensing'] ? 1 : 0; ?>"
@@ -267,33 +267,33 @@  discard block
 block discarded – undo
267 267
 		</a>
268 268
 		<?php
269 269
 
270
-	}
271
-
272
-
273
-	/**
274
-	 * Handles output of the addons page in admin.
275
-	 */
276
-	public function output() {
277
-		$tabs            = self::get_tabs();
278
-		$sections        = self::get_sections();
279
-		$theme           = wp_get_theme();
280
-		$section_keys    = array_keys( $sections );
281
-		$current_section = isset( $_GET['section'] ) ? sanitize_text_field( $_GET['section'] ) : current( $section_keys );
282
-		$current_tab     = empty( $_GET['tab'] ) ? 'addons' : sanitize_title( $_GET['tab'] );
283
-		include_once WPINV_PLUGIN_DIR . '/includes/admin/html-admin-page-addons.php';
284
-	}
285
-
286
-	/**
287
-	 * A list of recommended wp.org plugins.
288
-	 * @return array
289
-	 */
290
-	public function get_recommend_wp_plugins() {
291
-		$plugins = array(
270
+    }
271
+
272
+
273
+    /**
274
+     * Handles output of the addons page in admin.
275
+     */
276
+    public function output() {
277
+        $tabs            = self::get_tabs();
278
+        $sections        = self::get_sections();
279
+        $theme           = wp_get_theme();
280
+        $section_keys    = array_keys( $sections );
281
+        $current_section = isset( $_GET['section'] ) ? sanitize_text_field( $_GET['section'] ) : current( $section_keys );
282
+        $current_tab     = empty( $_GET['tab'] ) ? 'addons' : sanitize_title( $_GET['tab'] );
283
+        include_once WPINV_PLUGIN_DIR . '/includes/admin/html-admin-page-addons.php';
284
+    }
285
+
286
+    /**
287
+     * A list of recommended wp.org plugins.
288
+     * @return array
289
+     */
290
+    public function get_recommend_wp_plugins() {
291
+        $plugins = array(
292 292
             'invoicing-quotes' => array(
293 293
                 'url'       => 'https://wordpress.org/plugins/invoicing-quotes/',
294 294
                 'slug'      => 'invoicing-quotes',
295
-				'name'      => 'Quotes',
296
-				'thumbnail' => 'https://ps.w.org/invoicing-quotes/assets/banner-772x250.png',
295
+                'name'      => 'Quotes',
296
+                'thumbnail' => 'https://ps.w.org/invoicing-quotes/assets/banner-772x250.png',
297 297
                 'desc'      => __( 'Allows you to create quotes, send them to clients and convert them to Invoices when accepted by the customer.', 'invoicing' ),
298 298
             ),
299 299
             'geodirectory'     => array(
@@ -308,8 +308,8 @@  discard block
 block discarded – undo
308 308
                 'name' => 'UsersWP',
309 309
                 'desc' => __( 'Allow frontend user login and registration as well as have slick profile pages.', 'invoicing' ),
310 310
             ),
311
-		);
311
+        );
312 312
 
313
-		return $plugins;
314
-	}
313
+        return $plugins;
314
+    }
315 315
 }
Please login to merge, or discard this patch.
includes/api/class-getpaid-rest-controller.php 1 patch
Indentation   +539 added lines, -539 removed lines patch added patch discarded remove patch
@@ -21,569 +21,569 @@
 block discarded – undo
21 21
  */
22 22
 class GetPaid_REST_Controller extends WP_REST_Controller {
23 23
 
24
-	/**
24
+    /**
25 25
      * The namespaces of this controller's route.
26 26
      *
27 27
      * @since 1.0.19
28 28
      * @var array
29 29
      */
30
-	protected $namespaces;
30
+    protected $namespaces;
31 31
 
32
-	/**
32
+    /**
33 33
      * The official namespace of this controller's route.
34 34
      *
35 35
      * @since 1.0.19
36 36
      * @var string
37 37
      */
38
-	protected $namespace = 'getpaid/v1';
38
+    protected $namespace = 'getpaid/v1';
39 39
 
40
-	/**
40
+    /**
41 41
      * Cached results of get_item_schema.
42 42
      *
43 43
      * @since 1.0.19
44 44
      * @var array
45 45
      */
46
-	protected $schema;
46
+    protected $schema;
47 47
 
48 48
     /**
49
-	 * Constructor.
50
-	 *
51
-	 * @since 1.0.19
52
-	 *
53
-	 */
54
-	public function __construct() {
55
-
56
-		// Offer several namespaces for backwards compatibility.
57
-		$this->namespaces = apply_filters(
58
-			'getpaid_rest_api_namespaces',
59
-			array(
60
-				'getpaid/v1',
61
-				'invoicing/v1',
62
-				'wpi/v1',
63
-			)
64
-		);
65
-
66
-		// Register REST routes.
49
+     * Constructor.
50
+     *
51
+     * @since 1.0.19
52
+     *
53
+     */
54
+    public function __construct() {
55
+
56
+        // Offer several namespaces for backwards compatibility.
57
+        $this->namespaces = apply_filters(
58
+            'getpaid_rest_api_namespaces',
59
+            array(
60
+                'getpaid/v1',
61
+                'invoicing/v1',
62
+                'wpi/v1',
63
+            )
64
+        );
65
+
66
+        // Register REST routes.
67 67
         add_action( 'rest_api_init', array( $this, 'register_routes' ) );
68 68
 
69
-	}
70
-
71
-	/**
72
-	 * Registers routes for each namespace.
73
-	 *
74
-	 * @since 1.0.19
75
-	 *
76
-	 */
77
-	public function register_routes() {
78
-
79
-		foreach ( $this->namespaces as $namespace ) {
80
-			$this->register_namespace_routes( $namespace );
81
-		}
82
-
83
-	}
84
-
85
-	/**
86
-	 * Registers routes for a namespace.
87
-	 *
88
-	 * @since 1.0.19
89
-	 *
90
-	 * @param string $namespace
91
-	 */
92
-	public function register_namespace_routes( /** @scrutinizer ignore-unused */ $namespace ) {
93
-
94
-		getpaid_doing_it_wrong(
95
-			__CLASS__ . '::' . __METHOD__,
96
-			/* translators: %s: register_namespace_routes() */
97
-			sprintf( __( "Method '%s' must be overridden." ), __METHOD__ ),
98
-			'1.0.19'
99
-		);
100
-
101
-	}
102
-
103
-	/**
104
-	 * Get normalized rest base.
105
-	 *
106
-	 * @return string
107
-	 */
108
-	protected function get_normalized_rest_base() {
109
-		return preg_replace( '/\(.*\)\//i', '', $this->rest_base );
110
-	}
111
-
112
-	/**
113
-	 * Fill batches.
114
-	 *
115
-	 * @param array array of request items.
116
-	 * @return array
117
-	 */
118
-	protected function fill_batch_keys( $items ) {
119
-
120
-		$items['create'] = empty( $items['create'] ) ? array() : $items['create'];
121
-		$items['update'] = empty( $items['update'] ) ? array() : $items['update'];
122
-		$items['delete'] = empty( $items['delete'] ) ? array() : wp_parse_id_list( $items['delete'] );
123
-		return $items;
124
-
125
-	}
126
-
127
-	/**
128
-	 * Check batch limit.
129
-	 *
130
-	 * @param array $items Request items.
131
-	 * @return bool|WP_Error
132
-	 */
133
-	protected function check_batch_limit( $items ) {
134
-		$limit = apply_filters( 'getpaid_rest_batch_items_limit', 100, $this->get_normalized_rest_base() );
135
-		$total = count( $items['create'] ) + count( $items['update'] ) + count( $items['delete'] );
136
-
137
-		if ( $total > $limit ) {
138
-			/* translators: %s: items limit */
139
-			return new WP_Error( 'getpaid_rest_request_entity_too_large', sprintf( __( 'Unable to accept more than %s items for this request.', 'invoicing' ), $limit ), array( 'status' => 413 ) );
140
-		}
141
-
142
-		return true;
143
-	}
144
-
145
-	/**
146
-	 * Bulk create items.
147
-	 *
148
-	 * @param array $items Array of items to create.
149
-	 * @param WP_REST_Request $request Full details about the request.
150
-	 * @param WP_REST_Server $wp_rest_server
151
-	 * @return array()
152
-	 */
153
-	protected function batch_create_items( $items, $request, $wp_rest_server ) {
154
-
155
-		$query  = $request->get_query_params();
156
-		$create = array();
157
-
158
-		foreach ( $items as $item ) {
159
-			$_item = new WP_REST_Request( 'POST' );
160
-
161
-			// Default parameters.
162
-			$defaults = array();
163
-			$schema   = $this->get_public_item_schema();
164
-			foreach ( $schema['properties'] as $arg => $options ) {
165
-				if ( isset( $options['default'] ) ) {
166
-					$defaults[ $arg ] = $options['default'];
167
-				}
168
-			}
169
-			$_item->set_default_params( $defaults );
170
-
171
-			// Set request parameters.
172
-			$_item->set_body_params( $item );
173
-
174
-			// Set query (GET) parameters.
175
-			$_item->set_query_params( $query );
176
-
177
-			// Create the item.
178
-			$_response = $this->create_item( $_item );
179
-
180
-			// If an error occured...
181
-			if ( is_wp_error( $_response ) ) {
182
-
183
-				$create[]   = array(
184
-					'id'    => 0,
185
-					'error' => array(
186
-						'code'    => $_response->get_error_code(),
187
-						'message' => $_response->get_error_message(),
188
-						'data'    => $_response->get_error_data(),
189
-					),
190
-				);
191
-
192
-				continue;
193
-			}
194
-
195
-			$create[] = $wp_rest_server->response_to_data( /** @scrutinizer ignore-type */ $_response, false );
196
-
197
-		}
198
-
199
-		return $create;
69
+    }
70
+
71
+    /**
72
+     * Registers routes for each namespace.
73
+     *
74
+     * @since 1.0.19
75
+     *
76
+     */
77
+    public function register_routes() {
78
+
79
+        foreach ( $this->namespaces as $namespace ) {
80
+            $this->register_namespace_routes( $namespace );
81
+        }
82
+
83
+    }
84
+
85
+    /**
86
+     * Registers routes for a namespace.
87
+     *
88
+     * @since 1.0.19
89
+     *
90
+     * @param string $namespace
91
+     */
92
+    public function register_namespace_routes( /** @scrutinizer ignore-unused */ $namespace ) {
93
+
94
+        getpaid_doing_it_wrong(
95
+            __CLASS__ . '::' . __METHOD__,
96
+            /* translators: %s: register_namespace_routes() */
97
+            sprintf( __( "Method '%s' must be overridden." ), __METHOD__ ),
98
+            '1.0.19'
99
+        );
100
+
101
+    }
102
+
103
+    /**
104
+     * Get normalized rest base.
105
+     *
106
+     * @return string
107
+     */
108
+    protected function get_normalized_rest_base() {
109
+        return preg_replace( '/\(.*\)\//i', '', $this->rest_base );
110
+    }
111
+
112
+    /**
113
+     * Fill batches.
114
+     *
115
+     * @param array array of request items.
116
+     * @return array
117
+     */
118
+    protected function fill_batch_keys( $items ) {
119
+
120
+        $items['create'] = empty( $items['create'] ) ? array() : $items['create'];
121
+        $items['update'] = empty( $items['update'] ) ? array() : $items['update'];
122
+        $items['delete'] = empty( $items['delete'] ) ? array() : wp_parse_id_list( $items['delete'] );
123
+        return $items;
124
+
125
+    }
126
+
127
+    /**
128
+     * Check batch limit.
129
+     *
130
+     * @param array $items Request items.
131
+     * @return bool|WP_Error
132
+     */
133
+    protected function check_batch_limit( $items ) {
134
+        $limit = apply_filters( 'getpaid_rest_batch_items_limit', 100, $this->get_normalized_rest_base() );
135
+        $total = count( $items['create'] ) + count( $items['update'] ) + count( $items['delete'] );
136
+
137
+        if ( $total > $limit ) {
138
+            /* translators: %s: items limit */
139
+            return new WP_Error( 'getpaid_rest_request_entity_too_large', sprintf( __( 'Unable to accept more than %s items for this request.', 'invoicing' ), $limit ), array( 'status' => 413 ) );
140
+        }
141
+
142
+        return true;
143
+    }
144
+
145
+    /**
146
+     * Bulk create items.
147
+     *
148
+     * @param array $items Array of items to create.
149
+     * @param WP_REST_Request $request Full details about the request.
150
+     * @param WP_REST_Server $wp_rest_server
151
+     * @return array()
152
+     */
153
+    protected function batch_create_items( $items, $request, $wp_rest_server ) {
154
+
155
+        $query  = $request->get_query_params();
156
+        $create = array();
157
+
158
+        foreach ( $items as $item ) {
159
+            $_item = new WP_REST_Request( 'POST' );
160
+
161
+            // Default parameters.
162
+            $defaults = array();
163
+            $schema   = $this->get_public_item_schema();
164
+            foreach ( $schema['properties'] as $arg => $options ) {
165
+                if ( isset( $options['default'] ) ) {
166
+                    $defaults[ $arg ] = $options['default'];
167
+                }
168
+            }
169
+            $_item->set_default_params( $defaults );
170
+
171
+            // Set request parameters.
172
+            $_item->set_body_params( $item );
173
+
174
+            // Set query (GET) parameters.
175
+            $_item->set_query_params( $query );
176
+
177
+            // Create the item.
178
+            $_response = $this->create_item( $_item );
179
+
180
+            // If an error occured...
181
+            if ( is_wp_error( $_response ) ) {
182
+
183
+                $create[]   = array(
184
+                    'id'    => 0,
185
+                    'error' => array(
186
+                        'code'    => $_response->get_error_code(),
187
+                        'message' => $_response->get_error_message(),
188
+                        'data'    => $_response->get_error_data(),
189
+                    ),
190
+                );
191
+
192
+                continue;
193
+            }
194
+
195
+            $create[] = $wp_rest_server->response_to_data( /** @scrutinizer ignore-type */ $_response, false );
196
+
197
+        }
198
+
199
+        return $create;
200
+
201
+    }
202
+
203
+    /**
204
+     * Bulk update items.
205
+     *
206
+     * @param array $items Array of items to update.
207
+     * @param WP_REST_Request $request Full details about the request.
208
+     * @param WP_REST_Server $wp_rest_server
209
+     * @return array()
210
+     */
211
+    protected function batch_update_items( $items, $request, $wp_rest_server ) {
212
+
213
+        $query  = $request->get_query_params();
214
+        $update = array();
215
+
216
+        foreach ( $items as $item ) {
217
+
218
+            // Create a dummy request.
219
+            $_item = new WP_REST_Request( 'PUT' );
220
+
221
+            // Add body params.
222
+            $_item->set_body_params( $item );
223
+
224
+            // Set query (GET) parameters.
225
+            $_item->set_query_params( $query );
226
+
227
+            // Update the item.
228
+            $_response = $this->update_item( $_item );
229
+
230
+            // If an error occured...
231
+            if ( is_wp_error( $_response ) ) {
232
+
233
+                $update[] = array(
234
+                    'id'    => $item['id'],
235
+                    'error' => array(
236
+                        'code'    => $_response->get_error_code(),
237
+                        'message' => $_response->get_error_message(),
238
+                        'data'    => $_response->get_error_data(),
239
+                    ),
240
+                );
241
+
242
+                continue;
243
+
244
+            }
245
+
246
+            $update[] = $wp_rest_server->response_to_data( /** @scrutinizer ignore-type */ $_response, false );
247
+
248
+        }
249
+
250
+        return $update;
251
+
252
+    }
253
+
254
+    /**
255
+     * Bulk delete items.
256
+     *
257
+     * @param array $items Array of items to delete.
258
+     * @param WP_REST_Server $wp_rest_server
259
+     * @return array()
260
+     */
261
+    protected function batch_delete_items( $items, $wp_rest_server ) {
262
+
263
+        $delete = array();
264
+
265
+        foreach ( array_filter( $items ) as $id ) {
266
+
267
+            // Prepare the request.
268
+            $_item = new WP_REST_Request( 'DELETE' );
269
+            $_item->set_query_params(
270
+                array(
271
+                    'id'    => $id,
272
+                    'force' => true,
273
+                )
274
+            );
275
+
276
+            // Delete the item.
277
+            $_response = $this->delete_item( $_item );
278
+
279
+            if ( is_wp_error( $_response ) ) {
280
+
281
+                $delete[] = array(
282
+                    'id'    => $id,
283
+                    'error' => array(
284
+                        'code'    => $_response->get_error_code(),
285
+                        'message' => $_response->get_error_message(),
286
+                        'data'    => $_response->get_error_data(),
287
+                    ),
288
+                );
289
+
290
+                continue;
291
+            }
200 292
 
201
-	}
202
-
203
-	/**
204
-	 * Bulk update items.
205
-	 *
206
-	 * @param array $items Array of items to update.
207
-	 * @param WP_REST_Request $request Full details about the request.
208
-	 * @param WP_REST_Server $wp_rest_server
209
-	 * @return array()
210
-	 */
211
-	protected function batch_update_items( $items, $request, $wp_rest_server ) {
212
-
213
-		$query  = $request->get_query_params();
214
-		$update = array();
215
-
216
-		foreach ( $items as $item ) {
217
-
218
-			// Create a dummy request.
219
-			$_item = new WP_REST_Request( 'PUT' );
220
-
221
-			// Add body params.
222
-			$_item->set_body_params( $item );
223
-
224
-			// Set query (GET) parameters.
225
-			$_item->set_query_params( $query );
226
-
227
-			// Update the item.
228
-			$_response = $this->update_item( $_item );
229
-
230
-			// If an error occured...
231
-			if ( is_wp_error( $_response ) ) {
232
-
233
-				$update[] = array(
234
-					'id'    => $item['id'],
235
-					'error' => array(
236
-						'code'    => $_response->get_error_code(),
237
-						'message' => $_response->get_error_message(),
238
-						'data'    => $_response->get_error_data(),
239
-					),
240
-				);
241
-
242
-				continue;
243
-
244
-			}
245
-
246
-			$update[] = $wp_rest_server->response_to_data( /** @scrutinizer ignore-type */ $_response, false );
247
-
248
-		}
249
-
250
-		return $update;
251
-
252
-	}
293
+            $delete[] = $wp_rest_server->response_to_data( /** @scrutinizer ignore-type */ $_response, false );
253 294
 
254
-	/**
255
-	 * Bulk delete items.
256
-	 *
257
-	 * @param array $items Array of items to delete.
258
-	 * @param WP_REST_Server $wp_rest_server
259
-	 * @return array()
260
-	 */
261
-	protected function batch_delete_items( $items, $wp_rest_server ) {
262
-
263
-		$delete = array();
264
-
265
-		foreach ( array_filter( $items ) as $id ) {
266
-
267
-			// Prepare the request.
268
-			$_item = new WP_REST_Request( 'DELETE' );
269
-			$_item->set_query_params(
270
-				array(
271
-					'id'    => $id,
272
-					'force' => true,
273
-				)
274
-			);
275
-
276
-			// Delete the item.
277
-			$_response = $this->delete_item( $_item );
278
-
279
-			if ( is_wp_error( $_response ) ) {
280
-
281
-				$delete[] = array(
282
-					'id'    => $id,
283
-					'error' => array(
284
-						'code'    => $_response->get_error_code(),
285
-						'message' => $_response->get_error_message(),
286
-						'data'    => $_response->get_error_data(),
287
-					),
288
-				);
289
-
290
-				continue;
291
-			}
292
-
293
-			$delete[] = $wp_rest_server->response_to_data( /** @scrutinizer ignore-type */ $_response, false );
294
-
295
-		}
296
-
297
-		return $delete;
298
-
299
-	}
300
-
301
-	/**
302
-	 * Bulk create, update and delete items.
303
-	 *
304
-	 * @param WP_REST_Request $request Full details about the request.
305
-	 * @return WP_Error|array.
306
-	 */
307
-	public function batch_items( $request ) {
308
-		global $wp_rest_server;
309
-
310
-		// Prepare the batch items.
311
-		$items = $this->fill_batch_keys( array_filter( $request->get_params() ) );
312
-
313
-		// Ensure that the batch has not exceeded the limit to prevent abuse.
314
-		$limit = $this->check_batch_limit( $items );
315
-		if ( is_wp_error( $limit ) ) {
316
-			return $limit;
317
-		}
318
-
319
-		// Process the items.
320
-		return array(
321
-			'create' => $this->batch_create_items( $items['create'], $request, $wp_rest_server ),
322
-			'update' => $this->batch_update_items( $items['update'], $request, $wp_rest_server ),
323
-			'delete' => $this->batch_delete_items( $items['delete'], $wp_rest_server ),
324
-		);
325
-
326
-	}
327
-
328
-	/**
329
-	 * Add meta query.
330
-	 *
331
-	 * @since 1.0.19
332
-	 * @param array $args       Query args.
333
-	 * @param array $meta_query Meta query.
334
-	 * @return array
335
-	 */
336
-	protected function add_meta_query( $args, $meta_query ) {
337
-		if ( empty( $args['meta_query'] ) ) {
338
-			$args['meta_query'] = array();
339
-		}
340
-
341
-		$args['meta_query'][] = $meta_query;
342
-
343
-		return $args['meta_query'];
344
-	}
345
-
346
-	/**
347
-	 * Get the batch schema, conforming to JSON Schema.
348
-	 *
349
-	 * @return array
350
-	 */
351
-	public function get_public_batch_schema() {
352
-
353
-		return array(
354
-			'$schema'    => 'http://json-schema.org/draft-04/schema#',
355
-			'title'      => 'batch',
356
-			'type'       => 'object',
357
-			'properties' => array(
358
-				'create' => array(
359
-					'description' => __( 'List of created resources.', 'invoicing' ),
360
-					'type'        => 'array',
361
-					'context'     => array( 'view', 'edit' ),
362
-					'items'       => array(
363
-						'type' => 'object',
364
-					),
365
-				),
366
-				'update' => array(
367
-					'description' => __( 'List of updated resources.', 'invoicing' ),
368
-					'type'        => 'array',
369
-					'context'     => array( 'view', 'edit' ),
370
-					'items'       => array(
371
-						'type' => 'object',
372
-					),
373
-				),
374
-				'delete' => array(
375
-					'description' => __( 'List of deleted resources.', 'invoicing' ),
376
-					'type'        => 'array',
377
-					'context'     => array( 'view', 'edit' ),
378
-					'items'       => array(
379
-						'type' => 'integer',
380
-					),
381
-				),
382
-			),
383
-		);
384
-
385
-	}
386
-
387
-	/**
388
-	 * Returns the value of schema['properties']
389
-	 *
390
-	 * i.e Schema fields.
391
-	 *
392
-	 * @since 1.0.19
393
-	 * @return array
394
-	 */
395
-	protected function get_schema_properties() {
396
-
397
-		$schema     = $this->get_item_schema();
398
-		$properties = isset( $schema['properties'] ) ? $schema['properties'] : array();
399
-
400
-		// For back-compat, include any field with an empty schema
401
-		// because it won't be present in $this->get_item_schema().
402
-		foreach ( $this->get_additional_fields() as $field_name => $field_options ) {
403
-			if ( is_null( $field_options['schema'] ) ) {
404
-				$properties[ $field_name ] = $field_options;
405
-			}
406
-		}
407
-
408
-		return $properties;
409
-	}
410
-
411
-	/**
412
-	 * Filters fields by context.
413
-	 *
414
-	 * @param array $fields Array of fields
415
-	 * @param string|null context view, edit or embed
416
-	 * @since 1.0.19
417
-	 * @return array
418
-	 */
419
-	protected function filter_response_fields_by_context( $fields, $context ) {
420
-
421
-		if ( empty( $context ) ) {
422
-			return $fields;
423
-		}
424
-
425
-		foreach ( $fields as $name => $options ) {
426
-			if ( ! empty( $options['context'] ) && ! in_array( $context, $options['context'], true ) ) {
427
-				unset( $fields[ $name ] );
428
-			}
429
-		}
430
-
431
-		return $fields;
432
-
433
-	}
434
-
435
-	/**
436
-	 * Filters fields by an array of requested fields.
437
-	 *
438
-	 * @param array $fields Array of available fields
439
-	 * @param array $requested array of requested fields.
440
-	 * @since 1.0.19
441
-	 * @return array
442
-	 */
443
-	protected function filter_response_fields_by_array( $fields, $requested ) {
444
-
445
-		// Trim off any whitespace from the list array.
446
-		$requested = array_map( 'trim', $requested );
447
-
448
-		// Always persist 'id', because it can be needed for add_additional_fields_to_object().
449
-		if ( in_array( 'id', $fields, true ) ) {
450
-			$requested[] = 'id';
451
-		}
452
-
453
-		// Get rid of duplicate fields.
454
-		$requested = array_unique( $requested );
455
-
456
-		// Return the list of all included fields which are available.
457
-		return array_reduce(
458
-			$requested,
459
-			function( $response_fields, $field ) use ( $fields ) {
460
-
461
-				if ( in_array( $field, $fields, true ) ) {
462
-					$response_fields[] = $field;
463
-					return $response_fields;
464
-				}
465
-
466
-				// Check for nested fields if $field is not a direct match.
467
-				$nested_fields = explode( '.', $field );
468
-
469
-				// A nested field is included so long as its top-level property is
470
-				// present in the schema.
471
-				if ( in_array( $nested_fields[0], $fields, true ) ) {
472
-					$response_fields[] = $field;
473
-				}
474
-
475
-				return $response_fields;
476
-			},
477
-			array()
478
-		);
479
-
480
-	}
481
-
482
-	/**
483
-	 * Gets an array of fields to be included on the response.
484
-	 *
485
-	 * Included fields are based on item schema and `_fields=` request argument.
486
-	 * Copied from WordPress 5.3 to support old versions.
487
-	 *
488
-	 * @since 1.0.19
489
-	 * @param WP_REST_Request $request Full details about the request.
490
-	 * @return array Fields to be included in the response.
491
-	 */
492
-	public function get_fields_for_response( $request ) {
493
-
494
-		// Retrieve fields in the schema.
495
-		$properties = $this->get_schema_properties();
496
-
497
-		// Exclude fields that specify a different context than the request context.
498
-		$properties = $this->filter_response_fields_by_context( $properties, $request['context'] );
499
-
500
-		// We only need the field keys.
501
-		$fields = array_keys( $properties );
502
-
503
-		// Is the user filtering the response fields??
504
-		if ( empty( $request['_fields'] ) ) {
505
-			return $fields;
506
-		}
507
-
508
-		return $this->filter_response_fields_by_array( $fields, wpinv_parse_list( $request['_fields'] ) );
509
-
510
-	}
511
-
512
-	/**
513
-	 * Limits an object to the requested fields.
514
-	 *
515
-	 * Included fields are based on the `_fields` request argument.
516
-	 *
517
-	 * @since 1.0.19
518
-	 * @param array $data Fields to include in the response.
519
-	 * @param array $fields Requested fields.
520
-	 * @return array Fields to be included in the response.
521
-	 */
522
-	public function limit_object_to_requested_fields( $data, $fields, $prefix = '' ) {
523
-
524
-		// Is the user filtering the response fields??
525
-		if ( empty( $fields ) ) {
526
-			return $data;
527
-		}
528
-
529
-		foreach ( $data as $key => $value ) {
530
-
531
-			// Numeric arrays.
532
-			if ( is_numeric( $key ) && is_array( $value ) ) {
533
-				$data[ $key ] = $this->limit_object_to_requested_fields( $value, $fields, $prefix );
534
-				continue;
535
-			}
536
-
537
-			// Generate a new prefix.
538
-			$new_prefix = empty( $prefix ) ? $key : "$prefix.$key";
539
-
540
-			// Check if it was requested.
541
-			if ( ! empty( $key ) && ! $this->is_field_included( $new_prefix, $fields ) ) {
542
-				unset( $data[ $key ] );
543
-				continue;
544
-			}
545
-
546
-			if ( $key != 'meta_data' && is_array( $value ) ) {
547
-				$data[ $key ] = $this->limit_object_to_requested_fields( $value, $fields, $new_prefix );
548
-			}
295
+        }
296
+
297
+        return $delete;
298
+
299
+    }
300
+
301
+    /**
302
+     * Bulk create, update and delete items.
303
+     *
304
+     * @param WP_REST_Request $request Full details about the request.
305
+     * @return WP_Error|array.
306
+     */
307
+    public function batch_items( $request ) {
308
+        global $wp_rest_server;
309
+
310
+        // Prepare the batch items.
311
+        $items = $this->fill_batch_keys( array_filter( $request->get_params() ) );
312
+
313
+        // Ensure that the batch has not exceeded the limit to prevent abuse.
314
+        $limit = $this->check_batch_limit( $items );
315
+        if ( is_wp_error( $limit ) ) {
316
+            return $limit;
317
+        }
318
+
319
+        // Process the items.
320
+        return array(
321
+            'create' => $this->batch_create_items( $items['create'], $request, $wp_rest_server ),
322
+            'update' => $this->batch_update_items( $items['update'], $request, $wp_rest_server ),
323
+            'delete' => $this->batch_delete_items( $items['delete'], $wp_rest_server ),
324
+        );
325
+
326
+    }
327
+
328
+    /**
329
+     * Add meta query.
330
+     *
331
+     * @since 1.0.19
332
+     * @param array $args       Query args.
333
+     * @param array $meta_query Meta query.
334
+     * @return array
335
+     */
336
+    protected function add_meta_query( $args, $meta_query ) {
337
+        if ( empty( $args['meta_query'] ) ) {
338
+            $args['meta_query'] = array();
339
+        }
340
+
341
+        $args['meta_query'][] = $meta_query;
342
+
343
+        return $args['meta_query'];
344
+    }
345
+
346
+    /**
347
+     * Get the batch schema, conforming to JSON Schema.
348
+     *
349
+     * @return array
350
+     */
351
+    public function get_public_batch_schema() {
352
+
353
+        return array(
354
+            '$schema'    => 'http://json-schema.org/draft-04/schema#',
355
+            'title'      => 'batch',
356
+            'type'       => 'object',
357
+            'properties' => array(
358
+                'create' => array(
359
+                    'description' => __( 'List of created resources.', 'invoicing' ),
360
+                    'type'        => 'array',
361
+                    'context'     => array( 'view', 'edit' ),
362
+                    'items'       => array(
363
+                        'type' => 'object',
364
+                    ),
365
+                ),
366
+                'update' => array(
367
+                    'description' => __( 'List of updated resources.', 'invoicing' ),
368
+                    'type'        => 'array',
369
+                    'context'     => array( 'view', 'edit' ),
370
+                    'items'       => array(
371
+                        'type' => 'object',
372
+                    ),
373
+                ),
374
+                'delete' => array(
375
+                    'description' => __( 'List of deleted resources.', 'invoicing' ),
376
+                    'type'        => 'array',
377
+                    'context'     => array( 'view', 'edit' ),
378
+                    'items'       => array(
379
+                        'type' => 'integer',
380
+                    ),
381
+                ),
382
+            ),
383
+        );
384
+
385
+    }
386
+
387
+    /**
388
+     * Returns the value of schema['properties']
389
+     *
390
+     * i.e Schema fields.
391
+     *
392
+     * @since 1.0.19
393
+     * @return array
394
+     */
395
+    protected function get_schema_properties() {
396
+
397
+        $schema     = $this->get_item_schema();
398
+        $properties = isset( $schema['properties'] ) ? $schema['properties'] : array();
399
+
400
+        // For back-compat, include any field with an empty schema
401
+        // because it won't be present in $this->get_item_schema().
402
+        foreach ( $this->get_additional_fields() as $field_name => $field_options ) {
403
+            if ( is_null( $field_options['schema'] ) ) {
404
+                $properties[ $field_name ] = $field_options;
405
+            }
406
+        }
407
+
408
+        return $properties;
409
+    }
410
+
411
+    /**
412
+     * Filters fields by context.
413
+     *
414
+     * @param array $fields Array of fields
415
+     * @param string|null context view, edit or embed
416
+     * @since 1.0.19
417
+     * @return array
418
+     */
419
+    protected function filter_response_fields_by_context( $fields, $context ) {
420
+
421
+        if ( empty( $context ) ) {
422
+            return $fields;
423
+        }
424
+
425
+        foreach ( $fields as $name => $options ) {
426
+            if ( ! empty( $options['context'] ) && ! in_array( $context, $options['context'], true ) ) {
427
+                unset( $fields[ $name ] );
428
+            }
429
+        }
430
+
431
+        return $fields;
432
+
433
+    }
434
+
435
+    /**
436
+     * Filters fields by an array of requested fields.
437
+     *
438
+     * @param array $fields Array of available fields
439
+     * @param array $requested array of requested fields.
440
+     * @since 1.0.19
441
+     * @return array
442
+     */
443
+    protected function filter_response_fields_by_array( $fields, $requested ) {
444
+
445
+        // Trim off any whitespace from the list array.
446
+        $requested = array_map( 'trim', $requested );
447
+
448
+        // Always persist 'id', because it can be needed for add_additional_fields_to_object().
449
+        if ( in_array( 'id', $fields, true ) ) {
450
+            $requested[] = 'id';
451
+        }
452
+
453
+        // Get rid of duplicate fields.
454
+        $requested = array_unique( $requested );
455
+
456
+        // Return the list of all included fields which are available.
457
+        return array_reduce(
458
+            $requested,
459
+            function( $response_fields, $field ) use ( $fields ) {
460
+
461
+                if ( in_array( $field, $fields, true ) ) {
462
+                    $response_fields[] = $field;
463
+                    return $response_fields;
464
+                }
465
+
466
+                // Check for nested fields if $field is not a direct match.
467
+                $nested_fields = explode( '.', $field );
468
+
469
+                // A nested field is included so long as its top-level property is
470
+                // present in the schema.
471
+                if ( in_array( $nested_fields[0], $fields, true ) ) {
472
+                    $response_fields[] = $field;
473
+                }
474
+
475
+                return $response_fields;
476
+            },
477
+            array()
478
+        );
479
+
480
+    }
481
+
482
+    /**
483
+     * Gets an array of fields to be included on the response.
484
+     *
485
+     * Included fields are based on item schema and `_fields=` request argument.
486
+     * Copied from WordPress 5.3 to support old versions.
487
+     *
488
+     * @since 1.0.19
489
+     * @param WP_REST_Request $request Full details about the request.
490
+     * @return array Fields to be included in the response.
491
+     */
492
+    public function get_fields_for_response( $request ) {
493
+
494
+        // Retrieve fields in the schema.
495
+        $properties = $this->get_schema_properties();
496
+
497
+        // Exclude fields that specify a different context than the request context.
498
+        $properties = $this->filter_response_fields_by_context( $properties, $request['context'] );
499
+
500
+        // We only need the field keys.
501
+        $fields = array_keys( $properties );
502
+
503
+        // Is the user filtering the response fields??
504
+        if ( empty( $request['_fields'] ) ) {
505
+            return $fields;
506
+        }
507
+
508
+        return $this->filter_response_fields_by_array( $fields, wpinv_parse_list( $request['_fields'] ) );
509
+
510
+    }
511
+
512
+    /**
513
+     * Limits an object to the requested fields.
514
+     *
515
+     * Included fields are based on the `_fields` request argument.
516
+     *
517
+     * @since 1.0.19
518
+     * @param array $data Fields to include in the response.
519
+     * @param array $fields Requested fields.
520
+     * @return array Fields to be included in the response.
521
+     */
522
+    public function limit_object_to_requested_fields( $data, $fields, $prefix = '' ) {
523
+
524
+        // Is the user filtering the response fields??
525
+        if ( empty( $fields ) ) {
526
+            return $data;
527
+        }
528
+
529
+        foreach ( $data as $key => $value ) {
530
+
531
+            // Numeric arrays.
532
+            if ( is_numeric( $key ) && is_array( $value ) ) {
533
+                $data[ $key ] = $this->limit_object_to_requested_fields( $value, $fields, $prefix );
534
+                continue;
535
+            }
536
+
537
+            // Generate a new prefix.
538
+            $new_prefix = empty( $prefix ) ? $key : "$prefix.$key";
539
+
540
+            // Check if it was requested.
541
+            if ( ! empty( $key ) && ! $this->is_field_included( $new_prefix, $fields ) ) {
542
+                unset( $data[ $key ] );
543
+                continue;
544
+            }
545
+
546
+            if ( $key != 'meta_data' && is_array( $value ) ) {
547
+                $data[ $key ] = $this->limit_object_to_requested_fields( $value, $fields, $new_prefix );
548
+            }
549 549
 }
550 550
 
551
-		return $data;
552
-	}
553
-
554
-	/**
555
-	 * Given an array of fields to include in a response, some of which may be
556
-	 * `nested.fields`, determine whether the provided field should be included
557
-	 * in the response body.
558
-	 *
559
-	 * Copied from WordPress 5.3 to support old versions.
560
-	 *
561
-	 * @since 1.0.19
562
-	 *
563
-	 * @param string $field  A field to test for inclusion in the response body.
564
-	 * @param array  $fields An array of string fields supported by the endpoint.
565
-	 * @return bool Whether to include the field or not.
566
-	 * @see rest_is_field_included()
567
-	 */
568
-	public function is_field_included( $field, $fields ) {
569
-		if ( in_array( $field, $fields, true ) ) {
570
-			return true;
571
-		}
572
-
573
-		foreach ( $fields as $accepted_field ) {
574
-			// Check to see if $field is the parent of any item in $fields.
575
-			// A field "parent" should be accepted if "parent.child" is accepted.
576
-			if ( strpos( $accepted_field, "$field." ) === 0 ) {
577
-				return true;
578
-			}
579
-			// Conversely, if "parent" is accepted, all "parent.child" fields
580
-			// should also be accepted.
581
-			if ( strpos( $field, "$accepted_field." ) === 0 ) {
582
-				return true;
583
-			}
584
-		}
585
-
586
-		return false;
587
-	}
551
+        return $data;
552
+    }
553
+
554
+    /**
555
+     * Given an array of fields to include in a response, some of which may be
556
+     * `nested.fields`, determine whether the provided field should be included
557
+     * in the response body.
558
+     *
559
+     * Copied from WordPress 5.3 to support old versions.
560
+     *
561
+     * @since 1.0.19
562
+     *
563
+     * @param string $field  A field to test for inclusion in the response body.
564
+     * @param array  $fields An array of string fields supported by the endpoint.
565
+     * @return bool Whether to include the field or not.
566
+     * @see rest_is_field_included()
567
+     */
568
+    public function is_field_included( $field, $fields ) {
569
+        if ( in_array( $field, $fields, true ) ) {
570
+            return true;
571
+        }
572
+
573
+        foreach ( $fields as $accepted_field ) {
574
+            // Check to see if $field is the parent of any item in $fields.
575
+            // A field "parent" should be accepted if "parent.child" is accepted.
576
+            if ( strpos( $accepted_field, "$field." ) === 0 ) {
577
+                return true;
578
+            }
579
+            // Conversely, if "parent" is accepted, all "parent.child" fields
580
+            // should also be accepted.
581
+            if ( strpos( $field, "$accepted_field." ) === 0 ) {
582
+                return true;
583
+            }
584
+        }
585
+
586
+        return false;
587
+    }
588 588
 
589 589
 }
Please login to merge, or discard this patch.