| Conditions | 2 |
| Paths | 2 |
| Total Lines | 77 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 39 | * @since 2.4.0 |
||
| 40 | * @return void |
||
| 41 | */ |
||
| 42 | function give_render_dashboard_stats_widget() { |
||
| 43 | if ( ! current_user_can( apply_filters( 'give_dashboard_stats_cap', 'view_give_reports' ) ) ) { |
||
| 44 | return; |
||
| 45 | } |
||
| 46 | |||
| 47 | ?> |
||
| 48 | <div id="give-dashboard-sales-widget"> |
||
| 49 | <span class="spinner is-active" style="float: none;margin: auto 50%;padding-bottom: 15px;"></span> |
||
| 50 | |||
| 51 | <script> |
||
| 52 | jQuery(document).ready(function () { |
||
| 53 | jQuery.ajax({ |
||
| 54 | url: ajaxurl, |
||
| 55 | data: { |
||
| 56 | action: 'give_render_dashboard_stats_widget' |
||
| 57 | }, |
||
| 58 | success: function (response) { |
||
| 59 | jQuery('#give-dashboard-sales-widget').html(response); |
||
| 60 | } |
||
| 61 | }); |
||
| 62 | }) |
||
| 63 | </script> |
||
| 64 | </div> |
||
| 65 | <?php |
||
| 66 | } |
||
| 67 | |||
| 68 | /** |
||
| 69 | * Ajax handler for dashboard statistic widget render |
||
| 70 | * Note: only for internal use |
||
| 71 | * |
||
| 72 | * @since 2.4.0 |
||
| 73 | */ |
||
| 74 | function give_ajax_render_dashboard_stats_widget(){ |
||
| 75 | ob_start(); |
||
| 76 | give_dashboard_stats_widget(); |
||
| 77 | |||
| 78 | wp_send_json( ob_get_clean() ); |
||
| 79 | |||
| 80 | } |
||
| 81 | add_action( 'wp_ajax_give_render_dashboard_stats_widget', 'give_ajax_render_dashboard_stats_widget' ); |
||
| 82 | |||
| 83 | /** |
||
| 84 | * Sales Summary Dashboard Widget |
||
| 85 | * |
||
| 86 | * Builds and renders the statistics dashboard widget. This widget displays the current month's donations. |
||
| 87 | * |
||
| 88 | * @since 1.0 |
||
| 89 | * @return void |
||
| 90 | */ |
||
| 91 | function give_dashboard_stats_widget() { |
||
| 92 | |||
| 93 | if ( ! current_user_can( apply_filters( 'give_dashboard_stats_cap', 'view_give_reports' ) ) ) { |
||
| 94 | return; |
||
| 95 | } |
||
| 96 | $stats = new Give_Payment_Stats(); ?> |
||
| 97 | |||
| 98 | <div class="give-dashboard-widget"> |
||
| 99 | |||
| 100 | <div class="give-dashboard-today give-clearfix"> |
||
| 101 | <h3 class="give-dashboard-date-today"><?php echo date_i18n( _x( 'F j, Y', 'dashboard widget', 'give' ) ); ?></h3> |
||
|
|
|||
| 102 | |||
| 103 | <p class="give-dashboard-happy-day"><?php |
||
| 104 | printf( |
||
| 105 | /* translators: %s: day of the week */ |
||
| 106 | __( 'Happy %s!', 'give' ), |
||
| 107 | date_i18n( 'l', current_time( 'timestamp' ) ) |
||
| 108 | ); |
||
| 109 | ?></p> |
||
| 110 | |||
| 111 | <p class="give-dashboard-today-earnings"><?php |
||
| 112 | $earnings_today = $stats->get_earnings( 0, 'today', false ); |
||
| 113 | echo give_currency_filter( give_format_amount( $earnings_today, array( 'sanitize' => false ) ) ); |
||
| 114 | ?></p> |
||
| 115 | |||
| 116 | <p class="give-donations-today"><?php |
||
| 212 |