| Conditions | 18 |
| Paths | 1152 |
| Total Lines | 287 |
| Code Lines | 177 |
| Lines | 0 |
| Ratio | 0 % |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 183 | function give_customers_view( $customer ) { |
||
| 184 | |||
| 185 | $customer_edit_role = apply_filters( 'give_edit_customers_role', 'edit_give_payments' ); |
||
| 186 | |||
| 187 | ?> |
||
| 188 | |||
| 189 | <?php do_action( 'give_donor_card_top', $customer ); ?> |
||
| 190 | |||
| 191 | <div id="donor-summary" class="info-wrapper customer-section postbox"> |
||
| 192 | |||
| 193 | <form id="edit-customer-info" method="post" action="<?php echo admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=overview&id=' . $customer->id ); ?>"> |
||
| 194 | |||
| 195 | <div class="customer-info"> |
||
| 196 | |||
| 197 | |||
| 198 | <div class="donor-bio-header clearfix"> |
||
| 199 | |||
| 200 | <div class="avatar-wrap left" id="customer-avatar"> |
||
| 201 | <?php echo get_avatar( $customer->email ); ?> |
||
| 202 | </div> |
||
| 203 | |||
| 204 | <div class="customer-id" class="left"> |
||
| 205 | #<?php echo $customer->id; ?> |
||
| 206 | </div> |
||
| 207 | <div id="customer-name-wrap" class="left"> |
||
| 208 | <span class="customer-name info-item edit-item"><input size="15" data-key="name" name="customerinfo[name]" type="text" value="<?php echo esc_attr( $customer->name ); ?>" placeholder="<?php _e( 'Donor Name', 'give' ); ?>" /></span> |
||
| 209 | <span class="customer-name info-item editable"><span data-key="name"><?php echo $customer->name; ?></span></span> |
||
| 210 | </div> |
||
| 211 | <p class="customer-since info-item"> |
||
| 212 | <?php _e( 'Donor since', 'give' ); ?> |
||
| 213 | <?php echo date_i18n( get_option( 'date_format' ), strtotime( $customer->date_created ) ) ?> |
||
| 214 | </p> |
||
| 215 | <?php if ( current_user_can( $customer_edit_role ) ): ?> |
||
| 216 | <a title="<?php _e( 'Edit Donor', 'give' ); ?>" href="#" id="edit-customer" class="button info-item editable customer-edit-link"><?php _e( 'Edit Donor', 'give' ); ?></a> |
||
| 217 | <?php endif; ?> |
||
| 218 | </div> |
||
| 219 | <!-- /donor-bio-header --> |
||
| 220 | |||
| 221 | <div class="customer-main-wrapper"> |
||
| 222 | |||
| 223 | <table class="widefat"> |
||
| 224 | <tbody> |
||
| 225 | <tr> |
||
| 226 | <td><label for="tablecell"><?php esc_attr_e( 'Email', 'give' ); ?></label>:</td> |
||
| 227 | <td class="row-title"> |
||
| 228 | <span class="customer-name info-item edit-item"><input size="20" data-key="email" name="customerinfo[email]" type="text" value="<?php echo $customer->email; ?>" placeholder="<?php _e( 'Donor Email', 'give' ); ?>" /></span> |
||
| 229 | <span class="customer-email info-item editable" data-key="email"><?php echo $customer->email; ?></span> |
||
| 230 | </td> |
||
| 231 | </tr> |
||
| 232 | <tr class="alternate"> |
||
| 233 | <td><label for="tablecell"><?php esc_attr_e( 'User ID', 'give' ); ?></label>:</td> |
||
| 234 | <td class="row-title"> |
||
| 235 | <span class="customer-user-id info-item edit-item"> |
||
| 236 | <?php |
||
| 237 | |||
| 238 | $user_id = $customer->user_id > 0 ? $customer->user_id : ''; |
||
| 239 | $data_atts = array( |
||
| 240 | 'key' => 'user_login', |
||
| 241 | 'exclude' => $user_id |
||
| 242 | ); |
||
| 243 | $user_args = array( |
||
| 244 | 'name' => 'customerinfo[user_login]', |
||
| 245 | 'class' => 'give-user-dropdown', |
||
| 246 | 'data' => $data_atts, |
||
| 247 | ); |
||
| 248 | |||
| 249 | if ( ! empty( $user_id ) ) { |
||
| 250 | $userdata = get_userdata( $user_id ); |
||
| 251 | $user_args['value'] = $userdata->user_login; |
||
| 252 | } |
||
| 253 | |||
| 254 | echo Give()->html->ajax_user_search( $user_args ); |
||
| 255 | ?> |
||
| 256 | <input type="hidden" name="customerinfo[user_id]" data-key="user_id" value="<?php echo $customer->user_id; ?>" /> |
||
| 257 | </span> |
||
| 258 | |||
| 259 | <span class="customer-user-id info-item editable"> |
||
| 260 | <?php if ( intval( $customer->user_id ) > 0 ) : ?> |
||
| 261 | <span data-key="user_id"><?php echo $customer->user_id; ?></span> |
||
| 262 | <?php else : ?> |
||
| 263 | <span data-key="user_id"><?php _e( 'none', 'give' ); ?></span> |
||
| 264 | <?php endif; ?> |
||
| 265 | <?php if ( current_user_can( $customer_edit_role ) && intval( $customer->user_id ) > 0 ) : ?> |
||
| 266 | <span class="disconnect-user"> - <a id="disconnect-customer" href="#disconnect" title="<?php _e( 'Disconnects the current user ID from this customer record', 'give' ); ?>"><?php _e( 'Disconnect User', 'give' ); ?></a></span> |
||
| 267 | <?php endif; ?> |
||
| 268 | </span> |
||
| 269 | </td> |
||
| 270 | </tr> |
||
| 271 | <?php if ( isset( $customer->user_id ) && $customer->user_id > 0 ) : ?> |
||
| 272 | |||
| 273 | <tr> |
||
| 274 | <td><?php esc_attr_e( 'Address', 'give' ); ?>:</td> |
||
| 275 | <td class="row-title"> |
||
| 276 | |||
| 277 | <div class="customer-address-wrapper"> |
||
| 278 | |||
| 279 | <?php |
||
| 280 | $address = get_user_meta( $customer->user_id, '_give_user_address', true ); |
||
| 281 | $defaults = array( |
||
| 282 | 'line1' => '', |
||
| 283 | 'line2' => '', |
||
| 284 | 'city' => '', |
||
| 285 | 'state' => '', |
||
| 286 | 'country' => '', |
||
| 287 | 'zip' => '' |
||
| 288 | ); |
||
| 289 | |||
| 290 | $address = wp_parse_args( $address, $defaults ); |
||
| 291 | ?> |
||
| 292 | |||
| 293 | <?php if ( ! empty( $address ) ) { ?> |
||
| 294 | <span class="customer-address info-item editable"> |
||
| 295 | <span class="info-item" data-key="line1"><?php echo $address['line1']; ?></span> |
||
| 296 | <span class="info-item" data-key="line2"><?php echo $address['line2']; ?></span> |
||
| 297 | <span class="info-item" data-key="city"><?php echo $address['city']; ?></span> |
||
| 298 | <span class="info-item" data-key="state"><?php echo $address['state']; ?></span> |
||
| 299 | <span class="info-item" data-key="country"><?php echo $address['country']; ?></span> |
||
| 300 | <span class="info-item" data-key="zip"><?php echo $address['zip']; ?></span> |
||
| 301 | </span> |
||
| 302 | <?php } ?> |
||
| 303 | <span class="customer-address info-item edit-item"> |
||
| 304 | <input class="info-item" type="text" data-key="line1" name="customerinfo[line1]" placeholder="<?php _e( 'Address 1', 'give' ); ?>" value="<?php echo $address['line1']; ?>" /> |
||
| 305 | <input class="info-item" type="text" data-key="line2" name="customerinfo[line2]" placeholder="<?php _e( 'Address 2', 'give' ); ?>" value="<?php echo $address['line2']; ?>" /> |
||
| 306 | <input class="info-item" type="text" data-key="city" name="customerinfo[city]" placeholder="<?php _e( 'City', 'give' ); ?>" value="<?php echo $address['city']; ?>" /> |
||
| 307 | <select data-key="country" name="customerinfo[country]" id="billing_country" class="billing_country give-select edit-item"> |
||
| 308 | <?php |
||
| 309 | |||
| 310 | $selected_country = $address['country']; |
||
| 311 | |||
| 312 | $countries = give_get_country_list(); |
||
| 313 | foreach ( $countries as $country_code => $country ) { |
||
| 314 | echo '<option value="' . esc_attr( $country_code ) . '"' . selected( $country_code, $selected_country, false ) . '>' . $country . '</option>'; |
||
| 315 | } |
||
| 316 | ?> |
||
| 317 | </select> |
||
| 318 | <?php |
||
| 319 | $selected_state = give_get_state(); |
||
| 320 | $states = give_get_states( $selected_country ); |
||
| 321 | |||
| 322 | $selected_state = isset( $address['state'] ) ? $address['state'] : $selected_state; |
||
| 323 | |||
| 324 | if ( ! empty( $states ) ) : ?> |
||
| 325 | <select data-key="state" name="customerinfo[state]" id="card_state" class="card_state give-select info-item"> |
||
| 326 | <?php |
||
| 327 | foreach ( $states as $state_code => $state ) { |
||
| 328 | echo '<option value="' . $state_code . '"' . selected( $state_code, $selected_state, false ) . '>' . $state . '</option>'; |
||
| 329 | } |
||
| 330 | ?> |
||
| 331 | </select> |
||
| 332 | <?php else : ?> |
||
| 333 | <input type="text" size="6" data-key="state" name="customerinfo[state]" id="card_state" class="card_state give-input info-item" placeholder="<?php _e( 'State / Province', 'give' ); ?>" /> |
||
| 334 | <?php endif; ?> |
||
| 335 | <input class="info-item" type="text" data-key="zip" name="customerinfo[zip]" placeholder="<?php _e( 'Postal', 'give' ); ?>" value="<?php echo $address['zip']; ?>" /> |
||
| 336 | </span> |
||
| 337 | |||
| 338 | </div> |
||
| 339 | </td> |
||
| 340 | </tr> |
||
| 341 | <?php endif; ?> |
||
| 342 | </tbody> |
||
| 343 | </table> |
||
| 344 | |||
| 345 | |||
| 346 | </div> |
||
| 347 | |||
| 348 | |||
| 349 | </div> |
||
| 350 | |||
| 351 | <span id="customer-edit-actions" class="edit-item"> |
||
| 352 | <input type="hidden" data-key="id" name="customerinfo[id]" value="<?php echo $customer->id; ?>" /> |
||
| 353 | <?php wp_nonce_field( 'edit-customer', '_wpnonce', false, true ); ?> |
||
| 354 | <input type="hidden" name="give_action" value="edit-customer" /> |
||
| 355 | <input type="submit" id="give-edit-customer-save" class="button-secondary" value="<?php _e( 'Update Donor', 'give' ); ?>" /> |
||
| 356 | <a id="give-edit-customer-cancel" href="" class="delete"><?php _e( 'Cancel', 'give' ); ?></a> |
||
| 357 | </span> |
||
| 358 | |||
| 359 | </form> |
||
| 360 | </div> |
||
| 361 | |||
| 362 | <?php do_action( 'give_donor_before_stats', $customer ); ?> |
||
| 363 | |||
| 364 | <div id="customer-stats-wrapper" class="customer-section postbox clear"> |
||
| 365 | <ul> |
||
| 366 | <li> |
||
| 367 | <a title="<?php _e( 'View All Donations', 'give' ); ?>" href="<?php echo admin_url( 'edit.php?post_type=give_forms&page=give-payment-history&user=' . urlencode( $customer->email ) ); ?>"> |
||
| 368 | <span class="dashicons dashicons-heart"></span> |
||
| 369 | <?php |
||
| 370 | //Completed Donations |
||
| 371 | $completed_donations_text = sprintf( _n( '%d Completed Donation', '%d Completed Donations', $customer->purchase_count, 'give' ), $customer->purchase_count ); |
||
| 372 | echo apply_filters( 'give_donor_completed_donations', $completed_donations_text, $customer ); |
||
| 373 | ?> |
||
| 374 | </a> |
||
| 375 | </li> |
||
| 376 | <li> |
||
| 377 | <span class="dashicons dashicons-chart-area"></span> |
||
| 378 | <?php echo give_currency_filter( give_format_amount( $customer->purchase_value ) ); ?> <?php _e( 'Lifetime Donations', 'give' ); ?> |
||
| 379 | </li> |
||
| 380 | <?php do_action( 'give_donor_stats_list', $customer ); ?> |
||
| 381 | </ul> |
||
| 382 | </div> |
||
| 383 | |||
| 384 | <?php do_action( 'give_donor_before_tables_wrapper', $customer ); ?> |
||
| 385 | |||
| 386 | <div id="customer-tables-wrapper" class="customer-section"> |
||
| 387 | |||
| 388 | <?php do_action( 'give_donor_before_tables', $customer ); ?> |
||
| 389 | |||
| 390 | <h3><?php _e( 'Recent Donations', 'give' ); ?></h3> |
||
| 391 | <?php |
||
| 392 | $payment_ids = explode( ',', $customer->payment_ids ); |
||
| 393 | $payments = give_get_payments( array( 'post__in' => $payment_ids ) ); |
||
| 394 | $payments = array_slice( $payments, 0, 10 ); |
||
| 395 | ?> |
||
| 396 | <table class="wp-list-table widefat striped payments"> |
||
| 397 | <thead> |
||
| 398 | <tr> |
||
| 399 | <th><?php _e( 'ID', 'give' ); ?></th> |
||
| 400 | <th><?php _e( 'Amount', 'give' ); ?></th> |
||
| 401 | <th><?php _e( 'Date', 'give' ); ?></th> |
||
| 402 | <th><?php _e( 'Status', 'give' ); ?></th> |
||
| 403 | <th><?php _e( 'Actions', 'give' ); ?></th> |
||
| 404 | </tr> |
||
| 405 | </thead> |
||
| 406 | <tbody> |
||
| 407 | <?php if ( ! empty( $payments ) ) : ?> |
||
| 408 | <?php foreach ( $payments as $payment ) : ?> |
||
| 409 | <tr> |
||
| 410 | <td><?php echo $payment->ID; ?></td> |
||
| 411 | <td><?php echo give_payment_amount( $payment->ID ); ?></td> |
||
| 412 | <td><?php echo date_i18n( get_option( 'date_format' ), strtotime( $payment->post_date ) ); ?></td> |
||
| 413 | <td><?php echo give_get_payment_status( $payment, true ); ?></td> |
||
| 414 | <td> |
||
| 415 | <a title="<?php _e( 'View Details for Donation', 'give' ); |
||
| 416 | echo ' ' . $payment->ID; ?>" href="<?php echo admin_url( 'edit.php?post_type=give_forms&page=give-payment-history&view=view-order-details&id=' . $payment->ID ); ?>"> |
||
| 417 | <?php _e( 'View Details', 'give' ); ?> |
||
| 418 | </a> |
||
| 419 | <?php do_action( 'give_donor_recent_purchases_actions', $customer, $payment ); ?> |
||
| 420 | </td> |
||
| 421 | </tr> |
||
| 422 | <?php endforeach; ?> |
||
| 423 | <?php else: ?> |
||
| 424 | <tr> |
||
| 425 | <td colspan="5"><?php _e( 'No Donations Found', 'give' ); ?></td> |
||
| 426 | </tr> |
||
| 427 | <?php endif; ?> |
||
| 428 | </tbody> |
||
| 429 | </table> |
||
| 430 | |||
| 431 | <h3><?php _e( 'Completed Donations', 'give' ); ?></h3> |
||
| 432 | <?php |
||
| 433 | $donations = give_get_users_completed_donations( $customer->email ); |
||
| 434 | ?> |
||
| 435 | <table class="wp-list-table widefat striped downloads"> |
||
| 436 | <thead> |
||
| 437 | <tr> |
||
| 438 | <th><?php echo give_get_forms_label_singular(); ?></th> |
||
| 439 | <th width="120px"><?php _e( 'Actions', 'give' ); ?></th> |
||
| 440 | </tr> |
||
| 441 | </thead> |
||
| 442 | <tbody> |
||
| 443 | <?php if ( ! empty( $donations ) ) : ?> |
||
| 444 | <?php foreach ( $donations as $donation ) : ?> |
||
| 445 | <tr> |
||
| 446 | <td><?php echo $donation->post_title; ?></td> |
||
| 447 | <td> |
||
| 448 | <a title="<?php echo esc_attr( sprintf( __( 'View %s', 'give' ), $donation->post_title ) ); ?>" href="<?php echo esc_url( admin_url( 'post.php?action=edit&post=' . $donation->ID ) ); ?>"> |
||
| 449 | <?php printf( __( 'View %s', 'give' ), give_get_forms_label_singular() ); ?> |
||
| 450 | </a> |
||
| 451 | </td> |
||
| 452 | </tr> |
||
| 453 | <?php endforeach; ?> |
||
| 454 | <?php else: ?> |
||
| 455 | <tr> |
||
| 456 | <td colspan="2"><?php _e( 'No Completed Donations Found', 'give' ); ?></td> |
||
| 457 | </tr> |
||
| 458 | <?php endif; ?> |
||
| 459 | </tbody> |
||
| 460 | </table> |
||
| 461 | |||
| 462 | <?php do_action( 'give_donor_after_tables', $customer ); ?> |
||
| 463 | |||
| 464 | </div> |
||
| 465 | |||
| 466 | <?php do_action( 'give_donor_card_bottom', $customer ); ?> |
||
| 467 | |||
| 468 | <?php |
||
| 469 | } |
||
| 470 | |||
| 597 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.