@@ -9,13 +9,13 @@ discard block |
||
9 | 9 | */ |
10 | 10 | |
11 | 11 | // Exit if accessed directly. |
12 | -if ( ! defined( 'ABSPATH' ) ) { |
|
12 | +if ( ! defined('ABSPATH')) { |
|
13 | 13 | exit; |
14 | 14 | } |
15 | 15 | |
16 | 16 | // Load WP_List_Table if not loaded. |
17 | -if ( ! class_exists( 'WP_List_Table' ) ) { |
|
18 | - require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
17 | +if ( ! class_exists('WP_List_Table')) { |
|
18 | + require_once ABSPATH.'wp-admin/includes/class-wp-list-table.php'; |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | /** |
@@ -44,11 +44,11 @@ discard block |
||
44 | 44 | */ |
45 | 45 | public function __construct() { |
46 | 46 | // Set parent defaults. |
47 | - parent::__construct( array( |
|
48 | - 'singular' => give_get_forms_label_singular(), // Singular name of the listed records. |
|
49 | - 'plural' => give_get_forms_label_plural(), // Plural name of the listed records. |
|
47 | + parent::__construct(array( |
|
48 | + 'singular' => give_get_forms_label_singular(), // Singular name of the listed records. |
|
49 | + 'plural' => give_get_forms_label_plural(), // Plural name of the listed records. |
|
50 | 50 | 'ajax' => false // Does this table support ajax?. |
51 | - ) ); |
|
51 | + )); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | /** |
@@ -62,19 +62,19 @@ discard block |
||
62 | 62 | * |
63 | 63 | * @return string Column Name. |
64 | 64 | */ |
65 | - public function column_default( $item, $column_name ) { |
|
65 | + public function column_default($item, $column_name) { |
|
66 | 66 | |
67 | - switch ( $column_name ) { |
|
67 | + switch ($column_name) { |
|
68 | 68 | case 'ID' : |
69 | 69 | return $item['ID_label']; |
70 | 70 | case 'payment_id' : |
71 | - return empty( $item['payment_id'] ) ? esc_html__( 'n/a', 'give' ) : sprintf( "<a href=\"%s\" target=\"_blank\">{$item['payment_id']}</a>", get_edit_post_link( $item['payment_id'] ) ); |
|
71 | + return empty($item['payment_id']) ? esc_html__('n/a', 'give') : sprintf("<a href=\"%s\" target=\"_blank\">{$item['payment_id']}</a>", get_edit_post_link($item['payment_id'])); |
|
72 | 72 | case 'gateway' : |
73 | - return empty( $item['gateway'] ) ? esc_html__( 'n/a', 'give' ) : $item['gateway']; |
|
73 | + return empty($item['gateway']) ? esc_html__('n/a', 'give') : $item['gateway']; |
|
74 | 74 | case 'error' : |
75 | - return get_the_title( $item['ID'] ) ? get_the_title( $item['ID'] ) : esc_html__( 'Payment Error', 'give' ); |
|
75 | + return get_the_title($item['ID']) ? get_the_title($item['ID']) : esc_html__('Payment Error', 'give'); |
|
76 | 76 | default: |
77 | - return $item[ $column_name ]; |
|
77 | + return $item[$column_name]; |
|
78 | 78 | } |
79 | 79 | } |
80 | 80 | |
@@ -88,27 +88,27 @@ discard block |
||
88 | 88 | * |
89 | 89 | * @return void |
90 | 90 | */ |
91 | - public function column_message( $item ) { ?> |
|
92 | - <a href="#TB_inline?width=640&inlineId=log-message-<?php echo $item['ID']; ?>" class="thickbox give-error-log-details-link button button-small" data-tooltip="<?php esc_attr_e( 'View Log Message', 'give' ); ?>"><span class="dashicons dashicons-visibility"></span></a> |
|
91 | + public function column_message($item) { ?> |
|
92 | + <a href="#TB_inline?width=640&inlineId=log-message-<?php echo $item['ID']; ?>" class="thickbox give-error-log-details-link button button-small" data-tooltip="<?php esc_attr_e('View Log Message', 'give'); ?>"><span class="dashicons dashicons-visibility"></span></a> |
|
93 | 93 | <div id="log-message-<?php echo $item['ID']; ?>" style="display:none;"> |
94 | 94 | <?php |
95 | 95 | |
96 | - $log_message = get_post_field( 'post_content', $item['ID'] ); |
|
96 | + $log_message = get_post_field('post_content', $item['ID']); |
|
97 | 97 | |
98 | - $serialized = strpos( $log_message, '{"' ); |
|
98 | + $serialized = strpos($log_message, '{"'); |
|
99 | 99 | |
100 | 100 | // Check to see if the log message contains serialized information |
101 | - if ( $serialized !== false ) { |
|
102 | - $length = strlen( $log_message ) - $serialized; |
|
103 | - $intro = substr( $log_message, 0, - $length ); |
|
104 | - $data = substr( $log_message, $serialized, strlen( $log_message ) - 1 ); |
|
101 | + if ($serialized !== false) { |
|
102 | + $length = strlen($log_message) - $serialized; |
|
103 | + $intro = substr($log_message, 0, - $length); |
|
104 | + $data = substr($log_message, $serialized, strlen($log_message) - 1); |
|
105 | 105 | |
106 | - echo wpautop( $intro ); |
|
107 | - echo wpautop( '<strong>' . esc_html__( 'Log data:', 'give' ) . '</strong>' ); |
|
108 | - echo '<div style="word-wrap: break-word;">' . wpautop( $data ) . '</div>'; |
|
106 | + echo wpautop($intro); |
|
107 | + echo wpautop('<strong>'.esc_html__('Log data:', 'give').'</strong>'); |
|
108 | + echo '<div style="word-wrap: break-word;">'.wpautop($data).'</div>'; |
|
109 | 109 | } else { |
110 | 110 | // No serialized data found |
111 | - echo wpautop( $log_message ); |
|
111 | + echo wpautop($log_message); |
|
112 | 112 | } |
113 | 113 | ?> |
114 | 114 | </div> |
@@ -124,12 +124,12 @@ discard block |
||
124 | 124 | */ |
125 | 125 | public function get_columns() { |
126 | 126 | $columns = array( |
127 | - 'ID' => esc_html__( 'Log ID', 'give' ), |
|
128 | - 'error' => esc_html__( 'Error', 'give' ), |
|
129 | - 'gateway' => esc_html__( 'Gateway', 'give' ), |
|
130 | - 'payment_id' => esc_html__( 'Donation ID', 'give' ), |
|
131 | - 'date' => esc_html__( 'Date', 'give' ), |
|
132 | - 'message' => esc_html__( 'Details', 'give' ) |
|
127 | + 'ID' => esc_html__('Log ID', 'give'), |
|
128 | + 'error' => esc_html__('Error', 'give'), |
|
129 | + 'gateway' => esc_html__('Gateway', 'give'), |
|
130 | + 'payment_id' => esc_html__('Donation ID', 'give'), |
|
131 | + 'date' => esc_html__('Date', 'give'), |
|
132 | + 'message' => esc_html__('Details', 'give') |
|
133 | 133 | ); |
134 | 134 | |
135 | 135 | return $columns; |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | * @return int Current page number |
144 | 144 | */ |
145 | 145 | public function get_paged() { |
146 | - return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
146 | + return isset($_GET['paged']) ? absint($_GET['paged']) : 1; |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | /** |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | * @since 1.0 |
154 | 154 | * @return void |
155 | 155 | */ |
156 | - public function bulk_actions( $which = '' ) { |
|
156 | + public function bulk_actions($which = '') { |
|
157 | 157 | give_log_views(); |
158 | 158 | } |
159 | 159 | |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | |
172 | 172 | // Prevent the queries from getting cached. |
173 | 173 | // Without this there are occasional memory issues for some installs. |
174 | - wp_suspend_cache_addition( true ); |
|
174 | + wp_suspend_cache_addition(true); |
|
175 | 175 | |
176 | 176 | $logs_data = array(); |
177 | 177 | $paged = $this->get_paged(); |
@@ -180,17 +180,17 @@ discard block |
||
180 | 180 | 'paged' => $paged |
181 | 181 | ); |
182 | 182 | |
183 | - $logs = $give_logs->get_connected_logs( $log_query ); |
|
183 | + $logs = $give_logs->get_connected_logs($log_query); |
|
184 | 184 | |
185 | - if ( $logs ) { |
|
186 | - foreach ( $logs as $log ) { |
|
185 | + if ($logs) { |
|
186 | + foreach ($logs as $log) { |
|
187 | 187 | |
188 | 188 | $logs_data[] = array( |
189 | 189 | 'ID' => $log->ID, |
190 | - 'ID_label' => '<span class=\'give-item-label give-item-label-gray\'>' . $log->ID . '</span>', |
|
190 | + 'ID_label' => '<span class=\'give-item-label give-item-label-gray\'>'.$log->ID.'</span>', |
|
191 | 191 | 'payment_id' => $log->post_parent, |
192 | 192 | 'error' => 'error', |
193 | - 'gateway' => give_get_payment_gateway( $log->post_parent ), |
|
193 | + 'gateway' => give_get_payment_gateway($log->post_parent), |
|
194 | 194 | 'date' => $log->post_date |
195 | 195 | ); |
196 | 196 | } |
@@ -212,19 +212,19 @@ discard block |
||
212 | 212 | * |
213 | 213 | * @param string $which |
214 | 214 | */ |
215 | - protected function display_tablenav( $which ) { |
|
216 | - if ( 'top' === $which ) { |
|
217 | - wp_nonce_field( 'bulk-' . $this->_args['plural'] ); |
|
215 | + protected function display_tablenav($which) { |
|
216 | + if ('top' === $which) { |
|
217 | + wp_nonce_field('bulk-'.$this->_args['plural']); |
|
218 | 218 | } |
219 | 219 | ?> |
220 | - <div class="tablenav <?php echo esc_attr( $which ); ?>"> |
|
220 | + <div class="tablenav <?php echo esc_attr($which); ?>"> |
|
221 | 221 | |
222 | 222 | <div class="alignleft actions bulkactions"> |
223 | - <?php $this->bulk_actions( $which ); ?> |
|
223 | + <?php $this->bulk_actions($which); ?> |
|
224 | 224 | </div> |
225 | 225 | <?php |
226 | - $this->extra_tablenav( $which ); |
|
227 | - $this->pagination( $which ); |
|
226 | + $this->extra_tablenav($which); |
|
227 | + $this->pagination($which); |
|
228 | 228 | ?> |
229 | 229 | |
230 | 230 | <br class="clear"/> |
@@ -251,14 +251,14 @@ discard block |
||
251 | 251 | $columns = $this->get_columns(); |
252 | 252 | $hidden = array(); // No hidden columns |
253 | 253 | $sortable = $this->get_sortable_columns(); |
254 | - $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
254 | + $this->_column_headers = array($columns, $hidden, $sortable); |
|
255 | 255 | $this->items = $this->get_logs(); |
256 | - $total_items = $give_logs->get_log_count( 0, 'gateway_error' ); |
|
256 | + $total_items = $give_logs->get_log_count(0, 'gateway_error'); |
|
257 | 257 | |
258 | - $this->set_pagination_args( array( |
|
258 | + $this->set_pagination_args(array( |
|
259 | 259 | 'total_items' => $total_items, |
260 | 260 | 'per_page' => $this->per_page, |
261 | - 'total_pages' => ceil( $total_items / $this->per_page ) |
|
261 | + 'total_pages' => ceil($total_items / $this->per_page) |
|
262 | 262 | ) |
263 | 263 | ); |
264 | 264 | } |
@@ -232,7 +232,7 @@ |
||
232 | 232 | * @since 1.0 |
233 | 233 | * @access public |
234 | 234 | * |
235 | - * @return bool |
|
235 | + * @return null|boolean |
|
236 | 236 | */ |
237 | 237 | public function check_for_token() { |
238 | 238 |
@@ -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 | |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | public function __construct() { |
97 | 97 | |
98 | 98 | // get it started |
99 | - add_action( 'init', array( $this, 'init' ) ); |
|
99 | + add_action('init', array($this, 'init')); |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | /** |
@@ -120,29 +120,29 @@ discard block |
||
120 | 120 | */ |
121 | 121 | if ( |
122 | 122 | is_user_logged_in() |
123 | - || ! give_is_setting_enabled( give_get_option( 'email_access' ) ) |
|
123 | + || ! give_is_setting_enabled(give_get_option('email_access')) |
|
124 | 124 | || is_admin() |
125 | 125 | ) { |
126 | 126 | return; |
127 | 127 | } |
128 | 128 | |
129 | 129 | // Are db columns setup? |
130 | - $is_setup = give_get_option( 'email_access_installed' ); |
|
131 | - if ( empty( $is_setup ) ) { |
|
130 | + $is_setup = give_get_option('email_access_installed'); |
|
131 | + if (empty($is_setup)) { |
|
132 | 132 | $this->create_columns(); |
133 | 133 | } |
134 | 134 | |
135 | 135 | // Timeouts. |
136 | - $this->verify_throttle = apply_filters( 'give_nl_verify_throttle', 300 ); |
|
137 | - $this->token_expiration = apply_filters( 'give_nl_token_expiration', 7200 ); |
|
136 | + $this->verify_throttle = apply_filters('give_nl_verify_throttle', 300); |
|
137 | + $this->token_expiration = apply_filters('give_nl_token_expiration', 7200); |
|
138 | 138 | |
139 | 139 | // Setup login. |
140 | 140 | $this->check_for_token(); |
141 | 141 | |
142 | - if ( $this->token_exists ) { |
|
143 | - add_filter( 'give_can_view_receipt', '__return_true' ); |
|
144 | - add_filter( 'give_user_pending_verification', '__return_false' ); |
|
145 | - add_filter( 'give_get_users_donations_args', array( $this, 'users_donations_args' ) ); |
|
142 | + if ($this->token_exists) { |
|
143 | + add_filter('give_can_view_receipt', '__return_true'); |
|
144 | + add_filter('give_user_pending_verification', '__return_false'); |
|
145 | + add_filter('give_get_users_donations_args', array($this, 'users_donations_args')); |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | } |
@@ -157,25 +157,25 @@ discard block |
||
157 | 157 | * |
158 | 158 | * @return bool |
159 | 159 | */ |
160 | - public function can_send_email( $customer_id ) { |
|
160 | + public function can_send_email($customer_id) { |
|
161 | 161 | /* @var WPDB $wpdb */ |
162 | 162 | global $wpdb; |
163 | 163 | |
164 | 164 | // Prevent multiple emails within X minutes |
165 | - $throttle = date( 'Y-m-d H:i:s', time() - $this->verify_throttle ); |
|
165 | + $throttle = date('Y-m-d H:i:s', time() - $this->verify_throttle); |
|
166 | 166 | |
167 | 167 | // Does a user row exist? |
168 | 168 | $exists = (int) $wpdb->get_var( |
169 | - $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->prefix}give_customers WHERE id = %d", $customer_id ) |
|
169 | + $wpdb->prepare("SELECT COUNT(*) FROM {$wpdb->prefix}give_customers WHERE id = %d", $customer_id) |
|
170 | 170 | ); |
171 | 171 | |
172 | - if ( 0 < $exists ) { |
|
172 | + if (0 < $exists) { |
|
173 | 173 | $row_id = (int) $wpdb->get_var( |
174 | - $wpdb->prepare( "SELECT id FROM {$wpdb->prefix}give_customers WHERE id = %d AND (verify_throttle < %s OR verify_key = '') LIMIT 1", $customer_id, $throttle ) |
|
174 | + $wpdb->prepare("SELECT id FROM {$wpdb->prefix}give_customers WHERE id = %d AND (verify_throttle < %s OR verify_key = '') LIMIT 1", $customer_id, $throttle) |
|
175 | 175 | ); |
176 | 176 | |
177 | - if ( $row_id < 1 ) { |
|
178 | - give_set_error( 'give_email_access_attempts_exhausted', __( 'Please wait a few minutes before requesting a new email access link.', 'give' ) ); |
|
177 | + if ($row_id < 1) { |
|
178 | + give_set_error('give_email_access_attempts_exhausted', __('Please wait a few minutes before requesting a new email access link.', 'give')); |
|
179 | 179 | |
180 | 180 | return false; |
181 | 181 | } |
@@ -195,34 +195,34 @@ discard block |
||
195 | 195 | * |
196 | 196 | * @return void |
197 | 197 | */ |
198 | - public function send_email( $customer_id, $email ) { |
|
198 | + public function send_email($customer_id, $email) { |
|
199 | 199 | |
200 | - $verify_key = wp_generate_password( 20, false ); |
|
200 | + $verify_key = wp_generate_password(20, false); |
|
201 | 201 | |
202 | 202 | // Generate a new verify key |
203 | - $this->set_verify_key( $customer_id, $email, $verify_key ); |
|
203 | + $this->set_verify_key($customer_id, $email, $verify_key); |
|
204 | 204 | |
205 | 205 | // Get the donation history page |
206 | - $page_id = give_get_option( 'history_page' ); |
|
206 | + $page_id = give_get_option('history_page'); |
|
207 | 207 | |
208 | - $access_url = add_query_arg( array( |
|
208 | + $access_url = add_query_arg(array( |
|
209 | 209 | 'give_nl' => $verify_key, |
210 | - ), get_permalink( $page_id ) ); |
|
210 | + ), get_permalink($page_id)); |
|
211 | 211 | |
212 | 212 | // Nice subject and message. |
213 | - $subject = apply_filters( 'give_email_access_token_subject', sprintf( __( 'Your Access Link to %s', 'give' ), get_bloginfo( 'name' ) ) ); |
|
213 | + $subject = apply_filters('give_email_access_token_subject', sprintf(__('Your Access Link to %s', 'give'), get_bloginfo('name'))); |
|
214 | 214 | |
215 | - $message = __( 'You or someone in your organization requested an access link be sent to this email address. This is a temporary access link for you to view your donation information. Click on the link below to view:', 'give' ) . "\n\n"; |
|
216 | - $message .= '<a href="' . esc_url( $access_url ) . '" target="_blank">' . __( 'Access Donation Details »', 'give' ) . '</a>' . "\n\n"; |
|
215 | + $message = __('You or someone in your organization requested an access link be sent to this email address. This is a temporary access link for you to view your donation information. Click on the link below to view:', 'give')."\n\n"; |
|
216 | + $message .= '<a href="'.esc_url($access_url).'" target="_blank">'.__('Access Donation Details »', 'give').'</a>'."\n\n"; |
|
217 | 217 | $message .= "\n\n"; |
218 | - $message .= __( 'Sincerely,', 'give' ) . "\n"; |
|
219 | - $message .= get_bloginfo( 'name' ) . "\n"; |
|
218 | + $message .= __('Sincerely,', 'give')."\n"; |
|
219 | + $message .= get_bloginfo('name')."\n"; |
|
220 | 220 | |
221 | - $message = apply_filters( 'give_email_access_token_message', $message ); |
|
221 | + $message = apply_filters('give_email_access_token_message', $message); |
|
222 | 222 | |
223 | 223 | // Send the email. |
224 | - Give()->emails->__set( 'heading', apply_filters( 'give_email_access_token_heading', __( 'Your Access Link', 'give' ) ) ); |
|
225 | - Give()->emails->send( $email, $subject, $message ); |
|
224 | + Give()->emails->__set('heading', apply_filters('give_email_access_token_heading', __('Your Access Link', 'give'))); |
|
225 | + Give()->emails->send($email, $subject, $message); |
|
226 | 226 | |
227 | 227 | } |
228 | 228 | |
@@ -236,26 +236,26 @@ discard block |
||
236 | 236 | */ |
237 | 237 | public function check_for_token() { |
238 | 238 | |
239 | - $token = isset( $_GET['give_nl'] ) ? $_GET['give_nl'] : ''; |
|
239 | + $token = isset($_GET['give_nl']) ? $_GET['give_nl'] : ''; |
|
240 | 240 | |
241 | 241 | // Check for cookie. |
242 | - if ( empty( $token ) ) { |
|
243 | - $token = isset( $_COOKIE['give_nl'] ) ? $_COOKIE['give_nl'] : ''; |
|
242 | + if (empty($token)) { |
|
243 | + $token = isset($_COOKIE['give_nl']) ? $_COOKIE['give_nl'] : ''; |
|
244 | 244 | } |
245 | 245 | |
246 | 246 | // Must have a token. |
247 | - if ( ! empty( $token ) ) { |
|
247 | + if ( ! empty($token)) { |
|
248 | 248 | |
249 | - if ( ! $this->is_valid_token( $token ) ) { |
|
250 | - if ( ! $this->is_valid_verify_key( $token ) ) { |
|
249 | + if ( ! $this->is_valid_token($token)) { |
|
250 | + if ( ! $this->is_valid_verify_key($token)) { |
|
251 | 251 | return; |
252 | 252 | } |
253 | 253 | } |
254 | 254 | |
255 | 255 | $this->token_exists = true; |
256 | 256 | // Set cookie. |
257 | - $lifetime = current_time( 'timestamp' ) + Give()->session->set_expiration_time(); |
|
258 | - @setcookie( 'give_nl', $token, $lifetime, COOKIEPATH, COOKIE_DOMAIN, false ); |
|
257 | + $lifetime = current_time('timestamp') + Give()->session->set_expiration_time(); |
|
258 | + @setcookie('give_nl', $token, $lifetime, COOKIEPATH, COOKIE_DOMAIN, false); |
|
259 | 259 | |
260 | 260 | return true; |
261 | 261 | } |
@@ -271,26 +271,26 @@ discard block |
||
271 | 271 | * |
272 | 272 | * @return bool |
273 | 273 | */ |
274 | - public function is_valid_token( $token ) { |
|
274 | + public function is_valid_token($token) { |
|
275 | 275 | |
276 | 276 | global $wpdb; |
277 | 277 | |
278 | 278 | // Make sure token isn't expired. |
279 | - $expires = date( 'Y-m-d H:i:s', time() - $this->token_expiration ); |
|
279 | + $expires = date('Y-m-d H:i:s', time() - $this->token_expiration); |
|
280 | 280 | |
281 | 281 | $email = $wpdb->get_var( |
282 | - $wpdb->prepare( "SELECT email FROM {$wpdb->prefix}give_customers WHERE token = %s AND verify_throttle >= %s LIMIT 1", $token, $expires ) |
|
282 | + $wpdb->prepare("SELECT email FROM {$wpdb->prefix}give_customers WHERE token = %s AND verify_throttle >= %s LIMIT 1", $token, $expires) |
|
283 | 283 | ); |
284 | 284 | |
285 | - if ( ! empty( $email ) ) { |
|
285 | + if ( ! empty($email)) { |
|
286 | 286 | $this->token_email = $email; |
287 | 287 | $this->token = $token; |
288 | 288 | return true; |
289 | 289 | } |
290 | 290 | |
291 | 291 | // Set error only if email access form isn't being submitted |
292 | - if ( ! isset( $_POST['give_email'] ) && ! isset( $_POST['_wpnonce'] ) ) { |
|
293 | - give_set_error( 'give_email_token_expired', apply_filters( 'give_email_token_expired_message', __( 'Your access token has expired. Please request a new one below:', 'give' ) ) ); |
|
292 | + if ( ! isset($_POST['give_email']) && ! isset($_POST['_wpnonce'])) { |
|
293 | + give_set_error('give_email_token_expired', apply_filters('give_email_token_expired_message', __('Your access token has expired. Please request a new one below:', 'give'))); |
|
294 | 294 | } |
295 | 295 | |
296 | 296 | return false; |
@@ -309,25 +309,25 @@ discard block |
||
309 | 309 | * |
310 | 310 | * @return void |
311 | 311 | */ |
312 | - public function set_verify_key( $customer_id, $email, $verify_key ) { |
|
312 | + public function set_verify_key($customer_id, $email, $verify_key) { |
|
313 | 313 | global $wpdb; |
314 | 314 | |
315 | - $now = date( 'Y-m-d H:i:s' ); |
|
315 | + $now = date('Y-m-d H:i:s'); |
|
316 | 316 | |
317 | 317 | // Insert or update? |
318 | 318 | $row_id = (int) $wpdb->get_var( |
319 | - $wpdb->prepare( "SELECT id FROM {$wpdb->prefix}give_customers WHERE id = %d LIMIT 1", $customer_id ) |
|
319 | + $wpdb->prepare("SELECT id FROM {$wpdb->prefix}give_customers WHERE id = %d LIMIT 1", $customer_id) |
|
320 | 320 | ); |
321 | 321 | |
322 | 322 | // Update. |
323 | - if ( ! empty( $row_id ) ) { |
|
323 | + if ( ! empty($row_id)) { |
|
324 | 324 | $wpdb->query( |
325 | - $wpdb->prepare( "UPDATE {$wpdb->prefix}give_customers SET verify_key = %s, verify_throttle = %s WHERE id = %d LIMIT 1", $verify_key, $now, $row_id ) |
|
325 | + $wpdb->prepare("UPDATE {$wpdb->prefix}give_customers SET verify_key = %s, verify_throttle = %s WHERE id = %d LIMIT 1", $verify_key, $now, $row_id) |
|
326 | 326 | ); |
327 | 327 | } // Insert. |
328 | 328 | else { |
329 | 329 | $wpdb->query( |
330 | - $wpdb->prepare( "INSERT INTO {$wpdb->prefix}give_customers ( verify_key, verify_throttle) VALUES (%s, %s)", $verify_key, $now ) |
|
330 | + $wpdb->prepare("INSERT INTO {$wpdb->prefix}give_customers ( verify_key, verify_throttle) VALUES (%s, %s)", $verify_key, $now) |
|
331 | 331 | ); |
332 | 332 | } |
333 | 333 | } |
@@ -342,21 +342,21 @@ discard block |
||
342 | 342 | * |
343 | 343 | * @return bool |
344 | 344 | */ |
345 | - public function is_valid_verify_key( $token ) { |
|
345 | + public function is_valid_verify_key($token) { |
|
346 | 346 | /* @var WPDB $wpdb */ |
347 | 347 | global $wpdb; |
348 | 348 | |
349 | 349 | // See if the verify_key exists. |
350 | 350 | $row = $wpdb->get_row( |
351 | - $wpdb->prepare( "SELECT id, email FROM {$wpdb->prefix}give_customers WHERE verify_key = %s LIMIT 1", $token ) |
|
351 | + $wpdb->prepare("SELECT id, email FROM {$wpdb->prefix}give_customers WHERE verify_key = %s LIMIT 1", $token) |
|
352 | 352 | ); |
353 | 353 | |
354 | - $now = date( 'Y-m-d H:i:s' ); |
|
354 | + $now = date('Y-m-d H:i:s'); |
|
355 | 355 | |
356 | 356 | // Set token and remove verify key. |
357 | - if ( ! empty( $row ) ) { |
|
357 | + if ( ! empty($row)) { |
|
358 | 358 | $wpdb->query( |
359 | - $wpdb->prepare( "UPDATE {$wpdb->prefix}give_customers SET verify_key = '', token = %s, verify_throttle = %s WHERE id = %d LIMIT 1", $token, $now, $row->id ) |
|
359 | + $wpdb->prepare("UPDATE {$wpdb->prefix}give_customers SET verify_key = '', token = %s, verify_throttle = %s WHERE id = %d LIMIT 1", $token, $now, $row->id) |
|
360 | 360 | ); |
361 | 361 | |
362 | 362 | $this->token_email = $row->email; |
@@ -380,7 +380,7 @@ discard block |
||
380 | 380 | * |
381 | 381 | * @return mixed |
382 | 382 | */ |
383 | - public function users_donations_args( $args ) { |
|
383 | + public function users_donations_args($args) { |
|
384 | 384 | $args['user'] = $this->token_email; |
385 | 385 | |
386 | 386 | return $args; |
@@ -401,11 +401,11 @@ discard block |
||
401 | 401 | global $wpdb; |
402 | 402 | |
403 | 403 | // Create columns in customers table |
404 | - $query = $wpdb->query( "ALTER TABLE {$wpdb->prefix}give_customers ADD `token` VARCHAR(255) CHARACTER SET utf8 NOT NULL, ADD `verify_key` VARCHAR(255) CHARACTER SET utf8 NOT NULL AFTER `token`, ADD `verify_throttle` DATETIME NOT NULL AFTER `verify_key`" ); |
|
404 | + $query = $wpdb->query("ALTER TABLE {$wpdb->prefix}give_customers ADD `token` VARCHAR(255) CHARACTER SET utf8 NOT NULL, ADD `verify_key` VARCHAR(255) CHARACTER SET utf8 NOT NULL AFTER `token`, ADD `verify_throttle` DATETIME NOT NULL AFTER `verify_key`"); |
|
405 | 405 | |
406 | 406 | // Columns added properly |
407 | - if ( $query ) { |
|
408 | - give_update_option( 'email_access_installed', 1 ); |
|
407 | + if ($query) { |
|
408 | + give_update_option('email_access_installed', 1); |
|
409 | 409 | } |
410 | 410 | |
411 | 411 | } |
@@ -77,7 +77,7 @@ |
||
77 | 77 | * @uses api_request() |
78 | 78 | * |
79 | 79 | * @param array $_transient_data Update array build by WordPress. |
80 | - * @return array Modified update array with custom plugin data. |
|
80 | + * @return stdClass Modified update array with custom plugin data. |
|
81 | 81 | */ |
82 | 82 | public function check_update( $_transient_data ) { |
83 | 83 |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | // Exit if accessed directly |
4 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
4 | +if ( ! defined('ABSPATH')) exit; |
|
5 | 5 | |
6 | 6 | /** |
7 | 7 | * Allows plugins to use their own update API. |
@@ -29,20 +29,20 @@ discard block |
||
29 | 29 | * @param string $_plugin_file Path to the plugin file. |
30 | 30 | * @param array $_api_data Optional data to send with API calls. |
31 | 31 | */ |
32 | - public function __construct( $_api_url, $_plugin_file, $_api_data = null ) { |
|
32 | + public function __construct($_api_url, $_plugin_file, $_api_data = null) { |
|
33 | 33 | |
34 | 34 | global $edd_plugin_data; |
35 | 35 | |
36 | - $this->api_url = trailingslashit( $_api_url ); |
|
36 | + $this->api_url = trailingslashit($_api_url); |
|
37 | 37 | $this->api_data = $_api_data; |
38 | - $this->name = plugin_basename( $_plugin_file ); |
|
39 | - $this->slug = basename( $_plugin_file, '.php' ); |
|
38 | + $this->name = plugin_basename($_plugin_file); |
|
39 | + $this->slug = basename($_plugin_file, '.php'); |
|
40 | 40 | $this->version = $_api_data['version']; |
41 | - $this->wp_override = isset( $_api_data['wp_override'] ) ? (bool) $_api_data['wp_override'] : false; |
|
42 | - $this->beta = ! empty( $this->api_data['beta'] ) ? true : false; |
|
43 | - $this->cache_key = md5( serialize( $this->slug . $this->api_data['license'] . $this->beta ) ); |
|
41 | + $this->wp_override = isset($_api_data['wp_override']) ? (bool) $_api_data['wp_override'] : false; |
|
42 | + $this->beta = ! empty($this->api_data['beta']) ? true : false; |
|
43 | + $this->cache_key = md5(serialize($this->slug.$this->api_data['license'].$this->beta)); |
|
44 | 44 | |
45 | - $edd_plugin_data[ $this->slug ] = $this->api_data; |
|
45 | + $edd_plugin_data[$this->slug] = $this->api_data; |
|
46 | 46 | |
47 | 47 | // Set up hooks. |
48 | 48 | $this->init(); |
@@ -58,11 +58,11 @@ discard block |
||
58 | 58 | */ |
59 | 59 | public function init() { |
60 | 60 | |
61 | - add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ) ); |
|
62 | - add_filter( 'plugins_api', array( $this, 'plugins_api_filter' ), 10, 3 ); |
|
63 | - remove_action( 'after_plugin_row_' . $this->name, 'wp_plugin_update_row', 10 ); |
|
64 | - add_action( 'after_plugin_row_' . $this->name, array( $this, 'show_update_notification' ), 10, 2 ); |
|
65 | - add_action( 'admin_init', array( $this, 'show_changelog' ) ); |
|
61 | + add_filter('pre_set_site_transient_update_plugins', array($this, 'check_update')); |
|
62 | + add_filter('plugins_api', array($this, 'plugins_api_filter'), 10, 3); |
|
63 | + remove_action('after_plugin_row_'.$this->name, 'wp_plugin_update_row', 10); |
|
64 | + add_action('after_plugin_row_'.$this->name, array($this, 'show_update_notification'), 10, 2); |
|
65 | + add_action('admin_init', array($this, 'show_changelog')); |
|
66 | 66 | |
67 | 67 | } |
68 | 68 | |
@@ -79,41 +79,41 @@ discard block |
||
79 | 79 | * @param array $_transient_data Update array build by WordPress. |
80 | 80 | * @return array Modified update array with custom plugin data. |
81 | 81 | */ |
82 | - public function check_update( $_transient_data ) { |
|
82 | + public function check_update($_transient_data) { |
|
83 | 83 | |
84 | 84 | global $pagenow; |
85 | 85 | |
86 | - if ( ! is_object( $_transient_data ) ) { |
|
86 | + if ( ! is_object($_transient_data)) { |
|
87 | 87 | $_transient_data = new stdClass; |
88 | 88 | } |
89 | 89 | |
90 | - if ( 'plugins.php' == $pagenow && is_multisite() ) { |
|
90 | + if ('plugins.php' == $pagenow && is_multisite()) { |
|
91 | 91 | return $_transient_data; |
92 | 92 | } |
93 | 93 | |
94 | - if ( ! empty( $_transient_data->response ) && ! empty( $_transient_data->response[ $this->name ] ) && false === $this->wp_override ) { |
|
94 | + if ( ! empty($_transient_data->response) && ! empty($_transient_data->response[$this->name]) && false === $this->wp_override) { |
|
95 | 95 | return $_transient_data; |
96 | 96 | } |
97 | 97 | |
98 | 98 | $version_info = $this->get_cached_version_info(); |
99 | 99 | |
100 | - if ( false === $version_info ) { |
|
101 | - $version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug, 'beta' => $this->beta ) ); |
|
100 | + if (false === $version_info) { |
|
101 | + $version_info = $this->api_request('plugin_latest_version', array('slug' => $this->slug, 'beta' => $this->beta)); |
|
102 | 102 | |
103 | - $this->set_version_info_cache( $version_info ); |
|
103 | + $this->set_version_info_cache($version_info); |
|
104 | 104 | |
105 | 105 | } |
106 | 106 | |
107 | - if ( false !== $version_info && is_object( $version_info ) && isset( $version_info->new_version ) ) { |
|
107 | + if (false !== $version_info && is_object($version_info) && isset($version_info->new_version)) { |
|
108 | 108 | |
109 | - if ( version_compare( $this->version, $version_info->new_version, '<' ) ) { |
|
109 | + if (version_compare($this->version, $version_info->new_version, '<')) { |
|
110 | 110 | |
111 | - $_transient_data->response[ $this->name ] = $version_info; |
|
111 | + $_transient_data->response[$this->name] = $version_info; |
|
112 | 112 | |
113 | 113 | } |
114 | 114 | |
115 | - $_transient_data->last_checked = current_time( 'timestamp' ); |
|
116 | - $_transient_data->checked[ $this->name ] = $this->version; |
|
115 | + $_transient_data->last_checked = current_time('timestamp'); |
|
116 | + $_transient_data->checked[$this->name] = $this->version; |
|
117 | 117 | |
118 | 118 | } |
119 | 119 | |
@@ -126,97 +126,97 @@ discard block |
||
126 | 126 | * @param string $file |
127 | 127 | * @param array $plugin |
128 | 128 | */ |
129 | - public function show_update_notification( $file, $plugin ) { |
|
129 | + public function show_update_notification($file, $plugin) { |
|
130 | 130 | |
131 | - if ( is_network_admin() ) { |
|
131 | + if (is_network_admin()) { |
|
132 | 132 | return; |
133 | 133 | } |
134 | 134 | |
135 | - if( ! current_user_can( 'update_plugins' ) ) { |
|
135 | + if ( ! current_user_can('update_plugins')) { |
|
136 | 136 | return; |
137 | 137 | } |
138 | 138 | |
139 | - if( ! is_multisite() ) { |
|
139 | + if ( ! is_multisite()) { |
|
140 | 140 | return; |
141 | 141 | } |
142 | 142 | |
143 | - if ( $this->name != $file ) { |
|
143 | + if ($this->name != $file) { |
|
144 | 144 | return; |
145 | 145 | } |
146 | 146 | |
147 | 147 | // Remove our filter on the site transient |
148 | - remove_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ), 10 ); |
|
148 | + remove_filter('pre_set_site_transient_update_plugins', array($this, 'check_update'), 10); |
|
149 | 149 | |
150 | - $update_cache = get_site_transient( 'update_plugins' ); |
|
150 | + $update_cache = get_site_transient('update_plugins'); |
|
151 | 151 | |
152 | - $update_cache = is_object( $update_cache ) ? $update_cache : new stdClass(); |
|
152 | + $update_cache = is_object($update_cache) ? $update_cache : new stdClass(); |
|
153 | 153 | |
154 | - if ( empty( $update_cache->response ) || empty( $update_cache->response[ $this->name ] ) ) { |
|
154 | + if (empty($update_cache->response) || empty($update_cache->response[$this->name])) { |
|
155 | 155 | |
156 | 156 | $version_info = $this->get_cached_version_info(); |
157 | 157 | |
158 | - if ( false === $version_info ) { |
|
159 | - $version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug, 'beta' => $this->beta ) ); |
|
158 | + if (false === $version_info) { |
|
159 | + $version_info = $this->api_request('plugin_latest_version', array('slug' => $this->slug, 'beta' => $this->beta)); |
|
160 | 160 | |
161 | - $this->set_version_info_cache( $version_info ); |
|
161 | + $this->set_version_info_cache($version_info); |
|
162 | 162 | } |
163 | 163 | |
164 | - if ( ! is_object( $version_info ) ) { |
|
164 | + if ( ! is_object($version_info)) { |
|
165 | 165 | return; |
166 | 166 | } |
167 | 167 | |
168 | - if ( version_compare( $this->version, $version_info->new_version, '<' ) ) { |
|
168 | + if (version_compare($this->version, $version_info->new_version, '<')) { |
|
169 | 169 | |
170 | - $update_cache->response[ $this->name ] = $version_info; |
|
170 | + $update_cache->response[$this->name] = $version_info; |
|
171 | 171 | |
172 | 172 | } |
173 | 173 | |
174 | - $update_cache->last_checked = current_time( 'timestamp' ); |
|
175 | - $update_cache->checked[ $this->name ] = $this->version; |
|
174 | + $update_cache->last_checked = current_time('timestamp'); |
|
175 | + $update_cache->checked[$this->name] = $this->version; |
|
176 | 176 | |
177 | - set_site_transient( 'update_plugins', $update_cache ); |
|
177 | + set_site_transient('update_plugins', $update_cache); |
|
178 | 178 | |
179 | 179 | } else { |
180 | 180 | |
181 | - $version_info = $update_cache->response[ $this->name ]; |
|
181 | + $version_info = $update_cache->response[$this->name]; |
|
182 | 182 | |
183 | 183 | } |
184 | 184 | |
185 | 185 | // Restore our filter |
186 | - add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ) ); |
|
186 | + add_filter('pre_set_site_transient_update_plugins', array($this, 'check_update')); |
|
187 | 187 | |
188 | - if ( ! empty( $update_cache->response[ $this->name ] ) && version_compare( $this->version, $version_info->new_version, '<' ) ) { |
|
188 | + if ( ! empty($update_cache->response[$this->name]) && version_compare($this->version, $version_info->new_version, '<')) { |
|
189 | 189 | |
190 | 190 | // build a plugin list row, with update notification |
191 | - $wp_list_table = _get_list_table( 'WP_Plugins_List_Table' ); |
|
191 | + $wp_list_table = _get_list_table('WP_Plugins_List_Table'); |
|
192 | 192 | # <tr class="plugin-update-tr"><td colspan="' . $wp_list_table->get_column_count() . '" class="plugin-update colspanchange"> |
193 | - echo '<tr class="plugin-update-tr" id="' . $this->slug . '-update" data-slug="' . $this->slug . '" data-plugin="' . $this->slug . '/' . $file . '">'; |
|
193 | + echo '<tr class="plugin-update-tr" id="'.$this->slug.'-update" data-slug="'.$this->slug.'" data-plugin="'.$this->slug.'/'.$file.'">'; |
|
194 | 194 | echo '<td colspan="3" class="plugin-update colspanchange">'; |
195 | 195 | echo '<div class="update-message notice inline notice-warning notice-alt">'; |
196 | 196 | |
197 | - $changelog_link = self_admin_url( 'index.php?edd_sl_action=view_plugin_changelog&plugin=' . $this->name . '&slug=' . $this->slug . '&TB_iframe=true&width=772&height=911' ); |
|
197 | + $changelog_link = self_admin_url('index.php?edd_sl_action=view_plugin_changelog&plugin='.$this->name.'&slug='.$this->slug.'&TB_iframe=true&width=772&height=911'); |
|
198 | 198 | |
199 | - if ( empty( $version_info->download_link ) ) { |
|
199 | + if (empty($version_info->download_link)) { |
|
200 | 200 | printf( |
201 | - __( 'There is a new version of %1$s available. %2$sView version %3$s details%4$s.', 'easy-digital-downloads' ), |
|
202 | - esc_html( $version_info->name ), |
|
203 | - '<a target="_blank" class="thickbox" href="' . esc_url( $changelog_link ) . '">', |
|
204 | - esc_html( $version_info->new_version ), |
|
201 | + __('There is a new version of %1$s available. %2$sView version %3$s details%4$s.', 'easy-digital-downloads'), |
|
202 | + esc_html($version_info->name), |
|
203 | + '<a target="_blank" class="thickbox" href="'.esc_url($changelog_link).'">', |
|
204 | + esc_html($version_info->new_version), |
|
205 | 205 | '</a>' |
206 | 206 | ); |
207 | 207 | } else { |
208 | 208 | printf( |
209 | - __( 'There is a new version of %1$s available. %2$sView version %3$s details%4$s or %5$supdate now%6$s.', 'easy-digital-downloads' ), |
|
210 | - esc_html( $version_info->name ), |
|
211 | - '<a target="_blank" class="thickbox" href="' . esc_url( $changelog_link ) . '">', |
|
212 | - esc_html( $version_info->new_version ), |
|
209 | + __('There is a new version of %1$s available. %2$sView version %3$s details%4$s or %5$supdate now%6$s.', 'easy-digital-downloads'), |
|
210 | + esc_html($version_info->name), |
|
211 | + '<a target="_blank" class="thickbox" href="'.esc_url($changelog_link).'">', |
|
212 | + esc_html($version_info->new_version), |
|
213 | 213 | '</a>', |
214 | - '<a href="' . esc_url( wp_nonce_url( self_admin_url( 'update.php?action=upgrade-plugin&plugin=' ) . $this->name, 'upgrade-plugin_' . $this->name ) ) .'">', |
|
214 | + '<a href="'.esc_url(wp_nonce_url(self_admin_url('update.php?action=upgrade-plugin&plugin=').$this->name, 'upgrade-plugin_'.$this->name)).'">', |
|
215 | 215 | '</a>' |
216 | 216 | ); |
217 | 217 | } |
218 | 218 | |
219 | - do_action( "in_plugin_update_message-{$file}", $plugin, $version_info ); |
|
219 | + do_action("in_plugin_update_message-{$file}", $plugin, $version_info); |
|
220 | 220 | |
221 | 221 | echo '</div></td></tr>'; |
222 | 222 | } |
@@ -232,15 +232,15 @@ discard block |
||
232 | 232 | * @param object $_args |
233 | 233 | * @return object $_data |
234 | 234 | */ |
235 | - public function plugins_api_filter( $_data, $_action = '', $_args = null ) { |
|
235 | + public function plugins_api_filter($_data, $_action = '', $_args = null) { |
|
236 | 236 | |
237 | - if ( $_action != 'plugin_information' ) { |
|
237 | + if ($_action != 'plugin_information') { |
|
238 | 238 | |
239 | 239 | return $_data; |
240 | 240 | |
241 | 241 | } |
242 | 242 | |
243 | - if ( ! isset( $_args->slug ) || ( $_args->slug != $this->slug ) ) { |
|
243 | + if ( ! isset($_args->slug) || ($_args->slug != $this->slug)) { |
|
244 | 244 | |
245 | 245 | return $_data; |
246 | 246 | |
@@ -255,20 +255,20 @@ discard block |
||
255 | 255 | ) |
256 | 256 | ); |
257 | 257 | |
258 | - $cache_key = 'edd_api_request_' . md5( serialize( $this->slug . $this->api_data['license'] . $this->beta ) ); |
|
258 | + $cache_key = 'edd_api_request_'.md5(serialize($this->slug.$this->api_data['license'].$this->beta)); |
|
259 | 259 | |
260 | 260 | // Get the transient where we store the api request for this plugin for 24 hours |
261 | - $edd_api_request_transient = $this->get_cached_version_info( $cache_key ); |
|
261 | + $edd_api_request_transient = $this->get_cached_version_info($cache_key); |
|
262 | 262 | |
263 | 263 | //If we have no transient-saved value, run the API, set a fresh transient with the API value, and return that value too right now. |
264 | - if ( empty( $edd_api_request_transient ) ) { |
|
264 | + if (empty($edd_api_request_transient)) { |
|
265 | 265 | |
266 | - $api_response = $this->api_request( 'plugin_information', $to_send ); |
|
266 | + $api_response = $this->api_request('plugin_information', $to_send); |
|
267 | 267 | |
268 | 268 | // Expires in 3 hours |
269 | - $this->set_version_info_cache( $api_response, $cache_key ); |
|
269 | + $this->set_version_info_cache($api_response, $cache_key); |
|
270 | 270 | |
271 | - if ( false !== $api_response ) { |
|
271 | + if (false !== $api_response) { |
|
272 | 272 | $_data = $api_response; |
273 | 273 | } |
274 | 274 | |
@@ -277,20 +277,20 @@ discard block |
||
277 | 277 | } |
278 | 278 | |
279 | 279 | // Convert sections into an associative array, since we're getting an object, but Core expects an array. |
280 | - if ( isset( $_data->sections ) && ! is_array( $_data->sections ) ) { |
|
280 | + if (isset($_data->sections) && ! is_array($_data->sections)) { |
|
281 | 281 | $new_sections = array(); |
282 | - foreach ( $_data->sections as $key => $key ) { |
|
283 | - $new_sections[ $key ] = $key; |
|
282 | + foreach ($_data->sections as $key => $key) { |
|
283 | + $new_sections[$key] = $key; |
|
284 | 284 | } |
285 | 285 | |
286 | 286 | $_data->sections = $new_sections; |
287 | 287 | } |
288 | 288 | |
289 | 289 | // Convert banners into an associative array, since we're getting an object, but Core expects an array. |
290 | - if ( isset( $_data->banners ) && ! is_array( $_data->banners ) ) { |
|
290 | + if (isset($_data->banners) && ! is_array($_data->banners)) { |
|
291 | 291 | $new_banners = array(); |
292 | - foreach ( $_data->banners as $key => $key ) { |
|
293 | - $new_banners[ $key ] = $key; |
|
292 | + foreach ($_data->banners as $key => $key) { |
|
293 | + $new_banners[$key] = $key; |
|
294 | 294 | } |
295 | 295 | |
296 | 296 | $_data->banners = $new_banners; |
@@ -306,9 +306,9 @@ discard block |
||
306 | 306 | * @param string $url |
307 | 307 | * @return object $array |
308 | 308 | */ |
309 | - public function http_request_args( $args, $url ) { |
|
309 | + public function http_request_args($args, $url) { |
|
310 | 310 | // If it is an https request and we are performing a package download, disable ssl verification |
311 | - if ( strpos( $url, 'https://' ) !== false && strpos( $url, 'edd_action=package_download' ) ) { |
|
311 | + if (strpos($url, 'https://') !== false && strpos($url, 'edd_action=package_download')) { |
|
312 | 312 | $args['sslverify'] = false; |
313 | 313 | } |
314 | 314 | return $args; |
@@ -325,50 +325,50 @@ discard block |
||
325 | 325 | * @param array $_data Parameters for the API action. |
326 | 326 | * @return false|object |
327 | 327 | */ |
328 | - private function api_request( $_action, $_data ) { |
|
328 | + private function api_request($_action, $_data) { |
|
329 | 329 | |
330 | 330 | global $wp_version; |
331 | 331 | |
332 | - $data = array_merge( $this->api_data, $_data ); |
|
332 | + $data = array_merge($this->api_data, $_data); |
|
333 | 333 | |
334 | - if ( $data['slug'] != $this->slug ) { |
|
334 | + if ($data['slug'] != $this->slug) { |
|
335 | 335 | return; |
336 | 336 | } |
337 | 337 | |
338 | - if( $this->api_url == trailingslashit (home_url() ) ) { |
|
338 | + if ($this->api_url == trailingslashit(home_url())) { |
|
339 | 339 | return false; // Don't allow a plugin to ping itself |
340 | 340 | } |
341 | 341 | |
342 | 342 | $api_params = array( |
343 | 343 | 'edd_action' => 'get_version', |
344 | - 'license' => ! empty( $data['license'] ) ? $data['license'] : '', |
|
345 | - 'item_name' => isset( $data['item_name'] ) ? $data['item_name'] : false, |
|
346 | - 'item_id' => isset( $data['item_id'] ) ? $data['item_id'] : false, |
|
347 | - 'version' => isset( $data['version'] ) ? $data['version'] : false, |
|
344 | + 'license' => ! empty($data['license']) ? $data['license'] : '', |
|
345 | + 'item_name' => isset($data['item_name']) ? $data['item_name'] : false, |
|
346 | + 'item_id' => isset($data['item_id']) ? $data['item_id'] : false, |
|
347 | + 'version' => isset($data['version']) ? $data['version'] : false, |
|
348 | 348 | 'slug' => $data['slug'], |
349 | 349 | 'author' => $data['author'], |
350 | 350 | 'url' => home_url(), |
351 | - 'beta' => ! empty( $data['beta'] ), |
|
351 | + 'beta' => ! empty($data['beta']), |
|
352 | 352 | ); |
353 | 353 | |
354 | - $request = wp_remote_post( $this->api_url, array( 'timeout' => 15, 'sslverify' => false, 'body' => $api_params ) ); |
|
354 | + $request = wp_remote_post($this->api_url, array('timeout' => 15, 'sslverify' => false, 'body' => $api_params)); |
|
355 | 355 | |
356 | - if ( ! is_wp_error( $request ) ) { |
|
357 | - $request = json_decode( wp_remote_retrieve_body( $request ) ); |
|
356 | + if ( ! is_wp_error($request)) { |
|
357 | + $request = json_decode(wp_remote_retrieve_body($request)); |
|
358 | 358 | } |
359 | 359 | |
360 | - if ( $request && isset( $request->sections ) ) { |
|
361 | - $request->sections = maybe_unserialize( $request->sections ); |
|
360 | + if ($request && isset($request->sections)) { |
|
361 | + $request->sections = maybe_unserialize($request->sections); |
|
362 | 362 | } else { |
363 | 363 | $request = false; |
364 | 364 | } |
365 | 365 | |
366 | - if ( $request && isset( $request->banners ) ) { |
|
367 | - $request->banners = maybe_unserialize( $request->banners ); |
|
366 | + if ($request && isset($request->banners)) { |
|
367 | + $request->banners = maybe_unserialize($request->banners); |
|
368 | 368 | } |
369 | 369 | |
370 | - if( ! empty( $request->sections ) ) { |
|
371 | - foreach( $request->sections as $key => $section ) { |
|
370 | + if ( ! empty($request->sections)) { |
|
371 | + foreach ($request->sections as $key => $section) { |
|
372 | 372 | $request->$key = (array) $section; |
373 | 373 | } |
374 | 374 | } |
@@ -380,97 +380,97 @@ discard block |
||
380 | 380 | |
381 | 381 | global $edd_plugin_data; |
382 | 382 | |
383 | - if( empty( $_REQUEST['edd_sl_action'] ) || 'view_plugin_changelog' != $_REQUEST['edd_sl_action'] ) { |
|
383 | + if (empty($_REQUEST['edd_sl_action']) || 'view_plugin_changelog' != $_REQUEST['edd_sl_action']) { |
|
384 | 384 | return; |
385 | 385 | } |
386 | 386 | |
387 | - if( empty( $_REQUEST['plugin'] ) ) { |
|
387 | + if (empty($_REQUEST['plugin'])) { |
|
388 | 388 | return; |
389 | 389 | } |
390 | 390 | |
391 | - if( empty( $_REQUEST['slug'] ) ) { |
|
391 | + if (empty($_REQUEST['slug'])) { |
|
392 | 392 | return; |
393 | 393 | } |
394 | 394 | |
395 | - if( ! current_user_can( 'update_plugins' ) ) { |
|
396 | - wp_die( __( 'You do not have permission to install plugin updates', 'easy-digital-downloads' ), __( 'Error', 'easy-digital-downloads' ), array( 'response' => 403 ) ); |
|
395 | + if ( ! current_user_can('update_plugins')) { |
|
396 | + wp_die(__('You do not have permission to install plugin updates', 'easy-digital-downloads'), __('Error', 'easy-digital-downloads'), array('response' => 403)); |
|
397 | 397 | } |
398 | 398 | |
399 | - $data = $edd_plugin_data[ $_REQUEST['slug'] ]; |
|
400 | - $beta = ! empty( $data['beta'] ) ? true : false; |
|
401 | - $cache_key = md5( 'edd_plugin_' . sanitize_key( $_REQUEST['plugin'] ) . '_' . $beta . '_version_info' ); |
|
402 | - $version_info = $this->get_cached_version_info( $cache_key ); |
|
399 | + $data = $edd_plugin_data[$_REQUEST['slug']]; |
|
400 | + $beta = ! empty($data['beta']) ? true : false; |
|
401 | + $cache_key = md5('edd_plugin_'.sanitize_key($_REQUEST['plugin']).'_'.$beta.'_version_info'); |
|
402 | + $version_info = $this->get_cached_version_info($cache_key); |
|
403 | 403 | |
404 | - if( false === $version_info ) { |
|
404 | + if (false === $version_info) { |
|
405 | 405 | |
406 | 406 | $api_params = array( |
407 | 407 | 'edd_action' => 'get_version', |
408 | - 'item_name' => isset( $data['item_name'] ) ? $data['item_name'] : false, |
|
409 | - 'item_id' => isset( $data['item_id'] ) ? $data['item_id'] : false, |
|
408 | + 'item_name' => isset($data['item_name']) ? $data['item_name'] : false, |
|
409 | + 'item_id' => isset($data['item_id']) ? $data['item_id'] : false, |
|
410 | 410 | 'slug' => $_REQUEST['slug'], |
411 | 411 | 'author' => $data['author'], |
412 | 412 | 'url' => home_url(), |
413 | - 'beta' => ! empty( $data['beta'] ) |
|
413 | + 'beta' => ! empty($data['beta']) |
|
414 | 414 | ); |
415 | 415 | |
416 | - $request = wp_remote_post( $this->api_url, array( 'timeout' => 15, 'sslverify' => false, 'body' => $api_params ) ); |
|
416 | + $request = wp_remote_post($this->api_url, array('timeout' => 15, 'sslverify' => false, 'body' => $api_params)); |
|
417 | 417 | |
418 | - if ( ! is_wp_error( $request ) ) { |
|
419 | - $version_info = json_decode( wp_remote_retrieve_body( $request ) ); |
|
418 | + if ( ! is_wp_error($request)) { |
|
419 | + $version_info = json_decode(wp_remote_retrieve_body($request)); |
|
420 | 420 | } |
421 | 421 | |
422 | 422 | |
423 | - if ( ! empty( $version_info ) && isset( $version_info->sections ) ) { |
|
424 | - $version_info->sections = maybe_unserialize( $version_info->sections ); |
|
423 | + if ( ! empty($version_info) && isset($version_info->sections)) { |
|
424 | + $version_info->sections = maybe_unserialize($version_info->sections); |
|
425 | 425 | } else { |
426 | 426 | $version_info = false; |
427 | 427 | } |
428 | 428 | |
429 | - if( ! empty( $version_info ) ) { |
|
430 | - foreach( $version_info->sections as $key => $section ) { |
|
429 | + if ( ! empty($version_info)) { |
|
430 | + foreach ($version_info->sections as $key => $section) { |
|
431 | 431 | $version_info->$key = (array) $section; |
432 | 432 | } |
433 | 433 | } |
434 | 434 | |
435 | - $this->set_version_info_cache( $version_info, $cache_key ); |
|
435 | + $this->set_version_info_cache($version_info, $cache_key); |
|
436 | 436 | |
437 | 437 | } |
438 | 438 | |
439 | - if( ! empty( $version_info ) && isset( $version_info->sections['changelog'] ) ) { |
|
440 | - echo '<div style="background:#fff;padding:10px;">' . $version_info->sections['changelog'] . '</div>'; |
|
439 | + if ( ! empty($version_info) && isset($version_info->sections['changelog'])) { |
|
440 | + echo '<div style="background:#fff;padding:10px;">'.$version_info->sections['changelog'].'</div>'; |
|
441 | 441 | } |
442 | 442 | |
443 | 443 | exit; |
444 | 444 | } |
445 | 445 | |
446 | - public function get_cached_version_info( $cache_key = '' ) { |
|
446 | + public function get_cached_version_info($cache_key = '') { |
|
447 | 447 | |
448 | - if( empty( $cache_key ) ) { |
|
448 | + if (empty($cache_key)) { |
|
449 | 449 | $cache_key = $this->cache_key; |
450 | 450 | } |
451 | 451 | |
452 | - $cache = get_option( $cache_key ); |
|
452 | + $cache = get_option($cache_key); |
|
453 | 453 | |
454 | - if( empty( $cache['timeout'] ) || current_time( 'timestamp' ) > $cache['timeout'] ) { |
|
454 | + if (empty($cache['timeout']) || current_time('timestamp') > $cache['timeout']) { |
|
455 | 455 | return false; // Cache is expired |
456 | 456 | } |
457 | 457 | |
458 | - return json_decode( $cache['value'] ); |
|
458 | + return json_decode($cache['value']); |
|
459 | 459 | |
460 | 460 | } |
461 | 461 | |
462 | - public function set_version_info_cache( $value = '', $cache_key = '' ) { |
|
462 | + public function set_version_info_cache($value = '', $cache_key = '') { |
|
463 | 463 | |
464 | - if( empty( $cache_key ) ) { |
|
464 | + if (empty($cache_key)) { |
|
465 | 465 | $cache_key = $this->cache_key; |
466 | 466 | } |
467 | 467 | |
468 | 468 | $data = array( |
469 | - 'timeout' => strtotime( '+3 hours', current_time( 'timestamp' ) ), |
|
470 | - 'value' => json_encode( $value ) |
|
469 | + 'timeout' => strtotime('+3 hours', current_time('timestamp')), |
|
470 | + 'value' => json_encode($value) |
|
471 | 471 | ); |
472 | 472 | |
473 | - update_option( $cache_key, $data ); |
|
473 | + update_option($cache_key, $data); |
|
474 | 474 | |
475 | 475 | } |
476 | 476 |
@@ -1,7 +1,9 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | // Exit if accessed directly |
4 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
4 | +if ( ! defined( 'ABSPATH' ) ) { |
|
5 | + exit; |
|
6 | +} |
|
5 | 7 | |
6 | 8 | /** |
7 | 9 | * Allows plugins to use their own update API. |
@@ -9,11 +9,11 @@ discard block |
||
9 | 9 | * @since 1.8 |
10 | 10 | */ |
11 | 11 | |
12 | -if ( ! defined( 'ABSPATH' ) ) { |
|
12 | +if ( ! defined('ABSPATH')) { |
|
13 | 13 | exit; // Exit if accessed directly |
14 | 14 | } |
15 | 15 | |
16 | -if ( ! class_exists( 'Give_Settings_License' ) ) : |
|
16 | +if ( ! class_exists('Give_Settings_License')) : |
|
17 | 17 | |
18 | 18 | /** |
19 | 19 | * Give_Settings_License. |
@@ -43,11 +43,11 @@ discard block |
||
43 | 43 | */ |
44 | 44 | public function __construct() { |
45 | 45 | $this->id = 'licenses'; |
46 | - $this->label = esc_html__( 'Licenses', 'give' ); |
|
46 | + $this->label = esc_html__('Licenses', 'give'); |
|
47 | 47 | |
48 | - add_filter( 'give-settings_tabs_array', array( $this, 'add_settings_page' ), 20 ); |
|
49 | - add_action( "give-settings_settings_{$this->id}_page", array( $this, 'output' ) ); |
|
50 | - add_action( "give-settings_save_{$this->id}", array( $this, 'save' ) ); |
|
48 | + add_filter('give-settings_tabs_array', array($this, 'add_settings_page'), 20); |
|
49 | + add_action("give-settings_settings_{$this->id}_page", array($this, 'output')); |
|
50 | + add_action("give-settings_save_{$this->id}", array($this, 'save')); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | /** |
@@ -57,11 +57,11 @@ discard block |
||
57 | 57 | * @param array $pages Lst of pages. |
58 | 58 | * @return array |
59 | 59 | */ |
60 | - public function add_settings_page( $pages ) { |
|
60 | + public function add_settings_page($pages) { |
|
61 | 61 | $setting = $this->get_settings(); |
62 | 62 | // Bailout: Do not add licenses setting tab if it does not contain any setting fields. |
63 | - if( ! empty( $setting ) ) { |
|
64 | - $pages[ $this->id ] = $this->label; |
|
63 | + if ( ! empty($setting)) { |
|
64 | + $pages[$this->id] = $this->label; |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | return $pages; |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | * Filter the licenses settings. |
81 | 81 | * Backward compatibility: Please do not use this filter. This filter is deprecated in 1.8 |
82 | 82 | */ |
83 | - $settings = apply_filters( 'give_settings_licenses', $settings ); |
|
83 | + $settings = apply_filters('give_settings_licenses', $settings); |
|
84 | 84 | |
85 | 85 | /** |
86 | 86 | * Filter the settings. |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | * @since 1.8 |
89 | 89 | * @param array $settings |
90 | 90 | */ |
91 | - $settings = apply_filters( 'give_get_settings_' . $this->id, $settings ); |
|
91 | + $settings = apply_filters('give_get_settings_'.$this->id, $settings); |
|
92 | 92 | |
93 | 93 | // Output. |
94 | 94 | return $settings; |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | public function output() { |
104 | 104 | $settings = $this->get_settings(); |
105 | 105 | |
106 | - Give_Admin_Settings::output_fields( $settings, 'give_settings' ); |
|
106 | + Give_Admin_Settings::output_fields($settings, 'give_settings'); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | /** |
@@ -116,14 +116,14 @@ discard block |
||
116 | 116 | $settings = $this->get_settings(); |
117 | 117 | $current_section = give_get_current_setting_section(); |
118 | 118 | |
119 | - Give_Admin_Settings::save_fields( $settings, 'give_settings' ); |
|
119 | + Give_Admin_Settings::save_fields($settings, 'give_settings'); |
|
120 | 120 | |
121 | 121 | /** |
122 | 122 | * Trigger Action |
123 | 123 | * |
124 | 124 | * @since 1.8 |
125 | 125 | */ |
126 | - do_action( 'give_update_options_' . $this->id . '_' . $current_section ); |
|
126 | + do_action('give_update_options_'.$this->id.'_'.$current_section); |
|
127 | 127 | } |
128 | 128 | } |
129 | 129 |
@@ -65,23 +65,23 @@ discard block |
||
65 | 65 | * |
66 | 66 | * @param $args |
67 | 67 | */ |
68 | - public function __construct( $args ) { |
|
68 | + public function __construct($args) { |
|
69 | 69 | |
70 | 70 | // Only for admins. |
71 | - if ( ! is_admin() ) { |
|
71 | + if ( ! is_admin()) { |
|
72 | 72 | return; |
73 | 73 | } |
74 | 74 | |
75 | 75 | // This plugin is en_US native. |
76 | 76 | $this->locale = get_locale(); |
77 | - if ( 'en_US' === $this->locale ) { |
|
77 | + if ('en_US' === $this->locale) { |
|
78 | 78 | return; |
79 | 79 | } |
80 | 80 | |
81 | - $this->init( $args ); |
|
81 | + $this->init($args); |
|
82 | 82 | |
83 | - if ( ! $this->hide_promo() ) { |
|
84 | - add_action( $this->hook, array( $this, 'promo' ) ); |
|
83 | + if ( ! $this->hide_promo()) { |
|
84 | + add_action($this->hook, array($this, 'promo')); |
|
85 | 85 | } |
86 | 86 | } |
87 | 87 | |
@@ -92,8 +92,8 @@ discard block |
||
92 | 92 | * |
93 | 93 | * @param array $args |
94 | 94 | */ |
95 | - private function init( $args ) { |
|
96 | - foreach ( $args as $key => $arg ) { |
|
95 | + private function init($args) { |
|
96 | + foreach ($args as $key => $arg) { |
|
97 | 97 | $this->$key = $arg; |
98 | 98 | } |
99 | 99 | |
@@ -107,11 +107,11 @@ discard block |
||
107 | 107 | * @return bool |
108 | 108 | */ |
109 | 109 | private function hide_promo() { |
110 | - $hide_promo = get_transient( 'give_i18n_give_promo_hide' ); |
|
111 | - if ( ! $hide_promo ) { |
|
112 | - if ( filter_input( INPUT_GET, 'remove_i18n_promo', FILTER_VALIDATE_INT ) === 1 ) { |
|
110 | + $hide_promo = get_transient('give_i18n_give_promo_hide'); |
|
111 | + if ( ! $hide_promo) { |
|
112 | + if (filter_input(INPUT_GET, 'remove_i18n_promo', FILTER_VALIDATE_INT) === 1) { |
|
113 | 113 | // No expiration time, so this would normally not expire, but it wouldn't be copied to other sites etc. |
114 | - set_transient( 'give_i18n_give_promo_hide', true ); |
|
114 | + set_transient('give_i18n_give_promo_hide', true); |
|
115 | 115 | $hide_promo = true; |
116 | 116 | } |
117 | 117 | } |
@@ -130,20 +130,20 @@ discard block |
||
130 | 130 | $message = false; |
131 | 131 | |
132 | 132 | // Using a translation less than 90% complete. |
133 | - if ( $this->translation_exists && $this->translation_loaded && $this->percent_translated < 90 ) { |
|
134 | - $message = __( 'As you can see, there is a translation of this plugin in %1$s. This translation is currently %3$d%% complete. We need your help to make it complete and to fix any errors. Please register at %4$s to help %5$s to %1$s!', 'give' ); |
|
135 | - } elseif ( ! $this->translation_loaded && $this->translation_exists ) { |
|
136 | - $message = __( 'You\'re using WordPress in %1$s. While %2$s has been %3$d%% translated to %1$s, it has not been shipped with the plugin yet. You can help! Register at %4$s to help complete the translation to %1$s!', 'give' ); |
|
137 | - } elseif ( ! $this->translation_exists ) { |
|
138 | - $message = __( 'You\'re using WordPress in a language we don\'t support yet. We\'d love for %2$s to be translated in that language too, but unfortunately, it isn\'t right now. You can change that! Register at %4$s to help translate it!', 'give' ); |
|
133 | + if ($this->translation_exists && $this->translation_loaded && $this->percent_translated < 90) { |
|
134 | + $message = __('As you can see, there is a translation of this plugin in %1$s. This translation is currently %3$d%% complete. We need your help to make it complete and to fix any errors. Please register at %4$s to help %5$s to %1$s!', 'give'); |
|
135 | + } elseif ( ! $this->translation_loaded && $this->translation_exists) { |
|
136 | + $message = __('You\'re using WordPress in %1$s. While %2$s has been %3$d%% translated to %1$s, it has not been shipped with the plugin yet. You can help! Register at %4$s to help complete the translation to %1$s!', 'give'); |
|
137 | + } elseif ( ! $this->translation_exists) { |
|
138 | + $message = __('You\'re using WordPress in a language we don\'t support yet. We\'d love for %2$s to be translated in that language too, but unfortunately, it isn\'t right now. You can change that! Register at %4$s to help translate it!', 'give'); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | // Links. |
142 | - $registration_link = sprintf( '<a href="%1$s" target="_blank">%2$s</a>', 'https://wordpress.org/support/register.php', esc_html__( 'WordPress.org', 'give' ) ); |
|
143 | - $translations_link = sprintf( '<a href="%1$s" target="_blank">%2$s</a>', 'https://translate.wordpress.org/projects/wp-plugins/give', esc_html__( 'complete the translation', 'give' ) ); |
|
142 | + $registration_link = sprintf('<a href="%1$s" target="_blank">%2$s</a>', 'https://wordpress.org/support/register.php', esc_html__('WordPress.org', 'give')); |
|
143 | + $translations_link = sprintf('<a href="%1$s" target="_blank">%2$s</a>', 'https://translate.wordpress.org/projects/wp-plugins/give', esc_html__('complete the translation', 'give')); |
|
144 | 144 | |
145 | 145 | // Message. |
146 | - $message = sprintf( $message, $this->locale_name, 'Give', $this->percent_translated, $registration_link, $translations_link ); |
|
146 | + $message = sprintf($message, $this->locale_name, 'Give', $this->percent_translated, $registration_link, $translations_link); |
|
147 | 147 | |
148 | 148 | return $message; |
149 | 149 | |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | $this->translation_details(); |
158 | 158 | $message = $this->promo_message(); |
159 | 159 | |
160 | - if ( $message ) { ?> |
|
160 | + if ($message) { ?> |
|
161 | 161 | |
162 | 162 | <style> |
163 | 163 | /* Banner specific styles */ |
@@ -220,12 +220,12 @@ discard block |
||
220 | 220 | <a href="https://wordpress.org/support/register.php" class="alignleft give-i18n-icon" style="margin:0" target="_blank"><span class="dashicons dashicons-translation" style="font-size: 110px; text-decoration: none;"></span></a> |
221 | 221 | |
222 | 222 | <div class="give-i18n-notice-content"> |
223 | - <a href="<?php echo esc_url( add_query_arg( array( 'remove_i18n_promo' => '1' ) ) ); ?>" class="dismiss"><span class="dashicons dashicons-dismiss"></span></a> |
|
223 | + <a href="<?php echo esc_url(add_query_arg(array('remove_i18n_promo' => '1'))); ?>" class="dismiss"><span class="dashicons dashicons-dismiss"></span></a> |
|
224 | 224 | |
225 | - <h2 style="margin: 10px 0;"><?php printf( esc_html__( 'Help Translate Give to %s', 'give' ), $this->locale_name ); ?></h2> |
|
225 | + <h2 style="margin: 10px 0;"><?php printf(esc_html__('Help Translate Give to %s', 'give'), $this->locale_name); ?></h2> |
|
226 | 226 | <p><?php echo $message; ?></p> |
227 | 227 | <p> |
228 | - <a href="https://wordpress.org/support/register.php" target="_blank"><?php _e( 'Register now »', 'give' ); ?></a> |
|
228 | + <a href="https://wordpress.org/support/register.php" target="_blank"><?php _e('Register now »', 'give'); ?></a> |
|
229 | 229 | </p> |
230 | 230 | </div> |
231 | 231 | </div> |
@@ -242,11 +242,11 @@ discard block |
||
242 | 242 | */ |
243 | 243 | private function find_or_initialize_translation_details() { |
244 | 244 | |
245 | - $set = get_transient( 'give_i18n_give_' . $this->locale ); |
|
245 | + $set = get_transient('give_i18n_give_'.$this->locale); |
|
246 | 246 | |
247 | - if ( ! $set ) { |
|
247 | + if ( ! $set) { |
|
248 | 248 | $set = $this->retrieve_translation_details(); |
249 | - set_transient( 'give_i18n_give_' . $this->locale, $set, DAY_IN_SECONDS ); |
|
249 | + set_transient('give_i18n_give_'.$this->locale, $set, DAY_IN_SECONDS); |
|
250 | 250 | } |
251 | 251 | |
252 | 252 | return $set; |
@@ -260,10 +260,10 @@ discard block |
||
260 | 260 | private function translation_details() { |
261 | 261 | $set = $this->find_or_initialize_translation_details(); |
262 | 262 | |
263 | - $this->translation_exists = ! is_null( $set ); |
|
264 | - $this->translation_loaded = is_textdomain_loaded( 'give' ); |
|
263 | + $this->translation_exists = ! is_null($set); |
|
264 | + $this->translation_loaded = is_textdomain_loaded('give'); |
|
265 | 265 | |
266 | - $this->parse_translation_set( $set ); |
|
266 | + $this->parse_translation_set($set); |
|
267 | 267 | } |
268 | 268 | |
269 | 269 | /** |
@@ -275,26 +275,26 @@ discard block |
||
275 | 275 | */ |
276 | 276 | private function retrieve_translation_details() { |
277 | 277 | |
278 | - $api_url = trailingslashit( $this->glotpress_url ); |
|
278 | + $api_url = trailingslashit($this->glotpress_url); |
|
279 | 279 | |
280 | - $resp = wp_remote_get( $api_url ); |
|
280 | + $resp = wp_remote_get($api_url); |
|
281 | 281 | |
282 | - if ( is_wp_error( $resp ) || wp_remote_retrieve_response_code( $resp ) === '404' ) { |
|
282 | + if (is_wp_error($resp) || wp_remote_retrieve_response_code($resp) === '404') { |
|
283 | 283 | return null; |
284 | 284 | } |
285 | 285 | |
286 | - $body = wp_remote_retrieve_body( $resp ); |
|
287 | - unset( $resp ); |
|
286 | + $body = wp_remote_retrieve_body($resp); |
|
287 | + unset($resp); |
|
288 | 288 | |
289 | - if ( $body ) { |
|
290 | - $body = json_decode( $body ); |
|
289 | + if ($body) { |
|
290 | + $body = json_decode($body); |
|
291 | 291 | |
292 | - foreach ( $body->translation_sets as $set ) { |
|
293 | - if ( ! property_exists( $set, 'wp_locale' ) ) { |
|
292 | + foreach ($body->translation_sets as $set) { |
|
293 | + if ( ! property_exists($set, 'wp_locale')) { |
|
294 | 294 | continue; |
295 | 295 | } |
296 | 296 | |
297 | - if ( $this->locale == $set->wp_locale ) { |
|
297 | + if ($this->locale == $set->wp_locale) { |
|
298 | 298 | return $set; |
299 | 299 | } |
300 | 300 | } |
@@ -310,8 +310,8 @@ discard block |
||
310 | 310 | * |
311 | 311 | * @access private |
312 | 312 | */ |
313 | - private function parse_translation_set( $set ) { |
|
314 | - if ( $this->translation_exists && is_object( $set ) ) { |
|
313 | + private function parse_translation_set($set) { |
|
314 | + if ($this->translation_exists && is_object($set)) { |
|
315 | 315 | $this->locale_name = $set->name; |
316 | 316 | $this->percent_translated = $set->percent_translated; |
317 | 317 | } else { |
@@ -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 | |
@@ -30,36 +30,36 @@ discard block |
||
30 | 30 | * |
31 | 31 | * @return bool|object List of all user donations |
32 | 32 | */ |
33 | -function give_get_users_purchases( $user = 0, $number = 20, $pagination = false, $status = 'complete' ) { |
|
33 | +function give_get_users_purchases($user = 0, $number = 20, $pagination = false, $status = 'complete') { |
|
34 | 34 | |
35 | - if ( empty( $user ) ) { |
|
35 | + if (empty($user)) { |
|
36 | 36 | $user = get_current_user_id(); |
37 | 37 | } |
38 | 38 | |
39 | - if ( 0 === $user && ! Give()->email_access->token_exists ) { |
|
39 | + if (0 === $user && ! Give()->email_access->token_exists) { |
|
40 | 40 | return false; |
41 | 41 | } |
42 | 42 | |
43 | 43 | $status = $status === 'complete' ? 'publish' : $status; |
44 | 44 | |
45 | - if ( $pagination ) { |
|
46 | - if ( get_query_var( 'paged' ) ) { |
|
47 | - $paged = get_query_var( 'paged' ); |
|
48 | - } elseif ( get_query_var( 'page' ) ) { |
|
49 | - $paged = get_query_var( 'page' ); |
|
45 | + if ($pagination) { |
|
46 | + if (get_query_var('paged')) { |
|
47 | + $paged = get_query_var('paged'); |
|
48 | + } elseif (get_query_var('page')) { |
|
49 | + $paged = get_query_var('page'); |
|
50 | 50 | } else { |
51 | 51 | $paged = 1; |
52 | 52 | } |
53 | 53 | } |
54 | 54 | |
55 | - $args = apply_filters( 'give_get_users_donations_args', array( |
|
55 | + $args = apply_filters('give_get_users_donations_args', array( |
|
56 | 56 | 'user' => $user, |
57 | 57 | 'number' => $number, |
58 | 58 | 'status' => $status, |
59 | 59 | 'orderby' => 'date', |
60 | - ) ); |
|
60 | + )); |
|
61 | 61 | |
62 | - if ( $pagination ) { |
|
62 | + if ($pagination) { |
|
63 | 63 | |
64 | 64 | $args['page'] = $paged; |
65 | 65 | |
@@ -69,20 +69,20 @@ discard block |
||
69 | 69 | |
70 | 70 | } |
71 | 71 | |
72 | - $by_user_id = is_numeric( $user ) ? true : false; |
|
73 | - $customer = new Give_Customer( $user, $by_user_id ); |
|
72 | + $by_user_id = is_numeric($user) ? true : false; |
|
73 | + $customer = new Give_Customer($user, $by_user_id); |
|
74 | 74 | |
75 | - if ( ! empty( $customer->payment_ids ) ) { |
|
75 | + if ( ! empty($customer->payment_ids)) { |
|
76 | 76 | |
77 | - unset( $args['user'] ); |
|
78 | - $args['post__in'] = array_map( 'absint', explode( ',', $customer->payment_ids ) ); |
|
77 | + unset($args['user']); |
|
78 | + $args['post__in'] = array_map('absint', explode(',', $customer->payment_ids)); |
|
79 | 79 | |
80 | 80 | } |
81 | 81 | |
82 | - $purchases = give_get_payments( apply_filters( 'give_get_users_donations_args', $args ) ); |
|
82 | + $purchases = give_get_payments(apply_filters('give_get_users_donations_args', $args)); |
|
83 | 83 | |
84 | 84 | // No donations |
85 | - if ( ! $purchases ) { |
|
85 | + if ( ! $purchases) { |
|
86 | 86 | return false; |
87 | 87 | } |
88 | 88 | |
@@ -101,65 +101,65 @@ discard block |
||
101 | 101 | * |
102 | 102 | * @return bool|object List of unique forms donated by user |
103 | 103 | */ |
104 | -function give_get_users_completed_donations( $user = 0, $status = 'complete' ) { |
|
105 | - if ( empty( $user ) ) { |
|
104 | +function give_get_users_completed_donations($user = 0, $status = 'complete') { |
|
105 | + if (empty($user)) { |
|
106 | 106 | $user = get_current_user_id(); |
107 | 107 | } |
108 | 108 | |
109 | - if ( empty( $user ) ) { |
|
109 | + if (empty($user)) { |
|
110 | 110 | return false; |
111 | 111 | } |
112 | 112 | |
113 | - $by_user_id = is_numeric( $user ) ? true : false; |
|
113 | + $by_user_id = is_numeric($user) ? true : false; |
|
114 | 114 | |
115 | - $customer = new Give_Customer( $user, $by_user_id ); |
|
115 | + $customer = new Give_Customer($user, $by_user_id); |
|
116 | 116 | |
117 | - if ( empty( $customer->payment_ids ) ) { |
|
117 | + if (empty($customer->payment_ids)) { |
|
118 | 118 | return false; |
119 | 119 | } |
120 | 120 | |
121 | 121 | // Get all the items donated |
122 | - $payment_ids = array_reverse( explode( ',', $customer->payment_ids ) ); |
|
123 | - $limit_payments = apply_filters( 'give_users_completed_donations_payments', 50 ); |
|
124 | - if ( ! empty( $limit_payments ) ) { |
|
125 | - $payment_ids = array_slice( $payment_ids, 0, $limit_payments ); |
|
122 | + $payment_ids = array_reverse(explode(',', $customer->payment_ids)); |
|
123 | + $limit_payments = apply_filters('give_users_completed_donations_payments', 50); |
|
124 | + if ( ! empty($limit_payments)) { |
|
125 | + $payment_ids = array_slice($payment_ids, 0, $limit_payments); |
|
126 | 126 | } |
127 | 127 | $donation_data = array(); |
128 | - foreach ( $payment_ids as $payment_id ) { |
|
129 | - $donation_data[] = give_get_payment_meta( $payment_id ); |
|
128 | + foreach ($payment_ids as $payment_id) { |
|
129 | + $donation_data[] = give_get_payment_meta($payment_id); |
|
130 | 130 | } |
131 | 131 | |
132 | - if ( empty( $donation_data ) ) { |
|
132 | + if (empty($donation_data)) { |
|
133 | 133 | return false; |
134 | 134 | } |
135 | 135 | |
136 | 136 | // Grab only the post ids "form_id" of the forms donated on this order |
137 | 137 | $completed_donations_ids = array(); |
138 | - foreach ( $donation_data as $purchase_meta ) { |
|
139 | - $completed_donations_ids[] = isset( $purchase_meta['form_id'] ) ? $purchase_meta['form_id'] : ''; |
|
138 | + foreach ($donation_data as $purchase_meta) { |
|
139 | + $completed_donations_ids[] = isset($purchase_meta['form_id']) ? $purchase_meta['form_id'] : ''; |
|
140 | 140 | } |
141 | 141 | |
142 | - if ( empty( $completed_donations_ids ) ) { |
|
142 | + if (empty($completed_donations_ids)) { |
|
143 | 143 | return false; |
144 | 144 | } |
145 | 145 | |
146 | 146 | // Only include each donation once |
147 | - $form_ids = array_unique( $completed_donations_ids ); |
|
147 | + $form_ids = array_unique($completed_donations_ids); |
|
148 | 148 | |
149 | 149 | // Make sure we still have some products and a first item |
150 | - if ( empty( $form_ids ) || ! isset( $form_ids[0] ) ) { |
|
150 | + if (empty($form_ids) || ! isset($form_ids[0])) { |
|
151 | 151 | return false; |
152 | 152 | } |
153 | 153 | |
154 | - $post_type = get_post_type( $form_ids[0] ); |
|
154 | + $post_type = get_post_type($form_ids[0]); |
|
155 | 155 | |
156 | - $args = apply_filters( 'give_get_users_completed_donations_args', array( |
|
156 | + $args = apply_filters('give_get_users_completed_donations_args', array( |
|
157 | 157 | 'include' => $form_ids, |
158 | 158 | 'post_type' => $post_type, |
159 | - 'posts_per_page' => - 1, |
|
160 | - ) ); |
|
159 | + 'posts_per_page' => -1, |
|
160 | + )); |
|
161 | 161 | |
162 | - return apply_filters( 'give_users_completed_donations_list', get_posts( $args ) ); |
|
162 | + return apply_filters('give_users_completed_donations_list', get_posts($args)); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | |
@@ -175,12 +175,12 @@ discard block |
||
175 | 175 | * |
176 | 176 | * @return bool True if has donated, false other wise. |
177 | 177 | */ |
178 | -function give_has_purchases( $user_id = null ) { |
|
179 | - if ( empty( $user_id ) ) { |
|
178 | +function give_has_purchases($user_id = null) { |
|
179 | + if (empty($user_id)) { |
|
180 | 180 | $user_id = get_current_user_id(); |
181 | 181 | } |
182 | 182 | |
183 | - if ( give_get_users_purchases( $user_id, 1 ) ) { |
|
183 | + if (give_get_users_purchases($user_id, 1)) { |
|
184 | 184 | return true; // User has at least one donation |
185 | 185 | } |
186 | 186 | |
@@ -200,27 +200,27 @@ discard block |
||
200 | 200 | * |
201 | 201 | * @return array |
202 | 202 | */ |
203 | -function give_get_purchase_stats_by_user( $user = '' ) { |
|
203 | +function give_get_purchase_stats_by_user($user = '') { |
|
204 | 204 | |
205 | - if ( is_email( $user ) ) { |
|
205 | + if (is_email($user)) { |
|
206 | 206 | |
207 | 207 | $field = 'email'; |
208 | 208 | |
209 | - } elseif ( is_numeric( $user ) ) { |
|
209 | + } elseif (is_numeric($user)) { |
|
210 | 210 | |
211 | 211 | $field = 'user_id'; |
212 | 212 | |
213 | 213 | } |
214 | 214 | |
215 | 215 | $stats = array(); |
216 | - $customer = Give()->customers->get_customer_by( $field, $user ); |
|
216 | + $customer = Give()->customers->get_customer_by($field, $user); |
|
217 | 217 | |
218 | - if ( $customer ) { |
|
218 | + if ($customer) { |
|
219 | 219 | |
220 | - $customer = new Give_Customer( $customer->id ); |
|
220 | + $customer = new Give_Customer($customer->id); |
|
221 | 221 | |
222 | - $stats['purchases'] = absint( $customer->purchase_count ); |
|
223 | - $stats['total_spent'] = give_sanitize_amount( $customer->purchase_value ); |
|
222 | + $stats['purchases'] = absint($customer->purchase_count); |
|
223 | + $stats['total_spent'] = give_sanitize_amount($customer->purchase_value); |
|
224 | 224 | |
225 | 225 | } |
226 | 226 | |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | * |
230 | 230 | * @since 1.7 |
231 | 231 | */ |
232 | - $stats = (array) apply_filters( 'give_donation_stats_by_user', $stats, $user ); |
|
232 | + $stats = (array) apply_filters('give_donation_stats_by_user', $stats, $user); |
|
233 | 233 | |
234 | 234 | return $stats; |
235 | 235 | } |
@@ -247,21 +247,21 @@ discard block |
||
247 | 247 | * |
248 | 248 | * @return int The total number of donations |
249 | 249 | */ |
250 | -function give_count_purchases_of_customer( $user = null ) { |
|
250 | +function give_count_purchases_of_customer($user = null) { |
|
251 | 251 | |
252 | 252 | // Logged in? |
253 | - if ( empty( $user ) ) { |
|
253 | + if (empty($user)) { |
|
254 | 254 | $user = get_current_user_id(); |
255 | 255 | } |
256 | 256 | |
257 | 257 | // Email access? |
258 | - if ( empty( $user ) && Give()->email_access->token_email ) { |
|
258 | + if (empty($user) && Give()->email_access->token_email) { |
|
259 | 259 | $user = Give()->email_access->token_email; |
260 | 260 | } |
261 | 261 | |
262 | - $stats = ! empty( $user ) ? give_get_purchase_stats_by_user( $user ) : false; |
|
262 | + $stats = ! empty($user) ? give_get_purchase_stats_by_user($user) : false; |
|
263 | 263 | |
264 | - return isset( $stats['purchases'] ) ? $stats['purchases'] : 0; |
|
264 | + return isset($stats['purchases']) ? $stats['purchases'] : 0; |
|
265 | 265 | } |
266 | 266 | |
267 | 267 | /** |
@@ -274,9 +274,9 @@ discard block |
||
274 | 274 | * |
275 | 275 | * @return float The total amount the user has spent |
276 | 276 | */ |
277 | -function give_purchase_total_of_user( $user = null ) { |
|
277 | +function give_purchase_total_of_user($user = null) { |
|
278 | 278 | |
279 | - $stats = give_get_purchase_stats_by_user( $user ); |
|
279 | + $stats = give_get_purchase_stats_by_user($user); |
|
280 | 280 | |
281 | 281 | return $stats['total_spent']; |
282 | 282 | } |
@@ -292,40 +292,40 @@ discard block |
||
292 | 292 | * |
293 | 293 | * @return bool |
294 | 294 | */ |
295 | -function give_validate_username( $username, $form_id = 0 ) { |
|
295 | +function give_validate_username($username, $form_id = 0) { |
|
296 | 296 | $valid = true; |
297 | 297 | |
298 | 298 | // Validate username. |
299 | - if ( ! empty( $username ) ) { |
|
299 | + if ( ! empty($username)) { |
|
300 | 300 | |
301 | 301 | // Sanitize username. |
302 | - $sanitized_user_name = sanitize_user( $username, false ); |
|
302 | + $sanitized_user_name = sanitize_user($username, false); |
|
303 | 303 | |
304 | 304 | // We have an user name, check if it already exists. |
305 | - if ( username_exists( $username ) ) { |
|
305 | + if (username_exists($username)) { |
|
306 | 306 | // Username already registered. |
307 | - give_set_error( 'username_unavailable', esc_html__( 'Username already taken.', 'give' ) ); |
|
307 | + give_set_error('username_unavailable', esc_html__('Username already taken.', 'give')); |
|
308 | 308 | $valid = false; |
309 | 309 | |
310 | 310 | // Check if it's valid. |
311 | - } elseif ( $sanitized_user_name !== $username ) { |
|
311 | + } elseif ($sanitized_user_name !== $username) { |
|
312 | 312 | // Invalid username. |
313 | - if ( is_multisite() ) { |
|
314 | - give_set_error( 'username_invalid', esc_html__( 'Invalid username. Only lowercase letters (a-z) and numbers are allowed.', 'give' ) ); |
|
313 | + if (is_multisite()) { |
|
314 | + give_set_error('username_invalid', esc_html__('Invalid username. Only lowercase letters (a-z) and numbers are allowed.', 'give')); |
|
315 | 315 | $valid = false; |
316 | 316 | } else { |
317 | - give_set_error( 'username_invalid', esc_html__( 'Invalid username.', 'give' ) ); |
|
317 | + give_set_error('username_invalid', esc_html__('Invalid username.', 'give')); |
|
318 | 318 | $valid = false; |
319 | 319 | } |
320 | 320 | } |
321 | 321 | } else { |
322 | 322 | // Username is empty. |
323 | - give_set_error( 'username_empty', esc_html__( 'Enter a username.', 'give' ) ); |
|
323 | + give_set_error('username_empty', esc_html__('Enter a username.', 'give')); |
|
324 | 324 | $valid = false; |
325 | 325 | |
326 | 326 | // Check if guest checkout is disable for form. |
327 | - if ( $form_id && give_logged_in_only( $form_id ) ) { |
|
328 | - give_set_error( 'registration_required', esc_html__( 'You must register or login to complete your donation.', 'give' ) ); |
|
327 | + if ($form_id && give_logged_in_only($form_id)) { |
|
328 | + give_set_error('registration_required', esc_html__('You must register or login to complete your donation.', 'give')); |
|
329 | 329 | $valid = false; |
330 | 330 | } |
331 | 331 | } |
@@ -339,7 +339,7 @@ discard block |
||
339 | 339 | * @param string $username |
340 | 340 | * @param bool $form_id |
341 | 341 | */ |
342 | - $valid = (bool) apply_filters( 'give_validate_username', $valid, $username, $form_id ); |
|
342 | + $valid = (bool) apply_filters('give_validate_username', $valid, $username, $form_id); |
|
343 | 343 | |
344 | 344 | return $valid; |
345 | 345 | } |
@@ -355,22 +355,22 @@ discard block |
||
355 | 355 | * |
356 | 356 | * @return bool |
357 | 357 | */ |
358 | -function give_validate_user_email( $email, $registering_new_user = false ) { |
|
358 | +function give_validate_user_email($email, $registering_new_user = false) { |
|
359 | 359 | $valid = true; |
360 | 360 | |
361 | - if ( empty( $email ) ) { |
|
361 | + if (empty($email)) { |
|
362 | 362 | // No email. |
363 | - give_set_error( 'email_empty', esc_html__( 'Enter an email.', 'give' ) ); |
|
363 | + give_set_error('email_empty', esc_html__('Enter an email.', 'give')); |
|
364 | 364 | $valid = false; |
365 | 365 | |
366 | - } elseif ( ! is_email( $email ) ) { |
|
366 | + } elseif ( ! is_email($email)) { |
|
367 | 367 | // Validate email. |
368 | - give_set_error( 'email_invalid', esc_html__( 'Invalid email.', 'give' ) ); |
|
368 | + give_set_error('email_invalid', esc_html__('Invalid email.', 'give')); |
|
369 | 369 | $valid = false; |
370 | 370 | |
371 | - } elseif ( $registering_new_user && email_exists( $email ) ) { |
|
371 | + } elseif ($registering_new_user && email_exists($email)) { |
|
372 | 372 | // Check if email exists. |
373 | - give_set_error( 'email_used', esc_html__( 'The email already active for another user.', 'give' ) ); |
|
373 | + give_set_error('email_used', esc_html__('The email already active for another user.', 'give')); |
|
374 | 374 | $valid = false; |
375 | 375 | } |
376 | 376 | |
@@ -383,7 +383,7 @@ discard block |
||
383 | 383 | * @param string $email |
384 | 384 | * @param bool $registering_new_user |
385 | 385 | */ |
386 | - $valid = (bool) apply_filters( 'give_validate_user_email', $valid, $email, $registering_new_user ); |
|
386 | + $valid = (bool) apply_filters('give_validate_user_email', $valid, $email, $registering_new_user); |
|
387 | 387 | |
388 | 388 | return $valid; |
389 | 389 | } |
@@ -399,25 +399,25 @@ discard block |
||
399 | 399 | * |
400 | 400 | * @return bool |
401 | 401 | */ |
402 | -function give_validate_user_password( $password = '', $confirm_password = '', $registering_new_user = false ) { |
|
402 | +function give_validate_user_password($password = '', $confirm_password = '', $registering_new_user = false) { |
|
403 | 403 | $valid = true; |
404 | 404 | |
405 | - if ( $password && $confirm_password ) { |
|
405 | + if ($password && $confirm_password) { |
|
406 | 406 | // Verify confirmation matches. |
407 | - if ( $password != $confirm_password ) { |
|
407 | + if ($password != $confirm_password) { |
|
408 | 408 | // Passwords do not match |
409 | - give_set_error( 'password_mismatch', esc_html__( 'Passwords don\'t match.', 'give' ) ); |
|
409 | + give_set_error('password_mismatch', esc_html__('Passwords don\'t match.', 'give')); |
|
410 | 410 | $valid = false; |
411 | 411 | } |
412 | - } elseif ( $registering_new_user ) { |
|
412 | + } elseif ($registering_new_user) { |
|
413 | 413 | // Password or confirmation missing. |
414 | - if ( ! $password ) { |
|
414 | + if ( ! $password) { |
|
415 | 415 | // The password is invalid. |
416 | - give_set_error( 'password_empty', esc_html__( 'Enter a password.', 'give' ) ); |
|
416 | + give_set_error('password_empty', esc_html__('Enter a password.', 'give')); |
|
417 | 417 | $valid = false; |
418 | - } elseif ( ! $confirm_password ) { |
|
418 | + } elseif ( ! $confirm_password) { |
|
419 | 419 | // Confirmation password is invalid. |
420 | - give_set_error( 'confirmation_empty', esc_html__( 'Enter the password confirmation.', 'give' ) ); |
|
420 | + give_set_error('confirmation_empty', esc_html__('Enter the password confirmation.', 'give')); |
|
421 | 421 | $valid = false; |
422 | 422 | } |
423 | 423 | } |
@@ -432,7 +432,7 @@ discard block |
||
432 | 432 | * @param string $confirm_password |
433 | 433 | * @param bool $registering_new_user |
434 | 434 | */ |
435 | - $valid = (bool) apply_filters( 'give_validate_user_email', $valid, $password, $confirm_password, $registering_new_user ); |
|
435 | + $valid = (bool) apply_filters('give_validate_user_email', $valid, $password, $confirm_password, $registering_new_user); |
|
436 | 436 | |
437 | 437 | return $valid; |
438 | 438 | } |
@@ -451,32 +451,32 @@ discard block |
||
451 | 451 | * |
452 | 452 | * @return void |
453 | 453 | */ |
454 | -function give_add_past_purchases_to_new_user( $user_id ) { |
|
454 | +function give_add_past_purchases_to_new_user($user_id) { |
|
455 | 455 | |
456 | - $email = get_the_author_meta( 'user_email', $user_id ); |
|
456 | + $email = get_the_author_meta('user_email', $user_id); |
|
457 | 457 | |
458 | - $payments = give_get_payments( array( 's' => $email ) ); |
|
458 | + $payments = give_get_payments(array('s' => $email)); |
|
459 | 459 | |
460 | - if ( $payments ) { |
|
461 | - foreach ( $payments as $payment ) { |
|
462 | - if ( intval( give_get_payment_user_id( $payment->ID ) ) > 0 ) { |
|
460 | + if ($payments) { |
|
461 | + foreach ($payments as $payment) { |
|
462 | + if (intval(give_get_payment_user_id($payment->ID)) > 0) { |
|
463 | 463 | continue; |
464 | 464 | } // This payment already associated with an account |
465 | 465 | |
466 | - $meta = give_get_payment_meta( $payment->ID ); |
|
467 | - $meta['user_info'] = maybe_unserialize( $meta['user_info'] ); |
|
466 | + $meta = give_get_payment_meta($payment->ID); |
|
467 | + $meta['user_info'] = maybe_unserialize($meta['user_info']); |
|
468 | 468 | $meta['user_info']['id'] = $user_id; |
469 | 469 | $meta['user_info'] = $meta['user_info']; |
470 | 470 | |
471 | 471 | // Store the updated user ID in the payment meta |
472 | - give_update_payment_meta( $payment->ID, '_give_payment_meta', $meta ); |
|
473 | - give_update_payment_meta( $payment->ID, '_give_payment_user_id', $user_id ); |
|
472 | + give_update_payment_meta($payment->ID, '_give_payment_meta', $meta); |
|
473 | + give_update_payment_meta($payment->ID, '_give_payment_user_id', $user_id); |
|
474 | 474 | } |
475 | 475 | } |
476 | 476 | |
477 | 477 | } |
478 | 478 | |
479 | -add_action( 'user_register', 'give_add_past_purchases_to_new_user' ); |
|
479 | +add_action('user_register', 'give_add_past_purchases_to_new_user'); |
|
480 | 480 | |
481 | 481 | |
482 | 482 | /** |
@@ -502,34 +502,34 @@ discard block |
||
502 | 502 | * |
503 | 503 | * @return array The donor's address, if any |
504 | 504 | */ |
505 | -function give_get_donor_address( $user_id = 0 ) { |
|
506 | - if ( empty( $user_id ) ) { |
|
505 | +function give_get_donor_address($user_id = 0) { |
|
506 | + if (empty($user_id)) { |
|
507 | 507 | $user_id = get_current_user_id(); |
508 | 508 | } |
509 | 509 | |
510 | - $address = get_user_meta( $user_id, '_give_user_address', true ); |
|
510 | + $address = get_user_meta($user_id, '_give_user_address', true); |
|
511 | 511 | |
512 | - if ( ! isset( $address['line1'] ) ) { |
|
512 | + if ( ! isset($address['line1'])) { |
|
513 | 513 | $address['line1'] = ''; |
514 | 514 | } |
515 | 515 | |
516 | - if ( ! isset( $address['line2'] ) ) { |
|
516 | + if ( ! isset($address['line2'])) { |
|
517 | 517 | $address['line2'] = ''; |
518 | 518 | } |
519 | 519 | |
520 | - if ( ! isset( $address['city'] ) ) { |
|
520 | + if ( ! isset($address['city'])) { |
|
521 | 521 | $address['city'] = ''; |
522 | 522 | } |
523 | 523 | |
524 | - if ( ! isset( $address['zip'] ) ) { |
|
524 | + if ( ! isset($address['zip'])) { |
|
525 | 525 | $address['zip'] = ''; |
526 | 526 | } |
527 | 527 | |
528 | - if ( ! isset( $address['country'] ) ) { |
|
528 | + if ( ! isset($address['country'])) { |
|
529 | 529 | $address['country'] = ''; |
530 | 530 | } |
531 | 531 | |
532 | - if ( ! isset( $address['state'] ) ) { |
|
532 | + if ( ! isset($address['state'])) { |
|
533 | 533 | $address['state'] = ''; |
534 | 534 | } |
535 | 535 | |
@@ -549,42 +549,42 @@ discard block |
||
549 | 549 | * |
550 | 550 | * @return void |
551 | 551 | */ |
552 | -function give_new_user_notification( $user_id = 0, $user_data = array() ) { |
|
552 | +function give_new_user_notification($user_id = 0, $user_data = array()) { |
|
553 | 553 | |
554 | - if ( empty( $user_id ) || empty( $user_data ) ) { |
|
554 | + if (empty($user_id) || empty($user_data)) { |
|
555 | 555 | return; |
556 | 556 | } |
557 | - $blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); |
|
557 | + $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); |
|
558 | 558 | |
559 | 559 | /* translators: %s: site name */ |
560 | - $message = sprintf( esc_attr__( 'New user registration on your site %s:', 'give' ), $blogname ) . "\r\n\r\n"; |
|
560 | + $message = sprintf(esc_attr__('New user registration on your site %s:', 'give'), $blogname)."\r\n\r\n"; |
|
561 | 561 | /* translators: %s: user login */ |
562 | - $message .= sprintf( esc_attr__( 'Username: %s', 'give' ), $user_data['user_login'] ) . "\r\n\r\n"; |
|
562 | + $message .= sprintf(esc_attr__('Username: %s', 'give'), $user_data['user_login'])."\r\n\r\n"; |
|
563 | 563 | /* translators: %s: user email */ |
564 | - $message .= sprintf( esc_attr__( 'E-mail: %s', 'give' ), $user_data['user_email'] ) . "\r\n"; |
|
564 | + $message .= sprintf(esc_attr__('E-mail: %s', 'give'), $user_data['user_email'])."\r\n"; |
|
565 | 565 | |
566 | 566 | @wp_mail( |
567 | - get_option( 'admin_email' ), |
|
567 | + get_option('admin_email'), |
|
568 | 568 | sprintf( |
569 | 569 | /* translators: %s: site name */ |
570 | - esc_attr__( '[%s] New User Registration', 'give' ), |
|
570 | + esc_attr__('[%s] New User Registration', 'give'), |
|
571 | 571 | $blogname |
572 | 572 | ), |
573 | 573 | $message |
574 | 574 | ); |
575 | 575 | |
576 | 576 | /* translators: %s: user login */ |
577 | - $message = sprintf( esc_attr__( 'Username: %s', 'give' ), $user_data['user_login'] ) . "\r\n"; |
|
577 | + $message = sprintf(esc_attr__('Username: %s', 'give'), $user_data['user_login'])."\r\n"; |
|
578 | 578 | /* translators: %s: paswword */ |
579 | - $message .= sprintf( esc_attr__( 'Password: %s', 'give' ), esc_attr__( '[Password entered during donation]', 'give' ) ) . "\r\n"; |
|
579 | + $message .= sprintf(esc_attr__('Password: %s', 'give'), esc_attr__('[Password entered during donation]', 'give'))."\r\n"; |
|
580 | 580 | |
581 | - $message .= '<a href="' . wp_login_url() . '"> ' . esc_attr__( 'Click Here to Login »', 'give' ) . '</a>' . "\r\n"; |
|
581 | + $message .= '<a href="'.wp_login_url().'"> '.esc_attr__('Click Here to Login »', 'give').'</a>'."\r\n"; |
|
582 | 582 | |
583 | 583 | wp_mail( |
584 | 584 | $user_data['user_email'], |
585 | 585 | sprintf( |
586 | 586 | /* translators: %s: site name */ |
587 | - esc_attr__( '[%s] Your username and password', 'give' ), |
|
587 | + esc_attr__('[%s] Your username and password', 'give'), |
|
588 | 588 | $blogname |
589 | 589 | ), |
590 | 590 | $message |
@@ -592,4 +592,4 @@ discard block |
||
592 | 592 | |
593 | 593 | } |
594 | 594 | |
595 | -add_action( 'give_insert_user', 'give_new_user_notification', 10, 2 ); |
|
595 | +add_action('give_insert_user', 'give_new_user_notification', 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 | |
@@ -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_donation_form' ); |
|
164 | -add_action( 'wp_ajax_give_process_donation', 'give_process_donation_form' ); |
|
165 | -add_action( 'wp_ajax_nopriv_give_process_donation', 'give_process_donation_form' ); |
|
163 | +add_action('give_purchase', 'give_process_donation_form'); |
|
164 | +add_action('wp_ajax_give_process_donation', 'give_process_donation_form'); |
|
165 | +add_action('wp_ajax_nopriv_give_process_donation', 'give_process_donation_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_donation_login', 'give_process_form_login' ); |
|
238 | -add_action( 'wp_ajax_nopriv_give_process_donation_login', 'give_process_form_login' ); |
|
237 | +add_action('wp_ajax_give_process_donation_login', 'give_process_form_login'); |
|
238 | +add_action('wp_ajax_nopriv_give_process_donation_login', 'give_process_form_login'); |
|
239 | 239 | |
240 | 240 | /** |
241 | 241 | * Donation Form Validate Fields |
@@ -247,55 +247,55 @@ 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 | 278 | // Stop processing donor registration, if donor registration is optional and donor can do guest checkout. |
279 | 279 | // If registration form username field is empty that means donor do not want to registration instead want guest checkout. |
280 | 280 | if ( |
281 | - ! give_logged_in_only( $form_id ) |
|
282 | - && isset( $_POST['give-purchase-var'] ) |
|
281 | + ! give_logged_in_only($form_id) |
|
282 | + && isset($_POST['give-purchase-var']) |
|
283 | 283 | && $_POST['give-purchase-var'] == 'needs-to-register' |
284 | - && empty( $_POST['give_user_login'] ) |
|
284 | + && empty($_POST['give_user_login']) |
|
285 | 285 | ) { |
286 | - unset( $_POST['give-purchase-var'] ); |
|
286 | + unset($_POST['give-purchase-var']); |
|
287 | 287 | } |
288 | 288 | |
289 | - if ( is_user_logged_in() ) { |
|
289 | + if (is_user_logged_in()) { |
|
290 | 290 | // Collect logged in user data |
291 | 291 | $valid_data['logged_in_user'] = give_purchase_form_validate_logged_in_user(); |
292 | - } elseif ( isset( $_POST['give-purchase-var'] ) && $_POST['give-purchase-var'] == 'needs-to-register' ) { |
|
292 | + } elseif (isset($_POST['give-purchase-var']) && $_POST['give-purchase-var'] == 'needs-to-register') { |
|
293 | 293 | // Set new user registration as required |
294 | 294 | $valid_data['need_new_user'] = true; |
295 | 295 | // Validate new user data |
296 | 296 | $valid_data['new_user_data'] = give_purchase_form_validate_new_user(); |
297 | 297 | // Check if login validation is needed |
298 | - } elseif ( isset( $_POST['give-purchase-var'] ) && $_POST['give-purchase-var'] == 'needs-to-login' ) { |
|
298 | + } elseif (isset($_POST['give-purchase-var']) && $_POST['give-purchase-var'] == 'needs-to-login') { |
|
299 | 299 | // Set user login as required |
300 | 300 | $valid_data['need_user_login'] = true; |
301 | 301 | // Validate users login info |
@@ -320,41 +320,41 @@ discard block |
||
320 | 320 | */ |
321 | 321 | function give_purchase_form_validate_gateway() { |
322 | 322 | |
323 | - $form_id = isset( $_REQUEST['give-form-id'] ) ? $_REQUEST['give-form-id'] : 0; |
|
324 | - $amount = isset( $_REQUEST['give-amount'] ) ? give_sanitize_amount( $_REQUEST['give-amount'] ) : 0; |
|
325 | - $gateway = give_get_default_gateway( $form_id ); |
|
323 | + $form_id = isset($_REQUEST['give-form-id']) ? $_REQUEST['give-form-id'] : 0; |
|
324 | + $amount = isset($_REQUEST['give-amount']) ? give_sanitize_amount($_REQUEST['give-amount']) : 0; |
|
325 | + $gateway = give_get_default_gateway($form_id); |
|
326 | 326 | |
327 | 327 | // Check if a gateway value is present |
328 | - if ( ! empty( $_REQUEST['give-gateway'] ) ) { |
|
328 | + if ( ! empty($_REQUEST['give-gateway'])) { |
|
329 | 329 | |
330 | - $gateway = sanitize_text_field( $_REQUEST['give-gateway'] ); |
|
330 | + $gateway = sanitize_text_field($_REQUEST['give-gateway']); |
|
331 | 331 | |
332 | 332 | // Is amount being donated in LIVE mode 0.00? If so, error: |
333 | - if ( $amount == 0 && ! give_is_test_mode() ) { |
|
333 | + if ($amount == 0 && ! give_is_test_mode()) { |
|
334 | 334 | |
335 | - give_set_error( 'invalid_donation_amount', esc_html__( 'Please insert a valid donation amount.', 'give' ) ); |
|
335 | + give_set_error('invalid_donation_amount', esc_html__('Please insert a valid donation amount.', 'give')); |
|
336 | 336 | |
337 | 337 | } //Check for a minimum custom amount |
338 | - elseif ( ! give_verify_minimum_price() ) { |
|
338 | + elseif ( ! give_verify_minimum_price()) { |
|
339 | 339 | // translators: %s: minimum donation amount. |
340 | 340 | give_set_error( |
341 | 341 | 'invalid_donation_minimum', |
342 | 342 | sprintf( |
343 | 343 | /* translators: %s: minimum donation amount */ |
344 | - esc_html__( 'This form has a minimum donation amount of %s.', 'give' ), |
|
345 | - give_currency_filter( give_format_amount( give_get_form_minimum_price( $form_id ) ) ) |
|
344 | + esc_html__('This form has a minimum donation amount of %s.', 'give'), |
|
345 | + give_currency_filter(give_format_amount(give_get_form_minimum_price($form_id))) |
|
346 | 346 | ) |
347 | 347 | ); |
348 | 348 | |
349 | 349 | } //Is this test mode zero donation? Let it through but set to manual gateway. |
350 | - elseif ( $amount == 0 && give_is_test_mode() ) { |
|
350 | + elseif ($amount == 0 && give_is_test_mode()) { |
|
351 | 351 | |
352 | 352 | $gateway = 'manual'; |
353 | 353 | |
354 | 354 | } //Check if this gateway is active. |
355 | - elseif ( ! give_is_gateway_active( $gateway ) ) { |
|
355 | + elseif ( ! give_is_gateway_active($gateway)) { |
|
356 | 356 | |
357 | - give_set_error( 'invalid_gateway', esc_html__( 'The selected payment gateway is not enabled.', 'give' ) ); |
|
357 | + give_set_error('invalid_gateway', esc_html__('The selected payment gateway is not enabled.', 'give')); |
|
358 | 358 | |
359 | 359 | } |
360 | 360 | } |
@@ -372,23 +372,23 @@ discard block |
||
372 | 372 | */ |
373 | 373 | function give_verify_minimum_price() { |
374 | 374 | |
375 | - $amount = give_sanitize_amount( $_REQUEST['give-amount'] ); |
|
376 | - $form_id = isset( $_REQUEST['give-form-id'] ) ? $_REQUEST['give-form-id'] : 0; |
|
377 | - $price_id = isset( $_REQUEST['give-price-id'] ) ? $_REQUEST['give-price-id'] : 0; |
|
378 | - $variable_prices = give_has_variable_prices( $form_id ); |
|
375 | + $amount = give_sanitize_amount($_REQUEST['give-amount']); |
|
376 | + $form_id = isset($_REQUEST['give-form-id']) ? $_REQUEST['give-form-id'] : 0; |
|
377 | + $price_id = isset($_REQUEST['give-price-id']) ? $_REQUEST['give-price-id'] : 0; |
|
378 | + $variable_prices = give_has_variable_prices($form_id); |
|
379 | 379 | |
380 | - if ( $variable_prices && ! empty( $price_id ) ) { |
|
380 | + if ($variable_prices && ! empty($price_id)) { |
|
381 | 381 | |
382 | - $price_level_amount = give_get_price_option_amount( $form_id, $price_id ); |
|
382 | + $price_level_amount = give_get_price_option_amount($form_id, $price_id); |
|
383 | 383 | |
384 | - if ( $price_level_amount == $amount ) { |
|
384 | + if ($price_level_amount == $amount) { |
|
385 | 385 | return true; |
386 | 386 | } |
387 | 387 | } |
388 | 388 | |
389 | - $minimum = give_get_form_minimum_price( $form_id ); |
|
389 | + $minimum = give_get_form_minimum_price($form_id); |
|
390 | 390 | |
391 | - if ( $minimum > $amount ) { |
|
391 | + if ($minimum > $amount) { |
|
392 | 392 | return false; |
393 | 393 | } |
394 | 394 | |
@@ -404,9 +404,9 @@ discard block |
||
404 | 404 | */ |
405 | 405 | function give_purchase_form_validate_agree_to_terms() { |
406 | 406 | // Validate agree to terms. |
407 | - if ( ! isset( $_POST['give_agree_to_terms'] ) || $_POST['give_agree_to_terms'] != 1 ) { |
|
407 | + if ( ! isset($_POST['give_agree_to_terms']) || $_POST['give_agree_to_terms'] != 1) { |
|
408 | 408 | // User did not agree. |
409 | - give_set_error( 'agree_to_terms', apply_filters( 'give_agree_to_terms_text', esc_html__( 'You must agree to the terms and conditions.', 'give' ) ) ); |
|
409 | + give_set_error('agree_to_terms', apply_filters('give_agree_to_terms_text', esc_html__('You must agree to the terms and conditions.', 'give'))); |
|
410 | 410 | } |
411 | 411 | } |
412 | 412 | |
@@ -420,43 +420,43 @@ discard block |
||
420 | 420 | * |
421 | 421 | * @return array |
422 | 422 | */ |
423 | -function give_get_required_fields( $form_id ) { |
|
423 | +function give_get_required_fields($form_id) { |
|
424 | 424 | |
425 | - $payment_mode = give_get_chosen_gateway( $form_id ); |
|
425 | + $payment_mode = give_get_chosen_gateway($form_id); |
|
426 | 426 | |
427 | 427 | $required_fields = array( |
428 | 428 | 'give_email' => array( |
429 | 429 | 'error_id' => 'invalid_email', |
430 | - 'error_message' => esc_html__( 'Please enter a valid email address.', 'give' ), |
|
430 | + 'error_message' => esc_html__('Please enter a valid email address.', 'give'), |
|
431 | 431 | ), |
432 | 432 | 'give_first' => array( |
433 | 433 | 'error_id' => 'invalid_first_name', |
434 | - 'error_message' => esc_html__( 'Please enter your first name.', 'give' ), |
|
434 | + 'error_message' => esc_html__('Please enter your first name.', 'give'), |
|
435 | 435 | ), |
436 | 436 | ); |
437 | 437 | |
438 | - $require_address = give_require_billing_address( $payment_mode ); |
|
438 | + $require_address = give_require_billing_address($payment_mode); |
|
439 | 439 | |
440 | - if ( $require_address ) { |
|
441 | - $required_fields['card_address'] = array( |
|
440 | + if ($require_address) { |
|
441 | + $required_fields['card_address'] = array( |
|
442 | 442 | 'error_id' => 'invalid_card_address', |
443 | - 'error_message' => esc_html__( 'Please enter your primary billing address.', 'give' ), |
|
443 | + 'error_message' => esc_html__('Please enter your primary billing address.', 'give'), |
|
444 | 444 | ); |
445 | - $required_fields['card_zip'] = array( |
|
445 | + $required_fields['card_zip'] = array( |
|
446 | 446 | 'error_id' => 'invalid_zip_code', |
447 | - 'error_message' => esc_html__( 'Please enter your zip / postal code.', 'give' ), |
|
447 | + 'error_message' => esc_html__('Please enter your zip / postal code.', 'give'), |
|
448 | 448 | ); |
449 | - $required_fields['card_city'] = array( |
|
449 | + $required_fields['card_city'] = array( |
|
450 | 450 | 'error_id' => 'invalid_city', |
451 | - 'error_message' => esc_html__( 'Please enter your billing city.', 'give' ), |
|
451 | + 'error_message' => esc_html__('Please enter your billing city.', 'give'), |
|
452 | 452 | ); |
453 | 453 | $required_fields['billing_country'] = array( |
454 | 454 | 'error_id' => 'invalid_country', |
455 | - 'error_message' => esc_html__( 'Please select your billing country.', 'give' ), |
|
455 | + 'error_message' => esc_html__('Please select your billing country.', 'give'), |
|
456 | 456 | ); |
457 | - $required_fields['card_state'] = array( |
|
457 | + $required_fields['card_state'] = array( |
|
458 | 458 | 'error_id' => 'invalid_state', |
459 | - 'error_message' => esc_html__( 'Please enter billing state / province.', 'give' ), |
|
459 | + 'error_message' => esc_html__('Please enter billing state / province.', 'give'), |
|
460 | 460 | ); |
461 | 461 | } |
462 | 462 | |
@@ -465,7 +465,7 @@ discard block |
||
465 | 465 | * |
466 | 466 | * @since 1.7 |
467 | 467 | */ |
468 | - $required_fields = apply_filters( 'give_donation_form_required_fields', $required_fields, $form_id ); |
|
468 | + $required_fields = apply_filters('give_donation_form_required_fields', $required_fields, $form_id); |
|
469 | 469 | |
470 | 470 | return $required_fields; |
471 | 471 | |
@@ -480,16 +480,16 @@ discard block |
||
480 | 480 | * |
481 | 481 | * @return mixed|void |
482 | 482 | */ |
483 | -function give_require_billing_address( $payment_mode ) { |
|
483 | +function give_require_billing_address($payment_mode) { |
|
484 | 484 | |
485 | 485 | $return = false; |
486 | 486 | |
487 | - if ( isset( $_POST['billing_country'] ) || did_action( "give_{$payment_mode}_cc_form" ) || did_action( 'give_cc_form' ) ) { |
|
487 | + if (isset($_POST['billing_country']) || did_action("give_{$payment_mode}_cc_form") || did_action('give_cc_form')) { |
|
488 | 488 | $return = true; |
489 | 489 | } |
490 | 490 | |
491 | 491 | // Let payment gateways and other extensions determine if address fields should be required. |
492 | - return apply_filters( 'give_require_billing_address', $return ); |
|
492 | + return apply_filters('give_require_billing_address', $return); |
|
493 | 493 | |
494 | 494 | } |
495 | 495 | |
@@ -503,42 +503,42 @@ discard block |
||
503 | 503 | function give_purchase_form_validate_logged_in_user() { |
504 | 504 | global $user_ID; |
505 | 505 | |
506 | - $form_id = isset( $_POST['give-form-id'] ) ? $_POST['give-form-id'] : ''; |
|
506 | + $form_id = isset($_POST['give-form-id']) ? $_POST['give-form-id'] : ''; |
|
507 | 507 | |
508 | 508 | // Start empty array to collect valid user data. |
509 | 509 | $valid_user_data = array( |
510 | 510 | // Assume there will be errors. |
511 | - 'user_id' => - 1, |
|
511 | + 'user_id' => -1, |
|
512 | 512 | ); |
513 | 513 | |
514 | 514 | // Verify there is a user_ID. |
515 | - if ( $user_ID > 0 ) { |
|
515 | + if ($user_ID > 0) { |
|
516 | 516 | // Get the logged in user data. |
517 | - $user_data = get_userdata( $user_ID ); |
|
517 | + $user_data = get_userdata($user_ID); |
|
518 | 518 | |
519 | 519 | // Loop through required fields and show error messages. |
520 | - foreach ( give_get_required_fields( $form_id ) as $field_name => $value ) { |
|
521 | - if ( in_array( $value, give_get_required_fields( $form_id ) ) && empty( $_POST[ $field_name ] ) ) { |
|
522 | - give_set_error( $value['error_id'], $value['error_message'] ); |
|
520 | + foreach (give_get_required_fields($form_id) as $field_name => $value) { |
|
521 | + if (in_array($value, give_get_required_fields($form_id)) && empty($_POST[$field_name])) { |
|
522 | + give_set_error($value['error_id'], $value['error_message']); |
|
523 | 523 | } |
524 | 524 | } |
525 | 525 | |
526 | 526 | // Verify data. |
527 | - if ( $user_data ) { |
|
527 | + if ($user_data) { |
|
528 | 528 | // Collected logged in user data. |
529 | 529 | $valid_user_data = array( |
530 | 530 | 'user_id' => $user_ID, |
531 | - 'user_email' => isset( $_POST['give_email'] ) ? sanitize_email( $_POST['give_email'] ) : $user_data->user_email, |
|
532 | - 'user_first' => isset( $_POST['give_first'] ) && ! empty( $_POST['give_first'] ) ? sanitize_text_field( $_POST['give_first'] ) : $user_data->first_name, |
|
533 | - 'user_last' => isset( $_POST['give_last'] ) && ! empty( $_POST['give_last'] ) ? sanitize_text_field( $_POST['give_last'] ) : $user_data->last_name, |
|
531 | + 'user_email' => isset($_POST['give_email']) ? sanitize_email($_POST['give_email']) : $user_data->user_email, |
|
532 | + 'user_first' => isset($_POST['give_first']) && ! empty($_POST['give_first']) ? sanitize_text_field($_POST['give_first']) : $user_data->first_name, |
|
533 | + 'user_last' => isset($_POST['give_last']) && ! empty($_POST['give_last']) ? sanitize_text_field($_POST['give_last']) : $user_data->last_name, |
|
534 | 534 | ); |
535 | 535 | |
536 | - if ( ! is_email( $valid_user_data['user_email'] ) ) { |
|
537 | - give_set_error( 'email_invalid', esc_html__( 'Invalid email.', 'give' ) ); |
|
536 | + if ( ! is_email($valid_user_data['user_email'])) { |
|
537 | + give_set_error('email_invalid', esc_html__('Invalid email.', 'give')); |
|
538 | 538 | } |
539 | 539 | } else { |
540 | 540 | // Set invalid user error. |
541 | - give_set_error( 'invalid_user', esc_html__( 'The user information is invalid.', 'give' ) ); |
|
541 | + give_set_error('invalid_user', esc_html__('The user information is invalid.', 'give')); |
|
542 | 542 | } |
543 | 543 | } |
544 | 544 | |
@@ -557,7 +557,7 @@ discard block |
||
557 | 557 | // Default user data. |
558 | 558 | $default_user_data = array( |
559 | 559 | 'give-form-id' => '', |
560 | - 'user_id' => - 1, // Assume there will be errors. |
|
560 | + 'user_id' => -1, // Assume there will be errors. |
|
561 | 561 | 'user_first' => '', |
562 | 562 | 'user_last' => '', |
563 | 563 | 'give_user_login' => false, |
@@ -567,14 +567,14 @@ discard block |
||
567 | 567 | ); |
568 | 568 | |
569 | 569 | // Get user data. |
570 | - $user_data = wp_parse_args( array_map( 'trim', give_clean( $_POST ) ), $default_user_data ); |
|
570 | + $user_data = wp_parse_args(array_map('trim', give_clean($_POST)), $default_user_data); |
|
571 | 571 | $registering_new_user = false; |
572 | - $form_id = absint( $user_data['give-form-id'] ); |
|
572 | + $form_id = absint($user_data['give-form-id']); |
|
573 | 573 | |
574 | 574 | // Start an empty array to collect valid user data. |
575 | 575 | $valid_user_data = array( |
576 | 576 | // Assume there will be errors. |
577 | - 'user_id' => - 1, |
|
577 | + 'user_id' => -1, |
|
578 | 578 | |
579 | 579 | // Get first name. |
580 | 580 | 'user_first' => $user_data['give_first'], |
@@ -584,25 +584,25 @@ discard block |
||
584 | 584 | ); |
585 | 585 | |
586 | 586 | // Loop through required fields and show error messages. |
587 | - foreach ( give_get_required_fields( $form_id ) as $field_name => $value ) { |
|
588 | - if ( in_array( $value, give_get_required_fields( $form_id ) ) && empty( $_POST[ $field_name ] ) ) { |
|
589 | - give_set_error( $value['error_id'], $value['error_message'] ); |
|
587 | + foreach (give_get_required_fields($form_id) as $field_name => $value) { |
|
588 | + if (in_array($value, give_get_required_fields($form_id)) && empty($_POST[$field_name])) { |
|
589 | + give_set_error($value['error_id'], $value['error_message']); |
|
590 | 590 | } |
591 | 591 | } |
592 | 592 | |
593 | 593 | // Check if we have an username to register. |
594 | - if ( give_validate_username( $user_data['give_user_login'] ) ) { |
|
594 | + if (give_validate_username($user_data['give_user_login'])) { |
|
595 | 595 | $registering_new_user = true; |
596 | 596 | $valid_user_data['user_login'] = $user_data['give_user_login']; |
597 | 597 | } |
598 | 598 | |
599 | 599 | // Check if we have an email to verify. |
600 | - if ( give_validate_user_email( $user_data['give_email'], $registering_new_user ) ) { |
|
600 | + if (give_validate_user_email($user_data['give_email'], $registering_new_user)) { |
|
601 | 601 | $valid_user_data['user_email'] = $user_data['give_email']; |
602 | 602 | } |
603 | 603 | |
604 | 604 | // Check password. |
605 | - if ( give_validate_user_password( $user_data['give_user_pass'], $user_data['give_user_pass_confirm'], $registering_new_user ) ) { |
|
605 | + if (give_validate_user_password($user_data['give_user_pass'], $user_data['give_user_pass_confirm'], $registering_new_user)) { |
|
606 | 606 | // All is good to go. |
607 | 607 | $valid_user_data['user_pass'] = $user_data['give_user_pass']; |
608 | 608 | } |
@@ -622,36 +622,36 @@ discard block |
||
622 | 622 | // Start an array to collect valid user data. |
623 | 623 | $valid_user_data = array( |
624 | 624 | // Assume there will be errors |
625 | - 'user_id' => - 1, |
|
625 | + 'user_id' => -1, |
|
626 | 626 | ); |
627 | 627 | |
628 | 628 | // Username. |
629 | - if ( ! isset( $_POST['give_user_login'] ) || $_POST['give_user_login'] == '' ) { |
|
630 | - give_set_error( 'must_log_in', esc_html__( 'You must register or login to complete your donation.', 'give' ) ); |
|
629 | + if ( ! isset($_POST['give_user_login']) || $_POST['give_user_login'] == '') { |
|
630 | + give_set_error('must_log_in', esc_html__('You must register or login to complete your donation.', 'give')); |
|
631 | 631 | |
632 | 632 | return $valid_user_data; |
633 | 633 | } |
634 | 634 | |
635 | 635 | // Get the user by login. |
636 | - $user_data = get_user_by( 'login', strip_tags( $_POST['give_user_login'] ) ); |
|
636 | + $user_data = get_user_by('login', strip_tags($_POST['give_user_login'])); |
|
637 | 637 | |
638 | 638 | // Check if user exists. |
639 | - if ( $user_data ) { |
|
639 | + if ($user_data) { |
|
640 | 640 | // Get password. |
641 | - $user_pass = isset( $_POST['give_user_pass'] ) ? $_POST['give_user_pass'] : false; |
|
641 | + $user_pass = isset($_POST['give_user_pass']) ? $_POST['give_user_pass'] : false; |
|
642 | 642 | |
643 | 643 | // Check user_pass. |
644 | - if ( $user_pass ) { |
|
644 | + if ($user_pass) { |
|
645 | 645 | // Check if password is valid. |
646 | - if ( ! wp_check_password( $user_pass, $user_data->user_pass, $user_data->ID ) ) { |
|
646 | + if ( ! wp_check_password($user_pass, $user_data->user_pass, $user_data->ID)) { |
|
647 | 647 | // Incorrect password. |
648 | 648 | give_set_error( |
649 | 649 | 'password_incorrect', |
650 | 650 | sprintf( |
651 | 651 | '%1$s <a href="%2$s">%3$s</a>', |
652 | - esc_html__( 'The password you entered is incorrect.', 'give' ), |
|
653 | - wp_lostpassword_url( "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]" ), |
|
654 | - esc_html__( 'Reset Password', 'give' ) |
|
652 | + esc_html__('The password you entered is incorrect.', 'give'), |
|
653 | + wp_lostpassword_url("http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"), |
|
654 | + esc_html__('Reset Password', 'give') |
|
655 | 655 | ) |
656 | 656 | ); |
657 | 657 | // All is correct. |
@@ -668,11 +668,11 @@ discard block |
||
668 | 668 | } |
669 | 669 | } else { |
670 | 670 | // Empty password. |
671 | - give_set_error( 'password_empty', esc_html__( 'Enter a password.', 'give' ) ); |
|
671 | + give_set_error('password_empty', esc_html__('Enter a password.', 'give')); |
|
672 | 672 | } |
673 | 673 | } else { |
674 | 674 | // No username. |
675 | - give_set_error( 'username_incorrect', esc_html__( 'The username you entered does not exist.', 'give' ) ); |
|
675 | + give_set_error('username_incorrect', esc_html__('The username you entered does not exist.', 'give')); |
|
676 | 676 | } |
677 | 677 | |
678 | 678 | return $valid_user_data; |
@@ -687,7 +687,7 @@ discard block |
||
687 | 687 | */ |
688 | 688 | function give_purchase_form_validate_guest_user() { |
689 | 689 | |
690 | - $form_id = isset( $_POST['give-form-id'] ) ? $_POST['give-form-id'] : ''; |
|
690 | + $form_id = isset($_POST['give-form-id']) ? $_POST['give-form-id'] : ''; |
|
691 | 691 | |
692 | 692 | // Start an array to collect valid user data. |
693 | 693 | $valid_user_data = array( |
@@ -696,38 +696,38 @@ discard block |
||
696 | 696 | ); |
697 | 697 | |
698 | 698 | // Show error message if user must be logged in. |
699 | - if ( give_logged_in_only( $form_id ) ) { |
|
700 | - give_set_error( 'logged_in_only', esc_html__( 'You must be logged in to donate.', 'give' ) ); |
|
699 | + if (give_logged_in_only($form_id)) { |
|
700 | + give_set_error('logged_in_only', esc_html__('You must be logged in to donate.', 'give')); |
|
701 | 701 | } |
702 | 702 | |
703 | 703 | // Get the guest email. |
704 | - $guest_email = isset( $_POST['give_email'] ) ? $_POST['give_email'] : false; |
|
704 | + $guest_email = isset($_POST['give_email']) ? $_POST['give_email'] : false; |
|
705 | 705 | |
706 | 706 | // Check email. |
707 | - if ( $guest_email && strlen( $guest_email ) > 0 ) { |
|
707 | + if ($guest_email && strlen($guest_email) > 0) { |
|
708 | 708 | // Validate email. |
709 | - if ( ! is_email( $guest_email ) ) { |
|
709 | + if ( ! is_email($guest_email)) { |
|
710 | 710 | // Invalid email. |
711 | - give_set_error( 'email_invalid', esc_html__( 'Invalid email.', 'give' ) ); |
|
711 | + give_set_error('email_invalid', esc_html__('Invalid email.', 'give')); |
|
712 | 712 | } else { |
713 | 713 | // All is good to go. |
714 | 714 | $valid_user_data['user_email'] = $guest_email; |
715 | 715 | |
716 | 716 | // Get user_id from donor if exist. |
717 | - $donor = new Give_Customer( $guest_email ); |
|
718 | - if ( $donor->id && $donor->user_id ) { |
|
717 | + $donor = new Give_Customer($guest_email); |
|
718 | + if ($donor->id && $donor->user_id) { |
|
719 | 719 | $valid_user_data['user_id'] = $donor->user_id; |
720 | 720 | } |
721 | 721 | } |
722 | 722 | } else { |
723 | 723 | // No email. |
724 | - give_set_error( 'email_empty', esc_html__( 'Enter an email.', 'give' ) ); |
|
724 | + give_set_error('email_empty', esc_html__('Enter an email.', 'give')); |
|
725 | 725 | } |
726 | 726 | |
727 | 727 | // Loop through required fields and show error messages. |
728 | - foreach ( give_get_required_fields( $form_id ) as $field_name => $value ) { |
|
729 | - if ( in_array( $value, give_get_required_fields( $form_id ) ) && empty( $_POST[ $field_name ] ) ) { |
|
730 | - give_set_error( $value['error_id'], $value['error_message'] ); |
|
728 | + foreach (give_get_required_fields($form_id) as $field_name => $value) { |
|
729 | + if (in_array($value, give_get_required_fields($form_id)) && empty($_POST[$field_name])) { |
|
730 | + give_set_error($value['error_id'], $value['error_message']); |
|
731 | 731 | } |
732 | 732 | } |
733 | 733 | |
@@ -743,36 +743,36 @@ discard block |
||
743 | 743 | * @since 1.0 |
744 | 744 | * @return integer |
745 | 745 | */ |
746 | -function give_register_and_login_new_user( $user_data = array() ) { |
|
746 | +function give_register_and_login_new_user($user_data = array()) { |
|
747 | 747 | // Verify the array. |
748 | - if ( empty( $user_data ) ) { |
|
749 | - return - 1; |
|
748 | + if (empty($user_data)) { |
|
749 | + return -1; |
|
750 | 750 | } |
751 | 751 | |
752 | - if ( give_get_errors() ) { |
|
753 | - return - 1; |
|
752 | + if (give_get_errors()) { |
|
753 | + return -1; |
|
754 | 754 | } |
755 | 755 | |
756 | - $user_args = apply_filters( 'give_insert_user_args', array( |
|
757 | - 'user_login' => isset( $user_data['user_login'] ) ? $user_data['user_login'] : '', |
|
758 | - 'user_pass' => isset( $user_data['user_pass'] ) ? $user_data['user_pass'] : '', |
|
759 | - 'user_email' => isset( $user_data['user_email'] ) ? $user_data['user_email'] : '', |
|
760 | - 'first_name' => isset( $user_data['user_first'] ) ? $user_data['user_first'] : '', |
|
761 | - 'last_name' => isset( $user_data['user_last'] ) ? $user_data['user_last'] : '', |
|
762 | - 'user_registered' => date( 'Y-m-d H:i:s' ), |
|
763 | - 'role' => get_option( 'default_role' ), |
|
764 | - ), $user_data ); |
|
756 | + $user_args = apply_filters('give_insert_user_args', array( |
|
757 | + 'user_login' => isset($user_data['user_login']) ? $user_data['user_login'] : '', |
|
758 | + 'user_pass' => isset($user_data['user_pass']) ? $user_data['user_pass'] : '', |
|
759 | + 'user_email' => isset($user_data['user_email']) ? $user_data['user_email'] : '', |
|
760 | + 'first_name' => isset($user_data['user_first']) ? $user_data['user_first'] : '', |
|
761 | + 'last_name' => isset($user_data['user_last']) ? $user_data['user_last'] : '', |
|
762 | + 'user_registered' => date('Y-m-d H:i:s'), |
|
763 | + 'role' => get_option('default_role'), |
|
764 | + ), $user_data); |
|
765 | 765 | |
766 | 766 | // Insert new user. |
767 | - $user_id = wp_insert_user( $user_args ); |
|
767 | + $user_id = wp_insert_user($user_args); |
|
768 | 768 | |
769 | 769 | // Validate inserted user. |
770 | - if ( is_wp_error( $user_id ) ) { |
|
771 | - return - 1; |
|
770 | + if (is_wp_error($user_id)) { |
|
771 | + return -1; |
|
772 | 772 | } |
773 | 773 | |
774 | 774 | // Allow themes and plugins to filter the user data. |
775 | - $user_data = apply_filters( 'give_insert_user_data', $user_data, $user_args ); |
|
775 | + $user_data = apply_filters('give_insert_user_data', $user_data, $user_args); |
|
776 | 776 | |
777 | 777 | /** |
778 | 778 | * Fires after inserting user. |
@@ -782,10 +782,10 @@ discard block |
||
782 | 782 | * @param int $user_id User id. |
783 | 783 | * @param array $user_data Array containing user data. |
784 | 784 | */ |
785 | - do_action( 'give_insert_user', $user_id, $user_data ); |
|
785 | + do_action('give_insert_user', $user_id, $user_data); |
|
786 | 786 | |
787 | 787 | // Login new user. |
788 | - give_log_user_in( $user_id, $user_data['user_login'], $user_data['user_pass'] ); |
|
788 | + give_log_user_in($user_id, $user_data['user_login'], $user_data['user_pass']); |
|
789 | 789 | |
790 | 790 | // Return user id. |
791 | 791 | return $user_id; |
@@ -800,27 +800,27 @@ discard block |
||
800 | 800 | * @since 1.0 |
801 | 801 | * @return array |
802 | 802 | */ |
803 | -function give_get_purchase_form_user( $valid_data = array() ) { |
|
803 | +function give_get_purchase_form_user($valid_data = array()) { |
|
804 | 804 | |
805 | 805 | // Initialize user. |
806 | 806 | $user = false; |
807 | - $is_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX; |
|
807 | + $is_ajax = defined('DOING_AJAX') && DOING_AJAX; |
|
808 | 808 | |
809 | - if ( $is_ajax ) { |
|
809 | + if ($is_ajax) { |
|
810 | 810 | // Do not create or login the user during the ajax submission (check for errors only). |
811 | 811 | return true; |
812 | - } elseif ( is_user_logged_in() ) { |
|
812 | + } elseif (is_user_logged_in()) { |
|
813 | 813 | // Set the valid user as the logged in collected data. |
814 | 814 | $user = $valid_data['logged_in_user']; |
815 | - } elseif ( $valid_data['need_new_user'] === true || $valid_data['need_user_login'] === true ) { |
|
815 | + } elseif ($valid_data['need_new_user'] === true || $valid_data['need_user_login'] === true) { |
|
816 | 816 | // New user registration. |
817 | - if ( $valid_data['need_new_user'] === true ) { |
|
817 | + if ($valid_data['need_new_user'] === true) { |
|
818 | 818 | // Set user. |
819 | 819 | $user = $valid_data['new_user_data']; |
820 | 820 | // Register and login new user. |
821 | - $user['user_id'] = give_register_and_login_new_user( $user ); |
|
821 | + $user['user_id'] = give_register_and_login_new_user($user); |
|
822 | 822 | // User login |
823 | - } elseif ( $valid_data['need_user_login'] === true && ! $is_ajax ) { |
|
823 | + } elseif ($valid_data['need_user_login'] === true && ! $is_ajax) { |
|
824 | 824 | |
825 | 825 | /* |
826 | 826 | * The login form is now processed in the give_process_purchase_login() function. |
@@ -833,48 +833,48 @@ discard block |
||
833 | 833 | // Set user. |
834 | 834 | $user = $valid_data['login_user_data']; |
835 | 835 | // Login user. |
836 | - give_log_user_in( $user['user_id'], $user['user_login'], $user['user_pass'] ); |
|
836 | + give_log_user_in($user['user_id'], $user['user_login'], $user['user_pass']); |
|
837 | 837 | } |
838 | 838 | } |
839 | 839 | |
840 | 840 | // Check guest checkout. |
841 | - if ( false === $user && false === give_logged_in_only( $_POST['give-form-id'] ) ) { |
|
841 | + if (false === $user && false === give_logged_in_only($_POST['give-form-id'])) { |
|
842 | 842 | // Set user |
843 | 843 | $user = $valid_data['guest_user_data']; |
844 | 844 | } |
845 | 845 | |
846 | 846 | // Verify we have an user. |
847 | - if ( false === $user || empty( $user ) ) { |
|
847 | + if (false === $user || empty($user)) { |
|
848 | 848 | // Return false. |
849 | 849 | return false; |
850 | 850 | } |
851 | 851 | |
852 | 852 | // Get user first name. |
853 | - if ( ! isset( $user['user_first'] ) || strlen( trim( $user['user_first'] ) ) < 1 ) { |
|
854 | - $user['user_first'] = isset( $_POST['give_first'] ) ? strip_tags( trim( $_POST['give_first'] ) ) : ''; |
|
853 | + if ( ! isset($user['user_first']) || strlen(trim($user['user_first'])) < 1) { |
|
854 | + $user['user_first'] = isset($_POST['give_first']) ? strip_tags(trim($_POST['give_first'])) : ''; |
|
855 | 855 | } |
856 | 856 | |
857 | 857 | // Get user last name. |
858 | - if ( ! isset( $user['user_last'] ) || strlen( trim( $user['user_last'] ) ) < 1 ) { |
|
859 | - $user['user_last'] = isset( $_POST['give_last'] ) ? strip_tags( trim( $_POST['give_last'] ) ) : ''; |
|
858 | + if ( ! isset($user['user_last']) || strlen(trim($user['user_last'])) < 1) { |
|
859 | + $user['user_last'] = isset($_POST['give_last']) ? strip_tags(trim($_POST['give_last'])) : ''; |
|
860 | 860 | } |
861 | 861 | |
862 | 862 | // Get the user's billing address details. |
863 | 863 | $user['address'] = array(); |
864 | - $user['address']['line1'] = ! empty( $_POST['card_address'] ) ? sanitize_text_field( $_POST['card_address'] ) : false; |
|
865 | - $user['address']['line2'] = ! empty( $_POST['card_address_2'] ) ? sanitize_text_field( $_POST['card_address_2'] ) : false; |
|
866 | - $user['address']['city'] = ! empty( $_POST['card_city'] ) ? sanitize_text_field( $_POST['card_city'] ) : false; |
|
867 | - $user['address']['state'] = ! empty( $_POST['card_state'] ) ? sanitize_text_field( $_POST['card_state'] ) : false; |
|
868 | - $user['address']['country'] = ! empty( $_POST['billing_country'] ) ? sanitize_text_field( $_POST['billing_country'] ) : false; |
|
869 | - $user['address']['zip'] = ! empty( $_POST['card_zip'] ) ? sanitize_text_field( $_POST['card_zip'] ) : false; |
|
870 | - |
|
871 | - if ( empty( $user['address']['country'] ) ) { |
|
864 | + $user['address']['line1'] = ! empty($_POST['card_address']) ? sanitize_text_field($_POST['card_address']) : false; |
|
865 | + $user['address']['line2'] = ! empty($_POST['card_address_2']) ? sanitize_text_field($_POST['card_address_2']) : false; |
|
866 | + $user['address']['city'] = ! empty($_POST['card_city']) ? sanitize_text_field($_POST['card_city']) : false; |
|
867 | + $user['address']['state'] = ! empty($_POST['card_state']) ? sanitize_text_field($_POST['card_state']) : false; |
|
868 | + $user['address']['country'] = ! empty($_POST['billing_country']) ? sanitize_text_field($_POST['billing_country']) : false; |
|
869 | + $user['address']['zip'] = ! empty($_POST['card_zip']) ? sanitize_text_field($_POST['card_zip']) : false; |
|
870 | + |
|
871 | + if (empty($user['address']['country'])) { |
|
872 | 872 | $user['address'] = false; |
873 | 873 | } // Country will always be set if address fields are present. |
874 | 874 | |
875 | - if ( ! empty( $user['user_id'] ) && $user['user_id'] > 0 && ! empty( $user['address'] ) ) { |
|
875 | + if ( ! empty($user['user_id']) && $user['user_id'] > 0 && ! empty($user['address'])) { |
|
876 | 876 | // Store the address in the user's meta so the donation form can be pre-populated with it on return purchases. |
877 | - update_user_meta( $user['user_id'], '_give_user_address', $user['address'] ); |
|
877 | + update_user_meta($user['user_id'], '_give_user_address', $user['address']); |
|
878 | 878 | } |
879 | 879 | |
880 | 880 | // Return valid user. |
@@ -893,16 +893,16 @@ discard block |
||
893 | 893 | $card_data = give_get_purchase_cc_info(); |
894 | 894 | |
895 | 895 | // Validate the card zip. |
896 | - if ( ! empty( $card_data['card_zip'] ) ) { |
|
897 | - if ( ! give_purchase_form_validate_cc_zip( $card_data['card_zip'], $card_data['card_country'] ) ) { |
|
898 | - give_set_error( 'invalid_cc_zip', esc_html__( 'The zip / postal code you entered for your billing address is invalid.', 'give' ) ); |
|
896 | + if ( ! empty($card_data['card_zip'])) { |
|
897 | + if ( ! give_purchase_form_validate_cc_zip($card_data['card_zip'], $card_data['card_country'])) { |
|
898 | + give_set_error('invalid_cc_zip', esc_html__('The zip / postal code you entered for your billing address is invalid.', 'give')); |
|
899 | 899 | } |
900 | 900 | } |
901 | 901 | |
902 | 902 | // Ensure no spaces. |
903 | - if ( ! empty( $card_data['card_number'] ) ) { |
|
904 | - $card_data['card_number'] = str_replace( '+', '', $card_data['card_number'] ); // no "+" signs |
|
905 | - $card_data['card_number'] = str_replace( ' ', '', $card_data['card_number'] ); // No spaces |
|
903 | + if ( ! empty($card_data['card_number'])) { |
|
904 | + $card_data['card_number'] = str_replace('+', '', $card_data['card_number']); // no "+" signs |
|
905 | + $card_data['card_number'] = str_replace(' ', '', $card_data['card_number']); // No spaces |
|
906 | 906 | } |
907 | 907 | |
908 | 908 | // This should validate card numbers at some point too. |
@@ -918,17 +918,17 @@ discard block |
||
918 | 918 | */ |
919 | 919 | function give_get_purchase_cc_info() { |
920 | 920 | $cc_info = array(); |
921 | - $cc_info['card_name'] = isset( $_POST['card_name'] ) ? sanitize_text_field( $_POST['card_name'] ) : ''; |
|
922 | - $cc_info['card_number'] = isset( $_POST['card_number'] ) ? sanitize_text_field( $_POST['card_number'] ) : ''; |
|
923 | - $cc_info['card_cvc'] = isset( $_POST['card_cvc'] ) ? sanitize_text_field( $_POST['card_cvc'] ) : ''; |
|
924 | - $cc_info['card_exp_month'] = isset( $_POST['card_exp_month'] ) ? sanitize_text_field( $_POST['card_exp_month'] ) : ''; |
|
925 | - $cc_info['card_exp_year'] = isset( $_POST['card_exp_year'] ) ? sanitize_text_field( $_POST['card_exp_year'] ) : ''; |
|
926 | - $cc_info['card_address'] = isset( $_POST['card_address'] ) ? sanitize_text_field( $_POST['card_address'] ) : ''; |
|
927 | - $cc_info['card_address_2'] = isset( $_POST['card_address_2'] ) ? sanitize_text_field( $_POST['card_address_2'] ) : ''; |
|
928 | - $cc_info['card_city'] = isset( $_POST['card_city'] ) ? sanitize_text_field( $_POST['card_city'] ) : ''; |
|
929 | - $cc_info['card_state'] = isset( $_POST['card_state'] ) ? sanitize_text_field( $_POST['card_state'] ) : ''; |
|
930 | - $cc_info['card_country'] = isset( $_POST['billing_country'] ) ? sanitize_text_field( $_POST['billing_country'] ) : ''; |
|
931 | - $cc_info['card_zip'] = isset( $_POST['card_zip'] ) ? sanitize_text_field( $_POST['card_zip'] ) : ''; |
|
921 | + $cc_info['card_name'] = isset($_POST['card_name']) ? sanitize_text_field($_POST['card_name']) : ''; |
|
922 | + $cc_info['card_number'] = isset($_POST['card_number']) ? sanitize_text_field($_POST['card_number']) : ''; |
|
923 | + $cc_info['card_cvc'] = isset($_POST['card_cvc']) ? sanitize_text_field($_POST['card_cvc']) : ''; |
|
924 | + $cc_info['card_exp_month'] = isset($_POST['card_exp_month']) ? sanitize_text_field($_POST['card_exp_month']) : ''; |
|
925 | + $cc_info['card_exp_year'] = isset($_POST['card_exp_year']) ? sanitize_text_field($_POST['card_exp_year']) : ''; |
|
926 | + $cc_info['card_address'] = isset($_POST['card_address']) ? sanitize_text_field($_POST['card_address']) : ''; |
|
927 | + $cc_info['card_address_2'] = isset($_POST['card_address_2']) ? sanitize_text_field($_POST['card_address_2']) : ''; |
|
928 | + $cc_info['card_city'] = isset($_POST['card_city']) ? sanitize_text_field($_POST['card_city']) : ''; |
|
929 | + $cc_info['card_state'] = isset($_POST['card_state']) ? sanitize_text_field($_POST['card_state']) : ''; |
|
930 | + $cc_info['card_country'] = isset($_POST['billing_country']) ? sanitize_text_field($_POST['billing_country']) : ''; |
|
931 | + $cc_info['card_zip'] = isset($_POST['card_zip']) ? sanitize_text_field($_POST['card_zip']) : ''; |
|
932 | 932 | |
933 | 933 | // Return cc info |
934 | 934 | return $cc_info; |
@@ -944,14 +944,14 @@ discard block |
||
944 | 944 | * |
945 | 945 | * @return bool|mixed|void |
946 | 946 | */ |
947 | -function give_purchase_form_validate_cc_zip( $zip = 0, $country_code = '' ) { |
|
947 | +function give_purchase_form_validate_cc_zip($zip = 0, $country_code = '') { |
|
948 | 948 | $ret = false; |
949 | 949 | |
950 | - if ( empty( $zip ) || empty( $country_code ) ) { |
|
950 | + if (empty($zip) || empty($country_code)) { |
|
951 | 951 | return $ret; |
952 | 952 | } |
953 | 953 | |
954 | - $country_code = strtoupper( $country_code ); |
|
954 | + $country_code = strtoupper($country_code); |
|
955 | 955 | |
956 | 956 | $zip_regex = array( |
957 | 957 | 'AD' => 'AD\d{3}', |
@@ -1111,11 +1111,11 @@ discard block |
||
1111 | 1111 | 'ZM' => '\d{5}', |
1112 | 1112 | ); |
1113 | 1113 | |
1114 | - if ( ! isset( $zip_regex[ $country_code ] ) || preg_match( '/' . $zip_regex[ $country_code ] . '/i', $zip ) ) { |
|
1114 | + if ( ! isset($zip_regex[$country_code]) || preg_match('/'.$zip_regex[$country_code].'/i', $zip)) { |
|
1115 | 1115 | $ret = true; |
1116 | 1116 | } |
1117 | 1117 | |
1118 | - return apply_filters( 'give_is_zip_valid', $ret, $zip, $country_code ); |
|
1118 | + return apply_filters('give_is_zip_valid', $ret, $zip, $country_code); |
|
1119 | 1119 | } |
1120 | 1120 | |
1121 | 1121 | |
@@ -1129,36 +1129,36 @@ discard block |
||
1129 | 1129 | * |
1130 | 1130 | * @return bool |
1131 | 1131 | */ |
1132 | -function give_validate_multi_donation_form_level( $valid_data, $data ) { |
|
1132 | +function give_validate_multi_donation_form_level($valid_data, $data) { |
|
1133 | 1133 | /* @var Give_Donate_Form $form */ |
1134 | - $form = new Give_Donate_Form( $data['give-form-id'] ); |
|
1134 | + $form = new Give_Donate_Form($data['give-form-id']); |
|
1135 | 1135 | |
1136 | 1136 | $donation_level_matched = false; |
1137 | 1137 | |
1138 | - if ( $form->is_multi_type_donation_form() ) { |
|
1138 | + if ($form->is_multi_type_donation_form()) { |
|
1139 | 1139 | |
1140 | 1140 | // Bailout. |
1141 | - if ( ! ( $variable_prices = $form->get_prices() ) ) { |
|
1141 | + if ( ! ($variable_prices = $form->get_prices())) { |
|
1142 | 1142 | return false; |
1143 | 1143 | } |
1144 | 1144 | |
1145 | 1145 | // Sanitize donation amount. |
1146 | - $data['give-amount'] = give_sanitize_amount( $data['give-amount'] ); |
|
1146 | + $data['give-amount'] = give_sanitize_amount($data['give-amount']); |
|
1147 | 1147 | |
1148 | 1148 | // Get number of decimals. |
1149 | 1149 | $default_decimals = give_get_price_decimals(); |
1150 | 1150 | |
1151 | - if ( $data['give-amount'] === give_sanitize_amount( give_get_price_option_amount( $data['give-form-id'], $data['give-price-id'] ), $default_decimals ) ) { |
|
1151 | + if ($data['give-amount'] === give_sanitize_amount(give_get_price_option_amount($data['give-form-id'], $data['give-price-id']), $default_decimals)) { |
|
1152 | 1152 | return true; |
1153 | 1153 | } |
1154 | 1154 | |
1155 | 1155 | // Find correct donation level from all donation levels. |
1156 | - foreach ( $variable_prices as $variable_price ) { |
|
1156 | + foreach ($variable_prices as $variable_price) { |
|
1157 | 1157 | // Sanitize level amount. |
1158 | - $variable_price['_give_amount'] = give_sanitize_amount( $variable_price['_give_amount'], $default_decimals ); |
|
1158 | + $variable_price['_give_amount'] = give_sanitize_amount($variable_price['_give_amount'], $default_decimals); |
|
1159 | 1159 | |
1160 | 1160 | // Set first match donation level ID. |
1161 | - if ( $data['give-amount'] === $variable_price['_give_amount'] ) { |
|
1161 | + if ($data['give-amount'] === $variable_price['_give_amount']) { |
|
1162 | 1162 | $_POST['give-price-id'] = $variable_price['_give_id']['level_id']; |
1163 | 1163 | $donation_level_matched = true; |
1164 | 1164 | break; |
@@ -1169,19 +1169,19 @@ discard block |
||
1169 | 1169 | // If yes then set price id to custom if amount is greater then custom minimum amount (if any). |
1170 | 1170 | if ( |
1171 | 1171 | ! $donation_level_matched |
1172 | - && ( give_is_setting_enabled( get_post_meta( $data['give-form-id'], '_give_custom_amount', true ) ) ) |
|
1172 | + && (give_is_setting_enabled(get_post_meta($data['give-form-id'], '_give_custom_amount', true))) |
|
1173 | 1173 | ) { |
1174 | 1174 | // Sanitize custom minimum amount. |
1175 | - $custom_minimum_amount = give_sanitize_amount( get_post_meta( $data['give-form-id'], '_give_custom_amount_minimum', true ), $default_decimals ); |
|
1175 | + $custom_minimum_amount = give_sanitize_amount(get_post_meta($data['give-form-id'], '_give_custom_amount_minimum', true), $default_decimals); |
|
1176 | 1176 | |
1177 | - if ( $data['give-amount'] >= $custom_minimum_amount ) { |
|
1177 | + if ($data['give-amount'] >= $custom_minimum_amount) { |
|
1178 | 1178 | $_POST['give-price-id'] = 'custom'; |
1179 | 1179 | $donation_level_matched = true; |
1180 | 1180 | } |
1181 | 1181 | } |
1182 | 1182 | } |
1183 | 1183 | |
1184 | - return ( $donation_level_matched ? true : false ); |
|
1184 | + return ($donation_level_matched ? true : false); |
|
1185 | 1185 | } |
1186 | 1186 | |
1187 | -add_action( 'give_checkout_error_checks', 'give_validate_multi_donation_form_level', 10, 2 ); |
|
1187 | +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 | |
@@ -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' => '', |
@@ -123,84 +123,84 @@ discard block |
||
123 | 123 | 'continue_button_title' => '', |
124 | 124 | ); |
125 | 125 | |
126 | - $instance = wp_parse_args( (array) $instance, $defaults ); |
|
126 | + $instance = wp_parse_args((array) $instance, $defaults); |
|
127 | 127 | |
128 | 128 | // Backward compatibility: Set float labels as default if, it was set as empty previous. |
129 | - $instance['float_labels'] = empty( $instance['float_labels'] ) ? 'global' : $instance['float_labels']; |
|
129 | + $instance['float_labels'] = empty($instance['float_labels']) ? 'global' : $instance['float_labels']; |
|
130 | 130 | |
131 | 131 | // Query Give Forms |
132 | 132 | $args = array( |
133 | 133 | 'post_type' => 'give_forms', |
134 | - 'posts_per_page' => - 1, |
|
134 | + 'posts_per_page' => -1, |
|
135 | 135 | 'post_status' => 'publish', |
136 | 136 | ); |
137 | 137 | |
138 | - $give_forms = get_posts( $args ); |
|
138 | + $give_forms = get_posts($args); |
|
139 | 139 | ?> |
140 | 140 | <div class="give_forms_widget_container"> |
141 | 141 | |
142 | 142 | <?php // Widget: widget Title. ?> |
143 | 143 | <p> |
144 | - <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php esc_html_e( 'Title:', 'give' ); ?></label> |
|
145 | - <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> |
|
146 | - <small class="give-field-description"><?php esc_html_e( 'Leave blank to hide the widget title.', 'give' ); ?></small> |
|
144 | + <label for="<?php echo $this->get_field_id('title'); ?>"><?php esc_html_e('Title:', 'give'); ?></label> |
|
145 | + <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> |
|
146 | + <small class="give-field-description"><?php esc_html_e('Leave blank to hide the widget title.', 'give'); ?></small> |
|
147 | 147 | </p> |
148 | 148 | |
149 | 149 | <?php // Widget: Give Form?> |
150 | 150 | <p> |
151 | - <label for="<?php echo esc_attr( $this->get_field_id( 'id' ) ); ?>"><?php esc_html_e( 'Give Form:', 'give' ); ?></label> |
|
152 | - <select class="widefat" name="<?php echo esc_attr( $this->get_field_name( 'id' ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'id' ) ); ?>"> |
|
153 | - <option value="current"><?php esc_html_e( '- Select -', 'give' ); ?></option> |
|
154 | - <?php foreach ( $give_forms as $give_form ) { ?> |
|
155 | - <?php $form_title = empty( $give_form->post_title ) ? sprintf( __( 'Untitled (#%s)', 'give' ), $give_form->ID ) : $give_form->post_title; ?> |
|
156 | - <option <?php selected( absint( $instance['id'] ), $give_form->ID ); ?> value="<?php echo esc_attr( $give_form->ID ); ?>"><?php echo $form_title; ?></option> |
|
151 | + <label for="<?php echo esc_attr($this->get_field_id('id')); ?>"><?php esc_html_e('Give Form:', 'give'); ?></label> |
|
152 | + <select class="widefat" name="<?php echo esc_attr($this->get_field_name('id')); ?>" id="<?php echo esc_attr($this->get_field_id('id')); ?>"> |
|
153 | + <option value="current"><?php esc_html_e('- Select -', 'give'); ?></option> |
|
154 | + <?php foreach ($give_forms as $give_form) { ?> |
|
155 | + <?php $form_title = empty($give_form->post_title) ? sprintf(__('Untitled (#%s)', 'give'), $give_form->ID) : $give_form->post_title; ?> |
|
156 | + <option <?php selected(absint($instance['id']), $give_form->ID); ?> value="<?php echo esc_attr($give_form->ID); ?>"><?php echo $form_title; ?></option> |
|
157 | 157 | <?php } ?> |
158 | 158 | </select><br> |
159 | - <small class="give-field-description"><?php esc_html_e( 'Select a Give Form to embed in this widget.', 'give' ); ?></small> |
|
159 | + <small class="give-field-description"><?php esc_html_e('Select a Give Form to embed in this widget.', 'give'); ?></small> |
|
160 | 160 | </p> |
161 | 161 | |
162 | 162 | <?php // Widget: Display Style ?> |
163 | 163 | <p class="give_forms_display_style_setting_row"> |
164 | - <label for="<?php echo esc_attr( $this->get_field_id( 'display_style' ) ); ?>"><?php esc_html_e( 'Display Style:', 'give' ); ?></label><br> |
|
165 | - <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> |
|
166 | - <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> |
|
167 | - <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> |
|
168 | - <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> |
|
164 | + <label for="<?php echo esc_attr($this->get_field_id('display_style')); ?>"><?php esc_html_e('Display Style:', 'give'); ?></label><br> |
|
165 | + <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> |
|
166 | + <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> |
|
167 | + <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> |
|
168 | + <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> |
|
169 | 169 | <small class="give-field-description"> |
170 | - <?php echo esc_html__( 'Select a Give Form style.', 'give' ); ?> |
|
170 | + <?php echo esc_html__('Select a Give Form style.', 'give'); ?> |
|
171 | 171 | </small> |
172 | 172 | </p> |
173 | 173 | |
174 | 174 | <?php // Widget: Continue Button Title. ?> |
175 | 175 | <p class="give_forms_continue_button_title_setting_row"> |
176 | - <label for="<?php echo $this->get_field_id( 'continue_button_title' ); ?>"><?php esc_html_e( 'Button Text:', 'give' ); ?></label> |
|
177 | - <input type="text" class="widefat" id="<?php echo $this->get_field_id( 'continue_button_title' ); ?>" name="<?php echo $this->get_field_name( 'continue_button_title' ); ?>" value="<?php esc_attr_e( $instance['continue_button_title'] ); ?>" /><br> |
|
178 | - <small class="give-field-description"><?php esc_html_e( 'The button label for displaying the additional payment fields.', 'give' ); ?></small> |
|
176 | + <label for="<?php echo $this->get_field_id('continue_button_title'); ?>"><?php esc_html_e('Button Text:', 'give'); ?></label> |
|
177 | + <input type="text" class="widefat" id="<?php echo $this->get_field_id('continue_button_title'); ?>" name="<?php echo $this->get_field_name('continue_button_title'); ?>" value="<?php esc_attr_e($instance['continue_button_title']); ?>" /><br> |
|
178 | + <small class="give-field-description"><?php esc_html_e('The button label for displaying the additional payment fields.', 'give'); ?></small> |
|
179 | 179 | </p> |
180 | 180 | |
181 | 181 | <?php // Widget: Floating Labels ?> |
182 | 182 | <p> |
183 | - <label for="<?php echo esc_attr( $this->get_field_id( 'float_labels' ) ); ?>"><?php esc_html_e( 'Floating Labels (optional):', 'give' ); ?></label><br> |
|
184 | - <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> |
|
185 | - <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> |
|
186 | - <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> |
|
183 | + <label for="<?php echo esc_attr($this->get_field_id('float_labels')); ?>"><?php esc_html_e('Floating Labels (optional):', 'give'); ?></label><br> |
|
184 | + <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> |
|
185 | + <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> |
|
186 | + <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> |
|
187 | 187 | <small class="give-field-description"> |
188 | 188 | <?php |
189 | 189 | printf( |
190 | 190 | /* translators: %s: http://docs.givewp.com/form-floating-labels */ |
191 | - __( 'Override the <a href="%s" target="_blank">floating labels</a> setting for this Give form.', 'give' ), |
|
192 | - esc_url( 'http://docs.givewp.com/form-floating-labels' ) |
|
191 | + __('Override the <a href="%s" target="_blank">floating labels</a> setting for this Give form.', 'give'), |
|
192 | + esc_url('http://docs.givewp.com/form-floating-labels') |
|
193 | 193 | ); |
194 | 194 | ?></small> |
195 | 195 | </p> |
196 | 196 | |
197 | 197 | <?php // Widget: Display Content ?> |
198 | 198 | <p> |
199 | - <label for="<?php echo esc_attr( $this->get_field_id( 'show_content' ) ); ?>"><?php esc_html_e( 'Display Content (optional):', 'give' ); ?></label><br> |
|
200 | - <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> |
|
201 | - <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> |
|
202 | - <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> |
|
203 | - <small class="give-field-description"><?php esc_html_e( 'Override the display content setting for this Give form.', 'give' ); ?></small> |
|
199 | + <label for="<?php echo esc_attr($this->get_field_id('show_content')); ?>"><?php esc_html_e('Display Content (optional):', 'give'); ?></label><br> |
|
200 | + <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> |
|
201 | + <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> |
|
202 | + <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> |
|
203 | + <small class="give-field-description"><?php esc_html_e('Override the display content setting for this Give form.', 'give'); ?></small> |
|
204 | 204 | </div> |
205 | 205 | <?php |
206 | 206 | } |
@@ -210,8 +210,8 @@ discard block |
||
210 | 210 | * |
211 | 211 | * @return void |
212 | 212 | */ |
213 | - function widget_init(){ |
|
214 | - register_widget( $this->self ); |
|
213 | + function widget_init() { |
|
214 | + register_widget($this->self); |
|
215 | 215 | } |
216 | 216 | |
217 | 217 | /** |
@@ -222,7 +222,7 @@ discard block |
||
222 | 222 | * |
223 | 223 | * @return array |
224 | 224 | */ |
225 | - public function update( $new_instance, $old_instance ){ |
|
225 | + public function update($new_instance, $old_instance) { |
|
226 | 226 | $this->flush_widget_cache(); |
227 | 227 | |
228 | 228 | return $new_instance; |
@@ -233,8 +233,8 @@ discard block |
||
233 | 233 | * |
234 | 234 | * @return void |
235 | 235 | */ |
236 | - public function flush_widget_cache(){ |
|
237 | - wp_cache_delete( $this->self, 'widget' ); |
|
236 | + public function flush_widget_cache() { |
|
237 | + wp_cache_delete($this->self, 'widget'); |
|
238 | 238 | } |
239 | 239 | } |
240 | 240 |
@@ -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 | |
@@ -25,37 +25,37 @@ discard block |
||
25 | 25 | */ |
26 | 26 | function give_do_automatic_upgrades() { |
27 | 27 | $did_upgrade = false; |
28 | - $give_version = preg_replace( '/[^0-9.].*/', '', get_option( 'give_version' ) ); |
|
28 | + $give_version = preg_replace('/[^0-9.].*/', '', get_option('give_version')); |
|
29 | 29 | |
30 | - if ( ! $give_version ) { |
|
30 | + if ( ! $give_version) { |
|
31 | 31 | // 1.0 is the first version to use this option so we must add it. |
32 | 32 | $give_version = '1.0'; |
33 | 33 | } |
34 | 34 | |
35 | - switch ( true ) { |
|
35 | + switch (true) { |
|
36 | 36 | |
37 | - case version_compare( $give_version, '1.6', '<' ) : |
|
37 | + case version_compare($give_version, '1.6', '<') : |
|
38 | 38 | give_v16_upgrades(); |
39 | 39 | $did_upgrade = true; |
40 | 40 | break; |
41 | 41 | |
42 | - case version_compare( $give_version, '1.7', '<' ) : |
|
42 | + case version_compare($give_version, '1.7', '<') : |
|
43 | 43 | give_v17_upgrades(); |
44 | 44 | $did_upgrade = true; |
45 | 45 | break; |
46 | 46 | |
47 | - case version_compare( $give_version, '1.8', '<' ) : |
|
47 | + case version_compare($give_version, '1.8', '<') : |
|
48 | 48 | give_v18_upgrades(); |
49 | 49 | $did_upgrade = true; |
50 | 50 | } |
51 | 51 | |
52 | - if ( $did_upgrade ) { |
|
53 | - update_option( 'give_version', preg_replace( '/[^0-9.].*/', '', GIVE_VERSION ) ); |
|
52 | + if ($did_upgrade) { |
|
53 | + update_option('give_version', preg_replace('/[^0-9.].*/', '', GIVE_VERSION)); |
|
54 | 54 | } |
55 | 55 | } |
56 | 56 | |
57 | -add_action( 'admin_init', 'give_do_automatic_upgrades' ); |
|
58 | -add_action( 'give_upgrades', 'give_do_automatic_upgrades' ); |
|
57 | +add_action('admin_init', 'give_do_automatic_upgrades'); |
|
58 | +add_action('give_upgrades', 'give_do_automatic_upgrades'); |
|
59 | 59 | |
60 | 60 | /** |
61 | 61 | * Display Upgrade Notices |
@@ -65,18 +65,18 @@ discard block |
||
65 | 65 | */ |
66 | 66 | function give_show_upgrade_notices() { |
67 | 67 | // Don't show notices on the upgrades page. |
68 | - if ( isset( $_GET['page'] ) && $_GET['page'] == 'give-upgrades' ) { |
|
68 | + if (isset($_GET['page']) && $_GET['page'] == 'give-upgrades') { |
|
69 | 69 | return; |
70 | 70 | } |
71 | 71 | |
72 | - $give_version = get_option( 'give_version' ); |
|
72 | + $give_version = get_option('give_version'); |
|
73 | 73 | |
74 | - if ( ! $give_version ) { |
|
74 | + if ( ! $give_version) { |
|
75 | 75 | // 1.0 is the first version to use this option so we must add it. |
76 | 76 | $give_version = '1.0'; |
77 | 77 | } |
78 | 78 | |
79 | - $give_version = preg_replace( '/[^0-9.].*/', '', $give_version ); |
|
79 | + $give_version = preg_replace('/[^0-9.].*/', '', $give_version); |
|
80 | 80 | |
81 | 81 | /* |
82 | 82 | * NOTICE: |
@@ -87,31 +87,31 @@ discard block |
||
87 | 87 | */ |
88 | 88 | |
89 | 89 | // v1.3.2 Upgrades |
90 | - if ( version_compare( $give_version, '1.3.2', '<' ) || ! give_has_upgrade_completed( 'upgrade_give_payment_customer_id' ) ) { |
|
90 | + if (version_compare($give_version, '1.3.2', '<') || ! give_has_upgrade_completed('upgrade_give_payment_customer_id')) { |
|
91 | 91 | printf( |
92 | 92 | /* translators: %s: upgrade URL */ |
93 | - '<div class="updated"><p>' . __( 'Give needs to upgrade the donor database, click <a href="%s">here</a> to start the upgrade.', 'give' ) . '</p></div>', |
|
94 | - esc_url( admin_url( 'index.php?page=give-upgrades&give-upgrade=upgrade_give_payment_customer_id' ) ) |
|
93 | + '<div class="updated"><p>'.__('Give needs to upgrade the donor database, click <a href="%s">here</a> to start the upgrade.', 'give').'</p></div>', |
|
94 | + esc_url(admin_url('index.php?page=give-upgrades&give-upgrade=upgrade_give_payment_customer_id')) |
|
95 | 95 | ); |
96 | 96 | } |
97 | 97 | |
98 | 98 | // v1.3.4 Upgrades //ensure the user has gone through 1.3.4. |
99 | - if ( version_compare( $give_version, '1.3.4', '<' ) || ( ! give_has_upgrade_completed( 'upgrade_give_offline_status' ) && give_has_upgrade_completed( 'upgrade_give_payment_customer_id' ) ) ) { |
|
99 | + if (version_compare($give_version, '1.3.4', '<') || ( ! give_has_upgrade_completed('upgrade_give_offline_status') && give_has_upgrade_completed('upgrade_give_payment_customer_id'))) { |
|
100 | 100 | printf( |
101 | 101 | /* translators: %s: upgrade URL */ |
102 | - '<div class="updated"><p>' . __( 'Give needs to upgrade the donations database, click <a href="%s">here</a> to start the upgrade.', 'give' ) . '</p></div>', |
|
103 | - esc_url( admin_url( 'index.php?page=give-upgrades&give-upgrade=upgrade_give_offline_status' ) ) |
|
102 | + '<div class="updated"><p>'.__('Give needs to upgrade the donations database, click <a href="%s">here</a> to start the upgrade.', 'give').'</p></div>', |
|
103 | + esc_url(admin_url('index.php?page=give-upgrades&give-upgrade=upgrade_give_offline_status')) |
|
104 | 104 | ); |
105 | 105 | } |
106 | 106 | |
107 | 107 | // Check if we have a stalled upgrade. |
108 | 108 | $resume_upgrade = give_maybe_resume_upgrade(); |
109 | - if ( ! empty( $resume_upgrade ) ) { |
|
110 | - $resume_url = add_query_arg( $resume_upgrade, admin_url( 'index.php' ) ); |
|
109 | + if ( ! empty($resume_upgrade)) { |
|
110 | + $resume_url = add_query_arg($resume_upgrade, admin_url('index.php')); |
|
111 | 111 | echo Give_Notices::notice_html( |
112 | 112 | sprintf( |
113 | - __( 'Give needs to complete a database upgrade that was previously started, click <a href="%s">here</a> to resume the upgrade.', 'give' ), |
|
114 | - esc_url( $resume_url ) |
|
113 | + __('Give needs to complete a database upgrade that was previously started, click <a href="%s">here</a> to resume the upgrade.', 'give'), |
|
114 | + esc_url($resume_url) |
|
115 | 115 | ) |
116 | 116 | ); |
117 | 117 | |
@@ -119,11 +119,11 @@ discard block |
||
119 | 119 | } |
120 | 120 | |
121 | 121 | // v1.8 form metadata upgrades. |
122 | - if ( version_compare( $give_version, '1.8', '<' ) || ! give_has_upgrade_completed( 'v18_upgrades_form_metadata' ) ) { |
|
122 | + if (version_compare($give_version, '1.8', '<') || ! give_has_upgrade_completed('v18_upgrades_form_metadata')) { |
|
123 | 123 | echo Give_Notices::notice_html( |
124 | 124 | sprintf( |
125 | - esc_html__( 'Give needs to upgrade the form database, click %1$shere%2$s to start the upgrade.', 'give' ), |
|
126 | - '<a class="give-upgrade-link" href="' . esc_url( admin_url( 'index.php?page=give-upgrades&give-upgrade=give_v18_upgrades_form_metadata' ) ) . '">', |
|
125 | + esc_html__('Give needs to upgrade the form database, click %1$shere%2$s to start the upgrade.', 'give'), |
|
126 | + '<a class="give-upgrade-link" href="'.esc_url(admin_url('index.php?page=give-upgrades&give-upgrade=give_v18_upgrades_form_metadata')).'">', |
|
127 | 127 | '</a>' |
128 | 128 | ) |
129 | 129 | ); |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | $upgrade_links.on( 'click', function(e){ |
139 | 139 | e.preventDefault(); |
140 | 140 | |
141 | - if( ! window.confirm( '<?php _e( 'Please make sure to create a database backup before initiating the upgrade.', 'give' ); ?>' ) ) { |
|
141 | + if( ! window.confirm( '<?php _e('Please make sure to create a database backup before initiating the upgrade.', 'give'); ?>' ) ) { |
|
142 | 142 | return; |
143 | 143 | } |
144 | 144 | |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | <?php |
152 | 152 | } |
153 | 153 | |
154 | -add_action( 'admin_notices', 'give_show_upgrade_notices' ); |
|
154 | +add_action('admin_notices', 'give_show_upgrade_notices'); |
|
155 | 155 | |
156 | 156 | /** |
157 | 157 | * Triggers all upgrade functions |
@@ -163,29 +163,29 @@ discard block |
||
163 | 163 | */ |
164 | 164 | function give_trigger_upgrades() { |
165 | 165 | |
166 | - if ( ! current_user_can( 'manage_give_settings' ) ) { |
|
167 | - wp_die( esc_html__( 'You do not have permission to do Give upgrades.', 'give' ), esc_html__( 'Error', 'give' ), array( |
|
166 | + if ( ! current_user_can('manage_give_settings')) { |
|
167 | + wp_die(esc_html__('You do not have permission to do Give upgrades.', 'give'), esc_html__('Error', 'give'), array( |
|
168 | 168 | 'response' => 403, |
169 | - ) ); |
|
169 | + )); |
|
170 | 170 | } |
171 | 171 | |
172 | - $give_version = get_option( 'give_version' ); |
|
172 | + $give_version = get_option('give_version'); |
|
173 | 173 | |
174 | - if ( ! $give_version ) { |
|
174 | + if ( ! $give_version) { |
|
175 | 175 | // 1.0 is the first version to use this option so we must add it. |
176 | 176 | $give_version = '1.0'; |
177 | - add_option( 'give_version', $give_version ); |
|
177 | + add_option('give_version', $give_version); |
|
178 | 178 | } |
179 | 179 | |
180 | - update_option( 'give_version', GIVE_VERSION ); |
|
181 | - delete_option( 'give_doing_upgrade' ); |
|
180 | + update_option('give_version', GIVE_VERSION); |
|
181 | + delete_option('give_doing_upgrade'); |
|
182 | 182 | |
183 | - if ( DOING_AJAX ) { |
|
184 | - die( 'complete' ); |
|
183 | + if (DOING_AJAX) { |
|
184 | + die('complete'); |
|
185 | 185 | } // End if(). |
186 | 186 | } |
187 | 187 | |
188 | -add_action( 'wp_ajax_give_trigger_upgrades', 'give_trigger_upgrades' ); |
|
188 | +add_action('wp_ajax_give_trigger_upgrades', 'give_trigger_upgrades'); |
|
189 | 189 | |
190 | 190 | /** |
191 | 191 | * Check if the upgrade routine has been run for a specific action |
@@ -196,15 +196,15 @@ discard block |
||
196 | 196 | * |
197 | 197 | * @return bool If the action has been added to the completed actions array |
198 | 198 | */ |
199 | -function give_has_upgrade_completed( $upgrade_action = '' ) { |
|
199 | +function give_has_upgrade_completed($upgrade_action = '') { |
|
200 | 200 | |
201 | - if ( empty( $upgrade_action ) ) { |
|
201 | + if (empty($upgrade_action)) { |
|
202 | 202 | return false; |
203 | 203 | } |
204 | 204 | |
205 | 205 | $completed_upgrades = give_get_completed_upgrades(); |
206 | 206 | |
207 | - return in_array( $upgrade_action, $completed_upgrades ); |
|
207 | + return in_array($upgrade_action, $completed_upgrades); |
|
208 | 208 | |
209 | 209 | } |
210 | 210 | |
@@ -216,8 +216,8 @@ discard block |
||
216 | 216 | * @return mixed When nothing to resume returns false, otherwise starts the upgrade where it left off |
217 | 217 | */ |
218 | 218 | function give_maybe_resume_upgrade() { |
219 | - $doing_upgrade = get_option( 'give_doing_upgrade', false ); |
|
220 | - if ( empty( $doing_upgrade ) ) { |
|
219 | + $doing_upgrade = get_option('give_doing_upgrade', false); |
|
220 | + if (empty($doing_upgrade)) { |
|
221 | 221 | return false; |
222 | 222 | } |
223 | 223 | |
@@ -233,9 +233,9 @@ discard block |
||
233 | 233 | * |
234 | 234 | * @return bool If the function was successfully added |
235 | 235 | */ |
236 | -function give_set_upgrade_complete( $upgrade_action = '' ) { |
|
236 | +function give_set_upgrade_complete($upgrade_action = '') { |
|
237 | 237 | |
238 | - if ( empty( $upgrade_action ) ) { |
|
238 | + if (empty($upgrade_action)) { |
|
239 | 239 | return false; |
240 | 240 | } |
241 | 241 | |
@@ -243,9 +243,9 @@ discard block |
||
243 | 243 | $completed_upgrades[] = $upgrade_action; |
244 | 244 | |
245 | 245 | // Remove any blanks, and only show uniques. |
246 | - $completed_upgrades = array_unique( array_values( $completed_upgrades ) ); |
|
246 | + $completed_upgrades = array_unique(array_values($completed_upgrades)); |
|
247 | 247 | |
248 | - return update_option( 'give_completed_upgrades', $completed_upgrades ); |
|
248 | + return update_option('give_completed_upgrades', $completed_upgrades); |
|
249 | 249 | } |
250 | 250 | |
251 | 251 | /** |
@@ -256,9 +256,9 @@ discard block |
||
256 | 256 | */ |
257 | 257 | function give_get_completed_upgrades() { |
258 | 258 | |
259 | - $completed_upgrades = get_option( 'give_completed_upgrades' ); |
|
259 | + $completed_upgrades = get_option('give_completed_upgrades'); |
|
260 | 260 | |
261 | - if ( false === $completed_upgrades ) { |
|
261 | + if (false === $completed_upgrades) { |
|
262 | 262 | $completed_upgrades = array(); |
263 | 263 | } |
264 | 264 | |
@@ -275,31 +275,31 @@ discard block |
||
275 | 275 | */ |
276 | 276 | function give_v132_upgrade_give_payment_customer_id() { |
277 | 277 | global $wpdb; |
278 | - if ( ! current_user_can( 'manage_give_settings' ) ) { |
|
279 | - wp_die( esc_html__( 'You do not have permission to do Give upgrades.', 'give' ), esc_html__( 'Error', 'give' ), array( |
|
278 | + if ( ! current_user_can('manage_give_settings')) { |
|
279 | + wp_die(esc_html__('You do not have permission to do Give upgrades.', 'give'), esc_html__('Error', 'give'), array( |
|
280 | 280 | 'response' => 403, |
281 | - ) ); |
|
281 | + )); |
|
282 | 282 | } |
283 | 283 | |
284 | - ignore_user_abort( true ); |
|
284 | + ignore_user_abort(true); |
|
285 | 285 | |
286 | - if ( ! give_is_func_disabled( 'set_time_limit' ) && ! ini_get( 'safe_mode' ) ) { |
|
287 | - @set_time_limit( 0 ); |
|
286 | + if ( ! give_is_func_disabled('set_time_limit') && ! ini_get('safe_mode')) { |
|
287 | + @set_time_limit(0); |
|
288 | 288 | } |
289 | 289 | |
290 | 290 | // UPDATE DB METAKEYS. |
291 | 291 | $sql = "UPDATE $wpdb->postmeta SET meta_key = '_give_payment_customer_id' WHERE meta_key = '_give_payment_donor_id'"; |
292 | - $query = $wpdb->query( $sql ); |
|
292 | + $query = $wpdb->query($sql); |
|
293 | 293 | |
294 | - update_option( 'give_version', preg_replace( '/[^0-9.].*/', '', GIVE_VERSION ) ); |
|
295 | - give_set_upgrade_complete( 'upgrade_give_payment_customer_id' ); |
|
296 | - delete_option( 'give_doing_upgrade' ); |
|
297 | - wp_redirect( admin_url() ); |
|
294 | + update_option('give_version', preg_replace('/[^0-9.].*/', '', GIVE_VERSION)); |
|
295 | + give_set_upgrade_complete('upgrade_give_payment_customer_id'); |
|
296 | + delete_option('give_doing_upgrade'); |
|
297 | + wp_redirect(admin_url()); |
|
298 | 298 | exit; |
299 | 299 | |
300 | 300 | } |
301 | 301 | |
302 | -add_action( 'give_upgrade_give_payment_customer_id', 'give_v132_upgrade_give_payment_customer_id' ); |
|
302 | +add_action('give_upgrade_give_payment_customer_id', 'give_v132_upgrade_give_payment_customer_id'); |
|
303 | 303 | |
304 | 304 | /** |
305 | 305 | * Upgrades the Offline Status |
@@ -312,16 +312,16 @@ discard block |
||
312 | 312 | |
313 | 313 | global $wpdb; |
314 | 314 | |
315 | - if ( ! current_user_can( 'manage_give_settings' ) ) { |
|
316 | - wp_die( esc_html__( 'You do not have permission to do Give upgrades.', 'give' ), esc_html__( 'Error', 'give' ), array( |
|
315 | + if ( ! current_user_can('manage_give_settings')) { |
|
316 | + wp_die(esc_html__('You do not have permission to do Give upgrades.', 'give'), esc_html__('Error', 'give'), array( |
|
317 | 317 | 'response' => 403, |
318 | - ) ); |
|
318 | + )); |
|
319 | 319 | } |
320 | 320 | |
321 | - ignore_user_abort( true ); |
|
321 | + ignore_user_abort(true); |
|
322 | 322 | |
323 | - if ( ! give_is_func_disabled( 'set_time_limit' ) && ! ini_get( 'safe_mode' ) ) { |
|
324 | - @set_time_limit( 0 ); |
|
323 | + if ( ! give_is_func_disabled('set_time_limit') && ! ini_get('safe_mode')) { |
|
324 | + @set_time_limit(0); |
|
325 | 325 | } |
326 | 326 | |
327 | 327 | // Get abandoned offline payments. |
@@ -331,31 +331,31 @@ discard block |
||
331 | 331 | $where .= "AND ( p.post_status = 'abandoned' )"; |
332 | 332 | $where .= "AND ( m.meta_key = '_give_payment_gateway' AND m.meta_value = 'offline' )"; |
333 | 333 | |
334 | - $sql = $select . $join . $where; |
|
335 | - $found_payments = $wpdb->get_col( $sql ); |
|
334 | + $sql = $select.$join.$where; |
|
335 | + $found_payments = $wpdb->get_col($sql); |
|
336 | 336 | |
337 | - foreach ( $found_payments as $payment ) { |
|
337 | + foreach ($found_payments as $payment) { |
|
338 | 338 | |
339 | 339 | // Only change ones marked abandoned since our release last week because the admin may have marked some abandoned themselves. |
340 | - $modified_time = get_post_modified_time( 'U', false, $payment ); |
|
340 | + $modified_time = get_post_modified_time('U', false, $payment); |
|
341 | 341 | |
342 | 342 | // 1450124863 = 12/10/2015 20:42:25. |
343 | - if ( $modified_time >= 1450124863 ) { |
|
343 | + if ($modified_time >= 1450124863) { |
|
344 | 344 | |
345 | - give_update_payment_status( $payment, 'pending' ); |
|
345 | + give_update_payment_status($payment, 'pending'); |
|
346 | 346 | |
347 | 347 | } |
348 | 348 | } |
349 | 349 | |
350 | - update_option( 'give_version', preg_replace( '/[^0-9.].*/', '', GIVE_VERSION ) ); |
|
351 | - give_set_upgrade_complete( 'upgrade_give_offline_status' ); |
|
352 | - delete_option( 'give_doing_upgrade' ); |
|
353 | - wp_redirect( admin_url() ); |
|
350 | + update_option('give_version', preg_replace('/[^0-9.].*/', '', GIVE_VERSION)); |
|
351 | + give_set_upgrade_complete('upgrade_give_offline_status'); |
|
352 | + delete_option('give_doing_upgrade'); |
|
353 | + wp_redirect(admin_url()); |
|
354 | 354 | exit; |
355 | 355 | |
356 | 356 | } |
357 | 357 | |
358 | -add_action( 'give_upgrade_give_offline_status', 'give_v134_upgrade_give_offline_status' ); |
|
358 | +add_action('give_upgrade_give_offline_status', 'give_v134_upgrade_give_offline_status'); |
|
359 | 359 | |
360 | 360 | /** |
361 | 361 | * Cleanup User Roles |
@@ -366,17 +366,17 @@ discard block |
||
366 | 366 | */ |
367 | 367 | function give_v152_cleanup_users() { |
368 | 368 | |
369 | - $give_version = get_option( 'give_version' ); |
|
369 | + $give_version = get_option('give_version'); |
|
370 | 370 | |
371 | - if ( ! $give_version ) { |
|
371 | + if ( ! $give_version) { |
|
372 | 372 | // 1.0 is the first version to use this option so we must add it. |
373 | 373 | $give_version = '1.0'; |
374 | 374 | } |
375 | 375 | |
376 | - $give_version = preg_replace( '/[^0-9.].*/', '', $give_version ); |
|
376 | + $give_version = preg_replace('/[^0-9.].*/', '', $give_version); |
|
377 | 377 | |
378 | 378 | // v1.5.2 Upgrades |
379 | - if ( version_compare( $give_version, '1.5.2', '<' ) || ! give_has_upgrade_completed( 'upgrade_give_user_caps_cleanup' ) ) { |
|
379 | + if (version_compare($give_version, '1.5.2', '<') || ! give_has_upgrade_completed('upgrade_give_user_caps_cleanup')) { |
|
380 | 380 | |
381 | 381 | // Delete all caps with "ss". |
382 | 382 | // Also delete all unused "campaign" roles. |
@@ -423,9 +423,9 @@ discard block |
||
423 | 423 | ); |
424 | 424 | |
425 | 425 | global $wp_roles; |
426 | - foreach ( $delete_caps as $cap ) { |
|
427 | - foreach ( array_keys( $wp_roles->roles ) as $role ) { |
|
428 | - $wp_roles->remove_cap( $role, $cap ); |
|
426 | + foreach ($delete_caps as $cap) { |
|
427 | + foreach (array_keys($wp_roles->roles) as $role) { |
|
428 | + $wp_roles->remove_cap($role, $cap); |
|
429 | 429 | } |
430 | 430 | } |
431 | 431 | |
@@ -435,15 +435,15 @@ discard block |
||
435 | 435 | $roles->add_caps(); |
436 | 436 | |
437 | 437 | // The Update Ran. |
438 | - update_option( 'give_version', preg_replace( '/[^0-9.].*/', '', GIVE_VERSION ) ); |
|
439 | - give_set_upgrade_complete( 'upgrade_give_user_caps_cleanup' ); |
|
440 | - delete_option( 'give_doing_upgrade' ); |
|
438 | + update_option('give_version', preg_replace('/[^0-9.].*/', '', GIVE_VERSION)); |
|
439 | + give_set_upgrade_complete('upgrade_give_user_caps_cleanup'); |
|
440 | + delete_option('give_doing_upgrade'); |
|
441 | 441 | |
442 | 442 | }// End if(). |
443 | 443 | |
444 | 444 | } |
445 | 445 | |
446 | -add_action( 'admin_init', 'give_v152_cleanup_users' ); |
|
446 | +add_action('admin_init', 'give_v152_cleanup_users'); |
|
447 | 447 | |
448 | 448 | /** |
449 | 449 | * 1.6 Upgrade routine to create the customer meta table. |
@@ -483,53 +483,53 @@ discard block |
||
483 | 483 | |
484 | 484 | // Get addons license key. |
485 | 485 | $addons = array(); |
486 | - foreach ( $give_options as $key => $value ) { |
|
487 | - if ( false !== strpos( $key, '_license_key' ) ) { |
|
488 | - $addons[ $key ] = $value; |
|
486 | + foreach ($give_options as $key => $value) { |
|
487 | + if (false !== strpos($key, '_license_key')) { |
|
488 | + $addons[$key] = $value; |
|
489 | 489 | } |
490 | 490 | } |
491 | 491 | |
492 | 492 | // Bailout: We do not have any addon license data to upgrade. |
493 | - if ( empty( $addons ) ) { |
|
493 | + if (empty($addons)) { |
|
494 | 494 | return false; |
495 | 495 | } |
496 | 496 | |
497 | - foreach ( $addons as $key => $addon_license ) { |
|
497 | + foreach ($addons as $key => $addon_license) { |
|
498 | 498 | |
499 | 499 | // Get addon shortname. |
500 | - $shortname = str_replace( '_license_key', '', $key ); |
|
500 | + $shortname = str_replace('_license_key', '', $key); |
|
501 | 501 | |
502 | 502 | // Addon license option name. |
503 | - $addon_license_option_name = $shortname . '_license_active'; |
|
503 | + $addon_license_option_name = $shortname.'_license_active'; |
|
504 | 504 | |
505 | 505 | // bailout if license is empty. |
506 | - if ( empty( $addon_license ) ) { |
|
507 | - delete_option( $addon_license_option_name ); |
|
506 | + if (empty($addon_license)) { |
|
507 | + delete_option($addon_license_option_name); |
|
508 | 508 | continue; |
509 | 509 | } |
510 | 510 | |
511 | 511 | // Get addon name. |
512 | 512 | $addon_name = array(); |
513 | - $addon_name_parts = explode( '_', str_replace( 'give_', '', $shortname ) ); |
|
514 | - foreach ( $addon_name_parts as $name_part ) { |
|
513 | + $addon_name_parts = explode('_', str_replace('give_', '', $shortname)); |
|
514 | + foreach ($addon_name_parts as $name_part) { |
|
515 | 515 | |
516 | 516 | // Fix addon name |
517 | - switch ( $name_part ) { |
|
517 | + switch ($name_part) { |
|
518 | 518 | case 'authorizenet' : |
519 | 519 | $name_part = 'authorize.net'; |
520 | 520 | break; |
521 | 521 | } |
522 | 522 | |
523 | - $addon_name[] = ucfirst( $name_part ); |
|
523 | + $addon_name[] = ucfirst($name_part); |
|
524 | 524 | } |
525 | 525 | |
526 | - $addon_name = implode( ' ', $addon_name ); |
|
526 | + $addon_name = implode(' ', $addon_name); |
|
527 | 527 | |
528 | 528 | // Data to send to the API |
529 | 529 | $api_params = array( |
530 | 530 | 'edd_action' => 'activate_license', // never change from "edd_" to "give_"! |
531 | 531 | 'license' => $addon_license, |
532 | - 'item_name' => urlencode( $addon_name ), |
|
532 | + 'item_name' => urlencode($addon_name), |
|
533 | 533 | 'url' => home_url(), |
534 | 534 | ); |
535 | 535 | |
@@ -544,17 +544,17 @@ discard block |
||
544 | 544 | ); |
545 | 545 | |
546 | 546 | // Make sure there are no errors. |
547 | - if ( is_wp_error( $response ) ) { |
|
548 | - delete_option( $addon_license_option_name ); |
|
547 | + if (is_wp_error($response)) { |
|
548 | + delete_option($addon_license_option_name); |
|
549 | 549 | continue; |
550 | 550 | } |
551 | 551 | |
552 | 552 | // Tell WordPress to look for updates. |
553 | - set_site_transient( 'update_plugins', null ); |
|
553 | + set_site_transient('update_plugins', null); |
|
554 | 554 | |
555 | 555 | // Decode license data. |
556 | - $license_data = json_decode( wp_remote_retrieve_body( $response ) ); |
|
557 | - update_option( $addon_license_option_name, $license_data ); |
|
556 | + $license_data = json_decode(wp_remote_retrieve_body($response)); |
|
557 | + update_option($addon_license_option_name, $license_data); |
|
558 | 558 | }// End foreach(). |
559 | 559 | } |
560 | 560 | |
@@ -584,9 +584,9 @@ discard block |
||
584 | 584 | ); |
585 | 585 | |
586 | 586 | global $wp_roles; |
587 | - foreach ( $delete_caps as $cap ) { |
|
588 | - foreach ( array_keys( $wp_roles->roles ) as $role ) { |
|
589 | - $wp_roles->remove_cap( $role, $cap ); |
|
587 | + foreach ($delete_caps as $cap) { |
|
588 | + foreach (array_keys($wp_roles->roles) as $role) { |
|
589 | + $wp_roles->remove_cap($role, $cap); |
|
590 | 590 | } |
591 | 591 | } |
592 | 592 | |
@@ -620,7 +620,7 @@ discard block |
||
620 | 620 | function give_v18_upgrades_core_setting() { |
621 | 621 | // Core settings which changes from checkbox to radio. |
622 | 622 | $core_setting_names = array_merge( |
623 | - array_keys( give_v18_renamed_core_settings() ), |
|
623 | + array_keys(give_v18_renamed_core_settings()), |
|
624 | 624 | array( |
625 | 625 | 'uninstall_on_delete', |
626 | 626 | 'scripts_footer', |
@@ -632,48 +632,48 @@ discard block |
||
632 | 632 | ); |
633 | 633 | |
634 | 634 | // Bailout: If not any setting define. |
635 | - if ( $give_settings = get_option( 'give_settings' ) ) { |
|
635 | + if ($give_settings = get_option('give_settings')) { |
|
636 | 636 | |
637 | 637 | $setting_changed = false; |
638 | 638 | |
639 | 639 | // Loop: check each setting field. |
640 | - foreach ( $core_setting_names as $setting_name ) { |
|
640 | + foreach ($core_setting_names as $setting_name) { |
|
641 | 641 | // New setting name. |
642 | - $new_setting_name = preg_replace( '/^(enable_|disable_)/', '', $setting_name ); |
|
642 | + $new_setting_name = preg_replace('/^(enable_|disable_)/', '', $setting_name); |
|
643 | 643 | |
644 | 644 | // Continue: If setting already set. |
645 | 645 | if ( |
646 | - array_key_exists( $new_setting_name, $give_settings ) |
|
647 | - && in_array( $give_settings[ $new_setting_name ], array( 'enabled', 'disabled' ) ) |
|
646 | + array_key_exists($new_setting_name, $give_settings) |
|
647 | + && in_array($give_settings[$new_setting_name], array('enabled', 'disabled')) |
|
648 | 648 | ) { |
649 | 649 | continue; |
650 | 650 | } |
651 | 651 | |
652 | 652 | // Set checkbox value to radio value. |
653 | - $give_settings[ $setting_name ] = ( ! empty( $give_settings[ $setting_name ] ) && 'on' === $give_settings[ $setting_name ] ? 'enabled' : 'disabled' ); |
|
653 | + $give_settings[$setting_name] = ( ! empty($give_settings[$setting_name]) && 'on' === $give_settings[$setting_name] ? 'enabled' : 'disabled'); |
|
654 | 654 | |
655 | 655 | // @see https://github.com/WordImpress/Give/issues/1063 |
656 | - if ( false !== strpos( $setting_name, 'disable_' ) ) { |
|
656 | + if (false !== strpos($setting_name, 'disable_')) { |
|
657 | 657 | |
658 | - $give_settings[ $new_setting_name ] = ( give_is_setting_enabled( $give_settings[ $setting_name ] ) ? 'disabled' : 'enabled' ); |
|
659 | - } elseif ( false !== strpos( $setting_name, 'enable_' ) ) { |
|
658 | + $give_settings[$new_setting_name] = (give_is_setting_enabled($give_settings[$setting_name]) ? 'disabled' : 'enabled'); |
|
659 | + } elseif (false !== strpos($setting_name, 'enable_')) { |
|
660 | 660 | |
661 | - $give_settings[ $new_setting_name ] = ( give_is_setting_enabled( $give_settings[ $setting_name ] ) ? 'enabled' : 'disabled' ); |
|
661 | + $give_settings[$new_setting_name] = (give_is_setting_enabled($give_settings[$setting_name]) ? 'enabled' : 'disabled'); |
|
662 | 662 | } |
663 | 663 | |
664 | 664 | // Tell bot to update core setting to db. |
665 | - if ( ! $setting_changed ) { |
|
665 | + if ( ! $setting_changed) { |
|
666 | 666 | $setting_changed = true; |
667 | 667 | } |
668 | 668 | } |
669 | 669 | |
670 | 670 | // Update setting only if they changed. |
671 | - if ( $setting_changed ) { |
|
672 | - update_option( 'give_settings', $give_settings ); |
|
671 | + if ($setting_changed) { |
|
672 | + update_option('give_settings', $give_settings); |
|
673 | 673 | } |
674 | 674 | }// End if(). |
675 | 675 | |
676 | - give_set_upgrade_complete( 'v18_upgrades_core_setting' ); |
|
676 | + give_set_upgrade_complete('v18_upgrades_core_setting'); |
|
677 | 677 | } |
678 | 678 | |
679 | 679 | /** |
@@ -683,22 +683,22 @@ discard block |
||
683 | 683 | * @return void |
684 | 684 | */ |
685 | 685 | function give_v18_upgrades_form_metadata() { |
686 | - if ( ! current_user_can( 'manage_give_settings' ) ) { |
|
687 | - wp_die( esc_html__( 'You do not have permission to do Give upgrades.', 'give' ), esc_html__( 'Error', 'give' ), array( |
|
686 | + if ( ! current_user_can('manage_give_settings')) { |
|
687 | + wp_die(esc_html__('You do not have permission to do Give upgrades.', 'give'), esc_html__('Error', 'give'), array( |
|
688 | 688 | 'response' => 403, |
689 | - ) ); |
|
689 | + )); |
|
690 | 690 | } |
691 | 691 | |
692 | - ignore_user_abort( true ); |
|
692 | + ignore_user_abort(true); |
|
693 | 693 | |
694 | - if ( ! give_is_func_disabled( 'set_time_limit' ) && ! ini_get( 'safe_mode' ) ) { |
|
695 | - @set_time_limit( 0 ); |
|
694 | + if ( ! give_is_func_disabled('set_time_limit') && ! ini_get('safe_mode')) { |
|
695 | + @set_time_limit(0); |
|
696 | 696 | } |
697 | 697 | |
698 | - $step = isset( $_GET['step'] ) ? absint( $_GET['step'] ) : 1; |
|
698 | + $step = isset($_GET['step']) ? absint($_GET['step']) : 1; |
|
699 | 699 | |
700 | 700 | // form query |
701 | - $forms = new WP_Query( array( |
|
701 | + $forms = new WP_Query(array( |
|
702 | 702 | 'paged' => $step, |
703 | 703 | 'status' => 'any', |
704 | 704 | 'order' => 'ASC', |
@@ -707,39 +707,39 @@ discard block |
||
707 | 707 | ) |
708 | 708 | ); |
709 | 709 | |
710 | - if ( $forms->have_posts() ) { |
|
711 | - while ( $forms->have_posts() ) { |
|
710 | + if ($forms->have_posts()) { |
|
711 | + while ($forms->have_posts()) { |
|
712 | 712 | $forms->the_post(); |
713 | 713 | |
714 | 714 | // Form content. |
715 | 715 | // Note in version 1.8 display content setting split into display content and content placement setting. |
716 | 716 | // You can delete _give_content_option in future |
717 | - $show_content = get_post_meta( get_the_ID(), '_give_content_option', true ); |
|
718 | - if ( $show_content && ! get_post_meta( get_the_ID(), '_give_display_content', true ) ) { |
|
719 | - $field_value = ( 'none' !== $show_content ? 'enabled' : 'disabled' ); |
|
720 | - update_post_meta( get_the_ID(), '_give_display_content', $field_value ); |
|
717 | + $show_content = get_post_meta(get_the_ID(), '_give_content_option', true); |
|
718 | + if ($show_content && ! get_post_meta(get_the_ID(), '_give_display_content', true)) { |
|
719 | + $field_value = ('none' !== $show_content ? 'enabled' : 'disabled'); |
|
720 | + update_post_meta(get_the_ID(), '_give_display_content', $field_value); |
|
721 | 721 | |
722 | - $field_value = ( 'none' !== $show_content ? $show_content : 'give_pre_form' ); |
|
723 | - update_post_meta( get_the_ID(), '_give_content_placement', $field_value ); |
|
722 | + $field_value = ('none' !== $show_content ? $show_content : 'give_pre_form'); |
|
723 | + update_post_meta(get_the_ID(), '_give_content_placement', $field_value); |
|
724 | 724 | } |
725 | 725 | |
726 | 726 | // "Disable" Guest Donation. Checkbox |
727 | 727 | // See: https://github.com/WordImpress/Give/issues/1470 |
728 | - $guest_donation = get_post_meta( get_the_ID(), '_give_logged_in_only', true ); |
|
729 | - $guest_donation_newval = ( in_array( $guest_donation, array( 'yes', 'on' ) ) ? 'disabled' : 'enabled' ); |
|
730 | - update_post_meta( get_the_ID(), '_give_logged_in_only', $guest_donation_newval ); |
|
728 | + $guest_donation = get_post_meta(get_the_ID(), '_give_logged_in_only', true); |
|
729 | + $guest_donation_newval = (in_array($guest_donation, array('yes', 'on')) ? 'disabled' : 'enabled'); |
|
730 | + update_post_meta(get_the_ID(), '_give_logged_in_only', $guest_donation_newval); |
|
731 | 731 | |
732 | 732 | // Offline Donations |
733 | 733 | // See: https://github.com/WordImpress/Give/issues/1579 |
734 | - $offline_donation = get_post_meta( get_the_ID(), '_give_customize_offline_donations', true ); |
|
735 | - if ( 'no' === $offline_donation ) { |
|
734 | + $offline_donation = get_post_meta(get_the_ID(), '_give_customize_offline_donations', true); |
|
735 | + if ('no' === $offline_donation) { |
|
736 | 736 | $offline_donation_newval = 'global'; |
737 | - } elseif ( 'yes' === $offline_donation ) { |
|
737 | + } elseif ('yes' === $offline_donation) { |
|
738 | 738 | $offline_donation_newval = 'enabled'; |
739 | 739 | } else { |
740 | 740 | $offline_donation_newval = 'disabled'; |
741 | 741 | } |
742 | - update_post_meta( get_the_ID(), '_give_customize_offline_donations', $offline_donation_newval ); |
|
742 | + update_post_meta(get_the_ID(), '_give_customize_offline_donations', $offline_donation_newval); |
|
743 | 743 | |
744 | 744 | // Convert yes/no setting field to enabled/disabled. |
745 | 745 | $form_radio_settings = array( |
@@ -759,15 +759,15 @@ discard block |
||
759 | 759 | '_give_offline_donation_enable_billing_fields_single', |
760 | 760 | ); |
761 | 761 | |
762 | - foreach ( $form_radio_settings as $meta_key ) { |
|
762 | + foreach ($form_radio_settings as $meta_key) { |
|
763 | 763 | // Get value. |
764 | - $field_value = get_post_meta( get_the_ID(), $meta_key, true ); |
|
764 | + $field_value = get_post_meta(get_the_ID(), $meta_key, true); |
|
765 | 765 | |
766 | 766 | // Convert meta value only if it is in yes/no/none. |
767 | - if ( in_array( $field_value, array( 'yes', 'on', 'no', 'none' ) ) ) { |
|
767 | + if (in_array($field_value, array('yes', 'on', 'no', 'none'))) { |
|
768 | 768 | |
769 | - $field_value = ( in_array( $field_value, array( 'yes', 'on' ) ) ? 'enabled' : 'disabled' ); |
|
770 | - update_post_meta( get_the_ID(), $meta_key, $field_value ); |
|
769 | + $field_value = (in_array($field_value, array('yes', 'on')) ? 'enabled' : 'disabled'); |
|
770 | + update_post_meta(get_the_ID(), $meta_key, $field_value); |
|
771 | 771 | } |
772 | 772 | } |
773 | 773 | }// End while(). |
@@ -775,27 +775,27 @@ discard block |
||
775 | 775 | wp_reset_postdata(); |
776 | 776 | |
777 | 777 | // Forms found so upgrade them |
778 | - $step ++; |
|
779 | - $redirect = add_query_arg( array( |
|
778 | + $step++; |
|
779 | + $redirect = add_query_arg(array( |
|
780 | 780 | 'page' => 'give-upgrades', |
781 | 781 | 'give-upgrade' => 'give_v18_upgrades_form_metadata', |
782 | 782 | 'step' => $step, |
783 | - ), admin_url( 'index.php' ) ); |
|
784 | - wp_redirect( $redirect ); |
|
783 | + ), admin_url('index.php')); |
|
784 | + wp_redirect($redirect); |
|
785 | 785 | exit(); |
786 | 786 | |
787 | 787 | } else { |
788 | 788 | // No more forms found, finish up. |
789 | - update_option( 'give_version', preg_replace( '/[^0-9.].*/', '', GIVE_VERSION ) ); |
|
790 | - delete_option( 'give_doing_upgrade' ); |
|
791 | - give_set_upgrade_complete( 'v18_upgrades_form_metadata' ); |
|
789 | + update_option('give_version', preg_replace('/[^0-9.].*/', '', GIVE_VERSION)); |
|
790 | + delete_option('give_doing_upgrade'); |
|
791 | + give_set_upgrade_complete('v18_upgrades_form_metadata'); |
|
792 | 792 | |
793 | - wp_redirect( admin_url() ); |
|
793 | + wp_redirect(admin_url()); |
|
794 | 794 | exit; |
795 | 795 | } |
796 | 796 | } |
797 | 797 | |
798 | -add_action( 'give_give_v18_upgrades_form_metadata', 'give_v18_upgrades_form_metadata' ); |
|
798 | +add_action('give_give_v18_upgrades_form_metadata', 'give_v18_upgrades_form_metadata'); |
|
799 | 799 | |
800 | 800 | /** |
801 | 801 | * Get list of core setting renamed in version 1.8. |