@@ -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 | |
@@ -38,35 +38,35 @@ discard block |
||
| 38 | 38 | * |
| 39 | 39 | * @return float|int Total amount of donations based on the passed arguments. |
| 40 | 40 | */ |
| 41 | - public function get_sales( $form_id = 0, $start_date = false, $end_date = false, $status = 'publish' ) { |
|
| 41 | + public function get_sales($form_id = 0, $start_date = false, $end_date = false, $status = 'publish') { |
|
| 42 | 42 | |
| 43 | - $this->setup_dates( $start_date, $end_date ); |
|
| 43 | + $this->setup_dates($start_date, $end_date); |
|
| 44 | 44 | |
| 45 | 45 | // Make sure start date is valid |
| 46 | - if ( is_wp_error( $this->start_date ) ) { |
|
| 46 | + if (is_wp_error($this->start_date)) { |
|
| 47 | 47 | return $this->start_date; |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | // Make sure end date is valid |
| 51 | - if ( is_wp_error( $this->end_date ) ) { |
|
| 51 | + if (is_wp_error($this->end_date)) { |
|
| 52 | 52 | return $this->end_date; |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | - if ( empty( $form_id ) ) { |
|
| 55 | + if (empty($form_id)) { |
|
| 56 | 56 | |
| 57 | 57 | // Global sale stats |
| 58 | - add_filter( 'give_count_payments_where', array( $this, 'count_where' ) ); |
|
| 58 | + add_filter('give_count_payments_where', array($this, 'count_where')); |
|
| 59 | 59 | |
| 60 | - if ( is_array( $status ) ) { |
|
| 60 | + if (is_array($status)) { |
|
| 61 | 61 | $count = 0; |
| 62 | - foreach ( $status as $payment_status ) { |
|
| 62 | + foreach ($status as $payment_status) { |
|
| 63 | 63 | $count += give_count_payments()->$payment_status; |
| 64 | 64 | } |
| 65 | 65 | } else { |
| 66 | 66 | $count = give_count_payments()->$status; |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | - remove_filter( 'give_count_payments_where', array( $this, 'count_where' ) ); |
|
| 69 | + remove_filter('give_count_payments_where', array($this, 'count_where')); |
|
| 70 | 70 | |
| 71 | 71 | } else { |
| 72 | 72 | |
@@ -75,11 +75,11 @@ discard block |
||
| 75 | 75 | // Product specific stats |
| 76 | 76 | global $give_logs; |
| 77 | 77 | |
| 78 | - add_filter( 'posts_where', array( $this, 'payments_where' ) ); |
|
| 78 | + add_filter('posts_where', array($this, 'payments_where')); |
|
| 79 | 79 | |
| 80 | - $count = $give_logs->get_log_count( $form_id, 'sale' ); |
|
| 80 | + $count = $give_logs->get_log_count($form_id, 'sale'); |
|
| 81 | 81 | |
| 82 | - remove_filter( 'posts_where', array( $this, 'payments_where' ) ); |
|
| 82 | + remove_filter('posts_where', array($this, 'payments_where')); |
|
| 83 | 83 | |
| 84 | 84 | } |
| 85 | 85 | |
@@ -101,31 +101,31 @@ discard block |
||
| 101 | 101 | * |
| 102 | 102 | * @return float|int Total amount of donations based on the passed arguments. |
| 103 | 103 | */ |
| 104 | - public function get_earnings( $form_id = 0, $start_date = false, $end_date = false, $gateway_id = false ) { |
|
| 104 | + public function get_earnings($form_id = 0, $start_date = false, $end_date = false, $gateway_id = false) { |
|
| 105 | 105 | |
| 106 | 106 | global $wpdb; |
| 107 | 107 | |
| 108 | - $this->setup_dates( $start_date, $end_date ); |
|
| 108 | + $this->setup_dates($start_date, $end_date); |
|
| 109 | 109 | |
| 110 | 110 | // Make sure start date is valid |
| 111 | - if ( is_wp_error( $this->start_date ) ) { |
|
| 111 | + if (is_wp_error($this->start_date)) { |
|
| 112 | 112 | return $this->start_date; |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | // Make sure end date is valid |
| 116 | - if ( is_wp_error( $this->end_date ) ) { |
|
| 116 | + if (is_wp_error($this->end_date)) { |
|
| 117 | 117 | return $this->end_date; |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | - add_filter( 'posts_where', array( $this, 'payments_where' ) ); |
|
| 120 | + add_filter('posts_where', array($this, 'payments_where')); |
|
| 121 | 121 | |
| 122 | - if ( empty( $form_id ) ) { |
|
| 122 | + if (empty($form_id)) { |
|
| 123 | 123 | |
| 124 | 124 | // Global earning stats |
| 125 | 125 | $args = array( |
| 126 | 126 | 'post_type' => 'give_payment', |
| 127 | 127 | 'nopaging' => true, |
| 128 | - 'post_status' => array( 'publish' ), |
|
| 128 | + 'post_status' => array('publish'), |
|
| 129 | 129 | 'fields' => 'ids', |
| 130 | 130 | 'update_post_term_cache' => false, |
| 131 | 131 | 'suppress_filters' => false, |
@@ -137,24 +137,24 @@ discard block |
||
| 137 | 137 | ); |
| 138 | 138 | |
| 139 | 139 | //Filter by Gateway ID meta_key |
| 140 | - if ( $gateway_id !== false ) { |
|
| 140 | + if ($gateway_id !== false) { |
|
| 141 | 141 | $args['meta_key'] = '_give_payment_gateway'; |
| 142 | 142 | $args['meta_value'] = $gateway_id; |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | - $args = apply_filters( 'give_stats_earnings_args', $args ); |
|
| 146 | - $key = 'give_stats_' . substr( md5( serialize( $args ) ), 0, 15 ); |
|
| 147 | - $earnings = get_transient( $key ); |
|
| 145 | + $args = apply_filters('give_stats_earnings_args', $args); |
|
| 146 | + $key = 'give_stats_'.substr(md5(serialize($args)), 0, 15); |
|
| 147 | + $earnings = get_transient($key); |
|
| 148 | 148 | |
| 149 | - if ( false === $earnings ) { |
|
| 150 | - $sales = get_posts( $args ); |
|
| 149 | + if (false === $earnings) { |
|
| 150 | + $sales = get_posts($args); |
|
| 151 | 151 | $earnings = 0; |
| 152 | - if ( $sales ) { |
|
| 153 | - $sales = implode( ',', array_map('intval', $sales ) ); |
|
| 154 | - $earnings += $wpdb->get_var( "SELECT SUM(meta_value) FROM $wpdb->postmeta WHERE meta_key = '_give_payment_total' AND post_id IN({$sales})" ); |
|
| 152 | + if ($sales) { |
|
| 153 | + $sales = implode(',', array_map('intval', $sales)); |
|
| 154 | + $earnings += $wpdb->get_var("SELECT SUM(meta_value) FROM $wpdb->postmeta WHERE meta_key = '_give_payment_total' AND post_id IN({$sales})"); |
|
| 155 | 155 | } |
| 156 | 156 | // Cache the results for one hour |
| 157 | - set_transient( $key, $earnings, HOUR_IN_SECONDS ); |
|
| 157 | + set_transient($key, $earnings, HOUR_IN_SECONDS); |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | } else { |
@@ -174,37 +174,37 @@ discard block |
||
| 174 | 174 | 'give_transient_type' => 'give_earnings', |
| 175 | 175 | // This is not a valid query arg, but is used for cache keying |
| 176 | 176 | ); |
| 177 | - $args = apply_filters( 'give_stats_earnings_args', $args ); |
|
| 178 | - $key = 'give_stats_' . substr( md5( serialize( $args ) ), 0, 15 ); |
|
| 177 | + $args = apply_filters('give_stats_earnings_args', $args); |
|
| 178 | + $key = 'give_stats_'.substr(md5(serialize($args)), 0, 15); |
|
| 179 | 179 | //Set transient for faster stats |
| 180 | - $earnings = get_transient( $key ); |
|
| 180 | + $earnings = get_transient($key); |
|
| 181 | 181 | |
| 182 | - if ( false === $earnings ) { |
|
| 182 | + if (false === $earnings) { |
|
| 183 | 183 | |
| 184 | 184 | $this->timestamp = false; |
| 185 | - $log_ids = $give_logs->get_connected_logs( $args, 'sale' ); |
|
| 185 | + $log_ids = $give_logs->get_connected_logs($args, 'sale'); |
|
| 186 | 186 | $earnings = 0; |
| 187 | 187 | |
| 188 | - if ( $log_ids ) { |
|
| 189 | - $log_ids = implode( ',', array_map('intval', $log_ids ) ); |
|
| 190 | - $payment_ids = $wpdb->get_col( "SELECT meta_value FROM $wpdb->postmeta WHERE meta_key='_give_log_payment_id' AND post_id IN ($log_ids);" ); |
|
| 188 | + if ($log_ids) { |
|
| 189 | + $log_ids = implode(',', array_map('intval', $log_ids)); |
|
| 190 | + $payment_ids = $wpdb->get_col("SELECT meta_value FROM $wpdb->postmeta WHERE meta_key='_give_log_payment_id' AND post_id IN ($log_ids);"); |
|
| 191 | 191 | |
| 192 | - foreach ( $payment_ids as $payment_id ) { |
|
| 193 | - $earnings += give_get_payment_amount( $payment_id ); |
|
| 192 | + foreach ($payment_ids as $payment_id) { |
|
| 193 | + $earnings += give_get_payment_amount($payment_id); |
|
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | } |
| 197 | 197 | |
| 198 | 198 | // Cache the results for one hour |
| 199 | - set_transient( $key, $earnings, 60 * 60 ); |
|
| 199 | + set_transient($key, $earnings, 60 * 60); |
|
| 200 | 200 | } |
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | //remove our filter |
| 204 | - remove_filter( 'posts_where', array( $this, 'payments_where' ) ); |
|
| 204 | + remove_filter('posts_where', array($this, 'payments_where')); |
|
| 205 | 205 | |
| 206 | 206 | //return earnings |
| 207 | - return round( $earnings, give_currency_decimal_filter() ); |
|
| 207 | + return round($earnings, give_currency_decimal_filter()); |
|
| 208 | 208 | |
| 209 | 209 | } |
| 210 | 210 | |
@@ -221,29 +221,29 @@ discard block |
||
| 221 | 221 | * |
| 222 | 222 | * @return float|int Total amount of donations based on the passed arguments. |
| 223 | 223 | */ |
| 224 | - public function get_earnings_cache_key( $form_id = 0, $start_date = false, $end_date = false, $gateway_id = false ) { |
|
| 224 | + public function get_earnings_cache_key($form_id = 0, $start_date = false, $end_date = false, $gateway_id = false) { |
|
| 225 | 225 | |
| 226 | - $this->setup_dates( $start_date, $end_date ); |
|
| 226 | + $this->setup_dates($start_date, $end_date); |
|
| 227 | 227 | |
| 228 | 228 | // Make sure start date is valid |
| 229 | - if ( is_wp_error( $this->start_date ) ) { |
|
| 229 | + if (is_wp_error($this->start_date)) { |
|
| 230 | 230 | return $this->start_date; |
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | // Make sure end date is valid |
| 234 | - if ( is_wp_error( $this->end_date ) ) { |
|
| 234 | + if (is_wp_error($this->end_date)) { |
|
| 235 | 235 | return $this->end_date; |
| 236 | 236 | } |
| 237 | 237 | |
| 238 | - add_filter( 'posts_where', array( $this, 'payments_where' ) ); |
|
| 238 | + add_filter('posts_where', array($this, 'payments_where')); |
|
| 239 | 239 | |
| 240 | - if ( empty( $form_id ) ) { |
|
| 240 | + if (empty($form_id)) { |
|
| 241 | 241 | |
| 242 | 242 | // Global earning stats |
| 243 | 243 | $args = array( |
| 244 | 244 | 'post_type' => 'give_payment', |
| 245 | 245 | 'nopaging' => true, |
| 246 | - 'post_status' => array( 'publish' ), |
|
| 246 | + 'post_status' => array('publish'), |
|
| 247 | 247 | 'fields' => 'ids', |
| 248 | 248 | 'update_post_term_cache' => false, |
| 249 | 249 | 'suppress_filters' => false, |
@@ -255,13 +255,13 @@ discard block |
||
| 255 | 255 | ); |
| 256 | 256 | |
| 257 | 257 | //Filter by Gateway ID meta_key |
| 258 | - if ( $gateway_id !== false ) { |
|
| 258 | + if ($gateway_id !== false) { |
|
| 259 | 259 | $args['meta_key'] = '_give_payment_gateway'; |
| 260 | 260 | $args['meta_value'] = $gateway_id; |
| 261 | 261 | } |
| 262 | 262 | |
| 263 | - $args = apply_filters( 'give_stats_earnings_args', $args ); |
|
| 264 | - $key = 'give_stats_' . substr( md5( serialize( $args ) ), 0, 15 ); |
|
| 263 | + $args = apply_filters('give_stats_earnings_args', $args); |
|
| 264 | + $key = 'give_stats_'.substr(md5(serialize($args)), 0, 15); |
|
| 265 | 265 | |
| 266 | 266 | } else { |
| 267 | 267 | |
@@ -280,12 +280,12 @@ discard block |
||
| 280 | 280 | 'give_transient_type' => 'give_earnings', |
| 281 | 281 | // This is not a valid query arg, but is used for cache keying |
| 282 | 282 | ); |
| 283 | - $args = apply_filters( 'give_stats_earnings_args', $args ); |
|
| 284 | - $key = 'give_stats_' . substr( md5( serialize( $args ) ), 0, 15 ); |
|
| 283 | + $args = apply_filters('give_stats_earnings_args', $args); |
|
| 284 | + $key = 'give_stats_'.substr(md5(serialize($args)), 0, 15); |
|
| 285 | 285 | } |
| 286 | 286 | |
| 287 | 287 | //remove our filter |
| 288 | - remove_filter( 'posts_where', array( $this, 'payments_where' ) ); |
|
| 288 | + remove_filter('posts_where', array($this, 'payments_where')); |
|
| 289 | 289 | |
| 290 | 290 | //return earnings |
| 291 | 291 | return $key; |
@@ -302,16 +302,16 @@ discard block |
||
| 302 | 302 | * |
| 303 | 303 | * @return array Best selling forms |
| 304 | 304 | */ |
| 305 | - public function get_best_selling( $number = 10 ) { |
|
| 305 | + public function get_best_selling($number = 10) { |
|
| 306 | 306 | |
| 307 | 307 | global $wpdb; |
| 308 | 308 | |
| 309 | - $give_forms = $wpdb->get_results( $wpdb->prepare( |
|
| 309 | + $give_forms = $wpdb->get_results($wpdb->prepare( |
|
| 310 | 310 | "SELECT post_id as form_id, max(meta_value) as sales |
| 311 | 311 | FROM $wpdb->postmeta WHERE meta_key='_give_form_sales' AND meta_value > 0 |
| 312 | 312 | GROUP BY meta_value+0 |
| 313 | 313 | DESC LIMIT %d;", $number |
| 314 | - ) ); |
|
| 314 | + )); |
|
| 315 | 315 | |
| 316 | 316 | return $give_forms; |
| 317 | 317 | } |
@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | */ |
| 13 | 13 | |
| 14 | 14 | // Exit if accessed directly |
| 15 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 15 | +if ( ! defined('ABSPATH')) { |
|
| 16 | 16 | exit; |
| 17 | 17 | } |
| 18 | 18 | |
@@ -41,20 +41,20 @@ discard block |
||
| 41 | 41 | public function csv_cols() { |
| 42 | 42 | |
| 43 | 43 | $cols = array( |
| 44 | - 'ID' => esc_html__( 'ID', 'give' ), |
|
| 45 | - 'post_name' => esc_html__( 'Slug', 'give' ), |
|
| 46 | - 'post_title' => esc_html__( 'Name', 'give' ), |
|
| 47 | - 'post_date' => esc_html__( 'Date Created', 'give' ), |
|
| 48 | - 'post_author' => esc_html__( 'Author', 'give' ), |
|
| 49 | - 'post_content' => esc_html__( 'Description', 'give' ), |
|
| 50 | - 'post_excerpt' => esc_html__( 'Excerpt', 'give' ), |
|
| 51 | - 'post_status' => esc_html__( 'Status', 'give' ), |
|
| 52 | - 'categories' => esc_html__( 'Categories', 'give' ), |
|
| 53 | - 'tags' => esc_html__( 'Tags', 'give' ), |
|
| 54 | - 'give_price' => esc_html__( 'Price', 'give' ), |
|
| 55 | - '_thumbnail_id' => esc_html__( 'Featured Image', 'give' ), |
|
| 56 | - '_give_form_sales' => esc_html__( 'Donations', 'give' ), |
|
| 57 | - '_give_download_earnings' => esc_html__( 'Income', 'give' ), |
|
| 44 | + 'ID' => esc_html__('ID', 'give'), |
|
| 45 | + 'post_name' => esc_html__('Slug', 'give'), |
|
| 46 | + 'post_title' => esc_html__('Name', 'give'), |
|
| 47 | + 'post_date' => esc_html__('Date Created', 'give'), |
|
| 48 | + 'post_author' => esc_html__('Author', 'give'), |
|
| 49 | + 'post_content' => esc_html__('Description', 'give'), |
|
| 50 | + 'post_excerpt' => esc_html__('Excerpt', 'give'), |
|
| 51 | + 'post_status' => esc_html__('Status', 'give'), |
|
| 52 | + 'categories' => esc_html__('Categories', 'give'), |
|
| 53 | + 'tags' => esc_html__('Tags', 'give'), |
|
| 54 | + 'give_price' => esc_html__('Price', 'give'), |
|
| 55 | + '_thumbnail_id' => esc_html__('Featured Image', 'give'), |
|
| 56 | + '_give_form_sales' => esc_html__('Donations', 'give'), |
|
| 57 | + '_give_download_earnings' => esc_html__('Income', 'give'), |
|
| 58 | 58 | ); |
| 59 | 59 | |
| 60 | 60 | return $cols; |
@@ -86,43 +86,43 @@ discard block |
||
| 86 | 86 | 'paged' => $this->step |
| 87 | 87 | ); |
| 88 | 88 | |
| 89 | - $downloads = new WP_Query( $args ); |
|
| 89 | + $downloads = new WP_Query($args); |
|
| 90 | 90 | |
| 91 | - if ( $downloads->posts ) { |
|
| 92 | - foreach ( $downloads->posts as $download ) { |
|
| 91 | + if ($downloads->posts) { |
|
| 92 | + foreach ($downloads->posts as $download) { |
|
| 93 | 93 | |
| 94 | 94 | $row = array(); |
| 95 | 95 | |
| 96 | - foreach ( $this->csv_cols() as $key => $value ) { |
|
| 96 | + foreach ($this->csv_cols() as $key => $value) { |
|
| 97 | 97 | |
| 98 | 98 | // Setup default value |
| 99 | - $row[ $key ] = ''; |
|
| 99 | + $row[$key] = ''; |
|
| 100 | 100 | |
| 101 | - if ( in_array( $key, $meta ) ) { |
|
| 101 | + if (in_array($key, $meta)) { |
|
| 102 | 102 | |
| 103 | - switch ( $key ) { |
|
| 103 | + switch ($key) { |
|
| 104 | 104 | |
| 105 | 105 | case '_thumbnail_id' : |
| 106 | 106 | |
| 107 | - $image_id = get_post_thumbnail_id( $download->ID ); |
|
| 108 | - $row[ $key ] = wp_get_attachment_url( $image_id ); |
|
| 107 | + $image_id = get_post_thumbnail_id($download->ID); |
|
| 108 | + $row[$key] = wp_get_attachment_url($image_id); |
|
| 109 | 109 | |
| 110 | 110 | break; |
| 111 | 111 | |
| 112 | 112 | case 'give_price' : |
| 113 | 113 | |
| 114 | - if ( give_has_variable_prices( $download->ID ) ) { |
|
| 114 | + if (give_has_variable_prices($download->ID)) { |
|
| 115 | 115 | |
| 116 | 116 | $prices = array(); |
| 117 | - foreach ( give_get_variable_prices( $download->ID ) as $price ) { |
|
| 118 | - $prices[] = $price['name'] . ': ' . $price['amount']; |
|
| 117 | + foreach (give_get_variable_prices($download->ID) as $price) { |
|
| 118 | + $prices[] = $price['name'].': '.$price['amount']; |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | - $row[ $key ] = implode( ' | ', $prices ); |
|
| 121 | + $row[$key] = implode(' | ', $prices); |
|
| 122 | 122 | |
| 123 | 123 | } else { |
| 124 | 124 | |
| 125 | - $row[ $key ] = give_get_download_price( $download->ID ); |
|
| 125 | + $row[$key] = give_get_download_price($download->ID); |
|
| 126 | 126 | |
| 127 | 127 | } |
| 128 | 128 | |
@@ -132,54 +132,54 @@ discard block |
||
| 132 | 132 | |
| 133 | 133 | |
| 134 | 134 | $files = array(); |
| 135 | - foreach ( give_get_download_files( $download->ID ) as $file ) { |
|
| 135 | + foreach (give_get_download_files($download->ID) as $file) { |
|
| 136 | 136 | $files[] = $file['file']; |
| 137 | 137 | } |
| 138 | 138 | |
| 139 | - $row[ $key ] = implode( ' | ', $files ); |
|
| 139 | + $row[$key] = implode(' | ', $files); |
|
| 140 | 140 | |
| 141 | 141 | break; |
| 142 | 142 | |
| 143 | 143 | default : |
| 144 | 144 | |
| 145 | - $row[ $key ] = get_post_meta( $download->ID, $key, true ); |
|
| 145 | + $row[$key] = get_post_meta($download->ID, $key, true); |
|
| 146 | 146 | |
| 147 | 147 | break; |
| 148 | 148 | |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | - } elseif ( isset( $download->$key ) ) { |
|
| 151 | + } elseif (isset($download->$key)) { |
|
| 152 | 152 | |
| 153 | - switch ( $key ) { |
|
| 153 | + switch ($key) { |
|
| 154 | 154 | |
| 155 | 155 | case 'post_author' : |
| 156 | 156 | |
| 157 | - $row[ $key ] = get_the_author_meta( 'user_login', $download->post_author ); |
|
| 157 | + $row[$key] = get_the_author_meta('user_login', $download->post_author); |
|
| 158 | 158 | |
| 159 | 159 | break; |
| 160 | 160 | |
| 161 | 161 | default : |
| 162 | 162 | |
| 163 | - $row[ $key ] = $download->$key; |
|
| 163 | + $row[$key] = $download->$key; |
|
| 164 | 164 | |
| 165 | 165 | break; |
| 166 | 166 | } |
| 167 | 167 | |
| 168 | - } elseif ( 'tags' == $key ) { |
|
| 168 | + } elseif ('tags' == $key) { |
|
| 169 | 169 | |
| 170 | - $terms = get_the_terms( $download->ID, 'download_tag' ); |
|
| 171 | - if ( $terms ) { |
|
| 172 | - $terms = wp_list_pluck( $terms, 'name' ); |
|
| 173 | - $row[ $key ] = implode( ' | ', $terms ); |
|
| 170 | + $terms = get_the_terms($download->ID, 'download_tag'); |
|
| 171 | + if ($terms) { |
|
| 172 | + $terms = wp_list_pluck($terms, 'name'); |
|
| 173 | + $row[$key] = implode(' | ', $terms); |
|
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | |
| 177 | - } elseif ( 'categories' == $key ) { |
|
| 177 | + } elseif ('categories' == $key) { |
|
| 178 | 178 | |
| 179 | - $terms = get_the_terms( $download->ID, 'download_category' ); |
|
| 180 | - if ( $terms ) { |
|
| 181 | - $terms = wp_list_pluck( $terms, 'name' ); |
|
| 182 | - $row[ $key ] = implode( ' | ', $terms ); |
|
| 179 | + $terms = get_the_terms($download->ID, 'download_category'); |
|
| 180 | + if ($terms) { |
|
| 181 | + $terms = wp_list_pluck($terms, 'name'); |
|
| 182 | + $row[$key] = implode(' | ', $terms); |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | } |
@@ -190,8 +190,8 @@ discard block |
||
| 190 | 190 | |
| 191 | 191 | } |
| 192 | 192 | |
| 193 | - $data = apply_filters( 'give_export_get_data', $data ); |
|
| 194 | - $data = apply_filters( "give_export_get_data_{$this->export_type}", $data ); |
|
| 193 | + $data = apply_filters('give_export_get_data', $data); |
|
| 194 | + $data = apply_filters("give_export_get_data_{$this->export_type}", $data); |
|
| 195 | 195 | |
| 196 | 196 | return $data; |
| 197 | 197 | } |
@@ -210,20 +210,20 @@ discard block |
||
| 210 | 210 | |
| 211 | 211 | $args = array( |
| 212 | 212 | 'post_type' => 'give_forms', |
| 213 | - 'posts_per_page' => - 1, |
|
| 213 | + 'posts_per_page' => -1, |
|
| 214 | 214 | 'post_status' => 'any', |
| 215 | 215 | 'fields' => 'ids', |
| 216 | 216 | ); |
| 217 | 217 | |
| 218 | - $downloads = new WP_Query( $args ); |
|
| 218 | + $downloads = new WP_Query($args); |
|
| 219 | 219 | $total = (int) $downloads->post_count; |
| 220 | 220 | $percentage = 100; |
| 221 | 221 | |
| 222 | - if ( $total > 0 ) { |
|
| 223 | - $percentage = ( ( 30 * $this->step ) / $total ) * 100; |
|
| 222 | + if ($total > 0) { |
|
| 223 | + $percentage = ((30 * $this->step) / $total) * 100; |
|
| 224 | 224 | } |
| 225 | 225 | |
| 226 | - if ( $percentage > 100 ) { |
|
| 226 | + if ($percentage > 100) { |
|
| 227 | 227 | $percentage = 100; |
| 228 | 228 | } |
| 229 | 229 | |
@@ -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 | |
@@ -39,30 +39,30 @@ discard block |
||
| 39 | 39 | */ |
| 40 | 40 | public function csv_cols() { |
| 41 | 41 | $cols = array( |
| 42 | - 'id' => esc_html__( 'ID', 'give' ), // unaltered payment ID (use for querying). |
|
| 43 | - 'seq_id' => esc_html__( 'Payment Number', 'give' ), // sequential payment ID. |
|
| 44 | - 'email' => esc_html__( 'Email', 'give' ), |
|
| 45 | - 'first' => esc_html__( 'First Name', 'give' ), |
|
| 46 | - 'last' => esc_html__( 'Last Name', 'give' ), |
|
| 47 | - 'address1' => esc_html__( 'Address 1', 'give' ), |
|
| 48 | - 'address2' => esc_html__( 'Address 2', 'give' ), |
|
| 49 | - 'city' => esc_html__( 'City', 'give' ), |
|
| 50 | - 'state' => esc_html__( 'State', 'give' ), |
|
| 51 | - 'country' => esc_html__( 'Country', 'give' ), |
|
| 52 | - 'zip' => esc_html__( 'Zip / Postal Code', 'give' ), |
|
| 53 | - 'form_id' => esc_html__( 'Form ID', 'give' ), |
|
| 54 | - 'form_name' => esc_html__( 'Form Name', 'give' ), |
|
| 55 | - 'amount' => esc_html__( 'Amount', 'give' ) . ' (' . html_entity_decode( give_currency_filter( '' ) ) . ')', |
|
| 56 | - 'gateway' => esc_html__( 'Payment Method', 'give' ), |
|
| 57 | - 'trans_id' => esc_html__( 'Transaction ID', 'give' ), |
|
| 58 | - 'key' => esc_html__( 'Key', 'give' ), |
|
| 59 | - 'date' => esc_html__( 'Date', 'give' ), |
|
| 60 | - 'user' => esc_html__( 'User', 'give' ), |
|
| 61 | - 'status' => esc_html__( 'Status', 'give' ) |
|
| 42 | + 'id' => esc_html__('ID', 'give'), // unaltered payment ID (use for querying). |
|
| 43 | + 'seq_id' => esc_html__('Payment Number', 'give'), // sequential payment ID. |
|
| 44 | + 'email' => esc_html__('Email', 'give'), |
|
| 45 | + 'first' => esc_html__('First Name', 'give'), |
|
| 46 | + 'last' => esc_html__('Last Name', 'give'), |
|
| 47 | + 'address1' => esc_html__('Address 1', 'give'), |
|
| 48 | + 'address2' => esc_html__('Address 2', 'give'), |
|
| 49 | + 'city' => esc_html__('City', 'give'), |
|
| 50 | + 'state' => esc_html__('State', 'give'), |
|
| 51 | + 'country' => esc_html__('Country', 'give'), |
|
| 52 | + 'zip' => esc_html__('Zip / Postal Code', 'give'), |
|
| 53 | + 'form_id' => esc_html__('Form ID', 'give'), |
|
| 54 | + 'form_name' => esc_html__('Form Name', 'give'), |
|
| 55 | + 'amount' => esc_html__('Amount', 'give').' ('.html_entity_decode(give_currency_filter('')).')', |
|
| 56 | + 'gateway' => esc_html__('Payment Method', 'give'), |
|
| 57 | + 'trans_id' => esc_html__('Transaction ID', 'give'), |
|
| 58 | + 'key' => esc_html__('Key', 'give'), |
|
| 59 | + 'date' => esc_html__('Date', 'give'), |
|
| 60 | + 'user' => esc_html__('User', 'give'), |
|
| 61 | + 'status' => esc_html__('Status', 'give') |
|
| 62 | 62 | ); |
| 63 | 63 | |
| 64 | - if ( ! give_get_option( 'enable_sequential' ) ) { |
|
| 65 | - unset( $cols['seq_id'] ); |
|
| 64 | + if ( ! give_get_option('enable_sequential')) { |
|
| 65 | + unset($cols['seq_id']); |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | return $cols; |
@@ -87,12 +87,12 @@ discard block |
||
| 87 | 87 | 'status' => $this->status |
| 88 | 88 | ); |
| 89 | 89 | |
| 90 | - if ( ! empty( $this->start ) || ! empty( $this->end ) ) { |
|
| 90 | + if ( ! empty($this->start) || ! empty($this->end)) { |
|
| 91 | 91 | |
| 92 | 92 | $args['date_query'] = array( |
| 93 | 93 | array( |
| 94 | - 'after' => date( 'Y-n-d 00:00:00', strtotime( $this->start ) ), |
|
| 95 | - 'before' => date( 'Y-n-d 23:59:59', strtotime( $this->end ) ), |
|
| 94 | + 'after' => date('Y-n-d 00:00:00', strtotime($this->start)), |
|
| 95 | + 'before' => date('Y-n-d 23:59:59', strtotime($this->end)), |
|
| 96 | 96 | 'inclusive' => true |
| 97 | 97 | ) |
| 98 | 98 | ); |
@@ -101,52 +101,52 @@ discard block |
||
| 101 | 101 | |
| 102 | 102 | //echo json_encode($args ); exit; |
| 103 | 103 | |
| 104 | - $payments = give_get_payments( $args ); |
|
| 104 | + $payments = give_get_payments($args); |
|
| 105 | 105 | |
| 106 | - if ( $payments ) { |
|
| 106 | + if ($payments) { |
|
| 107 | 107 | |
| 108 | - foreach ( $payments as $payment ) { |
|
| 109 | - $payment_meta = give_get_payment_meta( $payment->ID ); |
|
| 110 | - $user_info = give_get_payment_meta_user_info( $payment->ID ); |
|
| 111 | - $total = give_get_payment_amount( $payment->ID ); |
|
| 112 | - $user_id = isset( $user_info['id'] ) && $user_info['id'] != - 1 ? $user_info['id'] : $user_info['email']; |
|
| 108 | + foreach ($payments as $payment) { |
|
| 109 | + $payment_meta = give_get_payment_meta($payment->ID); |
|
| 110 | + $user_info = give_get_payment_meta_user_info($payment->ID); |
|
| 111 | + $total = give_get_payment_amount($payment->ID); |
|
| 112 | + $user_id = isset($user_info['id']) && $user_info['id'] != - 1 ? $user_info['id'] : $user_info['email']; |
|
| 113 | 113 | $products = ''; |
| 114 | 114 | $skus = ''; |
| 115 | 115 | |
| 116 | - if ( is_numeric( $user_id ) ) { |
|
| 117 | - $user = get_userdata( $user_id ); |
|
| 116 | + if (is_numeric($user_id)) { |
|
| 117 | + $user = get_userdata($user_id); |
|
| 118 | 118 | } else { |
| 119 | 119 | $user = false; |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | $data[] = array( |
| 123 | 123 | 'id' => $payment->ID, |
| 124 | - 'seq_id' => give_get_payment_number( $payment->ID ), |
|
| 124 | + 'seq_id' => give_get_payment_number($payment->ID), |
|
| 125 | 125 | 'email' => $payment_meta['email'], |
| 126 | 126 | 'first' => $user_info['first_name'], |
| 127 | 127 | 'last' => $user_info['last_name'], |
| 128 | - 'address1' => isset( $user_info['address']['line1'] ) ? $user_info['address']['line1'] : '', |
|
| 129 | - 'address2' => isset( $user_info['address']['line2'] ) ? $user_info['address']['line2'] : '', |
|
| 130 | - 'city' => isset( $user_info['address']['city'] ) ? $user_info['address']['city'] : '', |
|
| 131 | - 'state' => isset( $user_info['address']['state'] ) ? $user_info['address']['state'] : '', |
|
| 132 | - 'country' => isset( $user_info['address']['country'] ) ? $user_info['address']['country'] : '', |
|
| 133 | - 'zip' => isset( $user_info['address']['zip'] ) ? $user_info['address']['zip'] : '', |
|
| 134 | - 'form_id' => isset( $payment_meta['form_id'] ) ? $payment_meta['form_id'] : '', |
|
| 135 | - 'form_name' => isset( $payment_meta['form_title'] ) ? $payment_meta['form_title'] : '', |
|
| 128 | + 'address1' => isset($user_info['address']['line1']) ? $user_info['address']['line1'] : '', |
|
| 129 | + 'address2' => isset($user_info['address']['line2']) ? $user_info['address']['line2'] : '', |
|
| 130 | + 'city' => isset($user_info['address']['city']) ? $user_info['address']['city'] : '', |
|
| 131 | + 'state' => isset($user_info['address']['state']) ? $user_info['address']['state'] : '', |
|
| 132 | + 'country' => isset($user_info['address']['country']) ? $user_info['address']['country'] : '', |
|
| 133 | + 'zip' => isset($user_info['address']['zip']) ? $user_info['address']['zip'] : '', |
|
| 134 | + 'form_id' => isset($payment_meta['form_id']) ? $payment_meta['form_id'] : '', |
|
| 135 | + 'form_name' => isset($payment_meta['form_title']) ? $payment_meta['form_title'] : '', |
|
| 136 | 136 | 'skus' => $skus, |
| 137 | - 'amount' => html_entity_decode( give_format_amount( $total ) ), |
|
| 138 | - 'gateway' => give_get_gateway_admin_label( get_post_meta( $payment->ID, '_give_payment_gateway', true ) ), |
|
| 139 | - 'trans_id' => give_get_payment_transaction_id( $payment->ID ), |
|
| 137 | + 'amount' => html_entity_decode(give_format_amount($total)), |
|
| 138 | + 'gateway' => give_get_gateway_admin_label(get_post_meta($payment->ID, '_give_payment_gateway', true)), |
|
| 139 | + 'trans_id' => give_get_payment_transaction_id($payment->ID), |
|
| 140 | 140 | 'key' => $payment_meta['key'], |
| 141 | 141 | 'date' => $payment->post_date, |
| 142 | - 'user' => $user ? $user->display_name : __( 'guest', 'give' ), |
|
| 143 | - 'status' => give_get_payment_status( $payment, true ) |
|
| 142 | + 'user' => $user ? $user->display_name : __('guest', 'give'), |
|
| 143 | + 'status' => give_get_payment_status($payment, true) |
|
| 144 | 144 | ); |
| 145 | 145 | |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | - $data = apply_filters( 'give_export_get_data', $data ); |
|
| 149 | - $data = apply_filters( "give_export_get_data_{$this->export_type}", $data ); |
|
| 148 | + $data = apply_filters('give_export_get_data', $data); |
|
| 149 | + $data = apply_filters("give_export_get_data_{$this->export_type}", $data); |
|
| 150 | 150 | |
| 151 | 151 | return $data; |
| 152 | 152 | |
@@ -166,27 +166,27 @@ discard block |
||
| 166 | 166 | |
| 167 | 167 | $status = $this->status; |
| 168 | 168 | $args = array( |
| 169 | - 'start-date' => date( 'n/d/Y', strtotime( $this->start ) ), |
|
| 170 | - 'end-date' => date( 'n/d/Y', strtotime( $this->end ) ), |
|
| 169 | + 'start-date' => date('n/d/Y', strtotime($this->start)), |
|
| 170 | + 'end-date' => date('n/d/Y', strtotime($this->end)), |
|
| 171 | 171 | ); |
| 172 | 172 | |
| 173 | - if ( 'any' == $status ) { |
|
| 173 | + if ('any' == $status) { |
|
| 174 | 174 | |
| 175 | - $total = array_sum( (array) give_count_payments( $args ) ); |
|
| 175 | + $total = array_sum((array) give_count_payments($args)); |
|
| 176 | 176 | |
| 177 | 177 | } else { |
| 178 | 178 | |
| 179 | - $total = give_count_payments( $args )->$status; |
|
| 179 | + $total = give_count_payments($args)->$status; |
|
| 180 | 180 | |
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | $percentage = 100; |
| 184 | 184 | |
| 185 | - if ( $total > 0 ) { |
|
| 186 | - $percentage = ( ( 30 * $this->step ) / $total ) * 100; |
|
| 185 | + if ($total > 0) { |
|
| 186 | + $percentage = ((30 * $this->step) / $total) * 100; |
|
| 187 | 187 | } |
| 188 | 188 | |
| 189 | - if ( $percentage > 100 ) { |
|
| 189 | + if ($percentage > 100) { |
|
| 190 | 190 | $percentage = 100; |
| 191 | 191 | } |
| 192 | 192 | |
@@ -200,9 +200,9 @@ discard block |
||
| 200 | 200 | * |
| 201 | 201 | * @param array $request The Form Data passed into the batch processing. |
| 202 | 202 | */ |
| 203 | - public function set_properties( $request ) { |
|
| 204 | - $this->start = isset( $request['start'] ) ? sanitize_text_field( $request['start'] ) : ''; |
|
| 205 | - $this->end = isset( $request['end'] ) ? sanitize_text_field( $request['end'] ) : ''; |
|
| 206 | - $this->status = isset( $request['status'] ) ? sanitize_text_field( $request['status'] ) : 'complete'; |
|
| 203 | + public function set_properties($request) { |
|
| 204 | + $this->start = isset($request['start']) ? sanitize_text_field($request['start']) : ''; |
|
| 205 | + $this->end = isset($request['end']) ? sanitize_text_field($request['end']) : ''; |
|
| 206 | + $this->status = isset($request['status']) ? sanitize_text_field($request['status']) : 'complete'; |
|
| 207 | 207 | } |
| 208 | 208 | } |
@@ -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 | |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | * @return bool Whether we can export or not |
| 38 | 38 | */ |
| 39 | 39 | public function can_export() { |
| 40 | - return (bool) apply_filters( 'give_export_capability', current_user_can( 'export_give_reports' ) ); |
|
| 40 | + return (bool) apply_filters('give_export_capability', current_user_can('export_give_reports')); |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | /** |
@@ -48,16 +48,16 @@ discard block |
||
| 48 | 48 | * @return void |
| 49 | 49 | */ |
| 50 | 50 | public function headers() { |
| 51 | - ignore_user_abort( true ); |
|
| 51 | + ignore_user_abort(true); |
|
| 52 | 52 | |
| 53 | - if ( ! give_is_func_disabled( 'set_time_limit' ) && ! ini_get( 'safe_mode' ) ) { |
|
| 54 | - set_time_limit( 0 ); |
|
| 53 | + if ( ! give_is_func_disabled('set_time_limit') && ! ini_get('safe_mode')) { |
|
| 54 | + set_time_limit(0); |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | nocache_headers(); |
| 58 | - header( 'Content-Type: text/csv; charset=utf-8' ); |
|
| 59 | - header( 'Content-Disposition: attachment; filename=give-export-' . $this->export_type . '-' . date( 'm-d-Y' ) . '.csv' ); |
|
| 60 | - header( "Expires: 0" ); |
|
| 58 | + header('Content-Type: text/csv; charset=utf-8'); |
|
| 59 | + header('Content-Disposition: attachment; filename=give-export-'.$this->export_type.'-'.date('m-d-Y').'.csv'); |
|
| 60 | + header("Expires: 0"); |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | /** |
@@ -69,8 +69,8 @@ discard block |
||
| 69 | 69 | */ |
| 70 | 70 | public function csv_cols() { |
| 71 | 71 | $cols = array( |
| 72 | - 'id' => esc_html__( 'ID', 'give' ), |
|
| 73 | - 'date' => esc_html__( 'Date', 'give' ) |
|
| 72 | + 'id' => esc_html__('ID', 'give'), |
|
| 73 | + 'date' => esc_html__('Date', 'give') |
|
| 74 | 74 | ); |
| 75 | 75 | |
| 76 | 76 | return $cols; |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | public function get_csv_cols() { |
| 87 | 87 | $cols = $this->csv_cols(); |
| 88 | 88 | |
| 89 | - return apply_filters( "give_export_csv_cols_{$this->export_type}", $cols ); |
|
| 89 | + return apply_filters("give_export_csv_cols_{$this->export_type}", $cols); |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | /** |
@@ -100,10 +100,10 @@ discard block |
||
| 100 | 100 | public function csv_cols_out() { |
| 101 | 101 | $cols = $this->get_csv_cols(); |
| 102 | 102 | $i = 1; |
| 103 | - foreach ( $cols as $col_id => $column ) { |
|
| 104 | - echo '"' . addslashes( $column ) . '"'; |
|
| 105 | - echo $i == count( $cols ) ? '' : ','; |
|
| 106 | - $i ++; |
|
| 103 | + foreach ($cols as $col_id => $column) { |
|
| 104 | + echo '"'.addslashes($column).'"'; |
|
| 105 | + echo $i == count($cols) ? '' : ','; |
|
| 106 | + $i++; |
|
| 107 | 107 | } |
| 108 | 108 | echo "\r\n"; |
| 109 | 109 | } |
@@ -120,16 +120,16 @@ discard block |
||
| 120 | 120 | $data = array( |
| 121 | 121 | 0 => array( |
| 122 | 122 | 'id' => '', |
| 123 | - 'data' => date( 'F j, Y' ) |
|
| 123 | + 'data' => date('F j, Y') |
|
| 124 | 124 | ), |
| 125 | 125 | 1 => array( |
| 126 | 126 | 'id' => '', |
| 127 | - 'data' => date( 'F j, Y' ) |
|
| 127 | + 'data' => date('F j, Y') |
|
| 128 | 128 | ) |
| 129 | 129 | ); |
| 130 | 130 | |
| 131 | - $data = apply_filters( 'give_export_get_data', $data ); |
|
| 132 | - $data = apply_filters( "give_export_get_data_{$this->export_type}", $data ); |
|
| 131 | + $data = apply_filters('give_export_get_data', $data); |
|
| 132 | + $data = apply_filters("give_export_get_data_{$this->export_type}", $data); |
|
| 133 | 133 | |
| 134 | 134 | return $data; |
| 135 | 135 | } |
@@ -147,14 +147,14 @@ discard block |
||
| 147 | 147 | $cols = $this->get_csv_cols(); |
| 148 | 148 | |
| 149 | 149 | // Output each row |
| 150 | - foreach ( $data as $row ) { |
|
| 150 | + foreach ($data as $row) { |
|
| 151 | 151 | $i = 1; |
| 152 | - foreach ( $row as $col_id => $column ) { |
|
| 152 | + foreach ($row as $col_id => $column) { |
|
| 153 | 153 | // Make sure the column is valid |
| 154 | - if ( array_key_exists( $col_id, $cols ) ) { |
|
| 155 | - echo '"' . addslashes( $column ) . '"'; |
|
| 156 | - echo $i == count( $cols ) ? '' : ','; |
|
| 157 | - $i ++; |
|
| 154 | + if (array_key_exists($col_id, $cols)) { |
|
| 155 | + echo '"'.addslashes($column).'"'; |
|
| 156 | + echo $i == count($cols) ? '' : ','; |
|
| 157 | + $i++; |
|
| 158 | 158 | } |
| 159 | 159 | } |
| 160 | 160 | echo "\r\n"; |
@@ -173,8 +173,8 @@ discard block |
||
| 173 | 173 | * @return void |
| 174 | 174 | */ |
| 175 | 175 | public function export() { |
| 176 | - if ( ! $this->can_export() ) { |
|
| 177 | - wp_die( esc_html__( 'You do not have permission to export data.', 'give' ), esc_html__( 'Error', 'give' ), array( 'response' => 403 ) ); |
|
| 176 | + if ( ! $this->can_export()) { |
|
| 177 | + wp_die(esc_html__('You do not have permission to export data.', 'give'), esc_html__('Error', 'give'), array('response' => 403)); |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | // Set headers |
@@ -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' ) : $item->payment_id; |
|
| 71 | + return empty($item->payment_id) ? esc_html__('n/a', 'give') : $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 | } |
@@ -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 | |
@@ -38,16 +38,16 @@ discard block |
||
| 38 | 38 | * @return void |
| 39 | 39 | */ |
| 40 | 40 | public function headers() { |
| 41 | - ignore_user_abort( true ); |
|
| 41 | + ignore_user_abort(true); |
|
| 42 | 42 | |
| 43 | - if ( ! give_is_func_disabled( 'set_time_limit' ) && ! ini_get( 'safe_mode' ) ) { |
|
| 44 | - set_time_limit( 0 ); |
|
| 43 | + if ( ! give_is_func_disabled('set_time_limit') && ! ini_get('safe_mode')) { |
|
| 44 | + set_time_limit(0); |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | nocache_headers(); |
| 48 | - header( 'Content-Type: text/csv; charset=utf-8' ); |
|
| 49 | - header( 'Content-Disposition: attachment; filename=' . apply_filters( 'give_earnings_export_filename', 'give-export-' . $this->export_type . '-' . date( 'n' ) . '-' . date( 'Y' ) ) . '.csv' ); |
|
| 50 | - header( "Expires: 0" ); |
|
| 48 | + header('Content-Type: text/csv; charset=utf-8'); |
|
| 49 | + header('Content-Disposition: attachment; filename='.apply_filters('give_earnings_export_filename', 'give-export-'.$this->export_type.'-'.date('n').'-'.date('Y')).'.csv'); |
|
| 50 | + header("Expires: 0"); |
|
| 51 | 51 | |
| 52 | 52 | } |
| 53 | 53 | |
@@ -61,10 +61,10 @@ discard block |
||
| 61 | 61 | public function csv_cols() { |
| 62 | 62 | |
| 63 | 63 | $cols = array( |
| 64 | - 'date' => esc_html__( 'Date', 'give' ), |
|
| 65 | - 'donations' => esc_html__( 'Donations', 'give' ), |
|
| 64 | + 'date' => esc_html__('Date', 'give'), |
|
| 65 | + 'donations' => esc_html__('Donations', 'give'), |
|
| 66 | 66 | /* translators: %s: currency */ |
| 67 | - 'earnings' => sprintf( esc_html__( 'Income (%s)', 'give' ), html_entity_decode( give_currency_filter( '' ) ) ) |
|
| 67 | + 'earnings' => sprintf(esc_html__('Income (%s)', 'give'), html_entity_decode(give_currency_filter(''))) |
|
| 68 | 68 | ); |
| 69 | 69 | |
| 70 | 70 | return $cols; |
@@ -79,28 +79,28 @@ discard block |
||
| 79 | 79 | */ |
| 80 | 80 | public function get_data() { |
| 81 | 81 | |
| 82 | - $start_year = isset( $_POST['start_year'] ) ? absint( $_POST['start_year'] ) : date( 'Y' ); |
|
| 83 | - $end_year = isset( $_POST['end_year'] ) ? absint( $_POST['end_year'] ) : date( 'Y' ); |
|
| 84 | - $start_month = isset( $_POST['start_month'] ) ? absint( $_POST['start_month'] ) : date( 'n' ); |
|
| 85 | - $end_month = isset( $_POST['end_month'] ) ? absint( $_POST['end_month'] ) : date( 'n' ); |
|
| 82 | + $start_year = isset($_POST['start_year']) ? absint($_POST['start_year']) : date('Y'); |
|
| 83 | + $end_year = isset($_POST['end_year']) ? absint($_POST['end_year']) : date('Y'); |
|
| 84 | + $start_month = isset($_POST['start_month']) ? absint($_POST['start_month']) : date('n'); |
|
| 85 | + $end_month = isset($_POST['end_month']) ? absint($_POST['end_month']) : date('n'); |
|
| 86 | 86 | |
| 87 | 87 | $data = array(); |
| 88 | 88 | $year = $start_year; |
| 89 | 89 | $stats = new Give_Payment_Stats; |
| 90 | 90 | |
| 91 | - while ( $year <= $end_year ) { |
|
| 91 | + while ($year <= $end_year) { |
|
| 92 | 92 | |
| 93 | - if ( $year == $start_year && $year == $end_year ) { |
|
| 93 | + if ($year == $start_year && $year == $end_year) { |
|
| 94 | 94 | |
| 95 | 95 | $m1 = $start_month; |
| 96 | 96 | $m2 = $end_month; |
| 97 | 97 | |
| 98 | - } elseif ( $year == $start_year ) { |
|
| 98 | + } elseif ($year == $start_year) { |
|
| 99 | 99 | |
| 100 | 100 | $m1 = $start_month; |
| 101 | 101 | $m2 = 12; |
| 102 | 102 | |
| 103 | - } elseif ( $year == $end_year ) { |
|
| 103 | + } elseif ($year == $end_year) { |
|
| 104 | 104 | |
| 105 | 105 | $m1 = 1; |
| 106 | 106 | $m2 = $end_month; |
@@ -112,28 +112,28 @@ discard block |
||
| 112 | 112 | |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | - while ( $m1 <= $m2 ) { |
|
| 115 | + while ($m1 <= $m2) { |
|
| 116 | 116 | |
| 117 | - $date1 = mktime( 0, 0, 0, $m1, 1, $year ); |
|
| 118 | - $date2 = mktime( 0, 0, 0, $m1, cal_days_in_month( CAL_GREGORIAN, $m1, $year ), $year ); |
|
| 117 | + $date1 = mktime(0, 0, 0, $m1, 1, $year); |
|
| 118 | + $date2 = mktime(0, 0, 0, $m1, cal_days_in_month(CAL_GREGORIAN, $m1, $year), $year); |
|
| 119 | 119 | |
| 120 | 120 | $data[] = array( |
| 121 | - 'date' => date_i18n( 'F Y', $date1 ), |
|
| 122 | - 'donations' => $stats->get_sales( 0, $date1, $date2 ), |
|
| 123 | - 'earnings' => give_format_amount( $stats->get_earnings( 0, $date1, $date2 ) ), |
|
| 121 | + 'date' => date_i18n('F Y', $date1), |
|
| 122 | + 'donations' => $stats->get_sales(0, $date1, $date2), |
|
| 123 | + 'earnings' => give_format_amount($stats->get_earnings(0, $date1, $date2)), |
|
| 124 | 124 | ); |
| 125 | 125 | |
| 126 | - $m1 ++; |
|
| 126 | + $m1++; |
|
| 127 | 127 | |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | |
| 131 | - $year ++; |
|
| 131 | + $year++; |
|
| 132 | 132 | |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | - $data = apply_filters( 'give_export_get_data', $data ); |
|
| 136 | - $data = apply_filters( "give_export_get_data_{$this->export_type}", $data ); |
|
| 135 | + $data = apply_filters('give_export_get_data', $data); |
|
| 136 | + $data = apply_filters("give_export_get_data_{$this->export_type}", $data); |
|
| 137 | 137 | |
| 138 | 138 | return $data; |
| 139 | 139 | } |
@@ -543,7 +543,7 @@ discard block |
||
| 543 | 543 | * and redirect back to the donor interface for feedback |
| 544 | 544 | * |
| 545 | 545 | * @since 1.7 |
| 546 | - * @return void|bool |
|
| 546 | + * @return false|null |
|
| 547 | 547 | */ |
| 548 | 548 | function give_remove_donor_email() { |
| 549 | 549 | if ( empty( $_GET['id'] ) || ! is_numeric( $_GET['id'] ) ) { |
@@ -583,7 +583,7 @@ discard block |
||
| 583 | 583 | * and redirect back to the donor interface for feedback |
| 584 | 584 | * |
| 585 | 585 | * @since 1.7 |
| 586 | - * @return void|bool |
|
| 586 | + * @return false|null |
|
| 587 | 587 | */ |
| 588 | 588 | function give_set_donor_primary_email() { |
| 589 | 589 | if ( empty( $_GET['id'] ) || ! is_numeric( $_GET['id'] ) ) { |
@@ -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 | |
@@ -23,15 +23,15 @@ discard block |
||
| 23 | 23 | * |
| 24 | 24 | * @return array $output Response messages |
| 25 | 25 | */ |
| 26 | -function give_edit_customer( $args ) { |
|
| 26 | +function give_edit_customer($args) { |
|
| 27 | 27 | |
| 28 | - $customer_edit_role = apply_filters( 'give_edit_customers_role', 'edit_give_payments' ); |
|
| 28 | + $customer_edit_role = apply_filters('give_edit_customers_role', 'edit_give_payments'); |
|
| 29 | 29 | |
| 30 | - if ( ! is_admin() || ! current_user_can( $customer_edit_role ) ) { |
|
| 31 | - wp_die( esc_html__( 'You do not have permission to edit this donor.', 'give' ), esc_html__( 'Error', 'give' ), array( 'response' => 403 ) ); |
|
| 30 | + if ( ! is_admin() || ! current_user_can($customer_edit_role)) { |
|
| 31 | + wp_die(esc_html__('You do not have permission to edit this donor.', 'give'), esc_html__('Error', 'give'), array('response' => 403)); |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | - if ( empty( $args ) ) { |
|
| 34 | + if (empty($args)) { |
|
| 35 | 35 | return; |
| 36 | 36 | } |
| 37 | 37 | |
@@ -39,12 +39,12 @@ discard block |
||
| 39 | 39 | $customer_id = (int) $args['customerinfo']['id']; |
| 40 | 40 | $nonce = $args['_wpnonce']; |
| 41 | 41 | |
| 42 | - if ( ! wp_verify_nonce( $nonce, 'edit-customer' ) ) { |
|
| 43 | - wp_die( esc_html__( 'Cheatin’ uh?', 'give' ), esc_html__( 'Error', 'give' ), array( 'response' => 400 ) ); |
|
| 42 | + if ( ! wp_verify_nonce($nonce, 'edit-customer')) { |
|
| 43 | + wp_die(esc_html__('Cheatin’ uh?', 'give'), esc_html__('Error', 'give'), array('response' => 400)); |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | - $customer = new Give_Customer( $customer_id ); |
|
| 47 | - if ( empty( $customer->id ) ) { |
|
| 46 | + $customer = new Give_Customer($customer_id); |
|
| 47 | + if (empty($customer->id)) { |
|
| 48 | 48 | return false; |
| 49 | 49 | } |
| 50 | 50 | |
@@ -53,19 +53,19 @@ discard block |
||
| 53 | 53 | 'user_id' => 0 |
| 54 | 54 | ); |
| 55 | 55 | |
| 56 | - $customer_info = wp_parse_args( $customer_info, $defaults ); |
|
| 56 | + $customer_info = wp_parse_args($customer_info, $defaults); |
|
| 57 | 57 | |
| 58 | - if ( (int) $customer_info['user_id'] != (int) $customer->user_id ) { |
|
| 58 | + if ((int) $customer_info['user_id'] != (int) $customer->user_id) { |
|
| 59 | 59 | |
| 60 | 60 | // Make sure we don't already have this user attached to a customer |
| 61 | - if ( ! empty( $customer_info['user_id'] ) && false !== Give()->customers->get_customer_by( 'user_id', $customer_info['user_id'] ) ) { |
|
| 62 | - give_set_error( 'give-invalid-customer-user_id', sprintf( esc_html__( 'The User ID %d is already associated with a different donor.', 'give' ), $customer_info['user_id'] ) ); |
|
| 61 | + if ( ! empty($customer_info['user_id']) && false !== Give()->customers->get_customer_by('user_id', $customer_info['user_id'])) { |
|
| 62 | + give_set_error('give-invalid-customer-user_id', sprintf(esc_html__('The User ID %d is already associated with a different donor.', 'give'), $customer_info['user_id'])); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | // Make sure it's actually a user |
| 66 | - $user = get_user_by( 'id', $customer_info['user_id'] ); |
|
| 67 | - if ( ! empty( $customer_info['user_id'] ) && false === $user ) { |
|
| 68 | - give_set_error( 'give-invalid-user_id', sprintf( esc_html__( 'The User ID %d does not exist. Please assign an existing user.', 'give' ), $customer_info['user_id'] ) ); |
|
| 66 | + $user = get_user_by('id', $customer_info['user_id']); |
|
| 67 | + if ( ! empty($customer_info['user_id']) && false === $user) { |
|
| 68 | + give_set_error('give-invalid-user_id', sprintf(esc_html__('The User ID %d does not exist. Please assign an existing user.', 'give'), $customer_info['user_id'])); |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | } |
@@ -73,52 +73,52 @@ discard block |
||
| 73 | 73 | // Record this for later |
| 74 | 74 | $previous_user_id = $customer->user_id; |
| 75 | 75 | |
| 76 | - if ( give_get_errors() ) { |
|
| 76 | + if (give_get_errors()) { |
|
| 77 | 77 | return; |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | // Setup the customer address, if present |
| 81 | 81 | $address = array(); |
| 82 | - if ( intval( $customer_info['user_id'] ) > 0 ) { |
|
| 82 | + if (intval($customer_info['user_id']) > 0) { |
|
| 83 | 83 | |
| 84 | - $current_address = get_user_meta( $customer_info['user_id'], '_give_user_address', true ); |
|
| 84 | + $current_address = get_user_meta($customer_info['user_id'], '_give_user_address', true); |
|
| 85 | 85 | |
| 86 | - if ( false === $current_address ) { |
|
| 87 | - $address['line1'] = isset( $customer_info['line1'] ) ? $customer_info['line1'] : ''; |
|
| 88 | - $address['line2'] = isset( $customer_info['line2'] ) ? $customer_info['line2'] : ''; |
|
| 89 | - $address['city'] = isset( $customer_info['city'] ) ? $customer_info['city'] : ''; |
|
| 90 | - $address['country'] = isset( $customer_info['country'] ) ? $customer_info['country'] : ''; |
|
| 91 | - $address['zip'] = isset( $customer_info['zip'] ) ? $customer_info['zip'] : ''; |
|
| 92 | - $address['state'] = isset( $customer_info['state'] ) ? $customer_info['state'] : ''; |
|
| 86 | + if (false === $current_address) { |
|
| 87 | + $address['line1'] = isset($customer_info['line1']) ? $customer_info['line1'] : ''; |
|
| 88 | + $address['line2'] = isset($customer_info['line2']) ? $customer_info['line2'] : ''; |
|
| 89 | + $address['city'] = isset($customer_info['city']) ? $customer_info['city'] : ''; |
|
| 90 | + $address['country'] = isset($customer_info['country']) ? $customer_info['country'] : ''; |
|
| 91 | + $address['zip'] = isset($customer_info['zip']) ? $customer_info['zip'] : ''; |
|
| 92 | + $address['state'] = isset($customer_info['state']) ? $customer_info['state'] : ''; |
|
| 93 | 93 | } else { |
| 94 | - $current_address = wp_parse_args( $current_address, array( |
|
| 94 | + $current_address = wp_parse_args($current_address, array( |
|
| 95 | 95 | 'line1', |
| 96 | 96 | 'line2', |
| 97 | 97 | 'city', |
| 98 | 98 | 'zip', |
| 99 | 99 | 'state', |
| 100 | 100 | 'country' |
| 101 | - ) ); |
|
| 102 | - $address['line1'] = isset( $customer_info['line1'] ) ? $customer_info['line1'] : $current_address['line1']; |
|
| 103 | - $address['line2'] = isset( $customer_info['line2'] ) ? $customer_info['line2'] : $current_address['line2']; |
|
| 104 | - $address['city'] = isset( $customer_info['city'] ) ? $customer_info['city'] : $current_address['city']; |
|
| 105 | - $address['country'] = isset( $customer_info['country'] ) ? $customer_info['country'] : $current_address['country']; |
|
| 106 | - $address['zip'] = isset( $customer_info['zip'] ) ? $customer_info['zip'] : $current_address['zip']; |
|
| 107 | - $address['state'] = isset( $customer_info['state'] ) ? $customer_info['state'] : $current_address['state']; |
|
| 101 | + )); |
|
| 102 | + $address['line1'] = isset($customer_info['line1']) ? $customer_info['line1'] : $current_address['line1']; |
|
| 103 | + $address['line2'] = isset($customer_info['line2']) ? $customer_info['line2'] : $current_address['line2']; |
|
| 104 | + $address['city'] = isset($customer_info['city']) ? $customer_info['city'] : $current_address['city']; |
|
| 105 | + $address['country'] = isset($customer_info['country']) ? $customer_info['country'] : $current_address['country']; |
|
| 106 | + $address['zip'] = isset($customer_info['zip']) ? $customer_info['zip'] : $current_address['zip']; |
|
| 107 | + $address['state'] = isset($customer_info['state']) ? $customer_info['state'] : $current_address['state']; |
|
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | // Sanitize the inputs |
| 113 | 113 | $customer_data = array(); |
| 114 | - $customer_data['name'] = strip_tags( stripslashes( $customer_info['name'] ) ); |
|
| 114 | + $customer_data['name'] = strip_tags(stripslashes($customer_info['name'])); |
|
| 115 | 115 | $customer_data['user_id'] = $customer_info['user_id']; |
| 116 | 116 | |
| 117 | - $customer_data = apply_filters( 'give_edit_customer_info', $customer_data, $customer_id ); |
|
| 118 | - $address = apply_filters( 'give_edit_customer_address', $address, $customer_id ); |
|
| 117 | + $customer_data = apply_filters('give_edit_customer_info', $customer_data, $customer_id); |
|
| 118 | + $address = apply_filters('give_edit_customer_address', $address, $customer_id); |
|
| 119 | 119 | |
| 120 | - $customer_data = array_map( 'sanitize_text_field', $customer_data ); |
|
| 121 | - $address = array_map( 'sanitize_text_field', $address ); |
|
| 120 | + $customer_data = array_map('sanitize_text_field', $customer_data); |
|
| 121 | + $address = array_map('sanitize_text_field', $address); |
|
| 122 | 122 | |
| 123 | 123 | |
| 124 | 124 | /** |
@@ -130,27 +130,27 @@ discard block |
||
| 130 | 130 | * @param array $customer_data The customer data. |
| 131 | 131 | * @param array $address The customer address. |
| 132 | 132 | */ |
| 133 | - do_action( 'give_pre_edit_customer', $customer_id, $customer_data, $address ); |
|
| 133 | + do_action('give_pre_edit_customer', $customer_id, $customer_data, $address); |
|
| 134 | 134 | |
| 135 | - $output = array(); |
|
| 135 | + $output = array(); |
|
| 136 | 136 | |
| 137 | - if ( $customer->update( $customer_data ) ) { |
|
| 137 | + if ($customer->update($customer_data)) { |
|
| 138 | 138 | |
| 139 | - if ( ! empty( $customer->user_id ) && $customer->user_id > 0 ) { |
|
| 140 | - update_user_meta( $customer->user_id, '_give_user_address', $address ); |
|
| 139 | + if ( ! empty($customer->user_id) && $customer->user_id > 0) { |
|
| 140 | + update_user_meta($customer->user_id, '_give_user_address', $address); |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | // Update some donation meta if we need to |
| 144 | - $payments_array = explode( ',', $customer->payment_ids ); |
|
| 144 | + $payments_array = explode(',', $customer->payment_ids); |
|
| 145 | 145 | |
| 146 | - if ( $customer->user_id != $previous_user_id ) { |
|
| 147 | - foreach ( $payments_array as $payment_id ) { |
|
| 148 | - give_update_payment_meta( $payment_id, '_give_payment_user_id', $customer->user_id ); |
|
| 146 | + if ($customer->user_id != $previous_user_id) { |
|
| 147 | + foreach ($payments_array as $payment_id) { |
|
| 148 | + give_update_payment_meta($payment_id, '_give_payment_user_id', $customer->user_id); |
|
| 149 | 149 | } |
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | $output['success'] = true; |
| 153 | - $customer_data = array_merge( $customer_data, $address ); |
|
| 153 | + $customer_data = array_merge($customer_data, $address); |
|
| 154 | 154 | $output['customer_info'] = $customer_data; |
| 155 | 155 | |
| 156 | 156 | } else { |
@@ -167,11 +167,11 @@ discard block |
||
| 167 | 167 | * @param int $customer_id The ID of the customer. |
| 168 | 168 | * @param array $customer_data The customer data. |
| 169 | 169 | */ |
| 170 | - do_action( 'give_post_edit_customer', $customer_id, $customer_data ); |
|
| 170 | + do_action('give_post_edit_customer', $customer_id, $customer_data); |
|
| 171 | 171 | |
| 172 | - if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { |
|
| 173 | - header( 'Content-Type: application/json' ); |
|
| 174 | - echo json_encode( $output ); |
|
| 172 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 173 | + header('Content-Type: application/json'); |
|
| 174 | + echo json_encode($output); |
|
| 175 | 175 | wp_die(); |
| 176 | 176 | } |
| 177 | 177 | |
@@ -179,7 +179,7 @@ discard block |
||
| 179 | 179 | |
| 180 | 180 | } |
| 181 | 181 | |
| 182 | -add_action( 'give_edit-customer', 'give_edit_customer', 10, 1 ); |
|
| 182 | +add_action('give_edit-customer', 'give_edit_customer', 10, 1); |
|
| 183 | 183 | |
| 184 | 184 | /** |
| 185 | 185 | * Save a customer note being added |
@@ -190,36 +190,36 @@ discard block |
||
| 190 | 190 | * |
| 191 | 191 | * @return int The Note ID that was saved, or 0 if nothing was saved |
| 192 | 192 | */ |
| 193 | -function give_customer_save_note( $args ) { |
|
| 193 | +function give_customer_save_note($args) { |
|
| 194 | 194 | |
| 195 | - $customer_view_role = apply_filters( 'give_view_customers_role', 'view_give_reports' ); |
|
| 195 | + $customer_view_role = apply_filters('give_view_customers_role', 'view_give_reports'); |
|
| 196 | 196 | |
| 197 | - if ( ! is_admin() || ! current_user_can( $customer_view_role ) ) { |
|
| 198 | - wp_die( esc_html__( 'You do not have permission to edit this donor.', 'give' ), esc_html__( 'Error', 'give' ), array( 'response' => 403 ) ); |
|
| 197 | + if ( ! is_admin() || ! current_user_can($customer_view_role)) { |
|
| 198 | + wp_die(esc_html__('You do not have permission to edit this donor.', 'give'), esc_html__('Error', 'give'), array('response' => 403)); |
|
| 199 | 199 | } |
| 200 | 200 | |
| 201 | - if ( empty( $args ) ) { |
|
| 201 | + if (empty($args)) { |
|
| 202 | 202 | return; |
| 203 | 203 | } |
| 204 | 204 | |
| 205 | - $customer_note = trim( sanitize_text_field( $args['customer_note'] ) ); |
|
| 205 | + $customer_note = trim(sanitize_text_field($args['customer_note'])); |
|
| 206 | 206 | $customer_id = (int) $args['customer_id']; |
| 207 | 207 | $nonce = $args['add_customer_note_nonce']; |
| 208 | 208 | |
| 209 | - if ( ! wp_verify_nonce( $nonce, 'add-customer-note' ) ) { |
|
| 210 | - wp_die( esc_html__( 'Cheatin’ uh?', 'give' ), esc_html__( 'Error', 'give' ), array( 'response' => 400 ) ); |
|
| 209 | + if ( ! wp_verify_nonce($nonce, 'add-customer-note')) { |
|
| 210 | + wp_die(esc_html__('Cheatin’ uh?', 'give'), esc_html__('Error', 'give'), array('response' => 400)); |
|
| 211 | 211 | } |
| 212 | 212 | |
| 213 | - if ( empty( $customer_note ) ) { |
|
| 214 | - give_set_error( 'empty-customer-note', esc_html__( 'A note is required.', 'give' ) ); |
|
| 213 | + if (empty($customer_note)) { |
|
| 214 | + give_set_error('empty-customer-note', esc_html__('A note is required.', 'give')); |
|
| 215 | 215 | } |
| 216 | 216 | |
| 217 | - if ( give_get_errors() ) { |
|
| 217 | + if (give_get_errors()) { |
|
| 218 | 218 | return; |
| 219 | 219 | } |
| 220 | 220 | |
| 221 | - $customer = new Give_Customer( $customer_id ); |
|
| 222 | - $new_note = $customer->add_note( $customer_note ); |
|
| 221 | + $customer = new Give_Customer($customer_id); |
|
| 222 | + $new_note = $customer->add_note($customer_note); |
|
| 223 | 223 | |
| 224 | 224 | /** |
| 225 | 225 | * Fires before inserting customer note. |
@@ -229,22 +229,22 @@ discard block |
||
| 229 | 229 | * @param int $customer_id The ID of the customer. |
| 230 | 230 | * @param string $new_note Note content. |
| 231 | 231 | */ |
| 232 | - do_action( 'give_pre_insert_customer_note', $customer_id, $new_note ); |
|
| 232 | + do_action('give_pre_insert_customer_note', $customer_id, $new_note); |
|
| 233 | 233 | |
| 234 | - if ( ! empty( $new_note ) && ! empty( $customer->id ) ) { |
|
| 234 | + if ( ! empty($new_note) && ! empty($customer->id)) { |
|
| 235 | 235 | |
| 236 | 236 | ob_start(); |
| 237 | 237 | ?> |
| 238 | 238 | <div class="customer-note-wrapper dashboard-comment-wrap comment-item"> |
| 239 | 239 | <span class="note-content-wrap"> |
| 240 | - <?php echo stripslashes( $new_note ); ?> |
|
| 240 | + <?php echo stripslashes($new_note); ?> |
|
| 241 | 241 | </span> |
| 242 | 242 | </div> |
| 243 | 243 | <?php |
| 244 | 244 | $output = ob_get_contents(); |
| 245 | 245 | ob_end_clean(); |
| 246 | 246 | |
| 247 | - if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { |
|
| 247 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 248 | 248 | echo $output; |
| 249 | 249 | exit; |
| 250 | 250 | } |
@@ -257,7 +257,7 @@ discard block |
||
| 257 | 257 | |
| 258 | 258 | } |
| 259 | 259 | |
| 260 | -add_action( 'give_add-customer-note', 'give_customer_save_note', 10, 1 ); |
|
| 260 | +add_action('give_add-customer-note', 'give_customer_save_note', 10, 1); |
|
| 261 | 261 | |
| 262 | 262 | /** |
| 263 | 263 | * Delete a customer |
@@ -268,37 +268,37 @@ discard block |
||
| 268 | 268 | * |
| 269 | 269 | * @return int Whether it was a successful deletion |
| 270 | 270 | */ |
| 271 | -function give_customer_delete( $args ) { |
|
| 271 | +function give_customer_delete($args) { |
|
| 272 | 272 | |
| 273 | - $customer_edit_role = apply_filters( 'give_edit_customers_role', 'edit_give_payments' ); |
|
| 273 | + $customer_edit_role = apply_filters('give_edit_customers_role', 'edit_give_payments'); |
|
| 274 | 274 | |
| 275 | - if ( ! is_admin() || ! current_user_can( $customer_edit_role ) ) { |
|
| 276 | - wp_die( esc_html__( 'You do not have permission to delete donors.', 'give' ), esc_html__( 'Error', 'give' ), array( 'response' => 403 ) ); |
|
| 275 | + if ( ! is_admin() || ! current_user_can($customer_edit_role)) { |
|
| 276 | + wp_die(esc_html__('You do not have permission to delete donors.', 'give'), esc_html__('Error', 'give'), array('response' => 403)); |
|
| 277 | 277 | } |
| 278 | 278 | |
| 279 | - if ( empty( $args ) ) { |
|
| 279 | + if (empty($args)) { |
|
| 280 | 280 | return; |
| 281 | 281 | } |
| 282 | 282 | |
| 283 | 283 | $customer_id = (int) $args['customer_id']; |
| 284 | - $confirm = ! empty( $args['give-customer-delete-confirm'] ) ? true : false; |
|
| 285 | - $remove_data = ! empty( $args['give-customer-delete-records'] ) ? true : false; |
|
| 284 | + $confirm = ! empty($args['give-customer-delete-confirm']) ? true : false; |
|
| 285 | + $remove_data = ! empty($args['give-customer-delete-records']) ? true : false; |
|
| 286 | 286 | $nonce = $args['_wpnonce']; |
| 287 | 287 | |
| 288 | - if ( ! wp_verify_nonce( $nonce, 'delete-customer' ) ) { |
|
| 289 | - wp_die( esc_html__( 'Cheatin’ uh?', 'give' ), esc_html__( 'Error', 'give' ), array( 'response' => 400 ) ); |
|
| 288 | + if ( ! wp_verify_nonce($nonce, 'delete-customer')) { |
|
| 289 | + wp_die(esc_html__('Cheatin’ uh?', 'give'), esc_html__('Error', 'give'), array('response' => 400)); |
|
| 290 | 290 | } |
| 291 | 291 | |
| 292 | - if ( ! $confirm ) { |
|
| 293 | - give_set_error( 'customer-delete-no-confirm', esc_html__( 'Please confirm you want to delete this donor.', 'give' ) ); |
|
| 292 | + if ( ! $confirm) { |
|
| 293 | + give_set_error('customer-delete-no-confirm', esc_html__('Please confirm you want to delete this donor.', 'give')); |
|
| 294 | 294 | } |
| 295 | 295 | |
| 296 | - if ( give_get_errors() ) { |
|
| 297 | - wp_redirect( admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=overview&id=' . $customer_id ) ); |
|
| 296 | + if (give_get_errors()) { |
|
| 297 | + wp_redirect(admin_url('edit.php?post_type=give_forms&page=give-donors&view=overview&id='.$customer_id)); |
|
| 298 | 298 | exit; |
| 299 | 299 | } |
| 300 | 300 | |
| 301 | - $customer = new Give_Customer( $customer_id ); |
|
| 301 | + $customer = new Give_Customer($customer_id); |
|
| 302 | 302 | |
| 303 | 303 | /** |
| 304 | 304 | * Fires before deleting customer. |
@@ -309,53 +309,53 @@ discard block |
||
| 309 | 309 | * @param bool $confirm Delete confirmation. |
| 310 | 310 | * @param bool $remove_data Records delete confirmation. |
| 311 | 311 | */ |
| 312 | - do_action( 'give_pre_delete_customer', $customer_id, $confirm, $remove_data ); |
|
| 312 | + do_action('give_pre_delete_customer', $customer_id, $confirm, $remove_data); |
|
| 313 | 313 | |
| 314 | - if ( $customer->id > 0 ) { |
|
| 314 | + if ($customer->id > 0) { |
|
| 315 | 315 | |
| 316 | - $payments_array = explode( ',', $customer->payment_ids ); |
|
| 317 | - $success = Give()->customers->delete( $customer->id ); |
|
| 316 | + $payments_array = explode(',', $customer->payment_ids); |
|
| 317 | + $success = Give()->customers->delete($customer->id); |
|
| 318 | 318 | |
| 319 | - if ( $success ) { |
|
| 319 | + if ($success) { |
|
| 320 | 320 | |
| 321 | - if ( $remove_data ) { |
|
| 321 | + if ($remove_data) { |
|
| 322 | 322 | |
| 323 | 323 | // Remove all donations, logs, etc |
| 324 | - foreach ( $payments_array as $payment_id ) { |
|
| 325 | - give_delete_purchase( $payment_id ); |
|
| 324 | + foreach ($payments_array as $payment_id) { |
|
| 325 | + give_delete_purchase($payment_id); |
|
| 326 | 326 | } |
| 327 | 327 | |
| 328 | 328 | } else { |
| 329 | 329 | |
| 330 | 330 | // Just set the donations to customer_id of 0 |
| 331 | - foreach ( $payments_array as $payment_id ) { |
|
| 332 | - give_update_payment_meta( $payment_id, '_give_payment_customer_id', 0 ); |
|
| 331 | + foreach ($payments_array as $payment_id) { |
|
| 332 | + give_update_payment_meta($payment_id, '_give_payment_customer_id', 0); |
|
| 333 | 333 | } |
| 334 | 334 | |
| 335 | 335 | } |
| 336 | 336 | |
| 337 | - $redirect = admin_url( 'edit.php?post_type=give_forms&page=give-donors&give-message=customer-deleted' ); |
|
| 337 | + $redirect = admin_url('edit.php?post_type=give_forms&page=give-donors&give-message=customer-deleted'); |
|
| 338 | 338 | |
| 339 | 339 | } else { |
| 340 | 340 | |
| 341 | - give_set_error( 'give-donor-delete-failed', esc_html__( 'Error deleting donor.', 'give' ) ); |
|
| 342 | - $redirect = admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=delete&id=' . $customer_id ); |
|
| 341 | + give_set_error('give-donor-delete-failed', esc_html__('Error deleting donor.', 'give')); |
|
| 342 | + $redirect = admin_url('edit.php?post_type=give_forms&page=give-donors&view=delete&id='.$customer_id); |
|
| 343 | 343 | |
| 344 | 344 | } |
| 345 | 345 | |
| 346 | 346 | } else { |
| 347 | 347 | |
| 348 | - give_set_error( 'give-customer-delete-invalid-id', esc_html__( 'Invalid Donor ID.', 'give' ) ); |
|
| 349 | - $redirect = admin_url( 'edit.php?post_type=give_forms&page=give-donors' ); |
|
| 348 | + give_set_error('give-customer-delete-invalid-id', esc_html__('Invalid Donor ID.', 'give')); |
|
| 349 | + $redirect = admin_url('edit.php?post_type=give_forms&page=give-donors'); |
|
| 350 | 350 | |
| 351 | 351 | } |
| 352 | 352 | |
| 353 | - wp_redirect( $redirect ); |
|
| 353 | + wp_redirect($redirect); |
|
| 354 | 354 | exit; |
| 355 | 355 | |
| 356 | 356 | } |
| 357 | 357 | |
| 358 | -add_action( 'give_delete-customer', 'give_customer_delete', 10, 1 ); |
|
| 358 | +add_action('give_delete-customer', 'give_customer_delete', 10, 1); |
|
| 359 | 359 | |
| 360 | 360 | /** |
| 361 | 361 | * Disconnect a user ID from a donor |
@@ -366,27 +366,27 @@ discard block |
||
| 366 | 366 | * |
| 367 | 367 | * @return bool If the disconnect was successful |
| 368 | 368 | */ |
| 369 | -function give_disconnect_customer_user_id( $args ) { |
|
| 369 | +function give_disconnect_customer_user_id($args) { |
|
| 370 | 370 | |
| 371 | - $customer_edit_role = apply_filters( 'give_edit_customers_role', 'edit_give_payments' ); |
|
| 371 | + $customer_edit_role = apply_filters('give_edit_customers_role', 'edit_give_payments'); |
|
| 372 | 372 | |
| 373 | - if ( ! is_admin() || ! current_user_can( $customer_edit_role ) ) { |
|
| 374 | - wp_die( esc_html__( 'You do not have permission to edit this donor.', 'give' ), esc_html__( 'Error', 'give' ), array( 'response' => 403 ) ); |
|
| 373 | + if ( ! is_admin() || ! current_user_can($customer_edit_role)) { |
|
| 374 | + wp_die(esc_html__('You do not have permission to edit this donor.', 'give'), esc_html__('Error', 'give'), array('response' => 403)); |
|
| 375 | 375 | } |
| 376 | 376 | |
| 377 | - if ( empty( $args ) ) { |
|
| 377 | + if (empty($args)) { |
|
| 378 | 378 | return; |
| 379 | 379 | } |
| 380 | 380 | |
| 381 | 381 | $customer_id = (int) $args['customer_id']; |
| 382 | 382 | $nonce = $args['_wpnonce']; |
| 383 | 383 | |
| 384 | - if ( ! wp_verify_nonce( $nonce, 'edit-customer' ) ) { |
|
| 385 | - wp_die( esc_html__( 'Cheatin’ uh?', 'give' ), esc_html__( 'Error', 'give' ), array( 'response' => 400 ) ); |
|
| 384 | + if ( ! wp_verify_nonce($nonce, 'edit-customer')) { |
|
| 385 | + wp_die(esc_html__('Cheatin’ uh?', 'give'), esc_html__('Error', 'give'), array('response' => 400)); |
|
| 386 | 386 | } |
| 387 | 387 | |
| 388 | - $customer = new Give_Customer( $customer_id ); |
|
| 389 | - if ( empty( $customer->id ) ) { |
|
| 388 | + $customer = new Give_Customer($customer_id); |
|
| 389 | + if (empty($customer->id)) { |
|
| 390 | 390 | return false; |
| 391 | 391 | } |
| 392 | 392 | |
@@ -400,16 +400,16 @@ discard block |
||
| 400 | 400 | * @param int $customer_id The ID of the customer. |
| 401 | 401 | * @param int $user_id The ID of the user. |
| 402 | 402 | */ |
| 403 | - do_action( 'give_pre_customer_disconnect_user_id', $customer_id, $user_id ); |
|
| 403 | + do_action('give_pre_customer_disconnect_user_id', $customer_id, $user_id); |
|
| 404 | 404 | |
| 405 | 405 | $output = array(); |
| 406 | - $customer_args = array( 'user_id' => 0 ); |
|
| 406 | + $customer_args = array('user_id' => 0); |
|
| 407 | 407 | |
| 408 | - if ( $customer->update( $customer_args ) ) { |
|
| 408 | + if ($customer->update($customer_args)) { |
|
| 409 | 409 | global $wpdb; |
| 410 | 410 | |
| 411 | - if ( ! empty( $customer->payment_ids ) ) { |
|
| 412 | - $wpdb->query( "UPDATE $wpdb->postmeta SET meta_value = 0 WHERE meta_key = '_give_payment_user_id' AND post_id IN ( $customer->payment_ids )" ); |
|
| 411 | + if ( ! empty($customer->payment_ids)) { |
|
| 412 | + $wpdb->query("UPDATE $wpdb->postmeta SET meta_value = 0 WHERE meta_key = '_give_payment_user_id' AND post_id IN ( $customer->payment_ids )"); |
|
| 413 | 413 | } |
| 414 | 414 | |
| 415 | 415 | $output['success'] = true; |
@@ -417,7 +417,7 @@ discard block |
||
| 417 | 417 | } else { |
| 418 | 418 | |
| 419 | 419 | $output['success'] = false; |
| 420 | - give_set_error( 'give-disconnect-user-fail', esc_html__( 'Failed to disconnect user from donor.', 'give' ) ); |
|
| 420 | + give_set_error('give-disconnect-user-fail', esc_html__('Failed to disconnect user from donor.', 'give')); |
|
| 421 | 421 | } |
| 422 | 422 | |
| 423 | 423 | /** |
@@ -427,11 +427,11 @@ discard block |
||
| 427 | 427 | * |
| 428 | 428 | * @param int $customer_id The ID of the customer. |
| 429 | 429 | */ |
| 430 | - do_action( 'give_post_customer_disconnect_user_id', $customer_id ); |
|
| 430 | + do_action('give_post_customer_disconnect_user_id', $customer_id); |
|
| 431 | 431 | |
| 432 | - if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { |
|
| 433 | - header( 'Content-Type: application/json' ); |
|
| 434 | - echo json_encode( $output ); |
|
| 432 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 433 | + header('Content-Type: application/json'); |
|
| 434 | + echo json_encode($output); |
|
| 435 | 435 | wp_die(); |
| 436 | 436 | } |
| 437 | 437 | |
@@ -439,7 +439,7 @@ discard block |
||
| 439 | 439 | |
| 440 | 440 | } |
| 441 | 441 | |
| 442 | -add_action( 'give_disconnect-userid', 'give_disconnect_customer_user_id', 10, 1 ); |
|
| 442 | +add_action('give_disconnect-userid', 'give_disconnect_customer_user_id', 10, 1); |
|
| 443 | 443 | |
| 444 | 444 | /** |
| 445 | 445 | * Add an email address to the donor from within the admin and log a donor note |
@@ -448,81 +448,81 @@ discard block |
||
| 448 | 448 | * @param array $args Array of arguments: nonce, customer id, and email address |
| 449 | 449 | * @return mixed If DOING_AJAX echos out JSON, otherwise returns array of success (bool) and message (string) |
| 450 | 450 | */ |
| 451 | -function give_add_donor_email( $args ) { |
|
| 452 | - $customer_edit_role = apply_filters( 'give_edit_customers_role', 'edit_give_payments' ); |
|
| 451 | +function give_add_donor_email($args) { |
|
| 452 | + $customer_edit_role = apply_filters('give_edit_customers_role', 'edit_give_payments'); |
|
| 453 | 453 | |
| 454 | - if ( ! is_admin() || ! current_user_can( $customer_edit_role ) ) { |
|
| 455 | - wp_die( esc_html__( 'You do not have permission to edit this donor.', 'edit' ) ); |
|
| 454 | + if ( ! is_admin() || ! current_user_can($customer_edit_role)) { |
|
| 455 | + wp_die(esc_html__('You do not have permission to edit this donor.', 'edit')); |
|
| 456 | 456 | } |
| 457 | 457 | |
| 458 | 458 | $output = array(); |
| 459 | - if ( empty( $args ) || empty( $args['email'] ) || empty( $args['customer_id'] ) ) { |
|
| 459 | + if (empty($args) || empty($args['email']) || empty($args['customer_id'])) { |
|
| 460 | 460 | $output['success'] = false; |
| 461 | - if ( empty( $args['email'] ) ) { |
|
| 462 | - $output['message'] = esc_html__( 'Email address is required.', 'give' ); |
|
| 463 | - } else if ( empty( $args['customer_id'] ) ) { |
|
| 464 | - $output['message'] = esc_html__( 'Customer ID is required.', 'give' ); |
|
| 461 | + if (empty($args['email'])) { |
|
| 462 | + $output['message'] = esc_html__('Email address is required.', 'give'); |
|
| 463 | + } else if (empty($args['customer_id'])) { |
|
| 464 | + $output['message'] = esc_html__('Customer ID is required.', 'give'); |
|
| 465 | 465 | } else { |
| 466 | - $output['message'] = esc_html__( 'An error has occurred. Please try again.', 'give' ); |
|
| 466 | + $output['message'] = esc_html__('An error has occurred. Please try again.', 'give'); |
|
| 467 | 467 | } |
| 468 | - } else if ( ! wp_verify_nonce( $args['_wpnonce'], 'give_add_donor_email' ) ) { |
|
| 468 | + } else if ( ! wp_verify_nonce($args['_wpnonce'], 'give_add_donor_email')) { |
|
| 469 | 469 | $output = array( |
| 470 | 470 | 'success' => false, |
| 471 | - 'message' => esc_html__( 'Nonce verification failed.', 'give' ), |
|
| 471 | + 'message' => esc_html__('Nonce verification failed.', 'give'), |
|
| 472 | 472 | ); |
| 473 | - } else if ( ! is_email( $args['email'] ) ) { |
|
| 473 | + } else if ( ! is_email($args['email'])) { |
|
| 474 | 474 | $output = array( |
| 475 | 475 | 'success' => false, |
| 476 | - 'message' => esc_html__( 'Invalid email address.', 'give' ), |
|
| 476 | + 'message' => esc_html__('Invalid email address.', 'give'), |
|
| 477 | 477 | ); |
| 478 | 478 | } else { |
| 479 | - $email = sanitize_email($args['email'] ); |
|
| 479 | + $email = sanitize_email($args['email']); |
|
| 480 | 480 | $customer_id = (int) $args['customer_id']; |
| 481 | 481 | $primary = 'true' === $args['primary'] ? true : false; |
| 482 | - $customer = new Give_Customer( $customer_id ); |
|
| 483 | - if ( false === $customer->add_email( $email, $primary ) ) { |
|
| 484 | - if ( in_array( $email, $customer->emails ) ) { |
|
| 482 | + $customer = new Give_Customer($customer_id); |
|
| 483 | + if (false === $customer->add_email($email, $primary)) { |
|
| 484 | + if (in_array($email, $customer->emails)) { |
|
| 485 | 485 | $output = array( |
| 486 | 486 | 'success' => false, |
| 487 | - 'message' => esc_html__( 'Email already associated with this donor.', 'give' ), |
|
| 487 | + 'message' => esc_html__('Email already associated with this donor.', 'give'), |
|
| 488 | 488 | ); |
| 489 | 489 | } else { |
| 490 | 490 | $output = array( |
| 491 | 491 | 'success' => false, |
| 492 | - 'message' => esc_html__( 'Email address is already associated with another donor.', 'give' ), |
|
| 492 | + 'message' => esc_html__('Email address is already associated with another donor.', 'give'), |
|
| 493 | 493 | ); |
| 494 | 494 | } |
| 495 | 495 | } else { |
| 496 | - $redirect = admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=overview&id=' . $customer_id . '&give-message=email-added' ); |
|
| 496 | + $redirect = admin_url('edit.php?post_type=give_forms&page=give-donors&view=overview&id='.$customer_id.'&give-message=email-added'); |
|
| 497 | 497 | $output = array( |
| 498 | 498 | 'success' => true, |
| 499 | - 'message' => esc_html__( 'Email successfully added to donor.', 'give' ), |
|
| 499 | + 'message' => esc_html__('Email successfully added to donor.', 'give'), |
|
| 500 | 500 | 'redirect' => $redirect, |
| 501 | 501 | ); |
| 502 | 502 | |
| 503 | 503 | $user = wp_get_current_user(); |
| 504 | - $user_login = ! empty( $user->user_login ) ? $user->user_login : esc_html__( 'System', 'give' ); |
|
| 505 | - $customer_note = sprintf( __( 'Email address %s added by %s', 'give' ), $email, $user_login ); |
|
| 506 | - $customer->add_note( $customer_note ); |
|
| 504 | + $user_login = ! empty($user->user_login) ? $user->user_login : esc_html__('System', 'give'); |
|
| 505 | + $customer_note = sprintf(__('Email address %s added by %s', 'give'), $email, $user_login); |
|
| 506 | + $customer->add_note($customer_note); |
|
| 507 | 507 | |
| 508 | - if ( $primary ) { |
|
| 509 | - $customer_note = sprintf( __( 'Email address %s set as primary by %s', 'give' ), $email, $user_login ); |
|
| 510 | - $customer->add_note( $customer_note ); |
|
| 508 | + if ($primary) { |
|
| 509 | + $customer_note = sprintf(__('Email address %s set as primary by %s', 'give'), $email, $user_login); |
|
| 510 | + $customer->add_note($customer_note); |
|
| 511 | 511 | } |
| 512 | 512 | } |
| 513 | 513 | } |
| 514 | 514 | |
| 515 | - do_action( 'give_post_add_customer_email', $customer_id, $args ); |
|
| 515 | + do_action('give_post_add_customer_email', $customer_id, $args); |
|
| 516 | 516 | |
| 517 | - if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { |
|
| 518 | - header( 'Content-Type: application/json' ); |
|
| 519 | - echo json_encode( $output ); |
|
| 517 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 518 | + header('Content-Type: application/json'); |
|
| 519 | + echo json_encode($output); |
|
| 520 | 520 | wp_die(); |
| 521 | 521 | } |
| 522 | 522 | |
| 523 | 523 | return $output; |
| 524 | 524 | } |
| 525 | -add_action( 'give_add_donor_email', 'give_add_donor_email', 10, 1 ); |
|
| 525 | +add_action('give_add_donor_email', 'give_add_donor_email', 10, 1); |
|
| 526 | 526 | |
| 527 | 527 | |
| 528 | 528 | /** |
@@ -533,36 +533,36 @@ discard block |
||
| 533 | 533 | * @return void|bool |
| 534 | 534 | */ |
| 535 | 535 | function give_remove_donor_email() { |
| 536 | - if ( empty( $_GET['id'] ) || ! is_numeric( $_GET['id'] ) ) { |
|
| 536 | + if (empty($_GET['id']) || ! is_numeric($_GET['id'])) { |
|
| 537 | 537 | return false; |
| 538 | 538 | } |
| 539 | - if ( empty( $_GET['email'] ) || ! is_email( $_GET['email'] ) ) { |
|
| 539 | + if (empty($_GET['email']) || ! is_email($_GET['email'])) { |
|
| 540 | 540 | return false; |
| 541 | 541 | } |
| 542 | - if ( empty( $_GET['_wpnonce'] ) ) { |
|
| 542 | + if (empty($_GET['_wpnonce'])) { |
|
| 543 | 543 | return false; |
| 544 | 544 | } |
| 545 | 545 | |
| 546 | 546 | $nonce = $_GET['_wpnonce']; |
| 547 | - if ( ! wp_verify_nonce( $nonce, 'give-remove-donor-email' ) ) { |
|
| 548 | - wp_die( esc_html__( 'Nonce verification failed', 'give' ), esc_html__( 'Error', 'give' ), array( 'response' => 403 ) ); |
|
| 547 | + if ( ! wp_verify_nonce($nonce, 'give-remove-donor-email')) { |
|
| 548 | + wp_die(esc_html__('Nonce verification failed', 'give'), esc_html__('Error', 'give'), array('response' => 403)); |
|
| 549 | 549 | } |
| 550 | 550 | |
| 551 | - $customer = new Give_Customer( $_GET['id'] ); |
|
| 552 | - if ( $customer->remove_email( $_GET['email'] ) ) { |
|
| 553 | - $url = add_query_arg( 'give-message', 'email-removed', admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=overview&id=' . $customer->id ) ); |
|
| 551 | + $customer = new Give_Customer($_GET['id']); |
|
| 552 | + if ($customer->remove_email($_GET['email'])) { |
|
| 553 | + $url = add_query_arg('give-message', 'email-removed', admin_url('edit.php?post_type=give_forms&page=give-donors&view=overview&id='.$customer->id)); |
|
| 554 | 554 | $user = wp_get_current_user(); |
| 555 | - $user_login = ! empty( $user->user_login ) ? $user->user_login : esc_html__( 'System', 'give' ); |
|
| 556 | - $customer_note = sprintf( __( 'Email address %s removed by %s', 'give' ), $_GET['email'], $user_login ); |
|
| 557 | - $customer->add_note( $customer_note ); |
|
| 555 | + $user_login = ! empty($user->user_login) ? $user->user_login : esc_html__('System', 'give'); |
|
| 556 | + $customer_note = sprintf(__('Email address %s removed by %s', 'give'), $_GET['email'], $user_login); |
|
| 557 | + $customer->add_note($customer_note); |
|
| 558 | 558 | } else { |
| 559 | - $url = add_query_arg( 'give-message', 'email-remove-failed', admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=overview&id=' . $customer->id ) ); |
|
| 559 | + $url = add_query_arg('give-message', 'email-remove-failed', admin_url('edit.php?post_type=give_forms&page=give-donors&view=overview&id='.$customer->id)); |
|
| 560 | 560 | } |
| 561 | 561 | |
| 562 | - wp_safe_redirect( $url ); |
|
| 562 | + wp_safe_redirect($url); |
|
| 563 | 563 | exit; |
| 564 | 564 | } |
| 565 | -add_action( 'give_remove_donor_email', 'give_remove_donor_email', 10 ); |
|
| 565 | +add_action('give_remove_donor_email', 'give_remove_donor_email', 10); |
|
| 566 | 566 | |
| 567 | 567 | |
| 568 | 568 | /** |
@@ -573,38 +573,38 @@ discard block |
||
| 573 | 573 | * @return void|bool |
| 574 | 574 | */ |
| 575 | 575 | function give_set_donor_primary_email() { |
| 576 | - if ( empty( $_GET['id'] ) || ! is_numeric( $_GET['id'] ) ) { |
|
| 576 | + if (empty($_GET['id']) || ! is_numeric($_GET['id'])) { |
|
| 577 | 577 | return false; |
| 578 | 578 | } |
| 579 | 579 | |
| 580 | - if ( empty( $_GET['email'] ) || ! is_email( $_GET['email'] ) ) { |
|
| 580 | + if (empty($_GET['email']) || ! is_email($_GET['email'])) { |
|
| 581 | 581 | return false; |
| 582 | 582 | } |
| 583 | 583 | |
| 584 | - if ( empty( $_GET['_wpnonce'] ) ) { |
|
| 584 | + if (empty($_GET['_wpnonce'])) { |
|
| 585 | 585 | return false; |
| 586 | 586 | } |
| 587 | 587 | |
| 588 | 588 | $nonce = $_GET['_wpnonce']; |
| 589 | 589 | |
| 590 | - if ( ! wp_verify_nonce( $nonce, 'give-set-donor-primary-email' ) ) { |
|
| 591 | - wp_die( esc_html__( 'Nonce verification failed', 'give' ), esc_html__( 'Error', 'give' ), array( 'response' => 403 ) ); |
|
| 590 | + if ( ! wp_verify_nonce($nonce, 'give-set-donor-primary-email')) { |
|
| 591 | + wp_die(esc_html__('Nonce verification failed', 'give'), esc_html__('Error', 'give'), array('response' => 403)); |
|
| 592 | 592 | } |
| 593 | 593 | |
| 594 | - $donor = new Give_Customer( $_GET['id'] ); |
|
| 594 | + $donor = new Give_Customer($_GET['id']); |
|
| 595 | 595 | |
| 596 | - if ( $donor->set_primary_email( $_GET['email'] ) ) { |
|
| 597 | - $url = add_query_arg( 'give-message', 'primary-email-updated', admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=overview&id=' . $donor->id ) ); |
|
| 596 | + if ($donor->set_primary_email($_GET['email'])) { |
|
| 597 | + $url = add_query_arg('give-message', 'primary-email-updated', admin_url('edit.php?post_type=give_forms&page=give-donors&view=overview&id='.$donor->id)); |
|
| 598 | 598 | $user = wp_get_current_user(); |
| 599 | - $user_login = ! empty( $user->user_login ) ? $user->user_login : esc_html__( 'System', 'give' ); |
|
| 600 | - $donor_note = sprintf( __( 'Email address %s set as primary by %s', 'give' ), $_GET['email'], $user_login ); |
|
| 599 | + $user_login = ! empty($user->user_login) ? $user->user_login : esc_html__('System', 'give'); |
|
| 600 | + $donor_note = sprintf(__('Email address %s set as primary by %s', 'give'), $_GET['email'], $user_login); |
|
| 601 | 601 | |
| 602 | - $donor->add_note( $donor_note ); |
|
| 602 | + $donor->add_note($donor_note); |
|
| 603 | 603 | } else { |
| 604 | - $url = add_query_arg( 'give-message', 'primary-email-failed', admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=overview&id=' . $donor->id ) ); |
|
| 604 | + $url = add_query_arg('give-message', 'primary-email-failed', admin_url('edit.php?post_type=give_forms&page=give-donors&view=overview&id='.$donor->id)); |
|
| 605 | 605 | } |
| 606 | 606 | |
| 607 | - wp_safe_redirect( $url ); |
|
| 607 | + wp_safe_redirect($url); |
|
| 608 | 608 | exit; |
| 609 | 609 | } |
| 610 | -add_action( 'give_set_donor_primary_email', 'give_set_donor_primary_email', 10 ); |
|
| 610 | +add_action('give_set_donor_primary_email', 'give_set_donor_primary_email', 10); |
|
@@ -890,7 +890,7 @@ discard block |
||
| 890 | 890 | * @access public |
| 891 | 891 | * |
| 892 | 892 | * @param string $meta_key Metadata name. Default is empty. |
| 893 | - * @param mixed $meta_value Metadata value. |
|
| 893 | + * @param string $meta_value Metadata value. |
|
| 894 | 894 | * @param bool $unique Optional. Whether the same key should not be added. Default is false. |
| 895 | 895 | * |
| 896 | 896 | * @return bool False for failure. True for success. |
@@ -922,7 +922,7 @@ discard block |
||
| 922 | 922 | * @access public |
| 923 | 923 | * |
| 924 | 924 | * @param string $meta_key Metadata name. Default is empty. |
| 925 | - * @param mixed $meta_value Optional. Metadata value. Default is empty. |
|
| 925 | + * @param string $meta_value Optional. Metadata value. Default is empty. |
|
| 926 | 926 | * |
| 927 | 927 | * @return bool False for failure. True for success. |
| 928 | 928 | */ |
@@ -714,12 +714,12 @@ discard block |
||
| 714 | 714 | |
| 715 | 715 | /** |
| 716 | 716 | * Decrease/Increase a customer's lifetime value. |
| 717 | - * |
|
| 718 | - * This function will update donation stat on basis of current amount and new amount donation difference. |
|
| 719 | - * Difference value can positive or negative. Negative value will decrease user donation stat while positive value increase donation stat. |
|
| 720 | - * |
|
| 717 | + * |
|
| 718 | + * This function will update donation stat on basis of current amount and new amount donation difference. |
|
| 719 | + * Difference value can positive or negative. Negative value will decrease user donation stat while positive value increase donation stat. |
|
| 720 | + * |
|
| 721 | 721 | * @since 1.0 |
| 722 | - * @access public |
|
| 722 | + * @access public |
|
| 723 | 723 | * |
| 724 | 724 | * @param float $curr_amount Current Donation amount. |
| 725 | 725 | * @param float $new_amount New (changed) Donation amount. |
@@ -727,35 +727,35 @@ discard block |
||
| 727 | 727 | * @return mixed If successful, the new donation stat value, otherwise false. |
| 728 | 728 | */ |
| 729 | 729 | public function update_donation_value( $curr_amount, $new_amount ) { |
| 730 | - /** |
|
| 731 | - * Payment total difference value can be: |
|
| 732 | - * zero (in case amount not change) |
|
| 733 | - * or -ve (in case amount decrease) |
|
| 734 | - * or +ve (in case amount increase) |
|
| 735 | - */ |
|
| 736 | - $payment_total_diff = $new_amount - $curr_amount; |
|
| 737 | - |
|
| 738 | - // We do not need to update donation stat if donation did not change. |
|
| 739 | - if( ! $payment_total_diff ) { |
|
| 740 | - return false; |
|
| 741 | - } |
|
| 742 | - |
|
| 743 | - |
|
| 744 | - if( $payment_total_diff > 0 ) { |
|
| 745 | - $this->increase_value( $payment_total_diff ); |
|
| 746 | - } else { |
|
| 747 | - // Pass payment total difference as +ve value to decrease amount from user lifetime stat. |
|
| 748 | - $this->decrease_value( -$payment_total_diff ); |
|
| 749 | - } |
|
| 750 | - |
|
| 751 | - return $this->purchase_value; |
|
| 730 | + /** |
|
| 731 | + * Payment total difference value can be: |
|
| 732 | + * zero (in case amount not change) |
|
| 733 | + * or -ve (in case amount decrease) |
|
| 734 | + * or +ve (in case amount increase) |
|
| 735 | + */ |
|
| 736 | + $payment_total_diff = $new_amount - $curr_amount; |
|
| 737 | + |
|
| 738 | + // We do not need to update donation stat if donation did not change. |
|
| 739 | + if( ! $payment_total_diff ) { |
|
| 740 | + return false; |
|
| 741 | + } |
|
| 742 | + |
|
| 743 | + |
|
| 744 | + if( $payment_total_diff > 0 ) { |
|
| 745 | + $this->increase_value( $payment_total_diff ); |
|
| 746 | + } else { |
|
| 747 | + // Pass payment total difference as +ve value to decrease amount from user lifetime stat. |
|
| 748 | + $this->decrease_value( -$payment_total_diff ); |
|
| 749 | + } |
|
| 750 | + |
|
| 751 | + return $this->purchase_value; |
|
| 752 | 752 | } |
| 753 | 753 | |
| 754 | 754 | /** |
| 755 | 755 | * Get the parsed notes for a customer as an array. |
| 756 | 756 | * |
| 757 | 757 | * @since 1.0 |
| 758 | - * @access public |
|
| 758 | + * @access public |
|
| 759 | 759 | * |
| 760 | 760 | * @param int $length The number of notes to get. |
| 761 | 761 | * @param int $paged What note to start at. |
@@ -780,7 +780,7 @@ discard block |
||
| 780 | 780 | * Get the total number of notes we have after parsing. |
| 781 | 781 | * |
| 782 | 782 | * @since 1.0 |
| 783 | - * @access public |
|
| 783 | + * @access public |
|
| 784 | 784 | * |
| 785 | 785 | * @return int The number of notes for the customer. |
| 786 | 786 | */ |
@@ -797,7 +797,7 @@ discard block |
||
| 797 | 797 | * Add a note for the customer. |
| 798 | 798 | * |
| 799 | 799 | * @since 1.0 |
| 800 | - * @access public |
|
| 800 | + * @access public |
|
| 801 | 801 | * |
| 802 | 802 | * @param string $note The note to add. Default is empty. |
| 803 | 803 | * |
@@ -856,7 +856,7 @@ discard block |
||
| 856 | 856 | * Get the notes column for the customer |
| 857 | 857 | * |
| 858 | 858 | * @since 1.0 |
| 859 | - * @access private |
|
| 859 | + * @access private |
|
| 860 | 860 | * |
| 861 | 861 | * @return string The Notes for the customer, non-parsed. |
| 862 | 862 | */ |
@@ -934,7 +934,7 @@ discard block |
||
| 934 | 934 | * Sanitize the data for update/create |
| 935 | 935 | * |
| 936 | 936 | * @since 1.0 |
| 937 | - * @access private |
|
| 937 | + * @access private |
|
| 938 | 938 | * |
| 939 | 939 | * @param array $data The data to sanitize. |
| 940 | 940 | * |
@@ -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 | |
@@ -144,29 +144,29 @@ discard block |
||
| 144 | 144 | * @param bool $_id_or_email |
| 145 | 145 | * @param bool $by_user_id |
| 146 | 146 | */ |
| 147 | - public function __construct( $_id_or_email = false, $by_user_id = false ) { |
|
| 147 | + public function __construct($_id_or_email = false, $by_user_id = false) { |
|
| 148 | 148 | |
| 149 | 149 | $this->db = new Give_DB_Customers; |
| 150 | 150 | |
| 151 | - if ( false === $_id_or_email || ( is_numeric( $_id_or_email ) && (int) $_id_or_email !== absint( $_id_or_email ) ) ) { |
|
| 151 | + if (false === $_id_or_email || (is_numeric($_id_or_email) && (int) $_id_or_email !== absint($_id_or_email))) { |
|
| 152 | 152 | return false; |
| 153 | 153 | } |
| 154 | 154 | |
| 155 | - $by_user_id = is_bool( $by_user_id ) ? $by_user_id : false; |
|
| 155 | + $by_user_id = is_bool($by_user_id) ? $by_user_id : false; |
|
| 156 | 156 | |
| 157 | - if ( is_numeric( $_id_or_email ) ) { |
|
| 157 | + if (is_numeric($_id_or_email)) { |
|
| 158 | 158 | $field = $by_user_id ? 'user_id' : 'id'; |
| 159 | 159 | } else { |
| 160 | 160 | $field = 'email'; |
| 161 | 161 | } |
| 162 | 162 | |
| 163 | - $customer = $this->db->get_customer_by( $field, $_id_or_email ); |
|
| 163 | + $customer = $this->db->get_customer_by($field, $_id_or_email); |
|
| 164 | 164 | |
| 165 | - if ( empty( $customer ) || ! is_object( $customer ) ) { |
|
| 165 | + if (empty($customer) || ! is_object($customer)) { |
|
| 166 | 166 | return false; |
| 167 | 167 | } |
| 168 | 168 | |
| 169 | - $this->setup_customer( $customer ); |
|
| 169 | + $this->setup_customer($customer); |
|
| 170 | 170 | |
| 171 | 171 | } |
| 172 | 172 | |
@@ -182,15 +182,15 @@ discard block |
||
| 182 | 182 | * |
| 183 | 183 | * @return bool If the setup was successful or not. |
| 184 | 184 | */ |
| 185 | - private function setup_customer( $customer ) { |
|
| 185 | + private function setup_customer($customer) { |
|
| 186 | 186 | |
| 187 | - if ( ! is_object( $customer ) ) { |
|
| 187 | + if ( ! is_object($customer)) { |
|
| 188 | 188 | return false; |
| 189 | 189 | } |
| 190 | 190 | |
| 191 | - foreach ( $customer as $key => $value ) { |
|
| 191 | + foreach ($customer as $key => $value) { |
|
| 192 | 192 | |
| 193 | - switch ( $key ) { |
|
| 193 | + switch ($key) { |
|
| 194 | 194 | |
| 195 | 195 | case 'notes': |
| 196 | 196 | $this->$key = $this->get_notes(); |
@@ -205,11 +205,11 @@ discard block |
||
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | // Get donor's all email including primary email. |
| 208 | - $this->emails = (array) $this->get_meta( 'additional_email', false ); |
|
| 209 | - $this->emails = array( 'primary' => $this->email ) + $this->emails; |
|
| 208 | + $this->emails = (array) $this->get_meta('additional_email', false); |
|
| 209 | + $this->emails = array('primary' => $this->email) + $this->emails; |
|
| 210 | 210 | |
| 211 | 211 | // Customer ID and email are the only things that are necessary, make sure they exist. |
| 212 | - if ( ! empty( $this->id ) && ! empty( $this->email ) ) { |
|
| 212 | + if ( ! empty($this->id) && ! empty($this->email)) { |
|
| 213 | 213 | return true; |
| 214 | 214 | } |
| 215 | 215 | |
@@ -223,16 +223,16 @@ discard block |
||
| 223 | 223 | * @since 1.0 |
| 224 | 224 | * @access public |
| 225 | 225 | */ |
| 226 | - public function __get( $key ) { |
|
| 226 | + public function __get($key) { |
|
| 227 | 227 | |
| 228 | - if ( method_exists( $this, 'get_' . $key ) ) { |
|
| 228 | + if (method_exists($this, 'get_'.$key)) { |
|
| 229 | 229 | |
| 230 | - return call_user_func( array( $this, 'get_' . $key ) ); |
|
| 230 | + return call_user_func(array($this, 'get_'.$key)); |
|
| 231 | 231 | |
| 232 | 232 | } else { |
| 233 | 233 | |
| 234 | 234 | /* translators: %s: property key */ |
| 235 | - return new WP_Error( 'give-customer-invalid-property', sprintf( esc_html__( 'Can\'t get property %s.', 'give' ), $key ) ); |
|
| 235 | + return new WP_Error('give-customer-invalid-property', sprintf(esc_html__('Can\'t get property %s.', 'give'), $key)); |
|
| 236 | 236 | |
| 237 | 237 | } |
| 238 | 238 | |
@@ -248,9 +248,9 @@ discard block |
||
| 248 | 248 | * |
| 249 | 249 | * @return bool|int False if not a valid creation, customer ID if user is found or valid creation. |
| 250 | 250 | */ |
| 251 | - public function create( $data = array() ) { |
|
| 251 | + public function create($data = array()) { |
|
| 252 | 252 | |
| 253 | - if ( $this->id != 0 || empty( $data ) ) { |
|
| 253 | + if ($this->id != 0 || empty($data)) { |
|
| 254 | 254 | return false; |
| 255 | 255 | } |
| 256 | 256 | |
@@ -258,15 +258,15 @@ discard block |
||
| 258 | 258 | 'payment_ids' => '' |
| 259 | 259 | ); |
| 260 | 260 | |
| 261 | - $args = wp_parse_args( $data, $defaults ); |
|
| 262 | - $args = $this->sanitize_columns( $args ); |
|
| 261 | + $args = wp_parse_args($data, $defaults); |
|
| 262 | + $args = $this->sanitize_columns($args); |
|
| 263 | 263 | |
| 264 | - if ( empty( $args['email'] ) || ! is_email( $args['email'] ) ) { |
|
| 264 | + if (empty($args['email']) || ! is_email($args['email'])) { |
|
| 265 | 265 | return false; |
| 266 | 266 | } |
| 267 | 267 | |
| 268 | - if ( ! empty( $args['payment_ids'] ) && is_array( $args['payment_ids'] ) ) { |
|
| 269 | - $args['payment_ids'] = implode( ',', array_unique( array_values( $args['payment_ids'] ) ) ); |
|
| 268 | + if ( ! empty($args['payment_ids']) && is_array($args['payment_ids'])) { |
|
| 269 | + $args['payment_ids'] = implode(',', array_unique(array_values($args['payment_ids']))); |
|
| 270 | 270 | } |
| 271 | 271 | |
| 272 | 272 | /** |
@@ -276,18 +276,18 @@ discard block |
||
| 276 | 276 | * |
| 277 | 277 | * @param array $args Customer attributes. |
| 278 | 278 | */ |
| 279 | - do_action( 'give_customer_pre_create', $args ); |
|
| 279 | + do_action('give_customer_pre_create', $args); |
|
| 280 | 280 | |
| 281 | 281 | $created = false; |
| 282 | 282 | |
| 283 | 283 | // The DB class 'add' implies an update if the customer being asked to be created already exists |
| 284 | - if ( $this->db->add( $data ) ) { |
|
| 284 | + if ($this->db->add($data)) { |
|
| 285 | 285 | |
| 286 | 286 | // We've successfully added/updated the customer, reset the class vars with the new data |
| 287 | - $customer = $this->db->get_customer_by( 'email', $args['email'] ); |
|
| 287 | + $customer = $this->db->get_customer_by('email', $args['email']); |
|
| 288 | 288 | |
| 289 | 289 | // Setup the customer data with the values from DB |
| 290 | - $this->setup_customer( $customer ); |
|
| 290 | + $this->setup_customer($customer); |
|
| 291 | 291 | |
| 292 | 292 | $created = $this->id; |
| 293 | 293 | } |
@@ -301,7 +301,7 @@ discard block |
||
| 301 | 301 | * customer ID if user is found or valid creation. |
| 302 | 302 | * @param array $args Customer attributes. |
| 303 | 303 | */ |
| 304 | - do_action( 'give_customer_post_create', $created, $args ); |
|
| 304 | + do_action('give_customer_post_create', $created, $args); |
|
| 305 | 305 | |
| 306 | 306 | return $created; |
| 307 | 307 | |
@@ -317,13 +317,13 @@ discard block |
||
| 317 | 317 | * |
| 318 | 318 | * @return bool If the update was successful or not. |
| 319 | 319 | */ |
| 320 | - public function update( $data = array() ) { |
|
| 320 | + public function update($data = array()) { |
|
| 321 | 321 | |
| 322 | - if ( empty( $data ) ) { |
|
| 322 | + if (empty($data)) { |
|
| 323 | 323 | return false; |
| 324 | 324 | } |
| 325 | 325 | |
| 326 | - $data = $this->sanitize_columns( $data ); |
|
| 326 | + $data = $this->sanitize_columns($data); |
|
| 327 | 327 | |
| 328 | 328 | /** |
| 329 | 329 | * Fires before updating customers. |
@@ -333,14 +333,14 @@ discard block |
||
| 333 | 333 | * @param int $customer_id Customer id. |
| 334 | 334 | * @param array $data Customer attributes. |
| 335 | 335 | */ |
| 336 | - do_action( 'give_customer_pre_update', $this->id, $data ); |
|
| 336 | + do_action('give_customer_pre_update', $this->id, $data); |
|
| 337 | 337 | |
| 338 | 338 | $updated = false; |
| 339 | 339 | |
| 340 | - if ( $this->db->update( $this->id, $data ) ) { |
|
| 340 | + if ($this->db->update($this->id, $data)) { |
|
| 341 | 341 | |
| 342 | - $customer = $this->db->get_customer_by( 'id', $this->id ); |
|
| 343 | - $this->setup_customer( $customer ); |
|
| 342 | + $customer = $this->db->get_customer_by('id', $this->id); |
|
| 343 | + $this->setup_customer($customer); |
|
| 344 | 344 | |
| 345 | 345 | $updated = true; |
| 346 | 346 | } |
@@ -354,7 +354,7 @@ discard block |
||
| 354 | 354 | * @param int $customer_id Customer id. |
| 355 | 355 | * @param array $data Customer attributes. |
| 356 | 356 | */ |
| 357 | - do_action( 'give_customer_post_update', $updated, $this->id, $data ); |
|
| 357 | + do_action('give_customer_post_update', $updated, $this->id, $data); |
|
| 358 | 358 | |
| 359 | 359 | return $updated; |
| 360 | 360 | } |
@@ -372,27 +372,27 @@ discard block |
||
| 372 | 372 | * |
| 373 | 373 | * @return bool If the attachment was successfuly. |
| 374 | 374 | */ |
| 375 | - public function attach_payment( $payment_id = 0, $update_stats = true ) { |
|
| 375 | + public function attach_payment($payment_id = 0, $update_stats = true) { |
|
| 376 | 376 | |
| 377 | - if ( empty( $payment_id ) ) { |
|
| 377 | + if (empty($payment_id)) { |
|
| 378 | 378 | return false; |
| 379 | 379 | } |
| 380 | 380 | |
| 381 | - if ( empty( $this->payment_ids ) ) { |
|
| 381 | + if (empty($this->payment_ids)) { |
|
| 382 | 382 | |
| 383 | 383 | $new_payment_ids = $payment_id; |
| 384 | 384 | |
| 385 | 385 | } else { |
| 386 | 386 | |
| 387 | - $payment_ids = array_map( 'absint', explode( ',', $this->payment_ids ) ); |
|
| 387 | + $payment_ids = array_map('absint', explode(',', $this->payment_ids)); |
|
| 388 | 388 | |
| 389 | - if ( in_array( $payment_id, $payment_ids ) ) { |
|
| 389 | + if (in_array($payment_id, $payment_ids)) { |
|
| 390 | 390 | $update_stats = false; |
| 391 | 391 | } |
| 392 | 392 | |
| 393 | 393 | $payment_ids[] = $payment_id; |
| 394 | 394 | |
| 395 | - $new_payment_ids = implode( ',', array_unique( array_values( $payment_ids ) ) ); |
|
| 395 | + $new_payment_ids = implode(',', array_unique(array_values($payment_ids))); |
|
| 396 | 396 | |
| 397 | 397 | } |
| 398 | 398 | |
@@ -404,20 +404,20 @@ discard block |
||
| 404 | 404 | * @param int $payment_id Payment id. |
| 405 | 405 | * @param int $customer_id Customer id. |
| 406 | 406 | */ |
| 407 | - do_action( 'give_customer_pre_attach_payment', $payment_id, $this->id ); |
|
| 407 | + do_action('give_customer_pre_attach_payment', $payment_id, $this->id); |
|
| 408 | 408 | |
| 409 | - $payment_added = $this->update( array( 'payment_ids' => $new_payment_ids ) ); |
|
| 409 | + $payment_added = $this->update(array('payment_ids' => $new_payment_ids)); |
|
| 410 | 410 | |
| 411 | - if ( $payment_added ) { |
|
| 411 | + if ($payment_added) { |
|
| 412 | 412 | |
| 413 | 413 | $this->payment_ids = $new_payment_ids; |
| 414 | 414 | |
| 415 | 415 | // We added this payment successfully, increment the stats |
| 416 | - if ( $update_stats ) { |
|
| 417 | - $payment_amount = give_get_payment_amount( $payment_id ); |
|
| 416 | + if ($update_stats) { |
|
| 417 | + $payment_amount = give_get_payment_amount($payment_id); |
|
| 418 | 418 | |
| 419 | - if ( ! empty( $payment_amount ) ) { |
|
| 420 | - $this->increase_value( $payment_amount ); |
|
| 419 | + if ( ! empty($payment_amount)) { |
|
| 420 | + $this->increase_value($payment_amount); |
|
| 421 | 421 | } |
| 422 | 422 | |
| 423 | 423 | $this->increase_purchase_count(); |
@@ -434,7 +434,7 @@ discard block |
||
| 434 | 434 | * @param int $payment_id Payment id. |
| 435 | 435 | * @param int $customer_id Customer id. |
| 436 | 436 | */ |
| 437 | - do_action( 'give_customer_post_attach_payment', $payment_added, $payment_id, $this->id ); |
|
| 437 | + do_action('give_customer_post_attach_payment', $payment_added, $payment_id, $this->id); |
|
| 438 | 438 | |
| 439 | 439 | return $payment_added; |
| 440 | 440 | } |
@@ -452,33 +452,33 @@ discard block |
||
| 452 | 452 | * |
| 453 | 453 | * @return boolean If the removal was successful. |
| 454 | 454 | */ |
| 455 | - public function remove_payment( $payment_id = 0, $update_stats = true ) { |
|
| 455 | + public function remove_payment($payment_id = 0, $update_stats = true) { |
|
| 456 | 456 | |
| 457 | - if ( empty( $payment_id ) ) { |
|
| 457 | + if (empty($payment_id)) { |
|
| 458 | 458 | return false; |
| 459 | 459 | } |
| 460 | 460 | |
| 461 | - $payment = new Give_Payment( $payment_id ); |
|
| 461 | + $payment = new Give_Payment($payment_id); |
|
| 462 | 462 | |
| 463 | - if ( 'publish' !== $payment->status && 'revoked' !== $payment->status ) { |
|
| 463 | + if ('publish' !== $payment->status && 'revoked' !== $payment->status) { |
|
| 464 | 464 | $update_stats = false; |
| 465 | 465 | } |
| 466 | 466 | |
| 467 | 467 | $new_payment_ids = ''; |
| 468 | 468 | |
| 469 | - if ( ! empty( $this->payment_ids ) ) { |
|
| 469 | + if ( ! empty($this->payment_ids)) { |
|
| 470 | 470 | |
| 471 | - $payment_ids = array_map( 'absint', explode( ',', $this->payment_ids ) ); |
|
| 471 | + $payment_ids = array_map('absint', explode(',', $this->payment_ids)); |
|
| 472 | 472 | |
| 473 | - $pos = array_search( $payment_id, $payment_ids ); |
|
| 474 | - if ( false === $pos ) { |
|
| 473 | + $pos = array_search($payment_id, $payment_ids); |
|
| 474 | + if (false === $pos) { |
|
| 475 | 475 | return false; |
| 476 | 476 | } |
| 477 | 477 | |
| 478 | - unset( $payment_ids[ $pos ] ); |
|
| 479 | - $payment_ids = array_filter( $payment_ids ); |
|
| 478 | + unset($payment_ids[$pos]); |
|
| 479 | + $payment_ids = array_filter($payment_ids); |
|
| 480 | 480 | |
| 481 | - $new_payment_ids = implode( ',', array_unique( array_values( $payment_ids ) ) ); |
|
| 481 | + $new_payment_ids = implode(',', array_unique(array_values($payment_ids))); |
|
| 482 | 482 | |
| 483 | 483 | } |
| 484 | 484 | |
@@ -490,20 +490,20 @@ discard block |
||
| 490 | 490 | * @param int $payment_id Payment id. |
| 491 | 491 | * @param int $customer_id Customer id. |
| 492 | 492 | */ |
| 493 | - do_action( 'give_customer_pre_remove_payment', $payment_id, $this->id ); |
|
| 493 | + do_action('give_customer_pre_remove_payment', $payment_id, $this->id); |
|
| 494 | 494 | |
| 495 | - $payment_removed = $this->update( array( 'payment_ids' => $new_payment_ids ) ); |
|
| 495 | + $payment_removed = $this->update(array('payment_ids' => $new_payment_ids)); |
|
| 496 | 496 | |
| 497 | - if ( $payment_removed ) { |
|
| 497 | + if ($payment_removed) { |
|
| 498 | 498 | |
| 499 | 499 | $this->payment_ids = $new_payment_ids; |
| 500 | 500 | |
| 501 | - if ( $update_stats ) { |
|
| 501 | + if ($update_stats) { |
|
| 502 | 502 | // We removed this payment successfully, decrement the stats |
| 503 | - $payment_amount = give_get_payment_amount( $payment_id ); |
|
| 503 | + $payment_amount = give_get_payment_amount($payment_id); |
|
| 504 | 504 | |
| 505 | - if ( ! empty( $payment_amount ) ) { |
|
| 506 | - $this->decrease_value( $payment_amount ); |
|
| 505 | + if ( ! empty($payment_amount)) { |
|
| 506 | + $this->decrease_value($payment_amount); |
|
| 507 | 507 | } |
| 508 | 508 | |
| 509 | 509 | $this->decrease_purchase_count(); |
@@ -520,7 +520,7 @@ discard block |
||
| 520 | 520 | * @param int $payment_id Payment id. |
| 521 | 521 | * @param int $customer_id Customer id. |
| 522 | 522 | */ |
| 523 | - do_action( 'give_customer_post_remove_payment', $payment_removed, $payment_id, $this->id ); |
|
| 523 | + do_action('give_customer_post_remove_payment', $payment_removed, $payment_id, $this->id); |
|
| 524 | 524 | |
| 525 | 525 | return $payment_removed; |
| 526 | 526 | |
@@ -536,10 +536,10 @@ discard block |
||
| 536 | 536 | * |
| 537 | 537 | * @return int The donation count. |
| 538 | 538 | */ |
| 539 | - public function increase_purchase_count( $count = 1 ) { |
|
| 539 | + public function increase_purchase_count($count = 1) { |
|
| 540 | 540 | |
| 541 | 541 | // Make sure it's numeric and not negative. |
| 542 | - if ( ! is_numeric( $count ) || $count != absint( $count ) ) { |
|
| 542 | + if ( ! is_numeric($count) || $count != absint($count)) { |
|
| 543 | 543 | return false; |
| 544 | 544 | } |
| 545 | 545 | |
@@ -553,9 +553,9 @@ discard block |
||
| 553 | 553 | * @param int $count The number to increase by. |
| 554 | 554 | * @param int $customer_id Customer id. |
| 555 | 555 | */ |
| 556 | - do_action( 'give_customer_pre_increase_purchase_count', $count, $this->id ); |
|
| 556 | + do_action('give_customer_pre_increase_purchase_count', $count, $this->id); |
|
| 557 | 557 | |
| 558 | - if ( $this->update( array( 'purchase_count' => $new_total ) ) ) { |
|
| 558 | + if ($this->update(array('purchase_count' => $new_total))) { |
|
| 559 | 559 | $this->purchase_count = $new_total; |
| 560 | 560 | } |
| 561 | 561 | |
@@ -568,7 +568,7 @@ discard block |
||
| 568 | 568 | * @param int $count The number increased by. |
| 569 | 569 | * @param int $customer_id Customer id. |
| 570 | 570 | */ |
| 571 | - do_action( 'give_customer_post_increase_purchase_count', $this->purchase_count, $count, $this->id ); |
|
| 571 | + do_action('give_customer_post_increase_purchase_count', $this->purchase_count, $count, $this->id); |
|
| 572 | 572 | |
| 573 | 573 | return $this->purchase_count; |
| 574 | 574 | } |
@@ -583,16 +583,16 @@ discard block |
||
| 583 | 583 | * |
| 584 | 584 | * @return mixed If successful, the new count, otherwise false. |
| 585 | 585 | */ |
| 586 | - public function decrease_purchase_count( $count = 1 ) { |
|
| 586 | + public function decrease_purchase_count($count = 1) { |
|
| 587 | 587 | |
| 588 | 588 | // Make sure it's numeric and not negative |
| 589 | - if ( ! is_numeric( $count ) || $count != absint( $count ) ) { |
|
| 589 | + if ( ! is_numeric($count) || $count != absint($count)) { |
|
| 590 | 590 | return false; |
| 591 | 591 | } |
| 592 | 592 | |
| 593 | 593 | $new_total = (int) $this->purchase_count - (int) $count; |
| 594 | 594 | |
| 595 | - if ( $new_total < 0 ) { |
|
| 595 | + if ($new_total < 0) { |
|
| 596 | 596 | $new_total = 0; |
| 597 | 597 | } |
| 598 | 598 | |
@@ -604,9 +604,9 @@ discard block |
||
| 604 | 604 | * @param int $count The number to decrease by. |
| 605 | 605 | * @param int $customer_id Customer id. |
| 606 | 606 | */ |
| 607 | - do_action( 'give_customer_pre_decrease_purchase_count', $count, $this->id ); |
|
| 607 | + do_action('give_customer_pre_decrease_purchase_count', $count, $this->id); |
|
| 608 | 608 | |
| 609 | - if ( $this->update( array( 'purchase_count' => $new_total ) ) ) { |
|
| 609 | + if ($this->update(array('purchase_count' => $new_total))) { |
|
| 610 | 610 | $this->purchase_count = $new_total; |
| 611 | 611 | } |
| 612 | 612 | |
@@ -619,7 +619,7 @@ discard block |
||
| 619 | 619 | * @param int $count The number decreased by. |
| 620 | 620 | * @param int $customer_id Customer id. |
| 621 | 621 | */ |
| 622 | - do_action( 'give_customer_post_decrease_purchase_count', $this->purchase_count, $count, $this->id ); |
|
| 622 | + do_action('give_customer_post_decrease_purchase_count', $this->purchase_count, $count, $this->id); |
|
| 623 | 623 | |
| 624 | 624 | return $this->purchase_count; |
| 625 | 625 | } |
@@ -634,9 +634,9 @@ discard block |
||
| 634 | 634 | * |
| 635 | 635 | * @return mixed If successful, the new value, otherwise false. |
| 636 | 636 | */ |
| 637 | - public function increase_value( $value = 0.00 ) { |
|
| 637 | + public function increase_value($value = 0.00) { |
|
| 638 | 638 | |
| 639 | - $new_value = floatval( $this->purchase_value ) + $value; |
|
| 639 | + $new_value = floatval($this->purchase_value) + $value; |
|
| 640 | 640 | |
| 641 | 641 | /** |
| 642 | 642 | * Fires before increasing customer lifetime value. |
@@ -646,9 +646,9 @@ discard block |
||
| 646 | 646 | * @param float $value The value to increase by. |
| 647 | 647 | * @param int $customer_id Customer id. |
| 648 | 648 | */ |
| 649 | - do_action( 'give_customer_pre_increase_value', $value, $this->id ); |
|
| 649 | + do_action('give_customer_pre_increase_value', $value, $this->id); |
|
| 650 | 650 | |
| 651 | - if ( $this->update( array( 'purchase_value' => $new_value ) ) ) { |
|
| 651 | + if ($this->update(array('purchase_value' => $new_value))) { |
|
| 652 | 652 | $this->purchase_value = $new_value; |
| 653 | 653 | } |
| 654 | 654 | |
@@ -661,7 +661,7 @@ discard block |
||
| 661 | 661 | * @param float $value The value increased by. |
| 662 | 662 | * @param int $customer_id Customer id. |
| 663 | 663 | */ |
| 664 | - do_action( 'give_customer_post_increase_value', $this->purchase_value, $value, $this->id ); |
|
| 664 | + do_action('give_customer_post_increase_value', $this->purchase_value, $value, $this->id); |
|
| 665 | 665 | |
| 666 | 666 | return $this->purchase_value; |
| 667 | 667 | } |
@@ -676,11 +676,11 @@ discard block |
||
| 676 | 676 | * |
| 677 | 677 | * @return mixed If successful, the new value, otherwise false. |
| 678 | 678 | */ |
| 679 | - public function decrease_value( $value = 0.00 ) { |
|
| 679 | + public function decrease_value($value = 0.00) { |
|
| 680 | 680 | |
| 681 | - $new_value = floatval( $this->purchase_value ) - $value; |
|
| 681 | + $new_value = floatval($this->purchase_value) - $value; |
|
| 682 | 682 | |
| 683 | - if ( $new_value < 0 ) { |
|
| 683 | + if ($new_value < 0) { |
|
| 684 | 684 | $new_value = 0.00; |
| 685 | 685 | } |
| 686 | 686 | |
@@ -692,9 +692,9 @@ discard block |
||
| 692 | 692 | * @param float $value The value to decrease by. |
| 693 | 693 | * @param int $customer_id Customer id. |
| 694 | 694 | */ |
| 695 | - do_action( 'give_customer_pre_decrease_value', $value, $this->id ); |
|
| 695 | + do_action('give_customer_pre_decrease_value', $value, $this->id); |
|
| 696 | 696 | |
| 697 | - if ( $this->update( array( 'purchase_value' => $new_value ) ) ) { |
|
| 697 | + if ($this->update(array('purchase_value' => $new_value))) { |
|
| 698 | 698 | $this->purchase_value = $new_value; |
| 699 | 699 | } |
| 700 | 700 | |
@@ -707,7 +707,7 @@ discard block |
||
| 707 | 707 | * @param float $value The value decreased by. |
| 708 | 708 | * @param int $customer_id Customer id. |
| 709 | 709 | */ |
| 710 | - do_action( 'give_customer_post_decrease_value', $this->purchase_value, $value, $this->id ); |
|
| 710 | + do_action('give_customer_post_decrease_value', $this->purchase_value, $value, $this->id); |
|
| 711 | 711 | |
| 712 | 712 | return $this->purchase_value; |
| 713 | 713 | } |
@@ -726,7 +726,7 @@ discard block |
||
| 726 | 726 | * |
| 727 | 727 | * @return mixed If successful, the new donation stat value, otherwise false. |
| 728 | 728 | */ |
| 729 | - public function update_donation_value( $curr_amount, $new_amount ) { |
|
| 729 | + public function update_donation_value($curr_amount, $new_amount) { |
|
| 730 | 730 | /** |
| 731 | 731 | * Payment total difference value can be: |
| 732 | 732 | * zero (in case amount not change) |
@@ -736,13 +736,13 @@ discard block |
||
| 736 | 736 | $payment_total_diff = $new_amount - $curr_amount; |
| 737 | 737 | |
| 738 | 738 | // We do not need to update donation stat if donation did not change. |
| 739 | - if( ! $payment_total_diff ) { |
|
| 739 | + if ( ! $payment_total_diff) { |
|
| 740 | 740 | return false; |
| 741 | 741 | } |
| 742 | 742 | |
| 743 | 743 | |
| 744 | - if( $payment_total_diff > 0 ) { |
|
| 745 | - $this->increase_value( $payment_total_diff ); |
|
| 744 | + if ($payment_total_diff > 0) { |
|
| 745 | + $this->increase_value($payment_total_diff); |
|
| 746 | 746 | } else { |
| 747 | 747 | // Pass payment total difference as +ve value to decrease amount from user lifetime stat. |
| 748 | 748 | $this->decrease_value( -$payment_total_diff ); |
@@ -762,15 +762,15 @@ discard block |
||
| 762 | 762 | * |
| 763 | 763 | * @return array The notes requested. |
| 764 | 764 | */ |
| 765 | - public function get_notes( $length = 20, $paged = 1 ) { |
|
| 765 | + public function get_notes($length = 20, $paged = 1) { |
|
| 766 | 766 | |
| 767 | - $length = is_numeric( $length ) ? $length : 20; |
|
| 768 | - $offset = is_numeric( $paged ) && $paged != 1 ? ( ( absint( $paged ) - 1 ) * $length ) : 0; |
|
| 767 | + $length = is_numeric($length) ? $length : 20; |
|
| 768 | + $offset = is_numeric($paged) && $paged != 1 ? ((absint($paged) - 1) * $length) : 0; |
|
| 769 | 769 | |
| 770 | 770 | $all_notes = $this->get_raw_notes(); |
| 771 | - $notes_array = array_reverse( array_filter( explode( "\n\n", $all_notes ) ) ); |
|
| 771 | + $notes_array = array_reverse(array_filter(explode("\n\n", $all_notes))); |
|
| 772 | 772 | |
| 773 | - $desired_notes = array_slice( $notes_array, $offset, $length ); |
|
| 773 | + $desired_notes = array_slice($notes_array, $offset, $length); |
|
| 774 | 774 | |
| 775 | 775 | return $desired_notes; |
| 776 | 776 | |
@@ -787,9 +787,9 @@ discard block |
||
| 787 | 787 | public function get_notes_count() { |
| 788 | 788 | |
| 789 | 789 | $all_notes = $this->get_raw_notes(); |
| 790 | - $notes_array = array_reverse( array_filter( explode( "\n\n", $all_notes ) ) ); |
|
| 790 | + $notes_array = array_reverse(array_filter(explode("\n\n", $all_notes))); |
|
| 791 | 791 | |
| 792 | - return count( $notes_array ); |
|
| 792 | + return count($notes_array); |
|
| 793 | 793 | |
| 794 | 794 | } |
| 795 | 795 | |
@@ -803,22 +803,22 @@ discard block |
||
| 803 | 803 | * |
| 804 | 804 | * @return string|boolean The new note if added successfully, false otherwise. |
| 805 | 805 | */ |
| 806 | - public function add_note( $note = '' ) { |
|
| 806 | + public function add_note($note = '') { |
|
| 807 | 807 | |
| 808 | - $note = trim( $note ); |
|
| 809 | - if ( empty( $note ) ) { |
|
| 808 | + $note = trim($note); |
|
| 809 | + if (empty($note)) { |
|
| 810 | 810 | return false; |
| 811 | 811 | } |
| 812 | 812 | |
| 813 | 813 | $notes = $this->get_raw_notes(); |
| 814 | 814 | |
| 815 | - if ( empty( $notes ) ) { |
|
| 815 | + if (empty($notes)) { |
|
| 816 | 816 | $notes = ''; |
| 817 | 817 | } |
| 818 | 818 | |
| 819 | - $note_string = date_i18n( 'F j, Y H:i:s', current_time( 'timestamp' ) ) . ' - ' . $note; |
|
| 820 | - $new_note = apply_filters( 'give_customer_add_note_string', $note_string ); |
|
| 821 | - $notes .= "\n\n" . $new_note; |
|
| 819 | + $note_string = date_i18n('F j, Y H:i:s', current_time('timestamp')).' - '.$note; |
|
| 820 | + $new_note = apply_filters('give_customer_add_note_string', $note_string); |
|
| 821 | + $notes .= "\n\n".$new_note; |
|
| 822 | 822 | |
| 823 | 823 | /** |
| 824 | 824 | * Fires before customer note added. |
@@ -828,11 +828,11 @@ discard block |
||
| 828 | 828 | * @param string $new_note New note to add. |
| 829 | 829 | * @param int $customer_id Customer id. |
| 830 | 830 | */ |
| 831 | - do_action( 'give_customer_pre_add_note', $new_note, $this->id ); |
|
| 831 | + do_action('give_customer_pre_add_note', $new_note, $this->id); |
|
| 832 | 832 | |
| 833 | - $updated = $this->update( array( 'notes' => $notes ) ); |
|
| 833 | + $updated = $this->update(array('notes' => $notes)); |
|
| 834 | 834 | |
| 835 | - if ( $updated ) { |
|
| 835 | + if ($updated) { |
|
| 836 | 836 | $this->notes = $this->get_notes(); |
| 837 | 837 | } |
| 838 | 838 | |
@@ -845,7 +845,7 @@ discard block |
||
| 845 | 845 | * @param string $new_note New note added. |
| 846 | 846 | * @param int $customer_id Customer id. |
| 847 | 847 | */ |
| 848 | - do_action( 'give_customer_post_add_note', $this->notes, $new_note, $this->id ); |
|
| 848 | + do_action('give_customer_post_add_note', $this->notes, $new_note, $this->id); |
|
| 849 | 849 | |
| 850 | 850 | // Return the formatted note, so we can test, as well as update any displays |
| 851 | 851 | return $new_note; |
@@ -862,7 +862,7 @@ discard block |
||
| 862 | 862 | */ |
| 863 | 863 | private function get_raw_notes() { |
| 864 | 864 | |
| 865 | - $all_notes = $this->db->get_column( 'notes', $this->id ); |
|
| 865 | + $all_notes = $this->db->get_column('notes', $this->id); |
|
| 866 | 866 | |
| 867 | 867 | return $all_notes; |
| 868 | 868 | |
@@ -879,8 +879,8 @@ discard block |
||
| 879 | 879 | * |
| 880 | 880 | * @return mixed Will be an array if $single is false. Will be value of meta data field if $single is true. |
| 881 | 881 | */ |
| 882 | - public function get_meta( $meta_key = '', $single = true ) { |
|
| 883 | - return Give()->customer_meta->get_meta( $this->id, $meta_key, $single ); |
|
| 882 | + public function get_meta($meta_key = '', $single = true) { |
|
| 883 | + return Give()->customer_meta->get_meta($this->id, $meta_key, $single); |
|
| 884 | 884 | } |
| 885 | 885 | |
| 886 | 886 | /** |
@@ -895,8 +895,8 @@ discard block |
||
| 895 | 895 | * |
| 896 | 896 | * @return bool False for failure. True for success. |
| 897 | 897 | */ |
| 898 | - public function add_meta( $meta_key = '', $meta_value, $unique = false ) { |
|
| 899 | - return Give()->customer_meta->add_meta( $this->id, $meta_key, $meta_value, $unique ); |
|
| 898 | + public function add_meta($meta_key = '', $meta_value, $unique = false) { |
|
| 899 | + return Give()->customer_meta->add_meta($this->id, $meta_key, $meta_value, $unique); |
|
| 900 | 900 | } |
| 901 | 901 | |
| 902 | 902 | /** |
@@ -911,8 +911,8 @@ discard block |
||
| 911 | 911 | * |
| 912 | 912 | * @return bool False on failure, true if success. |
| 913 | 913 | */ |
| 914 | - public function update_meta( $meta_key = '', $meta_value, $prev_value = '' ) { |
|
| 915 | - return Give()->customer_meta->update_meta( $this->id, $meta_key, $meta_value, $prev_value ); |
|
| 914 | + public function update_meta($meta_key = '', $meta_value, $prev_value = '') { |
|
| 915 | + return Give()->customer_meta->update_meta($this->id, $meta_key, $meta_value, $prev_value); |
|
| 916 | 916 | } |
| 917 | 917 | |
| 918 | 918 | /** |
@@ -926,8 +926,8 @@ discard block |
||
| 926 | 926 | * |
| 927 | 927 | * @return bool False for failure. True for success. |
| 928 | 928 | */ |
| 929 | - public function delete_meta( $meta_key = '', $meta_value = '' ) { |
|
| 930 | - return Give()->customer_meta->delete_meta( $this->id, $meta_key, $meta_value ); |
|
| 929 | + public function delete_meta($meta_key = '', $meta_value = '') { |
|
| 930 | + return Give()->customer_meta->delete_meta($this->id, $meta_key, $meta_value); |
|
| 931 | 931 | } |
| 932 | 932 | |
| 933 | 933 | /** |
@@ -940,51 +940,51 @@ discard block |
||
| 940 | 940 | * |
| 941 | 941 | * @return array The sanitized data, based off column defaults. |
| 942 | 942 | */ |
| 943 | - private function sanitize_columns( $data ) { |
|
| 943 | + private function sanitize_columns($data) { |
|
| 944 | 944 | |
| 945 | 945 | $columns = $this->db->get_columns(); |
| 946 | 946 | $default_values = $this->db->get_column_defaults(); |
| 947 | 947 | |
| 948 | - foreach ( $columns as $key => $type ) { |
|
| 948 | + foreach ($columns as $key => $type) { |
|
| 949 | 949 | |
| 950 | 950 | // Only sanitize data that we were provided |
| 951 | - if ( ! array_key_exists( $key, $data ) ) { |
|
| 951 | + if ( ! array_key_exists($key, $data)) { |
|
| 952 | 952 | continue; |
| 953 | 953 | } |
| 954 | 954 | |
| 955 | - switch ( $type ) { |
|
| 955 | + switch ($type) { |
|
| 956 | 956 | |
| 957 | 957 | case '%s': |
| 958 | - if ( 'email' == $key ) { |
|
| 959 | - $data[ $key ] = sanitize_email( $data[ $key ] ); |
|
| 960 | - } elseif ( 'notes' == $key ) { |
|
| 961 | - $data[ $key ] = strip_tags( $data[ $key ] ); |
|
| 958 | + if ('email' == $key) { |
|
| 959 | + $data[$key] = sanitize_email($data[$key]); |
|
| 960 | + } elseif ('notes' == $key) { |
|
| 961 | + $data[$key] = strip_tags($data[$key]); |
|
| 962 | 962 | } else { |
| 963 | - $data[ $key ] = sanitize_text_field( $data[ $key ] ); |
|
| 963 | + $data[$key] = sanitize_text_field($data[$key]); |
|
| 964 | 964 | } |
| 965 | 965 | break; |
| 966 | 966 | |
| 967 | 967 | case '%d': |
| 968 | - if ( ! is_numeric( $data[ $key ] ) || (int) $data[ $key ] !== absint( $data[ $key ] ) ) { |
|
| 969 | - $data[ $key ] = $default_values[ $key ]; |
|
| 968 | + if ( ! is_numeric($data[$key]) || (int) $data[$key] !== absint($data[$key])) { |
|
| 969 | + $data[$key] = $default_values[$key]; |
|
| 970 | 970 | } else { |
| 971 | - $data[ $key ] = absint( $data[ $key ] ); |
|
| 971 | + $data[$key] = absint($data[$key]); |
|
| 972 | 972 | } |
| 973 | 973 | break; |
| 974 | 974 | |
| 975 | 975 | case '%f': |
| 976 | 976 | // Convert what was given to a float |
| 977 | - $value = floatval( $data[ $key ] ); |
|
| 977 | + $value = floatval($data[$key]); |
|
| 978 | 978 | |
| 979 | - if ( ! is_float( $value ) ) { |
|
| 980 | - $data[ $key ] = $default_values[ $key ]; |
|
| 979 | + if ( ! is_float($value)) { |
|
| 980 | + $data[$key] = $default_values[$key]; |
|
| 981 | 981 | } else { |
| 982 | - $data[ $key ] = $value; |
|
| 982 | + $data[$key] = $value; |
|
| 983 | 983 | } |
| 984 | 984 | break; |
| 985 | 985 | |
| 986 | 986 | default: |
| 987 | - $data[ $key ] = sanitize_text_field( $data[ $key ] ); |
|
| 987 | + $data[$key] = sanitize_text_field($data[$key]); |
|
| 988 | 988 | break; |
| 989 | 989 | |
| 990 | 990 | } |
@@ -1002,33 +1002,33 @@ discard block |
||
| 1002 | 1002 | * @param bool $primary Allows setting the email added as the primary |
| 1003 | 1003 | * @return bool If the email was added successfully |
| 1004 | 1004 | */ |
| 1005 | - public function add_email( $email = '', $primary = false ) { |
|
| 1006 | - if( ! is_email( $email ) ) { |
|
| 1005 | + public function add_email($email = '', $primary = false) { |
|
| 1006 | + if ( ! is_email($email)) { |
|
| 1007 | 1007 | return false; |
| 1008 | 1008 | } |
| 1009 | - $existing = new Give_Customer( $email ); |
|
| 1009 | + $existing = new Give_Customer($email); |
|
| 1010 | 1010 | |
| 1011 | - if( $existing->id > 0 ) { |
|
| 1011 | + if ($existing->id > 0) { |
|
| 1012 | 1012 | // Email address already belongs to another customer |
| 1013 | 1013 | return false; |
| 1014 | 1014 | } |
| 1015 | 1015 | |
| 1016 | - if ( email_exists( $email ) ) { |
|
| 1017 | - $user = get_user_by( 'email', $email ); |
|
| 1018 | - if ( $user->ID != $this->user_id ) { |
|
| 1016 | + if (email_exists($email)) { |
|
| 1017 | + $user = get_user_by('email', $email); |
|
| 1018 | + if ($user->ID != $this->user_id) { |
|
| 1019 | 1019 | return false; |
| 1020 | 1020 | } |
| 1021 | 1021 | } |
| 1022 | 1022 | |
| 1023 | - do_action( 'give_donor_pre_add_email', $email, $this->id, $this ); |
|
| 1023 | + do_action('give_donor_pre_add_email', $email, $this->id, $this); |
|
| 1024 | 1024 | |
| 1025 | 1025 | // Add is used to ensure duplicate emails are not added |
| 1026 | - $ret = (bool) $this->add_meta( 'additional_email', $email ); |
|
| 1026 | + $ret = (bool) $this->add_meta('additional_email', $email); |
|
| 1027 | 1027 | |
| 1028 | - do_action( 'give_donor_post_add_email', $email, $this->id, $this ); |
|
| 1028 | + do_action('give_donor_post_add_email', $email, $this->id, $this); |
|
| 1029 | 1029 | |
| 1030 | - if ( $ret && true === $primary ) { |
|
| 1031 | - $this->set_primary_email( $email ); |
|
| 1030 | + if ($ret && true === $primary) { |
|
| 1031 | + $this->set_primary_email($email); |
|
| 1032 | 1032 | } |
| 1033 | 1033 | |
| 1034 | 1034 | return $ret; |
@@ -1042,16 +1042,16 @@ discard block |
||
| 1042 | 1042 | * @param string $email The email address to remove from the customer |
| 1043 | 1043 | * @return bool If the email was removeed successfully |
| 1044 | 1044 | */ |
| 1045 | - public function remove_email( $email = '' ) { |
|
| 1046 | - if( ! is_email( $email ) ) { |
|
| 1045 | + public function remove_email($email = '') { |
|
| 1046 | + if ( ! is_email($email)) { |
|
| 1047 | 1047 | return false; |
| 1048 | 1048 | } |
| 1049 | 1049 | |
| 1050 | - do_action( 'give_donor_pre_remove_email', $email, $this->id, $this ); |
|
| 1050 | + do_action('give_donor_pre_remove_email', $email, $this->id, $this); |
|
| 1051 | 1051 | |
| 1052 | - $ret = (bool) $this->delete_meta( 'additional_email', $email ); |
|
| 1052 | + $ret = (bool) $this->delete_meta('additional_email', $email); |
|
| 1053 | 1053 | |
| 1054 | - do_action( 'give_donor_post_remove_email', $email, $this->id, $this ); |
|
| 1054 | + do_action('give_donor_post_remove_email', $email, $this->id, $this); |
|
| 1055 | 1055 | |
| 1056 | 1056 | return $ret; |
| 1057 | 1057 | } |
@@ -1065,16 +1065,16 @@ discard block |
||
| 1065 | 1065 | * @param string $new_primary_email The email address to remove from the customer |
| 1066 | 1066 | * @return bool If the email was set as primary successfully |
| 1067 | 1067 | */ |
| 1068 | - public function set_primary_email( $new_primary_email = '' ) { |
|
| 1069 | - if( ! is_email( $new_primary_email ) ) { |
|
| 1068 | + public function set_primary_email($new_primary_email = '') { |
|
| 1069 | + if ( ! is_email($new_primary_email)) { |
|
| 1070 | 1070 | return false; |
| 1071 | 1071 | } |
| 1072 | 1072 | |
| 1073 | - do_action( 'give_donor_pre_set_primary_email', $new_primary_email, $this->id, $this ); |
|
| 1073 | + do_action('give_donor_pre_set_primary_email', $new_primary_email, $this->id, $this); |
|
| 1074 | 1074 | |
| 1075 | - $existing = new Give_Customer( $new_primary_email ); |
|
| 1075 | + $existing = new Give_Customer($new_primary_email); |
|
| 1076 | 1076 | |
| 1077 | - if( $existing->id > 0 && (int) $existing->id !== (int) $this->id ) { |
|
| 1077 | + if ($existing->id > 0 && (int) $existing->id !== (int) $this->id) { |
|
| 1078 | 1078 | // This email belongs to another customer |
| 1079 | 1079 | return false; |
| 1080 | 1080 | } |
@@ -1082,21 +1082,21 @@ discard block |
||
| 1082 | 1082 | $old_email = $this->email; |
| 1083 | 1083 | |
| 1084 | 1084 | // Update customer record with new email |
| 1085 | - $update = $this->update( array( 'email' => $new_primary_email ) ); |
|
| 1085 | + $update = $this->update(array('email' => $new_primary_email)); |
|
| 1086 | 1086 | |
| 1087 | 1087 | // Remove new primary from list of additional emails |
| 1088 | - $remove = $this->remove_email( $new_primary_email ); |
|
| 1088 | + $remove = $this->remove_email($new_primary_email); |
|
| 1089 | 1089 | |
| 1090 | 1090 | // Add old email to additional emails list |
| 1091 | - $add = $this->add_email( $old_email ); |
|
| 1091 | + $add = $this->add_email($old_email); |
|
| 1092 | 1092 | |
| 1093 | 1093 | $ret = $update && $remove && $add; |
| 1094 | 1094 | |
| 1095 | - if( $ret ) { |
|
| 1095 | + if ($ret) { |
|
| 1096 | 1096 | $this->email = $new_primary_email; |
| 1097 | 1097 | } |
| 1098 | 1098 | |
| 1099 | - do_action( 'give_donor_post_set_primary_email', $new_primary_email, $this->id, $this ); |
|
| 1099 | + do_action('give_donor_post_set_primary_email', $new_primary_email, $this->id, $this); |
|
| 1100 | 1100 | |
| 1101 | 1101 | return $ret; |
| 1102 | 1102 | } |
@@ -10,7 +10,7 @@ |
||
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | 12 | // Exit if accessed directly |
| 13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 13 | +if ( ! defined('ABSPATH')) { |
|
| 14 | 14 | exit; |
| 15 | 15 | } |
| 16 | 16 | |