@@ -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 | |
@@ -78,15 +78,15 @@ discard block |
||
78 | 78 | * |
79 | 79 | * @since 1.0 |
80 | 80 | */ |
81 | - public function __construct( $_data ) { |
|
81 | + public function __construct($_data) { |
|
82 | 82 | |
83 | 83 | $this->data = $_data; |
84 | 84 | |
85 | 85 | // Generate unique ID |
86 | - $this->id = md5( rand() ); |
|
86 | + $this->id = md5(rand()); |
|
87 | 87 | |
88 | 88 | // Setup default options; |
89 | - $this->options = apply_filters( 'give_graph_args', array( |
|
89 | + $this->options = apply_filters('give_graph_args', array( |
|
90 | 90 | 'y_mode' => null, |
91 | 91 | 'x_mode' => null, |
92 | 92 | 'y_decimals' => 0, |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | 'bars' => true, |
104 | 104 | 'lines' => false, |
105 | 105 | 'points' => true |
106 | - ) ); |
|
106 | + )); |
|
107 | 107 | |
108 | 108 | } |
109 | 109 | |
@@ -115,8 +115,8 @@ discard block |
||
115 | 115 | * |
116 | 116 | * @since 1.0 |
117 | 117 | */ |
118 | - public function set( $key, $value ) { |
|
119 | - $this->options[ $key ] = $value; |
|
118 | + public function set($key, $value) { |
|
119 | + $this->options[$key] = $value; |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | /** |
@@ -126,8 +126,8 @@ discard block |
||
126 | 126 | * |
127 | 127 | * @since 1.0 |
128 | 128 | */ |
129 | - public function get( $key ) { |
|
130 | - return isset( $this->options[ $key ] ) ? $this->options[ $key ] : false; |
|
129 | + public function get($key) { |
|
130 | + return isset($this->options[$key]) ? $this->options[$key] : false; |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | /** |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | * @since 1.0 |
137 | 137 | */ |
138 | 138 | public function get_data() { |
139 | - return apply_filters( 'give_get_graph_data', $this->data, $this ); |
|
139 | + return apply_filters('give_get_graph_data', $this->data, $this); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | /** |
@@ -146,19 +146,19 @@ discard block |
||
146 | 146 | */ |
147 | 147 | public function load_scripts() { |
148 | 148 | // Use minified libraries if SCRIPT_DEBUG is turned off |
149 | - $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min'; |
|
149 | + $suffix = (defined('SCRIPT_DEBUG') && SCRIPT_DEBUG) ? '' : '.min'; |
|
150 | 150 | |
151 | - wp_register_script( 'jquery-flot-orderbars', GIVE_PLUGIN_URL . 'assets/js/plugins/jquery.flot.orderBars' . $suffix . '.js', array('jquery-flot'), GIVE_VERSION ); |
|
152 | - wp_enqueue_script( 'jquery-flot-orderbars' ); |
|
151 | + wp_register_script('jquery-flot-orderbars', GIVE_PLUGIN_URL.'assets/js/plugins/jquery.flot.orderBars'.$suffix.'.js', array('jquery-flot'), GIVE_VERSION); |
|
152 | + wp_enqueue_script('jquery-flot-orderbars'); |
|
153 | 153 | |
154 | - wp_register_script( 'jquery-flot-time', GIVE_PLUGIN_URL . 'assets/js/plugins/jquery.flot.time' . $suffix . '.js', array('jquery-flot'), GIVE_VERSION ); |
|
155 | - wp_enqueue_script( 'jquery-flot-time' ); |
|
154 | + wp_register_script('jquery-flot-time', GIVE_PLUGIN_URL.'assets/js/plugins/jquery.flot.time'.$suffix.'.js', array('jquery-flot'), GIVE_VERSION); |
|
155 | + wp_enqueue_script('jquery-flot-time'); |
|
156 | 156 | |
157 | - wp_register_script( 'jquery-flot-resize', GIVE_PLUGIN_URL . 'assets/js/plugins/jquery.flot.resize' . $suffix . '.js', array('jquery-flot'), GIVE_VERSION ); |
|
158 | - wp_enqueue_script( 'jquery-flot-resize' ); |
|
157 | + wp_register_script('jquery-flot-resize', GIVE_PLUGIN_URL.'assets/js/plugins/jquery.flot.resize'.$suffix.'.js', array('jquery-flot'), GIVE_VERSION); |
|
158 | + wp_enqueue_script('jquery-flot-resize'); |
|
159 | 159 | |
160 | - wp_register_script( 'jquery-flot', GIVE_PLUGIN_URL . 'assets/js/plugins/jquery.flot' . $suffix . '.js', false, GIVE_VERSION ); |
|
161 | - wp_enqueue_script( 'jquery-flot' ); |
|
160 | + wp_register_script('jquery-flot', GIVE_PLUGIN_URL.'assets/js/plugins/jquery.flot'.$suffix.'.js', false, GIVE_VERSION); |
|
161 | + wp_enqueue_script('jquery-flot'); |
|
162 | 162 | |
163 | 163 | } |
164 | 164 | |
@@ -185,13 +185,13 @@ discard block |
||
185 | 185 | [ |
186 | 186 | <?php |
187 | 187 | $order = 0; |
188 | - foreach( $this->get_data() as $label => $data ) : |
|
188 | + foreach ($this->get_data() as $label => $data) : |
|
189 | 189 | ?> |
190 | 190 | { |
191 | - label : "<?php echo esc_attr( $label ); ?>", |
|
192 | - id : "<?php echo sanitize_key( $label ); ?>", |
|
191 | + label : "<?php echo esc_attr($label); ?>", |
|
192 | + id : "<?php echo sanitize_key($label); ?>", |
|
193 | 193 | // data format is: [ point on x, value on y ] |
194 | - data : [<?php foreach( $data as $point ) { echo '[' . implode( ',', $point ) . '],'; } ?>], |
|
194 | + data : [<?php foreach ($data as $point) { echo '['.implode(',', $point).'],'; } ?>], |
|
195 | 195 | points: { |
196 | 196 | show: <?php echo $this->options['points'] ? 'true' : 'false'; ?>, |
197 | 197 | }, |
@@ -206,7 +206,7 @@ discard block |
||
206 | 206 | fill : true, |
207 | 207 | fillColor: {colors: [{opacity: 0.4}, {opacity: 0.1}]} |
208 | 208 | }, |
209 | - <?php if( $this->options[ 'multiple_y_axes' ] ) : ?> |
|
209 | + <?php if ($this->options['multiple_y_axes']) : ?> |
|
210 | 210 | yaxis : <?php echo $yaxis_count; ?> |
211 | 211 | <?php endif; ?> |
212 | 212 | |
@@ -220,10 +220,10 @@ discard block |
||
220 | 220 | grid: { |
221 | 221 | show : true, |
222 | 222 | aboveData : false, |
223 | - color : "<?php echo $this->options[ 'color' ]; ?>", |
|
224 | - backgroundColor: "<?php echo $this->options[ 'bgcolor' ]; ?>", |
|
225 | - borderColor : "<?php echo $this->options[ 'bordercolor' ]; ?>", |
|
226 | - borderWidth : <?php echo absint( $this->options[ 'borderwidth' ] ); ?>, |
|
223 | + color : "<?php echo $this->options['color']; ?>", |
|
224 | + backgroundColor: "<?php echo $this->options['bgcolor']; ?>", |
|
225 | + borderColor : "<?php echo $this->options['bordercolor']; ?>", |
|
226 | + borderWidth : <?php echo absint($this->options['borderwidth']); ?>, |
|
227 | 227 | clickable : false, |
228 | 228 | hoverable : true |
229 | 229 | }, |
@@ -234,7 +234,7 @@ discard block |
||
234 | 234 | mode : "<?php echo $this->options['x_mode']; ?>", |
235 | 235 | timeFormat : "<?php echo $this->options['x_mode'] == 'time' ? $this->options['time_format'] : ''; ?>", |
236 | 236 | tickSize : "<?php echo $this->options['x_mode'] == 'time' ? '' : 1; ?>", |
237 | - <?php if( $this->options['x_mode'] != 'time' ) : ?> |
|
237 | + <?php if ($this->options['x_mode'] != 'time') : ?> |
|
238 | 238 | tickDecimals: <?php echo $this->options['x_decimals']; ?> |
239 | 239 | <?php endif; ?> |
240 | 240 | }, |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | min : 0, |
244 | 244 | mode : "<?php echo $this->options['y_mode']; ?>", |
245 | 245 | timeFormat : "<?php echo $this->options['y_mode'] == 'time' ? $this->options['time_format'] : ''; ?>", |
246 | - <?php if( $this->options['y_mode'] != 'time' ) : ?> |
|
246 | + <?php if ($this->options['y_mode'] != 'time') : ?> |
|
247 | 247 | tickDecimals: <?php echo $this->options['y_decimals']; ?> |
248 | 248 | <?php endif; ?> |
249 | 249 | } |
@@ -303,9 +303,9 @@ discard block |
||
303 | 303 | * @since 1.0 |
304 | 304 | */ |
305 | 305 | public function display() { |
306 | - do_action( 'give_before_graph', $this ); |
|
306 | + do_action('give_before_graph', $this); |
|
307 | 307 | echo $this->build_graph(); |
308 | - do_action( 'give_after_graph', $this ); |
|
308 | + do_action('give_after_graph', $this); |
|
309 | 309 | } |
310 | 310 | |
311 | 311 | } |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | |
12 | 12 | |
13 | 13 | // Exit if accessed directly |
14 | -if ( ! defined( 'ABSPATH' ) ) { |
|
14 | +if ( ! defined('ABSPATH')) { |
|
15 | 15 | exit; |
16 | 16 | } |
17 | 17 | |
@@ -26,16 +26,16 @@ discard block |
||
26 | 26 | * |
27 | 27 | * @return array $links |
28 | 28 | */ |
29 | -function give_plugin_action_links( $links, $file ) { |
|
30 | - $settings_link = '<a href="' . admin_url( 'edit.php?post_type=give_forms&page=give-settings' ) . '">' . esc_html__( 'Settings', 'give' ) . '</a>'; |
|
31 | - if ( $file == 'give/give.php' ) { |
|
32 | - array_unshift( $links, $settings_link ); |
|
29 | +function give_plugin_action_links($links, $file) { |
|
30 | + $settings_link = '<a href="'.admin_url('edit.php?post_type=give_forms&page=give-settings').'">'.esc_html__('Settings', 'give').'</a>'; |
|
31 | + if ($file == 'give/give.php') { |
|
32 | + array_unshift($links, $settings_link); |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | return $links; |
36 | 36 | } |
37 | 37 | |
38 | -add_filter( 'plugin_action_links', 'give_plugin_action_links', 10, 2 ); |
|
38 | +add_filter('plugin_action_links', 'give_plugin_action_links', 10, 2); |
|
39 | 39 | |
40 | 40 | |
41 | 41 | /** |
@@ -48,33 +48,33 @@ discard block |
||
48 | 48 | * |
49 | 49 | * @return array $input |
50 | 50 | */ |
51 | -function give_plugin_row_meta( $input, $file ) { |
|
52 | - if ( $file != 'give/give.php' ) { |
|
51 | +function give_plugin_row_meta($input, $file) { |
|
52 | + if ($file != 'give/give.php') { |
|
53 | 53 | return $input; |
54 | 54 | } |
55 | 55 | |
56 | - $give_addons_link = esc_url( add_query_arg( array( |
|
56 | + $give_addons_link = esc_url(add_query_arg(array( |
|
57 | 57 | 'utm_source' => 'plugins-page', |
58 | 58 | 'utm_medium' => 'plugin-row', |
59 | 59 | 'utm_campaign' => 'admin', |
60 | - ), 'https://givewp.com/addons/' ) |
|
60 | + ), 'https://givewp.com/addons/') |
|
61 | 61 | ); |
62 | 62 | |
63 | - $give_docs_link = esc_url( add_query_arg( array( |
|
63 | + $give_docs_link = esc_url(add_query_arg(array( |
|
64 | 64 | 'utm_source' => 'plugins-page', |
65 | 65 | 'utm_medium' => 'plugin-row', |
66 | 66 | 'utm_campaign' => 'admin', |
67 | - ), 'https://givewp.com/documentation/' ) |
|
67 | + ), 'https://givewp.com/documentation/') |
|
68 | 68 | ); |
69 | 69 | |
70 | 70 | $links = array( |
71 | - '<a href="' . $give_docs_link . '" target="_blank">' . esc_html__( 'Documentation', 'give' ) . '</a>', |
|
72 | - '<a href="' . $give_addons_link . '" target="_blank">' . esc_html__( 'Add-ons', 'give' ) . '</a>', |
|
71 | + '<a href="'.$give_docs_link.'" target="_blank">'.esc_html__('Documentation', 'give').'</a>', |
|
72 | + '<a href="'.$give_addons_link.'" target="_blank">'.esc_html__('Add-ons', 'give').'</a>', |
|
73 | 73 | ); |
74 | 74 | |
75 | - $input = array_merge( $input, $links ); |
|
75 | + $input = array_merge($input, $links); |
|
76 | 76 | |
77 | 77 | return $input; |
78 | 78 | } |
79 | 79 | |
80 | -add_filter( 'plugin_row_meta', 'give_plugin_row_meta', 10, 2 ); |
|
80 | +add_filter('plugin_row_meta', 'give_plugin_row_meta', 10, 2); |
@@ -65,7 +65,7 @@ |
||
65 | 65 | * |
66 | 66 | * @since 1.0 |
67 | 67 | * @uses Give_Session::get() |
68 | - * @return mixed array if errors are present, false if none found |
|
68 | + * @return string array if errors are present, false if none found |
|
69 | 69 | */ |
70 | 70 | function give_get_errors() { |
71 | 71 | return Give()->session->get( 'give_errors' ); |
@@ -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 | |
@@ -29,33 +29,33 @@ discard block |
||
29 | 29 | * |
30 | 30 | * @return void |
31 | 31 | */ |
32 | -function give_print_errors( $form_id ) { |
|
32 | +function give_print_errors($form_id) { |
|
33 | 33 | |
34 | 34 | $errors = give_get_errors(); |
35 | 35 | |
36 | - $request_form_id = isset( $_REQUEST['form-id'] ) ? intval( $_REQUEST['form-id'] ) : 0; |
|
36 | + $request_form_id = isset($_REQUEST['form-id']) ? intval($_REQUEST['form-id']) : 0; |
|
37 | 37 | |
38 | 38 | //Sanity checks first: Ensure that gateway returned errors display on the appropriate form |
39 | - if ( ! isset( $_POST['give_ajax'] ) && $request_form_id !== $form_id ) { |
|
39 | + if ( ! isset($_POST['give_ajax']) && $request_form_id !== $form_id) { |
|
40 | 40 | return; |
41 | 41 | } |
42 | 42 | |
43 | - if ( $errors ) { |
|
44 | - $classes = apply_filters( 'give_error_class', array( |
|
43 | + if ($errors) { |
|
44 | + $classes = apply_filters('give_error_class', array( |
|
45 | 45 | 'give_errors' |
46 | - ) ); |
|
47 | - echo '<div class="' . implode( ' ', $classes ) . '">'; |
|
46 | + )); |
|
47 | + echo '<div class="'.implode(' ', $classes).'">'; |
|
48 | 48 | // Loop error codes and display errors |
49 | - foreach ( $errors as $error_id => $error ) { |
|
50 | - echo '<div class="give_error" id="give_error_' . $error_id . '"><p><strong>' . esc_html__( 'Error', 'give' ) . '</strong>: ' . $error . '</p></div>'; |
|
49 | + foreach ($errors as $error_id => $error) { |
|
50 | + echo '<div class="give_error" id="give_error_'.$error_id.'"><p><strong>'.esc_html__('Error', 'give').'</strong>: '.$error.'</p></div>'; |
|
51 | 51 | } |
52 | 52 | echo '</div>'; |
53 | 53 | give_clear_errors(); |
54 | 54 | } |
55 | 55 | } |
56 | 56 | |
57 | -add_action( 'give_purchase_form_before_personal_info', 'give_print_errors' ); |
|
58 | -add_action( 'give_ajax_checkout_errors', 'give_print_errors' ); |
|
57 | +add_action('give_purchase_form_before_personal_info', 'give_print_errors'); |
|
58 | +add_action('give_ajax_checkout_errors', 'give_print_errors'); |
|
59 | 59 | |
60 | 60 | /** |
61 | 61 | * Get Errors |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | * @return mixed array if errors are present, false if none found |
69 | 69 | */ |
70 | 70 | function give_get_errors() { |
71 | - return Give()->session->get( 'give_errors' ); |
|
71 | + return Give()->session->get('give_errors'); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | /** |
@@ -84,13 +84,13 @@ discard block |
||
84 | 84 | * |
85 | 85 | * @return void |
86 | 86 | */ |
87 | -function give_set_error( $error_id, $error_message ) { |
|
87 | +function give_set_error($error_id, $error_message) { |
|
88 | 88 | $errors = give_get_errors(); |
89 | - if ( ! $errors ) { |
|
89 | + if ( ! $errors) { |
|
90 | 90 | $errors = array(); |
91 | 91 | } |
92 | - $errors[ $error_id ] = $error_message; |
|
93 | - Give()->session->set( 'give_errors', $errors ); |
|
92 | + $errors[$error_id] = $error_message; |
|
93 | + Give()->session->set('give_errors', $errors); |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | /** |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | * @return void |
102 | 102 | */ |
103 | 103 | function give_clear_errors() { |
104 | - Give()->session->set( 'give_errors', null ); |
|
104 | + Give()->session->set('give_errors', null); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | /** |
@@ -114,11 +114,11 @@ discard block |
||
114 | 114 | * |
115 | 115 | * @return string |
116 | 116 | */ |
117 | -function give_unset_error( $error_id ) { |
|
117 | +function give_unset_error($error_id) { |
|
118 | 118 | $errors = give_get_errors(); |
119 | - if ( $errors ) { |
|
120 | - unset( $errors[ $error_id ] ); |
|
121 | - Give()->session->set( 'give_errors', $errors ); |
|
119 | + if ($errors) { |
|
120 | + unset($errors[$error_id]); |
|
121 | + Give()->session->set('give_errors', $errors); |
|
122 | 122 | } |
123 | 123 | } |
124 | 124 | |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | * @return void |
130 | 130 | */ |
131 | 131 | function _give_die_handler() { |
132 | - if ( defined( 'GIVE_UNIT_TESTS' ) ) { |
|
132 | + if (defined('GIVE_UNIT_TESTS')) { |
|
133 | 133 | return '_give_die_handler'; |
134 | 134 | } else { |
135 | 135 | die(); |
@@ -144,10 +144,10 @@ discard block |
||
144 | 144 | * @since 1.0 |
145 | 145 | * @return void |
146 | 146 | */ |
147 | -function give_die( $message = '', $title = '', $status = 400 ) { |
|
148 | - add_filter( 'wp_die_ajax_handler', '_give_die_handler', 10, 3 ); |
|
149 | - add_filter( 'wp_die_handler', '_give_die_handler', 10, 3 ); |
|
150 | - wp_die( $message, $title, array( 'response' => $status ) ); |
|
147 | +function give_die($message = '', $title = '', $status = 400) { |
|
148 | + add_filter('wp_die_ajax_handler', '_give_die_handler', 10, 3); |
|
149 | + add_filter('wp_die_handler', '_give_die_handler', 10, 3); |
|
150 | + wp_die($message, $title, array('response' => $status)); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | /** |
@@ -162,10 +162,10 @@ discard block |
||
162 | 162 | * |
163 | 163 | * @return string $error |
164 | 164 | */ |
165 | -function give_output_error( $message, $echo = true, $error_id = 'warning' ) { |
|
166 | - $error = '<div class="give_errors" id="give_error_' . $error_id . '"><p class="give_error give_' . $error_id . '">' . $message . '</p></div>'; |
|
165 | +function give_output_error($message, $echo = true, $error_id = 'warning') { |
|
166 | + $error = '<div class="give_errors" id="give_error_'.$error_id.'"><p class="give_error give_'.$error_id.'">'.$message.'</p></div>'; |
|
167 | 167 | |
168 | - if ( $echo ) { |
|
168 | + if ($echo) { |
|
169 | 169 | echo $error; |
170 | 170 | } else { |
171 | 171 | return $error; |
@@ -33,20 +33,20 @@ discard block |
||
33 | 33 | $login_redirect = add_query_arg('give-login-success', 'true', give_get_current_page_url()); |
34 | 34 | } |
35 | 35 | |
36 | - if ( empty( $logout_redirect ) ) { |
|
37 | - $logout_redirect = add_query_arg( 'give-logout-success', 'true', give_get_current_page_url() ); |
|
38 | - } |
|
36 | + if ( empty( $logout_redirect ) ) { |
|
37 | + $logout_redirect = add_query_arg( 'give-logout-success', 'true', give_get_current_page_url() ); |
|
38 | + } |
|
39 | 39 | |
40 | 40 | |
41 | - // Add user_logout action to logout url. |
|
42 | - $logout_redirect = add_query_arg( |
|
43 | - array( |
|
44 | - 'give_action' => 'user_logout', |
|
45 | - 'give_logout_nonce' => wp_create_nonce( 'give-logout-nonce' ), |
|
46 | - 'give_logout_redirect' => urlencode( $logout_redirect ) |
|
47 | - ), |
|
48 | - home_url('/') |
|
49 | - ); |
|
41 | + // Add user_logout action to logout url. |
|
42 | + $logout_redirect = add_query_arg( |
|
43 | + array( |
|
44 | + 'give_action' => 'user_logout', |
|
45 | + 'give_logout_nonce' => wp_create_nonce( 'give-logout-nonce' ), |
|
46 | + 'give_logout_redirect' => urlencode( $logout_redirect ) |
|
47 | + ), |
|
48 | + home_url('/') |
|
49 | + ); |
|
50 | 50 | |
51 | 51 | $give_login_redirect = $login_redirect; |
52 | 52 | $give_logout_redirect = $logout_redirect; |
@@ -136,23 +136,23 @@ discard block |
||
136 | 136 | * @return void |
137 | 137 | */ |
138 | 138 | function give_process_user_logout( $data ) { |
139 | - if ( wp_verify_nonce( $data['give_logout_nonce'], 'give-logout-nonce' ) && is_user_logged_in() ) { |
|
139 | + if ( wp_verify_nonce( $data['give_logout_nonce'], 'give-logout-nonce' ) && is_user_logged_in() ) { |
|
140 | 140 | |
141 | - // Prevent occurring of any custom action on wp_logout. |
|
142 | - remove_all_actions( 'wp_logout' ); |
|
141 | + // Prevent occurring of any custom action on wp_logout. |
|
142 | + remove_all_actions( 'wp_logout' ); |
|
143 | 143 | |
144 | - // Before logout give action. |
|
145 | - do_action( 'give_before_user_logout' ); |
|
144 | + // Before logout give action. |
|
145 | + do_action( 'give_before_user_logout' ); |
|
146 | 146 | |
147 | - // Logout user. |
|
148 | - wp_logout(); |
|
147 | + // Logout user. |
|
148 | + wp_logout(); |
|
149 | 149 | |
150 | - // After logout give action. |
|
151 | - do_action( 'give_after_user_logout' ); |
|
150 | + // After logout give action. |
|
151 | + do_action( 'give_after_user_logout' ); |
|
152 | 152 | |
153 | - wp_redirect( $data['give_logout_redirect'] ); |
|
154 | - give_die(); |
|
155 | - } |
|
153 | + wp_redirect( $data['give_logout_redirect'] ); |
|
154 | + give_die(); |
|
155 | + } |
|
156 | 156 | } |
157 | 157 | |
158 | 158 | add_action( 'give_user_logout', 'give_process_user_logout' ); |
@@ -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 | |
@@ -26,15 +26,15 @@ discard block |
||
26 | 26 | * |
27 | 27 | * @return string Login form |
28 | 28 | */ |
29 | -function give_login_form( $login_redirect = '', $logout_redirect = '' ) { |
|
30 | - global $give_login_redirect, $give_logout_redirect;; |
|
29 | +function give_login_form($login_redirect = '', $logout_redirect = '') { |
|
30 | + global $give_login_redirect, $give_logout_redirect; ; |
|
31 | 31 | |
32 | - if ( empty( $login_redirect ) ) { |
|
32 | + if (empty($login_redirect)) { |
|
33 | 33 | $login_redirect = add_query_arg('give-login-success', 'true', give_get_current_page_url()); |
34 | 34 | } |
35 | 35 | |
36 | - if ( empty( $logout_redirect ) ) { |
|
37 | - $logout_redirect = add_query_arg( 'give-logout-success', 'true', give_get_current_page_url() ); |
|
36 | + if (empty($logout_redirect)) { |
|
37 | + $logout_redirect = add_query_arg('give-logout-success', 'true', give_get_current_page_url()); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | |
@@ -42,8 +42,8 @@ discard block |
||
42 | 42 | $logout_redirect = add_query_arg( |
43 | 43 | array( |
44 | 44 | 'give_action' => 'user_logout', |
45 | - 'give_logout_nonce' => wp_create_nonce( 'give-logout-nonce' ), |
|
46 | - 'give_logout_redirect' => urlencode( $logout_redirect ) |
|
45 | + 'give_logout_nonce' => wp_create_nonce('give-logout-nonce'), |
|
46 | + 'give_logout_redirect' => urlencode($logout_redirect) |
|
47 | 47 | ), |
48 | 48 | home_url('/') |
49 | 49 | ); |
@@ -53,9 +53,9 @@ discard block |
||
53 | 53 | |
54 | 54 | ob_start(); |
55 | 55 | |
56 | - give_get_template_part( 'shortcode', 'login' ); |
|
56 | + give_get_template_part('shortcode', 'login'); |
|
57 | 57 | |
58 | - return apply_filters( 'give_login_form', ob_get_clean() ); |
|
58 | + return apply_filters('give_login_form', ob_get_clean()); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | /** |
@@ -69,10 +69,10 @@ discard block |
||
69 | 69 | * |
70 | 70 | * @return string Register form |
71 | 71 | */ |
72 | -function give_register_form( $redirect = '' ) { |
|
72 | +function give_register_form($redirect = '') { |
|
73 | 73 | global $give_options, $give_register_redirect; |
74 | 74 | |
75 | - if ( empty( $redirect ) ) { |
|
75 | + if (empty($redirect)) { |
|
76 | 76 | $redirect = give_get_current_page_url(); |
77 | 77 | } |
78 | 78 | |
@@ -80,11 +80,11 @@ discard block |
||
80 | 80 | |
81 | 81 | ob_start(); |
82 | 82 | |
83 | - if ( ! is_user_logged_in() ) { |
|
84 | - give_get_template_part( 'shortcode', 'register' ); |
|
83 | + if ( ! is_user_logged_in()) { |
|
84 | + give_get_template_part('shortcode', 'register'); |
|
85 | 85 | } |
86 | 86 | |
87 | - return apply_filters( 'give_register_form', ob_get_clean() ); |
|
87 | + return apply_filters('give_register_form', ob_get_clean()); |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | /** |
@@ -96,34 +96,34 @@ discard block |
||
96 | 96 | * |
97 | 97 | * @return void |
98 | 98 | */ |
99 | -function give_process_login_form( $data ) { |
|
100 | - if ( wp_verify_nonce( $data['give_login_nonce'], 'give-login-nonce' ) ) { |
|
101 | - $user_data = get_user_by( 'login', $data['give_user_login'] ); |
|
102 | - if ( ! $user_data ) { |
|
103 | - $user_data = get_user_by( 'email', $data['give_user_login'] ); |
|
99 | +function give_process_login_form($data) { |
|
100 | + if (wp_verify_nonce($data['give_login_nonce'], 'give-login-nonce')) { |
|
101 | + $user_data = get_user_by('login', $data['give_user_login']); |
|
102 | + if ( ! $user_data) { |
|
103 | + $user_data = get_user_by('email', $data['give_user_login']); |
|
104 | 104 | } |
105 | - if ( $user_data ) { |
|
105 | + if ($user_data) { |
|
106 | 106 | $user_ID = $user_data->ID; |
107 | 107 | $user_email = $user_data->user_email; |
108 | - if ( wp_check_password( $data['give_user_pass'], $user_data->user_pass, $user_data->ID ) ) { |
|
109 | - give_log_user_in( $user_data->ID, $data['give_user_login'], $data['give_user_pass'] ); |
|
108 | + if (wp_check_password($data['give_user_pass'], $user_data->user_pass, $user_data->ID)) { |
|
109 | + give_log_user_in($user_data->ID, $data['give_user_login'], $data['give_user_pass']); |
|
110 | 110 | } else { |
111 | - give_set_error( 'password_incorrect', esc_html__( 'The password you entered is incorrect.', 'give' ) ); |
|
111 | + give_set_error('password_incorrect', esc_html__('The password you entered is incorrect.', 'give')); |
|
112 | 112 | } |
113 | 113 | } else { |
114 | - give_set_error( 'username_incorrect', esc_html__( 'The username you entered does not exist.', 'give' ) ); |
|
114 | + give_set_error('username_incorrect', esc_html__('The username you entered does not exist.', 'give')); |
|
115 | 115 | } |
116 | 116 | // Check for errors and redirect if none present |
117 | 117 | $errors = give_get_errors(); |
118 | - if ( ! $errors ) { |
|
119 | - $redirect = apply_filters( 'give_login_redirect', $data['give_login_redirect'], $user_ID ); |
|
120 | - wp_redirect( $redirect ); |
|
118 | + if ( ! $errors) { |
|
119 | + $redirect = apply_filters('give_login_redirect', $data['give_login_redirect'], $user_ID); |
|
120 | + wp_redirect($redirect); |
|
121 | 121 | give_die(); |
122 | 122 | } |
123 | 123 | } |
124 | 124 | } |
125 | 125 | |
126 | -add_action( 'give_user_login', 'give_process_login_form' ); |
|
126 | +add_action('give_user_login', 'give_process_login_form'); |
|
127 | 127 | |
128 | 128 | |
129 | 129 | /** |
@@ -135,27 +135,27 @@ discard block |
||
135 | 135 | * |
136 | 136 | * @return void |
137 | 137 | */ |
138 | -function give_process_user_logout( $data ) { |
|
139 | - if ( wp_verify_nonce( $data['give_logout_nonce'], 'give-logout-nonce' ) && is_user_logged_in() ) { |
|
138 | +function give_process_user_logout($data) { |
|
139 | + if (wp_verify_nonce($data['give_logout_nonce'], 'give-logout-nonce') && is_user_logged_in()) { |
|
140 | 140 | |
141 | 141 | // Prevent occurring of any custom action on wp_logout. |
142 | - remove_all_actions( 'wp_logout' ); |
|
142 | + remove_all_actions('wp_logout'); |
|
143 | 143 | |
144 | 144 | // Before logout give action. |
145 | - do_action( 'give_before_user_logout' ); |
|
145 | + do_action('give_before_user_logout'); |
|
146 | 146 | |
147 | 147 | // Logout user. |
148 | 148 | wp_logout(); |
149 | 149 | |
150 | 150 | // After logout give action. |
151 | - do_action( 'give_after_user_logout' ); |
|
151 | + do_action('give_after_user_logout'); |
|
152 | 152 | |
153 | - wp_redirect( $data['give_logout_redirect'] ); |
|
153 | + wp_redirect($data['give_logout_redirect']); |
|
154 | 154 | give_die(); |
155 | 155 | } |
156 | 156 | } |
157 | 157 | |
158 | -add_action( 'give_user_logout', 'give_process_user_logout' ); |
|
158 | +add_action('give_user_logout', 'give_process_user_logout'); |
|
159 | 159 | |
160 | 160 | /** |
161 | 161 | * Log User In |
@@ -168,15 +168,15 @@ discard block |
||
168 | 168 | * |
169 | 169 | * @return void |
170 | 170 | */ |
171 | -function give_log_user_in( $user_id, $user_login, $user_pass ) { |
|
172 | - if ( $user_id < 1 ) { |
|
171 | +function give_log_user_in($user_id, $user_login, $user_pass) { |
|
172 | + if ($user_id < 1) { |
|
173 | 173 | return; |
174 | 174 | } |
175 | 175 | |
176 | - wp_set_auth_cookie( $user_id ); |
|
177 | - wp_set_current_user( $user_id, $user_login ); |
|
178 | - do_action( 'wp_login', $user_login, get_userdata( $user_id ) ); |
|
179 | - do_action( 'give_log_user_in', $user_id, $user_login, $user_pass ); |
|
176 | + wp_set_auth_cookie($user_id); |
|
177 | + wp_set_current_user($user_id, $user_login); |
|
178 | + do_action('wp_login', $user_login, get_userdata($user_id)); |
|
179 | + do_action('give_log_user_in', $user_id, $user_login, $user_pass); |
|
180 | 180 | } |
181 | 181 | |
182 | 182 | |
@@ -189,70 +189,70 @@ discard block |
||
189 | 189 | * |
190 | 190 | * @return void |
191 | 191 | */ |
192 | -function give_process_register_form( $data ) { |
|
192 | +function give_process_register_form($data) { |
|
193 | 193 | |
194 | - if ( is_user_logged_in() ) { |
|
194 | + if (is_user_logged_in()) { |
|
195 | 195 | return; |
196 | 196 | } |
197 | 197 | |
198 | - if ( empty( $_POST['give_register_submit'] ) ) { |
|
198 | + if (empty($_POST['give_register_submit'])) { |
|
199 | 199 | return; |
200 | 200 | } |
201 | 201 | |
202 | - do_action( 'give_pre_process_register_form' ); |
|
202 | + do_action('give_pre_process_register_form'); |
|
203 | 203 | |
204 | - if ( empty( $data['give_user_login'] ) ) { |
|
205 | - give_set_error( 'empty_username', esc_html__( 'Invalid username.', 'give' ) ); |
|
204 | + if (empty($data['give_user_login'])) { |
|
205 | + give_set_error('empty_username', esc_html__('Invalid username.', 'give')); |
|
206 | 206 | } |
207 | 207 | |
208 | - if ( username_exists( $data['give_user_login'] ) ) { |
|
209 | - give_set_error( 'username_unavailable', esc_html__( 'Username already taken.', 'give' ) ); |
|
208 | + if (username_exists($data['give_user_login'])) { |
|
209 | + give_set_error('username_unavailable', esc_html__('Username already taken.', 'give')); |
|
210 | 210 | } |
211 | 211 | |
212 | - if ( ! validate_username( $data['give_user_login'] ) ) { |
|
213 | - give_set_error( 'username_invalid', esc_html__( 'Invalid username.', 'give' ) ); |
|
212 | + if ( ! validate_username($data['give_user_login'])) { |
|
213 | + give_set_error('username_invalid', esc_html__('Invalid username.', 'give')); |
|
214 | 214 | } |
215 | 215 | |
216 | - if ( email_exists( $data['give_user_email'] ) ) { |
|
217 | - give_set_error( 'email_unavailable', esc_html__( 'Email address already taken.', 'give' ) ); |
|
216 | + if (email_exists($data['give_user_email'])) { |
|
217 | + give_set_error('email_unavailable', esc_html__('Email address already taken.', 'give')); |
|
218 | 218 | } |
219 | 219 | |
220 | - if ( empty( $data['give_user_email'] ) || ! is_email( $data['give_user_email'] ) ) { |
|
221 | - give_set_error( 'email_invalid', esc_html__( 'Invalid email.', 'give' ) ); |
|
220 | + if (empty($data['give_user_email']) || ! is_email($data['give_user_email'])) { |
|
221 | + give_set_error('email_invalid', esc_html__('Invalid email.', 'give')); |
|
222 | 222 | } |
223 | 223 | |
224 | - if ( ! empty( $data['give_payment_email'] ) && $data['give_payment_email'] != $data['give_user_email'] && ! is_email( $data['give_payment_email'] ) ) { |
|
225 | - give_set_error( 'payment_email_invalid', esc_html__( 'Invalid payment email.', 'give' ) ); |
|
224 | + if ( ! empty($data['give_payment_email']) && $data['give_payment_email'] != $data['give_user_email'] && ! is_email($data['give_payment_email'])) { |
|
225 | + give_set_error('payment_email_invalid', esc_html__('Invalid payment email.', 'give')); |
|
226 | 226 | } |
227 | 227 | |
228 | - if ( empty( $_POST['give_user_pass'] ) ) { |
|
229 | - give_set_error( 'empty_password', esc_html__( 'Please enter a password.', 'give' ) ); |
|
228 | + if (empty($_POST['give_user_pass'])) { |
|
229 | + give_set_error('empty_password', esc_html__('Please enter a password.', 'give')); |
|
230 | 230 | } |
231 | 231 | |
232 | - if ( ( ! empty( $_POST['give_user_pass'] ) && empty( $_POST['give_user_pass2'] ) ) || ( $_POST['give_user_pass'] !== $_POST['give_user_pass2'] ) ) { |
|
233 | - give_set_error( 'password_mismatch', esc_html__( 'Passwords don\'t match.', 'give' ) ); |
|
232 | + if (( ! empty($_POST['give_user_pass']) && empty($_POST['give_user_pass2'])) || ($_POST['give_user_pass'] !== $_POST['give_user_pass2'])) { |
|
233 | + give_set_error('password_mismatch', esc_html__('Passwords don\'t match.', 'give')); |
|
234 | 234 | } |
235 | 235 | |
236 | - do_action( 'give_process_register_form' ); |
|
236 | + do_action('give_process_register_form'); |
|
237 | 237 | |
238 | 238 | // Check for errors and redirect if none present |
239 | 239 | $errors = give_get_errors(); |
240 | 240 | |
241 | - if ( empty( $errors ) ) { |
|
241 | + if (empty($errors)) { |
|
242 | 242 | |
243 | - $redirect = apply_filters( 'give_register_redirect', $data['give_redirect'] ); |
|
243 | + $redirect = apply_filters('give_register_redirect', $data['give_redirect']); |
|
244 | 244 | |
245 | - give_register_and_login_new_user( array( |
|
245 | + give_register_and_login_new_user(array( |
|
246 | 246 | 'user_login' => $data['give_user_login'], |
247 | 247 | 'user_pass' => $data['give_user_pass'], |
248 | 248 | 'user_email' => $data['give_user_email'], |
249 | - 'user_registered' => date( 'Y-m-d H:i:s' ), |
|
250 | - 'role' => get_option( 'default_role' ) |
|
251 | - ) ); |
|
249 | + 'user_registered' => date('Y-m-d H:i:s'), |
|
250 | + 'role' => get_option('default_role') |
|
251 | + )); |
|
252 | 252 | |
253 | - wp_redirect( $redirect ); |
|
253 | + wp_redirect($redirect); |
|
254 | 254 | give_die(); |
255 | 255 | } |
256 | 256 | } |
257 | 257 | |
258 | -add_action( 'give_user_register', 'give_process_register_form' ); |
|
259 | 258 | \ No newline at end of file |
259 | +add_action('give_user_register', 'give_process_register_form'); |
|
260 | 260 | \ No newline at end of file |
@@ -1437,7 +1437,7 @@ discard block |
||
1437 | 1437 | * Determines whether results should be displayed in XML or JSON |
1438 | 1438 | * |
1439 | 1439 | * @since 1.1 |
1440 | - * @access public |
|
1440 | + * @access public |
|
1441 | 1441 | * |
1442 | 1442 | * @return mixed|void |
1443 | 1443 | */ |
@@ -1455,7 +1455,7 @@ discard block |
||
1455 | 1455 | * |
1456 | 1456 | * @access private |
1457 | 1457 | * @since 1.1 |
1458 | - * |
|
1458 | + * |
|
1459 | 1459 | * @global Give_Logging $give_logs |
1460 | 1460 | * @global WP_Query $wp_query |
1461 | 1461 | * |
@@ -1468,15 +1468,15 @@ discard block |
||
1468 | 1468 | return; |
1469 | 1469 | } |
1470 | 1470 | |
1471 | - /** |
|
1472 | - * @var Give_Logging $give_logs |
|
1473 | - */ |
|
1471 | + /** |
|
1472 | + * @var Give_Logging $give_logs |
|
1473 | + */ |
|
1474 | 1474 | global $give_logs; |
1475 | 1475 | |
1476 | - /** |
|
1477 | - * @var WP_Query $wp_query |
|
1478 | - */ |
|
1479 | - global $wp_query; |
|
1476 | + /** |
|
1477 | + * @var WP_Query $wp_query |
|
1478 | + */ |
|
1479 | + global $wp_query; |
|
1480 | 1480 | |
1481 | 1481 | $query = array( |
1482 | 1482 | 'give-api' => $wp_query->query_vars['give-api'], |
@@ -1534,9 +1534,9 @@ discard block |
||
1534 | 1534 | * @param int $status_code |
1535 | 1535 | */ |
1536 | 1536 | public function output( $status_code = 200 ) { |
1537 | - /** |
|
1538 | - * @var WP_Query $wp_query |
|
1539 | - */ |
|
1537 | + /** |
|
1538 | + * @var WP_Query $wp_query |
|
1539 | + */ |
|
1540 | 1540 | global $wp_query; |
1541 | 1541 | |
1542 | 1542 | $format = $this->get_output_format(); |
@@ -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 | |
@@ -140,27 +140,27 @@ discard block |
||
140 | 140 | 'v1' => 'GIVE_API_V1', |
141 | 141 | ); |
142 | 142 | |
143 | - foreach ( $this->get_versions() as $version => $class ) { |
|
144 | - require_once GIVE_PLUGIN_DIR . 'includes/api/class-give-api-' . $version . '.php'; |
|
143 | + foreach ($this->get_versions() as $version => $class) { |
|
144 | + require_once GIVE_PLUGIN_DIR.'includes/api/class-give-api-'.$version.'.php'; |
|
145 | 145 | } |
146 | 146 | |
147 | - add_action( 'init', array( $this, 'add_endpoint' ) ); |
|
148 | - add_action( 'wp', array( $this, 'process_query' ), - 1 ); |
|
149 | - add_filter( 'query_vars', array( $this, 'query_vars' ) ); |
|
150 | - add_action( 'show_user_profile', array( $this, 'user_key_field' ) ); |
|
151 | - add_action( 'edit_user_profile', array( $this, 'user_key_field' ) ); |
|
152 | - add_action( 'personal_options_update', array( $this, 'update_key' ) ); |
|
153 | - add_action( 'edit_user_profile_update', array( $this, 'update_key' ) ); |
|
154 | - add_action( 'give_process_api_key', array( $this, 'process_api_key' ) ); |
|
147 | + add_action('init', array($this, 'add_endpoint')); |
|
148 | + add_action('wp', array($this, 'process_query'), - 1); |
|
149 | + add_filter('query_vars', array($this, 'query_vars')); |
|
150 | + add_action('show_user_profile', array($this, 'user_key_field')); |
|
151 | + add_action('edit_user_profile', array($this, 'user_key_field')); |
|
152 | + add_action('personal_options_update', array($this, 'update_key')); |
|
153 | + add_action('edit_user_profile_update', array($this, 'update_key')); |
|
154 | + add_action('give_process_api_key', array($this, 'process_api_key')); |
|
155 | 155 | |
156 | 156 | // Setup a backwards compatibility check for user API Keys |
157 | - add_filter( 'get_user_metadata', array( $this, 'api_key_backwards_compat' ), 10, 4 ); |
|
157 | + add_filter('get_user_metadata', array($this, 'api_key_backwards_compat'), 10, 4); |
|
158 | 158 | |
159 | 159 | // Determine if JSON_PRETTY_PRINT is available |
160 | - $this->pretty_print = defined( 'JSON_PRETTY_PRINT' ) ? JSON_PRETTY_PRINT : null; |
|
160 | + $this->pretty_print = defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : null; |
|
161 | 161 | |
162 | 162 | // Allow API request logging to be turned off |
163 | - $this->log_requests = apply_filters( 'give_api_log_requests', $this->log_requests ); |
|
163 | + $this->log_requests = apply_filters('give_api_log_requests', $this->log_requests); |
|
164 | 164 | |
165 | 165 | // Setup Give_Payment_Stats instance |
166 | 166 | $this->stats = new Give_Payment_Stats; |
@@ -176,8 +176,8 @@ discard block |
||
176 | 176 | * |
177 | 177 | * @since 1.1 |
178 | 178 | */ |
179 | - public function add_endpoint( $rewrite_rules ) { |
|
180 | - add_rewrite_endpoint( 'give-api', EP_ALL ); |
|
179 | + public function add_endpoint($rewrite_rules) { |
|
180 | + add_rewrite_endpoint('give-api', EP_ALL); |
|
181 | 181 | } |
182 | 182 | |
183 | 183 | /** |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | * |
191 | 191 | * @return string[] $vars New query vars |
192 | 192 | */ |
193 | - public function query_vars( $vars ) { |
|
193 | + public function query_vars($vars) { |
|
194 | 194 | |
195 | 195 | $vars[] = 'token'; |
196 | 196 | $vars[] = 'key'; |
@@ -241,11 +241,11 @@ discard block |
||
241 | 241 | */ |
242 | 242 | public function get_default_version() { |
243 | 243 | |
244 | - $version = get_option( 'give_default_api_version' ); |
|
244 | + $version = get_option('give_default_api_version'); |
|
245 | 245 | |
246 | - if ( defined( 'GIVE_API_VERSION' ) ) { |
|
246 | + if (defined('GIVE_API_VERSION')) { |
|
247 | 247 | $version = GIVE_API_VERSION; |
248 | - } elseif ( ! $version ) { |
|
248 | + } elseif ( ! $version) { |
|
249 | 249 | $version = 'v1'; |
250 | 250 | } |
251 | 251 | |
@@ -266,14 +266,14 @@ discard block |
||
266 | 266 | |
267 | 267 | $version = $wp_query->query_vars['give-api']; |
268 | 268 | |
269 | - if ( strpos( $version, '/' ) ) { |
|
269 | + if (strpos($version, '/')) { |
|
270 | 270 | |
271 | - $version = explode( '/', $version ); |
|
272 | - $version = strtolower( $version[0] ); |
|
271 | + $version = explode('/', $version); |
|
272 | + $version = strtolower($version[0]); |
|
273 | 273 | |
274 | - $wp_query->query_vars['give-api'] = str_replace( $version . '/', '', $wp_query->query_vars['give-api'] ); |
|
274 | + $wp_query->query_vars['give-api'] = str_replace($version.'/', '', $wp_query->query_vars['give-api']); |
|
275 | 275 | |
276 | - if ( array_key_exists( $version, $this->versions ) ) { |
|
276 | + if (array_key_exists($version, $this->versions)) { |
|
277 | 277 | |
278 | 278 | $this->queried_version = $version; |
279 | 279 | |
@@ -310,32 +310,32 @@ discard block |
||
310 | 310 | $this->override = false; |
311 | 311 | |
312 | 312 | // Make sure we have both user and api key |
313 | - if ( ! empty( $wp_query->query_vars['give-api'] ) && ( $wp_query->query_vars['give-api'] != 'forms' || ! empty( $wp_query->query_vars['token'] ) ) ) { |
|
313 | + if ( ! empty($wp_query->query_vars['give-api']) && ($wp_query->query_vars['give-api'] != 'forms' || ! empty($wp_query->query_vars['token']))) { |
|
314 | 314 | |
315 | - if ( empty( $wp_query->query_vars['token'] ) || empty( $wp_query->query_vars['key'] ) ) { |
|
315 | + if (empty($wp_query->query_vars['token']) || empty($wp_query->query_vars['key'])) { |
|
316 | 316 | $this->missing_auth(); |
317 | 317 | } |
318 | 318 | |
319 | 319 | // Retrieve the user by public API key and ensure they exist |
320 | - if ( ! ( $user = $this->get_user( $wp_query->query_vars['key'] ) ) ) { |
|
320 | + if ( ! ($user = $this->get_user($wp_query->query_vars['key']))) { |
|
321 | 321 | |
322 | 322 | $this->invalid_key(); |
323 | 323 | |
324 | 324 | } else { |
325 | 325 | |
326 | - $token = urldecode( $wp_query->query_vars['token'] ); |
|
327 | - $secret = $this->get_user_secret_key( $user ); |
|
328 | - $public = urldecode( $wp_query->query_vars['key'] ); |
|
326 | + $token = urldecode($wp_query->query_vars['token']); |
|
327 | + $secret = $this->get_user_secret_key($user); |
|
328 | + $public = urldecode($wp_query->query_vars['key']); |
|
329 | 329 | |
330 | - if ( hash_equals( md5( $secret . $public ), $token ) ) { |
|
330 | + if (hash_equals(md5($secret.$public), $token)) { |
|
331 | 331 | $this->is_valid_request = true; |
332 | 332 | } else { |
333 | 333 | $this->invalid_auth(); |
334 | 334 | } |
335 | 335 | } |
336 | - } elseif ( ! empty( $wp_query->query_vars['give-api'] ) && $wp_query->query_vars['give-api'] == 'forms' ) { |
|
336 | + } elseif ( ! empty($wp_query->query_vars['give-api']) && $wp_query->query_vars['give-api'] == 'forms') { |
|
337 | 337 | $this->is_valid_request = true; |
338 | - $wp_query->set( 'key', 'public' ); |
|
338 | + $wp_query->set('key', 'public'); |
|
339 | 339 | } |
340 | 340 | } |
341 | 341 | |
@@ -351,25 +351,25 @@ discard block |
||
351 | 351 | * |
352 | 352 | * @return bool if user ID is found, false otherwise |
353 | 353 | */ |
354 | - public function get_user( $key = '' ) { |
|
354 | + public function get_user($key = '') { |
|
355 | 355 | global $wpdb, $wp_query; |
356 | 356 | |
357 | - if ( empty( $key ) ) { |
|
358 | - $key = urldecode( $wp_query->query_vars['key'] ); |
|
357 | + if (empty($key)) { |
|
358 | + $key = urldecode($wp_query->query_vars['key']); |
|
359 | 359 | } |
360 | 360 | |
361 | - if ( empty( $key ) ) { |
|
361 | + if (empty($key)) { |
|
362 | 362 | return false; |
363 | 363 | } |
364 | 364 | |
365 | - $user = get_transient( md5( 'give_api_user_' . $key ) ); |
|
365 | + $user = get_transient(md5('give_api_user_'.$key)); |
|
366 | 366 | |
367 | - if ( false === $user ) { |
|
368 | - $user = $wpdb->get_var( $wpdb->prepare( "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = %s LIMIT 1", $key ) ); |
|
369 | - set_transient( md5( 'give_api_user_' . $key ), $user, DAY_IN_SECONDS ); |
|
367 | + if (false === $user) { |
|
368 | + $user = $wpdb->get_var($wpdb->prepare("SELECT user_id FROM $wpdb->usermeta WHERE meta_key = %s LIMIT 1", $key)); |
|
369 | + set_transient(md5('give_api_user_'.$key), $user, DAY_IN_SECONDS); |
|
370 | 370 | } |
371 | 371 | |
372 | - if ( $user != null ) { |
|
372 | + if ($user != null) { |
|
373 | 373 | $this->user_id = $user; |
374 | 374 | |
375 | 375 | return $user; |
@@ -378,37 +378,37 @@ discard block |
||
378 | 378 | return false; |
379 | 379 | } |
380 | 380 | |
381 | - public function get_user_public_key( $user_id = 0 ) { |
|
381 | + public function get_user_public_key($user_id = 0) { |
|
382 | 382 | global $wpdb; |
383 | 383 | |
384 | - if ( empty( $user_id ) ) { |
|
384 | + if (empty($user_id)) { |
|
385 | 385 | return ''; |
386 | 386 | } |
387 | 387 | |
388 | - $cache_key = md5( 'give_api_user_public_key' . $user_id ); |
|
389 | - $user_public_key = get_transient( $cache_key ); |
|
388 | + $cache_key = md5('give_api_user_public_key'.$user_id); |
|
389 | + $user_public_key = get_transient($cache_key); |
|
390 | 390 | |
391 | - if ( empty( $user_public_key ) ) { |
|
392 | - $user_public_key = $wpdb->get_var( $wpdb->prepare( "SELECT meta_key FROM $wpdb->usermeta WHERE meta_value = 'give_user_public_key' AND user_id = %d", $user_id ) ); |
|
393 | - set_transient( $cache_key, $user_public_key, HOUR_IN_SECONDS ); |
|
391 | + if (empty($user_public_key)) { |
|
392 | + $user_public_key = $wpdb->get_var($wpdb->prepare("SELECT meta_key FROM $wpdb->usermeta WHERE meta_value = 'give_user_public_key' AND user_id = %d", $user_id)); |
|
393 | + set_transient($cache_key, $user_public_key, HOUR_IN_SECONDS); |
|
394 | 394 | } |
395 | 395 | |
396 | 396 | return $user_public_key; |
397 | 397 | } |
398 | 398 | |
399 | - public function get_user_secret_key( $user_id = 0 ) { |
|
399 | + public function get_user_secret_key($user_id = 0) { |
|
400 | 400 | global $wpdb; |
401 | 401 | |
402 | - if ( empty( $user_id ) ) { |
|
402 | + if (empty($user_id)) { |
|
403 | 403 | return ''; |
404 | 404 | } |
405 | 405 | |
406 | - $cache_key = md5( 'give_api_user_secret_key' . $user_id ); |
|
407 | - $user_secret_key = get_transient( $cache_key ); |
|
406 | + $cache_key = md5('give_api_user_secret_key'.$user_id); |
|
407 | + $user_secret_key = get_transient($cache_key); |
|
408 | 408 | |
409 | - if ( empty( $user_secret_key ) ) { |
|
410 | - $user_secret_key = $wpdb->get_var( $wpdb->prepare( "SELECT meta_key FROM $wpdb->usermeta WHERE meta_value = 'give_user_secret_key' AND user_id = %d", $user_id ) ); |
|
411 | - set_transient( $cache_key, $user_secret_key, HOUR_IN_SECONDS ); |
|
409 | + if (empty($user_secret_key)) { |
|
410 | + $user_secret_key = $wpdb->get_var($wpdb->prepare("SELECT meta_key FROM $wpdb->usermeta WHERE meta_value = 'give_user_secret_key' AND user_id = %d", $user_id)); |
|
411 | + set_transient($cache_key, $user_secret_key, HOUR_IN_SECONDS); |
|
412 | 412 | } |
413 | 413 | |
414 | 414 | return $user_secret_key; |
@@ -424,10 +424,10 @@ discard block |
||
424 | 424 | */ |
425 | 425 | private function missing_auth() { |
426 | 426 | $error = array(); |
427 | - $error['error'] = esc_html__( 'You must specify both a token and API key!', 'give' ); |
|
427 | + $error['error'] = esc_html__('You must specify both a token and API key!', 'give'); |
|
428 | 428 | |
429 | 429 | $this->data = $error; |
430 | - $this->output( 401 ); |
|
430 | + $this->output(401); |
|
431 | 431 | } |
432 | 432 | |
433 | 433 | /** |
@@ -441,10 +441,10 @@ discard block |
||
441 | 441 | */ |
442 | 442 | private function invalid_auth() { |
443 | 443 | $error = array(); |
444 | - $error['error'] = esc_html__( 'Your request could not be authenticated!', 'give' ); |
|
444 | + $error['error'] = esc_html__('Your request could not be authenticated!', 'give'); |
|
445 | 445 | |
446 | 446 | $this->data = $error; |
447 | - $this->output( 403 ); |
|
447 | + $this->output(403); |
|
448 | 448 | } |
449 | 449 | |
450 | 450 | /** |
@@ -458,10 +458,10 @@ discard block |
||
458 | 458 | */ |
459 | 459 | private function invalid_key() { |
460 | 460 | $error = array(); |
461 | - $error['error'] = esc_html__( 'Invalid API key!', 'give' ); |
|
461 | + $error['error'] = esc_html__('Invalid API key!', 'give'); |
|
462 | 462 | |
463 | 463 | $this->data = $error; |
464 | - $this->output( 403 ); |
|
464 | + $this->output(403); |
|
465 | 465 | } |
466 | 466 | |
467 | 467 | /** |
@@ -474,10 +474,10 @@ discard block |
||
474 | 474 | */ |
475 | 475 | private function invalid_version() { |
476 | 476 | $error = array(); |
477 | - $error['error'] = esc_html__( 'Invalid API version!', 'give' ); |
|
477 | + $error['error'] = esc_html__('Invalid API version!', 'give'); |
|
478 | 478 | |
479 | 479 | $this->data = $error; |
480 | - $this->output( 404 ); |
|
480 | + $this->output(404); |
|
481 | 481 | } |
482 | 482 | |
483 | 483 | /** |
@@ -493,10 +493,10 @@ discard block |
||
493 | 493 | global $wp_query; |
494 | 494 | |
495 | 495 | // Start logging how long the request takes for logging |
496 | - $before = microtime( true ); |
|
496 | + $before = microtime(true); |
|
497 | 497 | |
498 | 498 | // Check for give-api var. Get out if not present |
499 | - if ( empty( $wp_query->query_vars['give-api'] ) ) { |
|
499 | + if (empty($wp_query->query_vars['give-api'])) { |
|
500 | 500 | return; |
501 | 501 | } |
502 | 502 | |
@@ -510,45 +510,45 @@ discard block |
||
510 | 510 | $this->validate_request(); |
511 | 511 | |
512 | 512 | // Only proceed if no errors have been noted |
513 | - if ( ! $this->is_valid_request ) { |
|
513 | + if ( ! $this->is_valid_request) { |
|
514 | 514 | return; |
515 | 515 | } |
516 | 516 | |
517 | - if ( ! defined( 'GIVE_DOING_API' ) ) { |
|
518 | - define( 'GIVE_DOING_API', true ); |
|
517 | + if ( ! defined('GIVE_DOING_API')) { |
|
518 | + define('GIVE_DOING_API', true); |
|
519 | 519 | } |
520 | 520 | |
521 | 521 | $data = array(); |
522 | 522 | $this->routes = new $this->versions[$this->get_queried_version()]; |
523 | 523 | $this->routes->validate_request(); |
524 | 524 | |
525 | - switch ( $this->endpoint ) : |
|
525 | + switch ($this->endpoint) : |
|
526 | 526 | |
527 | 527 | case 'stats' : |
528 | 528 | |
529 | - $data = $this->routes->get_stats( array( |
|
530 | - 'type' => isset( $wp_query->query_vars['type'] ) ? $wp_query->query_vars['type'] : null, |
|
531 | - 'form' => isset( $wp_query->query_vars['form'] ) ? $wp_query->query_vars['form'] : null, |
|
532 | - 'date' => isset( $wp_query->query_vars['date'] ) ? $wp_query->query_vars['date'] : null, |
|
533 | - 'startdate' => isset( $wp_query->query_vars['startdate'] ) ? $wp_query->query_vars['startdate'] : null, |
|
534 | - 'enddate' => isset( $wp_query->query_vars['enddate'] ) ? $wp_query->query_vars['enddate'] : null |
|
535 | - ) ); |
|
529 | + $data = $this->routes->get_stats(array( |
|
530 | + 'type' => isset($wp_query->query_vars['type']) ? $wp_query->query_vars['type'] : null, |
|
531 | + 'form' => isset($wp_query->query_vars['form']) ? $wp_query->query_vars['form'] : null, |
|
532 | + 'date' => isset($wp_query->query_vars['date']) ? $wp_query->query_vars['date'] : null, |
|
533 | + 'startdate' => isset($wp_query->query_vars['startdate']) ? $wp_query->query_vars['startdate'] : null, |
|
534 | + 'enddate' => isset($wp_query->query_vars['enddate']) ? $wp_query->query_vars['enddate'] : null |
|
535 | + )); |
|
536 | 536 | |
537 | 537 | break; |
538 | 538 | |
539 | 539 | case 'forms' : |
540 | 540 | |
541 | - $form = isset( $wp_query->query_vars['form'] ) ? $wp_query->query_vars['form'] : null; |
|
541 | + $form = isset($wp_query->query_vars['form']) ? $wp_query->query_vars['form'] : null; |
|
542 | 542 | |
543 | - $data = $this->routes->get_forms( $form ); |
|
543 | + $data = $this->routes->get_forms($form); |
|
544 | 544 | |
545 | 545 | break; |
546 | 546 | |
547 | 547 | case 'donors' : |
548 | 548 | |
549 | - $customer = isset( $wp_query->query_vars['donor'] ) ? $wp_query->query_vars['donor'] : null; |
|
549 | + $customer = isset($wp_query->query_vars['donor']) ? $wp_query->query_vars['donor'] : null; |
|
550 | 550 | |
551 | - $data = $this->routes->get_customers( $customer ); |
|
551 | + $data = $this->routes->get_customers($customer); |
|
552 | 552 | |
553 | 553 | break; |
554 | 554 | |
@@ -561,14 +561,14 @@ discard block |
||
561 | 561 | endswitch; |
562 | 562 | |
563 | 563 | // Allow extensions to setup their own return data |
564 | - $this->data = apply_filters( 'give_api_output_data', $data, $this->endpoint, $this ); |
|
564 | + $this->data = apply_filters('give_api_output_data', $data, $this->endpoint, $this); |
|
565 | 565 | |
566 | - $after = microtime( true ); |
|
567 | - $request_time = ( $after - $before ); |
|
566 | + $after = microtime(true); |
|
567 | + $request_time = ($after - $before); |
|
568 | 568 | $this->data['request_speed'] = $request_time; |
569 | 569 | |
570 | 570 | // Log this API request, if enabled. We log it here because we have access to errors. |
571 | - $this->log_request( $this->data ); |
|
571 | + $this->log_request($this->data); |
|
572 | 572 | |
573 | 573 | // Send out data to the output function |
574 | 574 | $this->output(); |
@@ -598,25 +598,25 @@ discard block |
||
598 | 598 | global $wp_query; |
599 | 599 | |
600 | 600 | // Whitelist our query options |
601 | - $accepted = apply_filters( 'give_api_valid_query_modes', array( |
|
601 | + $accepted = apply_filters('give_api_valid_query_modes', array( |
|
602 | 602 | 'stats', |
603 | 603 | 'forms', |
604 | 604 | 'donors', |
605 | 605 | 'donations' |
606 | - ) ); |
|
606 | + )); |
|
607 | 607 | |
608 | - $query = isset( $wp_query->query_vars['give-api'] ) ? $wp_query->query_vars['give-api'] : null; |
|
609 | - $query = str_replace( $this->queried_version . '/', '', $query ); |
|
608 | + $query = isset($wp_query->query_vars['give-api']) ? $wp_query->query_vars['give-api'] : null; |
|
609 | + $query = str_replace($this->queried_version.'/', '', $query); |
|
610 | 610 | |
611 | 611 | $error = array(); |
612 | 612 | |
613 | 613 | // Make sure our query is valid |
614 | - if ( ! in_array( $query, $accepted ) ) { |
|
615 | - $error['error'] = esc_html__( 'Invalid query!', 'give' ); |
|
614 | + if ( ! in_array($query, $accepted)) { |
|
615 | + $error['error'] = esc_html__('Invalid query!', 'give'); |
|
616 | 616 | |
617 | 617 | $this->data = $error; |
618 | 618 | // 400 is Bad Request |
619 | - $this->output( 400 ); |
|
619 | + $this->output(400); |
|
620 | 620 | } |
621 | 621 | |
622 | 622 | $this->endpoint = $query; |
@@ -633,7 +633,7 @@ discard block |
||
633 | 633 | public function get_paged() { |
634 | 634 | global $wp_query; |
635 | 635 | |
636 | - return isset( $wp_query->query_vars['page'] ) ? $wp_query->query_vars['page'] : 1; |
|
636 | + return isset($wp_query->query_vars['page']) ? $wp_query->query_vars['page'] : 1; |
|
637 | 637 | } |
638 | 638 | |
639 | 639 | |
@@ -648,13 +648,13 @@ discard block |
||
648 | 648 | public function per_page() { |
649 | 649 | global $wp_query; |
650 | 650 | |
651 | - $per_page = isset( $wp_query->query_vars['number'] ) ? $wp_query->query_vars['number'] : 10; |
|
651 | + $per_page = isset($wp_query->query_vars['number']) ? $wp_query->query_vars['number'] : 10; |
|
652 | 652 | |
653 | - if ( $per_page < 0 && $this->get_query_mode() == 'donors' ) { |
|
653 | + if ($per_page < 0 && $this->get_query_mode() == 'donors') { |
|
654 | 654 | $per_page = 99999999; |
655 | 655 | } // Customers query doesn't support -1 |
656 | 656 | |
657 | - return apply_filters( 'give_api_results_per_page', $per_page ); |
|
657 | + return apply_filters('give_api_results_per_page', $per_page); |
|
658 | 658 | } |
659 | 659 | |
660 | 660 | /** |
@@ -667,7 +667,7 @@ discard block |
||
667 | 667 | * |
668 | 668 | * @return array $dates |
669 | 669 | */ |
670 | - public function get_dates( $args = array() ) { |
|
670 | + public function get_dates($args = array()) { |
|
671 | 671 | $dates = array(); |
672 | 672 | |
673 | 673 | $defaults = array( |
@@ -678,60 +678,60 @@ discard block |
||
678 | 678 | 'enddate' => null |
679 | 679 | ); |
680 | 680 | |
681 | - $args = wp_parse_args( $args, $defaults ); |
|
681 | + $args = wp_parse_args($args, $defaults); |
|
682 | 682 | |
683 | - $current_time = current_time( 'timestamp' ); |
|
683 | + $current_time = current_time('timestamp'); |
|
684 | 684 | |
685 | - if ( 'range' === $args['date'] ) { |
|
686 | - $startdate = strtotime( $args['startdate'] ); |
|
687 | - $enddate = strtotime( $args['enddate'] ); |
|
688 | - $dates['day_start'] = date( 'd', $startdate ); |
|
689 | - $dates['day_end'] = date( 'd', $enddate ); |
|
690 | - $dates['m_start'] = date( 'n', $startdate ); |
|
691 | - $dates['m_end'] = date( 'n', $enddate ); |
|
692 | - $dates['year'] = date( 'Y', $startdate ); |
|
693 | - $dates['year_end'] = date( 'Y', $enddate ); |
|
685 | + if ('range' === $args['date']) { |
|
686 | + $startdate = strtotime($args['startdate']); |
|
687 | + $enddate = strtotime($args['enddate']); |
|
688 | + $dates['day_start'] = date('d', $startdate); |
|
689 | + $dates['day_end'] = date('d', $enddate); |
|
690 | + $dates['m_start'] = date('n', $startdate); |
|
691 | + $dates['m_end'] = date('n', $enddate); |
|
692 | + $dates['year'] = date('Y', $startdate); |
|
693 | + $dates['year_end'] = date('Y', $enddate); |
|
694 | 694 | } else { |
695 | 695 | // Modify dates based on predefined ranges |
696 | - switch ( $args['date'] ) : |
|
696 | + switch ($args['date']) : |
|
697 | 697 | |
698 | 698 | case 'this_month' : |
699 | 699 | $dates['day'] = null; |
700 | - $dates['m_start'] = date( 'n', $current_time ); |
|
701 | - $dates['m_end'] = date( 'n', $current_time ); |
|
702 | - $dates['year'] = date( 'Y', $current_time ); |
|
700 | + $dates['m_start'] = date('n', $current_time); |
|
701 | + $dates['m_end'] = date('n', $current_time); |
|
702 | + $dates['year'] = date('Y', $current_time); |
|
703 | 703 | break; |
704 | 704 | |
705 | 705 | case 'last_month' : |
706 | 706 | $dates['day'] = null; |
707 | - $dates['m_start'] = date( 'n', $current_time ) == 1 ? 12 : date( 'n', $current_time ) - 1; |
|
707 | + $dates['m_start'] = date('n', $current_time) == 1 ? 12 : date('n', $current_time) - 1; |
|
708 | 708 | $dates['m_end'] = $dates['m_start']; |
709 | - $dates['year'] = date( 'n', $current_time ) == 1 ? date( 'Y', $current_time ) - 1 : date( 'Y', $current_time ); |
|
709 | + $dates['year'] = date('n', $current_time) == 1 ? date('Y', $current_time) - 1 : date('Y', $current_time); |
|
710 | 710 | break; |
711 | 711 | |
712 | 712 | case 'today' : |
713 | - $dates['day'] = date( 'd', $current_time ); |
|
714 | - $dates['m_start'] = date( 'n', $current_time ); |
|
715 | - $dates['m_end'] = date( 'n', $current_time ); |
|
716 | - $dates['year'] = date( 'Y', $current_time ); |
|
713 | + $dates['day'] = date('d', $current_time); |
|
714 | + $dates['m_start'] = date('n', $current_time); |
|
715 | + $dates['m_end'] = date('n', $current_time); |
|
716 | + $dates['year'] = date('Y', $current_time); |
|
717 | 717 | break; |
718 | 718 | |
719 | 719 | case 'yesterday' : |
720 | 720 | |
721 | - $year = date( 'Y', $current_time ); |
|
722 | - $month = date( 'n', $current_time ); |
|
723 | - $day = date( 'd', $current_time ); |
|
721 | + $year = date('Y', $current_time); |
|
722 | + $month = date('n', $current_time); |
|
723 | + $day = date('d', $current_time); |
|
724 | 724 | |
725 | - if ( $month == 1 && $day == 1 ) { |
|
725 | + if ($month == 1 && $day == 1) { |
|
726 | 726 | |
727 | 727 | $year -= 1; |
728 | 728 | $month = 12; |
729 | - $day = cal_days_in_month( CAL_GREGORIAN, $month, $year ); |
|
729 | + $day = cal_days_in_month(CAL_GREGORIAN, $month, $year); |
|
730 | 730 | |
731 | - } elseif ( $month > 1 && $day == 1 ) { |
|
731 | + } elseif ($month > 1 && $day == 1) { |
|
732 | 732 | |
733 | 733 | $month -= 1; |
734 | - $day = cal_days_in_month( CAL_GREGORIAN, $month, $year ); |
|
734 | + $day = cal_days_in_month(CAL_GREGORIAN, $month, $year); |
|
735 | 735 | |
736 | 736 | } else { |
737 | 737 | |
@@ -747,65 +747,65 @@ discard block |
||
747 | 747 | break; |
748 | 748 | |
749 | 749 | case 'this_quarter' : |
750 | - $month_now = date( 'n', $current_time ); |
|
750 | + $month_now = date('n', $current_time); |
|
751 | 751 | |
752 | 752 | $dates['day'] = null; |
753 | 753 | |
754 | - if ( $month_now <= 3 ) { |
|
754 | + if ($month_now <= 3) { |
|
755 | 755 | |
756 | 756 | $dates['m_start'] = 1; |
757 | 757 | $dates['m_end'] = 3; |
758 | - $dates['year'] = date( 'Y', $current_time ); |
|
758 | + $dates['year'] = date('Y', $current_time); |
|
759 | 759 | |
760 | - } else if ( $month_now <= 6 ) { |
|
760 | + } else if ($month_now <= 6) { |
|
761 | 761 | |
762 | 762 | $dates['m_start'] = 4; |
763 | 763 | $dates['m_end'] = 6; |
764 | - $dates['year'] = date( 'Y', $current_time ); |
|
764 | + $dates['year'] = date('Y', $current_time); |
|
765 | 765 | |
766 | - } else if ( $month_now <= 9 ) { |
|
766 | + } else if ($month_now <= 9) { |
|
767 | 767 | |
768 | 768 | $dates['m_start'] = 7; |
769 | 769 | $dates['m_end'] = 9; |
770 | - $dates['year'] = date( 'Y', $current_time ); |
|
770 | + $dates['year'] = date('Y', $current_time); |
|
771 | 771 | |
772 | 772 | } else { |
773 | 773 | |
774 | 774 | $dates['m_start'] = 10; |
775 | 775 | $dates['m_end'] = 12; |
776 | - $dates['year'] = date( 'Y', $current_time ); |
|
776 | + $dates['year'] = date('Y', $current_time); |
|
777 | 777 | |
778 | 778 | } |
779 | 779 | break; |
780 | 780 | |
781 | 781 | case 'last_quarter' : |
782 | - $month_now = date( 'n', $current_time ); |
|
782 | + $month_now = date('n', $current_time); |
|
783 | 783 | |
784 | 784 | $dates['day'] = null; |
785 | 785 | |
786 | - if ( $month_now <= 3 ) { |
|
786 | + if ($month_now <= 3) { |
|
787 | 787 | |
788 | 788 | $dates['m_start'] = 10; |
789 | 789 | $dates['m_end'] = 12; |
790 | - $dates['year'] = date( 'Y', $current_time ) - 1; // Previous year |
|
790 | + $dates['year'] = date('Y', $current_time) - 1; // Previous year |
|
791 | 791 | |
792 | - } else if ( $month_now <= 6 ) { |
|
792 | + } else if ($month_now <= 6) { |
|
793 | 793 | |
794 | 794 | $dates['m_start'] = 1; |
795 | 795 | $dates['m_end'] = 3; |
796 | - $dates['year'] = date( 'Y', $current_time ); |
|
796 | + $dates['year'] = date('Y', $current_time); |
|
797 | 797 | |
798 | - } else if ( $month_now <= 9 ) { |
|
798 | + } else if ($month_now <= 9) { |
|
799 | 799 | |
800 | 800 | $dates['m_start'] = 4; |
801 | 801 | $dates['m_end'] = 6; |
802 | - $dates['year'] = date( 'Y', $current_time ); |
|
802 | + $dates['year'] = date('Y', $current_time); |
|
803 | 803 | |
804 | 804 | } else { |
805 | 805 | |
806 | 806 | $dates['m_start'] = 7; |
807 | 807 | $dates['m_end'] = 9; |
808 | - $dates['year'] = date( 'Y', $current_time ); |
|
808 | + $dates['year'] = date('Y', $current_time); |
|
809 | 809 | |
810 | 810 | } |
811 | 811 | break; |
@@ -814,14 +814,14 @@ discard block |
||
814 | 814 | $dates['day'] = null; |
815 | 815 | $dates['m_start'] = null; |
816 | 816 | $dates['m_end'] = null; |
817 | - $dates['year'] = date( 'Y', $current_time ); |
|
817 | + $dates['year'] = date('Y', $current_time); |
|
818 | 818 | break; |
819 | 819 | |
820 | 820 | case 'last_year' : |
821 | 821 | $dates['day'] = null; |
822 | 822 | $dates['m_start'] = null; |
823 | 823 | $dates['m_end'] = null; |
824 | - $dates['year'] = date( 'Y', $current_time ) - 1; |
|
824 | + $dates['year'] = date('Y', $current_time) - 1; |
|
825 | 825 | break; |
826 | 826 | |
827 | 827 | endswitch; |
@@ -835,7 +835,7 @@ discard block |
||
835 | 835 | * @param object $dates The dates used for retrieving earnings/donations |
836 | 836 | */ |
837 | 837 | |
838 | - return apply_filters( 'give_api_stat_dates', $dates ); |
|
838 | + return apply_filters('give_api_stat_dates', $dates); |
|
839 | 839 | } |
840 | 840 | |
841 | 841 | /** |
@@ -850,11 +850,11 @@ discard block |
||
850 | 850 | * |
851 | 851 | * @return array $customers Multidimensional array of the customers |
852 | 852 | */ |
853 | - public function get_customers( $customer = null ) { |
|
853 | + public function get_customers($customer = null) { |
|
854 | 854 | |
855 | 855 | $customers = array(); |
856 | 856 | $error = array(); |
857 | - if ( ! user_can( $this->user_id, 'view_give_sensitive_data' ) && ! $this->override ) { |
|
857 | + if ( ! user_can($this->user_id, 'view_give_sensitive_data') && ! $this->override) { |
|
858 | 858 | return $customers; |
859 | 859 | } |
860 | 860 | |
@@ -862,64 +862,64 @@ discard block |
||
862 | 862 | |
863 | 863 | $paged = $this->get_paged(); |
864 | 864 | $per_page = $this->per_page(); |
865 | - $offset = $per_page * ( $paged - 1 ); |
|
865 | + $offset = $per_page * ($paged - 1); |
|
866 | 866 | |
867 | - if ( is_numeric( $customer ) ) { |
|
867 | + if (is_numeric($customer)) { |
|
868 | 868 | $field = 'id'; |
869 | 869 | } else { |
870 | 870 | $field = 'email'; |
871 | 871 | } |
872 | 872 | |
873 | - $customer_query = Give()->customers->get_customers( array( |
|
873 | + $customer_query = Give()->customers->get_customers(array( |
|
874 | 874 | 'number' => $per_page, |
875 | 875 | 'offset' => $offset, |
876 | 876 | $field => $customer |
877 | - ) ); |
|
877 | + )); |
|
878 | 878 | $customer_count = 0; |
879 | 879 | |
880 | - if ( $customer_query ) { |
|
880 | + if ($customer_query) { |
|
881 | 881 | |
882 | - foreach ( $customer_query as $customer_obj ) { |
|
882 | + foreach ($customer_query as $customer_obj) { |
|
883 | 883 | |
884 | - $names = explode( ' ', $customer_obj->name ); |
|
885 | - $first_name = ! empty( $names[0] ) ? $names[0] : ''; |
|
884 | + $names = explode(' ', $customer_obj->name); |
|
885 | + $first_name = ! empty($names[0]) ? $names[0] : ''; |
|
886 | 886 | $last_name = ''; |
887 | - if ( ! empty( $names[1] ) ) { |
|
888 | - unset( $names[0] ); |
|
889 | - $last_name = implode( ' ', $names ); |
|
887 | + if ( ! empty($names[1])) { |
|
888 | + unset($names[0]); |
|
889 | + $last_name = implode(' ', $names); |
|
890 | 890 | } |
891 | 891 | |
892 | - $customers['donors'][ $customer_count ]['info']['user_id'] = ''; |
|
893 | - $customers['donors'][ $customer_count ]['info']['username'] = ''; |
|
894 | - $customers['donors'][ $customer_count ]['info']['display_name'] = ''; |
|
895 | - $customers['donors'][ $customer_count ]['info']['customer_id'] = $customer_obj->id; |
|
896 | - $customers['donors'][ $customer_count ]['info']['first_name'] = $first_name; |
|
897 | - $customers['donors'][ $customer_count ]['info']['last_name'] = $last_name; |
|
898 | - $customers['donors'][ $customer_count ]['info']['email'] = $customer_obj->email; |
|
892 | + $customers['donors'][$customer_count]['info']['user_id'] = ''; |
|
893 | + $customers['donors'][$customer_count]['info']['username'] = ''; |
|
894 | + $customers['donors'][$customer_count]['info']['display_name'] = ''; |
|
895 | + $customers['donors'][$customer_count]['info']['customer_id'] = $customer_obj->id; |
|
896 | + $customers['donors'][$customer_count]['info']['first_name'] = $first_name; |
|
897 | + $customers['donors'][$customer_count]['info']['last_name'] = $last_name; |
|
898 | + $customers['donors'][$customer_count]['info']['email'] = $customer_obj->email; |
|
899 | 899 | |
900 | - if ( ! empty( $customer_obj->user_id ) ) { |
|
900 | + if ( ! empty($customer_obj->user_id)) { |
|
901 | 901 | |
902 | - $user_data = get_userdata( $customer_obj->user_id ); |
|
902 | + $user_data = get_userdata($customer_obj->user_id); |
|
903 | 903 | |
904 | 904 | // Customer with registered account |
905 | - $customers['donors'][ $customer_count ]['info']['user_id'] = $customer_obj->user_id; |
|
906 | - $customers['donors'][ $customer_count ]['info']['username'] = $user_data->user_login; |
|
907 | - $customers['donors'][ $customer_count ]['info']['display_name'] = $user_data->display_name; |
|
905 | + $customers['donors'][$customer_count]['info']['user_id'] = $customer_obj->user_id; |
|
906 | + $customers['donors'][$customer_count]['info']['username'] = $user_data->user_login; |
|
907 | + $customers['donors'][$customer_count]['info']['display_name'] = $user_data->display_name; |
|
908 | 908 | |
909 | 909 | } |
910 | 910 | |
911 | - $customers['donors'][ $customer_count ]['stats']['total_donations'] = $customer_obj->purchase_count; |
|
912 | - $customers['donors'][ $customer_count ]['stats']['total_spent'] = $customer_obj->purchase_value; |
|
911 | + $customers['donors'][$customer_count]['stats']['total_donations'] = $customer_obj->purchase_count; |
|
912 | + $customers['donors'][$customer_count]['stats']['total_spent'] = $customer_obj->purchase_value; |
|
913 | 913 | |
914 | - $customer_count ++; |
|
914 | + $customer_count++; |
|
915 | 915 | |
916 | 916 | } |
917 | 917 | |
918 | - } elseif ( $customer ) { |
|
918 | + } elseif ($customer) { |
|
919 | 919 | |
920 | 920 | $error['error'] = sprintf( |
921 | 921 | /* translators: %s: customer */ |
922 | - esc_html__( 'Donor %s not found!', 'give' ), |
|
922 | + esc_html__('Donor %s not found!', 'give'), |
|
923 | 923 | $customer |
924 | 924 | ); |
925 | 925 | |
@@ -927,7 +927,7 @@ discard block |
||
927 | 927 | |
928 | 928 | } else { |
929 | 929 | |
930 | - $error['error'] = esc_html__( 'No donors found!', 'give' ); |
|
930 | + $error['error'] = esc_html__('No donors found!', 'give'); |
|
931 | 931 | |
932 | 932 | return $error; |
933 | 933 | |
@@ -946,38 +946,38 @@ discard block |
||
946 | 946 | * |
947 | 947 | * @return array $customers Multidimensional array of the forms |
948 | 948 | */ |
949 | - public function get_forms( $form = null ) { |
|
949 | + public function get_forms($form = null) { |
|
950 | 950 | |
951 | 951 | $forms = array(); |
952 | 952 | $error = array(); |
953 | 953 | |
954 | - if ( $form == null ) { |
|
954 | + if ($form == null) { |
|
955 | 955 | $forms['forms'] = array(); |
956 | 956 | |
957 | - $form_list = get_posts( array( |
|
957 | + $form_list = get_posts(array( |
|
958 | 958 | 'post_type' => 'give_forms', |
959 | 959 | 'posts_per_page' => $this->per_page(), |
960 | 960 | 'suppress_filters' => true, |
961 | 961 | 'paged' => $this->get_paged() |
962 | - ) ); |
|
962 | + )); |
|
963 | 963 | |
964 | - if ( $form_list ) { |
|
964 | + if ($form_list) { |
|
965 | 965 | $i = 0; |
966 | - foreach ( $form_list as $form_info ) { |
|
967 | - $forms['forms'][ $i ] = $this->get_form_data( $form_info ); |
|
968 | - $i ++; |
|
966 | + foreach ($form_list as $form_info) { |
|
967 | + $forms['forms'][$i] = $this->get_form_data($form_info); |
|
968 | + $i++; |
|
969 | 969 | } |
970 | 970 | } |
971 | 971 | } else { |
972 | - if ( get_post_type( $form ) == 'give_forms' ) { |
|
973 | - $form_info = get_post( $form ); |
|
972 | + if (get_post_type($form) == 'give_forms') { |
|
973 | + $form_info = get_post($form); |
|
974 | 974 | |
975 | - $forms['forms'][0] = $this->get_form_data( $form_info ); |
|
975 | + $forms['forms'][0] = $this->get_form_data($form_info); |
|
976 | 976 | |
977 | 977 | } else { |
978 | 978 | $error['error'] = sprintf( |
979 | 979 | /* translators: %s: form */ |
980 | - esc_html__( 'Form %s not found!', 'give' ), |
|
980 | + esc_html__('Form %s not found!', 'give'), |
|
981 | 981 | $form |
982 | 982 | ); |
983 | 983 | |
@@ -997,7 +997,7 @@ discard block |
||
997 | 997 | * |
998 | 998 | * @return array Array of post data to return back in the API |
999 | 999 | */ |
1000 | - private function get_form_data( $form_info ) { |
|
1000 | + private function get_form_data($form_info) { |
|
1001 | 1001 | |
1002 | 1002 | $form = array(); |
1003 | 1003 | |
@@ -1007,46 +1007,46 @@ discard block |
||
1007 | 1007 | $form['info']['create_date'] = $form_info->post_date; |
1008 | 1008 | $form['info']['modified_date'] = $form_info->post_modified; |
1009 | 1009 | $form['info']['status'] = $form_info->post_status; |
1010 | - $form['info']['link'] = html_entity_decode( $form_info->guid ); |
|
1011 | - $form['info']['content'] = get_post_meta( $form_info->ID, '_give_form_content', true ); |
|
1012 | - $form['info']['thumbnail'] = wp_get_attachment_url( get_post_thumbnail_id( $form_info->ID ) ); |
|
1010 | + $form['info']['link'] = html_entity_decode($form_info->guid); |
|
1011 | + $form['info']['content'] = get_post_meta($form_info->ID, '_give_form_content', true); |
|
1012 | + $form['info']['thumbnail'] = wp_get_attachment_url(get_post_thumbnail_id($form_info->ID)); |
|
1013 | 1013 | |
1014 | - if ( give_get_option( 'enable_categories' ) == 'on' ) { |
|
1015 | - $form['info']['category'] = get_the_terms( $form_info, 'give_forms_category' ); |
|
1016 | - $form['info']['tags'] = get_the_terms( $form_info, 'give_forms_tag' ); |
|
1014 | + if (give_get_option('enable_categories') == 'on') { |
|
1015 | + $form['info']['category'] = get_the_terms($form_info, 'give_forms_category'); |
|
1016 | + $form['info']['tags'] = get_the_terms($form_info, 'give_forms_tag'); |
|
1017 | 1017 | } |
1018 | - if ( give_get_option( 'enable_tags' ) == 'on' ) { |
|
1019 | - $form['info']['tags'] = get_the_terms( $form_info, 'give_forms_tag' ); |
|
1018 | + if (give_get_option('enable_tags') == 'on') { |
|
1019 | + $form['info']['tags'] = get_the_terms($form_info, 'give_forms_tag'); |
|
1020 | 1020 | } |
1021 | 1021 | |
1022 | - if ( user_can( $this->user_id, 'view_give_reports' ) || $this->override ) { |
|
1023 | - $form['stats']['total']['donations'] = give_get_form_sales_stats( $form_info->ID ); |
|
1024 | - $form['stats']['total']['earnings'] = give_get_form_earnings_stats( $form_info->ID ); |
|
1025 | - $form['stats']['monthly_average']['donations'] = give_get_average_monthly_form_sales( $form_info->ID ); |
|
1026 | - $form['stats']['monthly_average']['earnings'] = give_get_average_monthly_form_earnings( $form_info->ID ); |
|
1022 | + if (user_can($this->user_id, 'view_give_reports') || $this->override) { |
|
1023 | + $form['stats']['total']['donations'] = give_get_form_sales_stats($form_info->ID); |
|
1024 | + $form['stats']['total']['earnings'] = give_get_form_earnings_stats($form_info->ID); |
|
1025 | + $form['stats']['monthly_average']['donations'] = give_get_average_monthly_form_sales($form_info->ID); |
|
1026 | + $form['stats']['monthly_average']['earnings'] = give_get_average_monthly_form_earnings($form_info->ID); |
|
1027 | 1027 | } |
1028 | 1028 | |
1029 | 1029 | $counter = 0; |
1030 | - if ( give_has_variable_prices( $form_info->ID ) ) { |
|
1031 | - foreach ( give_get_variable_prices( $form_info->ID ) as $price ) { |
|
1032 | - $counter ++; |
|
1030 | + if (give_has_variable_prices($form_info->ID)) { |
|
1031 | + foreach (give_get_variable_prices($form_info->ID) as $price) { |
|
1032 | + $counter++; |
|
1033 | 1033 | //muli-level item |
1034 | - $level = isset( $price['_give_text'] ) ? $price['_give_text'] : 'level-' . $counter; |
|
1035 | - $form['pricing'][ sanitize_key( $level ) ] = $price['_give_amount']; |
|
1034 | + $level = isset($price['_give_text']) ? $price['_give_text'] : 'level-'.$counter; |
|
1035 | + $form['pricing'][sanitize_key($level)] = $price['_give_amount']; |
|
1036 | 1036 | |
1037 | 1037 | } |
1038 | 1038 | } else { |
1039 | - $form['pricing']['amount'] = give_get_form_price( $form_info->ID ); |
|
1039 | + $form['pricing']['amount'] = give_get_form_price($form_info->ID); |
|
1040 | 1040 | } |
1041 | 1041 | |
1042 | - if ( user_can( $this->user_id, 'view_give_sensitive_data' ) || $this->override ) { |
|
1042 | + if (user_can($this->user_id, 'view_give_sensitive_data') || $this->override) { |
|
1043 | 1043 | |
1044 | 1044 | //Sensitive data here |
1045 | - do_action( 'give_api_sensitive_data' ); |
|
1045 | + do_action('give_api_sensitive_data'); |
|
1046 | 1046 | |
1047 | 1047 | } |
1048 | 1048 | |
1049 | - return apply_filters( 'give_api_forms_form', $form ); |
|
1049 | + return apply_filters('give_api_forms_form', $form); |
|
1050 | 1050 | |
1051 | 1051 | } |
1052 | 1052 | |
@@ -1061,7 +1061,7 @@ discard block |
||
1061 | 1061 | * |
1062 | 1062 | * @return array |
1063 | 1063 | */ |
1064 | - public function get_stats( $args = array() ) { |
|
1064 | + public function get_stats($args = array()) { |
|
1065 | 1065 | $defaults = array( |
1066 | 1066 | 'type' => null, |
1067 | 1067 | 'form' => null, |
@@ -1070,9 +1070,9 @@ discard block |
||
1070 | 1070 | 'enddate' => null |
1071 | 1071 | ); |
1072 | 1072 | |
1073 | - $args = wp_parse_args( $args, $defaults ); |
|
1073 | + $args = wp_parse_args($args, $defaults); |
|
1074 | 1074 | |
1075 | - $dates = $this->get_dates( $args ); |
|
1075 | + $dates = $this->get_dates($args); |
|
1076 | 1076 | |
1077 | 1077 | $stats = array(); |
1078 | 1078 | $earnings = array( |
@@ -1083,41 +1083,41 @@ discard block |
||
1083 | 1083 | ); |
1084 | 1084 | $error = array(); |
1085 | 1085 | |
1086 | - if ( ! user_can( $this->user_id, 'view_give_reports' ) && ! $this->override ) { |
|
1086 | + if ( ! user_can($this->user_id, 'view_give_reports') && ! $this->override) { |
|
1087 | 1087 | return $stats; |
1088 | 1088 | } |
1089 | 1089 | |
1090 | - if ( $args['type'] == 'donations' ) { |
|
1090 | + if ($args['type'] == 'donations') { |
|
1091 | 1091 | |
1092 | - if ( $args['form'] == null ) { |
|
1093 | - if ( $args['date'] == null ) { |
|
1092 | + if ($args['form'] == null) { |
|
1093 | + if ($args['date'] == null) { |
|
1094 | 1094 | $sales = $this->get_default_sales_stats(); |
1095 | - } elseif ( $args['date'] === 'range' ) { |
|
1095 | + } elseif ($args['date'] === 'range') { |
|
1096 | 1096 | // Return sales for a date range |
1097 | 1097 | |
1098 | 1098 | // Ensure the end date is later than the start date |
1099 | - if ( $args['enddate'] < $args['startdate'] ) { |
|
1100 | - $error['error'] = esc_html__( 'The end date must be later than the start date!', 'give' ); |
|
1099 | + if ($args['enddate'] < $args['startdate']) { |
|
1100 | + $error['error'] = esc_html__('The end date must be later than the start date!', 'give'); |
|
1101 | 1101 | } |
1102 | 1102 | |
1103 | 1103 | // Ensure both the start and end date are specified |
1104 | - if ( empty( $args['startdate'] ) || empty( $args['enddate'] ) ) { |
|
1105 | - $error['error'] = esc_html__( 'Invalid or no date range specified!', 'give' ); |
|
1104 | + if (empty($args['startdate']) || empty($args['enddate'])) { |
|
1105 | + $error['error'] = esc_html__('Invalid or no date range specified!', 'give'); |
|
1106 | 1106 | } |
1107 | 1107 | |
1108 | 1108 | $total = 0; |
1109 | 1109 | |
1110 | 1110 | // Loop through the years |
1111 | 1111 | $y = $dates['year']; |
1112 | - while ( $y <= $dates['year_end'] ) : |
|
1112 | + while ($y <= $dates['year_end']) : |
|
1113 | 1113 | |
1114 | - if ( $dates['year'] == $dates['year_end'] ) { |
|
1114 | + if ($dates['year'] == $dates['year_end']) { |
|
1115 | 1115 | $month_start = $dates['m_start']; |
1116 | 1116 | $month_end = $dates['m_end']; |
1117 | - } elseif ( $y == $dates['year'] && $dates['year_end'] > $dates['year'] ) { |
|
1117 | + } elseif ($y == $dates['year'] && $dates['year_end'] > $dates['year']) { |
|
1118 | 1118 | $month_start = $dates['m_start']; |
1119 | 1119 | $month_end = 12; |
1120 | - } elseif ( $y == $dates['year_end'] ) { |
|
1120 | + } elseif ($y == $dates['year_end']) { |
|
1121 | 1121 | $month_start = 1; |
1122 | 1122 | $month_end = $dates['m_end']; |
1123 | 1123 | } else { |
@@ -1126,113 +1126,113 @@ discard block |
||
1126 | 1126 | } |
1127 | 1127 | |
1128 | 1128 | $i = $month_start; |
1129 | - while ( $i <= $month_end ) : |
|
1129 | + while ($i <= $month_end) : |
|
1130 | 1130 | |
1131 | - if ( $i == $dates['m_start'] ) { |
|
1131 | + if ($i == $dates['m_start']) { |
|
1132 | 1132 | $d = $dates['day_start']; |
1133 | 1133 | } else { |
1134 | 1134 | $d = 1; |
1135 | 1135 | } |
1136 | 1136 | |
1137 | - if ( $i == $dates['m_end'] ) { |
|
1137 | + if ($i == $dates['m_end']) { |
|
1138 | 1138 | $num_of_days = $dates['day_end']; |
1139 | 1139 | } else { |
1140 | - $num_of_days = cal_days_in_month( CAL_GREGORIAN, $i, $y ); |
|
1140 | + $num_of_days = cal_days_in_month(CAL_GREGORIAN, $i, $y); |
|
1141 | 1141 | } |
1142 | 1142 | |
1143 | - while ( $d <= $num_of_days ) : |
|
1144 | - $sale_count = give_get_sales_by_date( $d, $i, $y ); |
|
1145 | - $date_key = date( 'Ymd', strtotime( $y . '/' . $i . '/' . $d ) ); |
|
1146 | - if ( ! isset( $sales['sales'][ $date_key ] ) ) { |
|
1147 | - $sales['sales'][ $date_key ] = 0; |
|
1143 | + while ($d <= $num_of_days) : |
|
1144 | + $sale_count = give_get_sales_by_date($d, $i, $y); |
|
1145 | + $date_key = date('Ymd', strtotime($y.'/'.$i.'/'.$d)); |
|
1146 | + if ( ! isset($sales['sales'][$date_key])) { |
|
1147 | + $sales['sales'][$date_key] = 0; |
|
1148 | 1148 | } |
1149 | - $sales['sales'][ $date_key ] += $sale_count; |
|
1149 | + $sales['sales'][$date_key] += $sale_count; |
|
1150 | 1150 | $total += $sale_count; |
1151 | - $d ++; |
|
1151 | + $d++; |
|
1152 | 1152 | endwhile; |
1153 | - $i ++; |
|
1153 | + $i++; |
|
1154 | 1154 | endwhile; |
1155 | 1155 | |
1156 | - $y ++; |
|
1156 | + $y++; |
|
1157 | 1157 | endwhile; |
1158 | 1158 | |
1159 | 1159 | $sales['totals'] = $total; |
1160 | 1160 | } else { |
1161 | - if ( $args['date'] == 'this_quarter' || $args['date'] == 'last_quarter' ) { |
|
1161 | + if ($args['date'] == 'this_quarter' || $args['date'] == 'last_quarter') { |
|
1162 | 1162 | $sales_count = 0; |
1163 | 1163 | |
1164 | 1164 | // Loop through the months |
1165 | 1165 | $month = $dates['m_start']; |
1166 | 1166 | |
1167 | - while ( $month <= $dates['m_end'] ) : |
|
1168 | - $sales_count += give_get_sales_by_date( null, $month, $dates['year'] ); |
|
1169 | - $month ++; |
|
1167 | + while ($month <= $dates['m_end']) : |
|
1168 | + $sales_count += give_get_sales_by_date(null, $month, $dates['year']); |
|
1169 | + $month++; |
|
1170 | 1170 | endwhile; |
1171 | 1171 | |
1172 | - $sales['donations'][ $args['date'] ] = $sales_count; |
|
1172 | + $sales['donations'][$args['date']] = $sales_count; |
|
1173 | 1173 | } else { |
1174 | - $sales['donations'][ $args['date'] ] = give_get_sales_by_date( $dates['day'], $dates['m_start'], $dates['year'] ); |
|
1174 | + $sales['donations'][$args['date']] = give_get_sales_by_date($dates['day'], $dates['m_start'], $dates['year']); |
|
1175 | 1175 | } |
1176 | 1176 | } |
1177 | - } elseif ( $args['form'] == 'all' ) { |
|
1178 | - $forms = get_posts( array( 'post_type' => 'give_forms', 'nopaging' => true ) ); |
|
1177 | + } elseif ($args['form'] == 'all') { |
|
1178 | + $forms = get_posts(array('post_type' => 'give_forms', 'nopaging' => true)); |
|
1179 | 1179 | $i = 0; |
1180 | - foreach ( $forms as $form_info ) { |
|
1181 | - $sales['donations'][ $i ] = array( $form_info->post_name => give_get_form_sales_stats( $form_info->ID ) ); |
|
1182 | - $i ++; |
|
1180 | + foreach ($forms as $form_info) { |
|
1181 | + $sales['donations'][$i] = array($form_info->post_name => give_get_form_sales_stats($form_info->ID)); |
|
1182 | + $i++; |
|
1183 | 1183 | } |
1184 | 1184 | } else { |
1185 | - if ( get_post_type( $args['form'] ) == 'give_forms' ) { |
|
1186 | - $form_info = get_post( $args['form'] ); |
|
1187 | - $sales['donations'][0] = array( $form_info->post_name => give_get_form_sales_stats( $args['form'] ) ); |
|
1185 | + if (get_post_type($args['form']) == 'give_forms') { |
|
1186 | + $form_info = get_post($args['form']); |
|
1187 | + $sales['donations'][0] = array($form_info->post_name => give_get_form_sales_stats($args['form'])); |
|
1188 | 1188 | } else { |
1189 | 1189 | $error['error'] = sprintf( |
1190 | 1190 | /* translators: %s: form */ |
1191 | - esc_html__( 'Product %s not found!', 'give' ), |
|
1191 | + esc_html__('Product %s not found!', 'give'), |
|
1192 | 1192 | $args['form'] |
1193 | 1193 | ); |
1194 | 1194 | } |
1195 | 1195 | } |
1196 | 1196 | |
1197 | - if ( ! empty( $error ) ) { |
|
1197 | + if ( ! empty($error)) { |
|
1198 | 1198 | return $error; |
1199 | 1199 | } |
1200 | 1200 | |
1201 | 1201 | return $sales; |
1202 | 1202 | |
1203 | - } elseif ( $args['type'] == 'earnings' ) { |
|
1204 | - if ( $args['form'] == null ) { |
|
1205 | - if ( $args['date'] == null ) { |
|
1203 | + } elseif ($args['type'] == 'earnings') { |
|
1204 | + if ($args['form'] == null) { |
|
1205 | + if ($args['date'] == null) { |
|
1206 | 1206 | $earnings = $this->get_default_earnings_stats(); |
1207 | - } elseif ( $args['date'] === 'range' ) { |
|
1207 | + } elseif ($args['date'] === 'range') { |
|
1208 | 1208 | // Return sales for a date range |
1209 | 1209 | |
1210 | 1210 | // Ensure the end date is later than the start date |
1211 | - if ( $args['enddate'] < $args['startdate'] ) { |
|
1212 | - $error['error'] = esc_html__( 'The end date must be later than the start date!', 'give' ); |
|
1211 | + if ($args['enddate'] < $args['startdate']) { |
|
1212 | + $error['error'] = esc_html__('The end date must be later than the start date!', 'give'); |
|
1213 | 1213 | } |
1214 | 1214 | |
1215 | 1215 | // Ensure both the start and end date are specified |
1216 | - if ( empty( $args['startdate'] ) || empty( $args['enddate'] ) ) { |
|
1217 | - $error['error'] = esc_html__( 'Invalid or no date range specified!', 'give' ); |
|
1216 | + if (empty($args['startdate']) || empty($args['enddate'])) { |
|
1217 | + $error['error'] = esc_html__('Invalid or no date range specified!', 'give'); |
|
1218 | 1218 | } |
1219 | 1219 | |
1220 | 1220 | $total = (float) 0.00; |
1221 | 1221 | |
1222 | 1222 | // Loop through the years |
1223 | 1223 | $y = $dates['year']; |
1224 | - if ( ! isset( $earnings['earnings'] ) ) { |
|
1224 | + if ( ! isset($earnings['earnings'])) { |
|
1225 | 1225 | $earnings['earnings'] = array(); |
1226 | 1226 | } |
1227 | - while ( $y <= $dates['year_end'] ) : |
|
1227 | + while ($y <= $dates['year_end']) : |
|
1228 | 1228 | |
1229 | - if ( $dates['year'] == $dates['year_end'] ) { |
|
1229 | + if ($dates['year'] == $dates['year_end']) { |
|
1230 | 1230 | $month_start = $dates['m_start']; |
1231 | 1231 | $month_end = $dates['m_end']; |
1232 | - } elseif ( $y == $dates['year'] && $dates['year_end'] > $dates['year'] ) { |
|
1232 | + } elseif ($y == $dates['year'] && $dates['year_end'] > $dates['year']) { |
|
1233 | 1233 | $month_start = $dates['m_start']; |
1234 | 1234 | $month_end = 12; |
1235 | - } elseif ( $y == $dates['year_end'] ) { |
|
1235 | + } elseif ($y == $dates['year_end']) { |
|
1236 | 1236 | $month_start = 1; |
1237 | 1237 | $month_end = $dates['m_end']; |
1238 | 1238 | } else { |
@@ -1241,92 +1241,92 @@ discard block |
||
1241 | 1241 | } |
1242 | 1242 | |
1243 | 1243 | $i = $month_start; |
1244 | - while ( $i <= $month_end ) : |
|
1244 | + while ($i <= $month_end) : |
|
1245 | 1245 | |
1246 | - if ( $i == $dates['m_start'] ) { |
|
1246 | + if ($i == $dates['m_start']) { |
|
1247 | 1247 | $d = $dates['day_start']; |
1248 | 1248 | } else { |
1249 | 1249 | $d = 1; |
1250 | 1250 | } |
1251 | 1251 | |
1252 | - if ( $i == $dates['m_end'] ) { |
|
1252 | + if ($i == $dates['m_end']) { |
|
1253 | 1253 | $num_of_days = $dates['day_end']; |
1254 | 1254 | } else { |
1255 | - $num_of_days = cal_days_in_month( CAL_GREGORIAN, $i, $y ); |
|
1255 | + $num_of_days = cal_days_in_month(CAL_GREGORIAN, $i, $y); |
|
1256 | 1256 | } |
1257 | 1257 | |
1258 | - while ( $d <= $num_of_days ) : |
|
1259 | - $earnings_stat = give_get_earnings_by_date( $d, $i, $y ); |
|
1260 | - $date_key = date( 'Ymd', strtotime( $y . '/' . $i . '/' . $d ) ); |
|
1261 | - if ( ! isset( $earnings['earnings'][ $date_key ] ) ) { |
|
1262 | - $earnings['earnings'][ $date_key ] = 0; |
|
1258 | + while ($d <= $num_of_days) : |
|
1259 | + $earnings_stat = give_get_earnings_by_date($d, $i, $y); |
|
1260 | + $date_key = date('Ymd', strtotime($y.'/'.$i.'/'.$d)); |
|
1261 | + if ( ! isset($earnings['earnings'][$date_key])) { |
|
1262 | + $earnings['earnings'][$date_key] = 0; |
|
1263 | 1263 | } |
1264 | - $earnings['earnings'][ $date_key ] += $earnings_stat; |
|
1264 | + $earnings['earnings'][$date_key] += $earnings_stat; |
|
1265 | 1265 | $total += $earnings_stat; |
1266 | - $d ++; |
|
1266 | + $d++; |
|
1267 | 1267 | endwhile; |
1268 | 1268 | |
1269 | - $i ++; |
|
1269 | + $i++; |
|
1270 | 1270 | endwhile; |
1271 | 1271 | |
1272 | - $y ++; |
|
1272 | + $y++; |
|
1273 | 1273 | endwhile; |
1274 | 1274 | |
1275 | 1275 | $earnings['totals'] = $total; |
1276 | 1276 | } else { |
1277 | - if ( $args['date'] == 'this_quarter' || $args['date'] == 'last_quarter' ) { |
|
1277 | + if ($args['date'] == 'this_quarter' || $args['date'] == 'last_quarter') { |
|
1278 | 1278 | $earnings_count = (float) 0.00; |
1279 | 1279 | |
1280 | 1280 | // Loop through the months |
1281 | 1281 | $month = $dates['m_start']; |
1282 | 1282 | |
1283 | - while ( $month <= $dates['m_end'] ) : |
|
1284 | - $earnings_count += give_get_earnings_by_date( null, $month, $dates['year'] ); |
|
1285 | - $month ++; |
|
1283 | + while ($month <= $dates['m_end']) : |
|
1284 | + $earnings_count += give_get_earnings_by_date(null, $month, $dates['year']); |
|
1285 | + $month++; |
|
1286 | 1286 | endwhile; |
1287 | 1287 | |
1288 | - $earnings['earnings'][ $args['date'] ] = $earnings_count; |
|
1288 | + $earnings['earnings'][$args['date']] = $earnings_count; |
|
1289 | 1289 | } else { |
1290 | - $earnings['earnings'][ $args['date'] ] = give_get_earnings_by_date( $dates['day'], $dates['m_start'], $dates['year'] ); |
|
1290 | + $earnings['earnings'][$args['date']] = give_get_earnings_by_date($dates['day'], $dates['m_start'], $dates['year']); |
|
1291 | 1291 | } |
1292 | 1292 | } |
1293 | - } elseif ( $args['form'] == 'all' ) { |
|
1294 | - $forms = get_posts( array( 'post_type' => 'give_forms', 'nopaging' => true ) ); |
|
1293 | + } elseif ($args['form'] == 'all') { |
|
1294 | + $forms = get_posts(array('post_type' => 'give_forms', 'nopaging' => true)); |
|
1295 | 1295 | |
1296 | 1296 | $i = 0; |
1297 | - foreach ( $forms as $form_info ) { |
|
1298 | - $earnings['earnings'][ $i ] = array( $form_info->post_name => give_get_form_earnings_stats( $form_info->ID ) ); |
|
1299 | - $i ++; |
|
1297 | + foreach ($forms as $form_info) { |
|
1298 | + $earnings['earnings'][$i] = array($form_info->post_name => give_get_form_earnings_stats($form_info->ID)); |
|
1299 | + $i++; |
|
1300 | 1300 | } |
1301 | 1301 | } else { |
1302 | - if ( get_post_type( $args['form'] ) == 'give_forms' ) { |
|
1303 | - $form_info = get_post( $args['form'] ); |
|
1304 | - $earnings['earnings'][0] = array( $form_info->post_name => give_get_form_earnings_stats( $args['form'] ) ); |
|
1302 | + if (get_post_type($args['form']) == 'give_forms') { |
|
1303 | + $form_info = get_post($args['form']); |
|
1304 | + $earnings['earnings'][0] = array($form_info->post_name => give_get_form_earnings_stats($args['form'])); |
|
1305 | 1305 | } else { |
1306 | 1306 | $error['error'] = sprintf( |
1307 | 1307 | /* translators: %s: form */ |
1308 | - esc_html__( 'Form %s not found!', 'give' ), |
|
1308 | + esc_html__('Form %s not found!', 'give'), |
|
1309 | 1309 | $args['form'] |
1310 | 1310 | ); |
1311 | 1311 | } |
1312 | 1312 | } |
1313 | 1313 | |
1314 | - if ( ! empty( $error ) ) { |
|
1314 | + if ( ! empty($error)) { |
|
1315 | 1315 | return $error; |
1316 | 1316 | } |
1317 | 1317 | |
1318 | 1318 | return $earnings; |
1319 | - } elseif ( $args['type'] == 'donors' ) { |
|
1319 | + } elseif ($args['type'] == 'donors') { |
|
1320 | 1320 | $customers = new Give_DB_Customers(); |
1321 | 1321 | $stats['donations']['total_donors'] = $customers->count(); |
1322 | 1322 | |
1323 | 1323 | return $stats; |
1324 | 1324 | |
1325 | - } elseif ( empty( $args['type'] ) ) { |
|
1326 | - $stats = array_merge( $stats, $this->get_default_sales_stats() ); |
|
1327 | - $stats = array_merge( $stats, $this->get_default_earnings_stats() ); |
|
1325 | + } elseif (empty($args['type'])) { |
|
1326 | + $stats = array_merge($stats, $this->get_default_sales_stats()); |
|
1327 | + $stats = array_merge($stats, $this->get_default_earnings_stats()); |
|
1328 | 1328 | |
1329 | - return array( 'stats' => $stats ); |
|
1329 | + return array('stats' => $stats); |
|
1330 | 1330 | } |
1331 | 1331 | } |
1332 | 1332 | |
@@ -1342,18 +1342,18 @@ discard block |
||
1342 | 1342 | |
1343 | 1343 | $sales = array(); |
1344 | 1344 | |
1345 | - if ( ! user_can( $this->user_id, 'view_give_reports' ) && ! $this->override ) { |
|
1345 | + if ( ! user_can($this->user_id, 'view_give_reports') && ! $this->override) { |
|
1346 | 1346 | return $sales; |
1347 | 1347 | } |
1348 | 1348 | |
1349 | - if ( isset( $wp_query->query_vars['id'] ) ) { |
|
1349 | + if (isset($wp_query->query_vars['id'])) { |
|
1350 | 1350 | $query = array(); |
1351 | - $query[] = new Give_Payment( $wp_query->query_vars['id'] ); |
|
1352 | - } elseif ( isset( $wp_query->query_vars['purchasekey'] ) ) { |
|
1351 | + $query[] = new Give_Payment($wp_query->query_vars['id']); |
|
1352 | + } elseif (isset($wp_query->query_vars['purchasekey'])) { |
|
1353 | 1353 | $query = array(); |
1354 | - $query[] = give_get_payment_by( 'key', $wp_query->query_vars['purchasekey'] ); |
|
1355 | - } elseif ( isset( $wp_query->query_vars['email'] ) ) { |
|
1356 | - $args = array( |
|
1354 | + $query[] = give_get_payment_by('key', $wp_query->query_vars['purchasekey']); |
|
1355 | + } elseif (isset($wp_query->query_vars['email'])) { |
|
1356 | + $args = array( |
|
1357 | 1357 | 'fields' => 'ids', |
1358 | 1358 | 'meta_key' => '_give_payment_user_email', |
1359 | 1359 | 'meta_value' => $wp_query->query_vars['email'], |
@@ -1361,7 +1361,7 @@ discard block |
||
1361 | 1361 | 'page' => $this->get_paged(), |
1362 | 1362 | 'status' => 'publish' |
1363 | 1363 | ); |
1364 | - $query = give_get_payments( $args ); |
|
1364 | + $query = give_get_payments($args); |
|
1365 | 1365 | } else { |
1366 | 1366 | $args = array( |
1367 | 1367 | 'fields' => 'ids', |
@@ -1369,14 +1369,14 @@ discard block |
||
1369 | 1369 | 'page' => $this->get_paged(), |
1370 | 1370 | 'status' => 'publish' |
1371 | 1371 | ); |
1372 | - $query = give_get_payments( $args ); |
|
1372 | + $query = give_get_payments($args); |
|
1373 | 1373 | } |
1374 | - if ( $query ) { |
|
1374 | + if ($query) { |
|
1375 | 1375 | $i = 0; |
1376 | - foreach ( $query as $payment ) { |
|
1376 | + foreach ($query as $payment) { |
|
1377 | 1377 | |
1378 | - if ( is_numeric( $payment ) ) { |
|
1379 | - $payment = new Give_Payment( $payment ); |
|
1378 | + if (is_numeric($payment)) { |
|
1379 | + $payment = new Give_Payment($payment); |
|
1380 | 1380 | $payment_meta = $payment->get_meta(); |
1381 | 1381 | $user_info = $payment->user_info; |
1382 | 1382 | } else { |
@@ -1386,40 +1386,40 @@ discard block |
||
1386 | 1386 | $payment_meta = $payment->get_meta(); |
1387 | 1387 | $user_info = $payment->user_info; |
1388 | 1388 | |
1389 | - $first_name = isset( $user_info['first_name'] ) ? $user_info['first_name'] : ''; |
|
1390 | - $last_name = isset( $user_info['last_name'] ) ? $user_info['last_name'] : ''; |
|
1391 | - |
|
1392 | - $sales['donations'][ $i ]['ID'] = $payment->number; |
|
1393 | - $sales['donations'][ $i ]['transaction_id'] = $payment->transaction_id; |
|
1394 | - $sales['donations'][ $i ]['key'] = $payment->key; |
|
1395 | - $sales['donations'][ $i ]['total'] = $payment->total; |
|
1396 | - $sales['donations'][ $i ]['gateway'] = $payment->gateway; |
|
1397 | - $sales['donations'][ $i ]['name'] = $first_name . ' ' . $last_name; |
|
1398 | - $sales['donations'][ $i ]['fname'] = $first_name; |
|
1399 | - $sales['donations'][ $i ]['lname'] = $last_name; |
|
1400 | - $sales['donations'][ $i ]['email'] = $payment->email; |
|
1401 | - $sales['donations'][ $i ]['date'] = $payment->date; |
|
1402 | - |
|
1403 | - $form_id = isset( $payment_meta['form_id'] ) ? $payment_meta['form_id'] : $payment_meta; |
|
1404 | - $price = isset( $payment_meta['form_id'] ) ? give_get_form_price( $payment_meta['form_id'] ) : false; |
|
1405 | - $price_id = isset( $payment_meta['price_id'] ) ? $payment_meta['price_id'] : null; |
|
1406 | - |
|
1407 | - $sales['donations'][ $i ]['form']['id'] = $form_id; |
|
1408 | - $sales['donations'][ $i ]['form']['name'] = get_the_title( $payment_meta['form_id'] ); |
|
1409 | - $sales['donations'][ $i ]['form']['price'] = $price; |
|
1410 | - |
|
1411 | - if ( give_has_variable_prices( $form_id ) ) { |
|
1412 | - if ( isset( $payment_meta['price_id'] ) ) { |
|
1413 | - $price_name = give_get_price_option_name( $form_id, $payment_meta['price_id'], $payment->ID ); |
|
1414 | - $sales['donations'][ $i ]['form']['price_name'] = $price_name; |
|
1415 | - $sales['donations'][ $i ]['form']['price_id'] = $price_id; |
|
1416 | - $sales['donations'][ $i ]['form']['price'] = give_get_price_option_amount( $form_id, $price_id ); |
|
1389 | + $first_name = isset($user_info['first_name']) ? $user_info['first_name'] : ''; |
|
1390 | + $last_name = isset($user_info['last_name']) ? $user_info['last_name'] : ''; |
|
1391 | + |
|
1392 | + $sales['donations'][$i]['ID'] = $payment->number; |
|
1393 | + $sales['donations'][$i]['transaction_id'] = $payment->transaction_id; |
|
1394 | + $sales['donations'][$i]['key'] = $payment->key; |
|
1395 | + $sales['donations'][$i]['total'] = $payment->total; |
|
1396 | + $sales['donations'][$i]['gateway'] = $payment->gateway; |
|
1397 | + $sales['donations'][$i]['name'] = $first_name.' '.$last_name; |
|
1398 | + $sales['donations'][$i]['fname'] = $first_name; |
|
1399 | + $sales['donations'][$i]['lname'] = $last_name; |
|
1400 | + $sales['donations'][$i]['email'] = $payment->email; |
|
1401 | + $sales['donations'][$i]['date'] = $payment->date; |
|
1402 | + |
|
1403 | + $form_id = isset($payment_meta['form_id']) ? $payment_meta['form_id'] : $payment_meta; |
|
1404 | + $price = isset($payment_meta['form_id']) ? give_get_form_price($payment_meta['form_id']) : false; |
|
1405 | + $price_id = isset($payment_meta['price_id']) ? $payment_meta['price_id'] : null; |
|
1406 | + |
|
1407 | + $sales['donations'][$i]['form']['id'] = $form_id; |
|
1408 | + $sales['donations'][$i]['form']['name'] = get_the_title($payment_meta['form_id']); |
|
1409 | + $sales['donations'][$i]['form']['price'] = $price; |
|
1410 | + |
|
1411 | + if (give_has_variable_prices($form_id)) { |
|
1412 | + if (isset($payment_meta['price_id'])) { |
|
1413 | + $price_name = give_get_price_option_name($form_id, $payment_meta['price_id'], $payment->ID); |
|
1414 | + $sales['donations'][$i]['form']['price_name'] = $price_name; |
|
1415 | + $sales['donations'][$i]['form']['price_id'] = $price_id; |
|
1416 | + $sales['donations'][$i]['form']['price'] = give_get_price_option_amount($form_id, $price_id); |
|
1417 | 1417 | |
1418 | 1418 | } |
1419 | 1419 | } |
1420 | 1420 | |
1421 | 1421 | //Add custom meta to API |
1422 | - foreach ( $payment_meta as $meta_key => $meta_value ) { |
|
1422 | + foreach ($payment_meta as $meta_key => $meta_value) { |
|
1423 | 1423 | |
1424 | 1424 | $exceptions = array( |
1425 | 1425 | 'form_title', |
@@ -1432,19 +1432,19 @@ discard block |
||
1432 | 1432 | ); |
1433 | 1433 | |
1434 | 1434 | //Don't clutter up results with dupes |
1435 | - if ( in_array( $meta_key, $exceptions ) ) { |
|
1435 | + if (in_array($meta_key, $exceptions)) { |
|
1436 | 1436 | continue; |
1437 | 1437 | } |
1438 | 1438 | |
1439 | - $sales['donations'][ $i ]['payment_meta'][ $meta_key ] = $meta_value; |
|
1439 | + $sales['donations'][$i]['payment_meta'][$meta_key] = $meta_value; |
|
1440 | 1440 | |
1441 | 1441 | } |
1442 | 1442 | |
1443 | - $i ++; |
|
1443 | + $i++; |
|
1444 | 1444 | } |
1445 | 1445 | } |
1446 | 1446 | |
1447 | - return apply_filters( 'give_api_donations_endpoint', $sales ); |
|
1447 | + return apply_filters('give_api_donations_endpoint', $sales); |
|
1448 | 1448 | } |
1449 | 1449 | |
1450 | 1450 | /** |
@@ -1460,9 +1460,9 @@ discard block |
||
1460 | 1460 | public function get_output_format() { |
1461 | 1461 | global $wp_query; |
1462 | 1462 | |
1463 | - $format = isset( $wp_query->query_vars['format'] ) ? $wp_query->query_vars['format'] : 'json'; |
|
1463 | + $format = isset($wp_query->query_vars['format']) ? $wp_query->query_vars['format'] : 'json'; |
|
1464 | 1464 | |
1465 | - return apply_filters( 'give_api_output_format', $format ); |
|
1465 | + return apply_filters('give_api_output_format', $format); |
|
1466 | 1466 | } |
1467 | 1467 | |
1468 | 1468 | |
@@ -1479,8 +1479,8 @@ discard block |
||
1479 | 1479 | * |
1480 | 1480 | * @return void |
1481 | 1481 | */ |
1482 | - private function log_request( $data = array() ) { |
|
1483 | - if ( ! $this->log_requests ) { |
|
1482 | + private function log_request($data = array()) { |
|
1483 | + if ( ! $this->log_requests) { |
|
1484 | 1484 | return; |
1485 | 1485 | } |
1486 | 1486 | |
@@ -1496,36 +1496,36 @@ discard block |
||
1496 | 1496 | |
1497 | 1497 | $query = array( |
1498 | 1498 | 'give-api' => $wp_query->query_vars['give-api'], |
1499 | - 'key' => isset( $wp_query->query_vars['key'] ) ? $wp_query->query_vars['key'] : null, |
|
1500 | - 'token' => isset( $wp_query->query_vars['token'] ) ? $wp_query->query_vars['token'] : null, |
|
1501 | - 'query' => isset( $wp_query->query_vars['query'] ) ? $wp_query->query_vars['query'] : null, |
|
1502 | - 'type' => isset( $wp_query->query_vars['type'] ) ? $wp_query->query_vars['type'] : null, |
|
1503 | - 'form' => isset( $wp_query->query_vars['form'] ) ? $wp_query->query_vars['form'] : null, |
|
1504 | - 'customer' => isset( $wp_query->query_vars['customer'] ) ? $wp_query->query_vars['customer'] : null, |
|
1505 | - 'date' => isset( $wp_query->query_vars['date'] ) ? $wp_query->query_vars['date'] : null, |
|
1506 | - 'startdate' => isset( $wp_query->query_vars['startdate'] ) ? $wp_query->query_vars['startdate'] : null, |
|
1507 | - 'enddate' => isset( $wp_query->query_vars['enddate'] ) ? $wp_query->query_vars['enddate'] : null, |
|
1508 | - 'id' => isset( $wp_query->query_vars['id'] ) ? $wp_query->query_vars['id'] : null, |
|
1509 | - 'purchasekey' => isset( $wp_query->query_vars['purchasekey'] ) ? $wp_query->query_vars['purchasekey'] : null, |
|
1510 | - 'email' => isset( $wp_query->query_vars['email'] ) ? $wp_query->query_vars['email'] : null, |
|
1499 | + 'key' => isset($wp_query->query_vars['key']) ? $wp_query->query_vars['key'] : null, |
|
1500 | + 'token' => isset($wp_query->query_vars['token']) ? $wp_query->query_vars['token'] : null, |
|
1501 | + 'query' => isset($wp_query->query_vars['query']) ? $wp_query->query_vars['query'] : null, |
|
1502 | + 'type' => isset($wp_query->query_vars['type']) ? $wp_query->query_vars['type'] : null, |
|
1503 | + 'form' => isset($wp_query->query_vars['form']) ? $wp_query->query_vars['form'] : null, |
|
1504 | + 'customer' => isset($wp_query->query_vars['customer']) ? $wp_query->query_vars['customer'] : null, |
|
1505 | + 'date' => isset($wp_query->query_vars['date']) ? $wp_query->query_vars['date'] : null, |
|
1506 | + 'startdate' => isset($wp_query->query_vars['startdate']) ? $wp_query->query_vars['startdate'] : null, |
|
1507 | + 'enddate' => isset($wp_query->query_vars['enddate']) ? $wp_query->query_vars['enddate'] : null, |
|
1508 | + 'id' => isset($wp_query->query_vars['id']) ? $wp_query->query_vars['id'] : null, |
|
1509 | + 'purchasekey' => isset($wp_query->query_vars['purchasekey']) ? $wp_query->query_vars['purchasekey'] : null, |
|
1510 | + 'email' => isset($wp_query->query_vars['email']) ? $wp_query->query_vars['email'] : null, |
|
1511 | 1511 | ); |
1512 | 1512 | |
1513 | 1513 | $log_data = array( |
1514 | 1514 | 'log_type' => 'api_request', |
1515 | - 'post_excerpt' => http_build_query( $query ), |
|
1516 | - 'post_content' => ! empty( $data['error'] ) ? $data['error'] : '', |
|
1515 | + 'post_excerpt' => http_build_query($query), |
|
1516 | + 'post_content' => ! empty($data['error']) ? $data['error'] : '', |
|
1517 | 1517 | ); |
1518 | 1518 | |
1519 | 1519 | $log_meta = array( |
1520 | 1520 | 'request_ip' => give_get_ip(), |
1521 | 1521 | 'user' => $this->user_id, |
1522 | - 'key' => isset( $wp_query->query_vars['key'] ) ? $wp_query->query_vars['key'] : null, |
|
1523 | - 'token' => isset( $wp_query->query_vars['token'] ) ? $wp_query->query_vars['token'] : null, |
|
1522 | + 'key' => isset($wp_query->query_vars['key']) ? $wp_query->query_vars['key'] : null, |
|
1523 | + 'token' => isset($wp_query->query_vars['token']) ? $wp_query->query_vars['token'] : null, |
|
1524 | 1524 | 'time' => $data['request_speed'], |
1525 | 1525 | 'version' => $this->get_queried_version() |
1526 | 1526 | ); |
1527 | 1527 | |
1528 | - $give_logs->insert_log( $log_data, $log_meta ); |
|
1528 | + $give_logs->insert_log($log_data, $log_meta); |
|
1529 | 1529 | } |
1530 | 1530 | |
1531 | 1531 | |
@@ -1549,7 +1549,7 @@ discard block |
||
1549 | 1549 | * |
1550 | 1550 | * @param int $status_code |
1551 | 1551 | */ |
1552 | - public function output( $status_code = 200 ) { |
|
1552 | + public function output($status_code = 200) { |
|
1553 | 1553 | /** |
1554 | 1554 | * @var WP_Query $wp_query |
1555 | 1555 | */ |
@@ -1557,27 +1557,27 @@ discard block |
||
1557 | 1557 | |
1558 | 1558 | $format = $this->get_output_format(); |
1559 | 1559 | |
1560 | - status_header( $status_code ); |
|
1560 | + status_header($status_code); |
|
1561 | 1561 | |
1562 | - do_action( 'give_api_output_before', $this->data, $this, $format ); |
|
1562 | + do_action('give_api_output_before', $this->data, $this, $format); |
|
1563 | 1563 | |
1564 | - switch ( $format ) : |
|
1564 | + switch ($format) : |
|
1565 | 1565 | |
1566 | 1566 | case 'xml' : |
1567 | 1567 | |
1568 | - require_once GIVE_PLUGIN_DIR . 'includes/libraries/array2xml.php'; |
|
1569 | - $xml = Array2XML::createXML( 'give', $this->data ); |
|
1568 | + require_once GIVE_PLUGIN_DIR.'includes/libraries/array2xml.php'; |
|
1569 | + $xml = Array2XML::createXML('give', $this->data); |
|
1570 | 1570 | echo $xml->saveXML(); |
1571 | 1571 | |
1572 | 1572 | break; |
1573 | 1573 | |
1574 | 1574 | case 'json' : |
1575 | 1575 | |
1576 | - header( 'Content-Type: application/json' ); |
|
1577 | - if ( ! empty( $this->pretty_print ) ) { |
|
1578 | - echo json_encode( $this->data, $this->pretty_print ); |
|
1576 | + header('Content-Type: application/json'); |
|
1577 | + if ( ! empty($this->pretty_print)) { |
|
1578 | + echo json_encode($this->data, $this->pretty_print); |
|
1579 | 1579 | } else { |
1580 | - echo json_encode( $this->data ); |
|
1580 | + echo json_encode($this->data); |
|
1581 | 1581 | } |
1582 | 1582 | |
1583 | 1583 | break; |
@@ -1586,13 +1586,13 @@ discard block |
||
1586 | 1586 | default : |
1587 | 1587 | |
1588 | 1588 | // Allow other formats to be added via extensions |
1589 | - do_action( 'give_api_output_' . $format, $this->data, $this ); |
|
1589 | + do_action('give_api_output_'.$format, $this->data, $this); |
|
1590 | 1590 | |
1591 | 1591 | break; |
1592 | 1592 | |
1593 | 1593 | endswitch; |
1594 | 1594 | |
1595 | - do_action( 'give_api_output_after', $this->data, $this, $format ); |
|
1595 | + do_action('give_api_output_after', $this->data, $this, $format); |
|
1596 | 1596 | |
1597 | 1597 | give_die(); |
1598 | 1598 | } |
@@ -1609,37 +1609,37 @@ discard block |
||
1609 | 1609 | * |
1610 | 1610 | * @return void |
1611 | 1611 | */ |
1612 | - function user_key_field( $user ) { |
|
1612 | + function user_key_field($user) { |
|
1613 | 1613 | |
1614 | - if ( ( give_get_option( 'api_allow_user_keys', false ) || current_user_can( 'manage_give_settings' ) ) && current_user_can( 'edit_user', $user->ID ) ) { |
|
1615 | - $user = get_userdata( $user->ID ); |
|
1614 | + if ((give_get_option('api_allow_user_keys', false) || current_user_can('manage_give_settings')) && current_user_can('edit_user', $user->ID)) { |
|
1615 | + $user = get_userdata($user->ID); |
|
1616 | 1616 | ?> |
1617 | 1617 | <table class="form-table"> |
1618 | 1618 | <tbody> |
1619 | 1619 | <tr> |
1620 | 1620 | <th> |
1621 | - <?php esc_html_e( 'Give API Keys', 'give' ); ?> |
|
1621 | + <?php esc_html_e('Give API Keys', 'give'); ?> |
|
1622 | 1622 | </th> |
1623 | 1623 | <td> |
1624 | 1624 | <?php |
1625 | - $public_key = $this->get_user_public_key( $user->ID ); |
|
1626 | - $secret_key = $this->get_user_secret_key( $user->ID ); |
|
1625 | + $public_key = $this->get_user_public_key($user->ID); |
|
1626 | + $secret_key = $this->get_user_secret_key($user->ID); |
|
1627 | 1627 | ?> |
1628 | - <?php if ( empty( $user->give_user_public_key ) ) { ?> |
|
1628 | + <?php if (empty($user->give_user_public_key)) { ?> |
|
1629 | 1629 | <input name="give_set_api_key" type="checkbox" id="give_set_api_key" value="0"/> |
1630 | - <span class="description"><?php esc_html_e( 'Generate API Key', 'give' ); ?></span> |
|
1630 | + <span class="description"><?php esc_html_e('Generate API Key', 'give'); ?></span> |
|
1631 | 1631 | <?php } else { ?> |
1632 | - <strong style="display:inline-block; width: 125px;"><?php esc_html_e( 'Public key:', 'give' ); ?> </strong> |
|
1633 | - <input type="text" disabled="disabled" class="regular-text" id="publickey" value="<?php echo esc_attr( $public_key ); ?>"/> |
|
1632 | + <strong style="display:inline-block; width: 125px;"><?php esc_html_e('Public key:', 'give'); ?> </strong> |
|
1633 | + <input type="text" disabled="disabled" class="regular-text" id="publickey" value="<?php echo esc_attr($public_key); ?>"/> |
|
1634 | 1634 | <br/> |
1635 | - <strong style="display:inline-block; width: 125px;"><?php esc_html_e( 'Secret key:', 'give' ); ?> </strong> |
|
1636 | - <input type="text" disabled="disabled" class="regular-text" id="privatekey" value="<?php echo esc_attr( $secret_key ); ?>"/> |
|
1635 | + <strong style="display:inline-block; width: 125px;"><?php esc_html_e('Secret key:', 'give'); ?> </strong> |
|
1636 | + <input type="text" disabled="disabled" class="regular-text" id="privatekey" value="<?php echo esc_attr($secret_key); ?>"/> |
|
1637 | 1637 | <br/> |
1638 | - <strong style="display:inline-block; width: 125px;"><?php esc_html_e( 'Token:', 'give' ); ?> </strong> |
|
1639 | - <input type="text" disabled="disabled" class="regular-text" id="token" value="<?php echo esc_attr( $this->get_token( $user->ID ) ); ?>"/> |
|
1638 | + <strong style="display:inline-block; width: 125px;"><?php esc_html_e('Token:', 'give'); ?> </strong> |
|
1639 | + <input type="text" disabled="disabled" class="regular-text" id="token" value="<?php echo esc_attr($this->get_token($user->ID)); ?>"/> |
|
1640 | 1640 | <br/> |
1641 | 1641 | <input name="give_set_api_key" type="checkbox" id="give_set_api_key" value="0"/> |
1642 | - <span class="description"><label for="give_set_api_key"><?php esc_html_e( 'Revoke API Keys', 'give' ); ?></label></span> |
|
1642 | + <span class="description"><label for="give_set_api_key"><?php esc_html_e('Revoke API Keys', 'give'); ?></label></span> |
|
1643 | 1643 | <?php } ?> |
1644 | 1644 | </td> |
1645 | 1645 | </tr> |
@@ -1658,69 +1658,69 @@ discard block |
||
1658 | 1658 | * |
1659 | 1659 | * @return void |
1660 | 1660 | */ |
1661 | - public function process_api_key( $args ) { |
|
1661 | + public function process_api_key($args) { |
|
1662 | 1662 | |
1663 | - if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'give-api-nonce' ) ) { |
|
1663 | + if ( ! wp_verify_nonce($_REQUEST['_wpnonce'], 'give-api-nonce')) { |
|
1664 | 1664 | |
1665 | - wp_die( esc_html__( 'Nonce verification failed.', 'give' ), esc_html__( 'Error', 'give' ), array( 'response' => 403 ) ); |
|
1665 | + wp_die(esc_html__('Nonce verification failed.', 'give'), esc_html__('Error', 'give'), array('response' => 403)); |
|
1666 | 1666 | |
1667 | 1667 | } |
1668 | 1668 | |
1669 | - if ( empty( $args['user_id'] ) ) { |
|
1670 | - wp_die( esc_html__( 'User ID Required.', 'give' ), esc_html__( 'Error', 'give' ), array( 'response' => 401 ) ); |
|
1669 | + if (empty($args['user_id'])) { |
|
1670 | + wp_die(esc_html__('User ID Required.', 'give'), esc_html__('Error', 'give'), array('response' => 401)); |
|
1671 | 1671 | } |
1672 | 1672 | |
1673 | - if ( is_numeric( $args['user_id'] ) ) { |
|
1674 | - $user_id = isset( $args['user_id'] ) ? absint( $args['user_id'] ) : get_current_user_id(); |
|
1673 | + if (is_numeric($args['user_id'])) { |
|
1674 | + $user_id = isset($args['user_id']) ? absint($args['user_id']) : get_current_user_id(); |
|
1675 | 1675 | } else { |
1676 | - $userdata = get_user_by( 'login', $args['user_id'] ); |
|
1676 | + $userdata = get_user_by('login', $args['user_id']); |
|
1677 | 1677 | $user_id = $userdata->ID; |
1678 | 1678 | } |
1679 | - $process = isset( $args['give_api_process'] ) ? strtolower( $args['give_api_process'] ) : false; |
|
1679 | + $process = isset($args['give_api_process']) ? strtolower($args['give_api_process']) : false; |
|
1680 | 1680 | |
1681 | - if ( $user_id == get_current_user_id() && ! give_get_option( 'allow_user_api_keys' ) && ! current_user_can( 'manage_give_settings' ) ) { |
|
1681 | + if ($user_id == get_current_user_id() && ! give_get_option('allow_user_api_keys') && ! current_user_can('manage_give_settings')) { |
|
1682 | 1682 | wp_die( |
1683 | 1683 | sprintf( |
1684 | 1684 | /* translators: %s: process */ |
1685 | - esc_html__( 'You do not have permission to %s API keys for this user.', 'give' ), |
|
1685 | + esc_html__('You do not have permission to %s API keys for this user.', 'give'), |
|
1686 | 1686 | $process |
1687 | 1687 | ), |
1688 | - esc_html__( 'Error', 'give' ), |
|
1689 | - array( 'response' => 403 ) |
|
1688 | + esc_html__('Error', 'give'), |
|
1689 | + array('response' => 403) |
|
1690 | 1690 | ); |
1691 | - } elseif ( ! current_user_can( 'manage_give_settings' ) ) { |
|
1691 | + } elseif ( ! current_user_can('manage_give_settings')) { |
|
1692 | 1692 | wp_die( |
1693 | 1693 | sprintf( |
1694 | 1694 | /* translators: %s: process */ |
1695 | - esc_html__( 'You do not have permission to %s API keys for this user.', 'give' ), |
|
1695 | + esc_html__('You do not have permission to %s API keys for this user.', 'give'), |
|
1696 | 1696 | $process |
1697 | 1697 | ), |
1698 | - esc_html__( 'Error', 'give' ), |
|
1699 | - array( 'response' => 403 ) |
|
1698 | + esc_html__('Error', 'give'), |
|
1699 | + array('response' => 403) |
|
1700 | 1700 | ); |
1701 | 1701 | } |
1702 | 1702 | |
1703 | - switch ( $process ) { |
|
1703 | + switch ($process) { |
|
1704 | 1704 | case 'generate': |
1705 | - if ( $this->generate_api_key( $user_id ) ) { |
|
1706 | - delete_transient( 'give_total_api_keys' ); |
|
1707 | - wp_redirect( add_query_arg( 'give-message', 'api-key-generated', 'edit.php?post_type=give_forms&page=give-settings&tab=api' ) ); |
|
1705 | + if ($this->generate_api_key($user_id)) { |
|
1706 | + delete_transient('give_total_api_keys'); |
|
1707 | + wp_redirect(add_query_arg('give-message', 'api-key-generated', 'edit.php?post_type=give_forms&page=give-settings&tab=api')); |
|
1708 | 1708 | exit(); |
1709 | 1709 | } else { |
1710 | - wp_redirect( add_query_arg( 'give-message', 'api-key-failed', 'edit.php?post_type=give_forms&page=give-settings&tab=api' ) ); |
|
1710 | + wp_redirect(add_query_arg('give-message', 'api-key-failed', 'edit.php?post_type=give_forms&page=give-settings&tab=api')); |
|
1711 | 1711 | exit(); |
1712 | 1712 | } |
1713 | 1713 | break; |
1714 | 1714 | case 'regenerate': |
1715 | - $this->generate_api_key( $user_id, true ); |
|
1716 | - delete_transient( 'give_total_api_keys' ); |
|
1717 | - wp_redirect( add_query_arg( 'give-message', 'api-key-regenerated', 'edit.php?post_type=give_forms&page=give-settings&tab=api' ) ); |
|
1715 | + $this->generate_api_key($user_id, true); |
|
1716 | + delete_transient('give_total_api_keys'); |
|
1717 | + wp_redirect(add_query_arg('give-message', 'api-key-regenerated', 'edit.php?post_type=give_forms&page=give-settings&tab=api')); |
|
1718 | 1718 | exit(); |
1719 | 1719 | break; |
1720 | 1720 | case 'revoke': |
1721 | - $this->revoke_api_key( $user_id ); |
|
1722 | - delete_transient( 'give_total_api_keys' ); |
|
1723 | - wp_redirect( add_query_arg( 'give-message', 'api-key-revoked', 'edit.php?post_type=give_forms&page=give-settings&tab=api' ) ); |
|
1721 | + $this->revoke_api_key($user_id); |
|
1722 | + delete_transient('give_total_api_keys'); |
|
1723 | + wp_redirect(add_query_arg('give-message', 'api-key-revoked', 'edit.php?post_type=give_forms&page=give-settings&tab=api')); |
|
1724 | 1724 | exit(); |
1725 | 1725 | break; |
1726 | 1726 | default; |
@@ -1739,34 +1739,34 @@ discard block |
||
1739 | 1739 | * |
1740 | 1740 | * @return boolean True if (re)generated succesfully, false otherwise. |
1741 | 1741 | */ |
1742 | - public function generate_api_key( $user_id = 0, $regenerate = false ) { |
|
1742 | + public function generate_api_key($user_id = 0, $regenerate = false) { |
|
1743 | 1743 | |
1744 | - if ( empty( $user_id ) ) { |
|
1744 | + if (empty($user_id)) { |
|
1745 | 1745 | return false; |
1746 | 1746 | } |
1747 | 1747 | |
1748 | - $user = get_userdata( $user_id ); |
|
1748 | + $user = get_userdata($user_id); |
|
1749 | 1749 | |
1750 | - if ( ! $user ) { |
|
1750 | + if ( ! $user) { |
|
1751 | 1751 | return false; |
1752 | 1752 | } |
1753 | 1753 | |
1754 | - $public_key = $this->get_user_public_key( $user_id ); |
|
1755 | - $secret_key = $this->get_user_secret_key( $user_id ); |
|
1754 | + $public_key = $this->get_user_public_key($user_id); |
|
1755 | + $secret_key = $this->get_user_secret_key($user_id); |
|
1756 | 1756 | |
1757 | - if ( empty( $public_key ) || $regenerate == true ) { |
|
1758 | - $new_public_key = $this->generate_public_key( $user->user_email ); |
|
1759 | - $new_secret_key = $this->generate_private_key( $user->ID ); |
|
1757 | + if (empty($public_key) || $regenerate == true) { |
|
1758 | + $new_public_key = $this->generate_public_key($user->user_email); |
|
1759 | + $new_secret_key = $this->generate_private_key($user->ID); |
|
1760 | 1760 | } else { |
1761 | 1761 | return false; |
1762 | 1762 | } |
1763 | 1763 | |
1764 | - if ( $regenerate == true ) { |
|
1765 | - $this->revoke_api_key( $user->ID ); |
|
1764 | + if ($regenerate == true) { |
|
1765 | + $this->revoke_api_key($user->ID); |
|
1766 | 1766 | } |
1767 | 1767 | |
1768 | - update_user_meta( $user_id, $new_public_key, 'give_user_public_key' ); |
|
1769 | - update_user_meta( $user_id, $new_secret_key, 'give_user_secret_key' ); |
|
1768 | + update_user_meta($user_id, $new_public_key, 'give_user_public_key'); |
|
1769 | + update_user_meta($user_id, $new_secret_key, 'give_user_secret_key'); |
|
1770 | 1770 | |
1771 | 1771 | return true; |
1772 | 1772 | } |
@@ -1781,26 +1781,26 @@ discard block |
||
1781 | 1781 | * |
1782 | 1782 | * @return string |
1783 | 1783 | */ |
1784 | - public function revoke_api_key( $user_id = 0 ) { |
|
1784 | + public function revoke_api_key($user_id = 0) { |
|
1785 | 1785 | |
1786 | - if ( empty( $user_id ) ) { |
|
1786 | + if (empty($user_id)) { |
|
1787 | 1787 | return false; |
1788 | 1788 | } |
1789 | 1789 | |
1790 | - $user = get_userdata( $user_id ); |
|
1790 | + $user = get_userdata($user_id); |
|
1791 | 1791 | |
1792 | - if ( ! $user ) { |
|
1792 | + if ( ! $user) { |
|
1793 | 1793 | return false; |
1794 | 1794 | } |
1795 | 1795 | |
1796 | - $public_key = $this->get_user_public_key( $user_id ); |
|
1797 | - $secret_key = $this->get_user_secret_key( $user_id ); |
|
1798 | - if ( ! empty( $public_key ) ) { |
|
1799 | - delete_transient( md5( 'give_api_user_' . $public_key ) ); |
|
1800 | - delete_transient( md5( 'give_api_user_public_key' . $user_id ) ); |
|
1801 | - delete_transient( md5( 'give_api_user_secret_key' . $user_id ) ); |
|
1802 | - delete_user_meta( $user_id, $public_key ); |
|
1803 | - delete_user_meta( $user_id, $secret_key ); |
|
1796 | + $public_key = $this->get_user_public_key($user_id); |
|
1797 | + $secret_key = $this->get_user_secret_key($user_id); |
|
1798 | + if ( ! empty($public_key)) { |
|
1799 | + delete_transient(md5('give_api_user_'.$public_key)); |
|
1800 | + delete_transient(md5('give_api_user_public_key'.$user_id)); |
|
1801 | + delete_transient(md5('give_api_user_secret_key'.$user_id)); |
|
1802 | + delete_user_meta($user_id, $public_key); |
|
1803 | + delete_user_meta($user_id, $secret_key); |
|
1804 | 1804 | } else { |
1805 | 1805 | return false; |
1806 | 1806 | } |
@@ -1825,22 +1825,22 @@ discard block |
||
1825 | 1825 | * |
1826 | 1826 | * @return void |
1827 | 1827 | */ |
1828 | - public function update_key( $user_id ) { |
|
1829 | - if ( current_user_can( 'edit_user', $user_id ) && isset( $_POST['give_set_api_key'] ) ) { |
|
1828 | + public function update_key($user_id) { |
|
1829 | + if (current_user_can('edit_user', $user_id) && isset($_POST['give_set_api_key'])) { |
|
1830 | 1830 | |
1831 | - $user = get_userdata( $user_id ); |
|
1831 | + $user = get_userdata($user_id); |
|
1832 | 1832 | |
1833 | - $public_key = $this->get_user_public_key( $user_id ); |
|
1834 | - $secret_key = $this->get_user_secret_key( $user_id ); |
|
1833 | + $public_key = $this->get_user_public_key($user_id); |
|
1834 | + $secret_key = $this->get_user_secret_key($user_id); |
|
1835 | 1835 | |
1836 | - if ( empty( $public_key ) ) { |
|
1837 | - $new_public_key = $this->generate_public_key( $user->user_email ); |
|
1838 | - $new_secret_key = $this->generate_private_key( $user->ID ); |
|
1836 | + if (empty($public_key)) { |
|
1837 | + $new_public_key = $this->generate_public_key($user->user_email); |
|
1838 | + $new_secret_key = $this->generate_private_key($user->ID); |
|
1839 | 1839 | |
1840 | - update_user_meta( $user_id, $new_public_key, 'give_user_public_key' ); |
|
1841 | - update_user_meta( $user_id, $new_secret_key, 'give_user_secret_key' ); |
|
1840 | + update_user_meta($user_id, $new_public_key, 'give_user_public_key'); |
|
1841 | + update_user_meta($user_id, $new_secret_key, 'give_user_secret_key'); |
|
1842 | 1842 | } else { |
1843 | - $this->revoke_api_key( $user_id ); |
|
1843 | + $this->revoke_api_key($user_id); |
|
1844 | 1844 | } |
1845 | 1845 | } |
1846 | 1846 | } |
@@ -1855,9 +1855,9 @@ discard block |
||
1855 | 1855 | * |
1856 | 1856 | * @return string |
1857 | 1857 | */ |
1858 | - private function generate_public_key( $user_email = '' ) { |
|
1859 | - $auth_key = defined( 'AUTH_KEY' ) ? AUTH_KEY : ''; |
|
1860 | - $public = hash( 'md5', $user_email . $auth_key . date( 'U' ) ); |
|
1858 | + private function generate_public_key($user_email = '') { |
|
1859 | + $auth_key = defined('AUTH_KEY') ? AUTH_KEY : ''; |
|
1860 | + $public = hash('md5', $user_email.$auth_key.date('U')); |
|
1861 | 1861 | |
1862 | 1862 | return $public; |
1863 | 1863 | } |
@@ -1872,9 +1872,9 @@ discard block |
||
1872 | 1872 | * |
1873 | 1873 | * @return string |
1874 | 1874 | */ |
1875 | - private function generate_private_key( $user_id = 0 ) { |
|
1876 | - $auth_key = defined( 'AUTH_KEY' ) ? AUTH_KEY : ''; |
|
1877 | - $secret = hash( 'md5', $user_id . $auth_key . date( 'U' ) ); |
|
1875 | + private function generate_private_key($user_id = 0) { |
|
1876 | + $auth_key = defined('AUTH_KEY') ? AUTH_KEY : ''; |
|
1877 | + $secret = hash('md5', $user_id.$auth_key.date('U')); |
|
1878 | 1878 | |
1879 | 1879 | return $secret; |
1880 | 1880 | } |
@@ -1889,8 +1889,8 @@ discard block |
||
1889 | 1889 | * |
1890 | 1890 | * @return string |
1891 | 1891 | */ |
1892 | - public function get_token( $user_id = 0 ) { |
|
1893 | - return hash( 'md5', $this->get_user_secret_key( $user_id ) . $this->get_user_public_key( $user_id ) ); |
|
1892 | + public function get_token($user_id = 0) { |
|
1893 | + return hash('md5', $this->get_user_secret_key($user_id).$this->get_user_public_key($user_id)); |
|
1894 | 1894 | } |
1895 | 1895 | |
1896 | 1896 | /** |
@@ -1904,9 +1904,9 @@ discard block |
||
1904 | 1904 | |
1905 | 1905 | // Default sales return |
1906 | 1906 | $sales = array(); |
1907 | - $sales['donations']['today'] = $this->stats->get_sales( 0, 'today' ); |
|
1908 | - $sales['donations']['current_month'] = $this->stats->get_sales( 0, 'this_month' ); |
|
1909 | - $sales['donations']['last_month'] = $this->stats->get_sales( 0, 'last_month' ); |
|
1907 | + $sales['donations']['today'] = $this->stats->get_sales(0, 'today'); |
|
1908 | + $sales['donations']['current_month'] = $this->stats->get_sales(0, 'this_month'); |
|
1909 | + $sales['donations']['last_month'] = $this->stats->get_sales(0, 'last_month'); |
|
1910 | 1910 | $sales['donations']['totals'] = give_get_total_sales(); |
1911 | 1911 | |
1912 | 1912 | return $sales; |
@@ -1923,9 +1923,9 @@ discard block |
||
1923 | 1923 | |
1924 | 1924 | // Default earnings return |
1925 | 1925 | $earnings = array(); |
1926 | - $earnings['earnings']['today'] = $this->stats->get_earnings( 0, 'today' ); |
|
1927 | - $earnings['earnings']['current_month'] = $this->stats->get_earnings( 0, 'this_month' ); |
|
1928 | - $earnings['earnings']['last_month'] = $this->stats->get_earnings( 0, 'last_month' ); |
|
1926 | + $earnings['earnings']['today'] = $this->stats->get_earnings(0, 'today'); |
|
1927 | + $earnings['earnings']['current_month'] = $this->stats->get_earnings(0, 'this_month'); |
|
1928 | + $earnings['earnings']['last_month'] = $this->stats->get_earnings(0, 'last_month'); |
|
1929 | 1929 | $earnings['earnings']['totals'] = give_get_total_earnings(); |
1930 | 1930 | |
1931 | 1931 | return $earnings; |
@@ -1945,25 +1945,25 @@ discard block |
||
1945 | 1945 | * |
1946 | 1946 | * @return string The API key/secret for the user supplied |
1947 | 1947 | */ |
1948 | - public function api_key_backwards_compat( $check, $object_id, $meta_key, $single ) { |
|
1948 | + public function api_key_backwards_compat($check, $object_id, $meta_key, $single) { |
|
1949 | 1949 | |
1950 | - if ( $meta_key !== 'give_user_public_key' && $meta_key !== 'give_user_secret_key' ) { |
|
1950 | + if ($meta_key !== 'give_user_public_key' && $meta_key !== 'give_user_secret_key') { |
|
1951 | 1951 | return $check; |
1952 | 1952 | } |
1953 | 1953 | |
1954 | 1954 | $return = $check; |
1955 | 1955 | |
1956 | - switch ( $meta_key ) { |
|
1956 | + switch ($meta_key) { |
|
1957 | 1957 | case 'give_user_public_key': |
1958 | - $return = Give()->api->get_user_public_key( $object_id ); |
|
1958 | + $return = Give()->api->get_user_public_key($object_id); |
|
1959 | 1959 | break; |
1960 | 1960 | case 'give_user_secret_key': |
1961 | - $return = Give()->api->get_user_secret_key( $object_id ); |
|
1961 | + $return = Give()->api->get_user_secret_key($object_id); |
|
1962 | 1962 | break; |
1963 | 1963 | } |
1964 | 1964 | |
1965 | - if ( ! $single ) { |
|
1966 | - $return = array( $return ); |
|
1965 | + if ( ! $single) { |
|
1966 | + $return = array($return); |
|
1967 | 1967 | } |
1968 | 1968 | |
1969 | 1969 | return $return; |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | |
92 | 92 | //validate display_style and float_labels value |
93 | 93 | if ( ( $key == 'display_style' && ! in_array( $value, array( 'onpage', 'reveal', 'modal' ) ) ) |
94 | - || ( $key == 'float_labels' && ! in_array( $value, array( 'enabled', 'disabled' ) ) ) |
|
94 | + || ( $key == 'float_labels' && ! in_array( $value, array( 'enabled', 'disabled' ) ) ) |
|
95 | 95 | ) { |
96 | 96 | |
97 | 97 | $atts[ $key ] = ''; |
@@ -169,15 +169,15 @@ discard block |
||
169 | 169 | */ |
170 | 170 | function give_login_form_shortcode( $atts, $content = null ) { |
171 | 171 | $atts = shortcode_atts( array( |
172 | - // Add backward compatibility for redirect attribute. |
|
173 | - 'redirect' => '', |
|
172 | + // Add backward compatibility for redirect attribute. |
|
173 | + 'redirect' => '', |
|
174 | 174 | |
175 | 175 | 'login-redirect' => '', |
176 | 176 | 'logout-redirect' => '', |
177 | 177 | ), $atts, 'give_login' ); |
178 | 178 | |
179 | - // Check login-redirect attribute first, if it empty or not found then check for redirect attribute and add value of this to login-redirect attribute. |
|
180 | - $atts['login-redirect'] = ! empty( $atts['login-redirect'] ) ? $atts['login-redirect'] : ( ! empty( $atts['redirect' ] ) ? $atts['redirect'] : '' ); |
|
179 | + // Check login-redirect attribute first, if it empty or not found then check for redirect attribute and add value of this to login-redirect attribute. |
|
180 | + $atts['login-redirect'] = ! empty( $atts['login-redirect'] ) ? $atts['login-redirect'] : ( ! empty( $atts['redirect' ] ) ? $atts['redirect'] : '' ); |
|
181 | 181 | |
182 | 182 | return give_login_form( $atts['login-redirect'], $atts['logout-redirect'] ); |
183 | 183 | } |
@@ -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 | |
@@ -25,28 +25,28 @@ discard block |
||
25 | 25 | */ |
26 | 26 | function give_donation_history() { |
27 | 27 | |
28 | - $email_access = give_get_option( 'email_access' ); |
|
28 | + $email_access = give_get_option('email_access'); |
|
29 | 29 | |
30 | 30 | //Is user logged in? Does a session exist? Does an email-access token exist? |
31 | - if ( is_user_logged_in() || Give()->session->get_session_expiration() !== false || ( $email_access == 'on' && Give()->email_access->token_exists ) ) { |
|
31 | + if (is_user_logged_in() || Give()->session->get_session_expiration() !== false || ($email_access == 'on' && Give()->email_access->token_exists)) { |
|
32 | 32 | ob_start(); |
33 | - give_get_template_part( 'history', 'donations' ); |
|
33 | + give_get_template_part('history', 'donations'); |
|
34 | 34 | |
35 | 35 | return ob_get_clean(); |
36 | 36 | } //Is Email-based access enabled? |
37 | - elseif ( $email_access == 'on' ) { |
|
37 | + elseif ($email_access == 'on') { |
|
38 | 38 | |
39 | 39 | ob_start(); |
40 | - give_get_template_part( 'email', 'login-form' ); |
|
40 | + give_get_template_part('email', 'login-form'); |
|
41 | 41 | |
42 | 42 | return ob_get_clean(); |
43 | 43 | } else { |
44 | - $message = esc_html__( 'You must be logged in to view your donation history. Please login using your account or create an account using the same email you used to donate with.', 'give' ); |
|
45 | - echo apply_filters( 'give_donation_history_nonuser_message', give_output_error( $message, false ), $message ); |
|
44 | + $message = esc_html__('You must be logged in to view your donation history. Please login using your account or create an account using the same email you used to donate with.', 'give'); |
|
45 | + echo apply_filters('give_donation_history_nonuser_message', give_output_error($message, false), $message); |
|
46 | 46 | } |
47 | 47 | } |
48 | 48 | |
49 | -add_shortcode( 'donation_history', 'give_donation_history' ); |
|
49 | +add_shortcode('donation_history', 'give_donation_history'); |
|
50 | 50 | |
51 | 51 | /** |
52 | 52 | * Donation Form Shortcode |
@@ -60,53 +60,53 @@ discard block |
||
60 | 60 | * |
61 | 61 | * @return string |
62 | 62 | */ |
63 | -function give_form_shortcode( $atts, $content = null ) { |
|
64 | - $atts = shortcode_atts( array( |
|
63 | +function give_form_shortcode($atts, $content = null) { |
|
64 | + $atts = shortcode_atts(array( |
|
65 | 65 | 'id' => '', |
66 | 66 | 'show_title' => true, |
67 | 67 | 'show_goal' => true, |
68 | 68 | 'show_content' => '', |
69 | 69 | 'float_labels' => '', |
70 | 70 | 'display_style' => '', |
71 | - ), $atts, 'give_form' ); |
|
71 | + ), $atts, 'give_form'); |
|
72 | 72 | |
73 | - foreach ( $atts as $key => $value ) { |
|
73 | + foreach ($atts as $key => $value) { |
|
74 | 74 | //convert shortcode_atts values to booleans |
75 | - if ( $key == 'show_title' ) { |
|
76 | - $atts[ $key ] = filter_var( $atts[ $key ], FILTER_VALIDATE_BOOLEAN ); |
|
77 | - } elseif ( $key == 'show_goal' ) { |
|
78 | - $atts[ $key ] = filter_var( $atts[ $key ], FILTER_VALIDATE_BOOLEAN ); |
|
75 | + if ($key == 'show_title') { |
|
76 | + $atts[$key] = filter_var($atts[$key], FILTER_VALIDATE_BOOLEAN); |
|
77 | + } elseif ($key == 'show_goal') { |
|
78 | + $atts[$key] = filter_var($atts[$key], FILTER_VALIDATE_BOOLEAN); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | //validate show_content value |
82 | - if ( $key == 'show_content' ) { |
|
83 | - if ( ! in_array( $value, array( 'none', 'above', 'below' ) ) ) { |
|
84 | - $atts[ $key ] = ''; |
|
85 | - } else if ( $value == 'above' ) { |
|
86 | - $atts[ $key ] = 'give_pre_form'; |
|
87 | - } else if ( $value == 'below' ) { |
|
88 | - $atts[ $key ] = 'give_post_form'; |
|
82 | + if ($key == 'show_content') { |
|
83 | + if ( ! in_array($value, array('none', 'above', 'below'))) { |
|
84 | + $atts[$key] = ''; |
|
85 | + } else if ($value == 'above') { |
|
86 | + $atts[$key] = 'give_pre_form'; |
|
87 | + } else if ($value == 'below') { |
|
88 | + $atts[$key] = 'give_post_form'; |
|
89 | 89 | } |
90 | 90 | } |
91 | 91 | |
92 | 92 | //validate display_style and float_labels value |
93 | - if ( ( $key == 'display_style' && ! in_array( $value, array( 'onpage', 'reveal', 'modal' ) ) ) |
|
94 | - || ( $key == 'float_labels' && ! in_array( $value, array( 'enabled', 'disabled' ) ) ) |
|
93 | + if (($key == 'display_style' && ! in_array($value, array('onpage', 'reveal', 'modal'))) |
|
94 | + || ($key == 'float_labels' && ! in_array($value, array('enabled', 'disabled'))) |
|
95 | 95 | ) { |
96 | 96 | |
97 | - $atts[ $key ] = ''; |
|
97 | + $atts[$key] = ''; |
|
98 | 98 | } |
99 | 99 | } |
100 | 100 | |
101 | 101 | //get the Give Form |
102 | 102 | ob_start(); |
103 | - give_get_donation_form( $atts ); |
|
103 | + give_get_donation_form($atts); |
|
104 | 104 | $final_output = ob_get_clean(); |
105 | 105 | |
106 | - return apply_filters( 'give_donate_form', $final_output, $atts ); |
|
106 | + return apply_filters('give_donate_form', $final_output, $atts); |
|
107 | 107 | } |
108 | 108 | |
109 | -add_shortcode( 'give_form', 'give_form_shortcode' ); |
|
109 | +add_shortcode('give_form', 'give_form_shortcode'); |
|
110 | 110 | |
111 | 111 | /** |
112 | 112 | * Donation Form Goal Shortcode. |
@@ -120,37 +120,37 @@ discard block |
||
120 | 120 | * |
121 | 121 | * @return string |
122 | 122 | */ |
123 | -function give_goal_shortcode( $atts, $content = null ) { |
|
124 | - $atts = shortcode_atts( array( |
|
123 | +function give_goal_shortcode($atts, $content = null) { |
|
124 | + $atts = shortcode_atts(array( |
|
125 | 125 | 'id' => '', |
126 | 126 | 'show_text' => true, |
127 | 127 | 'show_bar' => true, |
128 | - ), $atts, 'give_goal' ); |
|
128 | + ), $atts, 'give_goal'); |
|
129 | 129 | |
130 | 130 | |
131 | 131 | //get the Give Form. |
132 | 132 | ob_start(); |
133 | 133 | |
134 | 134 | //Sanity check 1: ensure there is an ID Provided. |
135 | - if ( empty( $atts['id'] ) ) { |
|
136 | - give_output_error( esc_html__( 'Error: No Donation form ID for the shortcode provided.', 'give' ), true ); |
|
135 | + if (empty($atts['id'])) { |
|
136 | + give_output_error(esc_html__('Error: No Donation form ID for the shortcode provided.', 'give'), true); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | //Sanity check 2: Check that this form even has Goals enabled. |
140 | - $goal_option = get_post_meta( $atts['id'], '_give_goal_option', true ); |
|
141 | - if ( empty( $goal_option ) || $goal_option !== 'yes' ) { |
|
142 | - give_output_error( esc_html__( 'Error: This form does not have Goals enabled.', 'give' ), true ); |
|
140 | + $goal_option = get_post_meta($atts['id'], '_give_goal_option', true); |
|
141 | + if (empty($goal_option) || $goal_option !== 'yes') { |
|
142 | + give_output_error(esc_html__('Error: This form does not have Goals enabled.', 'give'), true); |
|
143 | 143 | } else { |
144 | 144 | //Passed all sanity checks: output Goal. |
145 | - give_show_goal_progress( $atts['id'], $atts ); |
|
145 | + give_show_goal_progress($atts['id'], $atts); |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | $final_output = ob_get_clean(); |
149 | 149 | |
150 | - return apply_filters( 'give_goal_shortcode_output', $final_output, $atts ); |
|
150 | + return apply_filters('give_goal_shortcode_output', $final_output, $atts); |
|
151 | 151 | } |
152 | 152 | |
153 | -add_shortcode( 'give_goal', 'give_goal_shortcode' ); |
|
153 | +add_shortcode('give_goal', 'give_goal_shortcode'); |
|
154 | 154 | |
155 | 155 | |
156 | 156 | /** |
@@ -167,22 +167,22 @@ discard block |
||
167 | 167 | * @uses give_login_form() |
168 | 168 | * @return string |
169 | 169 | */ |
170 | -function give_login_form_shortcode( $atts, $content = null ) { |
|
171 | - $atts = shortcode_atts( array( |
|
170 | +function give_login_form_shortcode($atts, $content = null) { |
|
171 | + $atts = shortcode_atts(array( |
|
172 | 172 | // Add backward compatibility for redirect attribute. |
173 | 173 | 'redirect' => '', |
174 | 174 | |
175 | 175 | 'login-redirect' => '', |
176 | 176 | 'logout-redirect' => '', |
177 | - ), $atts, 'give_login' ); |
|
177 | + ), $atts, 'give_login'); |
|
178 | 178 | |
179 | 179 | // Check login-redirect attribute first, if it empty or not found then check for redirect attribute and add value of this to login-redirect attribute. |
180 | - $atts['login-redirect'] = ! empty( $atts['login-redirect'] ) ? $atts['login-redirect'] : ( ! empty( $atts['redirect' ] ) ? $atts['redirect'] : '' ); |
|
180 | + $atts['login-redirect'] = ! empty($atts['login-redirect']) ? $atts['login-redirect'] : ( ! empty($atts['redirect']) ? $atts['redirect'] : ''); |
|
181 | 181 | |
182 | - return give_login_form( $atts['login-redirect'], $atts['logout-redirect'] ); |
|
182 | + return give_login_form($atts['login-redirect'], $atts['logout-redirect']); |
|
183 | 183 | } |
184 | 184 | |
185 | -add_shortcode( 'give_login', 'give_login_form_shortcode' ); |
|
185 | +add_shortcode('give_login', 'give_login_form_shortcode'); |
|
186 | 186 | |
187 | 187 | /** |
188 | 188 | * Register Shortcode. |
@@ -197,15 +197,15 @@ discard block |
||
197 | 197 | * @uses give_register_form() |
198 | 198 | * @return string |
199 | 199 | */ |
200 | -function give_register_form_shortcode( $atts, $content = null ) { |
|
201 | - $atts = shortcode_atts( array( |
|
200 | +function give_register_form_shortcode($atts, $content = null) { |
|
201 | + $atts = shortcode_atts(array( |
|
202 | 202 | 'redirect' => '', |
203 | - ), $atts, 'give_register' ); |
|
203 | + ), $atts, 'give_register'); |
|
204 | 204 | |
205 | - return give_register_form( $atts['redirect'] ); |
|
205 | + return give_register_form($atts['redirect']); |
|
206 | 206 | } |
207 | 207 | |
208 | -add_shortcode( 'give_register', 'give_register_form_shortcode' ); |
|
208 | +add_shortcode('give_register', 'give_register_form_shortcode'); |
|
209 | 209 | |
210 | 210 | |
211 | 211 | /** |
@@ -220,62 +220,62 @@ discard block |
||
220 | 220 | * |
221 | 221 | * @return string |
222 | 222 | */ |
223 | -function give_receipt_shortcode( $atts, $content = null ) { |
|
223 | +function give_receipt_shortcode($atts, $content = null) { |
|
224 | 224 | |
225 | 225 | global $give_receipt_args, $payment; |
226 | 226 | |
227 | - $give_receipt_args = shortcode_atts( array( |
|
228 | - 'error' => esc_html__( 'Sorry, you are missing the payment key to view this donation receipt.', 'give' ), |
|
227 | + $give_receipt_args = shortcode_atts(array( |
|
228 | + 'error' => esc_html__('Sorry, you are missing the payment key to view this donation receipt.', 'give'), |
|
229 | 229 | 'price' => true, |
230 | 230 | 'donor' => true, |
231 | 231 | 'date' => true, |
232 | 232 | 'payment_key' => false, |
233 | 233 | 'payment_method' => true, |
234 | 234 | 'payment_id' => true |
235 | - ), $atts, 'give_receipt' ); |
|
235 | + ), $atts, 'give_receipt'); |
|
236 | 236 | |
237 | 237 | //set $session var |
238 | 238 | $session = give_get_purchase_session(); |
239 | 239 | |
240 | 240 | //set payment key var |
241 | - if ( isset( $_GET['payment_key'] ) ) { |
|
242 | - $payment_key = urldecode( $_GET['payment_key'] ); |
|
243 | - } elseif ( $session ) { |
|
241 | + if (isset($_GET['payment_key'])) { |
|
242 | + $payment_key = urldecode($_GET['payment_key']); |
|
243 | + } elseif ($session) { |
|
244 | 244 | $payment_key = $session['purchase_key']; |
245 | - } elseif ( $give_receipt_args['payment_key'] ) { |
|
245 | + } elseif ($give_receipt_args['payment_key']) { |
|
246 | 246 | $payment_key = $give_receipt_args['payment_key']; |
247 | 247 | } |
248 | 248 | |
249 | - $email_access = give_get_option( 'email_access' ); |
|
249 | + $email_access = give_get_option('email_access'); |
|
250 | 250 | |
251 | 251 | // No payment_key found & Email Access is Turned on: |
252 | - if ( ! isset( $payment_key ) && $email_access == 'on' && ! Give()->email_access->token_exists ) { |
|
252 | + if ( ! isset($payment_key) && $email_access == 'on' && ! Give()->email_access->token_exists) { |
|
253 | 253 | |
254 | 254 | ob_start(); |
255 | 255 | |
256 | - give_get_template_part( 'email-login-form' ); |
|
256 | + give_get_template_part('email-login-form'); |
|
257 | 257 | |
258 | 258 | return ob_get_clean(); |
259 | 259 | |
260 | - } elseif ( ! isset( $payment_key ) ) { |
|
260 | + } elseif ( ! isset($payment_key)) { |
|
261 | 261 | |
262 | - return give_output_error( $give_receipt_args['error'], false, 'error' ); |
|
262 | + return give_output_error($give_receipt_args['error'], false, 'error'); |
|
263 | 263 | |
264 | 264 | } |
265 | 265 | |
266 | - $payment_id = give_get_purchase_id_by_key( $payment_key ); |
|
267 | - $user_can_view = give_can_view_receipt( $payment_key ); |
|
266 | + $payment_id = give_get_purchase_id_by_key($payment_key); |
|
267 | + $user_can_view = give_can_view_receipt($payment_key); |
|
268 | 268 | |
269 | 269 | // Key was provided, but user is logged out. Offer them the ability to login and view the receipt. |
270 | - if ( ! $user_can_view && $email_access == 'on' && ! Give()->email_access->token_exists ) { |
|
270 | + if ( ! $user_can_view && $email_access == 'on' && ! Give()->email_access->token_exists) { |
|
271 | 271 | |
272 | 272 | ob_start(); |
273 | 273 | |
274 | - give_get_template_part( 'email-login-form' ); |
|
274 | + give_get_template_part('email-login-form'); |
|
275 | 275 | |
276 | 276 | return ob_get_clean(); |
277 | 277 | |
278 | - } elseif ( ! $user_can_view ) { |
|
278 | + } elseif ( ! $user_can_view) { |
|
279 | 279 | |
280 | 280 | global $give_login_redirect; |
281 | 281 | |
@@ -283,9 +283,9 @@ discard block |
||
283 | 283 | |
284 | 284 | ob_start(); |
285 | 285 | |
286 | - give_output_error( apply_filters( 'give_must_be_logged_in_error_message', esc_html__( 'You must be logged in to view this donation payment receipt.', 'give' ) ) ); |
|
286 | + give_output_error(apply_filters('give_must_be_logged_in_error_message', esc_html__('You must be logged in to view this donation payment receipt.', 'give'))); |
|
287 | 287 | |
288 | - give_get_template_part( 'shortcode', 'login' ); |
|
288 | + give_get_template_part('shortcode', 'login'); |
|
289 | 289 | |
290 | 290 | $login_form = ob_get_clean(); |
291 | 291 | |
@@ -300,13 +300,13 @@ discard block |
||
300 | 300 | * or if user is logged in and the user can view sensitive shop data. |
301 | 301 | * |
302 | 302 | */ |
303 | - if ( ! apply_filters( 'give_user_can_view_receipt', $user_can_view, $give_receipt_args ) ) { |
|
304 | - return give_output_error( $give_receipt_args['error'], false, 'error' ); |
|
303 | + if ( ! apply_filters('give_user_can_view_receipt', $user_can_view, $give_receipt_args)) { |
|
304 | + return give_output_error($give_receipt_args['error'], false, 'error'); |
|
305 | 305 | } |
306 | 306 | |
307 | 307 | ob_start(); |
308 | 308 | |
309 | - give_get_template_part( 'shortcode', 'receipt' ); |
|
309 | + give_get_template_part('shortcode', 'receipt'); |
|
310 | 310 | |
311 | 311 | $display = ob_get_clean(); |
312 | 312 | |
@@ -315,7 +315,7 @@ discard block |
||
315 | 315 | |
316 | 316 | } |
317 | 317 | |
318 | -add_shortcode( 'give_receipt', 'give_receipt_shortcode' ); |
|
318 | +add_shortcode('give_receipt', 'give_receipt_shortcode'); |
|
319 | 319 | |
320 | 320 | /** |
321 | 321 | * Profile Editor Shortcode. |
@@ -335,18 +335,18 @@ discard block |
||
335 | 335 | * |
336 | 336 | * @return string Output generated from the profile editor |
337 | 337 | */ |
338 | -function give_profile_editor_shortcode( $atts, $content = null ) { |
|
338 | +function give_profile_editor_shortcode($atts, $content = null) { |
|
339 | 339 | |
340 | 340 | ob_start(); |
341 | 341 | |
342 | - give_get_template_part( 'shortcode', 'profile-editor' ); |
|
342 | + give_get_template_part('shortcode', 'profile-editor'); |
|
343 | 343 | |
344 | 344 | $display = ob_get_clean(); |
345 | 345 | |
346 | 346 | return $display; |
347 | 347 | } |
348 | 348 | |
349 | -add_shortcode( 'give_profile_editor', 'give_profile_editor_shortcode' ); |
|
349 | +add_shortcode('give_profile_editor', 'give_profile_editor_shortcode'); |
|
350 | 350 | |
351 | 351 | /** |
352 | 352 | * Process Profile Updater Form. |
@@ -359,30 +359,30 @@ discard block |
||
359 | 359 | * |
360 | 360 | * @return bool |
361 | 361 | */ |
362 | -function give_process_profile_editor_updates( $data ) { |
|
362 | +function give_process_profile_editor_updates($data) { |
|
363 | 363 | // Profile field change request |
364 | - if ( empty( $_POST['give_profile_editor_submit'] ) && ! is_user_logged_in() ) { |
|
364 | + if (empty($_POST['give_profile_editor_submit']) && ! is_user_logged_in()) { |
|
365 | 365 | return false; |
366 | 366 | } |
367 | 367 | |
368 | 368 | // Nonce security |
369 | - if ( ! wp_verify_nonce( $data['give_profile_editor_nonce'], 'give-profile-editor-nonce' ) ) { |
|
369 | + if ( ! wp_verify_nonce($data['give_profile_editor_nonce'], 'give-profile-editor-nonce')) { |
|
370 | 370 | return false; |
371 | 371 | } |
372 | 372 | |
373 | 373 | $user_id = get_current_user_id(); |
374 | - $old_user_data = get_userdata( $user_id ); |
|
375 | - |
|
376 | - $display_name = isset( $data['give_display_name'] ) ? sanitize_text_field( $data['give_display_name'] ) : $old_user_data->display_name; |
|
377 | - $first_name = isset( $data['give_first_name'] ) ? sanitize_text_field( $data['give_first_name'] ) : $old_user_data->first_name; |
|
378 | - $last_name = isset( $data['give_last_name'] ) ? sanitize_text_field( $data['give_last_name'] ) : $old_user_data->last_name; |
|
379 | - $email = isset( $data['give_email'] ) ? sanitize_email( $data['give_email'] ) : $old_user_data->user_email; |
|
380 | - $line1 = ( isset( $data['give_address_line1'] ) ? sanitize_text_field( $data['give_address_line1'] ) : '' ); |
|
381 | - $line2 = ( isset( $data['give_address_line2'] ) ? sanitize_text_field( $data['give_address_line2'] ) : '' ); |
|
382 | - $city = ( isset( $data['give_address_city'] ) ? sanitize_text_field( $data['give_address_city'] ) : '' ); |
|
383 | - $state = ( isset( $data['give_address_state'] ) ? sanitize_text_field( $data['give_address_state'] ) : '' ); |
|
384 | - $zip = ( isset( $data['give_address_zip'] ) ? sanitize_text_field( $data['give_address_zip'] ) : '' ); |
|
385 | - $country = ( isset( $data['give_address_country'] ) ? sanitize_text_field( $data['give_address_country'] ) : '' ); |
|
374 | + $old_user_data = get_userdata($user_id); |
|
375 | + |
|
376 | + $display_name = isset($data['give_display_name']) ? sanitize_text_field($data['give_display_name']) : $old_user_data->display_name; |
|
377 | + $first_name = isset($data['give_first_name']) ? sanitize_text_field($data['give_first_name']) : $old_user_data->first_name; |
|
378 | + $last_name = isset($data['give_last_name']) ? sanitize_text_field($data['give_last_name']) : $old_user_data->last_name; |
|
379 | + $email = isset($data['give_email']) ? sanitize_email($data['give_email']) : $old_user_data->user_email; |
|
380 | + $line1 = (isset($data['give_address_line1']) ? sanitize_text_field($data['give_address_line1']) : ''); |
|
381 | + $line2 = (isset($data['give_address_line2']) ? sanitize_text_field($data['give_address_line2']) : ''); |
|
382 | + $city = (isset($data['give_address_city']) ? sanitize_text_field($data['give_address_city']) : ''); |
|
383 | + $state = (isset($data['give_address_state']) ? sanitize_text_field($data['give_address_state']) : ''); |
|
384 | + $zip = (isset($data['give_address_zip']) ? sanitize_text_field($data['give_address_zip']) : ''); |
|
385 | + $country = (isset($data['give_address_country']) ? sanitize_text_field($data['give_address_country']) : ''); |
|
386 | 386 | |
387 | 387 | $userdata = array( |
388 | 388 | 'ID' => $user_id, |
@@ -410,38 +410,38 @@ discard block |
||
410 | 410 | * @param int $user_id The ID of the user. |
411 | 411 | * @param array $userdata User info, including ID, first name, last name, display name and email. |
412 | 412 | */ |
413 | - do_action( 'give_pre_update_user_profile', $user_id, $userdata ); |
|
413 | + do_action('give_pre_update_user_profile', $user_id, $userdata); |
|
414 | 414 | |
415 | 415 | // New password |
416 | - if ( ! empty( $data['give_new_user_pass1'] ) ) { |
|
417 | - if ( $data['give_new_user_pass1'] !== $data['give_new_user_pass2'] ) { |
|
418 | - give_set_error( 'password_mismatch', esc_html__( 'The passwords you entered do not match. Please try again.', 'give' ) ); |
|
416 | + if ( ! empty($data['give_new_user_pass1'])) { |
|
417 | + if ($data['give_new_user_pass1'] !== $data['give_new_user_pass2']) { |
|
418 | + give_set_error('password_mismatch', esc_html__('The passwords you entered do not match. Please try again.', 'give')); |
|
419 | 419 | } else { |
420 | 420 | $userdata['user_pass'] = $data['give_new_user_pass1']; |
421 | 421 | } |
422 | 422 | } |
423 | 423 | |
424 | 424 | // Make sure the new email doesn't belong to another user |
425 | - if ( $email != $old_user_data->user_email ) { |
|
426 | - if ( email_exists( $email ) ) { |
|
427 | - give_set_error( 'email_exists', esc_html__( 'The email you entered belongs to another user. Please use another.', 'give' ) ); |
|
425 | + if ($email != $old_user_data->user_email) { |
|
426 | + if (email_exists($email)) { |
|
427 | + give_set_error('email_exists', esc_html__('The email you entered belongs to another user. Please use another.', 'give')); |
|
428 | 428 | } |
429 | 429 | } |
430 | 430 | |
431 | 431 | // Check for errors |
432 | 432 | $errors = give_get_errors(); |
433 | 433 | |
434 | - if ( $errors ) { |
|
434 | + if ($errors) { |
|
435 | 435 | // Send back to the profile editor if there are errors |
436 | - wp_redirect( $data['give_redirect'] ); |
|
436 | + wp_redirect($data['give_redirect']); |
|
437 | 437 | give_die(); |
438 | 438 | } |
439 | 439 | |
440 | 440 | // Update the user |
441 | - $meta = update_user_meta( $user_id, '_give_user_address', $address ); |
|
442 | - $updated = wp_update_user( $userdata ); |
|
441 | + $meta = update_user_meta($user_id, '_give_user_address', $address); |
|
442 | + $updated = wp_update_user($userdata); |
|
443 | 443 | |
444 | - if ( $updated ) { |
|
444 | + if ($updated) { |
|
445 | 445 | |
446 | 446 | /** |
447 | 447 | * Fires after updating user profile. |
@@ -451,13 +451,13 @@ discard block |
||
451 | 451 | * @param int $user_id The ID of the user. |
452 | 452 | * @param array $userdata User info, including ID, first name, last name, display name and email. |
453 | 453 | */ |
454 | - do_action( 'give_user_profile_updated', $user_id, $userdata ); |
|
455 | - wp_redirect( add_query_arg( 'updated', 'true', $data['give_redirect'] ) ); |
|
454 | + do_action('give_user_profile_updated', $user_id, $userdata); |
|
455 | + wp_redirect(add_query_arg('updated', 'true', $data['give_redirect'])); |
|
456 | 456 | give_die(); |
457 | 457 | } |
458 | 458 | |
459 | 459 | return false; |
460 | 460 | } |
461 | 461 | |
462 | -add_action( 'give_edit_user_profile', 'give_process_profile_editor_updates' ); |
|
462 | +add_action('give_edit_user_profile', 'give_process_profile_editor_updates'); |
|
463 | 463 |
@@ -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,13 +23,13 @@ discard block |
||
23 | 23 | * |
24 | 24 | * @return bool true if has variable prices, false otherwise |
25 | 25 | */ |
26 | -function give_has_variable_prices( $form_id = 0 ) { |
|
26 | +function give_has_variable_prices($form_id = 0) { |
|
27 | 27 | |
28 | - if ( empty( $form_id ) ) { |
|
28 | + if (empty($form_id)) { |
|
29 | 29 | return false; |
30 | 30 | } |
31 | 31 | |
32 | - $form = new Give_Donate_Form( $form_id ); |
|
32 | + $form = new Give_Donate_Form($form_id); |
|
33 | 33 | |
34 | 34 | return $form->has_variable_prices(); |
35 | 35 | } |
@@ -44,13 +44,13 @@ discard block |
||
44 | 44 | * |
45 | 45 | * @return array Variable prices |
46 | 46 | */ |
47 | -function give_get_variable_prices( $form_id = 0 ) { |
|
47 | +function give_get_variable_prices($form_id = 0) { |
|
48 | 48 | |
49 | - if ( empty( $form_id ) ) { |
|
49 | + if (empty($form_id)) { |
|
50 | 50 | return false; |
51 | 51 | } |
52 | 52 | |
53 | - $form = new Give_Donate_Form( $form_id ); |
|
53 | + $form = new Give_Donate_Form($form_id); |
|
54 | 54 | |
55 | 55 | return $form->prices; |
56 | 56 | |
@@ -67,13 +67,13 @@ discard block |
||
67 | 67 | * |
68 | 68 | * @return string $default_price |
69 | 69 | */ |
70 | -function give_get_default_multilevel_amount( $form_id ) { |
|
70 | +function give_get_default_multilevel_amount($form_id) { |
|
71 | 71 | $default_price = '1.00'; |
72 | - $prices = apply_filters( 'give_form_variable_prices', give_get_variable_prices( $form_id ), $form_id ); |
|
72 | + $prices = apply_filters('give_form_variable_prices', give_get_variable_prices($form_id), $form_id); |
|
73 | 73 | |
74 | - foreach ( $prices as $price ) { |
|
74 | + foreach ($prices as $price) { |
|
75 | 75 | |
76 | - if ( isset( $price['_give_default'] ) && $price['_give_default'] === 'default' ) { |
|
76 | + if (isset($price['_give_default']) && $price['_give_default'] === 'default') { |
|
77 | 77 | $default_price = $price['_give_amount']; |
78 | 78 | } |
79 | 79 | |
@@ -94,15 +94,15 @@ discard block |
||
94 | 94 | * @return string $default_price |
95 | 95 | * @since 1.0 |
96 | 96 | */ |
97 | -function give_get_default_form_amount( $form_id ) { |
|
97 | +function give_get_default_form_amount($form_id) { |
|
98 | 98 | |
99 | - if ( give_has_variable_prices( $form_id ) ) { |
|
99 | + if (give_has_variable_prices($form_id)) { |
|
100 | 100 | |
101 | - $default_amount = give_get_default_multilevel_amount( $form_id ); |
|
101 | + $default_amount = give_get_default_multilevel_amount($form_id); |
|
102 | 102 | |
103 | 103 | } else { |
104 | 104 | |
105 | - $default_amount = get_post_meta( $form_id, '_give_set_price', true ); |
|
105 | + $default_amount = get_post_meta($form_id, '_give_set_price', true); |
|
106 | 106 | |
107 | 107 | } |
108 | 108 | |
@@ -123,13 +123,13 @@ discard block |
||
123 | 123 | * |
124 | 124 | * @return bool |
125 | 125 | */ |
126 | -function give_is_custom_price_mode( $form_id = 0 ) { |
|
126 | +function give_is_custom_price_mode($form_id = 0) { |
|
127 | 127 | |
128 | - if ( empty( $form_id ) ) { |
|
128 | + if (empty($form_id)) { |
|
129 | 129 | return false; |
130 | 130 | } |
131 | 131 | |
132 | - $form = new Give_Donate_Form( $form_id ); |
|
132 | + $form = new Give_Donate_Form($form_id); |
|
133 | 133 | |
134 | 134 | return $form->is_custom_price_mode(); |
135 | 135 | } |
136 | 136 | \ No newline at end of file |
@@ -781,7 +781,7 @@ |
||
781 | 781 | foreach ( $prices as $price ) { |
782 | 782 | if ( isset( $price['_give_id']['level_id'] ) && $price['_give_id']['level_id'] == $price_id ) { |
783 | 783 | $amount = isset( $price['_give_amount'] ) ? $price['_give_amount'] : 0.00; |
784 | - break; |
|
784 | + break; |
|
785 | 785 | }; |
786 | 786 | } |
787 | 787 |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | * Used to redirect a user back to the purchase |
157 | 157 | * page if there are errors present. |
158 | 158 | * |
159 | - * @param array $args |
|
159 | + * @param string $args |
|
160 | 160 | * |
161 | 161 | * @access public |
162 | 162 | * @since 1.0 |
@@ -390,7 +390,7 @@ discard block |
||
390 | 390 | * |
391 | 391 | * @param int $form_id Give Form ID |
392 | 392 | * |
393 | - * @return int $earnings Earnings for a certain form |
|
393 | + * @return double $earnings Earnings for a certain form |
|
394 | 394 | */ |
395 | 395 | function give_get_form_earnings_stats( $form_id = 0 ) { |
396 | 396 | $give_form = new Give_Donate_Form( $form_id ); |
@@ -544,7 +544,7 @@ |
||
544 | 544 | |
545 | 545 | if( $payment_total_diff > 0 ) { |
546 | 546 | $this->increase_value( $payment_total_diff ); |
547 | - }else{ |
|
547 | + } else{ |
|
548 | 548 | // Pass payment total difference as +ve value to decrease amount from user lifetime stat. |
549 | 549 | $this->decrease_value( -$payment_total_diff ); |
550 | 550 | } |
@@ -565,12 +565,12 @@ discard block |
||
565 | 565 | |
566 | 566 | /** |
567 | 567 | * Decrease/Increase a customer's lifetime value. |
568 | - * |
|
569 | - * This function will update donation stat on basis of current amount and new amount donation difference. |
|
570 | - * Difference value can positive or negative. Negative value will decrease user donation stat while positive value increase donation stat. |
|
571 | - * |
|
568 | + * |
|
569 | + * This function will update donation stat on basis of current amount and new amount donation difference. |
|
570 | + * Difference value can positive or negative. Negative value will decrease user donation stat while positive value increase donation stat. |
|
571 | + * |
|
572 | 572 | * @since 1.0 |
573 | - * @access public |
|
573 | + * @access public |
|
574 | 574 | * |
575 | 575 | * @param float $curr_amount Current Donation amount. |
576 | 576 | * @param float $new_amount New (changed) Donation amount. |
@@ -578,35 +578,35 @@ discard block |
||
578 | 578 | * @return mixed If successful, the new donation stat value, otherwise false. |
579 | 579 | */ |
580 | 580 | public function update_donation_value( $curr_amount, $new_amount ) { |
581 | - /** |
|
582 | - * Payment total difference value can be: |
|
583 | - * zero (in case amount not change) |
|
584 | - * or -ve (in case amount decrease) |
|
585 | - * or +ve (in case amount increase) |
|
586 | - */ |
|
587 | - $payment_total_diff = $new_amount - $curr_amount; |
|
588 | - |
|
589 | - // We do not need to update donation stat if donation did not change. |
|
590 | - if( ! $payment_total_diff ) { |
|
591 | - return false; |
|
592 | - } |
|
593 | - |
|
594 | - |
|
595 | - if( $payment_total_diff > 0 ) { |
|
596 | - $this->increase_value( $payment_total_diff ); |
|
597 | - }else{ |
|
598 | - // Pass payment total difference as +ve value to decrease amount from user lifetime stat. |
|
599 | - $this->decrease_value( -$payment_total_diff ); |
|
600 | - } |
|
601 | - |
|
602 | - return $this->purchase_value; |
|
581 | + /** |
|
582 | + * Payment total difference value can be: |
|
583 | + * zero (in case amount not change) |
|
584 | + * or -ve (in case amount decrease) |
|
585 | + * or +ve (in case amount increase) |
|
586 | + */ |
|
587 | + $payment_total_diff = $new_amount - $curr_amount; |
|
588 | + |
|
589 | + // We do not need to update donation stat if donation did not change. |
|
590 | + if( ! $payment_total_diff ) { |
|
591 | + return false; |
|
592 | + } |
|
593 | + |
|
594 | + |
|
595 | + if( $payment_total_diff > 0 ) { |
|
596 | + $this->increase_value( $payment_total_diff ); |
|
597 | + }else{ |
|
598 | + // Pass payment total difference as +ve value to decrease amount from user lifetime stat. |
|
599 | + $this->decrease_value( -$payment_total_diff ); |
|
600 | + } |
|
601 | + |
|
602 | + return $this->purchase_value; |
|
603 | 603 | } |
604 | 604 | |
605 | 605 | /** |
606 | 606 | * Get the parsed notes for a customer as an array. |
607 | 607 | * |
608 | 608 | * @since 1.0 |
609 | - * @access public |
|
609 | + * @access public |
|
610 | 610 | * |
611 | 611 | * @param integer $length The number of notes to get. |
612 | 612 | * @param integer $paged What note to start at. |
@@ -631,7 +631,7 @@ discard block |
||
631 | 631 | * Get the total number of notes we have after parsing. |
632 | 632 | * |
633 | 633 | * @since 1.0 |
634 | - * @access public |
|
634 | + * @access public |
|
635 | 635 | * |
636 | 636 | * @return int The number of notes for the customer. |
637 | 637 | */ |
@@ -648,7 +648,7 @@ discard block |
||
648 | 648 | * Add a note for the customer. |
649 | 649 | * |
650 | 650 | * @since 1.0 |
651 | - * @access public |
|
651 | + * @access public |
|
652 | 652 | * |
653 | 653 | * @param string $note The note to add. Default is empty. |
654 | 654 | * |
@@ -690,7 +690,7 @@ discard block |
||
690 | 690 | * Get the notes column for the customer |
691 | 691 | * |
692 | 692 | * @since 1.0 |
693 | - * @access private |
|
693 | + * @access private |
|
694 | 694 | * |
695 | 695 | * @return string The Notes for the customer, non-parsed. |
696 | 696 | */ |
@@ -768,7 +768,7 @@ discard block |
||
768 | 768 | * Sanitize the data for update/create |
769 | 769 | * |
770 | 770 | * @since 1.0 |
771 | - * @access private |
|
771 | + * @access private |
|
772 | 772 | * |
773 | 773 | * @param array $data The data to sanitize. |
774 | 774 | * |
@@ -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 | |
@@ -134,29 +134,29 @@ discard block |
||
134 | 134 | * @param bool $_id_or_email |
135 | 135 | * @param bool $by_user_id |
136 | 136 | */ |
137 | - public function __construct( $_id_or_email = false, $by_user_id = false ) { |
|
137 | + public function __construct($_id_or_email = false, $by_user_id = false) { |
|
138 | 138 | |
139 | 139 | $this->db = new Give_DB_Customers; |
140 | 140 | |
141 | - if ( false === $_id_or_email || ( is_numeric( $_id_or_email ) && (int) $_id_or_email !== absint( $_id_or_email ) ) ) { |
|
141 | + if (false === $_id_or_email || (is_numeric($_id_or_email) && (int) $_id_or_email !== absint($_id_or_email))) { |
|
142 | 142 | return false; |
143 | 143 | } |
144 | 144 | |
145 | - $by_user_id = is_bool( $by_user_id ) ? $by_user_id : false; |
|
145 | + $by_user_id = is_bool($by_user_id) ? $by_user_id : false; |
|
146 | 146 | |
147 | - if ( is_numeric( $_id_or_email ) ) { |
|
147 | + if (is_numeric($_id_or_email)) { |
|
148 | 148 | $field = $by_user_id ? 'user_id' : 'id'; |
149 | 149 | } else { |
150 | 150 | $field = 'email'; |
151 | 151 | } |
152 | 152 | |
153 | - $customer = $this->db->get_customer_by( $field, $_id_or_email ); |
|
153 | + $customer = $this->db->get_customer_by($field, $_id_or_email); |
|
154 | 154 | |
155 | - if ( empty( $customer ) || ! is_object( $customer ) ) { |
|
155 | + if (empty($customer) || ! is_object($customer)) { |
|
156 | 156 | return false; |
157 | 157 | } |
158 | 158 | |
159 | - $this->setup_customer( $customer ); |
|
159 | + $this->setup_customer($customer); |
|
160 | 160 | |
161 | 161 | } |
162 | 162 | |
@@ -172,15 +172,15 @@ discard block |
||
172 | 172 | * |
173 | 173 | * @return bool If the setup was successful or not. |
174 | 174 | */ |
175 | - private function setup_customer( $customer ) { |
|
175 | + private function setup_customer($customer) { |
|
176 | 176 | |
177 | - if ( ! is_object( $customer ) ) { |
|
177 | + if ( ! is_object($customer)) { |
|
178 | 178 | return false; |
179 | 179 | } |
180 | 180 | |
181 | - foreach ( $customer as $key => $value ) { |
|
181 | + foreach ($customer as $key => $value) { |
|
182 | 182 | |
183 | - switch ( $key ) { |
|
183 | + switch ($key) { |
|
184 | 184 | |
185 | 185 | case 'notes': |
186 | 186 | $this->$key = $this->get_notes(); |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | } |
196 | 196 | |
197 | 197 | // Customer ID and email are the only things that are necessary, make sure they exist |
198 | - if ( ! empty( $this->id ) && ! empty( $this->email ) ) { |
|
198 | + if ( ! empty($this->id) && ! empty($this->email)) { |
|
199 | 199 | return true; |
200 | 200 | } |
201 | 201 | |
@@ -209,16 +209,16 @@ discard block |
||
209 | 209 | * @since 1.0 |
210 | 210 | * @access public |
211 | 211 | */ |
212 | - public function __get( $key ) { |
|
212 | + public function __get($key) { |
|
213 | 213 | |
214 | - if ( method_exists( $this, 'get_' . $key ) ) { |
|
214 | + if (method_exists($this, 'get_'.$key)) { |
|
215 | 215 | |
216 | - return call_user_func( array( $this, 'get_' . $key ) ); |
|
216 | + return call_user_func(array($this, 'get_'.$key)); |
|
217 | 217 | |
218 | 218 | } else { |
219 | 219 | |
220 | 220 | /* translators: %s: property key */ |
221 | - return new WP_Error( 'give-customer-invalid-property', sprintf( esc_html__( 'Can\'t get property %s.', 'give' ), $key ) ); |
|
221 | + return new WP_Error('give-customer-invalid-property', sprintf(esc_html__('Can\'t get property %s.', 'give'), $key)); |
|
222 | 222 | |
223 | 223 | } |
224 | 224 | |
@@ -234,9 +234,9 @@ discard block |
||
234 | 234 | * |
235 | 235 | * @return mixed False if not a valid creation, Customer ID if user is found or valid creation. |
236 | 236 | */ |
237 | - public function create( $data = array() ) { |
|
237 | + public function create($data = array()) { |
|
238 | 238 | |
239 | - if ( $this->id != 0 || empty( $data ) ) { |
|
239 | + if ($this->id != 0 || empty($data)) { |
|
240 | 240 | return false; |
241 | 241 | } |
242 | 242 | |
@@ -244,34 +244,34 @@ discard block |
||
244 | 244 | 'payment_ids' => '' |
245 | 245 | ); |
246 | 246 | |
247 | - $args = wp_parse_args( $data, $defaults ); |
|
248 | - $args = $this->sanitize_columns( $args ); |
|
247 | + $args = wp_parse_args($data, $defaults); |
|
248 | + $args = $this->sanitize_columns($args); |
|
249 | 249 | |
250 | - if ( empty( $args['email'] ) || ! is_email( $args['email'] ) ) { |
|
250 | + if (empty($args['email']) || ! is_email($args['email'])) { |
|
251 | 251 | return false; |
252 | 252 | } |
253 | 253 | |
254 | - if ( ! empty( $args['payment_ids'] ) && is_array( $args['payment_ids'] ) ) { |
|
255 | - $args['payment_ids'] = implode( ',', array_unique( array_values( $args['payment_ids'] ) ) ); |
|
254 | + if ( ! empty($args['payment_ids']) && is_array($args['payment_ids'])) { |
|
255 | + $args['payment_ids'] = implode(',', array_unique(array_values($args['payment_ids']))); |
|
256 | 256 | } |
257 | 257 | |
258 | - do_action( 'give_customer_pre_create', $args ); |
|
258 | + do_action('give_customer_pre_create', $args); |
|
259 | 259 | |
260 | 260 | $created = false; |
261 | 261 | |
262 | 262 | // The DB class 'add' implies an update if the customer being asked to be created already exists |
263 | - if ( $this->db->add( $data ) ) { |
|
263 | + if ($this->db->add($data)) { |
|
264 | 264 | |
265 | 265 | // We've successfully added/updated the customer, reset the class vars with the new data |
266 | - $customer = $this->db->get_customer_by( 'email', $args['email'] ); |
|
266 | + $customer = $this->db->get_customer_by('email', $args['email']); |
|
267 | 267 | |
268 | 268 | // Setup the customer data with the values from DB |
269 | - $this->setup_customer( $customer ); |
|
269 | + $this->setup_customer($customer); |
|
270 | 270 | |
271 | 271 | $created = $this->id; |
272 | 272 | } |
273 | 273 | |
274 | - do_action( 'give_customer_post_create', $created, $args ); |
|
274 | + do_action('give_customer_post_create', $created, $args); |
|
275 | 275 | |
276 | 276 | return $created; |
277 | 277 | |
@@ -287,27 +287,27 @@ discard block |
||
287 | 287 | * |
288 | 288 | * @return bool If the update was successful or not. |
289 | 289 | */ |
290 | - public function update( $data = array() ) { |
|
290 | + public function update($data = array()) { |
|
291 | 291 | |
292 | - if ( empty( $data ) ) { |
|
292 | + if (empty($data)) { |
|
293 | 293 | return false; |
294 | 294 | } |
295 | 295 | |
296 | - $data = $this->sanitize_columns( $data ); |
|
296 | + $data = $this->sanitize_columns($data); |
|
297 | 297 | |
298 | - do_action( 'give_customer_pre_update', $this->id, $data ); |
|
298 | + do_action('give_customer_pre_update', $this->id, $data); |
|
299 | 299 | |
300 | 300 | $updated = false; |
301 | 301 | |
302 | - if ( $this->db->update( $this->id, $data ) ) { |
|
302 | + if ($this->db->update($this->id, $data)) { |
|
303 | 303 | |
304 | - $customer = $this->db->get_customer_by( 'id', $this->id ); |
|
305 | - $this->setup_customer( $customer ); |
|
304 | + $customer = $this->db->get_customer_by('id', $this->id); |
|
305 | + $this->setup_customer($customer); |
|
306 | 306 | |
307 | 307 | $updated = true; |
308 | 308 | } |
309 | 309 | |
310 | - do_action( 'give_customer_post_update', $updated, $this->id, $data ); |
|
310 | + do_action('give_customer_post_update', $updated, $this->id, $data); |
|
311 | 311 | |
312 | 312 | return $updated; |
313 | 313 | } |
@@ -325,44 +325,44 @@ discard block |
||
325 | 325 | * |
326 | 326 | * @return bool If the attachment was successfuly. |
327 | 327 | */ |
328 | - public function attach_payment( $payment_id = 0, $update_stats = true ) { |
|
328 | + public function attach_payment($payment_id = 0, $update_stats = true) { |
|
329 | 329 | |
330 | - if ( empty( $payment_id ) ) { |
|
330 | + if (empty($payment_id)) { |
|
331 | 331 | return false; |
332 | 332 | } |
333 | 333 | |
334 | - if ( empty( $this->payment_ids ) ) { |
|
334 | + if (empty($this->payment_ids)) { |
|
335 | 335 | |
336 | 336 | $new_payment_ids = $payment_id; |
337 | 337 | |
338 | 338 | } else { |
339 | 339 | |
340 | - $payment_ids = array_map( 'absint', explode( ',', $this->payment_ids ) ); |
|
340 | + $payment_ids = array_map('absint', explode(',', $this->payment_ids)); |
|
341 | 341 | |
342 | - if ( in_array( $payment_id, $payment_ids ) ) { |
|
342 | + if (in_array($payment_id, $payment_ids)) { |
|
343 | 343 | $update_stats = false; |
344 | 344 | } |
345 | 345 | |
346 | 346 | $payment_ids[] = $payment_id; |
347 | 347 | |
348 | - $new_payment_ids = implode( ',', array_unique( array_values( $payment_ids ) ) ); |
|
348 | + $new_payment_ids = implode(',', array_unique(array_values($payment_ids))); |
|
349 | 349 | |
350 | 350 | } |
351 | 351 | |
352 | - do_action( 'give_customer_pre_attach_payment', $payment_id, $this->id ); |
|
352 | + do_action('give_customer_pre_attach_payment', $payment_id, $this->id); |
|
353 | 353 | |
354 | - $payment_added = $this->update( array( 'payment_ids' => $new_payment_ids ) ); |
|
354 | + $payment_added = $this->update(array('payment_ids' => $new_payment_ids)); |
|
355 | 355 | |
356 | - if ( $payment_added ) { |
|
356 | + if ($payment_added) { |
|
357 | 357 | |
358 | 358 | $this->payment_ids = $new_payment_ids; |
359 | 359 | |
360 | 360 | // We added this payment successfully, increment the stats |
361 | - if ( $update_stats ) { |
|
362 | - $payment_amount = give_get_payment_amount( $payment_id ); |
|
361 | + if ($update_stats) { |
|
362 | + $payment_amount = give_get_payment_amount($payment_id); |
|
363 | 363 | |
364 | - if ( ! empty( $payment_amount ) ) { |
|
365 | - $this->increase_value( $payment_amount ); |
|
364 | + if ( ! empty($payment_amount)) { |
|
365 | + $this->increase_value($payment_amount); |
|
366 | 366 | } |
367 | 367 | |
368 | 368 | $this->increase_purchase_count(); |
@@ -370,7 +370,7 @@ discard block |
||
370 | 370 | |
371 | 371 | } |
372 | 372 | |
373 | - do_action( 'give_customer_post_attach_payment', $payment_added, $payment_id, $this->id ); |
|
373 | + do_action('give_customer_post_attach_payment', $payment_added, $payment_id, $this->id); |
|
374 | 374 | |
375 | 375 | return $payment_added; |
376 | 376 | } |
@@ -388,50 +388,50 @@ discard block |
||
388 | 388 | * |
389 | 389 | * @return boolean If the removal was successful. |
390 | 390 | */ |
391 | - public function remove_payment( $payment_id = 0, $update_stats = true ) { |
|
391 | + public function remove_payment($payment_id = 0, $update_stats = true) { |
|
392 | 392 | |
393 | - if ( empty( $payment_id ) ) { |
|
393 | + if (empty($payment_id)) { |
|
394 | 394 | return false; |
395 | 395 | } |
396 | 396 | |
397 | - $payment = new Give_Payment( $payment_id ); |
|
397 | + $payment = new Give_Payment($payment_id); |
|
398 | 398 | |
399 | - if ( 'publish' !== $payment->status && 'revoked' !== $payment->status ) { |
|
399 | + if ('publish' !== $payment->status && 'revoked' !== $payment->status) { |
|
400 | 400 | $update_stats = false; |
401 | 401 | } |
402 | 402 | |
403 | 403 | $new_payment_ids = ''; |
404 | 404 | |
405 | - if ( ! empty( $this->payment_ids ) ) { |
|
405 | + if ( ! empty($this->payment_ids)) { |
|
406 | 406 | |
407 | - $payment_ids = array_map( 'absint', explode( ',', $this->payment_ids ) ); |
|
407 | + $payment_ids = array_map('absint', explode(',', $this->payment_ids)); |
|
408 | 408 | |
409 | - $pos = array_search( $payment_id, $payment_ids ); |
|
410 | - if ( false === $pos ) { |
|
409 | + $pos = array_search($payment_id, $payment_ids); |
|
410 | + if (false === $pos) { |
|
411 | 411 | return false; |
412 | 412 | } |
413 | 413 | |
414 | - unset( $payment_ids[ $pos ] ); |
|
415 | - $payment_ids = array_filter( $payment_ids ); |
|
414 | + unset($payment_ids[$pos]); |
|
415 | + $payment_ids = array_filter($payment_ids); |
|
416 | 416 | |
417 | - $new_payment_ids = implode( ',', array_unique( array_values( $payment_ids ) ) ); |
|
417 | + $new_payment_ids = implode(',', array_unique(array_values($payment_ids))); |
|
418 | 418 | |
419 | 419 | } |
420 | 420 | |
421 | - do_action( 'give_customer_pre_remove_payment', $payment_id, $this->id ); |
|
421 | + do_action('give_customer_pre_remove_payment', $payment_id, $this->id); |
|
422 | 422 | |
423 | - $payment_removed = $this->update( array( 'payment_ids' => $new_payment_ids ) ); |
|
423 | + $payment_removed = $this->update(array('payment_ids' => $new_payment_ids)); |
|
424 | 424 | |
425 | - if ( $payment_removed ) { |
|
425 | + if ($payment_removed) { |
|
426 | 426 | |
427 | 427 | $this->payment_ids = $new_payment_ids; |
428 | 428 | |
429 | - if ( $update_stats ) { |
|
429 | + if ($update_stats) { |
|
430 | 430 | // We removed this payment successfully, decrement the stats |
431 | - $payment_amount = give_get_payment_amount( $payment_id ); |
|
431 | + $payment_amount = give_get_payment_amount($payment_id); |
|
432 | 432 | |
433 | - if ( ! empty( $payment_amount ) ) { |
|
434 | - $this->decrease_value( $payment_amount ); |
|
433 | + if ( ! empty($payment_amount)) { |
|
434 | + $this->decrease_value($payment_amount); |
|
435 | 435 | } |
436 | 436 | |
437 | 437 | $this->decrease_purchase_count(); |
@@ -439,7 +439,7 @@ discard block |
||
439 | 439 | |
440 | 440 | } |
441 | 441 | |
442 | - do_action( 'give_customer_post_remove_payment', $payment_removed, $payment_id, $this->id ); |
|
442 | + do_action('give_customer_post_remove_payment', $payment_removed, $payment_id, $this->id); |
|
443 | 443 | |
444 | 444 | return $payment_removed; |
445 | 445 | |
@@ -455,22 +455,22 @@ discard block |
||
455 | 455 | * |
456 | 456 | * @return int The purchase count. |
457 | 457 | */ |
458 | - public function increase_purchase_count( $count = 1 ) { |
|
458 | + public function increase_purchase_count($count = 1) { |
|
459 | 459 | |
460 | 460 | // Make sure it's numeric and not negative. |
461 | - if ( ! is_numeric( $count ) || $count != absint( $count ) ) { |
|
461 | + if ( ! is_numeric($count) || $count != absint($count)) { |
|
462 | 462 | return false; |
463 | 463 | } |
464 | 464 | |
465 | 465 | $new_total = (int) $this->purchase_count + (int) $count; |
466 | 466 | |
467 | - do_action( 'give_customer_pre_increase_purchase_count', $count, $this->id ); |
|
467 | + do_action('give_customer_pre_increase_purchase_count', $count, $this->id); |
|
468 | 468 | |
469 | - if ( $this->update( array( 'purchase_count' => $new_total ) ) ) { |
|
469 | + if ($this->update(array('purchase_count' => $new_total))) { |
|
470 | 470 | $this->purchase_count = $new_total; |
471 | 471 | } |
472 | 472 | |
473 | - do_action( 'give_customer_post_increase_purchase_count', $this->purchase_count, $count, $this->id ); |
|
473 | + do_action('give_customer_post_increase_purchase_count', $this->purchase_count, $count, $this->id); |
|
474 | 474 | |
475 | 475 | return $this->purchase_count; |
476 | 476 | } |
@@ -485,26 +485,26 @@ discard block |
||
485 | 485 | * |
486 | 486 | * @return mixed If successful, the new count, otherwise false. |
487 | 487 | */ |
488 | - public function decrease_purchase_count( $count = 1 ) { |
|
488 | + public function decrease_purchase_count($count = 1) { |
|
489 | 489 | |
490 | 490 | // Make sure it's numeric and not negative |
491 | - if ( ! is_numeric( $count ) || $count != absint( $count ) ) { |
|
491 | + if ( ! is_numeric($count) || $count != absint($count)) { |
|
492 | 492 | return false; |
493 | 493 | } |
494 | 494 | |
495 | 495 | $new_total = (int) $this->purchase_count - (int) $count; |
496 | 496 | |
497 | - if ( $new_total < 0 ) { |
|
497 | + if ($new_total < 0) { |
|
498 | 498 | $new_total = 0; |
499 | 499 | } |
500 | 500 | |
501 | - do_action( 'give_customer_pre_decrease_purchase_count', $count, $this->id ); |
|
501 | + do_action('give_customer_pre_decrease_purchase_count', $count, $this->id); |
|
502 | 502 | |
503 | - if ( $this->update( array( 'purchase_count' => $new_total ) ) ) { |
|
503 | + if ($this->update(array('purchase_count' => $new_total))) { |
|
504 | 504 | $this->purchase_count = $new_total; |
505 | 505 | } |
506 | 506 | |
507 | - do_action( 'give_customer_post_decrease_purchase_count', $this->purchase_count, $count, $this->id ); |
|
507 | + do_action('give_customer_post_decrease_purchase_count', $this->purchase_count, $count, $this->id); |
|
508 | 508 | |
509 | 509 | return $this->purchase_count; |
510 | 510 | } |
@@ -519,17 +519,17 @@ discard block |
||
519 | 519 | * |
520 | 520 | * @return mixed If successful, the new value, otherwise false. |
521 | 521 | */ |
522 | - public function increase_value( $value = 0.00 ) { |
|
522 | + public function increase_value($value = 0.00) { |
|
523 | 523 | |
524 | - $new_value = floatval( $this->purchase_value ) + $value; |
|
524 | + $new_value = floatval($this->purchase_value) + $value; |
|
525 | 525 | |
526 | - do_action( 'give_customer_pre_increase_value', $value, $this->id ); |
|
526 | + do_action('give_customer_pre_increase_value', $value, $this->id); |
|
527 | 527 | |
528 | - if ( $this->update( array( 'purchase_value' => $new_value ) ) ) { |
|
528 | + if ($this->update(array('purchase_value' => $new_value))) { |
|
529 | 529 | $this->purchase_value = $new_value; |
530 | 530 | } |
531 | 531 | |
532 | - do_action( 'give_customer_post_increase_value', $this->purchase_value, $value, $this->id ); |
|
532 | + do_action('give_customer_post_increase_value', $this->purchase_value, $value, $this->id); |
|
533 | 533 | |
534 | 534 | return $this->purchase_value; |
535 | 535 | } |
@@ -544,21 +544,21 @@ discard block |
||
544 | 544 | * |
545 | 545 | * @return mixed If successful, the new value, otherwise false. |
546 | 546 | */ |
547 | - public function decrease_value( $value = 0.00 ) { |
|
547 | + public function decrease_value($value = 0.00) { |
|
548 | 548 | |
549 | - $new_value = floatval( $this->purchase_value ) - $value; |
|
549 | + $new_value = floatval($this->purchase_value) - $value; |
|
550 | 550 | |
551 | - if ( $new_value < 0 ) { |
|
551 | + if ($new_value < 0) { |
|
552 | 552 | $new_value = 0.00; |
553 | 553 | } |
554 | 554 | |
555 | - do_action( 'give_customer_pre_decrease_value', $value, $this->id ); |
|
555 | + do_action('give_customer_pre_decrease_value', $value, $this->id); |
|
556 | 556 | |
557 | - if ( $this->update( array( 'purchase_value' => $new_value ) ) ) { |
|
557 | + if ($this->update(array('purchase_value' => $new_value))) { |
|
558 | 558 | $this->purchase_value = $new_value; |
559 | 559 | } |
560 | 560 | |
561 | - do_action( 'give_customer_post_decrease_value', $this->purchase_value, $value, $this->id ); |
|
561 | + do_action('give_customer_post_decrease_value', $this->purchase_value, $value, $this->id); |
|
562 | 562 | |
563 | 563 | return $this->purchase_value; |
564 | 564 | } |
@@ -577,7 +577,7 @@ discard block |
||
577 | 577 | * |
578 | 578 | * @return mixed If successful, the new donation stat value, otherwise false. |
579 | 579 | */ |
580 | - public function update_donation_value( $curr_amount, $new_amount ) { |
|
580 | + public function update_donation_value($curr_amount, $new_amount) { |
|
581 | 581 | /** |
582 | 582 | * Payment total difference value can be: |
583 | 583 | * zero (in case amount not change) |
@@ -587,14 +587,14 @@ discard block |
||
587 | 587 | $payment_total_diff = $new_amount - $curr_amount; |
588 | 588 | |
589 | 589 | // We do not need to update donation stat if donation did not change. |
590 | - if( ! $payment_total_diff ) { |
|
590 | + if ( ! $payment_total_diff) { |
|
591 | 591 | return false; |
592 | 592 | } |
593 | 593 | |
594 | 594 | |
595 | - if( $payment_total_diff > 0 ) { |
|
596 | - $this->increase_value( $payment_total_diff ); |
|
597 | - }else{ |
|
595 | + if ($payment_total_diff > 0) { |
|
596 | + $this->increase_value($payment_total_diff); |
|
597 | + } else { |
|
598 | 598 | // Pass payment total difference as +ve value to decrease amount from user lifetime stat. |
599 | 599 | $this->decrease_value( -$payment_total_diff ); |
600 | 600 | } |
@@ -613,15 +613,15 @@ discard block |
||
613 | 613 | * |
614 | 614 | * @return array The notes requested. |
615 | 615 | */ |
616 | - public function get_notes( $length = 20, $paged = 1 ) { |
|
616 | + public function get_notes($length = 20, $paged = 1) { |
|
617 | 617 | |
618 | - $length = is_numeric( $length ) ? $length : 20; |
|
619 | - $offset = is_numeric( $paged ) && $paged != 1 ? ( ( absint( $paged ) - 1 ) * $length ) : 0; |
|
618 | + $length = is_numeric($length) ? $length : 20; |
|
619 | + $offset = is_numeric($paged) && $paged != 1 ? ((absint($paged) - 1) * $length) : 0; |
|
620 | 620 | |
621 | 621 | $all_notes = $this->get_raw_notes(); |
622 | - $notes_array = array_reverse( array_filter( explode( "\n\n", $all_notes ) ) ); |
|
622 | + $notes_array = array_reverse(array_filter(explode("\n\n", $all_notes))); |
|
623 | 623 | |
624 | - $desired_notes = array_slice( $notes_array, $offset, $length ); |
|
624 | + $desired_notes = array_slice($notes_array, $offset, $length); |
|
625 | 625 | |
626 | 626 | return $desired_notes; |
627 | 627 | |
@@ -638,9 +638,9 @@ discard block |
||
638 | 638 | public function get_notes_count() { |
639 | 639 | |
640 | 640 | $all_notes = $this->get_raw_notes(); |
641 | - $notes_array = array_reverse( array_filter( explode( "\n\n", $all_notes ) ) ); |
|
641 | + $notes_array = array_reverse(array_filter(explode("\n\n", $all_notes))); |
|
642 | 642 | |
643 | - return count( $notes_array ); |
|
643 | + return count($notes_array); |
|
644 | 644 | |
645 | 645 | } |
646 | 646 | |
@@ -654,32 +654,32 @@ discard block |
||
654 | 654 | * |
655 | 655 | * @return string|boolean The new note if added successfully, false otherwise. |
656 | 656 | */ |
657 | - public function add_note( $note = '' ) { |
|
657 | + public function add_note($note = '') { |
|
658 | 658 | |
659 | - $note = trim( $note ); |
|
660 | - if ( empty( $note ) ) { |
|
659 | + $note = trim($note); |
|
660 | + if (empty($note)) { |
|
661 | 661 | return false; |
662 | 662 | } |
663 | 663 | |
664 | 664 | $notes = $this->get_raw_notes(); |
665 | 665 | |
666 | - if ( empty( $notes ) ) { |
|
666 | + if (empty($notes)) { |
|
667 | 667 | $notes = ''; |
668 | 668 | } |
669 | 669 | |
670 | - $note_string = date_i18n( 'F j, Y H:i:s', current_time( 'timestamp' ) ) . ' - ' . $note; |
|
671 | - $new_note = apply_filters( 'give_customer_add_note_string', $note_string ); |
|
672 | - $notes .= "\n\n" . $new_note; |
|
670 | + $note_string = date_i18n('F j, Y H:i:s', current_time('timestamp')).' - '.$note; |
|
671 | + $new_note = apply_filters('give_customer_add_note_string', $note_string); |
|
672 | + $notes .= "\n\n".$new_note; |
|
673 | 673 | |
674 | - do_action( 'give_customer_pre_add_note', $new_note, $this->id ); |
|
674 | + do_action('give_customer_pre_add_note', $new_note, $this->id); |
|
675 | 675 | |
676 | - $updated = $this->update( array( 'notes' => $notes ) ); |
|
676 | + $updated = $this->update(array('notes' => $notes)); |
|
677 | 677 | |
678 | - if ( $updated ) { |
|
678 | + if ($updated) { |
|
679 | 679 | $this->notes = $this->get_notes(); |
680 | 680 | } |
681 | 681 | |
682 | - do_action( 'give_customer_post_add_note', $this->notes, $new_note, $this->id ); |
|
682 | + do_action('give_customer_post_add_note', $this->notes, $new_note, $this->id); |
|
683 | 683 | |
684 | 684 | // Return the formatted note, so we can test, as well as update any displays |
685 | 685 | return $new_note; |
@@ -696,7 +696,7 @@ discard block |
||
696 | 696 | */ |
697 | 697 | private function get_raw_notes() { |
698 | 698 | |
699 | - $all_notes = $this->db->get_column( 'notes', $this->id ); |
|
699 | + $all_notes = $this->db->get_column('notes', $this->id); |
|
700 | 700 | |
701 | 701 | return $all_notes; |
702 | 702 | |
@@ -713,8 +713,8 @@ discard block |
||
713 | 713 | * |
714 | 714 | * @return mixed Will be an array if $single is false. Will be value of meta data field if $single is true. |
715 | 715 | */ |
716 | - public function get_meta( $meta_key = '', $single = true ) { |
|
717 | - return Give()->customer_meta->get_meta( $this->id, $meta_key, $single ); |
|
716 | + public function get_meta($meta_key = '', $single = true) { |
|
717 | + return Give()->customer_meta->get_meta($this->id, $meta_key, $single); |
|
718 | 718 | } |
719 | 719 | |
720 | 720 | /** |
@@ -729,8 +729,8 @@ discard block |
||
729 | 729 | * |
730 | 730 | * @return bool False for failure. True for success. |
731 | 731 | */ |
732 | - public function add_meta( $meta_key = '', $meta_value, $unique = false ) { |
|
733 | - return Give()->customer_meta->add_meta( $this->id, $meta_key, $meta_value, $unique ); |
|
732 | + public function add_meta($meta_key = '', $meta_value, $unique = false) { |
|
733 | + return Give()->customer_meta->add_meta($this->id, $meta_key, $meta_value, $unique); |
|
734 | 734 | } |
735 | 735 | |
736 | 736 | /** |
@@ -745,8 +745,8 @@ discard block |
||
745 | 745 | * |
746 | 746 | * @return bool False on failure, true if success. |
747 | 747 | */ |
748 | - public function update_meta( $meta_key = '', $meta_value, $prev_value = '' ) { |
|
749 | - return Give()->customer_meta->update_meta( $this->id, $meta_key, $meta_value, $prev_value ); |
|
748 | + public function update_meta($meta_key = '', $meta_value, $prev_value = '') { |
|
749 | + return Give()->customer_meta->update_meta($this->id, $meta_key, $meta_value, $prev_value); |
|
750 | 750 | } |
751 | 751 | |
752 | 752 | /** |
@@ -760,8 +760,8 @@ discard block |
||
760 | 760 | * |
761 | 761 | * @return bool False for failure. True for success. |
762 | 762 | */ |
763 | - public function delete_meta( $meta_key = '', $meta_value = '' ) { |
|
764 | - return Give()->customer_meta->delete_meta( $this->id, $meta_key, $meta_value ); |
|
763 | + public function delete_meta($meta_key = '', $meta_value = '') { |
|
764 | + return Give()->customer_meta->delete_meta($this->id, $meta_key, $meta_value); |
|
765 | 765 | } |
766 | 766 | |
767 | 767 | /** |
@@ -774,51 +774,51 @@ discard block |
||
774 | 774 | * |
775 | 775 | * @return array The sanitized data, based off column defaults. |
776 | 776 | */ |
777 | - private function sanitize_columns( $data ) { |
|
777 | + private function sanitize_columns($data) { |
|
778 | 778 | |
779 | 779 | $columns = $this->db->get_columns(); |
780 | 780 | $default_values = $this->db->get_column_defaults(); |
781 | 781 | |
782 | - foreach ( $columns as $key => $type ) { |
|
782 | + foreach ($columns as $key => $type) { |
|
783 | 783 | |
784 | 784 | // Only sanitize data that we were provided |
785 | - if ( ! array_key_exists( $key, $data ) ) { |
|
785 | + if ( ! array_key_exists($key, $data)) { |
|
786 | 786 | continue; |
787 | 787 | } |
788 | 788 | |
789 | - switch ( $type ) { |
|
789 | + switch ($type) { |
|
790 | 790 | |
791 | 791 | case '%s': |
792 | - if ( 'email' == $key ) { |
|
793 | - $data[ $key ] = sanitize_email( $data[ $key ] ); |
|
794 | - } elseif ( 'notes' == $key ) { |
|
795 | - $data[ $key ] = strip_tags( $data[ $key ] ); |
|
792 | + if ('email' == $key) { |
|
793 | + $data[$key] = sanitize_email($data[$key]); |
|
794 | + } elseif ('notes' == $key) { |
|
795 | + $data[$key] = strip_tags($data[$key]); |
|
796 | 796 | } else { |
797 | - $data[ $key ] = sanitize_text_field( $data[ $key ] ); |
|
797 | + $data[$key] = sanitize_text_field($data[$key]); |
|
798 | 798 | } |
799 | 799 | break; |
800 | 800 | |
801 | 801 | case '%d': |
802 | - if ( ! is_numeric( $data[ $key ] ) || (int) $data[ $key ] !== absint( $data[ $key ] ) ) { |
|
803 | - $data[ $key ] = $default_values[ $key ]; |
|
802 | + if ( ! is_numeric($data[$key]) || (int) $data[$key] !== absint($data[$key])) { |
|
803 | + $data[$key] = $default_values[$key]; |
|
804 | 804 | } else { |
805 | - $data[ $key ] = absint( $data[ $key ] ); |
|
805 | + $data[$key] = absint($data[$key]); |
|
806 | 806 | } |
807 | 807 | break; |
808 | 808 | |
809 | 809 | case '%f': |
810 | 810 | // Convert what was given to a float |
811 | - $value = floatval( $data[ $key ] ); |
|
811 | + $value = floatval($data[$key]); |
|
812 | 812 | |
813 | - if ( ! is_float( $value ) ) { |
|
814 | - $data[ $key ] = $default_values[ $key ]; |
|
813 | + if ( ! is_float($value)) { |
|
814 | + $data[$key] = $default_values[$key]; |
|
815 | 815 | } else { |
816 | - $data[ $key ] = $value; |
|
816 | + $data[$key] = $value; |
|
817 | 817 | } |
818 | 818 | break; |
819 | 819 | |
820 | 820 | default: |
821 | - $data[ $key ] = sanitize_text_field( $data[ $key ] ); |
|
821 | + $data[$key] = sanitize_text_field($data[$key]); |
|
822 | 822 | break; |
823 | 823 | |
824 | 824 | } |