@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | */ |
13 | 13 | |
14 | 14 | // Exit if accessed directly. |
15 | -if ( ! defined( 'ABSPATH' ) ) { |
|
15 | +if ( ! defined('ABSPATH')) { |
|
16 | 16 | exit; |
17 | 17 | } |
18 | 18 | |
@@ -41,20 +41,20 @@ discard block |
||
41 | 41 | public function csv_cols() { |
42 | 42 | |
43 | 43 | $cols = array( |
44 | - 'ID' => esc_html__( 'ID', 'give' ), |
|
45 | - 'post_name' => esc_html__( 'Slug', 'give' ), |
|
46 | - 'post_title' => esc_html__( 'Name', 'give' ), |
|
47 | - 'post_date' => esc_html__( 'Date Created', 'give' ), |
|
48 | - 'post_author' => esc_html__( 'Author', 'give' ), |
|
49 | - 'post_content' => esc_html__( 'Description', 'give' ), |
|
50 | - 'post_excerpt' => esc_html__( 'Excerpt', 'give' ), |
|
51 | - 'post_status' => esc_html__( 'Status', 'give' ), |
|
52 | - 'categories' => esc_html__( 'Categories', 'give' ), |
|
53 | - 'tags' => esc_html__( 'Tags', 'give' ), |
|
54 | - 'give_price' => esc_html__( 'Price', 'give' ), |
|
55 | - '_thumbnail_id' => esc_html__( 'Featured Image', 'give' ), |
|
56 | - '_give_form_sales' => esc_html__( 'Donations', 'give' ), |
|
57 | - '_give_download_earnings' => esc_html__( 'Income', 'give' ), |
|
44 | + 'ID' => esc_html__('ID', 'give'), |
|
45 | + 'post_name' => esc_html__('Slug', 'give'), |
|
46 | + 'post_title' => esc_html__('Name', 'give'), |
|
47 | + 'post_date' => esc_html__('Date Created', 'give'), |
|
48 | + 'post_author' => esc_html__('Author', 'give'), |
|
49 | + 'post_content' => esc_html__('Description', 'give'), |
|
50 | + 'post_excerpt' => esc_html__('Excerpt', 'give'), |
|
51 | + 'post_status' => esc_html__('Status', 'give'), |
|
52 | + 'categories' => esc_html__('Categories', 'give'), |
|
53 | + 'tags' => esc_html__('Tags', 'give'), |
|
54 | + 'give_price' => esc_html__('Price', 'give'), |
|
55 | + '_thumbnail_id' => esc_html__('Featured Image', 'give'), |
|
56 | + '_give_form_sales' => esc_html__('Donations', 'give'), |
|
57 | + '_give_download_earnings' => esc_html__('Income', 'give'), |
|
58 | 58 | ); |
59 | 59 | |
60 | 60 | return $cols; |
@@ -86,43 +86,43 @@ discard block |
||
86 | 86 | 'paged' => $this->step |
87 | 87 | ); |
88 | 88 | |
89 | - $downloads = new WP_Query( $args ); |
|
89 | + $downloads = new WP_Query($args); |
|
90 | 90 | |
91 | - if ( $downloads->posts ) { |
|
92 | - foreach ( $downloads->posts as $download ) { |
|
91 | + if ($downloads->posts) { |
|
92 | + foreach ($downloads->posts as $download) { |
|
93 | 93 | |
94 | 94 | $row = array(); |
95 | 95 | |
96 | - foreach ( $this->csv_cols() as $key => $value ) { |
|
96 | + foreach ($this->csv_cols() as $key => $value) { |
|
97 | 97 | |
98 | 98 | // Setup default value |
99 | - $row[ $key ] = ''; |
|
99 | + $row[$key] = ''; |
|
100 | 100 | |
101 | - if ( in_array( $key, $meta ) ) { |
|
101 | + if (in_array($key, $meta)) { |
|
102 | 102 | |
103 | - switch ( $key ) { |
|
103 | + switch ($key) { |
|
104 | 104 | |
105 | 105 | case '_thumbnail_id' : |
106 | 106 | |
107 | - $image_id = get_post_thumbnail_id( $download->ID ); |
|
108 | - $row[ $key ] = wp_get_attachment_url( $image_id ); |
|
107 | + $image_id = get_post_thumbnail_id($download->ID); |
|
108 | + $row[$key] = wp_get_attachment_url($image_id); |
|
109 | 109 | |
110 | 110 | break; |
111 | 111 | |
112 | 112 | case 'give_price' : |
113 | 113 | |
114 | - if ( give_has_variable_prices( $download->ID ) ) { |
|
114 | + if (give_has_variable_prices($download->ID)) { |
|
115 | 115 | |
116 | 116 | $prices = array(); |
117 | - foreach ( give_get_variable_prices( $download->ID ) as $price ) { |
|
118 | - $prices[] = $price['name'] . ': ' . $price['amount']; |
|
117 | + foreach (give_get_variable_prices($download->ID) as $price) { |
|
118 | + $prices[] = $price['name'].': '.$price['amount']; |
|
119 | 119 | } |
120 | 120 | |
121 | - $row[ $key ] = implode( ' | ', $prices ); |
|
121 | + $row[$key] = implode(' | ', $prices); |
|
122 | 122 | |
123 | 123 | } else { |
124 | 124 | |
125 | - $row[ $key ] = give_get_download_price( $download->ID ); |
|
125 | + $row[$key] = give_get_download_price($download->ID); |
|
126 | 126 | |
127 | 127 | } |
128 | 128 | |
@@ -132,54 +132,54 @@ discard block |
||
132 | 132 | |
133 | 133 | |
134 | 134 | $files = array(); |
135 | - foreach ( give_get_download_files( $download->ID ) as $file ) { |
|
135 | + foreach (give_get_download_files($download->ID) as $file) { |
|
136 | 136 | $files[] = $file['file']; |
137 | 137 | } |
138 | 138 | |
139 | - $row[ $key ] = implode( ' | ', $files ); |
|
139 | + $row[$key] = implode(' | ', $files); |
|
140 | 140 | |
141 | 141 | break; |
142 | 142 | |
143 | 143 | default : |
144 | 144 | |
145 | - $row[ $key ] = get_post_meta( $download->ID, $key, true ); |
|
145 | + $row[$key] = get_post_meta($download->ID, $key, true); |
|
146 | 146 | |
147 | 147 | break; |
148 | 148 | |
149 | 149 | } |
150 | 150 | |
151 | - } elseif ( isset( $download->$key ) ) { |
|
151 | + } elseif (isset($download->$key)) { |
|
152 | 152 | |
153 | - switch ( $key ) { |
|
153 | + switch ($key) { |
|
154 | 154 | |
155 | 155 | case 'post_author' : |
156 | 156 | |
157 | - $row[ $key ] = get_the_author_meta( 'user_login', $download->post_author ); |
|
157 | + $row[$key] = get_the_author_meta('user_login', $download->post_author); |
|
158 | 158 | |
159 | 159 | break; |
160 | 160 | |
161 | 161 | default : |
162 | 162 | |
163 | - $row[ $key ] = $download->$key; |
|
163 | + $row[$key] = $download->$key; |
|
164 | 164 | |
165 | 165 | break; |
166 | 166 | } |
167 | 167 | |
168 | - } elseif ( 'tags' == $key ) { |
|
168 | + } elseif ('tags' == $key) { |
|
169 | 169 | |
170 | - $terms = get_the_terms( $download->ID, 'download_tag' ); |
|
171 | - if ( $terms ) { |
|
172 | - $terms = wp_list_pluck( $terms, 'name' ); |
|
173 | - $row[ $key ] = implode( ' | ', $terms ); |
|
170 | + $terms = get_the_terms($download->ID, 'download_tag'); |
|
171 | + if ($terms) { |
|
172 | + $terms = wp_list_pluck($terms, 'name'); |
|
173 | + $row[$key] = implode(' | ', $terms); |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | |
177 | - } elseif ( 'categories' == $key ) { |
|
177 | + } elseif ('categories' == $key) { |
|
178 | 178 | |
179 | - $terms = get_the_terms( $download->ID, 'download_category' ); |
|
180 | - if ( $terms ) { |
|
181 | - $terms = wp_list_pluck( $terms, 'name' ); |
|
182 | - $row[ $key ] = implode( ' | ', $terms ); |
|
179 | + $terms = get_the_terms($download->ID, 'download_category'); |
|
180 | + if ($terms) { |
|
181 | + $terms = wp_list_pluck($terms, 'name'); |
|
182 | + $row[$key] = implode(' | ', $terms); |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | } |
@@ -190,8 +190,8 @@ discard block |
||
190 | 190 | |
191 | 191 | } |
192 | 192 | |
193 | - $data = apply_filters( 'give_export_get_data', $data ); |
|
194 | - $data = apply_filters( "give_export_get_data_{$this->export_type}", $data ); |
|
193 | + $data = apply_filters('give_export_get_data', $data); |
|
194 | + $data = apply_filters("give_export_get_data_{$this->export_type}", $data); |
|
195 | 195 | |
196 | 196 | return $data; |
197 | 197 | } |
@@ -210,20 +210,20 @@ discard block |
||
210 | 210 | |
211 | 211 | $args = array( |
212 | 212 | 'post_type' => 'give_forms', |
213 | - 'posts_per_page' => - 1, |
|
213 | + 'posts_per_page' => -1, |
|
214 | 214 | 'post_status' => 'any', |
215 | 215 | 'fields' => 'ids', |
216 | 216 | ); |
217 | 217 | |
218 | - $downloads = new WP_Query( $args ); |
|
218 | + $downloads = new WP_Query($args); |
|
219 | 219 | $total = (int) $downloads->post_count; |
220 | 220 | $percentage = 100; |
221 | 221 | |
222 | - if ( $total > 0 ) { |
|
223 | - $percentage = ( ( 30 * $this->step ) / $total ) * 100; |
|
222 | + if ($total > 0) { |
|
223 | + $percentage = ((30 * $this->step) / $total) * 100; |
|
224 | 224 | } |
225 | 225 | |
226 | - if ( $percentage > 100 ) { |
|
226 | + if ($percentage > 100) { |
|
227 | 227 | $percentage = 100; |
228 | 228 | } |
229 | 229 |
@@ -11,12 +11,12 @@ discard block |
||
11 | 11 | */ |
12 | 12 | |
13 | 13 | // Exit if accessed directly. |
14 | -if ( ! defined( 'ABSPATH' ) ) { |
|
14 | +if ( ! defined('ABSPATH')) { |
|
15 | 15 | exit; |
16 | 16 | } |
17 | 17 | |
18 | -require_once GIVE_PLUGIN_DIR . 'includes/admin/reporting/class-export.php'; |
|
19 | -require_once GIVE_PLUGIN_DIR . 'includes/admin/reporting/export/export-actions.php'; |
|
18 | +require_once GIVE_PLUGIN_DIR.'includes/admin/reporting/class-export.php'; |
|
19 | +require_once GIVE_PLUGIN_DIR.'includes/admin/reporting/export/export-actions.php'; |
|
20 | 20 | |
21 | 21 | /** |
22 | 22 | * Process batch exports via ajax |
@@ -26,14 +26,14 @@ discard block |
||
26 | 26 | */ |
27 | 27 | function give_do_ajax_export() { |
28 | 28 | |
29 | - require_once GIVE_PLUGIN_DIR . 'includes/admin/reporting/export/class-batch-export.php'; |
|
29 | + require_once GIVE_PLUGIN_DIR.'includes/admin/reporting/export/class-batch-export.php'; |
|
30 | 30 | |
31 | - parse_str( $_POST['form'], $form ); |
|
31 | + parse_str($_POST['form'], $form); |
|
32 | 32 | |
33 | 33 | $_REQUEST = $form = (array) $form; |
34 | 34 | |
35 | - if ( ! wp_verify_nonce( $_REQUEST['give_ajax_export'], 'give_ajax_export' ) ) { |
|
36 | - die( '-2' ); |
|
35 | + if ( ! wp_verify_nonce($_REQUEST['give_ajax_export'], 'give_ajax_export')) { |
|
36 | + die('-2'); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | /** |
@@ -43,69 +43,69 @@ discard block |
||
43 | 43 | * |
44 | 44 | * @param string $class Export class. |
45 | 45 | */ |
46 | - do_action( 'give_batch_export_class_include', $form['give-export-class'] ); |
|
46 | + do_action('give_batch_export_class_include', $form['give-export-class']); |
|
47 | 47 | |
48 | - $step = absint( $_POST['step'] ); |
|
49 | - $class = sanitize_text_field( $form['give-export-class'] ); |
|
48 | + $step = absint($_POST['step']); |
|
49 | + $class = sanitize_text_field($form['give-export-class']); |
|
50 | 50 | |
51 | - $export = new $class( $step ); |
|
51 | + $export = new $class($step); |
|
52 | 52 | |
53 | - if ( ! $export->can_export() ) { |
|
54 | - die( '-1' ); |
|
53 | + if ( ! $export->can_export()) { |
|
54 | + die('-1'); |
|
55 | 55 | } |
56 | 56 | |
57 | - if ( ! $export->is_writable ) { |
|
57 | + if ( ! $export->is_writable) { |
|
58 | 58 | $json_args = array( |
59 | 59 | 'error' => true, |
60 | - 'message' => esc_html__( 'Export location or file not writable.', 'give' ) |
|
60 | + 'message' => esc_html__('Export location or file not writable.', 'give') |
|
61 | 61 | ); |
62 | 62 | echo json_encode($json_args); |
63 | 63 | exit; |
64 | 64 | } |
65 | 65 | |
66 | - $export->set_properties( $_REQUEST ); |
|
66 | + $export->set_properties($_REQUEST); |
|
67 | 67 | |
68 | 68 | $export->pre_fetch(); |
69 | 69 | |
70 | - $ret = $export->process_step( $step ); |
|
70 | + $ret = $export->process_step($step); |
|
71 | 71 | |
72 | 72 | $percentage = $export->get_percentage_complete(); |
73 | 73 | |
74 | - if ( $ret ) { |
|
74 | + if ($ret) { |
|
75 | 75 | |
76 | 76 | $step += 1; |
77 | - echo json_encode( array( 'step' => $step, 'percentage' => $percentage ) ); |
|
77 | + echo json_encode(array('step' => $step, 'percentage' => $percentage)); |
|
78 | 78 | exit; |
79 | 79 | |
80 | - } elseif ( true === $export->is_empty ) { |
|
80 | + } elseif (true === $export->is_empty) { |
|
81 | 81 | |
82 | - echo json_encode( array( |
|
82 | + echo json_encode(array( |
|
83 | 83 | 'error' => true, |
84 | - 'message' => esc_html__( 'No data found for export parameters.', 'give' ) |
|
85 | - ) ); |
|
84 | + 'message' => esc_html__('No data found for export parameters.', 'give') |
|
85 | + )); |
|
86 | 86 | exit; |
87 | 87 | |
88 | - } elseif ( true === $export->done && true === $export->is_void ) { |
|
88 | + } elseif (true === $export->done && true === $export->is_void) { |
|
89 | 89 | |
90 | - $message = ! empty( $export->message ) ? $export->message : esc_html__( 'Batch Processing Complete', 'give' ); |
|
91 | - echo json_encode( array( 'success' => true, 'message' => $message ) ); |
|
90 | + $message = ! empty($export->message) ? $export->message : esc_html__('Batch Processing Complete', 'give'); |
|
91 | + echo json_encode(array('success' => true, 'message' => $message)); |
|
92 | 92 | exit; |
93 | 93 | |
94 | 94 | } else { |
95 | 95 | |
96 | - $args = array_merge( $_REQUEST, array( |
|
96 | + $args = array_merge($_REQUEST, array( |
|
97 | 97 | 'step' => $step, |
98 | 98 | 'class' => $class, |
99 | - 'nonce' => wp_create_nonce( 'give-batch-export' ), |
|
99 | + 'nonce' => wp_create_nonce('give-batch-export'), |
|
100 | 100 | 'give_action' => 'form_batch_export', |
101 | - ) ); |
|
101 | + )); |
|
102 | 102 | |
103 | - $download_url = add_query_arg( $args, admin_url() ); |
|
103 | + $download_url = add_query_arg($args, admin_url()); |
|
104 | 104 | |
105 | - echo json_encode( array( 'step' => 'done', 'url' => $download_url ) ); |
|
105 | + echo json_encode(array('step' => 'done', 'url' => $download_url)); |
|
106 | 106 | exit; |
107 | 107 | |
108 | 108 | } |
109 | 109 | } |
110 | 110 | |
111 | -add_action( 'wp_ajax_give_do_ajax_export', 'give_do_ajax_export' ); |
|
111 | +add_action('wp_ajax_give_do_ajax_export', 'give_do_ajax_export'); |
@@ -111,14 +111,14 @@ discard block |
||
111 | 111 | * @since 1.0 |
112 | 112 | * @access public |
113 | 113 | * |
114 | - * @param int $column Column ID. |
|
115 | - * @param int $row_id Row ID. |
|
116 | - * |
|
117 | - * @return object |
|
114 | + * @param int $column Column ID. |
|
115 | + * @param int $row_id Row ID. |
|
116 | + * |
|
117 | + * @return object |
|
118 | 118 | */ |
119 | 119 | public function get_by( $column, $row_id ) { |
120 | - /* @var WPDB $wpdb */ |
|
121 | - global $wpdb; |
|
120 | + /* @var WPDB $wpdb */ |
|
121 | + global $wpdb; |
|
122 | 122 | |
123 | 123 | $column = esc_sql( $column ); |
124 | 124 | return $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $this->table_name WHERE $column = %s LIMIT 1;", $row_id ) ); |
@@ -129,15 +129,15 @@ discard block |
||
129 | 129 | * |
130 | 130 | * @since 1.0 |
131 | 131 | * @access public |
132 | - * |
|
133 | - * @param int $column Column ID. |
|
134 | - * @param int $row_id Row ID. |
|
135 | - * |
|
132 | + * |
|
133 | + * @param int $column Column ID. |
|
134 | + * @param int $row_id Row ID. |
|
135 | + * |
|
136 | 136 | * @return string Column value. |
137 | 137 | */ |
138 | 138 | public function get_column( $column, $row_id ) { |
139 | - /* @var WPDB $wpdb */ |
|
140 | - global $wpdb; |
|
139 | + /* @var WPDB $wpdb */ |
|
140 | + global $wpdb; |
|
141 | 141 | |
142 | 142 | $column = esc_sql( $column ); |
143 | 143 | return $wpdb->get_var( $wpdb->prepare( "SELECT $column FROM $this->table_name WHERE $this->primary_key = %s LIMIT 1;", $row_id ) ); |
@@ -148,16 +148,16 @@ discard block |
||
148 | 148 | * |
149 | 149 | * @since 1.0 |
150 | 150 | * @access public |
151 | - * |
|
152 | - * @param int $column Column ID. |
|
153 | - * @param string $column_where Column name. |
|
154 | - * @param string $column_value Column value. |
|
155 | - * |
|
151 | + * |
|
152 | + * @param int $column Column ID. |
|
153 | + * @param string $column_where Column name. |
|
154 | + * @param string $column_value Column value. |
|
155 | + * |
|
156 | 156 | * @return string |
157 | 157 | */ |
158 | 158 | public function get_column_by( $column, $column_where, $column_value ) { |
159 | - /* @var WPDB $wpdb */ |
|
160 | - global $wpdb; |
|
159 | + /* @var WPDB $wpdb */ |
|
160 | + global $wpdb; |
|
161 | 161 | |
162 | 162 | $column_where = esc_sql( $column_where ); |
163 | 163 | $column = esc_sql( $column ); |
@@ -169,15 +169,15 @@ discard block |
||
169 | 169 | * |
170 | 170 | * @since 1.0 |
171 | 171 | * @access public |
172 | - * |
|
173 | - * @param array $data |
|
174 | - * @param string $type |
|
175 | - * |
|
172 | + * |
|
173 | + * @param array $data |
|
174 | + * @param string $type |
|
175 | + * |
|
176 | 176 | * @return int |
177 | 177 | */ |
178 | 178 | public function insert( $data, $type = '' ) { |
179 | - /* @var WPDB $wpdb */ |
|
180 | - global $wpdb; |
|
179 | + /* @var WPDB $wpdb */ |
|
180 | + global $wpdb; |
|
181 | 181 | |
182 | 182 | // Set default values. |
183 | 183 | $data = wp_parse_args( $data, $this->get_column_defaults() ); |
@@ -224,16 +224,16 @@ discard block |
||
224 | 224 | * |
225 | 225 | * @since 1.0 |
226 | 226 | * @access public |
227 | - * |
|
228 | - * @param int $row_id Column ID |
|
229 | - * @param array $data |
|
230 | - * @param string $where Column value |
|
231 | - * |
|
227 | + * |
|
228 | + * @param int $row_id Column ID |
|
229 | + * @param array $data |
|
230 | + * @param string $where Column value |
|
231 | + * |
|
232 | 232 | * @return bool |
233 | 233 | */ |
234 | 234 | public function update( $row_id, $data = array(), $where = '' ) { |
235 | - /* @var WPDB $wpdb */ |
|
236 | - global $wpdb; |
|
235 | + /* @var WPDB $wpdb */ |
|
236 | + global $wpdb; |
|
237 | 237 | |
238 | 238 | // Row ID must be positive integer |
239 | 239 | $row_id = absint( $row_id ); |
@@ -271,14 +271,14 @@ discard block |
||
271 | 271 | * |
272 | 272 | * @since 1.0 |
273 | 273 | * @access public |
274 | - * |
|
275 | - * @param int $row_id Column ID. |
|
276 | - * |
|
274 | + * |
|
275 | + * @param int $row_id Column ID. |
|
276 | + * |
|
277 | 277 | * @return bool |
278 | 278 | */ |
279 | 279 | public function delete( $row_id = 0 ) { |
280 | - /* @var WPDB $wpdb */ |
|
281 | - global $wpdb; |
|
280 | + /* @var WPDB $wpdb */ |
|
281 | + global $wpdb; |
|
282 | 282 | |
283 | 283 | // Row ID must be positive integer |
284 | 284 | $row_id = absint( $row_id ); |
@@ -299,13 +299,13 @@ discard block |
||
299 | 299 | * |
300 | 300 | * @since 1.3.2 |
301 | 301 | * @access public |
302 | - * |
|
302 | + * |
|
303 | 303 | * @param string $table The table name. |
304 | - * |
|
304 | + * |
|
305 | 305 | * @return bool If the table name exists. |
306 | 306 | */ |
307 | 307 | public function table_exists( $table ) { |
308 | - /* @var WPDB $wpdb */ |
|
308 | + /* @var WPDB $wpdb */ |
|
309 | 309 | global $wpdb; |
310 | 310 | |
311 | 311 | $table = sanitize_text_field( $table ); |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | */ |
11 | 11 | |
12 | 12 | // Exit if accessed directly. |
13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
13 | +if ( ! defined('ABSPATH')) { |
|
14 | 14 | exit; |
15 | 15 | } |
16 | 16 | |
@@ -98,11 +98,11 @@ discard block |
||
98 | 98 | * |
99 | 99 | * @return object |
100 | 100 | */ |
101 | - public function get( $row_id ) { |
|
101 | + public function get($row_id) { |
|
102 | 102 | /* @var WPDB $wpdb */ |
103 | 103 | global $wpdb; |
104 | 104 | |
105 | - return $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $this->table_name WHERE $this->primary_key = %s LIMIT 1;", $row_id ) ); |
|
105 | + return $wpdb->get_row($wpdb->prepare("SELECT * FROM $this->table_name WHERE $this->primary_key = %s LIMIT 1;", $row_id)); |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | /** |
@@ -116,12 +116,12 @@ discard block |
||
116 | 116 | * |
117 | 117 | * @return object |
118 | 118 | */ |
119 | - public function get_by( $column, $row_id ) { |
|
119 | + public function get_by($column, $row_id) { |
|
120 | 120 | /* @var WPDB $wpdb */ |
121 | 121 | global $wpdb; |
122 | 122 | |
123 | - $column = esc_sql( $column ); |
|
124 | - return $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $this->table_name WHERE $column = %s LIMIT 1;", $row_id ) ); |
|
123 | + $column = esc_sql($column); |
|
124 | + return $wpdb->get_row($wpdb->prepare("SELECT * FROM $this->table_name WHERE $column = %s LIMIT 1;", $row_id)); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
@@ -135,12 +135,12 @@ discard block |
||
135 | 135 | * |
136 | 136 | * @return string Column value. |
137 | 137 | */ |
138 | - public function get_column( $column, $row_id ) { |
|
138 | + public function get_column($column, $row_id) { |
|
139 | 139 | /* @var WPDB $wpdb */ |
140 | 140 | global $wpdb; |
141 | 141 | |
142 | - $column = esc_sql( $column ); |
|
143 | - return $wpdb->get_var( $wpdb->prepare( "SELECT $column FROM $this->table_name WHERE $this->primary_key = %s LIMIT 1;", $row_id ) ); |
|
142 | + $column = esc_sql($column); |
|
143 | + return $wpdb->get_var($wpdb->prepare("SELECT $column FROM $this->table_name WHERE $this->primary_key = %s LIMIT 1;", $row_id)); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
@@ -155,13 +155,13 @@ discard block |
||
155 | 155 | * |
156 | 156 | * @return string |
157 | 157 | */ |
158 | - public function get_column_by( $column, $column_where, $column_value ) { |
|
158 | + public function get_column_by($column, $column_where, $column_value) { |
|
159 | 159 | /* @var WPDB $wpdb */ |
160 | 160 | global $wpdb; |
161 | 161 | |
162 | - $column_where = esc_sql( $column_where ); |
|
163 | - $column = esc_sql( $column ); |
|
164 | - return $wpdb->get_var( $wpdb->prepare( "SELECT $column FROM $this->table_name WHERE $column_where = %s LIMIT 1;", $column_value ) ); |
|
162 | + $column_where = esc_sql($column_where); |
|
163 | + $column = esc_sql($column); |
|
164 | + return $wpdb->get_var($wpdb->prepare("SELECT $column FROM $this->table_name WHERE $column_where = %s LIMIT 1;", $column_value)); |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | /** |
@@ -175,12 +175,12 @@ discard block |
||
175 | 175 | * |
176 | 176 | * @return int |
177 | 177 | */ |
178 | - public function insert( $data, $type = '' ) { |
|
178 | + public function insert($data, $type = '') { |
|
179 | 179 | /* @var WPDB $wpdb */ |
180 | 180 | global $wpdb; |
181 | 181 | |
182 | 182 | // Set default values. |
183 | - $data = wp_parse_args( $data, $this->get_column_defaults() ); |
|
183 | + $data = wp_parse_args($data, $this->get_column_defaults()); |
|
184 | 184 | |
185 | 185 | /** |
186 | 186 | * Fires before inserting data to the database. |
@@ -189,22 +189,22 @@ discard block |
||
189 | 189 | * |
190 | 190 | * @param array $data |
191 | 191 | */ |
192 | - do_action( "give_pre_insert_{$type}", $data ); |
|
192 | + do_action("give_pre_insert_{$type}", $data); |
|
193 | 193 | |
194 | 194 | // Initialise column format array |
195 | 195 | $column_formats = $this->get_columns(); |
196 | 196 | |
197 | 197 | // Force fields to lower case |
198 | - $data = array_change_key_case( $data ); |
|
198 | + $data = array_change_key_case($data); |
|
199 | 199 | |
200 | 200 | // White list columns |
201 | - $data = array_intersect_key( $data, $column_formats ); |
|
201 | + $data = array_intersect_key($data, $column_formats); |
|
202 | 202 | |
203 | 203 | // Reorder $column_formats to match the order of columns given in $data |
204 | - $data_keys = array_keys( $data ); |
|
205 | - $column_formats = array_merge( array_flip( $data_keys ), $column_formats ); |
|
204 | + $data_keys = array_keys($data); |
|
205 | + $column_formats = array_merge(array_flip($data_keys), $column_formats); |
|
206 | 206 | |
207 | - $wpdb->insert( $this->table_name, $data, $column_formats ); |
|
207 | + $wpdb->insert($this->table_name, $data, $column_formats); |
|
208 | 208 | |
209 | 209 | /** |
210 | 210 | * Fires after inserting data to the database. |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | * @param int $insert_id |
215 | 215 | * @param array $data |
216 | 216 | */ |
217 | - do_action( "give_post_insert_{$type}", $wpdb->insert_id, $data ); |
|
217 | + do_action("give_post_insert_{$type}", $wpdb->insert_id, $data); |
|
218 | 218 | |
219 | 219 | return $wpdb->insert_id; |
220 | 220 | } |
@@ -231,18 +231,18 @@ discard block |
||
231 | 231 | * |
232 | 232 | * @return bool |
233 | 233 | */ |
234 | - public function update( $row_id, $data = array(), $where = '' ) { |
|
234 | + public function update($row_id, $data = array(), $where = '') { |
|
235 | 235 | /* @var WPDB $wpdb */ |
236 | 236 | global $wpdb; |
237 | 237 | |
238 | 238 | // Row ID must be positive integer |
239 | - $row_id = absint( $row_id ); |
|
239 | + $row_id = absint($row_id); |
|
240 | 240 | |
241 | - if ( empty( $row_id ) ) { |
|
241 | + if (empty($row_id)) { |
|
242 | 242 | return false; |
243 | 243 | } |
244 | 244 | |
245 | - if ( empty( $where ) ) { |
|
245 | + if (empty($where)) { |
|
246 | 246 | $where = $this->primary_key; |
247 | 247 | } |
248 | 248 | |
@@ -250,16 +250,16 @@ discard block |
||
250 | 250 | $column_formats = $this->get_columns(); |
251 | 251 | |
252 | 252 | // Force fields to lower case |
253 | - $data = array_change_key_case( $data ); |
|
253 | + $data = array_change_key_case($data); |
|
254 | 254 | |
255 | 255 | // White list columns |
256 | - $data = array_intersect_key( $data, $column_formats ); |
|
256 | + $data = array_intersect_key($data, $column_formats); |
|
257 | 257 | |
258 | 258 | // Reorder $column_formats to match the order of columns given in $data |
259 | - $data_keys = array_keys( $data ); |
|
260 | - $column_formats = array_merge( array_flip( $data_keys ), $column_formats ); |
|
259 | + $data_keys = array_keys($data); |
|
260 | + $column_formats = array_merge(array_flip($data_keys), $column_formats); |
|
261 | 261 | |
262 | - if ( false === $wpdb->update( $this->table_name, $data, array( $where => $row_id ), $column_formats ) ) { |
|
262 | + if (false === $wpdb->update($this->table_name, $data, array($where => $row_id), $column_formats)) { |
|
263 | 263 | return false; |
264 | 264 | } |
265 | 265 | |
@@ -276,18 +276,18 @@ discard block |
||
276 | 276 | * |
277 | 277 | * @return bool |
278 | 278 | */ |
279 | - public function delete( $row_id = 0 ) { |
|
279 | + public function delete($row_id = 0) { |
|
280 | 280 | /* @var WPDB $wpdb */ |
281 | 281 | global $wpdb; |
282 | 282 | |
283 | 283 | // Row ID must be positive integer |
284 | - $row_id = absint( $row_id ); |
|
284 | + $row_id = absint($row_id); |
|
285 | 285 | |
286 | - if ( empty( $row_id ) ) { |
|
286 | + if (empty($row_id)) { |
|
287 | 287 | return false; |
288 | 288 | } |
289 | 289 | |
290 | - if ( false === $wpdb->query( $wpdb->prepare( "DELETE FROM $this->table_name WHERE $this->primary_key = %d", $row_id ) ) ) { |
|
290 | + if (false === $wpdb->query($wpdb->prepare("DELETE FROM $this->table_name WHERE $this->primary_key = %d", $row_id))) { |
|
291 | 291 | return false; |
292 | 292 | } |
293 | 293 | |
@@ -304,13 +304,13 @@ discard block |
||
304 | 304 | * |
305 | 305 | * @return bool If the table name exists. |
306 | 306 | */ |
307 | - public function table_exists( $table ) { |
|
307 | + public function table_exists($table) { |
|
308 | 308 | /* @var WPDB $wpdb */ |
309 | 309 | global $wpdb; |
310 | 310 | |
311 | - $table = sanitize_text_field( $table ); |
|
311 | + $table = sanitize_text_field($table); |
|
312 | 312 | |
313 | - return $wpdb->get_var( $wpdb->prepare( "SHOW TABLES LIKE '%s'", $table ) ) === $table; |
|
313 | + return $wpdb->get_var($wpdb->prepare("SHOW TABLES LIKE '%s'", $table)) === $table; |
|
314 | 314 | } |
315 | 315 | |
316 | 316 | /** |
@@ -322,7 +322,7 @@ discard block |
||
322 | 322 | * @return bool Returns if the customers table was installed and upgrade routine run. |
323 | 323 | */ |
324 | 324 | public function installed() { |
325 | - return $this->table_exists( $this->table_name ); |
|
325 | + return $this->table_exists($this->table_name); |
|
326 | 326 | } |
327 | 327 | |
328 | 328 | } |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | */ |
11 | 11 | |
12 | 12 | // Exit if accessed directly. |
13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
13 | +if ( ! defined('ABSPATH')) { |
|
14 | 14 | exit; |
15 | 15 | } |
16 | 16 | |
@@ -62,50 +62,50 @@ discard block |
||
62 | 62 | * |
63 | 63 | * @return bool If the gravatar exists or not |
64 | 64 | */ |
65 | - public function validate_gravatar( $id_or_email ) { |
|
65 | + public function validate_gravatar($id_or_email) { |
|
66 | 66 | //id or email code borrowed from wp-includes/pluggable.php |
67 | 67 | $email = ''; |
68 | - if ( is_numeric( $id_or_email ) ) { |
|
68 | + if (is_numeric($id_or_email)) { |
|
69 | 69 | $id = (int) $id_or_email; |
70 | - $user = get_userdata( $id ); |
|
71 | - if ( $user ) { |
|
70 | + $user = get_userdata($id); |
|
71 | + if ($user) { |
|
72 | 72 | $email = $user->user_email; |
73 | 73 | } |
74 | - } elseif ( is_object( $id_or_email ) ) { |
|
74 | + } elseif (is_object($id_or_email)) { |
|
75 | 75 | // No avatar for pingbacks or trackbacks |
76 | - $allowed_comment_types = apply_filters( 'get_avatar_comment_types', array( 'comment' ) ); |
|
77 | - if ( ! empty( $id_or_email->comment_type ) && ! in_array( $id_or_email->comment_type, (array) $allowed_comment_types ) ) { |
|
76 | + $allowed_comment_types = apply_filters('get_avatar_comment_types', array('comment')); |
|
77 | + if ( ! empty($id_or_email->comment_type) && ! in_array($id_or_email->comment_type, (array) $allowed_comment_types)) { |
|
78 | 78 | return false; |
79 | 79 | } |
80 | 80 | |
81 | - if ( ! empty( $id_or_email->user_id ) ) { |
|
81 | + if ( ! empty($id_or_email->user_id)) { |
|
82 | 82 | $id = (int) $id_or_email->user_id; |
83 | - $user = get_userdata( $id ); |
|
84 | - if ( $user ) { |
|
83 | + $user = get_userdata($id); |
|
84 | + if ($user) { |
|
85 | 85 | $email = $user->user_email; |
86 | 86 | } |
87 | - } elseif ( ! empty( $id_or_email->comment_author_email ) ) { |
|
87 | + } elseif ( ! empty($id_or_email->comment_author_email)) { |
|
88 | 88 | $email = $id_or_email->comment_author_email; |
89 | 89 | } |
90 | 90 | } else { |
91 | 91 | $email = $id_or_email; |
92 | 92 | } |
93 | 93 | |
94 | - $hashkey = md5( strtolower( trim( $email ) ) ); |
|
95 | - $uri = 'http://www.gravatar.com/avatar/' . $hashkey . '?d=404'; |
|
94 | + $hashkey = md5(strtolower(trim($email))); |
|
95 | + $uri = 'http://www.gravatar.com/avatar/'.$hashkey.'?d=404'; |
|
96 | 96 | |
97 | - $data = wp_cache_get( $hashkey ); |
|
98 | - if ( false === $data ) { |
|
99 | - $response = wp_remote_head( $uri ); |
|
100 | - if ( is_wp_error( $response ) ) { |
|
97 | + $data = wp_cache_get($hashkey); |
|
98 | + if (false === $data) { |
|
99 | + $response = wp_remote_head($uri); |
|
100 | + if (is_wp_error($response)) { |
|
101 | 101 | $data = 'not200'; |
102 | 102 | } else { |
103 | 103 | $data = $response['response']['code']; |
104 | 104 | } |
105 | - wp_cache_set( $hashkey, $data, $group = '', $expire = 60 * 5 ); |
|
105 | + wp_cache_set($hashkey, $data, $group = '', $expire = 60 * 5); |
|
106 | 106 | |
107 | 107 | } |
108 | - if ( $data == '200' ) { |
|
108 | + if ($data == '200') { |
|
109 | 109 | return true; |
110 | 110 | } else { |
111 | 111 | return false; |
@@ -122,19 +122,19 @@ discard block |
||
122 | 122 | * |
123 | 123 | * @return array IDs if logs, false otherwise |
124 | 124 | */ |
125 | - public function get_log_ids( $form_id = '' ) { |
|
125 | + public function get_log_ids($form_id = '') { |
|
126 | 126 | |
127 | 127 | // get Give_Logging class |
128 | 128 | global $give_logs; |
129 | 129 | |
130 | 130 | // get log for this form |
131 | - $logs = $give_logs->get_logs( $form_id ); |
|
131 | + $logs = $give_logs->get_logs($form_id); |
|
132 | 132 | |
133 | - if ( $logs ) { |
|
133 | + if ($logs) { |
|
134 | 134 | $log_ids = array(); |
135 | 135 | |
136 | 136 | // make an array with all the donor IDs |
137 | - foreach ( $logs as $log ) { |
|
137 | + foreach ($logs as $log) { |
|
138 | 138 | $log_ids[] = $log->ID; |
139 | 139 | } |
140 | 140 | |
@@ -155,51 +155,51 @@ discard block |
||
155 | 155 | * |
156 | 156 | * @return mixed |
157 | 157 | */ |
158 | - public function get_payment_ids( $form_id = '' ) { |
|
158 | + public function get_payment_ids($form_id = '') { |
|
159 | 159 | |
160 | 160 | $give_options = give_get_settings(); |
161 | 161 | |
162 | - $log_ids = $this->get_log_ids( $form_id ); |
|
162 | + $log_ids = $this->get_log_ids($form_id); |
|
163 | 163 | |
164 | - if ( $log_ids ) { |
|
164 | + if ($log_ids) { |
|
165 | 165 | |
166 | 166 | $payment_ids = array(); |
167 | 167 | |
168 | - foreach ( $log_ids as $id ) { |
|
168 | + foreach ($log_ids as $id) { |
|
169 | 169 | // get the payment ID for each corresponding log ID |
170 | - $payment_ids[] = get_post_meta( $id, '_give_log_payment_id', true ); |
|
170 | + $payment_ids[] = get_post_meta($id, '_give_log_payment_id', true); |
|
171 | 171 | } |
172 | 172 | |
173 | 173 | // remove donors who have donated more than once so we can have unique avatars |
174 | 174 | $unique_emails = array(); |
175 | 175 | |
176 | - foreach ( $payment_ids as $key => $id ) { |
|
176 | + foreach ($payment_ids as $key => $id) { |
|
177 | 177 | |
178 | - $email = get_post_meta( $id, '_give_payment_user_email', true ); |
|
178 | + $email = get_post_meta($id, '_give_payment_user_email', true); |
|
179 | 179 | |
180 | - if ( isset ( $give_options['give_donors_gravatars_has_gravatar_account'] ) ) { |
|
181 | - if ( ! $this->validate_gravatar( $email ) ) { |
|
180 | + if (isset ($give_options['give_donors_gravatars_has_gravatar_account'])) { |
|
181 | + if ( ! $this->validate_gravatar($email)) { |
|
182 | 182 | continue; |
183 | 183 | } |
184 | 184 | } |
185 | 185 | |
186 | - $unique_emails[ $id ] = get_post_meta( $id, '_give_payment_user_email', true ); |
|
186 | + $unique_emails[$id] = get_post_meta($id, '_give_payment_user_email', true); |
|
187 | 187 | |
188 | 188 | } |
189 | 189 | |
190 | 190 | $unique_ids = array(); |
191 | 191 | |
192 | 192 | // strip duplicate emails |
193 | - $unique_emails = array_unique( $unique_emails ); |
|
193 | + $unique_emails = array_unique($unique_emails); |
|
194 | 194 | |
195 | 195 | // convert the unique IDs back into simple array |
196 | - foreach ( $unique_emails as $id => $email ) { |
|
196 | + foreach ($unique_emails as $id => $email) { |
|
197 | 197 | $unique_ids[] = $id; |
198 | 198 | } |
199 | 199 | |
200 | 200 | // randomize the payment IDs if enabled |
201 | - if ( isset( $give_options['give_donors_gravatars_random_gravatars'] ) ) { |
|
202 | - shuffle( $unique_ids ); |
|
201 | + if (isset($give_options['give_donors_gravatars_random_gravatars'])) { |
|
202 | + shuffle($unique_ids); |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | // return our unique IDs |
@@ -220,22 +220,22 @@ discard block |
||
220 | 220 | * |
221 | 221 | * @return string |
222 | 222 | */ |
223 | - public function gravatars( $form_id = false, $title = '' ) { |
|
223 | + public function gravatars($form_id = false, $title = '') { |
|
224 | 224 | |
225 | 225 | // unique $payment_ids |
226 | - $payment_ids = $this->get_payment_ids( $form_id ); |
|
226 | + $payment_ids = $this->get_payment_ids($form_id); |
|
227 | 227 | |
228 | 228 | $give_options = give_get_settings(); |
229 | 229 | |
230 | 230 | // return if no ID |
231 | - if ( ! $form_id ) { |
|
231 | + if ( ! $form_id) { |
|
232 | 232 | return; |
233 | 233 | } |
234 | 234 | |
235 | 235 | // minimum amount of donations before showing gravatars |
236 | 236 | // if the number of items in array is not greater or equal to the number specified, then exit |
237 | - if ( isset( $give_options['give_donors_gravatars_min_purchases_required'] ) && '' != $give_options['give_donors_gravatars_min_purchases_required'] ) { |
|
238 | - if ( ! ( count( $payment_ids ) >= $give_options['give_donors_gravatars_min_purchases_required'] ) ) { |
|
237 | + if (isset($give_options['give_donors_gravatars_min_purchases_required']) && '' != $give_options['give_donors_gravatars_min_purchases_required']) { |
|
238 | + if ( ! (count($payment_ids) >= $give_options['give_donors_gravatars_min_purchases_required'])) { |
|
239 | 239 | return; |
240 | 240 | } |
241 | 241 | } |
@@ -246,51 +246,51 @@ discard block |
||
246 | 246 | echo '<div id="give-purchase-gravatars">'; |
247 | 247 | |
248 | 248 | |
249 | - if ( isset ( $title ) ) { |
|
249 | + if (isset ($title)) { |
|
250 | 250 | |
251 | - if ( $title ) { |
|
252 | - echo apply_filters( 'give_donors_gravatars_title', '<h3 class="give-gravatars-title">' . esc_attr( $title ) . '</h3>' ); |
|
253 | - } elseif ( isset( $give_options['give_donors_gravatars_heading'] ) ) { |
|
254 | - echo apply_filters( 'give_donors_gravatars_title', '<h3 class="give-gravatars-title">' . esc_attr( $give_options['give_donors_gravatars_heading'] ) . '</h2>' ); |
|
251 | + if ($title) { |
|
252 | + echo apply_filters('give_donors_gravatars_title', '<h3 class="give-gravatars-title">'.esc_attr($title).'</h3>'); |
|
253 | + } elseif (isset($give_options['give_donors_gravatars_heading'])) { |
|
254 | + echo apply_filters('give_donors_gravatars_title', '<h3 class="give-gravatars-title">'.esc_attr($give_options['give_donors_gravatars_heading']).'</h2>'); |
|
255 | 255 | } |
256 | 256 | |
257 | 257 | } |
258 | 258 | echo '<ul class="give-purchase-gravatars-list">'; |
259 | 259 | $i = 0; |
260 | 260 | |
261 | - if ( $payment_ids ) { |
|
262 | - foreach ( $payment_ids as $id ) { |
|
261 | + if ($payment_ids) { |
|
262 | + foreach ($payment_ids as $id) { |
|
263 | 263 | |
264 | 264 | // Give saves a blank option even when the control is turned off, hence the extra check |
265 | - if ( isset( $give_options['give_donors_gravatars_maximum_number'] ) && '' != $give_options['give_donors_gravatars_maximum_number'] && $i == $give_options['give_donors_gravatars_maximum_number'] ) { |
|
265 | + if (isset($give_options['give_donors_gravatars_maximum_number']) && '' != $give_options['give_donors_gravatars_maximum_number'] && $i == $give_options['give_donors_gravatars_maximum_number']) { |
|
266 | 266 | continue; |
267 | 267 | } |
268 | 268 | |
269 | 269 | // get the payment meta |
270 | - $payment_meta = get_post_meta( $id, '_give_payment_meta', true ); |
|
270 | + $payment_meta = get_post_meta($id, '_give_payment_meta', true); |
|
271 | 271 | |
272 | 272 | // unserialize the payment meta |
273 | - $user_info = maybe_unserialize( $payment_meta['user_info'] ); |
|
273 | + $user_info = maybe_unserialize($payment_meta['user_info']); |
|
274 | 274 | |
275 | 275 | // get donor's first name |
276 | 276 | $name = $user_info['first_name']; |
277 | 277 | |
278 | 278 | // get donor's email |
279 | - $email = get_post_meta( $id, '_give_payment_user_email', true ); |
|
279 | + $email = get_post_meta($id, '_give_payment_user_email', true); |
|
280 | 280 | |
281 | 281 | // set gravatar size and provide filter |
282 | - $size = isset( $give_options['give_donors_gravatars_gravatar_size'] ) ? apply_filters( 'give_donors_gravatars_gravatar_size', $give_options['give_donors_gravatars_gravatar_size'] ) : ''; |
|
282 | + $size = isset($give_options['give_donors_gravatars_gravatar_size']) ? apply_filters('give_donors_gravatars_gravatar_size', $give_options['give_donors_gravatars_gravatar_size']) : ''; |
|
283 | 283 | |
284 | 284 | // default image |
285 | - $default_image = apply_filters( 'give_donors_gravatars_gravatar_default_image', false ); |
|
285 | + $default_image = apply_filters('give_donors_gravatars_gravatar_default_image', false); |
|
286 | 286 | |
287 | 287 | // assemble output |
288 | 288 | $output .= '<li>'; |
289 | 289 | |
290 | - $output .= get_avatar( $email, $size, $default_image, $name ); |
|
290 | + $output .= get_avatar($email, $size, $default_image, $name); |
|
291 | 291 | $output .= '</li>'; |
292 | 292 | |
293 | - $i ++; |
|
293 | + $i++; |
|
294 | 294 | |
295 | 295 | } // end foreach |
296 | 296 | } |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | echo '</ul>'; |
300 | 300 | echo '</div>'; |
301 | 301 | |
302 | - return apply_filters( 'give_donors_gravatars', ob_get_clean() ); |
|
302 | + return apply_filters('give_donors_gravatars', ob_get_clean()); |
|
303 | 303 | } |
304 | 304 | |
305 | 305 | /** |
@@ -311,7 +311,7 @@ discard block |
||
311 | 311 | * @return void |
312 | 312 | */ |
313 | 313 | public function register_widget() { |
314 | - register_widget( 'Give_Donors_Gravatars_Widget' ); |
|
314 | + register_widget('Give_Donors_Gravatars_Widget'); |
|
315 | 315 | } |
316 | 316 | |
317 | 317 | /** |
@@ -325,19 +325,19 @@ discard block |
||
325 | 325 | * |
326 | 326 | * @return string |
327 | 327 | */ |
328 | - public function shortcode( $atts, $content = null ) { |
|
328 | + public function shortcode($atts, $content = null) { |
|
329 | 329 | |
330 | - $atts = shortcode_atts( array( |
|
330 | + $atts = shortcode_atts(array( |
|
331 | 331 | 'id' => '', |
332 | 332 | 'title' => '' |
333 | - ), $atts, 'give_donors_gravatars' ); |
|
333 | + ), $atts, 'give_donors_gravatars'); |
|
334 | 334 | |
335 | 335 | // if no ID is passed on single give_forms pages, get the correct ID |
336 | - if ( is_singular( 'give_forms' ) ) { |
|
336 | + if (is_singular('give_forms')) { |
|
337 | 337 | $id = get_the_ID(); |
338 | 338 | } |
339 | 339 | |
340 | - $content = $this->gravatars( $atts['id'], $atts['title'] ); |
|
340 | + $content = $this->gravatars($atts['id'], $atts['title']); |
|
341 | 341 | |
342 | 342 | return $content; |
343 | 343 | |
@@ -353,56 +353,56 @@ discard block |
||
353 | 353 | * |
354 | 354 | * @return array Gravatar settings. |
355 | 355 | */ |
356 | - public function settings( $settings ) { |
|
356 | + public function settings($settings) { |
|
357 | 357 | |
358 | 358 | $give_gravatar_settings = array( |
359 | 359 | array( |
360 | - 'name' => esc_html__( 'Donator Gravatars', 'give' ), |
|
360 | + 'name' => esc_html__('Donator Gravatars', 'give'), |
|
361 | 361 | 'desc' => '<hr>', |
362 | 362 | 'id' => 'give_title', |
363 | 363 | 'type' => 'give_title' |
364 | 364 | ), |
365 | 365 | array( |
366 | - 'name' => esc_html__( 'Heading', 'give' ), |
|
367 | - 'desc' => esc_html__( 'The heading to display above the Gravatars.', 'give' ), |
|
366 | + 'name' => esc_html__('Heading', 'give'), |
|
367 | + 'desc' => esc_html__('The heading to display above the Gravatars.', 'give'), |
|
368 | 368 | 'type' => 'text', |
369 | 369 | 'id' => 'give_donors_gravatars_heading' |
370 | 370 | ), |
371 | 371 | array( |
372 | - 'name' => esc_html__( 'Gravatar Size', 'give' ), |
|
373 | - 'desc' => esc_html__( 'The size of each Gravatar in pixels (512px maximum).', 'give' ), |
|
372 | + 'name' => esc_html__('Gravatar Size', 'give'), |
|
373 | + 'desc' => esc_html__('The size of each Gravatar in pixels (512px maximum).', 'give'), |
|
374 | 374 | 'type' => 'text_small', |
375 | 375 | 'id' => 'give_donors_gravatars_gravatar_size', |
376 | 376 | 'default' => '64' |
377 | 377 | ), |
378 | 378 | array( |
379 | - 'name' => esc_html__( 'Minimum Unique Donations Required', 'give' ), |
|
380 | - 'desc' => esc_html__( 'The minimum number of unique donations a form must have before the Gravatars are shown. Leave blank for no minimum.', 'give' ), |
|
379 | + 'name' => esc_html__('Minimum Unique Donations Required', 'give'), |
|
380 | + 'desc' => esc_html__('The minimum number of unique donations a form must have before the Gravatars are shown. Leave blank for no minimum.', 'give'), |
|
381 | 381 | 'type' => 'text_small', |
382 | 382 | 'id' => 'give_donors_gravatars_min_purchases_required', |
383 | 383 | ), |
384 | 384 | array( |
385 | - 'name' => esc_html__( 'Maximum Gravatars To Show', 'give' ), |
|
386 | - 'desc' => esc_html__( 'The maximum number of gravatars to show. Leave blank for no limit.', 'give' ), |
|
385 | + 'name' => esc_html__('Maximum Gravatars To Show', 'give'), |
|
386 | + 'desc' => esc_html__('The maximum number of gravatars to show. Leave blank for no limit.', 'give'), |
|
387 | 387 | 'type' => 'text', |
388 | 388 | 'id' => 'give_donors_gravatars_maximum_number', |
389 | 389 | 'default' => '20', |
390 | 390 | ), |
391 | 391 | array( |
392 | - 'name' => esc_html__( 'Gravatar Visibility', 'give' ), |
|
393 | - 'desc' => esc_html__( 'Show only donors with a Gravatar account.', 'give' ), |
|
392 | + 'name' => esc_html__('Gravatar Visibility', 'give'), |
|
393 | + 'desc' => esc_html__('Show only donors with a Gravatar account.', 'give'), |
|
394 | 394 | 'id' => 'give_donors_gravatars_has_gravatar_account', |
395 | 395 | 'type' => 'checkbox', |
396 | 396 | ), |
397 | 397 | array( |
398 | - 'name' => esc_html__( 'Randomize Gravatars', 'give' ), |
|
399 | - 'desc' => esc_html__( 'Randomize the Gravatars.', 'give' ), |
|
398 | + 'name' => esc_html__('Randomize Gravatars', 'give'), |
|
399 | + 'desc' => esc_html__('Randomize the Gravatars.', 'give'), |
|
400 | 400 | 'id' => 'give_donors_gravatars_random_gravatars', |
401 | 401 | 'type' => 'checkbox', |
402 | 402 | ), |
403 | 403 | ); |
404 | 404 | |
405 | - return array_merge( $settings, $give_gravatar_settings ); |
|
405 | + return array_merge($settings, $give_gravatar_settings); |
|
406 | 406 | } |
407 | 407 | |
408 | 408 | } |
@@ -428,7 +428,7 @@ discard block |
||
428 | 428 | // widget settings |
429 | 429 | $widget_ops = array( |
430 | 430 | 'classname' => 'give-donors-gravatars', |
431 | - 'description' => esc_html__( 'Displays gravatars of people who have donated using your your form. Will only show on the single form page.', 'give' ), |
|
431 | + 'description' => esc_html__('Displays gravatars of people who have donated using your your form. Will only show on the single form page.', 'give'), |
|
432 | 432 | ); |
433 | 433 | |
434 | 434 | // widget control settings |
@@ -441,7 +441,7 @@ discard block |
||
441 | 441 | // create the widget |
442 | 442 | parent::__construct( |
443 | 443 | 'give_donors_gravatars_widget', |
444 | - esc_html__( 'Give Donors Gravatars', 'give' ), |
|
444 | + esc_html__('Give Donors Gravatars', 'give'), |
|
445 | 445 | $widget_ops, |
446 | 446 | $control_ops |
447 | 447 | ); |
@@ -461,29 +461,29 @@ discard block |
||
461 | 461 | * |
462 | 462 | * @return void |
463 | 463 | */ |
464 | - public function widget( $args, $instance ) { |
|
464 | + public function widget($args, $instance) { |
|
465 | 465 | |
466 | 466 | //@TODO: Don't extract it!!! |
467 | - extract( $args ); |
|
467 | + extract($args); |
|
468 | 468 | |
469 | - if ( ! is_singular( 'give_forms' ) ) { |
|
469 | + if ( ! is_singular('give_forms')) { |
|
470 | 470 | return; |
471 | 471 | } |
472 | 472 | |
473 | 473 | // Variables from widget settings |
474 | - $title = apply_filters( 'widget_title', $instance['title'] ); |
|
474 | + $title = apply_filters('widget_title', $instance['title']); |
|
475 | 475 | |
476 | 476 | // Used by themes. Opens the widget |
477 | 477 | echo $before_widget; |
478 | 478 | |
479 | 479 | // Display the widget title |
480 | - if ( $title ) { |
|
481 | - echo $before_title . $title . $after_title; |
|
480 | + if ($title) { |
|
481 | + echo $before_title.$title.$after_title; |
|
482 | 482 | } |
483 | 483 | |
484 | 484 | $gravatars = new Give_Donors_Gravatars(); |
485 | 485 | |
486 | - echo $gravatars->gravatars( get_the_ID(), null ); // remove title |
|
486 | + echo $gravatars->gravatars(get_the_ID(), null); // remove title |
|
487 | 487 | |
488 | 488 | // Used by themes. Closes the widget |
489 | 489 | echo $after_widget; |
@@ -503,11 +503,11 @@ discard block |
||
503 | 503 | * |
504 | 504 | * @return array Updated settings to save. |
505 | 505 | */ |
506 | - public function update( $new_instance, $old_instance ) { |
|
506 | + public function update($new_instance, $old_instance) { |
|
507 | 507 | |
508 | 508 | $instance = $old_instance; |
509 | 509 | |
510 | - $instance['title'] = strip_tags( $new_instance['title'] ); |
|
510 | + $instance['title'] = strip_tags($new_instance['title']); |
|
511 | 511 | |
512 | 512 | return $instance; |
513 | 513 | |
@@ -525,19 +525,19 @@ discard block |
||
525 | 525 | * |
526 | 526 | * @return void |
527 | 527 | */ |
528 | - public function form( $instance ) { |
|
528 | + public function form($instance) { |
|
529 | 529 | |
530 | 530 | // Set up some default widget settings. |
531 | 531 | $defaults = array( |
532 | 532 | 'title' => '', |
533 | 533 | ); |
534 | 534 | |
535 | - $instance = wp_parse_args( (array) $instance, $defaults ); ?> |
|
535 | + $instance = wp_parse_args((array) $instance, $defaults); ?> |
|
536 | 536 | |
537 | 537 | <!-- Title --> |
538 | 538 | <p> |
539 | - <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php esc_html_e( 'Title:', 'give' ) ?></label> |
|
540 | - <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo $instance['title']; ?>" /> |
|
539 | + <label for="<?php echo $this->get_field_id('title'); ?>"><?php esc_html_e('Title:', 'give') ?></label> |
|
540 | + <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $instance['title']; ?>" /> |
|
541 | 541 | </p> |
542 | 542 | |
543 | 543 | <?php |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | */ |
13 | 13 | |
14 | 14 | // Exit if accessed directly. |
15 | -if ( ! defined( 'ABSPATH' ) ) { |
|
15 | +if ( ! defined('ABSPATH')) { |
|
16 | 16 | exit; |
17 | 17 | } |
18 | 18 | |
@@ -87,12 +87,12 @@ discard block |
||
87 | 87 | */ |
88 | 88 | public function __construct() { |
89 | 89 | |
90 | - if ( 'none' === $this->get_template() ) { |
|
90 | + if ('none' === $this->get_template()) { |
|
91 | 91 | $this->html = false; |
92 | 92 | } |
93 | 93 | |
94 | - add_action( 'give_email_send_before', array( $this, 'send_before' ) ); |
|
95 | - add_action( 'give_email_send_after', array( $this, 'send_after' ) ); |
|
94 | + add_action('give_email_send_before', array($this, 'send_before')); |
|
95 | + add_action('give_email_send_after', array($this, 'send_after')); |
|
96 | 96 | |
97 | 97 | } |
98 | 98 | |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | * @param $key |
105 | 105 | * @param $value |
106 | 106 | */ |
107 | - public function __set( $key, $value ) { |
|
107 | + public function __set($key, $value) { |
|
108 | 108 | $this->$key = $value; |
109 | 109 | } |
110 | 110 | |
@@ -114,11 +114,11 @@ discard block |
||
114 | 114 | * @since 1.0 |
115 | 115 | */ |
116 | 116 | public function get_from_name() { |
117 | - if ( ! $this->from_name ) { |
|
118 | - $this->from_name = give_get_option( 'from_name', get_bloginfo( 'name' ) ); |
|
117 | + if ( ! $this->from_name) { |
|
118 | + $this->from_name = give_get_option('from_name', get_bloginfo('name')); |
|
119 | 119 | } |
120 | 120 | |
121 | - return apply_filters( 'give_email_from_name', wp_specialchars_decode( $this->from_name ), $this ); |
|
121 | + return apply_filters('give_email_from_name', wp_specialchars_decode($this->from_name), $this); |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | /** |
@@ -127,11 +127,11 @@ discard block |
||
127 | 127 | * @since 1.0 |
128 | 128 | */ |
129 | 129 | public function get_from_address() { |
130 | - if ( ! $this->from_address ) { |
|
131 | - $this->from_address = give_get_option( 'from_email', get_option( 'admin_email' ) ); |
|
130 | + if ( ! $this->from_address) { |
|
131 | + $this->from_address = give_get_option('from_email', get_option('admin_email')); |
|
132 | 132 | } |
133 | 133 | |
134 | - return apply_filters( 'give_email_from_address', $this->from_address, $this ); |
|
134 | + return apply_filters('give_email_from_address', $this->from_address, $this); |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | /** |
@@ -140,13 +140,13 @@ discard block |
||
140 | 140 | * @since 1.0 |
141 | 141 | */ |
142 | 142 | public function get_content_type() { |
143 | - if ( ! $this->content_type && $this->html ) { |
|
144 | - $this->content_type = apply_filters( 'give_email_default_content_type', 'text/html', $this ); |
|
145 | - } else if ( ! $this->html ) { |
|
143 | + if ( ! $this->content_type && $this->html) { |
|
144 | + $this->content_type = apply_filters('give_email_default_content_type', 'text/html', $this); |
|
145 | + } else if ( ! $this->html) { |
|
146 | 146 | $this->content_type = 'text/plain'; |
147 | 147 | } |
148 | 148 | |
149 | - return apply_filters( 'give_email_content_type', $this->content_type, $this ); |
|
149 | + return apply_filters('give_email_content_type', $this->content_type, $this); |
|
150 | 150 | } |
151 | 151 | |
152 | 152 | /** |
@@ -155,13 +155,13 @@ discard block |
||
155 | 155 | * @since 1.0 |
156 | 156 | */ |
157 | 157 | public function get_headers() { |
158 | - if ( ! $this->headers ) { |
|
158 | + if ( ! $this->headers) { |
|
159 | 159 | $this->headers = "From: {$this->get_from_name()} <{$this->get_from_address()}>\r\n"; |
160 | 160 | $this->headers .= "Reply-To: {$this->get_from_address()}\r\n"; |
161 | 161 | $this->headers .= "Content-Type: {$this->get_content_type()}; charset=utf-8\r\n"; |
162 | 162 | } |
163 | 163 | |
164 | - return apply_filters( 'give_email_headers', $this->headers, $this ); |
|
164 | + return apply_filters('give_email_headers', $this->headers, $this); |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | /** |
@@ -171,11 +171,11 @@ discard block |
||
171 | 171 | */ |
172 | 172 | public function get_templates() { |
173 | 173 | $templates = array( |
174 | - 'default' => esc_html__( 'Default Template', 'give' ), |
|
175 | - 'none' => esc_html__( 'No template, plain text only', 'give' ) |
|
174 | + 'default' => esc_html__('Default Template', 'give'), |
|
175 | + 'none' => esc_html__('No template, plain text only', 'give') |
|
176 | 176 | ); |
177 | 177 | |
178 | - return apply_filters( 'give_email_templates', $templates ); |
|
178 | + return apply_filters('give_email_templates', $templates); |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | /** |
@@ -184,11 +184,11 @@ discard block |
||
184 | 184 | * @since 1.0 |
185 | 185 | */ |
186 | 186 | public function get_template() { |
187 | - if ( ! $this->template ) { |
|
188 | - $this->template = give_get_option( 'email_template', 'default' ); |
|
187 | + if ( ! $this->template) { |
|
188 | + $this->template = give_get_option('email_template', 'default'); |
|
189 | 189 | } |
190 | 190 | |
191 | - return apply_filters( 'give_email_template', $this->template ); |
|
191 | + return apply_filters('give_email_template', $this->template); |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | /** |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | * @since 1.0 |
198 | 198 | */ |
199 | 199 | public function get_heading() { |
200 | - return apply_filters( 'give_email_heading', $this->heading ); |
|
200 | + return apply_filters('give_email_heading', $this->heading); |
|
201 | 201 | } |
202 | 202 | |
203 | 203 | /** |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | * |
208 | 208 | * @return mixed |
209 | 209 | */ |
210 | - public function parse_tags( $content ) { |
|
210 | + public function parse_tags($content) { |
|
211 | 211 | return $content; |
212 | 212 | } |
213 | 213 | |
@@ -220,19 +220,19 @@ discard block |
||
220 | 220 | * |
221 | 221 | * @return mixed|void |
222 | 222 | */ |
223 | - public function build_email( $message ) { |
|
223 | + public function build_email($message) { |
|
224 | 224 | |
225 | - if ( false === $this->html ) { |
|
226 | - return apply_filters( 'give_email_message', wp_strip_all_tags( $message ), $this ); |
|
225 | + if (false === $this->html) { |
|
226 | + return apply_filters('give_email_message', wp_strip_all_tags($message), $this); |
|
227 | 227 | } |
228 | 228 | |
229 | - $message = $this->text_to_html( $message ); |
|
229 | + $message = $this->text_to_html($message); |
|
230 | 230 | |
231 | 231 | $template = $this->get_template(); |
232 | 232 | |
233 | 233 | ob_start(); |
234 | 234 | |
235 | - give_get_template_part( 'emails/header', $template, true ); |
|
235 | + give_get_template_part('emails/header', $template, true); |
|
236 | 236 | |
237 | 237 | /** |
238 | 238 | * Fires in the email head. |
@@ -241,17 +241,17 @@ discard block |
||
241 | 241 | * |
242 | 242 | * @param Give_Emails $this The email object. |
243 | 243 | */ |
244 | - do_action( 'give_email_header', $this ); |
|
244 | + do_action('give_email_header', $this); |
|
245 | 245 | |
246 | - if ( has_action( 'give_email_template_' . $template ) ) { |
|
246 | + if (has_action('give_email_template_'.$template)) { |
|
247 | 247 | /** |
248 | 248 | * Fires in a specific email template. |
249 | 249 | * |
250 | 250 | * @since 1.0 |
251 | 251 | */ |
252 | - do_action( "give_email_template_{$template}" ); |
|
252 | + do_action("give_email_template_{$template}"); |
|
253 | 253 | } else { |
254 | - give_get_template_part( 'emails/body', $template, true ); |
|
254 | + give_get_template_part('emails/body', $template, true); |
|
255 | 255 | } |
256 | 256 | |
257 | 257 | /** |
@@ -261,9 +261,9 @@ discard block |
||
261 | 261 | * |
262 | 262 | * @param Give_Emails $this The email object. |
263 | 263 | */ |
264 | - do_action( 'give_email_body', $this ); |
|
264 | + do_action('give_email_body', $this); |
|
265 | 265 | |
266 | - give_get_template_part( 'emails/footer', $template, true ); |
|
266 | + give_get_template_part('emails/footer', $template, true); |
|
267 | 267 | |
268 | 268 | /** |
269 | 269 | * Fires in the email footer. |
@@ -272,12 +272,12 @@ discard block |
||
272 | 272 | * |
273 | 273 | * @param Give_Emails $this The email object. |
274 | 274 | */ |
275 | - do_action( 'give_email_footer', $this ); |
|
275 | + do_action('give_email_footer', $this); |
|
276 | 276 | |
277 | 277 | $body = ob_get_clean(); |
278 | - $message = str_replace( '{email}', $message, $body ); |
|
278 | + $message = str_replace('{email}', $message, $body); |
|
279 | 279 | |
280 | - return apply_filters( 'give_email_message', $message, $this ); |
|
280 | + return apply_filters('give_email_message', $message, $this); |
|
281 | 281 | } |
282 | 282 | |
283 | 283 | /** |
@@ -290,10 +290,10 @@ discard block |
||
290 | 290 | * |
291 | 291 | * @return bool |
292 | 292 | */ |
293 | - public function send( $to, $subject, $message, $attachments = '' ) { |
|
293 | + public function send($to, $subject, $message, $attachments = '') { |
|
294 | 294 | |
295 | - if ( ! did_action( 'init' ) && ! did_action( 'admin_init' ) ) { |
|
296 | - _doing_it_wrong( __FUNCTION__, esc_html__( 'You cannot send email with Give_Emails until init/admin_init has been reached.', 'give' ), null ); |
|
295 | + if ( ! did_action('init') && ! did_action('admin_init')) { |
|
296 | + _doing_it_wrong(__FUNCTION__, esc_html__('You cannot send email with Give_Emails until init/admin_init has been reached.', 'give'), null); |
|
297 | 297 | |
298 | 298 | return false; |
299 | 299 | } |
@@ -305,16 +305,16 @@ discard block |
||
305 | 305 | * |
306 | 306 | * @param Give_Emails $this The email object. |
307 | 307 | */ |
308 | - do_action( 'give_email_send_before', $this ); |
|
308 | + do_action('give_email_send_before', $this); |
|
309 | 309 | |
310 | - $subject = $this->parse_tags( $subject ); |
|
311 | - $message = $this->parse_tags( $message ); |
|
310 | + $subject = $this->parse_tags($subject); |
|
311 | + $message = $this->parse_tags($message); |
|
312 | 312 | |
313 | - $message = $this->build_email( $message ); |
|
313 | + $message = $this->build_email($message); |
|
314 | 314 | |
315 | - $attachments = apply_filters( 'give_email_attachments', $attachments, $this ); |
|
315 | + $attachments = apply_filters('give_email_attachments', $attachments, $this); |
|
316 | 316 | |
317 | - $sent = wp_mail( $to, $subject, $message, $this->get_headers(), $attachments ); |
|
317 | + $sent = wp_mail($to, $subject, $message, $this->get_headers(), $attachments); |
|
318 | 318 | |
319 | 319 | /** |
320 | 320 | * Fires after sending an email. |
@@ -323,7 +323,7 @@ discard block |
||
323 | 323 | * |
324 | 324 | * @param Give_Emails $this The email object. |
325 | 325 | */ |
326 | - do_action( 'give_email_send_after', $this ); |
|
326 | + do_action('give_email_send_after', $this); |
|
327 | 327 | |
328 | 328 | return $sent; |
329 | 329 | |
@@ -335,9 +335,9 @@ discard block |
||
335 | 335 | * @since 1.0 |
336 | 336 | */ |
337 | 337 | public function send_before() { |
338 | - add_filter( 'wp_mail_from', array( $this, 'get_from_address' ) ); |
|
339 | - add_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ) ); |
|
340 | - add_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ) ); |
|
338 | + add_filter('wp_mail_from', array($this, 'get_from_address')); |
|
339 | + add_filter('wp_mail_from_name', array($this, 'get_from_name')); |
|
340 | + add_filter('wp_mail_content_type', array($this, 'get_content_type')); |
|
341 | 341 | } |
342 | 342 | |
343 | 343 | /** |
@@ -346,9 +346,9 @@ discard block |
||
346 | 346 | * @since 1.0 |
347 | 347 | */ |
348 | 348 | public function send_after() { |
349 | - remove_filter( 'wp_mail_from', array( $this, 'get_from_address' ) ); |
|
350 | - remove_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ) ); |
|
351 | - remove_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ) ); |
|
349 | + remove_filter('wp_mail_from', array($this, 'get_from_address')); |
|
350 | + remove_filter('wp_mail_from_name', array($this, 'get_from_name')); |
|
351 | + remove_filter('wp_mail_content_type', array($this, 'get_content_type')); |
|
352 | 352 | |
353 | 353 | // Reset heading to an empty string |
354 | 354 | $this->heading = ''; |
@@ -359,10 +359,10 @@ discard block |
||
359 | 359 | * |
360 | 360 | * @since 1.0 |
361 | 361 | */ |
362 | - public function text_to_html( $message ) { |
|
362 | + public function text_to_html($message) { |
|
363 | 363 | |
364 | - if ( 'text/html' == $this->content_type || true === $this->html ) { |
|
365 | - $message = wpautop( $message ); |
|
364 | + if ('text/html' == $this->content_type || true === $this->html) { |
|
365 | + $message = wpautop($message); |
|
366 | 366 | } |
367 | 367 | |
368 | 368 | return $message; |
@@ -10,7 +10,7 @@ |
||
10 | 10 | */ |
11 | 11 | |
12 | 12 | // Exit if accessed directly. |
13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
13 | +if ( ! defined('ABSPATH')) { |
|
14 | 14 | exit; |
15 | 15 | } |
16 | 16 |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | */ |
11 | 11 | |
12 | 12 | // Exit if accessed directly. |
13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
13 | +if ( ! defined('ABSPATH')) { |
|
14 | 14 | exit; |
15 | 15 | } |
16 | 16 | |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | * |
20 | 20 | * @since 1.0 |
21 | 21 | */ |
22 | -class Give_Forms_Widget extends WP_Widget{ |
|
22 | +class Give_Forms_Widget extends WP_Widget { |
|
23 | 23 | /** |
24 | 24 | * The widget class name |
25 | 25 | * |
@@ -30,19 +30,19 @@ discard block |
||
30 | 30 | /** |
31 | 31 | * Instantiate the class |
32 | 32 | */ |
33 | - public function __construct(){ |
|
34 | - $this->self = get_class( $this ); |
|
33 | + public function __construct() { |
|
34 | + $this->self = get_class($this); |
|
35 | 35 | |
36 | 36 | parent::__construct( |
37 | - strtolower( $this->self ), |
|
38 | - esc_html__( 'Give - Donation Form', 'give' ), |
|
37 | + strtolower($this->self), |
|
38 | + esc_html__('Give - Donation Form', 'give'), |
|
39 | 39 | array( |
40 | - 'description' => esc_html__( 'Display a Give Donation Form in your theme\'s widget powered sidebar.', 'give' ) |
|
40 | + 'description' => esc_html__('Display a Give Donation Form in your theme\'s widget powered sidebar.', 'give') |
|
41 | 41 | ) |
42 | 42 | ); |
43 | 43 | |
44 | - add_action( 'widgets_init', array( $this, 'widget_init' ) ); |
|
45 | - add_action( 'admin_enqueue_scripts', array( $this, 'admin_widget_scripts' ) ); |
|
44 | + add_action('widgets_init', array($this, 'widget_init')); |
|
45 | + add_action('admin_enqueue_scripts', array($this, 'admin_widget_scripts')); |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | /** |
@@ -52,23 +52,23 @@ discard block |
||
52 | 52 | * |
53 | 53 | * @return void |
54 | 54 | */ |
55 | - public function admin_widget_scripts( $hook ){ |
|
55 | + public function admin_widget_scripts($hook) { |
|
56 | 56 | // Directories of assets |
57 | - $js_dir = GIVE_PLUGIN_URL . 'assets/js/admin/'; |
|
58 | - $js_plugins = GIVE_PLUGIN_URL . 'assets/js/plugins/'; |
|
59 | - $css_dir = GIVE_PLUGIN_URL . 'assets/css/'; |
|
57 | + $js_dir = GIVE_PLUGIN_URL.'assets/js/admin/'; |
|
58 | + $js_plugins = GIVE_PLUGIN_URL.'assets/js/plugins/'; |
|
59 | + $css_dir = GIVE_PLUGIN_URL.'assets/css/'; |
|
60 | 60 | |
61 | 61 | // Use minified libraries if SCRIPT_DEBUG is turned off |
62 | - $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min'; |
|
62 | + $suffix = (defined('SCRIPT_DEBUG') && SCRIPT_DEBUG) ? '' : '.min'; |
|
63 | 63 | |
64 | 64 | // Widget Script |
65 | - if ( $hook == 'widgets.php' ) { |
|
65 | + if ($hook == 'widgets.php') { |
|
66 | 66 | |
67 | - wp_enqueue_style( 'give-qtip-css', $css_dir . 'jquery.qtip' . $suffix . '.css' ); |
|
67 | + wp_enqueue_style('give-qtip-css', $css_dir.'jquery.qtip'.$suffix.'.css'); |
|
68 | 68 | |
69 | - wp_enqueue_script( 'give-qtip', $js_plugins . 'jquery.qtip' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION ); |
|
69 | + wp_enqueue_script('give-qtip', $js_plugins.'jquery.qtip'.$suffix.'.js', array('jquery'), GIVE_VERSION); |
|
70 | 70 | |
71 | - wp_enqueue_script( 'give-admin-widgets-scripts', $js_dir . 'admin-widgets' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION, false ); |
|
71 | + wp_enqueue_script('give-admin-widgets-scripts', $js_dir.'admin-widgets'.$suffix.'.js', array('jquery'), GIVE_VERSION, false); |
|
72 | 72 | } |
73 | 73 | } |
74 | 74 | |
@@ -79,9 +79,9 @@ discard block |
||
79 | 79 | * before_widget, and after_widget. |
80 | 80 | * @param array $instance The settings for the particular instance of the widget. |
81 | 81 | */ |
82 | - public function widget( $args, $instance ){ |
|
83 | - $title = !empty( $instance['title'] ) ? $instance['title'] : ''; |
|
84 | - $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); |
|
82 | + public function widget($args, $instance) { |
|
83 | + $title = ! empty($instance['title']) ? $instance['title'] : ''; |
|
84 | + $title = apply_filters('widget_title', $title, $instance, $this->id_base); |
|
85 | 85 | |
86 | 86 | echo $args['before_widget']; |
87 | 87 | |
@@ -90,11 +90,11 @@ discard block |
||
90 | 90 | * |
91 | 91 | * @since 1.0 |
92 | 92 | */ |
93 | - do_action( 'give_before_forms_widget' ); |
|
93 | + do_action('give_before_forms_widget'); |
|
94 | 94 | |
95 | - echo $title ? $args['before_title'] . $title . $args['after_title'] : ''; |
|
95 | + echo $title ? $args['before_title'].$title.$args['after_title'] : ''; |
|
96 | 96 | |
97 | - give_get_donation_form( $instance ); |
|
97 | + give_get_donation_form($instance); |
|
98 | 98 | |
99 | 99 | echo $args['after_widget']; |
100 | 100 | |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | * |
104 | 104 | * @since 1.0 |
105 | 105 | */ |
106 | - do_action( 'give_after_forms_widget' ); |
|
106 | + do_action('give_after_forms_widget'); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | /** |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | * |
114 | 114 | * @return string |
115 | 115 | */ |
116 | - public function form( $instance ){ |
|
116 | + public function form($instance) { |
|
117 | 117 | $defaults = array( |
118 | 118 | 'title' => '', |
119 | 119 | 'id' => '', |
@@ -122,77 +122,77 @@ discard block |
||
122 | 122 | 'show_content' => 'none', |
123 | 123 | ); |
124 | 124 | |
125 | - $instance = wp_parse_args( (array) $instance, $defaults ); |
|
125 | + $instance = wp_parse_args((array) $instance, $defaults); |
|
126 | 126 | |
127 | 127 | // Backward compatibility: Set float labels as default if, it was set as empty previous. |
128 | - $instance['float_labels'] = empty( $instance['float_labels'] ) ? 'global' : $instance['float_labels']; |
|
128 | + $instance['float_labels'] = empty($instance['float_labels']) ? 'global' : $instance['float_labels']; |
|
129 | 129 | |
130 | 130 | // Query Give Forms |
131 | 131 | $args = array( |
132 | 132 | 'post_type' => 'give_forms', |
133 | - 'posts_per_page' => - 1, |
|
133 | + 'posts_per_page' => -1, |
|
134 | 134 | 'post_status' => 'publish', |
135 | 135 | ); |
136 | 136 | |
137 | - $give_forms = get_posts( $args ); |
|
137 | + $give_forms = get_posts($args); |
|
138 | 138 | |
139 | 139 | // Widget: Title |
140 | 140 | |
141 | 141 | ?><p> |
142 | - <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php esc_html_e( 'Title:', 'give' ); ?></label> |
|
143 | - <input type="text" class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php esc_attr_e( $instance['title'] ); ?>" /><br> |
|
144 | - <small class="give-field-description"><?php esc_html_e( 'Leave blank to hide the widget title.', 'give' ); ?></small> |
|
142 | + <label for="<?php echo $this->get_field_id('title'); ?>"><?php esc_html_e('Title:', 'give'); ?></label> |
|
143 | + <input type="text" class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php esc_attr_e($instance['title']); ?>" /><br> |
|
144 | + <small class="give-field-description"><?php esc_html_e('Leave blank to hide the widget title.', 'give'); ?></small> |
|
145 | 145 | </p><?php |
146 | 146 | |
147 | 147 | // Widget: Give Form |
148 | 148 | |
149 | 149 | ?><p> |
150 | - <label for="<?php echo esc_attr( $this->get_field_id( 'id' ) ); ?>"><?php esc_html_e( 'Give Form:', 'give' ); ?></label> |
|
151 | - <select class="widefat" name="<?php echo esc_attr( $this->get_field_name( 'id' ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'id' ) ); ?>"> |
|
152 | - <option value="current"><?php esc_html_e( '- Select -', 'give' ); ?></option> |
|
153 | - <?php foreach ( $give_forms as $give_form ) { ?> |
|
154 | - <?php $form_title = empty( $give_form->post_title ) ? sprintf( __( 'Untitled (#%s)', 'give' ), $give_form->ID ) : $give_form->post_title; ?> |
|
155 | - <option <?php selected( absint( $instance['id'] ), $give_form->ID ); ?> value="<?php echo esc_attr( $give_form->ID ); ?>"><?php echo $form_title; ?></option> |
|
150 | + <label for="<?php echo esc_attr($this->get_field_id('id')); ?>"><?php esc_html_e('Give Form:', 'give'); ?></label> |
|
151 | + <select class="widefat" name="<?php echo esc_attr($this->get_field_name('id')); ?>" id="<?php echo esc_attr($this->get_field_id('id')); ?>"> |
|
152 | + <option value="current"><?php esc_html_e('- Select -', 'give'); ?></option> |
|
153 | + <?php foreach ($give_forms as $give_form) { ?> |
|
154 | + <?php $form_title = empty($give_form->post_title) ? sprintf(__('Untitled (#%s)', 'give'), $give_form->ID) : $give_form->post_title; ?> |
|
155 | + <option <?php selected(absint($instance['id']), $give_form->ID); ?> value="<?php echo esc_attr($give_form->ID); ?>"><?php echo $form_title; ?></option> |
|
156 | 156 | <?php } ?> |
157 | 157 | </select><br> |
158 | - <small class="give-field-description"><?php esc_html_e( 'Select a Give Form to embed in this widget.', 'give' ); ?></small> |
|
158 | + <small class="give-field-description"><?php esc_html_e('Select a Give Form to embed in this widget.', 'give'); ?></small> |
|
159 | 159 | </p> |
160 | 160 | |
161 | 161 | <?php // Widget: Display Style ?> |
162 | 162 | <p> |
163 | - <label for="<?php echo esc_attr( $this->get_field_id( 'display_style' ) ); ?>"><?php esc_html_e( 'Display Style:', 'give' ); ?></label><br> |
|
164 | - <label for="<?php echo $this->get_field_id( 'display_style' ); ?>-onpage"><input type="radio" class="widefat" id="<?php echo $this->get_field_id( 'display_style' ); ?>-onpage" name="<?php echo $this->get_field_name( 'display_style' ); ?>" value="onpage" <?php checked( $instance['display_style'], 'onpage' ); ?>> <?php echo esc_html__( 'All Fields', 'give' ); ?></label> |
|
165 | - <label for="<?php echo $this->get_field_id( 'display_style' ); ?>-reveal"><input type="radio" class="widefat" id="<?php echo $this->get_field_id( 'display_style' ); ?>-reveal" name="<?php echo $this->get_field_name( 'display_style' ); ?>" value="reveal" <?php checked( $instance['display_style'], 'reveal' ); ?>> <?php echo esc_html__( 'Reveal', 'give' ); ?></label> |
|
166 | - <label for="<?php echo $this->get_field_id( 'display_style' ); ?>-modal"><input type="radio" class="widefat" id="<?php echo $this->get_field_id( 'display_style' ); ?>-modal" name="<?php echo $this->get_field_name( 'display_style' ); ?>" value="modal" <?php checked( $instance['display_style'], 'modal' ); ?>> <?php echo esc_html__( 'Modal', 'give' ); ?></label> |
|
167 | - <label for="<?php echo $this->get_field_id( 'display_style' ); ?>-button"><input type="radio" class="widefat" id="<?php echo $this->get_field_id( 'display_style' ); ?>-button" name="<?php echo $this->get_field_name( 'display_style' ); ?>" value="button" <?php checked( $instance['display_style'], 'button' ); ?>> <?php echo esc_html__( 'Button', 'give' ); ?></label><br> |
|
163 | + <label for="<?php echo esc_attr($this->get_field_id('display_style')); ?>"><?php esc_html_e('Display Style:', 'give'); ?></label><br> |
|
164 | + <label for="<?php echo $this->get_field_id('display_style'); ?>-onpage"><input type="radio" class="widefat" id="<?php echo $this->get_field_id('display_style'); ?>-onpage" name="<?php echo $this->get_field_name('display_style'); ?>" value="onpage" <?php checked($instance['display_style'], 'onpage'); ?>> <?php echo esc_html__('All Fields', 'give'); ?></label> |
|
165 | + <label for="<?php echo $this->get_field_id('display_style'); ?>-reveal"><input type="radio" class="widefat" id="<?php echo $this->get_field_id('display_style'); ?>-reveal" name="<?php echo $this->get_field_name('display_style'); ?>" value="reveal" <?php checked($instance['display_style'], 'reveal'); ?>> <?php echo esc_html__('Reveal', 'give'); ?></label> |
|
166 | + <label for="<?php echo $this->get_field_id('display_style'); ?>-modal"><input type="radio" class="widefat" id="<?php echo $this->get_field_id('display_style'); ?>-modal" name="<?php echo $this->get_field_name('display_style'); ?>" value="modal" <?php checked($instance['display_style'], 'modal'); ?>> <?php echo esc_html__('Modal', 'give'); ?></label> |
|
167 | + <label for="<?php echo $this->get_field_id('display_style'); ?>-button"><input type="radio" class="widefat" id="<?php echo $this->get_field_id('display_style'); ?>-button" name="<?php echo $this->get_field_name('display_style'); ?>" value="button" <?php checked($instance['display_style'], 'button'); ?>> <?php echo esc_html__('Button', 'give'); ?></label><br> |
|
168 | 168 | <small class="give-field-description"> |
169 | - <?php echo esc_html__( 'Select a Give Form style.', 'give' ); ?> |
|
169 | + <?php echo esc_html__('Select a Give Form style.', 'give'); ?> |
|
170 | 170 | </small> |
171 | 171 | </p> |
172 | 172 | |
173 | 173 | <?php // Widget: Floating Labels ?> |
174 | 174 | <p> |
175 | - <label for="<?php echo esc_attr( $this->get_field_id( 'float_labels' ) ); ?>"><?php esc_html_e( 'Floating Labels (optional):', 'give' ); ?></label><br> |
|
176 | - <label for="<?php echo $this->get_field_id( 'float_labels' ); ?>-global"><input type="radio" class="widefat" id="<?php echo $this->get_field_id( 'float_labels' ); ?>-global" name="<?php echo $this->get_field_name( 'float_labels' ); ?>" value="global" <?php checked( $instance['float_labels'], 'global' ); ?>> <?php echo esc_html__( 'Global Option', 'give' ); ?></label> |
|
177 | - <label for="<?php echo $this->get_field_id( 'float_labels' ); ?>-enabled"><input type="radio" class="widefat" id="<?php echo $this->get_field_id( 'float_labels' ); ?>-enabled" name="<?php echo $this->get_field_name( 'float_labels' ); ?>" value="enabled" <?php checked( $instance['float_labels'], 'enabled' ); ?>> <?php echo esc_html__( 'Yes', 'give' ); ?></label> |
|
178 | - <label for="<?php echo $this->get_field_id( 'float_labels' ); ?>-disabled"><input type="radio" class="widefat" id="<?php echo $this->get_field_id( 'float_labels' ); ?>-disabled" name="<?php echo $this->get_field_name( 'float_labels' ); ?>" value="disabled" <?php checked( $instance['float_labels'], 'disabled' ); ?>> <?php echo esc_html__( 'No', 'give' ); ?></label><br> |
|
175 | + <label for="<?php echo esc_attr($this->get_field_id('float_labels')); ?>"><?php esc_html_e('Floating Labels (optional):', 'give'); ?></label><br> |
|
176 | + <label for="<?php echo $this->get_field_id('float_labels'); ?>-global"><input type="radio" class="widefat" id="<?php echo $this->get_field_id('float_labels'); ?>-global" name="<?php echo $this->get_field_name('float_labels'); ?>" value="global" <?php checked($instance['float_labels'], 'global'); ?>> <?php echo esc_html__('Global Option', 'give'); ?></label> |
|
177 | + <label for="<?php echo $this->get_field_id('float_labels'); ?>-enabled"><input type="radio" class="widefat" id="<?php echo $this->get_field_id('float_labels'); ?>-enabled" name="<?php echo $this->get_field_name('float_labels'); ?>" value="enabled" <?php checked($instance['float_labels'], 'enabled'); ?>> <?php echo esc_html__('Yes', 'give'); ?></label> |
|
178 | + <label for="<?php echo $this->get_field_id('float_labels'); ?>-disabled"><input type="radio" class="widefat" id="<?php echo $this->get_field_id('float_labels'); ?>-disabled" name="<?php echo $this->get_field_name('float_labels'); ?>" value="disabled" <?php checked($instance['float_labels'], 'disabled'); ?>> <?php echo esc_html__('No', 'give'); ?></label><br> |
|
179 | 179 | <small class="give-field-description"> |
180 | 180 | <?php |
181 | 181 | printf( |
182 | 182 | /* translators: %s: http://docs.givewp.com/form-floating-labels */ |
183 | - __( 'Override the <a href="%s" target="_blank">floating labels</a> setting for this Give form.', 'give' ), |
|
184 | - esc_url( 'http://docs.givewp.com/form-floating-labels' ) |
|
183 | + __('Override the <a href="%s" target="_blank">floating labels</a> setting for this Give form.', 'give'), |
|
184 | + esc_url('http://docs.givewp.com/form-floating-labels') |
|
185 | 185 | ); |
186 | 186 | ?></small> |
187 | 187 | </p> |
188 | 188 | |
189 | 189 | <?php // Widget: Display Content ?> |
190 | 190 | <p> |
191 | - <label for="<?php echo esc_attr( $this->get_field_id( 'show_content' ) ); ?>"><?php esc_html_e( 'Display Content (optional):', 'give' ); ?></label><br> |
|
192 | - <label for="<?php echo $this->get_field_id( 'show_content' ); ?>-none"><input type="radio" class="widefat" id="<?php echo $this->get_field_id( 'show_content' ); ?>-none" name="<?php echo $this->get_field_name( 'show_content' ); ?>" value="none" <?php checked( $instance['show_content'], 'none' ); ?>> <?php echo esc_html__( 'None', 'give' ); ?></label> |
|
193 | - <label for="<?php echo $this->get_field_id( 'show_content' ); ?>-above"><input type="radio" class="widefat" id="<?php echo $this->get_field_id( 'show_content' ); ?>-above" name="<?php echo $this->get_field_name( 'show_content' ); ?>" value="above" <?php checked( $instance['show_content'], 'above' ); ?>> <?php echo esc_html__( 'Above', 'give' ); ?></label> |
|
194 | - <label for="<?php echo $this->get_field_id( 'show_content' ); ?>-below"><input type="radio" class="widefat" id="<?php echo $this->get_field_id( 'show_content' ); ?>-below" name="<?php echo $this->get_field_name( 'show_content' ); ?>" value="below" <?php checked( $instance['show_content'], 'below' ); ?>> <?php echo esc_html__( 'Below', 'give' ); ?></label><br> |
|
195 | - <small class="give-field-description"><?php esc_html_e( 'Override the display content setting for this Give form.', 'give' ); ?></small> |
|
191 | + <label for="<?php echo esc_attr($this->get_field_id('show_content')); ?>"><?php esc_html_e('Display Content (optional):', 'give'); ?></label><br> |
|
192 | + <label for="<?php echo $this->get_field_id('show_content'); ?>-none"><input type="radio" class="widefat" id="<?php echo $this->get_field_id('show_content'); ?>-none" name="<?php echo $this->get_field_name('show_content'); ?>" value="none" <?php checked($instance['show_content'], 'none'); ?>> <?php echo esc_html__('None', 'give'); ?></label> |
|
193 | + <label for="<?php echo $this->get_field_id('show_content'); ?>-above"><input type="radio" class="widefat" id="<?php echo $this->get_field_id('show_content'); ?>-above" name="<?php echo $this->get_field_name('show_content'); ?>" value="above" <?php checked($instance['show_content'], 'above'); ?>> <?php echo esc_html__('Above', 'give'); ?></label> |
|
194 | + <label for="<?php echo $this->get_field_id('show_content'); ?>-below"><input type="radio" class="widefat" id="<?php echo $this->get_field_id('show_content'); ?>-below" name="<?php echo $this->get_field_name('show_content'); ?>" value="below" <?php checked($instance['show_content'], 'below'); ?>> <?php echo esc_html__('Below', 'give'); ?></label><br> |
|
195 | + <small class="give-field-description"><?php esc_html_e('Override the display content setting for this Give form.', 'give'); ?></small> |
|
196 | 196 | <?php |
197 | 197 | } |
198 | 198 | |
@@ -201,8 +201,8 @@ discard block |
||
201 | 201 | * |
202 | 202 | * @return void |
203 | 203 | */ |
204 | - function widget_init(){ |
|
205 | - register_widget( $this->self ); |
|
204 | + function widget_init() { |
|
205 | + register_widget($this->self); |
|
206 | 206 | } |
207 | 207 | |
208 | 208 | /** |
@@ -213,7 +213,7 @@ discard block |
||
213 | 213 | * |
214 | 214 | * @return array |
215 | 215 | */ |
216 | - public function update( $new_instance, $old_instance ){ |
|
216 | + public function update($new_instance, $old_instance) { |
|
217 | 217 | $this->flush_widget_cache(); |
218 | 218 | |
219 | 219 | return $new_instance; |
@@ -224,8 +224,8 @@ discard block |
||
224 | 224 | * |
225 | 225 | * @return void |
226 | 226 | */ |
227 | - public function flush_widget_cache(){ |
|
228 | - wp_cache_delete( $this->self, 'widget' ); |
|
227 | + public function flush_widget_cache() { |
|
228 | + wp_cache_delete($this->self, 'widget'); |
|
229 | 229 | } |
230 | 230 | } |
231 | 231 |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | */ |
11 | 11 | |
12 | 12 | // Exit if accessed directly. |
13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
13 | +if ( ! defined('ABSPATH')) { |
|
14 | 14 | exit; |
15 | 15 | } |
16 | 16 | |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | * |
31 | 31 | * @since 1.0 |
32 | 32 | */ |
33 | - do_action( 'give_pre_process_donation' ); |
|
33 | + do_action('give_pre_process_donation'); |
|
34 | 34 | |
35 | 35 | // Validate the form $_POST data |
36 | 36 | $valid_data = give_purchase_form_validate_fields(); |
@@ -45,26 +45,26 @@ discard block |
||
45 | 45 | * @param bool|array $valid_data Validate fields. |
46 | 46 | * @param array $_POST Array of variables passed via the HTTP POST. |
47 | 47 | */ |
48 | - do_action( 'give_checkout_error_checks', $valid_data, $_POST ); |
|
48 | + do_action('give_checkout_error_checks', $valid_data, $_POST); |
|
49 | 49 | |
50 | - $is_ajax = isset( $_POST['give_ajax'] ); |
|
50 | + $is_ajax = isset($_POST['give_ajax']); |
|
51 | 51 | |
52 | 52 | // Process the login form |
53 | - if ( isset( $_POST['give_login_submit'] ) ) { |
|
53 | + if (isset($_POST['give_login_submit'])) { |
|
54 | 54 | give_process_form_login(); |
55 | 55 | } |
56 | 56 | |
57 | 57 | // Validate the user |
58 | - $user = give_get_purchase_form_user( $valid_data ); |
|
58 | + $user = give_get_purchase_form_user($valid_data); |
|
59 | 59 | |
60 | - if ( false === $valid_data || give_get_errors() || ! $user ) { |
|
61 | - if ( $is_ajax ) { |
|
60 | + if (false === $valid_data || give_get_errors() || ! $user) { |
|
61 | + if ($is_ajax) { |
|
62 | 62 | /** |
63 | 63 | * Fires when AJAX sends back errors from the donation form. |
64 | 64 | * |
65 | 65 | * @since 1.0 |
66 | 66 | */ |
67 | - do_action( 'give_ajax_donation_errors' ); |
|
67 | + do_action('give_ajax_donation_errors'); |
|
68 | 68 | give_die(); |
69 | 69 | } else { |
70 | 70 | return false; |
@@ -72,17 +72,17 @@ discard block |
||
72 | 72 | } |
73 | 73 | |
74 | 74 | // If AJAX send back success to proceed with form submission |
75 | - if ( $is_ajax ) { |
|
75 | + if ($is_ajax) { |
|
76 | 76 | echo 'success'; |
77 | 77 | give_die(); |
78 | 78 | } |
79 | 79 | |
80 | 80 | // After AJAX: Setup session if not using php_sessions |
81 | - if ( ! Give()->session->use_php_sessions() ) { |
|
81 | + if ( ! Give()->session->use_php_sessions()) { |
|
82 | 82 | // Double-check that set_cookie is publicly accessible; |
83 | 83 | // we're using a slightly modified class-wp-sessions.php |
84 | - $session_reflection = new ReflectionMethod( 'WP_Session', 'set_cookie' ); |
|
85 | - if ( $session_reflection->isPublic() ) { |
|
84 | + $session_reflection = new ReflectionMethod('WP_Session', 'set_cookie'); |
|
85 | + if ($session_reflection->isPublic()) { |
|
86 | 86 | // Manually set the cookie. |
87 | 87 | Give()->session->init()->set_cookie(); |
88 | 88 | } |
@@ -97,18 +97,18 @@ discard block |
||
97 | 97 | 'address' => $user['address'], |
98 | 98 | ); |
99 | 99 | |
100 | - $auth_key = defined( 'AUTH_KEY' ) ? AUTH_KEY : ''; |
|
100 | + $auth_key = defined('AUTH_KEY') ? AUTH_KEY : ''; |
|
101 | 101 | |
102 | - $price = isset( $_POST['give-amount'] ) ? (float) apply_filters( 'give_donation_total', give_sanitize_amount( give_format_amount( $_POST['give-amount'] ) ) ) : '0.00'; |
|
103 | - $purchase_key = strtolower( md5( $user['user_email'] . date( 'Y-m-d H:i:s' ) . $auth_key . uniqid( 'give', true ) ) ); |
|
102 | + $price = isset($_POST['give-amount']) ? (float) apply_filters('give_donation_total', give_sanitize_amount(give_format_amount($_POST['give-amount']))) : '0.00'; |
|
103 | + $purchase_key = strtolower(md5($user['user_email'].date('Y-m-d H:i:s').$auth_key.uniqid('give', true))); |
|
104 | 104 | |
105 | 105 | // Setup donation information |
106 | 106 | $purchase_data = array( |
107 | 107 | 'price' => $price, |
108 | 108 | 'purchase_key' => $purchase_key, |
109 | 109 | 'user_email' => $user['user_email'], |
110 | - 'date' => date( 'Y-m-d H:i:s', current_time( 'timestamp' ) ), |
|
111 | - 'user_info' => stripslashes_deep( $user_info ), |
|
110 | + 'date' => date('Y-m-d H:i:s', current_time('timestamp')), |
|
111 | + 'user_info' => stripslashes_deep($user_info), |
|
112 | 112 | 'post_data' => $_POST, |
113 | 113 | 'gateway' => $valid_data['gateway'], |
114 | 114 | 'card_info' => $valid_data['cc_info'], |
@@ -128,10 +128,10 @@ discard block |
||
128 | 128 | * @param array $user_info Array containing basic user information. |
129 | 129 | * @param bool|array $valid_data Validate fields. |
130 | 130 | */ |
131 | - do_action( 'give_checkout_before_gateway', $_POST, $user_info, $valid_data ); |
|
131 | + do_action('give_checkout_before_gateway', $_POST, $user_info, $valid_data); |
|
132 | 132 | |
133 | 133 | // Sanity check for price |
134 | - if ( ! $purchase_data['price'] ) { |
|
134 | + if ( ! $purchase_data['price']) { |
|
135 | 135 | // Revert to manual |
136 | 136 | $purchase_data['gateway'] = 'manual'; |
137 | 137 | $_POST['give-gateway'] = 'manual'; |
@@ -142,27 +142,27 @@ discard block |
||
142 | 142 | * |
143 | 143 | * @since 1.7 |
144 | 144 | */ |
145 | - $purchase_data = apply_filters( 'give_donation_data_before_gateway', $purchase_data, $valid_data ); |
|
145 | + $purchase_data = apply_filters('give_donation_data_before_gateway', $purchase_data, $valid_data); |
|
146 | 146 | |
147 | 147 | // Setup the data we're storing in the donation session |
148 | 148 | $session_data = $purchase_data; |
149 | 149 | |
150 | 150 | // Make sure credit card numbers are never stored in sessions |
151 | - unset( $session_data['card_info']['card_number'] ); |
|
152 | - unset( $session_data['post_data']['card_number'] ); |
|
151 | + unset($session_data['card_info']['card_number']); |
|
152 | + unset($session_data['post_data']['card_number']); |
|
153 | 153 | |
154 | 154 | // Used for showing data to non logged-in users after donation, and for other plugins needing donation data. |
155 | - give_set_purchase_session( $session_data ); |
|
155 | + give_set_purchase_session($session_data); |
|
156 | 156 | |
157 | 157 | // Send info to the gateway for payment processing |
158 | - give_send_to_gateway( $purchase_data['gateway'], $purchase_data ); |
|
158 | + give_send_to_gateway($purchase_data['gateway'], $purchase_data); |
|
159 | 159 | give_die(); |
160 | 160 | |
161 | 161 | } |
162 | 162 | |
163 | -add_action( 'give_purchase', 'give_process_purchase_form' ); |
|
164 | -add_action( 'wp_ajax_give_process_checkout', 'give_process_purchase_form' ); |
|
165 | -add_action( 'wp_ajax_nopriv_give_process_checkout', 'give_process_purchase_form' ); |
|
163 | +add_action('give_purchase', 'give_process_purchase_form'); |
|
164 | +add_action('wp_ajax_give_process_checkout', 'give_process_purchase_form'); |
|
165 | +add_action('wp_ajax_nopriv_give_process_checkout', 'give_process_purchase_form'); |
|
166 | 166 | |
167 | 167 | |
168 | 168 | /** |
@@ -175,26 +175,26 @@ discard block |
||
175 | 175 | * |
176 | 176 | * @return void |
177 | 177 | */ |
178 | -function give_checkout_check_existing_email( $valid_data, $post ) { |
|
178 | +function give_checkout_check_existing_email($valid_data, $post) { |
|
179 | 179 | |
180 | 180 | // Verify that the email address belongs to this customer. |
181 | - if ( is_user_logged_in() ) { |
|
181 | + if (is_user_logged_in()) { |
|
182 | 182 | |
183 | 183 | $email = $valid_data['logged_in_user']['user_email']; |
184 | - $customer = new Give_Customer( get_current_user_id(), true ); |
|
184 | + $customer = new Give_Customer(get_current_user_id(), true); |
|
185 | 185 | |
186 | 186 | // If this email address is not registered with this customer, see if it belongs to any other customer |
187 | - if ( $email !== $customer->email && ( is_array( $customer->emails ) && ! in_array( $email, $customer->emails ) ) ) { |
|
188 | - $found_customer = new Give_Customer( $email ); |
|
187 | + if ($email !== $customer->email && (is_array($customer->emails) && ! in_array($email, $customer->emails))) { |
|
188 | + $found_customer = new Give_Customer($email); |
|
189 | 189 | |
190 | - if ( $found_customer->id > 0 ) { |
|
191 | - give_set_error( 'give-customer-email-exists', sprintf( esc_html__( 'The email address %s is already in use.', 'give' ), $email ) ); |
|
190 | + if ($found_customer->id > 0) { |
|
191 | + give_set_error('give-customer-email-exists', sprintf(esc_html__('The email address %s is already in use.', 'give'), $email)); |
|
192 | 192 | } |
193 | 193 | } |
194 | 194 | } |
195 | 195 | } |
196 | 196 | |
197 | -add_action( 'give_checkout_error_checks', 'give_checkout_check_existing_email', 10, 2 ); |
|
197 | +add_action('give_checkout_error_checks', 'give_checkout_check_existing_email', 10, 2); |
|
198 | 198 | |
199 | 199 | /** |
200 | 200 | * Process the checkout login form |
@@ -205,37 +205,37 @@ discard block |
||
205 | 205 | */ |
206 | 206 | function give_process_form_login() { |
207 | 207 | |
208 | - $is_ajax = isset( $_POST['give_ajax'] ); |
|
208 | + $is_ajax = isset($_POST['give_ajax']); |
|
209 | 209 | |
210 | 210 | $user_data = give_purchase_form_validate_user_login(); |
211 | 211 | |
212 | - if ( give_get_errors() || $user_data['user_id'] < 1 ) { |
|
213 | - if ( $is_ajax ) { |
|
212 | + if (give_get_errors() || $user_data['user_id'] < 1) { |
|
213 | + if ($is_ajax) { |
|
214 | 214 | /** |
215 | 215 | * Fires when AJAX sends back errors from the donation form. |
216 | 216 | * |
217 | 217 | * @since 1.0 |
218 | 218 | */ |
219 | - do_action( 'give_ajax_donation_errors' ); |
|
219 | + do_action('give_ajax_donation_errors'); |
|
220 | 220 | give_die(); |
221 | 221 | } else { |
222 | - wp_redirect( $_SERVER['HTTP_REFERER'] ); |
|
222 | + wp_redirect($_SERVER['HTTP_REFERER']); |
|
223 | 223 | exit; |
224 | 224 | } |
225 | 225 | } |
226 | 226 | |
227 | - give_log_user_in( $user_data['user_id'], $user_data['user_login'], $user_data['user_pass'] ); |
|
227 | + give_log_user_in($user_data['user_id'], $user_data['user_login'], $user_data['user_pass']); |
|
228 | 228 | |
229 | - if ( $is_ajax ) { |
|
229 | + if ($is_ajax) { |
|
230 | 230 | echo 'success'; |
231 | 231 | give_die(); |
232 | 232 | } else { |
233 | - wp_redirect( $_SERVER['HTTP_REFERER'] ); |
|
233 | + wp_redirect($_SERVER['HTTP_REFERER']); |
|
234 | 234 | } |
235 | 235 | } |
236 | 236 | |
237 | -add_action( 'wp_ajax_give_process_checkout_login', 'give_process_form_login' ); |
|
238 | -add_action( 'wp_ajax_nopriv_give_process_checkout_login', 'give_process_form_login' ); |
|
237 | +add_action('wp_ajax_give_process_checkout_login', 'give_process_form_login'); |
|
238 | +add_action('wp_ajax_nopriv_give_process_checkout_login', 'give_process_form_login'); |
|
239 | 239 | |
240 | 240 | /** |
241 | 241 | * Donation Form Validate Fields |
@@ -247,44 +247,44 @@ discard block |
||
247 | 247 | function give_purchase_form_validate_fields() { |
248 | 248 | |
249 | 249 | // Check if there is $_POST |
250 | - if ( empty( $_POST ) ) { |
|
250 | + if (empty($_POST)) { |
|
251 | 251 | return false; |
252 | 252 | } |
253 | 253 | |
254 | - $form_id = isset( $_POST['give-form-id'] ) ? $_POST['give-form-id'] : ''; |
|
254 | + $form_id = isset($_POST['give-form-id']) ? $_POST['give-form-id'] : ''; |
|
255 | 255 | |
256 | 256 | // Start an array to collect valid data |
257 | 257 | $valid_data = array( |
258 | 258 | 'gateway' => give_purchase_form_validate_gateway(), // Gateway fallback (amount is validated here) |
259 | - 'need_new_user' => false, // New user flag |
|
260 | - 'need_user_login' => false, // Login user flag |
|
261 | - 'logged_user_data' => array(), // Logged user collected data |
|
262 | - 'new_user_data' => array(), // New user collected data |
|
263 | - 'login_user_data' => array(), // Login user collected data |
|
264 | - 'guest_user_data' => array(), // Guest user collected data |
|
265 | - 'cc_info' => give_purchase_form_validate_cc(),// Credit card info |
|
259 | + 'need_new_user' => false, // New user flag |
|
260 | + 'need_user_login' => false, // Login user flag |
|
261 | + 'logged_user_data' => array(), // Logged user collected data |
|
262 | + 'new_user_data' => array(), // New user collected data |
|
263 | + 'login_user_data' => array(), // Login user collected data |
|
264 | + 'guest_user_data' => array(), // Guest user collected data |
|
265 | + 'cc_info' => give_purchase_form_validate_cc(), // Credit card info |
|
266 | 266 | ); |
267 | 267 | |
268 | 268 | // Validate Honeypot First |
269 | - if ( ! empty( $_POST['give-honeypot'] ) ) { |
|
270 | - give_set_error( 'invalid_honeypot', esc_html__( 'Honeypot field detected. Go away bad bot!', 'give' ) ); |
|
269 | + if ( ! empty($_POST['give-honeypot'])) { |
|
270 | + give_set_error('invalid_honeypot', esc_html__('Honeypot field detected. Go away bad bot!', 'give')); |
|
271 | 271 | } |
272 | 272 | |
273 | 273 | // Validate agree to terms |
274 | - if ( give_is_terms_enabled( $form_id ) ) { |
|
274 | + if (give_is_terms_enabled($form_id)) { |
|
275 | 275 | give_purchase_form_validate_agree_to_terms(); |
276 | 276 | } |
277 | 277 | |
278 | - if ( is_user_logged_in() ) { |
|
278 | + if (is_user_logged_in()) { |
|
279 | 279 | // Collect logged in user data |
280 | 280 | $valid_data['logged_in_user'] = give_purchase_form_validate_logged_in_user(); |
281 | - } elseif ( isset( $_POST['give-purchase-var'] ) && $_POST['give-purchase-var'] == 'needs-to-register' ) { |
|
281 | + } elseif (isset($_POST['give-purchase-var']) && $_POST['give-purchase-var'] == 'needs-to-register') { |
|
282 | 282 | // Set new user registration as required |
283 | 283 | $valid_data['need_new_user'] = true; |
284 | 284 | // Validate new user data |
285 | 285 | $valid_data['new_user_data'] = give_purchase_form_validate_new_user(); |
286 | 286 | // Check if login validation is needed |
287 | - } elseif ( isset( $_POST['give-purchase-var'] ) && $_POST['give-purchase-var'] == 'needs-to-login' ) { |
|
287 | + } elseif (isset($_POST['give-purchase-var']) && $_POST['give-purchase-var'] == 'needs-to-login') { |
|
288 | 288 | // Set user login as required |
289 | 289 | $valid_data['need_user_login'] = true; |
290 | 290 | // Validate users login info |
@@ -309,41 +309,41 @@ discard block |
||
309 | 309 | */ |
310 | 310 | function give_purchase_form_validate_gateway() { |
311 | 311 | |
312 | - $form_id = isset( $_REQUEST['give-form-id'] ) ? $_REQUEST['give-form-id'] : 0; |
|
313 | - $amount = isset( $_REQUEST['give-amount'] ) ? give_sanitize_amount( $_REQUEST['give-amount'] ) : 0; |
|
314 | - $gateway = give_get_default_gateway( $form_id ); |
|
312 | + $form_id = isset($_REQUEST['give-form-id']) ? $_REQUEST['give-form-id'] : 0; |
|
313 | + $amount = isset($_REQUEST['give-amount']) ? give_sanitize_amount($_REQUEST['give-amount']) : 0; |
|
314 | + $gateway = give_get_default_gateway($form_id); |
|
315 | 315 | |
316 | 316 | // Check if a gateway value is present |
317 | - if ( ! empty( $_REQUEST['give-gateway'] ) ) { |
|
317 | + if ( ! empty($_REQUEST['give-gateway'])) { |
|
318 | 318 | |
319 | - $gateway = sanitize_text_field( $_REQUEST['give-gateway'] ); |
|
319 | + $gateway = sanitize_text_field($_REQUEST['give-gateway']); |
|
320 | 320 | |
321 | 321 | // Is amount being donated in LIVE mode 0.00? If so, error: |
322 | - if ( $amount == 0 && ! give_is_test_mode() ) { |
|
322 | + if ($amount == 0 && ! give_is_test_mode()) { |
|
323 | 323 | |
324 | - give_set_error( 'invalid_donation_amount', esc_html__( 'Please insert a valid donation amount.', 'give' ) ); |
|
324 | + give_set_error('invalid_donation_amount', esc_html__('Please insert a valid donation amount.', 'give')); |
|
325 | 325 | |
326 | 326 | } //Check for a minimum custom amount |
327 | - elseif ( ! give_verify_minimum_price() ) { |
|
327 | + elseif ( ! give_verify_minimum_price()) { |
|
328 | 328 | // translators: %s: minimum donation amount. |
329 | 329 | give_set_error( |
330 | 330 | 'invalid_donation_minimum', |
331 | 331 | sprintf( |
332 | 332 | /* translators: %s: minimum donation amount */ |
333 | - esc_html__( 'This form has a minimum donation amount of %s.', 'give' ), |
|
334 | - give_currency_filter( give_format_amount( give_get_form_minimum_price( $form_id ) ) ) |
|
333 | + esc_html__('This form has a minimum donation amount of %s.', 'give'), |
|
334 | + give_currency_filter(give_format_amount(give_get_form_minimum_price($form_id))) |
|
335 | 335 | ) |
336 | 336 | ); |
337 | 337 | |
338 | 338 | } //Is this test mode zero donation? Let it through but set to manual gateway. |
339 | - elseif ( $amount == 0 && give_is_test_mode() ) { |
|
339 | + elseif ($amount == 0 && give_is_test_mode()) { |
|
340 | 340 | |
341 | 341 | $gateway = 'manual'; |
342 | 342 | |
343 | 343 | } //Check if this gateway is active. |
344 | - elseif ( ! give_is_gateway_active( $gateway ) ) { |
|
344 | + elseif ( ! give_is_gateway_active($gateway)) { |
|
345 | 345 | |
346 | - give_set_error( 'invalid_gateway', esc_html__( 'The selected payment gateway is not enabled.', 'give' ) ); |
|
346 | + give_set_error('invalid_gateway', esc_html__('The selected payment gateway is not enabled.', 'give')); |
|
347 | 347 | |
348 | 348 | } |
349 | 349 | } |
@@ -361,23 +361,23 @@ discard block |
||
361 | 361 | */ |
362 | 362 | function give_verify_minimum_price() { |
363 | 363 | |
364 | - $amount = give_sanitize_amount( $_REQUEST['give-amount'] ); |
|
365 | - $form_id = isset( $_REQUEST['give-form-id'] ) ? $_REQUEST['give-form-id'] : 0; |
|
366 | - $price_id = isset( $_REQUEST['give-price-id'] ) ? $_REQUEST['give-price-id'] : 0; |
|
367 | - $variable_prices = give_has_variable_prices( $form_id ); |
|
364 | + $amount = give_sanitize_amount($_REQUEST['give-amount']); |
|
365 | + $form_id = isset($_REQUEST['give-form-id']) ? $_REQUEST['give-form-id'] : 0; |
|
366 | + $price_id = isset($_REQUEST['give-price-id']) ? $_REQUEST['give-price-id'] : 0; |
|
367 | + $variable_prices = give_has_variable_prices($form_id); |
|
368 | 368 | |
369 | - if ( $variable_prices && ! empty( $price_id ) ) { |
|
369 | + if ($variable_prices && ! empty($price_id)) { |
|
370 | 370 | |
371 | - $price_level_amount = give_get_price_option_amount( $form_id, $price_id ); |
|
371 | + $price_level_amount = give_get_price_option_amount($form_id, $price_id); |
|
372 | 372 | |
373 | - if ( $price_level_amount == $amount ) { |
|
373 | + if ($price_level_amount == $amount) { |
|
374 | 374 | return true; |
375 | 375 | } |
376 | 376 | } |
377 | 377 | |
378 | - $minimum = give_get_form_minimum_price( $form_id ); |
|
378 | + $minimum = give_get_form_minimum_price($form_id); |
|
379 | 379 | |
380 | - if ( $minimum > $amount ) { |
|
380 | + if ($minimum > $amount) { |
|
381 | 381 | return false; |
382 | 382 | } |
383 | 383 | |
@@ -393,9 +393,9 @@ discard block |
||
393 | 393 | */ |
394 | 394 | function give_purchase_form_validate_agree_to_terms() { |
395 | 395 | // Validate agree to terms. |
396 | - if ( ! isset( $_POST['give_agree_to_terms'] ) || $_POST['give_agree_to_terms'] != 1 ) { |
|
396 | + if ( ! isset($_POST['give_agree_to_terms']) || $_POST['give_agree_to_terms'] != 1) { |
|
397 | 397 | // User did not agree. |
398 | - give_set_error( 'agree_to_terms', apply_filters( 'give_agree_to_terms_text', esc_html__( 'You must agree to the terms and conditions.', 'give' ) ) ); |
|
398 | + give_set_error('agree_to_terms', apply_filters('give_agree_to_terms_text', esc_html__('You must agree to the terms and conditions.', 'give'))); |
|
399 | 399 | } |
400 | 400 | } |
401 | 401 | |
@@ -409,43 +409,43 @@ discard block |
||
409 | 409 | * |
410 | 410 | * @return array |
411 | 411 | */ |
412 | -function give_get_required_fields( $form_id ) { |
|
412 | +function give_get_required_fields($form_id) { |
|
413 | 413 | |
414 | - $payment_mode = give_get_chosen_gateway( $form_id ); |
|
414 | + $payment_mode = give_get_chosen_gateway($form_id); |
|
415 | 415 | |
416 | 416 | $required_fields = array( |
417 | 417 | 'give_email' => array( |
418 | 418 | 'error_id' => 'invalid_email', |
419 | - 'error_message' => esc_html__( 'Please enter a valid email address.', 'give' ), |
|
419 | + 'error_message' => esc_html__('Please enter a valid email address.', 'give'), |
|
420 | 420 | ), |
421 | 421 | 'give_first' => array( |
422 | 422 | 'error_id' => 'invalid_first_name', |
423 | - 'error_message' => esc_html__( 'Please enter your first name.', 'give' ), |
|
423 | + 'error_message' => esc_html__('Please enter your first name.', 'give'), |
|
424 | 424 | ), |
425 | 425 | ); |
426 | 426 | |
427 | - $require_address = give_require_billing_address( $payment_mode ); |
|
427 | + $require_address = give_require_billing_address($payment_mode); |
|
428 | 428 | |
429 | - if ( $require_address ) { |
|
430 | - $required_fields['card_address'] = array( |
|
429 | + if ($require_address) { |
|
430 | + $required_fields['card_address'] = array( |
|
431 | 431 | 'error_id' => 'invalid_card_address', |
432 | - 'error_message' => esc_html__( 'Please enter your primary billing address.', 'give' ), |
|
432 | + 'error_message' => esc_html__('Please enter your primary billing address.', 'give'), |
|
433 | 433 | ); |
434 | - $required_fields['card_zip'] = array( |
|
434 | + $required_fields['card_zip'] = array( |
|
435 | 435 | 'error_id' => 'invalid_zip_code', |
436 | - 'error_message' => esc_html__( 'Please enter your zip / postal code.', 'give' ), |
|
436 | + 'error_message' => esc_html__('Please enter your zip / postal code.', 'give'), |
|
437 | 437 | ); |
438 | - $required_fields['card_city'] = array( |
|
438 | + $required_fields['card_city'] = array( |
|
439 | 439 | 'error_id' => 'invalid_city', |
440 | - 'error_message' => esc_html__( 'Please enter your billing city.', 'give' ), |
|
440 | + 'error_message' => esc_html__('Please enter your billing city.', 'give'), |
|
441 | 441 | ); |
442 | 442 | $required_fields['billing_country'] = array( |
443 | 443 | 'error_id' => 'invalid_country', |
444 | - 'error_message' => esc_html__( 'Please select your billing country.', 'give' ), |
|
444 | + 'error_message' => esc_html__('Please select your billing country.', 'give'), |
|
445 | 445 | ); |
446 | - $required_fields['card_state'] = array( |
|
446 | + $required_fields['card_state'] = array( |
|
447 | 447 | 'error_id' => 'invalid_state', |
448 | - 'error_message' => esc_html__( 'Please enter billing state / province.', 'give' ), |
|
448 | + 'error_message' => esc_html__('Please enter billing state / province.', 'give'), |
|
449 | 449 | ); |
450 | 450 | } |
451 | 451 | |
@@ -454,7 +454,7 @@ discard block |
||
454 | 454 | * |
455 | 455 | * @since 1.7 |
456 | 456 | */ |
457 | - $required_fields = apply_filters( 'give_donation_form_required_fields', $required_fields, $form_id ); |
|
457 | + $required_fields = apply_filters('give_donation_form_required_fields', $required_fields, $form_id); |
|
458 | 458 | |
459 | 459 | return $required_fields; |
460 | 460 | |
@@ -469,16 +469,16 @@ discard block |
||
469 | 469 | * |
470 | 470 | * @return mixed|void |
471 | 471 | */ |
472 | -function give_require_billing_address( $payment_mode ) { |
|
472 | +function give_require_billing_address($payment_mode) { |
|
473 | 473 | |
474 | 474 | $return = false; |
475 | 475 | |
476 | - if ( isset( $_POST['billing_country'] ) || did_action( "give_{$payment_mode}_cc_form" ) || did_action( 'give_cc_form' ) ) { |
|
476 | + if (isset($_POST['billing_country']) || did_action("give_{$payment_mode}_cc_form") || did_action('give_cc_form')) { |
|
477 | 477 | $return = true; |
478 | 478 | } |
479 | 479 | |
480 | 480 | // Let payment gateways and other extensions determine if address fields should be required. |
481 | - return apply_filters( 'give_require_billing_address', $return ); |
|
481 | + return apply_filters('give_require_billing_address', $return); |
|
482 | 482 | |
483 | 483 | } |
484 | 484 | |
@@ -492,42 +492,42 @@ discard block |
||
492 | 492 | function give_purchase_form_validate_logged_in_user() { |
493 | 493 | global $user_ID; |
494 | 494 | |
495 | - $form_id = isset( $_POST['give-form-id'] ) ? $_POST['give-form-id'] : ''; |
|
495 | + $form_id = isset($_POST['give-form-id']) ? $_POST['give-form-id'] : ''; |
|
496 | 496 | |
497 | 497 | // Start empty array to collect valid user data. |
498 | 498 | $valid_user_data = array( |
499 | 499 | // Assume there will be errors. |
500 | - 'user_id' => - 1, |
|
500 | + 'user_id' => -1, |
|
501 | 501 | ); |
502 | 502 | |
503 | 503 | // Verify there is a user_ID. |
504 | - if ( $user_ID > 0 ) { |
|
504 | + if ($user_ID > 0) { |
|
505 | 505 | // Get the logged in user data. |
506 | - $user_data = get_userdata( $user_ID ); |
|
506 | + $user_data = get_userdata($user_ID); |
|
507 | 507 | |
508 | 508 | // Loop through required fields and show error messages. |
509 | - foreach ( give_get_required_fields( $form_id ) as $field_name => $value ) { |
|
510 | - if ( in_array( $value, give_get_required_fields( $form_id ) ) && empty( $_POST[ $field_name ] ) ) { |
|
511 | - give_set_error( $value['error_id'], $value['error_message'] ); |
|
509 | + foreach (give_get_required_fields($form_id) as $field_name => $value) { |
|
510 | + if (in_array($value, give_get_required_fields($form_id)) && empty($_POST[$field_name])) { |
|
511 | + give_set_error($value['error_id'], $value['error_message']); |
|
512 | 512 | } |
513 | 513 | } |
514 | 514 | |
515 | 515 | // Verify data. |
516 | - if ( $user_data ) { |
|
516 | + if ($user_data) { |
|
517 | 517 | // Collected logged in user data. |
518 | 518 | $valid_user_data = array( |
519 | 519 | 'user_id' => $user_ID, |
520 | - 'user_email' => isset( $_POST['give_email'] ) ? sanitize_email( $_POST['give_email'] ) : $user_data->user_email, |
|
521 | - 'user_first' => isset( $_POST['give_first'] ) && ! empty( $_POST['give_first'] ) ? sanitize_text_field( $_POST['give_first'] ) : $user_data->first_name, |
|
522 | - 'user_last' => isset( $_POST['give_last'] ) && ! empty( $_POST['give_last'] ) ? sanitize_text_field( $_POST['give_last'] ) : $user_data->last_name, |
|
520 | + 'user_email' => isset($_POST['give_email']) ? sanitize_email($_POST['give_email']) : $user_data->user_email, |
|
521 | + 'user_first' => isset($_POST['give_first']) && ! empty($_POST['give_first']) ? sanitize_text_field($_POST['give_first']) : $user_data->first_name, |
|
522 | + 'user_last' => isset($_POST['give_last']) && ! empty($_POST['give_last']) ? sanitize_text_field($_POST['give_last']) : $user_data->last_name, |
|
523 | 523 | ); |
524 | 524 | |
525 | - if ( ! is_email( $valid_user_data['user_email'] ) ) { |
|
526 | - give_set_error( 'email_invalid', esc_html__( 'Invalid email.', 'give' ) ); |
|
525 | + if ( ! is_email($valid_user_data['user_email'])) { |
|
526 | + give_set_error('email_invalid', esc_html__('Invalid email.', 'give')); |
|
527 | 527 | } |
528 | 528 | } else { |
529 | 529 | // Set invalid user error. |
530 | - give_set_error( 'invalid_user', esc_html__( 'The user information is invalid.', 'give' ) ); |
|
530 | + give_set_error('invalid_user', esc_html__('The user information is invalid.', 'give')); |
|
531 | 531 | } |
532 | 532 | } |
533 | 533 | |
@@ -546,7 +546,7 @@ discard block |
||
546 | 546 | // Default user data. |
547 | 547 | $default_user_data = array( |
548 | 548 | 'give-form-id' => '', |
549 | - 'user_id' => - 1, // Assume there will be errors. |
|
549 | + 'user_id' => -1, // Assume there will be errors. |
|
550 | 550 | 'user_first' => '', |
551 | 551 | 'user_last' => '', |
552 | 552 | 'give_user_login' => false, |
@@ -556,14 +556,14 @@ discard block |
||
556 | 556 | ); |
557 | 557 | |
558 | 558 | // Get user data. |
559 | - $user_data = wp_parse_args( array_map( 'trim', give_clean( $_POST ) ), $default_user_data ); |
|
559 | + $user_data = wp_parse_args(array_map('trim', give_clean($_POST)), $default_user_data); |
|
560 | 560 | $registering_new_user = false; |
561 | - $form_id = absint( $user_data['give-form-id'] ); |
|
561 | + $form_id = absint($user_data['give-form-id']); |
|
562 | 562 | |
563 | 563 | // Start an empty array to collect valid user data. |
564 | 564 | $valid_user_data = array( |
565 | 565 | // Assume there will be errors. |
566 | - 'user_id' => - 1, |
|
566 | + 'user_id' => -1, |
|
567 | 567 | |
568 | 568 | // Get first name. |
569 | 569 | 'user_first' => $user_data['give_first'], |
@@ -573,25 +573,25 @@ discard block |
||
573 | 573 | ); |
574 | 574 | |
575 | 575 | // Loop through required fields and show error messages. |
576 | - foreach ( give_get_required_fields( $form_id ) as $field_name => $value ) { |
|
577 | - if ( in_array( $value, give_get_required_fields( $form_id ) ) && empty( $_POST[ $field_name ] ) ) { |
|
578 | - give_set_error( $value['error_id'], $value['error_message'] ); |
|
576 | + foreach (give_get_required_fields($form_id) as $field_name => $value) { |
|
577 | + if (in_array($value, give_get_required_fields($form_id)) && empty($_POST[$field_name])) { |
|
578 | + give_set_error($value['error_id'], $value['error_message']); |
|
579 | 579 | } |
580 | 580 | } |
581 | 581 | |
582 | 582 | // Check if we have an username to register. |
583 | - if( give_validate_username( $user_data['give_user_login'] ) ) { |
|
583 | + if (give_validate_username($user_data['give_user_login'])) { |
|
584 | 584 | $registering_new_user = true; |
585 | 585 | $valid_user_data['user_login'] = $user_data['give_user_login']; |
586 | 586 | } |
587 | 587 | |
588 | 588 | // Check if we have an email to verify. |
589 | - if( give_validate_user_email( $user_data['give_email'], $registering_new_user ) ) { |
|
589 | + if (give_validate_user_email($user_data['give_email'], $registering_new_user)) { |
|
590 | 590 | $valid_user_data['user_email'] = $user_data['give_email']; |
591 | 591 | } |
592 | 592 | |
593 | 593 | // Check password. |
594 | - if( give_validate_user_password( $user_data['give_user_pass'], $user_data['give_user_pass_confirm'], $registering_new_user)){ |
|
594 | + if (give_validate_user_password($user_data['give_user_pass'], $user_data['give_user_pass_confirm'], $registering_new_user)) { |
|
595 | 595 | // All is good to go. |
596 | 596 | $valid_user_data['user_pass'] = $user_data['give_user_pass']; |
597 | 597 | } |
@@ -611,36 +611,36 @@ discard block |
||
611 | 611 | // Start an array to collect valid user data. |
612 | 612 | $valid_user_data = array( |
613 | 613 | // Assume there will be errors |
614 | - 'user_id' => - 1, |
|
614 | + 'user_id' => -1, |
|
615 | 615 | ); |
616 | 616 | |
617 | 617 | // Username. |
618 | - if ( ! isset( $_POST['give_user_login'] ) || $_POST['give_user_login'] == '' ) { |
|
619 | - give_set_error( 'must_log_in', esc_html__( 'You must register or login to complete your donation.', 'give' ) ); |
|
618 | + if ( ! isset($_POST['give_user_login']) || $_POST['give_user_login'] == '') { |
|
619 | + give_set_error('must_log_in', esc_html__('You must register or login to complete your donation.', 'give')); |
|
620 | 620 | |
621 | 621 | return $valid_user_data; |
622 | 622 | } |
623 | 623 | |
624 | 624 | // Get the user by login. |
625 | - $user_data = get_user_by( 'login', strip_tags( $_POST['give_user_login'] ) ); |
|
625 | + $user_data = get_user_by('login', strip_tags($_POST['give_user_login'])); |
|
626 | 626 | |
627 | 627 | // Check if user exists. |
628 | - if ( $user_data ) { |
|
628 | + if ($user_data) { |
|
629 | 629 | // Get password. |
630 | - $user_pass = isset( $_POST['give_user_pass'] ) ? $_POST['give_user_pass'] : false; |
|
630 | + $user_pass = isset($_POST['give_user_pass']) ? $_POST['give_user_pass'] : false; |
|
631 | 631 | |
632 | 632 | // Check user_pass. |
633 | - if ( $user_pass ) { |
|
633 | + if ($user_pass) { |
|
634 | 634 | // Check if password is valid. |
635 | - if ( ! wp_check_password( $user_pass, $user_data->user_pass, $user_data->ID ) ) { |
|
635 | + if ( ! wp_check_password($user_pass, $user_data->user_pass, $user_data->ID)) { |
|
636 | 636 | // Incorrect password. |
637 | 637 | give_set_error( |
638 | 638 | 'password_incorrect', |
639 | 639 | sprintf( |
640 | 640 | '%1$s <a href="%2$s">%3$s</a>', |
641 | - esc_html__( 'The password you entered is incorrect.', 'give' ), |
|
642 | - wp_lostpassword_url( "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]" ), |
|
643 | - esc_html__( 'Reset Password', 'give' ) |
|
641 | + esc_html__('The password you entered is incorrect.', 'give'), |
|
642 | + wp_lostpassword_url("http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"), |
|
643 | + esc_html__('Reset Password', 'give') |
|
644 | 644 | ) |
645 | 645 | ); |
646 | 646 | // All is correct. |
@@ -657,11 +657,11 @@ discard block |
||
657 | 657 | } |
658 | 658 | } else { |
659 | 659 | // Empty password. |
660 | - give_set_error( 'password_empty', esc_html__( 'Enter a password.', 'give' ) ); |
|
660 | + give_set_error('password_empty', esc_html__('Enter a password.', 'give')); |
|
661 | 661 | } |
662 | 662 | } else { |
663 | 663 | // No username. |
664 | - give_set_error( 'username_incorrect', esc_html__( 'The username you entered does not exist.', 'give' ) ); |
|
664 | + give_set_error('username_incorrect', esc_html__('The username you entered does not exist.', 'give')); |
|
665 | 665 | } |
666 | 666 | |
667 | 667 | return $valid_user_data; |
@@ -676,7 +676,7 @@ discard block |
||
676 | 676 | */ |
677 | 677 | function give_purchase_form_validate_guest_user() { |
678 | 678 | |
679 | - $form_id = isset( $_POST['give-form-id'] ) ? $_POST['give-form-id'] : ''; |
|
679 | + $form_id = isset($_POST['give-form-id']) ? $_POST['give-form-id'] : ''; |
|
680 | 680 | |
681 | 681 | // Start an array to collect valid user data. |
682 | 682 | $valid_user_data = array( |
@@ -685,38 +685,38 @@ discard block |
||
685 | 685 | ); |
686 | 686 | |
687 | 687 | // Show error message if user must be logged in. |
688 | - if ( give_logged_in_only( $form_id ) ) { |
|
689 | - give_set_error( 'logged_in_only', esc_html__( 'You must be logged in to donate.', 'give' ) ); |
|
688 | + if (give_logged_in_only($form_id)) { |
|
689 | + give_set_error('logged_in_only', esc_html__('You must be logged in to donate.', 'give')); |
|
690 | 690 | } |
691 | 691 | |
692 | 692 | // Get the guest email. |
693 | - $guest_email = isset( $_POST['give_email'] ) ? $_POST['give_email'] : false; |
|
693 | + $guest_email = isset($_POST['give_email']) ? $_POST['give_email'] : false; |
|
694 | 694 | |
695 | 695 | // Check email. |
696 | - if ( $guest_email && strlen( $guest_email ) > 0 ) { |
|
696 | + if ($guest_email && strlen($guest_email) > 0) { |
|
697 | 697 | // Validate email. |
698 | - if ( ! is_email( $guest_email ) ) { |
|
698 | + if ( ! is_email($guest_email)) { |
|
699 | 699 | // Invalid email. |
700 | - give_set_error( 'email_invalid', esc_html__( 'Invalid email.', 'give' ) ); |
|
700 | + give_set_error('email_invalid', esc_html__('Invalid email.', 'give')); |
|
701 | 701 | } else { |
702 | 702 | // All is good to go. |
703 | 703 | $valid_user_data['user_email'] = $guest_email; |
704 | 704 | |
705 | 705 | // Get user_id from donor if exist. |
706 | - $donor = new Give_Customer( $guest_email ); |
|
707 | - if ( $donor->id && $donor->user_id ) { |
|
706 | + $donor = new Give_Customer($guest_email); |
|
707 | + if ($donor->id && $donor->user_id) { |
|
708 | 708 | $valid_user_data['user_id'] = $donor->user_id; |
709 | 709 | } |
710 | 710 | } |
711 | 711 | } else { |
712 | 712 | // No email. |
713 | - give_set_error( 'email_empty', esc_html__( 'Enter an email.', 'give' ) ); |
|
713 | + give_set_error('email_empty', esc_html__('Enter an email.', 'give')); |
|
714 | 714 | } |
715 | 715 | |
716 | 716 | // Loop through required fields and show error messages. |
717 | - foreach ( give_get_required_fields( $form_id ) as $field_name => $value ) { |
|
718 | - if ( in_array( $value, give_get_required_fields( $form_id ) ) && empty( $_POST[ $field_name ] ) ) { |
|
719 | - give_set_error( $value['error_id'], $value['error_message'] ); |
|
717 | + foreach (give_get_required_fields($form_id) as $field_name => $value) { |
|
718 | + if (in_array($value, give_get_required_fields($form_id)) && empty($_POST[$field_name])) { |
|
719 | + give_set_error($value['error_id'], $value['error_message']); |
|
720 | 720 | } |
721 | 721 | } |
722 | 722 | |
@@ -732,36 +732,36 @@ discard block |
||
732 | 732 | * @since 1.0 |
733 | 733 | * @return integer |
734 | 734 | */ |
735 | -function give_register_and_login_new_user( $user_data = array() ) { |
|
735 | +function give_register_and_login_new_user($user_data = array()) { |
|
736 | 736 | // Verify the array. |
737 | - if ( empty( $user_data ) ) { |
|
738 | - return - 1; |
|
737 | + if (empty($user_data)) { |
|
738 | + return -1; |
|
739 | 739 | } |
740 | 740 | |
741 | - if ( give_get_errors() ) { |
|
742 | - return - 1; |
|
741 | + if (give_get_errors()) { |
|
742 | + return -1; |
|
743 | 743 | } |
744 | 744 | |
745 | - $user_args = apply_filters( 'give_insert_user_args', array( |
|
746 | - 'user_login' => isset( $user_data['user_login'] ) ? $user_data['user_login'] : '', |
|
747 | - 'user_pass' => isset( $user_data['user_pass'] ) ? $user_data['user_pass'] : '', |
|
748 | - 'user_email' => isset( $user_data['user_email'] ) ? $user_data['user_email'] : '', |
|
749 | - 'first_name' => isset( $user_data['user_first'] ) ? $user_data['user_first'] : '', |
|
750 | - 'last_name' => isset( $user_data['user_last'] ) ? $user_data['user_last'] : '', |
|
751 | - 'user_registered' => date( 'Y-m-d H:i:s' ), |
|
752 | - 'role' => get_option( 'default_role' ), |
|
753 | - ), $user_data ); |
|
745 | + $user_args = apply_filters('give_insert_user_args', array( |
|
746 | + 'user_login' => isset($user_data['user_login']) ? $user_data['user_login'] : '', |
|
747 | + 'user_pass' => isset($user_data['user_pass']) ? $user_data['user_pass'] : '', |
|
748 | + 'user_email' => isset($user_data['user_email']) ? $user_data['user_email'] : '', |
|
749 | + 'first_name' => isset($user_data['user_first']) ? $user_data['user_first'] : '', |
|
750 | + 'last_name' => isset($user_data['user_last']) ? $user_data['user_last'] : '', |
|
751 | + 'user_registered' => date('Y-m-d H:i:s'), |
|
752 | + 'role' => get_option('default_role'), |
|
753 | + ), $user_data); |
|
754 | 754 | |
755 | 755 | // Insert new user. |
756 | - $user_id = wp_insert_user( $user_args ); |
|
756 | + $user_id = wp_insert_user($user_args); |
|
757 | 757 | |
758 | 758 | // Validate inserted user. |
759 | - if ( is_wp_error( $user_id ) ) { |
|
760 | - return - 1; |
|
759 | + if (is_wp_error($user_id)) { |
|
760 | + return -1; |
|
761 | 761 | } |
762 | 762 | |
763 | 763 | // Allow themes and plugins to filter the user data. |
764 | - $user_data = apply_filters( 'give_insert_user_data', $user_data, $user_args ); |
|
764 | + $user_data = apply_filters('give_insert_user_data', $user_data, $user_args); |
|
765 | 765 | |
766 | 766 | /** |
767 | 767 | * Fires after inserting user. |
@@ -771,10 +771,10 @@ discard block |
||
771 | 771 | * @param int $user_id User id. |
772 | 772 | * @param array $user_data Array containing user data. |
773 | 773 | */ |
774 | - do_action( 'give_insert_user', $user_id, $user_data ); |
|
774 | + do_action('give_insert_user', $user_id, $user_data); |
|
775 | 775 | |
776 | 776 | // Login new user. |
777 | - give_log_user_in( $user_id, $user_data['user_login'], $user_data['user_pass'] ); |
|
777 | + give_log_user_in($user_id, $user_data['user_login'], $user_data['user_pass']); |
|
778 | 778 | |
779 | 779 | // Return user id. |
780 | 780 | return $user_id; |
@@ -789,27 +789,27 @@ discard block |
||
789 | 789 | * @since 1.0 |
790 | 790 | * @return array |
791 | 791 | */ |
792 | -function give_get_purchase_form_user( $valid_data = array() ) { |
|
792 | +function give_get_purchase_form_user($valid_data = array()) { |
|
793 | 793 | |
794 | 794 | // Initialize user. |
795 | 795 | $user = false; |
796 | - $is_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX; |
|
796 | + $is_ajax = defined('DOING_AJAX') && DOING_AJAX; |
|
797 | 797 | |
798 | - if ( $is_ajax ) { |
|
798 | + if ($is_ajax) { |
|
799 | 799 | // Do not create or login the user during the ajax submission (check for errors only). |
800 | 800 | return true; |
801 | - } elseif ( is_user_logged_in() ) { |
|
801 | + } elseif (is_user_logged_in()) { |
|
802 | 802 | // Set the valid user as the logged in collected data. |
803 | 803 | $user = $valid_data['logged_in_user']; |
804 | - } elseif ( $valid_data['need_new_user'] === true || $valid_data['need_user_login'] === true ) { |
|
804 | + } elseif ($valid_data['need_new_user'] === true || $valid_data['need_user_login'] === true) { |
|
805 | 805 | // New user registration. |
806 | - if ( $valid_data['need_new_user'] === true ) { |
|
806 | + if ($valid_data['need_new_user'] === true) { |
|
807 | 807 | // Set user. |
808 | 808 | $user = $valid_data['new_user_data']; |
809 | 809 | // Register and login new user. |
810 | - $user['user_id'] = give_register_and_login_new_user( $user ); |
|
810 | + $user['user_id'] = give_register_and_login_new_user($user); |
|
811 | 811 | // User login |
812 | - } elseif ( $valid_data['need_user_login'] === true && ! $is_ajax ) { |
|
812 | + } elseif ($valid_data['need_user_login'] === true && ! $is_ajax) { |
|
813 | 813 | |
814 | 814 | /* |
815 | 815 | * The login form is now processed in the give_process_purchase_login() function. |
@@ -822,48 +822,48 @@ discard block |
||
822 | 822 | // Set user. |
823 | 823 | $user = $valid_data['login_user_data']; |
824 | 824 | // Login user. |
825 | - give_log_user_in( $user['user_id'], $user['user_login'], $user['user_pass'] ); |
|
825 | + give_log_user_in($user['user_id'], $user['user_login'], $user['user_pass']); |
|
826 | 826 | } |
827 | 827 | } |
828 | 828 | |
829 | 829 | // Check guest checkout. |
830 | - if ( false === $user && false === give_logged_in_only( $_POST['give-form-id'] ) ) { |
|
830 | + if (false === $user && false === give_logged_in_only($_POST['give-form-id'])) { |
|
831 | 831 | // Set user |
832 | 832 | $user = $valid_data['guest_user_data']; |
833 | 833 | } |
834 | 834 | |
835 | 835 | // Verify we have an user. |
836 | - if ( false === $user || empty( $user ) ) { |
|
836 | + if (false === $user || empty($user)) { |
|
837 | 837 | // Return false. |
838 | 838 | return false; |
839 | 839 | } |
840 | 840 | |
841 | 841 | // Get user first name. |
842 | - if ( ! isset( $user['user_first'] ) || strlen( trim( $user['user_first'] ) ) < 1 ) { |
|
843 | - $user['user_first'] = isset( $_POST['give_first'] ) ? strip_tags( trim( $_POST['give_first'] ) ) : ''; |
|
842 | + if ( ! isset($user['user_first']) || strlen(trim($user['user_first'])) < 1) { |
|
843 | + $user['user_first'] = isset($_POST['give_first']) ? strip_tags(trim($_POST['give_first'])) : ''; |
|
844 | 844 | } |
845 | 845 | |
846 | 846 | // Get user last name. |
847 | - if ( ! isset( $user['user_last'] ) || strlen( trim( $user['user_last'] ) ) < 1 ) { |
|
848 | - $user['user_last'] = isset( $_POST['give_last'] ) ? strip_tags( trim( $_POST['give_last'] ) ) : ''; |
|
847 | + if ( ! isset($user['user_last']) || strlen(trim($user['user_last'])) < 1) { |
|
848 | + $user['user_last'] = isset($_POST['give_last']) ? strip_tags(trim($_POST['give_last'])) : ''; |
|
849 | 849 | } |
850 | 850 | |
851 | 851 | // Get the user's billing address details. |
852 | 852 | $user['address'] = array(); |
853 | - $user['address']['line1'] = ! empty( $_POST['card_address'] ) ? sanitize_text_field( $_POST['card_address'] ) : false; |
|
854 | - $user['address']['line2'] = ! empty( $_POST['card_address_2'] ) ? sanitize_text_field( $_POST['card_address_2'] ) : false; |
|
855 | - $user['address']['city'] = ! empty( $_POST['card_city'] ) ? sanitize_text_field( $_POST['card_city'] ) : false; |
|
856 | - $user['address']['state'] = ! empty( $_POST['card_state'] ) ? sanitize_text_field( $_POST['card_state'] ) : false; |
|
857 | - $user['address']['country'] = ! empty( $_POST['billing_country'] ) ? sanitize_text_field( $_POST['billing_country'] ) : false; |
|
858 | - $user['address']['zip'] = ! empty( $_POST['card_zip'] ) ? sanitize_text_field( $_POST['card_zip'] ) : false; |
|
859 | - |
|
860 | - if ( empty( $user['address']['country'] ) ) { |
|
853 | + $user['address']['line1'] = ! empty($_POST['card_address']) ? sanitize_text_field($_POST['card_address']) : false; |
|
854 | + $user['address']['line2'] = ! empty($_POST['card_address_2']) ? sanitize_text_field($_POST['card_address_2']) : false; |
|
855 | + $user['address']['city'] = ! empty($_POST['card_city']) ? sanitize_text_field($_POST['card_city']) : false; |
|
856 | + $user['address']['state'] = ! empty($_POST['card_state']) ? sanitize_text_field($_POST['card_state']) : false; |
|
857 | + $user['address']['country'] = ! empty($_POST['billing_country']) ? sanitize_text_field($_POST['billing_country']) : false; |
|
858 | + $user['address']['zip'] = ! empty($_POST['card_zip']) ? sanitize_text_field($_POST['card_zip']) : false; |
|
859 | + |
|
860 | + if (empty($user['address']['country'])) { |
|
861 | 861 | $user['address'] = false; |
862 | 862 | } // Country will always be set if address fields are present. |
863 | 863 | |
864 | - if ( ! empty( $user['user_id'] ) && $user['user_id'] > 0 && ! empty( $user['address'] ) ) { |
|
864 | + if ( ! empty($user['user_id']) && $user['user_id'] > 0 && ! empty($user['address'])) { |
|
865 | 865 | // Store the address in the user's meta so the donation form can be pre-populated with it on return purchases. |
866 | - update_user_meta( $user['user_id'], '_give_user_address', $user['address'] ); |
|
866 | + update_user_meta($user['user_id'], '_give_user_address', $user['address']); |
|
867 | 867 | } |
868 | 868 | |
869 | 869 | // Return valid user. |
@@ -882,16 +882,16 @@ discard block |
||
882 | 882 | $card_data = give_get_purchase_cc_info(); |
883 | 883 | |
884 | 884 | // Validate the card zip. |
885 | - if ( ! empty( $card_data['card_zip'] ) ) { |
|
886 | - if ( ! give_purchase_form_validate_cc_zip( $card_data['card_zip'], $card_data['card_country'] ) ) { |
|
887 | - give_set_error( 'invalid_cc_zip', esc_html__( 'The zip / postal code you entered for your billing address is invalid.', 'give' ) ); |
|
885 | + if ( ! empty($card_data['card_zip'])) { |
|
886 | + if ( ! give_purchase_form_validate_cc_zip($card_data['card_zip'], $card_data['card_country'])) { |
|
887 | + give_set_error('invalid_cc_zip', esc_html__('The zip / postal code you entered for your billing address is invalid.', 'give')); |
|
888 | 888 | } |
889 | 889 | } |
890 | 890 | |
891 | 891 | // Ensure no spaces. |
892 | - if ( ! empty( $card_data['card_number'] ) ) { |
|
893 | - $card_data['card_number'] = str_replace( '+', '', $card_data['card_number'] ); // no "+" signs |
|
894 | - $card_data['card_number'] = str_replace( ' ', '', $card_data['card_number'] ); // No spaces |
|
892 | + if ( ! empty($card_data['card_number'])) { |
|
893 | + $card_data['card_number'] = str_replace('+', '', $card_data['card_number']); // no "+" signs |
|
894 | + $card_data['card_number'] = str_replace(' ', '', $card_data['card_number']); // No spaces |
|
895 | 895 | } |
896 | 896 | |
897 | 897 | // This should validate card numbers at some point too. |
@@ -907,17 +907,17 @@ discard block |
||
907 | 907 | */ |
908 | 908 | function give_get_purchase_cc_info() { |
909 | 909 | $cc_info = array(); |
910 | - $cc_info['card_name'] = isset( $_POST['card_name'] ) ? sanitize_text_field( $_POST['card_name'] ) : ''; |
|
911 | - $cc_info['card_number'] = isset( $_POST['card_number'] ) ? sanitize_text_field( $_POST['card_number'] ) : ''; |
|
912 | - $cc_info['card_cvc'] = isset( $_POST['card_cvc'] ) ? sanitize_text_field( $_POST['card_cvc'] ) : ''; |
|
913 | - $cc_info['card_exp_month'] = isset( $_POST['card_exp_month'] ) ? sanitize_text_field( $_POST['card_exp_month'] ) : ''; |
|
914 | - $cc_info['card_exp_year'] = isset( $_POST['card_exp_year'] ) ? sanitize_text_field( $_POST['card_exp_year'] ) : ''; |
|
915 | - $cc_info['card_address'] = isset( $_POST['card_address'] ) ? sanitize_text_field( $_POST['card_address'] ) : ''; |
|
916 | - $cc_info['card_address_2'] = isset( $_POST['card_address_2'] ) ? sanitize_text_field( $_POST['card_address_2'] ) : ''; |
|
917 | - $cc_info['card_city'] = isset( $_POST['card_city'] ) ? sanitize_text_field( $_POST['card_city'] ) : ''; |
|
918 | - $cc_info['card_state'] = isset( $_POST['card_state'] ) ? sanitize_text_field( $_POST['card_state'] ) : ''; |
|
919 | - $cc_info['card_country'] = isset( $_POST['billing_country'] ) ? sanitize_text_field( $_POST['billing_country'] ) : ''; |
|
920 | - $cc_info['card_zip'] = isset( $_POST['card_zip'] ) ? sanitize_text_field( $_POST['card_zip'] ) : ''; |
|
910 | + $cc_info['card_name'] = isset($_POST['card_name']) ? sanitize_text_field($_POST['card_name']) : ''; |
|
911 | + $cc_info['card_number'] = isset($_POST['card_number']) ? sanitize_text_field($_POST['card_number']) : ''; |
|
912 | + $cc_info['card_cvc'] = isset($_POST['card_cvc']) ? sanitize_text_field($_POST['card_cvc']) : ''; |
|
913 | + $cc_info['card_exp_month'] = isset($_POST['card_exp_month']) ? sanitize_text_field($_POST['card_exp_month']) : ''; |
|
914 | + $cc_info['card_exp_year'] = isset($_POST['card_exp_year']) ? sanitize_text_field($_POST['card_exp_year']) : ''; |
|
915 | + $cc_info['card_address'] = isset($_POST['card_address']) ? sanitize_text_field($_POST['card_address']) : ''; |
|
916 | + $cc_info['card_address_2'] = isset($_POST['card_address_2']) ? sanitize_text_field($_POST['card_address_2']) : ''; |
|
917 | + $cc_info['card_city'] = isset($_POST['card_city']) ? sanitize_text_field($_POST['card_city']) : ''; |
|
918 | + $cc_info['card_state'] = isset($_POST['card_state']) ? sanitize_text_field($_POST['card_state']) : ''; |
|
919 | + $cc_info['card_country'] = isset($_POST['billing_country']) ? sanitize_text_field($_POST['billing_country']) : ''; |
|
920 | + $cc_info['card_zip'] = isset($_POST['card_zip']) ? sanitize_text_field($_POST['card_zip']) : ''; |
|
921 | 921 | |
922 | 922 | // Return cc info |
923 | 923 | return $cc_info; |
@@ -933,14 +933,14 @@ discard block |
||
933 | 933 | * |
934 | 934 | * @return bool|mixed|void |
935 | 935 | */ |
936 | -function give_purchase_form_validate_cc_zip( $zip = 0, $country_code = '' ) { |
|
936 | +function give_purchase_form_validate_cc_zip($zip = 0, $country_code = '') { |
|
937 | 937 | $ret = false; |
938 | 938 | |
939 | - if ( empty( $zip ) || empty( $country_code ) ) { |
|
939 | + if (empty($zip) || empty($country_code)) { |
|
940 | 940 | return $ret; |
941 | 941 | } |
942 | 942 | |
943 | - $country_code = strtoupper( $country_code ); |
|
943 | + $country_code = strtoupper($country_code); |
|
944 | 944 | |
945 | 945 | $zip_regex = array( |
946 | 946 | 'AD' => 'AD\d{3}', |
@@ -1100,11 +1100,11 @@ discard block |
||
1100 | 1100 | 'ZM' => '\d{5}', |
1101 | 1101 | ); |
1102 | 1102 | |
1103 | - if ( ! isset( $zip_regex[ $country_code ] ) || preg_match( '/' . $zip_regex[ $country_code ] . '/i', $zip ) ) { |
|
1103 | + if ( ! isset($zip_regex[$country_code]) || preg_match('/'.$zip_regex[$country_code].'/i', $zip)) { |
|
1104 | 1104 | $ret = true; |
1105 | 1105 | } |
1106 | 1106 | |
1107 | - return apply_filters( 'give_is_zip_valid', $ret, $zip, $country_code ); |
|
1107 | + return apply_filters('give_is_zip_valid', $ret, $zip, $country_code); |
|
1108 | 1108 | } |
1109 | 1109 | |
1110 | 1110 | |
@@ -1118,36 +1118,36 @@ discard block |
||
1118 | 1118 | * |
1119 | 1119 | * @return bool |
1120 | 1120 | */ |
1121 | -function give_validate_multi_donation_form_level( $valid_data, $data ) { |
|
1121 | +function give_validate_multi_donation_form_level($valid_data, $data) { |
|
1122 | 1122 | /* @var Give_Donate_Form $form */ |
1123 | - $form = new Give_Donate_Form( $data['give-form-id'] ); |
|
1123 | + $form = new Give_Donate_Form($data['give-form-id']); |
|
1124 | 1124 | |
1125 | 1125 | $donation_level_matched = false; |
1126 | 1126 | |
1127 | - if ( $form->is_multi_type_donation_form() ) { |
|
1127 | + if ($form->is_multi_type_donation_form()) { |
|
1128 | 1128 | |
1129 | 1129 | // Bailout. |
1130 | - if ( ! ( $variable_prices = $form->get_prices() ) ) { |
|
1130 | + if ( ! ($variable_prices = $form->get_prices())) { |
|
1131 | 1131 | return false; |
1132 | 1132 | } |
1133 | 1133 | |
1134 | 1134 | // Sanitize donation amount. |
1135 | - $data['give-amount'] = give_sanitize_amount( $data['give-amount'] ); |
|
1135 | + $data['give-amount'] = give_sanitize_amount($data['give-amount']); |
|
1136 | 1136 | |
1137 | 1137 | // Get number of decimals. |
1138 | 1138 | $default_decimals = give_get_price_decimals(); |
1139 | 1139 | |
1140 | - if ( $data['give-amount'] === give_sanitize_amount( give_get_price_option_amount( $data['give-form-id'], $data['give-price-id'] ), $default_decimals ) ) { |
|
1140 | + if ($data['give-amount'] === give_sanitize_amount(give_get_price_option_amount($data['give-form-id'], $data['give-price-id']), $default_decimals)) { |
|
1141 | 1141 | return true; |
1142 | 1142 | } |
1143 | 1143 | |
1144 | 1144 | // Find correct donation level from all donation levels. |
1145 | - foreach ( $variable_prices as $variable_price ) { |
|
1145 | + foreach ($variable_prices as $variable_price) { |
|
1146 | 1146 | // Sanitize level amount. |
1147 | - $variable_price['_give_amount'] = give_sanitize_amount( $variable_price['_give_amount'], $default_decimals ); |
|
1147 | + $variable_price['_give_amount'] = give_sanitize_amount($variable_price['_give_amount'], $default_decimals); |
|
1148 | 1148 | |
1149 | 1149 | // Set first match donation level ID. |
1150 | - if ( $data['give-amount'] === $variable_price['_give_amount'] ) { |
|
1150 | + if ($data['give-amount'] === $variable_price['_give_amount']) { |
|
1151 | 1151 | $_POST['give-price-id'] = $variable_price['_give_id']['level_id']; |
1152 | 1152 | $donation_level_matched = true; |
1153 | 1153 | break; |
@@ -1158,19 +1158,19 @@ discard block |
||
1158 | 1158 | // If yes then set price id to custom if amount is greater then custom minimum amount (if any). |
1159 | 1159 | if ( |
1160 | 1160 | ! $donation_level_matched |
1161 | - && ( give_is_setting_enabled( get_post_meta( $data['give-form-id'], '_give_custom_amount', true ) ) ) |
|
1161 | + && (give_is_setting_enabled(get_post_meta($data['give-form-id'], '_give_custom_amount', true))) |
|
1162 | 1162 | ) { |
1163 | 1163 | // Sanitize custom minimum amount. |
1164 | - $custom_minimum_amount = give_sanitize_amount( get_post_meta( $data['give-form-id'], '_give_custom_amount_minimum', true ), $default_decimals ); |
|
1164 | + $custom_minimum_amount = give_sanitize_amount(get_post_meta($data['give-form-id'], '_give_custom_amount_minimum', true), $default_decimals); |
|
1165 | 1165 | |
1166 | - if ( $data['give-amount'] >= $custom_minimum_amount ) { |
|
1166 | + if ($data['give-amount'] >= $custom_minimum_amount) { |
|
1167 | 1167 | $_POST['give-price-id'] = 'custom'; |
1168 | 1168 | $donation_level_matched = true; |
1169 | 1169 | } |
1170 | 1170 | } |
1171 | 1171 | } |
1172 | 1172 | |
1173 | - return ( $donation_level_matched ? true : false ); |
|
1173 | + return ($donation_level_matched ? true : false); |
|
1174 | 1174 | } |
1175 | 1175 | |
1176 | -add_action( 'give_checkout_error_checks', 'give_validate_multi_donation_form_level', 10, 2 ); |
|
1176 | +add_action('give_checkout_error_checks', 'give_validate_multi_donation_form_level', 10, 2); |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | */ |
11 | 11 | |
12 | 12 | // Exit if accessed directly. |
13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
13 | +if ( ! defined('ABSPATH')) { |
|
14 | 14 | exit; |
15 | 15 | } |
16 | 16 | |
@@ -33,11 +33,11 @@ discard block |
||
33 | 33 | /* @var WPDB $wpdb */ |
34 | 34 | global $wpdb; |
35 | 35 | |
36 | - $this->table_name = $wpdb->prefix . 'give_customermeta'; |
|
36 | + $this->table_name = $wpdb->prefix.'give_customermeta'; |
|
37 | 37 | $this->primary_key = 'meta_id'; |
38 | 38 | $this->version = '1.0'; |
39 | 39 | |
40 | - add_action( 'plugins_loaded', array( $this, 'register_table' ), 11 ); |
|
40 | + add_action('plugins_loaded', array($this, 'register_table'), 11); |
|
41 | 41 | |
42 | 42 | } |
43 | 43 | |
@@ -85,13 +85,13 @@ discard block |
||
85 | 85 | * |
86 | 86 | * @return mixed Will be an array if $single is false. Will be value of meta data field if $single is true. |
87 | 87 | */ |
88 | - public function get_meta( $customer_id = 0, $meta_key = '', $single = false ) { |
|
89 | - $customer_id = $this->sanitize_customer_id( $customer_id ); |
|
90 | - if ( false === $customer_id ) { |
|
88 | + public function get_meta($customer_id = 0, $meta_key = '', $single = false) { |
|
89 | + $customer_id = $this->sanitize_customer_id($customer_id); |
|
90 | + if (false === $customer_id) { |
|
91 | 91 | return false; |
92 | 92 | } |
93 | 93 | |
94 | - return get_metadata( 'customer', $customer_id, $meta_key, $single ); |
|
94 | + return get_metadata('customer', $customer_id, $meta_key, $single); |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | /** |
@@ -109,13 +109,13 @@ discard block |
||
109 | 109 | * |
110 | 110 | * @return bool False for failure. True for success. |
111 | 111 | */ |
112 | - public function add_meta( $customer_id = 0, $meta_key = '', $meta_value, $unique = false ) { |
|
113 | - $customer_id = $this->sanitize_customer_id( $customer_id ); |
|
114 | - if ( false === $customer_id ) { |
|
112 | + public function add_meta($customer_id = 0, $meta_key = '', $meta_value, $unique = false) { |
|
113 | + $customer_id = $this->sanitize_customer_id($customer_id); |
|
114 | + if (false === $customer_id) { |
|
115 | 115 | return false; |
116 | 116 | } |
117 | 117 | |
118 | - return add_metadata( 'customer', $customer_id, $meta_key, $meta_value, $unique ); |
|
118 | + return add_metadata('customer', $customer_id, $meta_key, $meta_value, $unique); |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | /** |
@@ -138,13 +138,13 @@ discard block |
||
138 | 138 | * |
139 | 139 | * @return bool False on failure, true if success. |
140 | 140 | */ |
141 | - public function update_meta( $customer_id = 0, $meta_key = '', $meta_value, $prev_value = '' ) { |
|
142 | - $customer_id = $this->sanitize_customer_id( $customer_id ); |
|
143 | - if ( false === $customer_id ) { |
|
141 | + public function update_meta($customer_id = 0, $meta_key = '', $meta_value, $prev_value = '') { |
|
142 | + $customer_id = $this->sanitize_customer_id($customer_id); |
|
143 | + if (false === $customer_id) { |
|
144 | 144 | return false; |
145 | 145 | } |
146 | 146 | |
147 | - return update_metadata( 'customer', $customer_id, $meta_key, $meta_value, $prev_value ); |
|
147 | + return update_metadata('customer', $customer_id, $meta_key, $meta_value, $prev_value); |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | /** |
@@ -165,8 +165,8 @@ discard block |
||
165 | 165 | * |
166 | 166 | * @return bool False for failure. True for success. |
167 | 167 | */ |
168 | - public function delete_meta( $customer_id = 0, $meta_key = '', $meta_value = '' ) { |
|
169 | - return delete_metadata( 'customer', $customer_id, $meta_key, $meta_value ); |
|
168 | + public function delete_meta($customer_id = 0, $meta_key = '', $meta_value = '') { |
|
169 | + return delete_metadata('customer', $customer_id, $meta_key, $meta_value); |
|
170 | 170 | } |
171 | 171 | |
172 | 172 | /** |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | */ |
180 | 180 | public function create_table() { |
181 | 181 | |
182 | - require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
182 | + require_once(ABSPATH.'wp-admin/includes/upgrade.php'); |
|
183 | 183 | |
184 | 184 | $sql = "CREATE TABLE {$this->table_name} ( |
185 | 185 | meta_id bigint(20) NOT NULL AUTO_INCREMENT, |
@@ -191,9 +191,9 @@ discard block |
||
191 | 191 | KEY meta_key (meta_key) |
192 | 192 | ) CHARACTER SET utf8 COLLATE utf8_general_ci;"; |
193 | 193 | |
194 | - dbDelta( $sql ); |
|
194 | + dbDelta($sql); |
|
195 | 195 | |
196 | - update_option( $this->table_name . '_db_version', $this->version ); |
|
196 | + update_option($this->table_name.'_db_version', $this->version); |
|
197 | 197 | } |
198 | 198 | |
199 | 199 | /** |
@@ -206,23 +206,23 @@ discard block |
||
206 | 206 | * |
207 | 207 | * @return int|bool The normalized customer ID or false if it's found to not be valid. |
208 | 208 | */ |
209 | - private function sanitize_customer_id( $customer_id ) { |
|
210 | - if ( ! is_numeric( $customer_id ) ) { |
|
209 | + private function sanitize_customer_id($customer_id) { |
|
210 | + if ( ! is_numeric($customer_id)) { |
|
211 | 211 | return false; |
212 | 212 | } |
213 | 213 | |
214 | 214 | $customer_id = (int) $customer_id; |
215 | 215 | |
216 | 216 | // We were given a non positive number |
217 | - if ( absint( $customer_id ) !== $customer_id ) { |
|
217 | + if (absint($customer_id) !== $customer_id) { |
|
218 | 218 | return false; |
219 | 219 | } |
220 | 220 | |
221 | - if ( empty( $customer_id ) ) { |
|
221 | + if (empty($customer_id)) { |
|
222 | 222 | return false; |
223 | 223 | } |
224 | 224 | |
225 | - return absint( $customer_id ); |
|
225 | + return absint($customer_id); |
|
226 | 226 | |
227 | 227 | } |
228 | 228 |