Passed
Push — master ( b57280...b80081 )
by Brian
09:26 queued 04:33
created
includes/admin/meta-boxes/class-mb-payment-form.php 1 patch
Spacing   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // MUST have WordPress.
3
-if ( !defined( 'WPINC' ) ) {
4
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
3
+if (!defined('WPINC')) {
4
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
5 5
 }
6 6
 
7 7
 class WPInv_Meta_Box_Payment_Form {
@@ -11,23 +11,23 @@  discard block
 block discarded – undo
11 11
      *
12 12
      * @param WP_Post $post
13 13
      */
14
-    public static function output_details( $post ) {
15
-        $details = get_post_meta( $post->ID, 'payment_form_data', true );
14
+    public static function output_details($post) {
15
+        $details = get_post_meta($post->ID, 'payment_form_data', true);
16 16
 
17
-        if ( ! is_array( $details ) ) {
17
+        if (!is_array($details)) {
18 18
             return;
19 19
         }
20 20
 
21 21
         echo '<div class="gdmbx2-wrap form-table"> <div class="gdmbx2-metabox gdmbx-field-list">';
22 22
 
23
-        foreach ( $details as $key => $value ) {
24
-            $key = sanitize_text_field( $key );
23
+        foreach ($details as $key => $value) {
24
+            $key = sanitize_text_field($key);
25 25
 
26
-            if ( is_array( $value ) ) {
27
-                $value = implode( ',', $value );
26
+            if (is_array($value)) {
27
+                $value = implode(',', $value);
28 28
             }
29 29
 
30
-            $value = esc_html( $value );
30
+            $value = esc_html($value);
31 31
 
32 32
             echo "<div class='gdmbx-row gdmbx-type-select'>";
33 33
             echo "<div class='gdmbx-th'><label>$key:</label></div>";
@@ -43,9 +43,9 @@  discard block
 block discarded – undo
43 43
      *
44 44
      * @param WP_Post $post
45 45
      */
46
-    public static function output_shortcode( $post ) {
46
+    public static function output_shortcode($post) {
47 47
 
48
-        if ( ! is_numeric( $post ) ) {
48
+        if (!is_numeric($post)) {
49 49
             $post = $post->ID;
50 50
         }
51 51
 
@@ -57,9 +57,9 @@  discard block
 block discarded – undo
57 57
      *
58 58
      * @param WP_Post $post
59 59
      */
60
-    public static function output ( $post ) {
61
-        $success_page        = get_post_meta( $post->ID, 'wpinv_success_page', true );
62
-        $success_page        = empty( $success_page ) ? wpinv_get_success_page_uri() : $success_page
60
+    public static function output($post) {
61
+        $success_page        = get_post_meta($post->ID, 'wpinv_success_page', true);
62
+        $success_page        = empty($success_page) ? wpinv_get_success_page_uri() : $success_page
63 63
         ?>
64 64
 
65 65
         <div id="wpinv-form-builder" style="display: flex; flex-flow: wrap;">
@@ -67,20 +67,20 @@  discard block
 block discarded – undo
67 67
             <div class="wpinv-form-builder-left bsui" style="flex: 0 0 320px;">
68 68
                 <ul class="wpinv-form-builder-tabs  nav nav-tabs">
69 69
                     <li class='nav-item' v-if="active_tab!='new_item'">
70
-                        <a @click.prevent="active_tab='new_item'" class="nav-link p-3" :class="{ 'active': active_tab=='new_item' }" href="#"><?php _e( 'Add new element', 'invoicing' ); ?></a>
70
+                        <a @click.prevent="active_tab='new_item'" class="nav-link p-3" :class="{ 'active': active_tab=='new_item' }" href="#"><?php _e('Add new element', 'invoicing'); ?></a>
71 71
                     </li>
72 72
                     <li class='nav-item' v-if='false'>
73
-                        <a @click.prevent="active_tab='edit_item'" class="nav-link p-3" :class="{ 'active': active_tab=='edit_item' }" href="#"><?php _e( 'Edit element', 'invoicing' ); ?></a>
73
+                        <a @click.prevent="active_tab='edit_item'" class="nav-link p-3" :class="{ 'active': active_tab=='edit_item' }" href="#"><?php _e('Edit element', 'invoicing'); ?></a>
74 74
                     </li>
75 75
                     <li class='nav-item' v-if='false'>
76
-                        <a @click.prevent="active_tab='settings'" class="nav-link p-3" :class="{ 'active': active_tab=='settings' }" href="#"><?php _e( 'Settings', 'invoicing' ); ?></a>
76
+                        <a @click.prevent="active_tab='settings'" class="nav-link p-3" :class="{ 'active': active_tab=='settings' }" href="#"><?php _e('Settings', 'invoicing'); ?></a>
77 77
                     </li>
78 78
                 </ul>
79 79
 
80 80
                 <div class="wpinv-form-builder-tab-content bsui" style="margin-top: 16px;">
81 81
                     <div class="wpinv-form-builder-tab-pane" v-if="active_tab=='new_item'">
82 82
                         <div class="wpinv-form-builder-add-field-types">
83
-                            <small class='form-text text-muted'><?php _e( 'Add an element by dragging it to the payment form.', 'invoicing' ); ?></small>
83
+                            <small class='form-text text-muted'><?php _e('Add an element by dragging it to the payment form.', 'invoicing'); ?></small>
84 84
                             <draggable class="section mt-2" style="display: flex; flex-flow: wrap; justify-content: space-between;" v-model="elements" :group="{ name: 'fields', pull: 'clone', put: false }" :sort="false" :clone="addDraggedField" tag="ul" filter=".wpinv-undraggable">
85 85
                                 <li v-for="element in elements" class= "wpinv-payment-form-left-fields-field" @click.prevent="addField(element)" :class="{ 'd-none': element.defaults.premade }">
86 86
                                     <button class="button btn">
@@ -95,9 +95,9 @@  discard block
 block discarded – undo
95 95
 
96 96
                     <div class="wpinv-form-builder-tab-pane bsui" v-if="active_tab=='edit_item'" style="font-size: 16px;">
97 97
                         <div class="wpinv-form-builder-edit-field-wrapper">
98
-                            <?php do_action( 'wpinv_payment_form_edit_element_template', 'active_form_element', $post ); ?>
98
+                            <?php do_action('wpinv_payment_form_edit_element_template', 'active_form_element', $post); ?>
99 99
                             <div>
100
-                                <button type="button" class="button button-link button-link-delete" @click.prevent="removeField(active_form_element)" v-show="! active_form_element.premade"><?php _e( 'Delete Field', 'invoicing' ); ?></button>
100
+                                <button type="button" class="button button-link button-link-delete" @click.prevent="removeField(active_form_element)" v-show="! active_form_element.premade"><?php _e('Delete Field', 'invoicing'); ?></button>
101 101
                             </div>
102 102
                         </div>
103 103
                     </div>
@@ -106,9 +106,9 @@  discard block
 block discarded – undo
106 106
                         <div class="wpinv-form-builder-settings-wrapper">
107 107
                         
108 108
                             <div class='form-group'>
109
-                                <label for="wpi-success-page"><?php _e( 'Success Page', 'invoicing' ); ?></label>
110
-                                <input  placeholder="https://" id='wpi-success-page' value="<?php echo esc_url( $success_page ); ?>" class='form-control' type='text'>
111
-                                <small class='form-text text-muted'><?php _e( 'Where should we redirect users after successfuly completing their payment?', 'invoicing' ); ?></small>
109
+                                <label for="wpi-success-page"><?php _e('Success Page', 'invoicing'); ?></label>
110
+                                <input  placeholder="https://" id='wpi-success-page' value="<?php echo esc_url($success_page); ?>" class='form-control' type='text'>
111
+                                <small class='form-text text-muted'><?php _e('Where should we redirect users after successfuly completing their payment?', 'invoicing'); ?></small>
112 112
                             </div>
113 113
 
114 114
                         </div>
@@ -119,12 +119,12 @@  discard block
 block discarded – undo
119 119
 
120 120
             <div class="wpinv-form-builder-right" style="flex: 1; padding-top: 40px;border-left: 1px solid #ddd;padding-left: 20px;min-height: 520px;margin-left: 10px;">
121 121
 
122
-                <small class='form-text text-muted' v-if='form_elements.length'><?php _e( 'Click on any element to edit or delete it.', 'invoicing' ); ?></small>
123
-                <p class='form-text text-muted' v-if='! form_elements.length'><?php _e( 'This form is empty. Add new elements by dragging them from the right.', 'invoicing' ); ?></p>
122
+                <small class='form-text text-muted' v-if='form_elements.length'><?php _e('Click on any element to edit or delete it.', 'invoicing'); ?></small>
123
+                <p class='form-text text-muted' v-if='! form_elements.length'><?php _e('This form is empty. Add new elements by dragging them from the right.', 'invoicing'); ?></p>
124 124
 
125 125
                 <draggable class="section bsui" v-model="form_elements" @add="highlightLastDroppedField" group="fields" tag="div" style="min-height: 100%; font-size: 16px;">
126 126
                     <div v-for="form_element in form_elements" class="wpinv-form-builder-element-preview" :class="{ active: active_form_element==form_element &&  active_tab=='edit_item' }" @click="active_tab = 'edit_item'; active_form_element = form_element">
127
-                        <?php do_action( 'wpinv_payment_form_render_element_template', 'form_element', $post ); ?>
127
+                        <?php do_action('wpinv_payment_form_render_element_template', 'form_element', $post); ?>
128 128
                     </div>
129 129
                 </draggable>
130 130
             </div>
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
             <textarea style="display:none;" name="wpinv_form_items" v-model="itemString"></textarea>
134 134
         </div>
135 135
         
136
-        <?php wp_nonce_field( 'wpinv_save_payment_form', 'wpinv_save_payment_form' ) ;?>
136
+        <?php wp_nonce_field('wpinv_save_payment_form', 'wpinv_save_payment_form'); ?>
137 137
 
138 138
         <?php
139 139
     }
@@ -141,83 +141,83 @@  discard block
 block discarded – undo
141 141
     /**
142 142
      * Saves our payment forms.
143 143
      */
144
-    public static function save( $post_id, $post ) {
144
+    public static function save($post_id, $post) {
145 145
 
146
-        remove_action( 'save_post', 'WPInv_Meta_Box_Payment_Form::save' );
146
+        remove_action('save_post', 'WPInv_Meta_Box_Payment_Form::save');
147 147
 
148 148
         // $post_id and $post are required.
149
-        if ( empty( $post_id ) || empty( $post ) ) {
149
+        if (empty($post_id) || empty($post)) {
150 150
             return;
151 151
         }
152 152
         
153 153
         // Ensure that this user can edit the post.
154
-        if ( ! current_user_can( 'edit_post', $post_id ) ) {
154
+        if (!current_user_can('edit_post', $post_id)) {
155 155
             return;
156 156
         }
157 157
 
158 158
         // Dont' save meta boxes for revisions or autosaves
159
-        if ( defined( 'DOING_AUTOSAVE' ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) {
159
+        if (defined('DOING_AUTOSAVE') || is_int(wp_is_post_revision($post)) || is_int(wp_is_post_autosave($post))) {
160 160
             return;
161 161
         }
162 162
 
163 163
         // Do not save for ajax requests.
164
-        if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) {
164
+        if ((defined('DOING_AJAX') && DOING_AJAX) || isset($_REQUEST['bulk_edit'])) {
165 165
             return;
166 166
         }
167 167
 
168 168
         // Confirm the security nonce.
169
-        if ( empty( $_POST['wpinv_save_payment_form'] ) || ! wp_verify_nonce( $_POST['wpinv_save_payment_form'], 'wpinv_save_payment_form' ) ) {
169
+        if (empty($_POST['wpinv_save_payment_form']) || !wp_verify_nonce($_POST['wpinv_save_payment_form'], 'wpinv_save_payment_form')) {
170 170
             return;
171 171
         }
172 172
 
173 173
         // Save form items.
174
-        $form_items = json_decode( wp_unslash( $_POST['wpinv_form_items'] ), true );
174
+        $form_items = json_decode(wp_unslash($_POST['wpinv_form_items']), true);
175 175
 
176
-        if ( empty( $form_items ) ) {
176
+        if (empty($form_items)) {
177 177
             $form_items = array();
178 178
         }
179 179
 
180
-        update_post_meta( $post_id, 'wpinv_form_items', self::maybe_save_items( $form_items ) );
180
+        update_post_meta($post_id, 'wpinv_form_items', self::maybe_save_items($form_items));
181 181
 
182 182
         // Save form elements.
183
-        $wpinv_form_elements = json_decode( wp_unslash( $_POST['wpinv_form_elements'] ), true );
184
-        if ( empty( $wpinv_form_elements ) ) {
183
+        $wpinv_form_elements = json_decode(wp_unslash($_POST['wpinv_form_elements']), true);
184
+        if (empty($wpinv_form_elements)) {
185 185
             $wpinv_form_elements = array();
186 186
         }
187 187
 
188
-        update_post_meta( $post_id, 'wpinv_form_elements', $wpinv_form_elements );
188
+        update_post_meta($post_id, 'wpinv_form_elements', $wpinv_form_elements);
189 189
     }
190 190
 
191 191
     /**
192 192
      * Saves unsaved form items.
193 193
      */
194
-    public static function maybe_save_items( $items ) {
194
+    public static function maybe_save_items($items) {
195 195
 
196 196
         $saved = array();
197 197
 
198
-        foreach( $items as $item ) {
198
+        foreach ($items as $item) {
199 199
 
200
-            if ( is_numeric( $item['id'] ) ) {
200
+            if (is_numeric($item['id'])) {
201 201
                 $saved[] = $item;
202 202
                 continue;
203 203
             }
204 204
 
205 205
             $data = array(
206
-                'post_title'   => sanitize_text_field( $item['title'] ),
207
-                'post_excerpt' => wp_kses_post( $item['description'] ),
206
+                'post_title'   => sanitize_text_field($item['title']),
207
+                'post_excerpt' => wp_kses_post($item['description']),
208 208
                 'post_status'  => 'publish',
209 209
                 'meta'         => array(
210 210
                     'type'      => 'custom',
211
-                    'price'     => wpinv_sanitize_amount( $item['price'] ),
211
+                    'price'     => wpinv_sanitize_amount($item['price']),
212 212
                     'vat_rule'  => 'digital',
213 213
                     'vat_class' => '_standard',
214 214
                 )
215 215
             );
216 216
             
217
-            $new_item  = new WPInv_Item();
218
-            $new_item->create( $data );
217
+            $new_item = new WPInv_Item();
218
+            $new_item->create($data);
219 219
     
220
-            if ( ! empty( $new_item ) ) {
220
+            if (!empty($new_item)) {
221 221
                 $item['id'] = $new_item->ID;
222 222
                 $saved[] = $item;
223 223
             }
@@ -230,5 +230,5 @@  discard block
 block discarded – undo
230 230
 
231 231
 }
232 232
 
233
-add_action( 'save_post_wpi_payment_form', 'WPInv_Meta_Box_Payment_Form::save', 10, 2 );
233
+add_action('save_post_wpi_payment_form', 'WPInv_Meta_Box_Payment_Form::save', 10, 2);
234 234
 
Please login to merge, or discard this patch.