@@ -12,23 +12,23 @@ discard block |
||
| 12 | 12 | */ |
| 13 | 13 | class GetPaid_Reports_Report_Items extends GetPaid_Reports_Abstract_Report { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * @var string |
|
| 17 | - */ |
|
| 18 | - public $field = 'item_name'; |
|
| 19 | - |
|
| 20 | - /** |
|
| 21 | - * Retrieves the earning sql. |
|
| 22 | - * |
|
| 23 | - */ |
|
| 24 | - public function get_sql( $range ) { |
|
| 25 | - global $wpdb; |
|
| 26 | - |
|
| 27 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
| 28 | - $table2 = $wpdb->prefix . 'getpaid_invoice_items'; |
|
| 29 | - $clauses = $this->get_range_sql( $range ); |
|
| 30 | - |
|
| 31 | - $sql = "SELECT |
|
| 15 | + /** |
|
| 16 | + * @var string |
|
| 17 | + */ |
|
| 18 | + public $field = 'item_name'; |
|
| 19 | + |
|
| 20 | + /** |
|
| 21 | + * Retrieves the earning sql. |
|
| 22 | + * |
|
| 23 | + */ |
|
| 24 | + public function get_sql( $range ) { |
|
| 25 | + global $wpdb; |
|
| 26 | + |
|
| 27 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
| 28 | + $table2 = $wpdb->prefix . 'getpaid_invoice_items'; |
|
| 29 | + $clauses = $this->get_range_sql( $range ); |
|
| 30 | + |
|
| 31 | + $sql = "SELECT |
|
| 32 | 32 | item.item_name AS item_name, |
| 33 | 33 | item.item_id AS item_id, |
| 34 | 34 | SUM(price) as total |
@@ -43,91 +43,91 @@ discard block |
||
| 43 | 43 | ORDER BY total DESC |
| 44 | 44 | "; |
| 45 | 45 | |
| 46 | - return apply_filters( 'getpaid_items_graphs_get_sql', $sql, $range ); |
|
| 46 | + return apply_filters( 'getpaid_items_graphs_get_sql', $sql, $range ); |
|
| 47 | 47 | |
| 48 | - } |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * Prepares the report stats. |
|
| 52 | - * |
|
| 53 | - */ |
|
| 54 | - public function prepare_stats() { |
|
| 55 | - global $wpdb; |
|
| 56 | - $this->stats = $wpdb->get_results( $this->get_sql( $this->get_range() ) ); |
|
| 57 | - $this->stats = $this->normalize_stats( $this->stats ); |
|
| 58 | - } |
|
| 50 | + /** |
|
| 51 | + * Prepares the report stats. |
|
| 52 | + * |
|
| 53 | + */ |
|
| 54 | + public function prepare_stats() { |
|
| 55 | + global $wpdb; |
|
| 56 | + $this->stats = $wpdb->get_results( $this->get_sql( $this->get_range() ) ); |
|
| 57 | + $this->stats = $this->normalize_stats( $this->stats ); |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * Normalizes the report stats. |
|
| 62 | - * |
|
| 63 | - */ |
|
| 64 | - public function normalize_stats( $stats ) { |
|
| 65 | - $normalized = array(); |
|
| 66 | - $others = 0; |
|
| 67 | - $did = 0; |
|
| 60 | + /** |
|
| 61 | + * Normalizes the report stats. |
|
| 62 | + * |
|
| 63 | + */ |
|
| 64 | + public function normalize_stats( $stats ) { |
|
| 65 | + $normalized = array(); |
|
| 66 | + $others = 0; |
|
| 67 | + $did = 0; |
|
| 68 | 68 | |
| 69 | - foreach ( $stats as $stat ) { |
|
| 69 | + foreach ( $stats as $stat ) { |
|
| 70 | 70 | |
| 71 | - if ( $did > 4 ) { |
|
| 71 | + if ( $did > 4 ) { |
|
| 72 | 72 | |
| 73 | - $others += wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ); |
|
| 73 | + $others += wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ); |
|
| 74 | 74 | |
| 75 | - } else { |
|
| 75 | + } else { |
|
| 76 | 76 | |
| 77 | - $normalized[] = array( |
|
| 78 | - 'total' => wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ), |
|
| 79 | - 'item_name' => strip_tags( $stat->item_name ), |
|
| 80 | - ); |
|
| 77 | + $normalized[] = array( |
|
| 78 | + 'total' => wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ), |
|
| 79 | + 'item_name' => strip_tags( $stat->item_name ), |
|
| 80 | + ); |
|
| 81 | 81 | |
| 82 | - } |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - $did++; |
|
| 85 | - } |
|
| 84 | + $did++; |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - if ( $others > 0 ) { |
|
| 87 | + if ( $others > 0 ) { |
|
| 88 | 88 | |
| 89 | - $normalized[] = array( |
|
| 90 | - 'total' => wpinv_round_amount( wpinv_sanitize_amount( $others ) ), |
|
| 91 | - 'item_name' => esc_html__( 'Others', 'invoicing' ), |
|
| 92 | - ); |
|
| 89 | + $normalized[] = array( |
|
| 90 | + 'total' => wpinv_round_amount( wpinv_sanitize_amount( $others ) ), |
|
| 91 | + 'item_name' => esc_html__( 'Others', 'invoicing' ), |
|
| 92 | + ); |
|
| 93 | 93 | |
| 94 | - } |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | - return $normalized; |
|
| 97 | - } |
|
| 96 | + return $normalized; |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | - /** |
|
| 100 | - * Retrieves report data. |
|
| 101 | - * |
|
| 102 | - */ |
|
| 103 | - public function get_data() { |
|
| 99 | + /** |
|
| 100 | + * Retrieves report data. |
|
| 101 | + * |
|
| 102 | + */ |
|
| 103 | + public function get_data() { |
|
| 104 | 104 | |
| 105 | - $data = wp_list_pluck( $this->stats, 'total' ); |
|
| 106 | - $colors = array( '#009688', '#4caf50', '#8bc34a', '#00bcd4', '#03a9f4', '#2196f3' ); |
|
| 105 | + $data = wp_list_pluck( $this->stats, 'total' ); |
|
| 106 | + $colors = array( '#009688', '#4caf50', '#8bc34a', '#00bcd4', '#03a9f4', '#2196f3' ); |
|
| 107 | 107 | |
| 108 | - shuffle( $colors ); |
|
| 108 | + shuffle( $colors ); |
|
| 109 | 109 | |
| 110 | - return array( |
|
| 111 | - 'data' => $data, |
|
| 112 | - 'backgroundColor' => $colors, |
|
| 113 | - ); |
|
| 110 | + return array( |
|
| 111 | + 'data' => $data, |
|
| 112 | + 'backgroundColor' => $colors, |
|
| 113 | + ); |
|
| 114 | 114 | |
| 115 | - } |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - /** |
|
| 118 | - * Retrieves report labels. |
|
| 119 | - * |
|
| 120 | - */ |
|
| 121 | - public function get_labels() { |
|
| 122 | - return wp_list_pluck( $this->stats, 'item_name' ); |
|
| 123 | - } |
|
| 117 | + /** |
|
| 118 | + * Retrieves report labels. |
|
| 119 | + * |
|
| 120 | + */ |
|
| 121 | + public function get_labels() { |
|
| 122 | + return wp_list_pluck( $this->stats, 'item_name' ); |
|
| 123 | + } |
|
| 124 | 124 | |
| 125 | - /** |
|
| 126 | - * Displays the actual report. |
|
| 127 | - * |
|
| 128 | - */ |
|
| 129 | - public function display_stats() { |
|
| 130 | - ?> |
|
| 125 | + /** |
|
| 126 | + * Displays the actual report. |
|
| 127 | + * |
|
| 128 | + */ |
|
| 129 | + public function display_stats() { |
|
| 130 | + ?> |
|
| 131 | 131 | |
| 132 | 132 | <canvas id="getpaid-chartjs-earnings-items"></canvas> |
| 133 | 133 | |
@@ -156,6 +156,6 @@ discard block |
||
| 156 | 156 | </script> |
| 157 | 157 | |
| 158 | 158 | <?php |
| 159 | - } |
|
| 159 | + } |
|
| 160 | 160 | |
| 161 | 161 | } |
@@ -5,7 +5,7 @@ discard block |
||
| 5 | 5 | * |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | -defined( 'ABSPATH' ) || exit; |
|
| 8 | +defined('ABSPATH') || exit; |
|
| 9 | 9 | |
| 10 | 10 | /** |
| 11 | 11 | * GetPaid_Reports_Report_Items Class. |
@@ -21,12 +21,12 @@ discard block |
||
| 21 | 21 | * Retrieves the earning sql. |
| 22 | 22 | * |
| 23 | 23 | */ |
| 24 | - public function get_sql( $range ) { |
|
| 24 | + public function get_sql($range) { |
|
| 25 | 25 | global $wpdb; |
| 26 | 26 | |
| 27 | 27 | $table = $wpdb->prefix . 'getpaid_invoices'; |
| 28 | 28 | $table2 = $wpdb->prefix . 'getpaid_invoice_items'; |
| 29 | - $clauses = $this->get_range_sql( $range ); |
|
| 29 | + $clauses = $this->get_range_sql($range); |
|
| 30 | 30 | |
| 31 | 31 | $sql = "SELECT |
| 32 | 32 | item.item_name AS item_name, |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | ORDER BY total DESC |
| 44 | 44 | "; |
| 45 | 45 | |
| 46 | - return apply_filters( 'getpaid_items_graphs_get_sql', $sql, $range ); |
|
| 46 | + return apply_filters('getpaid_items_graphs_get_sql', $sql, $range); |
|
| 47 | 47 | |
| 48 | 48 | } |
| 49 | 49 | |
@@ -53,30 +53,30 @@ discard block |
||
| 53 | 53 | */ |
| 54 | 54 | public function prepare_stats() { |
| 55 | 55 | global $wpdb; |
| 56 | - $this->stats = $wpdb->get_results( $this->get_sql( $this->get_range() ) ); |
|
| 57 | - $this->stats = $this->normalize_stats( $this->stats ); |
|
| 56 | + $this->stats = $wpdb->get_results($this->get_sql($this->get_range())); |
|
| 57 | + $this->stats = $this->normalize_stats($this->stats); |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | /** |
| 61 | 61 | * Normalizes the report stats. |
| 62 | 62 | * |
| 63 | 63 | */ |
| 64 | - public function normalize_stats( $stats ) { |
|
| 64 | + public function normalize_stats($stats) { |
|
| 65 | 65 | $normalized = array(); |
| 66 | 66 | $others = 0; |
| 67 | 67 | $did = 0; |
| 68 | 68 | |
| 69 | - foreach ( $stats as $stat ) { |
|
| 69 | + foreach ($stats as $stat) { |
|
| 70 | 70 | |
| 71 | - if ( $did > 4 ) { |
|
| 71 | + if ($did > 4) { |
|
| 72 | 72 | |
| 73 | - $others += wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ); |
|
| 73 | + $others += wpinv_round_amount(wpinv_sanitize_amount($stat->total)); |
|
| 74 | 74 | |
| 75 | 75 | } else { |
| 76 | 76 | |
| 77 | 77 | $normalized[] = array( |
| 78 | - 'total' => wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ), |
|
| 79 | - 'item_name' => strip_tags( $stat->item_name ), |
|
| 78 | + 'total' => wpinv_round_amount(wpinv_sanitize_amount($stat->total)), |
|
| 79 | + 'item_name' => strip_tags($stat->item_name), |
|
| 80 | 80 | ); |
| 81 | 81 | |
| 82 | 82 | } |
@@ -84,11 +84,11 @@ discard block |
||
| 84 | 84 | $did++; |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | - if ( $others > 0 ) { |
|
| 87 | + if ($others > 0) { |
|
| 88 | 88 | |
| 89 | 89 | $normalized[] = array( |
| 90 | - 'total' => wpinv_round_amount( wpinv_sanitize_amount( $others ) ), |
|
| 91 | - 'item_name' => esc_html__( 'Others', 'invoicing' ), |
|
| 90 | + 'total' => wpinv_round_amount(wpinv_sanitize_amount($others)), |
|
| 91 | + 'item_name' => esc_html__('Others', 'invoicing'), |
|
| 92 | 92 | ); |
| 93 | 93 | |
| 94 | 94 | } |
@@ -102,10 +102,10 @@ discard block |
||
| 102 | 102 | */ |
| 103 | 103 | public function get_data() { |
| 104 | 104 | |
| 105 | - $data = wp_list_pluck( $this->stats, 'total' ); |
|
| 106 | - $colors = array( '#009688', '#4caf50', '#8bc34a', '#00bcd4', '#03a9f4', '#2196f3' ); |
|
| 105 | + $data = wp_list_pluck($this->stats, 'total'); |
|
| 106 | + $colors = array('#009688', '#4caf50', '#8bc34a', '#00bcd4', '#03a9f4', '#2196f3'); |
|
| 107 | 107 | |
| 108 | - shuffle( $colors ); |
|
| 108 | + shuffle($colors); |
|
| 109 | 109 | |
| 110 | 110 | return array( |
| 111 | 111 | 'data' => $data, |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | * |
| 120 | 120 | */ |
| 121 | 121 | public function get_labels() { |
| 122 | - return wp_list_pluck( $this->stats, 'item_name' ); |
|
| 122 | + return wp_list_pluck($this->stats, 'item_name'); |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | /** |
@@ -140,8 +140,8 @@ discard block |
||
| 140 | 140 | { |
| 141 | 141 | type: 'doughnut', |
| 142 | 142 | data: { |
| 143 | - 'labels': <?php echo wp_json_encode( wp_kses_post_deep( $this->get_labels() ) ); ?>, |
|
| 144 | - 'datasets': [ <?php echo wp_json_encode( wp_kses_post_deep( $this->get_data() ) ); ?> ] |
|
| 143 | + 'labels': <?php echo wp_json_encode(wp_kses_post_deep($this->get_labels())); ?>, |
|
| 144 | + 'datasets': [ <?php echo wp_json_encode(wp_kses_post_deep($this->get_data())); ?> ] |
|
| 145 | 145 | }, |
| 146 | 146 | options: { |
| 147 | 147 | legend: { |
@@ -12,43 +12,43 @@ discard block |
||
| 12 | 12 | */ |
| 13 | 13 | class GetPaid_Reports_Report_Earnings extends GetPaid_Reports_Abstract_Report { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Retrieves the earning graphs. |
|
| 17 | - * |
|
| 18 | - */ |
|
| 19 | - public function get_graphs() { |
|
| 15 | + /** |
|
| 16 | + * Retrieves the earning graphs. |
|
| 17 | + * |
|
| 18 | + */ |
|
| 19 | + public function get_graphs() { |
|
| 20 | 20 | |
| 21 | - $graphs = array( |
|
| 21 | + $graphs = array( |
|
| 22 | 22 | |
| 23 | 23 | 'total' => __( 'Earnings', 'invoicing' ), |
| 24 | 24 | 'discount' => __( 'Discount', 'invoicing' ), |
| 25 | - 'fees_total' => __( 'Fees', 'invoicing' ), |
|
| 26 | - 'tax' => __( 'Tax', 'invoicing' ), |
|
| 25 | + 'fees_total' => __( 'Fees', 'invoicing' ), |
|
| 26 | + 'tax' => __( 'Tax', 'invoicing' ), |
|
| 27 | 27 | |
| 28 | - ); |
|
| 28 | + ); |
|
| 29 | 29 | |
| 30 | - return apply_filters( 'getpaid_earning_graphs', $graphs ); |
|
| 30 | + return apply_filters( 'getpaid_earning_graphs', $graphs ); |
|
| 31 | 31 | |
| 32 | - } |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Retrieves the earning sql. |
|
| 36 | - * |
|
| 37 | - */ |
|
| 38 | - public function get_sql( $range ) { |
|
| 39 | - global $wpdb; |
|
| 34 | + /** |
|
| 35 | + * Retrieves the earning sql. |
|
| 36 | + * |
|
| 37 | + */ |
|
| 38 | + public function get_sql( $range ) { |
|
| 39 | + global $wpdb; |
|
| 40 | 40 | |
| 41 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
| 42 | - $clauses = $this->get_range_sql( $range ); |
|
| 43 | - $graphs = array_keys( $this->get_graphs() ); |
|
| 44 | - $graphs_sql = array(); |
|
| 41 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
| 42 | + $clauses = $this->get_range_sql( $range ); |
|
| 43 | + $graphs = array_keys( $this->get_graphs() ); |
|
| 44 | + $graphs_sql = array(); |
|
| 45 | 45 | |
| 46 | - foreach ( $graphs as $graph ) { |
|
| 47 | - $graphs_sql[] = "SUM( meta.$graph ) AS $graph"; |
|
| 48 | - } |
|
| 46 | + foreach ( $graphs as $graph ) { |
|
| 47 | + $graphs_sql[] = "SUM( meta.$graph ) AS $graph"; |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - $graphs_sql = implode( ', ', $graphs_sql ); |
|
| 51 | - $sql = "SELECT {$clauses[0]} AS completed_date, $graphs_sql |
|
| 50 | + $graphs_sql = implode( ', ', $graphs_sql ); |
|
| 51 | + $sql = "SELECT {$clauses[0]} AS completed_date, $graphs_sql |
|
| 52 | 52 | FROM $wpdb->posts |
| 53 | 53 | LEFT JOIN $table as meta ON meta.post_id = $wpdb->posts.ID |
| 54 | 54 | WHERE meta.post_id IS NOT NULL |
@@ -58,94 +58,94 @@ discard block |
||
| 58 | 58 | GROUP BY {$clauses[0]} |
| 59 | 59 | "; |
| 60 | 60 | |
| 61 | - return apply_filters( 'getpaid_earning_graphs_get_sql', $sql, $range ); |
|
| 62 | - |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * Prepares the report stats. |
|
| 67 | - * |
|
| 68 | - */ |
|
| 69 | - public function prepare_stats() { |
|
| 70 | - global $wpdb; |
|
| 71 | - $this->stats = $wpdb->get_results( $this->get_sql( $this->get_range() ) ); |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * Retrieves report labels. |
|
| 76 | - * |
|
| 77 | - */ |
|
| 78 | - public function get_labels( $range ) { |
|
| 79 | - |
|
| 80 | - $labels = array( |
|
| 81 | - 'today' => $this->get_hours_in_a_day(), |
|
| 82 | - 'yesterday' => $this->get_hours_in_a_day(), |
|
| 83 | - '7_days' => $this->get_days_in_period( 7 ), |
|
| 84 | - '30_days' => $this->get_days_in_period( 30 ), |
|
| 85 | - '60_days' => $this->get_days_in_period( 60 ), |
|
| 86 | - '90_days' => $this->get_weeks_in_period( 90 ), |
|
| 87 | - '180_days' => $this->get_weeks_in_period( 180 ), |
|
| 88 | - '360_days' => $this->get_weeks_in_period( 360 ), |
|
| 89 | - ); |
|
| 90 | - |
|
| 91 | - $label = isset( $labels[ $range ] ) ? $labels[ $range ] : $labels['7_days']; |
|
| 92 | - return apply_filters( 'getpaid_earning_graphs_get_labels', $label, $range ); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * Retrieves report datasets. |
|
| 97 | - * |
|
| 98 | - */ |
|
| 99 | - public function get_datasets( $labels ) { |
|
| 100 | - |
|
| 101 | - $datasets = array(); |
|
| 102 | - |
|
| 103 | - foreach ( $this->get_graphs() as $key => $label ) { |
|
| 104 | - $datasets[ $key ] = array( |
|
| 105 | - 'label' => $label, |
|
| 106 | - 'data' => $this->get_data( $key, $labels ), |
|
| 107 | - ); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - return apply_filters( 'getpaid_earning_graphs_get_datasets', $datasets, $labels ); |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * Retrieves report data. |
|
| 115 | - * |
|
| 116 | - */ |
|
| 117 | - public function get_data( $key, $labels ) { |
|
| 118 | - |
|
| 119 | - $data = wp_list_pluck( $this->stats, $key, 'completed_date' ); |
|
| 120 | - $prepared = array(); |
|
| 121 | - |
|
| 122 | - foreach ( $labels as $label ) { |
|
| 123 | - |
|
| 124 | - $value = 0; |
|
| 125 | - if ( isset( $data[ $label ] ) ) { |
|
| 126 | - $value = wpinv_round_amount( wpinv_sanitize_amount( $data[ $label ] ) ); |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - $prepared[] = $value; |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - return apply_filters( 'getpaid_earning_graphs_get_data', $prepared, $key, $labels ); |
|
| 133 | - |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * Displays the report card. |
|
| 138 | - * |
|
| 139 | - */ |
|
| 140 | - public function display() { |
|
| 141 | - |
|
| 142 | - $labels = $this->get_labels( $this->get_range() ); |
|
| 143 | - $chart_data = array( |
|
| 144 | - 'labels' => array_values( $labels ), |
|
| 145 | - 'datasets' => $this->get_datasets( array_keys( $labels ) ), |
|
| 146 | - ); |
|
| 147 | - |
|
| 148 | - ?> |
|
| 61 | + return apply_filters( 'getpaid_earning_graphs_get_sql', $sql, $range ); |
|
| 62 | + |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * Prepares the report stats. |
|
| 67 | + * |
|
| 68 | + */ |
|
| 69 | + public function prepare_stats() { |
|
| 70 | + global $wpdb; |
|
| 71 | + $this->stats = $wpdb->get_results( $this->get_sql( $this->get_range() ) ); |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * Retrieves report labels. |
|
| 76 | + * |
|
| 77 | + */ |
|
| 78 | + public function get_labels( $range ) { |
|
| 79 | + |
|
| 80 | + $labels = array( |
|
| 81 | + 'today' => $this->get_hours_in_a_day(), |
|
| 82 | + 'yesterday' => $this->get_hours_in_a_day(), |
|
| 83 | + '7_days' => $this->get_days_in_period( 7 ), |
|
| 84 | + '30_days' => $this->get_days_in_period( 30 ), |
|
| 85 | + '60_days' => $this->get_days_in_period( 60 ), |
|
| 86 | + '90_days' => $this->get_weeks_in_period( 90 ), |
|
| 87 | + '180_days' => $this->get_weeks_in_period( 180 ), |
|
| 88 | + '360_days' => $this->get_weeks_in_period( 360 ), |
|
| 89 | + ); |
|
| 90 | + |
|
| 91 | + $label = isset( $labels[ $range ] ) ? $labels[ $range ] : $labels['7_days']; |
|
| 92 | + return apply_filters( 'getpaid_earning_graphs_get_labels', $label, $range ); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * Retrieves report datasets. |
|
| 97 | + * |
|
| 98 | + */ |
|
| 99 | + public function get_datasets( $labels ) { |
|
| 100 | + |
|
| 101 | + $datasets = array(); |
|
| 102 | + |
|
| 103 | + foreach ( $this->get_graphs() as $key => $label ) { |
|
| 104 | + $datasets[ $key ] = array( |
|
| 105 | + 'label' => $label, |
|
| 106 | + 'data' => $this->get_data( $key, $labels ), |
|
| 107 | + ); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + return apply_filters( 'getpaid_earning_graphs_get_datasets', $datasets, $labels ); |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * Retrieves report data. |
|
| 115 | + * |
|
| 116 | + */ |
|
| 117 | + public function get_data( $key, $labels ) { |
|
| 118 | + |
|
| 119 | + $data = wp_list_pluck( $this->stats, $key, 'completed_date' ); |
|
| 120 | + $prepared = array(); |
|
| 121 | + |
|
| 122 | + foreach ( $labels as $label ) { |
|
| 123 | + |
|
| 124 | + $value = 0; |
|
| 125 | + if ( isset( $data[ $label ] ) ) { |
|
| 126 | + $value = wpinv_round_amount( wpinv_sanitize_amount( $data[ $label ] ) ); |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + $prepared[] = $value; |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + return apply_filters( 'getpaid_earning_graphs_get_data', $prepared, $key, $labels ); |
|
| 133 | + |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * Displays the report card. |
|
| 138 | + * |
|
| 139 | + */ |
|
| 140 | + public function display() { |
|
| 141 | + |
|
| 142 | + $labels = $this->get_labels( $this->get_range() ); |
|
| 143 | + $chart_data = array( |
|
| 144 | + 'labels' => array_values( $labels ), |
|
| 145 | + 'datasets' => $this->get_datasets( array_keys( $labels ) ), |
|
| 146 | + ); |
|
| 147 | + |
|
| 148 | + ?> |
|
| 149 | 149 | |
| 150 | 150 | <?php foreach ( $chart_data['datasets'] as $key => $dataset ) : ?> |
| 151 | 151 | <div class="row mb-4"> |
@@ -165,15 +165,15 @@ discard block |
||
| 165 | 165 | |
| 166 | 166 | <?php |
| 167 | 167 | |
| 168 | - } |
|
| 168 | + } |
|
| 169 | 169 | |
| 170 | - /** |
|
| 171 | - * Displays the actual report. |
|
| 172 | - * |
|
| 173 | - */ |
|
| 174 | - public function display_graph( $key, $dataset, $labels ) { |
|
| 170 | + /** |
|
| 171 | + * Displays the actual report. |
|
| 172 | + * |
|
| 173 | + */ |
|
| 174 | + public function display_graph( $key, $dataset, $labels ) { |
|
| 175 | 175 | |
| 176 | - ?> |
|
| 176 | + ?> |
|
| 177 | 177 | |
| 178 | 178 | <canvas id="getpaid-chartjs-earnings-<?php echo esc_attr( $key ); ?>"></canvas> |
| 179 | 179 | |
@@ -223,20 +223,20 @@ discard block |
||
| 223 | 223 | </script> |
| 224 | 224 | |
| 225 | 225 | <?php |
| 226 | - } |
|
| 226 | + } |
|
| 227 | 227 | |
| 228 | - /** |
|
| 229 | - * Displays the actual report. |
|
| 230 | - * |
|
| 231 | - */ |
|
| 232 | - public function display_stats() {} |
|
| 228 | + /** |
|
| 229 | + * Displays the actual report. |
|
| 230 | + * |
|
| 231 | + */ |
|
| 232 | + public function display_stats() {} |
|
| 233 | 233 | |
| 234 | - /** |
|
| 235 | - * Displays the range selector. |
|
| 236 | - * |
|
| 237 | - */ |
|
| 238 | - public function display_range_selector() { |
|
| 234 | + /** |
|
| 235 | + * Displays the range selector. |
|
| 236 | + * |
|
| 237 | + */ |
|
| 238 | + public function display_range_selector() { |
|
| 239 | 239 | |
| 240 | - } |
|
| 240 | + } |
|
| 241 | 241 | |
| 242 | 242 | } |
@@ -5,7 +5,7 @@ discard block |
||
| 5 | 5 | * |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | -defined( 'ABSPATH' ) || exit; |
|
| 8 | +defined('ABSPATH') || exit; |
|
| 9 | 9 | |
| 10 | 10 | /** |
| 11 | 11 | * GetPaid_Reports_Report_Earnings Class. |
@@ -20,14 +20,14 @@ discard block |
||
| 20 | 20 | |
| 21 | 21 | $graphs = array( |
| 22 | 22 | |
| 23 | - 'total' => __( 'Earnings', 'invoicing' ), |
|
| 24 | - 'discount' => __( 'Discount', 'invoicing' ), |
|
| 25 | - 'fees_total' => __( 'Fees', 'invoicing' ), |
|
| 26 | - 'tax' => __( 'Tax', 'invoicing' ), |
|
| 23 | + 'total' => __('Earnings', 'invoicing'), |
|
| 24 | + 'discount' => __('Discount', 'invoicing'), |
|
| 25 | + 'fees_total' => __('Fees', 'invoicing'), |
|
| 26 | + 'tax' => __('Tax', 'invoicing'), |
|
| 27 | 27 | |
| 28 | 28 | ); |
| 29 | 29 | |
| 30 | - return apply_filters( 'getpaid_earning_graphs', $graphs ); |
|
| 30 | + return apply_filters('getpaid_earning_graphs', $graphs); |
|
| 31 | 31 | |
| 32 | 32 | } |
| 33 | 33 | |
@@ -35,19 +35,19 @@ discard block |
||
| 35 | 35 | * Retrieves the earning sql. |
| 36 | 36 | * |
| 37 | 37 | */ |
| 38 | - public function get_sql( $range ) { |
|
| 38 | + public function get_sql($range) { |
|
| 39 | 39 | global $wpdb; |
| 40 | 40 | |
| 41 | 41 | $table = $wpdb->prefix . 'getpaid_invoices'; |
| 42 | - $clauses = $this->get_range_sql( $range ); |
|
| 43 | - $graphs = array_keys( $this->get_graphs() ); |
|
| 42 | + $clauses = $this->get_range_sql($range); |
|
| 43 | + $graphs = array_keys($this->get_graphs()); |
|
| 44 | 44 | $graphs_sql = array(); |
| 45 | 45 | |
| 46 | - foreach ( $graphs as $graph ) { |
|
| 46 | + foreach ($graphs as $graph) { |
|
| 47 | 47 | $graphs_sql[] = "SUM( meta.$graph ) AS $graph"; |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | - $graphs_sql = implode( ', ', $graphs_sql ); |
|
| 50 | + $graphs_sql = implode(', ', $graphs_sql); |
|
| 51 | 51 | $sql = "SELECT {$clauses[0]} AS completed_date, $graphs_sql |
| 52 | 52 | FROM $wpdb->posts |
| 53 | 53 | LEFT JOIN $table as meta ON meta.post_id = $wpdb->posts.ID |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | GROUP BY {$clauses[0]} |
| 59 | 59 | "; |
| 60 | 60 | |
| 61 | - return apply_filters( 'getpaid_earning_graphs_get_sql', $sql, $range ); |
|
| 61 | + return apply_filters('getpaid_earning_graphs_get_sql', $sql, $range); |
|
| 62 | 62 | |
| 63 | 63 | } |
| 64 | 64 | |
@@ -68,68 +68,68 @@ discard block |
||
| 68 | 68 | */ |
| 69 | 69 | public function prepare_stats() { |
| 70 | 70 | global $wpdb; |
| 71 | - $this->stats = $wpdb->get_results( $this->get_sql( $this->get_range() ) ); |
|
| 71 | + $this->stats = $wpdb->get_results($this->get_sql($this->get_range())); |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | /** |
| 75 | 75 | * Retrieves report labels. |
| 76 | 76 | * |
| 77 | 77 | */ |
| 78 | - public function get_labels( $range ) { |
|
| 78 | + public function get_labels($range) { |
|
| 79 | 79 | |
| 80 | 80 | $labels = array( |
| 81 | 81 | 'today' => $this->get_hours_in_a_day(), |
| 82 | 82 | 'yesterday' => $this->get_hours_in_a_day(), |
| 83 | - '7_days' => $this->get_days_in_period( 7 ), |
|
| 84 | - '30_days' => $this->get_days_in_period( 30 ), |
|
| 85 | - '60_days' => $this->get_days_in_period( 60 ), |
|
| 86 | - '90_days' => $this->get_weeks_in_period( 90 ), |
|
| 87 | - '180_days' => $this->get_weeks_in_period( 180 ), |
|
| 88 | - '360_days' => $this->get_weeks_in_period( 360 ), |
|
| 83 | + '7_days' => $this->get_days_in_period(7), |
|
| 84 | + '30_days' => $this->get_days_in_period(30), |
|
| 85 | + '60_days' => $this->get_days_in_period(60), |
|
| 86 | + '90_days' => $this->get_weeks_in_period(90), |
|
| 87 | + '180_days' => $this->get_weeks_in_period(180), |
|
| 88 | + '360_days' => $this->get_weeks_in_period(360), |
|
| 89 | 89 | ); |
| 90 | 90 | |
| 91 | - $label = isset( $labels[ $range ] ) ? $labels[ $range ] : $labels['7_days']; |
|
| 92 | - return apply_filters( 'getpaid_earning_graphs_get_labels', $label, $range ); |
|
| 91 | + $label = isset($labels[$range]) ? $labels[$range] : $labels['7_days']; |
|
| 92 | + return apply_filters('getpaid_earning_graphs_get_labels', $label, $range); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | /** |
| 96 | 96 | * Retrieves report datasets. |
| 97 | 97 | * |
| 98 | 98 | */ |
| 99 | - public function get_datasets( $labels ) { |
|
| 99 | + public function get_datasets($labels) { |
|
| 100 | 100 | |
| 101 | 101 | $datasets = array(); |
| 102 | 102 | |
| 103 | - foreach ( $this->get_graphs() as $key => $label ) { |
|
| 104 | - $datasets[ $key ] = array( |
|
| 103 | + foreach ($this->get_graphs() as $key => $label) { |
|
| 104 | + $datasets[$key] = array( |
|
| 105 | 105 | 'label' => $label, |
| 106 | - 'data' => $this->get_data( $key, $labels ), |
|
| 106 | + 'data' => $this->get_data($key, $labels), |
|
| 107 | 107 | ); |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | - return apply_filters( 'getpaid_earning_graphs_get_datasets', $datasets, $labels ); |
|
| 110 | + return apply_filters('getpaid_earning_graphs_get_datasets', $datasets, $labels); |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | /** |
| 114 | 114 | * Retrieves report data. |
| 115 | 115 | * |
| 116 | 116 | */ |
| 117 | - public function get_data( $key, $labels ) { |
|
| 117 | + public function get_data($key, $labels) { |
|
| 118 | 118 | |
| 119 | - $data = wp_list_pluck( $this->stats, $key, 'completed_date' ); |
|
| 119 | + $data = wp_list_pluck($this->stats, $key, 'completed_date'); |
|
| 120 | 120 | $prepared = array(); |
| 121 | 121 | |
| 122 | - foreach ( $labels as $label ) { |
|
| 122 | + foreach ($labels as $label) { |
|
| 123 | 123 | |
| 124 | 124 | $value = 0; |
| 125 | - if ( isset( $data[ $label ] ) ) { |
|
| 126 | - $value = wpinv_round_amount( wpinv_sanitize_amount( $data[ $label ] ) ); |
|
| 125 | + if (isset($data[$label])) { |
|
| 126 | + $value = wpinv_round_amount(wpinv_sanitize_amount($data[$label])); |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | $prepared[] = $value; |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | - return apply_filters( 'getpaid_earning_graphs_get_data', $prepared, $key, $labels ); |
|
| 132 | + return apply_filters('getpaid_earning_graphs_get_data', $prepared, $key, $labels); |
|
| 133 | 133 | |
| 134 | 134 | } |
| 135 | 135 | |
@@ -139,24 +139,24 @@ discard block |
||
| 139 | 139 | */ |
| 140 | 140 | public function display() { |
| 141 | 141 | |
| 142 | - $labels = $this->get_labels( $this->get_range() ); |
|
| 142 | + $labels = $this->get_labels($this->get_range()); |
|
| 143 | 143 | $chart_data = array( |
| 144 | - 'labels' => array_values( $labels ), |
|
| 145 | - 'datasets' => $this->get_datasets( array_keys( $labels ) ), |
|
| 144 | + 'labels' => array_values($labels), |
|
| 145 | + 'datasets' => $this->get_datasets(array_keys($labels)), |
|
| 146 | 146 | ); |
| 147 | 147 | |
| 148 | 148 | ?> |
| 149 | 149 | |
| 150 | - <?php foreach ( $chart_data['datasets'] as $key => $dataset ) : ?> |
|
| 150 | + <?php foreach ($chart_data['datasets'] as $key => $dataset) : ?> |
|
| 151 | 151 | <div class="row mb-4"> |
| 152 | 152 | <div class="col-12"> |
| 153 | 153 | <div class="card m-0 p-0" style="max-width:100%"> |
| 154 | 154 | <div class="card-header d-flex align-items-center"> |
| 155 | - <strong class="flex-grow-1"><?php echo esc_html( $dataset['label'] ); ?></strong> |
|
| 155 | + <strong class="flex-grow-1"><?php echo esc_html($dataset['label']); ?></strong> |
|
| 156 | 156 | <?php $this->display_range_selector(); ?> |
| 157 | 157 | </div> |
| 158 | 158 | <div class="card-body"> |
| 159 | - <?php $this->display_graph( $key, $dataset, $chart_data['labels'] ); ?> |
|
| 159 | + <?php $this->display_graph($key, $dataset, $chart_data['labels']); ?> |
|
| 160 | 160 | </div> |
| 161 | 161 | </div> |
| 162 | 162 | </div> |
@@ -171,26 +171,26 @@ discard block |
||
| 171 | 171 | * Displays the actual report. |
| 172 | 172 | * |
| 173 | 173 | */ |
| 174 | - public function display_graph( $key, $dataset, $labels ) { |
|
| 174 | + public function display_graph($key, $dataset, $labels) { |
|
| 175 | 175 | |
| 176 | 176 | ?> |
| 177 | 177 | |
| 178 | - <canvas id="getpaid-chartjs-earnings-<?php echo esc_attr( $key ); ?>"></canvas> |
|
| 178 | + <canvas id="getpaid-chartjs-earnings-<?php echo esc_attr($key); ?>"></canvas> |
|
| 179 | 179 | |
| 180 | 180 | <script> |
| 181 | 181 | window.addEventListener( 'DOMContentLoaded', function() { |
| 182 | 182 | |
| 183 | - var ctx = document.getElementById( 'getpaid-chartjs-earnings-<?php echo esc_attr( $key ); ?>' ).getContext('2d'); |
|
| 183 | + var ctx = document.getElementById( 'getpaid-chartjs-earnings-<?php echo esc_attr($key); ?>' ).getContext('2d'); |
|
| 184 | 184 | new Chart( |
| 185 | 185 | ctx, |
| 186 | 186 | { |
| 187 | 187 | type: 'line', |
| 188 | 188 | data: { |
| 189 | - 'labels': <?php echo wp_json_encode( wpinv_clean( $labels ) ); ?>, |
|
| 189 | + 'labels': <?php echo wp_json_encode(wpinv_clean($labels)); ?>, |
|
| 190 | 190 | 'datasets': [ |
| 191 | 191 | { |
| 192 | - label: '<?php echo esc_attr( $dataset['label'] ); ?>', |
|
| 193 | - data: <?php echo wp_json_encode( wpinv_clean( $dataset['data'] ) ); ?>, |
|
| 192 | + label: '<?php echo esc_attr($dataset['label']); ?>', |
|
| 193 | + data: <?php echo wp_json_encode(wpinv_clean($dataset['data'])); ?>, |
|
| 194 | 194 | backgroundColor: 'rgba(54, 162, 235, 0.1)', |
| 195 | 195 | borderColor: 'rgb(54, 162, 235)', |
| 196 | 196 | borderWidth: 4, |
@@ -12,22 +12,22 @@ discard block |
||
| 12 | 12 | */ |
| 13 | 13 | class GetPaid_Reports_Report_Discounts extends GetPaid_Reports_Abstract_Report { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * @var string |
|
| 17 | - */ |
|
| 18 | - public $field = 'discount_code'; |
|
| 19 | - |
|
| 20 | - /** |
|
| 21 | - * Retrieves the discounts sql. |
|
| 22 | - * |
|
| 23 | - */ |
|
| 24 | - public function get_sql( $range ) { |
|
| 25 | - global $wpdb; |
|
| 26 | - |
|
| 27 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
| 28 | - $clauses = $this->get_range_sql( $range ); |
|
| 29 | - |
|
| 30 | - $sql = "SELECT |
|
| 15 | + /** |
|
| 16 | + * @var string |
|
| 17 | + */ |
|
| 18 | + public $field = 'discount_code'; |
|
| 19 | + |
|
| 20 | + /** |
|
| 21 | + * Retrieves the discounts sql. |
|
| 22 | + * |
|
| 23 | + */ |
|
| 24 | + public function get_sql( $range ) { |
|
| 25 | + global $wpdb; |
|
| 26 | + |
|
| 27 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
| 28 | + $clauses = $this->get_range_sql( $range ); |
|
| 29 | + |
|
| 30 | + $sql = "SELECT |
|
| 31 | 31 | meta.discount_code AS discount_code, |
| 32 | 32 | SUM(total) as total |
| 33 | 33 | FROM $wpdb->posts |
@@ -41,91 +41,91 @@ discard block |
||
| 41 | 41 | ORDER BY total DESC |
| 42 | 42 | "; |
| 43 | 43 | |
| 44 | - return apply_filters( 'getpaid_discounts_graphs_get_sql', $sql, $range ); |
|
| 44 | + return apply_filters( 'getpaid_discounts_graphs_get_sql', $sql, $range ); |
|
| 45 | 45 | |
| 46 | - } |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * Prepares the report stats. |
|
| 50 | - * |
|
| 51 | - */ |
|
| 52 | - public function prepare_stats() { |
|
| 53 | - global $wpdb; |
|
| 54 | - $this->stats = $wpdb->get_results( $this->get_sql( $this->get_range() ) ); |
|
| 55 | - $this->stats = $this->normalize_stats( $this->stats ); |
|
| 56 | - } |
|
| 48 | + /** |
|
| 49 | + * Prepares the report stats. |
|
| 50 | + * |
|
| 51 | + */ |
|
| 52 | + public function prepare_stats() { |
|
| 53 | + global $wpdb; |
|
| 54 | + $this->stats = $wpdb->get_results( $this->get_sql( $this->get_range() ) ); |
|
| 55 | + $this->stats = $this->normalize_stats( $this->stats ); |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * Normalizes the report stats. |
|
| 60 | - * |
|
| 61 | - */ |
|
| 62 | - public function normalize_stats( $stats ) { |
|
| 63 | - $normalized = array(); |
|
| 64 | - $others = 0; |
|
| 65 | - $did = 0; |
|
| 58 | + /** |
|
| 59 | + * Normalizes the report stats. |
|
| 60 | + * |
|
| 61 | + */ |
|
| 62 | + public function normalize_stats( $stats ) { |
|
| 63 | + $normalized = array(); |
|
| 64 | + $others = 0; |
|
| 65 | + $did = 0; |
|
| 66 | 66 | |
| 67 | - foreach ( $stats as $stat ) { |
|
| 67 | + foreach ( $stats as $stat ) { |
|
| 68 | 68 | |
| 69 | - if ( $did > 4 ) { |
|
| 69 | + if ( $did > 4 ) { |
|
| 70 | 70 | |
| 71 | - $others += wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ); |
|
| 71 | + $others += wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ); |
|
| 72 | 72 | |
| 73 | - } else { |
|
| 73 | + } else { |
|
| 74 | 74 | |
| 75 | - $normalized[] = array( |
|
| 76 | - 'total' => wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ), |
|
| 77 | - 'discount_code' => strip_tags( $stat->discount_code ), |
|
| 78 | - ); |
|
| 75 | + $normalized[] = array( |
|
| 76 | + 'total' => wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ), |
|
| 77 | + 'discount_code' => strip_tags( $stat->discount_code ), |
|
| 78 | + ); |
|
| 79 | 79 | |
| 80 | - } |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - $did++; |
|
| 83 | - } |
|
| 82 | + $did++; |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - if ( $others > 0 ) { |
|
| 85 | + if ( $others > 0 ) { |
|
| 86 | 86 | |
| 87 | - $normalized[] = array( |
|
| 88 | - 'total' => wpinv_round_amount( wpinv_sanitize_amount( $others ) ), |
|
| 89 | - 'discount_code' => esc_html__( 'Others', 'invoicing' ), |
|
| 90 | - ); |
|
| 87 | + $normalized[] = array( |
|
| 88 | + 'total' => wpinv_round_amount( wpinv_sanitize_amount( $others ) ), |
|
| 89 | + 'discount_code' => esc_html__( 'Others', 'invoicing' ), |
|
| 90 | + ); |
|
| 91 | 91 | |
| 92 | - } |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - return $normalized; |
|
| 95 | - } |
|
| 94 | + return $normalized; |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - /** |
|
| 98 | - * Retrieves report data. |
|
| 99 | - * |
|
| 100 | - */ |
|
| 101 | - public function get_data() { |
|
| 97 | + /** |
|
| 98 | + * Retrieves report data. |
|
| 99 | + * |
|
| 100 | + */ |
|
| 101 | + public function get_data() { |
|
| 102 | 102 | |
| 103 | - $data = wp_list_pluck( $this->stats, 'total' ); |
|
| 104 | - $colors = array( '#009688', '#4caf50', '#8bc34a', '#00bcd4', '#03a9f4', '#2196f3' ); |
|
| 103 | + $data = wp_list_pluck( $this->stats, 'total' ); |
|
| 104 | + $colors = array( '#009688', '#4caf50', '#8bc34a', '#00bcd4', '#03a9f4', '#2196f3' ); |
|
| 105 | 105 | |
| 106 | - shuffle( $colors ); |
|
| 106 | + shuffle( $colors ); |
|
| 107 | 107 | |
| 108 | - return array( |
|
| 109 | - 'data' => $data, |
|
| 110 | - 'backgroundColor' => $colors, |
|
| 111 | - ); |
|
| 108 | + return array( |
|
| 109 | + 'data' => $data, |
|
| 110 | + 'backgroundColor' => $colors, |
|
| 111 | + ); |
|
| 112 | 112 | |
| 113 | - } |
|
| 113 | + } |
|
| 114 | 114 | |
| 115 | - /** |
|
| 116 | - * Retrieves report labels. |
|
| 117 | - * |
|
| 118 | - */ |
|
| 119 | - public function get_labels() { |
|
| 120 | - return wp_list_pluck( $this->stats, 'discount_code' ); |
|
| 121 | - } |
|
| 115 | + /** |
|
| 116 | + * Retrieves report labels. |
|
| 117 | + * |
|
| 118 | + */ |
|
| 119 | + public function get_labels() { |
|
| 120 | + return wp_list_pluck( $this->stats, 'discount_code' ); |
|
| 121 | + } |
|
| 122 | 122 | |
| 123 | - /** |
|
| 124 | - * Displays the actual report. |
|
| 125 | - * |
|
| 126 | - */ |
|
| 127 | - public function display_stats() { |
|
| 128 | - ?> |
|
| 123 | + /** |
|
| 124 | + * Displays the actual report. |
|
| 125 | + * |
|
| 126 | + */ |
|
| 127 | + public function display_stats() { |
|
| 128 | + ?> |
|
| 129 | 129 | |
| 130 | 130 | <canvas id="getpaid-chartjs-earnings-discount_code"></canvas> |
| 131 | 131 | |
@@ -154,6 +154,6 @@ discard block |
||
| 154 | 154 | </script> |
| 155 | 155 | |
| 156 | 156 | <?php |
| 157 | - } |
|
| 157 | + } |
|
| 158 | 158 | |
| 159 | 159 | } |
@@ -5,7 +5,7 @@ discard block |
||
| 5 | 5 | * |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | -defined( 'ABSPATH' ) || exit; |
|
| 8 | +defined('ABSPATH') || exit; |
|
| 9 | 9 | |
| 10 | 10 | /** |
| 11 | 11 | * GetPaid_Reports_Report_Discounts Class. |
@@ -21,11 +21,11 @@ discard block |
||
| 21 | 21 | * Retrieves the discounts sql. |
| 22 | 22 | * |
| 23 | 23 | */ |
| 24 | - public function get_sql( $range ) { |
|
| 24 | + public function get_sql($range) { |
|
| 25 | 25 | global $wpdb; |
| 26 | 26 | |
| 27 | 27 | $table = $wpdb->prefix . 'getpaid_invoices'; |
| 28 | - $clauses = $this->get_range_sql( $range ); |
|
| 28 | + $clauses = $this->get_range_sql($range); |
|
| 29 | 29 | |
| 30 | 30 | $sql = "SELECT |
| 31 | 31 | meta.discount_code AS discount_code, |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | ORDER BY total DESC |
| 42 | 42 | "; |
| 43 | 43 | |
| 44 | - return apply_filters( 'getpaid_discounts_graphs_get_sql', $sql, $range ); |
|
| 44 | + return apply_filters('getpaid_discounts_graphs_get_sql', $sql, $range); |
|
| 45 | 45 | |
| 46 | 46 | } |
| 47 | 47 | |
@@ -51,30 +51,30 @@ discard block |
||
| 51 | 51 | */ |
| 52 | 52 | public function prepare_stats() { |
| 53 | 53 | global $wpdb; |
| 54 | - $this->stats = $wpdb->get_results( $this->get_sql( $this->get_range() ) ); |
|
| 55 | - $this->stats = $this->normalize_stats( $this->stats ); |
|
| 54 | + $this->stats = $wpdb->get_results($this->get_sql($this->get_range())); |
|
| 55 | + $this->stats = $this->normalize_stats($this->stats); |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | /** |
| 59 | 59 | * Normalizes the report stats. |
| 60 | 60 | * |
| 61 | 61 | */ |
| 62 | - public function normalize_stats( $stats ) { |
|
| 62 | + public function normalize_stats($stats) { |
|
| 63 | 63 | $normalized = array(); |
| 64 | 64 | $others = 0; |
| 65 | 65 | $did = 0; |
| 66 | 66 | |
| 67 | - foreach ( $stats as $stat ) { |
|
| 67 | + foreach ($stats as $stat) { |
|
| 68 | 68 | |
| 69 | - if ( $did > 4 ) { |
|
| 69 | + if ($did > 4) { |
|
| 70 | 70 | |
| 71 | - $others += wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ); |
|
| 71 | + $others += wpinv_round_amount(wpinv_sanitize_amount($stat->total)); |
|
| 72 | 72 | |
| 73 | 73 | } else { |
| 74 | 74 | |
| 75 | 75 | $normalized[] = array( |
| 76 | - 'total' => wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ), |
|
| 77 | - 'discount_code' => strip_tags( $stat->discount_code ), |
|
| 76 | + 'total' => wpinv_round_amount(wpinv_sanitize_amount($stat->total)), |
|
| 77 | + 'discount_code' => strip_tags($stat->discount_code), |
|
| 78 | 78 | ); |
| 79 | 79 | |
| 80 | 80 | } |
@@ -82,11 +82,11 @@ discard block |
||
| 82 | 82 | $did++; |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | - if ( $others > 0 ) { |
|
| 85 | + if ($others > 0) { |
|
| 86 | 86 | |
| 87 | 87 | $normalized[] = array( |
| 88 | - 'total' => wpinv_round_amount( wpinv_sanitize_amount( $others ) ), |
|
| 89 | - 'discount_code' => esc_html__( 'Others', 'invoicing' ), |
|
| 88 | + 'total' => wpinv_round_amount(wpinv_sanitize_amount($others)), |
|
| 89 | + 'discount_code' => esc_html__('Others', 'invoicing'), |
|
| 90 | 90 | ); |
| 91 | 91 | |
| 92 | 92 | } |
@@ -100,10 +100,10 @@ discard block |
||
| 100 | 100 | */ |
| 101 | 101 | public function get_data() { |
| 102 | 102 | |
| 103 | - $data = wp_list_pluck( $this->stats, 'total' ); |
|
| 104 | - $colors = array( '#009688', '#4caf50', '#8bc34a', '#00bcd4', '#03a9f4', '#2196f3' ); |
|
| 103 | + $data = wp_list_pluck($this->stats, 'total'); |
|
| 104 | + $colors = array('#009688', '#4caf50', '#8bc34a', '#00bcd4', '#03a9f4', '#2196f3'); |
|
| 105 | 105 | |
| 106 | - shuffle( $colors ); |
|
| 106 | + shuffle($colors); |
|
| 107 | 107 | |
| 108 | 108 | return array( |
| 109 | 109 | 'data' => $data, |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | * |
| 118 | 118 | */ |
| 119 | 119 | public function get_labels() { |
| 120 | - return wp_list_pluck( $this->stats, 'discount_code' ); |
|
| 120 | + return wp_list_pluck($this->stats, 'discount_code'); |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | /** |
@@ -138,8 +138,8 @@ discard block |
||
| 138 | 138 | { |
| 139 | 139 | type: 'doughnut', |
| 140 | 140 | data: { |
| 141 | - 'labels': <?php echo wp_json_encode( wpinv_clean( $this->get_labels() ) ); ?>, |
|
| 142 | - 'datasets': [ <?php echo wp_json_encode( wpinv_clean( $this->get_data() ) ); ?> ] |
|
| 141 | + 'labels': <?php echo wp_json_encode(wpinv_clean($this->get_labels())); ?>, |
|
| 142 | + 'datasets': [ <?php echo wp_json_encode(wpinv_clean($this->get_data())); ?> ] |
|
| 143 | 143 | }, |
| 144 | 144 | options: { |
| 145 | 145 | legend: { |
@@ -12,88 +12,88 @@ discard block |
||
| 12 | 12 | */ |
| 13 | 13 | class GetPaid_Reports_Report { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * @var array |
|
| 17 | - */ |
|
| 18 | - public $views; |
|
| 15 | + /** |
|
| 16 | + * @var array |
|
| 17 | + */ |
|
| 18 | + public $views; |
|
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * Class constructor. |
|
| 22 | - * |
|
| 23 | - */ |
|
| 24 | - public function __construct() { |
|
| 20 | + /** |
|
| 21 | + * Class constructor. |
|
| 22 | + * |
|
| 23 | + */ |
|
| 24 | + public function __construct() { |
|
| 25 | 25 | |
| 26 | - $this->views = array( |
|
| 26 | + $this->views = array( |
|
| 27 | 27 | |
| 28 | 28 | 'items' => array( |
| 29 | - 'label' => __( 'Items', 'invoicing' ), |
|
| 30 | - 'class' => 'GetPaid_Reports_Report_Items', |
|
| 31 | - ), |
|
| 29 | + 'label' => __( 'Items', 'invoicing' ), |
|
| 30 | + 'class' => 'GetPaid_Reports_Report_Items', |
|
| 31 | + ), |
|
| 32 | 32 | |
| 33 | - 'gateways' => array( |
|
| 34 | - 'label' => __( 'Payment Methods', 'invoicing' ), |
|
| 35 | - 'class' => 'GetPaid_Reports_Report_Gateways', |
|
| 36 | - ), |
|
| 33 | + 'gateways' => array( |
|
| 34 | + 'label' => __( 'Payment Methods', 'invoicing' ), |
|
| 35 | + 'class' => 'GetPaid_Reports_Report_Gateways', |
|
| 36 | + ), |
|
| 37 | 37 | |
| 38 | - 'discounts' => array( |
|
| 39 | - 'label' => __( 'Discount Codes', 'invoicing' ), |
|
| 40 | - 'class' => 'GetPaid_Reports_Report_Discounts', |
|
| 41 | - ), |
|
| 38 | + 'discounts' => array( |
|
| 39 | + 'label' => __( 'Discount Codes', 'invoicing' ), |
|
| 40 | + 'class' => 'GetPaid_Reports_Report_Discounts', |
|
| 41 | + ), |
|
| 42 | 42 | |
| 43 | 43 | ); |
| 44 | 44 | |
| 45 | - $this->views = apply_filters( 'wpinv_report_views', $this->views ); |
|
| 46 | - |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * Retrieves the current range. |
|
| 51 | - * |
|
| 52 | - */ |
|
| 53 | - public function get_range() { |
|
| 54 | - $valid_ranges = $this->get_periods(); |
|
| 55 | - |
|
| 56 | - if ( isset( $_GET['date_range'] ) && array_key_exists( $_GET['date_range'], $valid_ranges ) ) { |
|
| 57 | - return sanitize_key( $_GET['date_range'] ); |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - return '7_days'; |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * Returns an array of date ranges. |
|
| 65 | - * |
|
| 66 | - * @return array |
|
| 67 | - */ |
|
| 68 | - public function get_periods() { |
|
| 69 | - |
|
| 70 | - $periods = array( |
|
| 71 | - 'today' => __( 'Today', 'invoicing' ), |
|
| 72 | - 'yesterday' => __( 'Yesterday', 'invoicing' ), |
|
| 73 | - 'week' => __( 'This week', 'invoicing' ), |
|
| 74 | - 'last_week' => __( 'Last week', 'invoicing' ), |
|
| 75 | - '7_days' => __( 'Last 7 days', 'invoicing' ), |
|
| 76 | - 'month' => __( 'This month', 'invoicing' ), |
|
| 77 | - 'last_month' => __( 'Last month', 'invoicing' ), |
|
| 78 | - '30_days' => __( 'Last 30 days', 'invoicing' ), |
|
| 79 | - 'quarter' => __( 'This Quarter', 'invoicing' ), |
|
| 80 | - 'last_quarter' => __( 'Last Quarter', 'invoicing' ), |
|
| 81 | - 'year' => __( 'This year', 'invoicing' ), |
|
| 82 | - 'last_year' => __( 'Last Year', 'invoicing' ), |
|
| 83 | - 'custom' => __( 'Custom Date Range', 'invoicing' ), |
|
| 84 | - ); |
|
| 85 | - |
|
| 86 | - return apply_filters( 'getpaid_earning_periods', $periods ); |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * Displays the range selector. |
|
| 91 | - * |
|
| 92 | - */ |
|
| 93 | - public function display_range_selector() { |
|
| 94 | - |
|
| 95 | - $range = $this->get_range(); |
|
| 96 | - ?> |
|
| 45 | + $this->views = apply_filters( 'wpinv_report_views', $this->views ); |
|
| 46 | + |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * Retrieves the current range. |
|
| 51 | + * |
|
| 52 | + */ |
|
| 53 | + public function get_range() { |
|
| 54 | + $valid_ranges = $this->get_periods(); |
|
| 55 | + |
|
| 56 | + if ( isset( $_GET['date_range'] ) && array_key_exists( $_GET['date_range'], $valid_ranges ) ) { |
|
| 57 | + return sanitize_key( $_GET['date_range'] ); |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + return '7_days'; |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * Returns an array of date ranges. |
|
| 65 | + * |
|
| 66 | + * @return array |
|
| 67 | + */ |
|
| 68 | + public function get_periods() { |
|
| 69 | + |
|
| 70 | + $periods = array( |
|
| 71 | + 'today' => __( 'Today', 'invoicing' ), |
|
| 72 | + 'yesterday' => __( 'Yesterday', 'invoicing' ), |
|
| 73 | + 'week' => __( 'This week', 'invoicing' ), |
|
| 74 | + 'last_week' => __( 'Last week', 'invoicing' ), |
|
| 75 | + '7_days' => __( 'Last 7 days', 'invoicing' ), |
|
| 76 | + 'month' => __( 'This month', 'invoicing' ), |
|
| 77 | + 'last_month' => __( 'Last month', 'invoicing' ), |
|
| 78 | + '30_days' => __( 'Last 30 days', 'invoicing' ), |
|
| 79 | + 'quarter' => __( 'This Quarter', 'invoicing' ), |
|
| 80 | + 'last_quarter' => __( 'Last Quarter', 'invoicing' ), |
|
| 81 | + 'year' => __( 'This year', 'invoicing' ), |
|
| 82 | + 'last_year' => __( 'Last Year', 'invoicing' ), |
|
| 83 | + 'custom' => __( 'Custom Date Range', 'invoicing' ), |
|
| 84 | + ); |
|
| 85 | + |
|
| 86 | + return apply_filters( 'getpaid_earning_periods', $periods ); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * Displays the range selector. |
|
| 91 | + * |
|
| 92 | + */ |
|
| 93 | + public function display_range_selector() { |
|
| 94 | + |
|
| 95 | + $range = $this->get_range(); |
|
| 96 | + ?> |
|
| 97 | 97 | |
| 98 | 98 | <form method="get" class="getpaid-filter-earnings float-right"> |
| 99 | 99 | <?php getpaid_hidden_field( 'page', isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : 'wpinv-reports' ); ?> |
@@ -115,14 +115,14 @@ discard block |
||
| 115 | 115 | </form> |
| 116 | 116 | |
| 117 | 117 | <?php |
| 118 | - } |
|
| 118 | + } |
|
| 119 | 119 | |
| 120 | - /** |
|
| 121 | - * Displays the reports tab. |
|
| 122 | - * |
|
| 123 | - */ |
|
| 124 | - public function display() { |
|
| 125 | - ?> |
|
| 120 | + /** |
|
| 121 | + * Displays the reports tab. |
|
| 122 | + * |
|
| 123 | + */ |
|
| 124 | + public function display() { |
|
| 125 | + ?> |
|
| 126 | 126 | |
| 127 | 127 | <div class="mt-4"> |
| 128 | 128 | |
@@ -202,16 +202,16 @@ discard block |
||
| 202 | 202 | |
| 203 | 203 | <?php |
| 204 | 204 | |
| 205 | - } |
|
| 205 | + } |
|
| 206 | 206 | |
| 207 | - /** |
|
| 208 | - * Displays the left side. |
|
| 209 | - * |
|
| 210 | - */ |
|
| 211 | - public function display_left() { |
|
| 212 | - $graphs = wpinv_get_report_graphs(); |
|
| 207 | + /** |
|
| 208 | + * Displays the left side. |
|
| 209 | + * |
|
| 210 | + */ |
|
| 211 | + public function display_left() { |
|
| 212 | + $graphs = wpinv_get_report_graphs(); |
|
| 213 | 213 | |
| 214 | - ?> |
|
| 214 | + ?> |
|
| 215 | 215 | |
| 216 | 216 | <?php foreach ( $graphs as $key => $graph ) : ?> |
| 217 | 217 | <div class="row mb-4"> |
@@ -230,35 +230,35 @@ discard block |
||
| 230 | 230 | |
| 231 | 231 | <?php |
| 232 | 232 | |
| 233 | - } |
|
| 234 | - |
|
| 235 | - /** |
|
| 236 | - * Retrieves the download url. |
|
| 237 | - * |
|
| 238 | - */ |
|
| 239 | - public function get_download_url( $graph, $file_type ) { |
|
| 240 | - |
|
| 241 | - return wp_nonce_url( |
|
| 242 | - add_query_arg( |
|
| 243 | - array( |
|
| 244 | - 'getpaid-admin-action' => 'download_graph', |
|
| 245 | - 'file_type' => urlencode( $file_type ), |
|
| 246 | - 'graph' => urlencode( $graph ), |
|
| 247 | - ) |
|
| 248 | - ), |
|
| 249 | - 'getpaid-nonce', |
|
| 250 | - 'getpaid-nonce' |
|
| 251 | - ); |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + /** |
|
| 236 | + * Retrieves the download url. |
|
| 237 | + * |
|
| 238 | + */ |
|
| 239 | + public function get_download_url( $graph, $file_type ) { |
|
| 240 | + |
|
| 241 | + return wp_nonce_url( |
|
| 242 | + add_query_arg( |
|
| 243 | + array( |
|
| 244 | + 'getpaid-admin-action' => 'download_graph', |
|
| 245 | + 'file_type' => urlencode( $file_type ), |
|
| 246 | + 'graph' => urlencode( $graph ), |
|
| 247 | + ) |
|
| 248 | + ), |
|
| 249 | + 'getpaid-nonce', |
|
| 250 | + 'getpaid-nonce' |
|
| 251 | + ); |
|
| 252 | 252 | |
| 253 | - } |
|
| 253 | + } |
|
| 254 | 254 | |
| 255 | - /** |
|
| 256 | - * Displays the right side. |
|
| 257 | - * |
|
| 258 | - */ |
|
| 259 | - public function display_right() { |
|
| 255 | + /** |
|
| 256 | + * Displays the right side. |
|
| 257 | + * |
|
| 258 | + */ |
|
| 259 | + public function display_right() { |
|
| 260 | 260 | |
| 261 | - ?> |
|
| 261 | + ?> |
|
| 262 | 262 | |
| 263 | 263 | <?php foreach ( $this->views as $key => $view ) : ?> |
| 264 | 264 | <div class="row mb-4"> |
@@ -287,10 +287,10 @@ discard block |
||
| 287 | 287 | </div> |
| 288 | 288 | <div class="card-body"> |
| 289 | 289 | <?php |
| 290 | - $class = $view['class']; |
|
| 291 | - $class = new $class(); |
|
| 292 | - $class->display_stats(); |
|
| 293 | - ?> |
|
| 290 | + $class = $view['class']; |
|
| 291 | + $class = new $class(); |
|
| 292 | + $class->display_stats(); |
|
| 293 | + ?> |
|
| 294 | 294 | </div> |
| 295 | 295 | </div> |
| 296 | 296 | </div> |
@@ -299,68 +299,68 @@ discard block |
||
| 299 | 299 | |
| 300 | 300 | <?php |
| 301 | 301 | |
| 302 | - do_action( 'getpaid_reports_display_right', $this ); |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - /** |
|
| 306 | - * Returns a list of report cards. |
|
| 307 | - * |
|
| 308 | - */ |
|
| 309 | - public function get_cards() { |
|
| 310 | - |
|
| 311 | - $cards = array( |
|
| 312 | - 'total_sales' => array( |
|
| 313 | - 'description' => __( 'Gross sales in the period.', 'invoicing' ), |
|
| 314 | - 'label' => __( 'Gross Revenue', 'invoicing' ), |
|
| 315 | - ), |
|
| 316 | - 'net_sales' => array( |
|
| 317 | - 'description' => __( 'Net sales in the period.', 'invoicing' ), |
|
| 318 | - 'label' => __( 'Net Revenue', 'invoicing' ), |
|
| 319 | - ), |
|
| 320 | - 'average_sales' => array( |
|
| 321 | - 'description' => __( 'Average net daily/monthly sales.', 'invoicing' ), |
|
| 322 | - 'label' => __( 'Avg. Net Sales', 'invoicing' ), |
|
| 323 | - ), |
|
| 324 | - 'average_total_sales' => array( |
|
| 325 | - 'description' => __( 'Average gross daily/monthly sales.', 'invoicing' ), |
|
| 326 | - 'label' => __( 'Avg. Gross Sales', 'invoicing' ), |
|
| 327 | - ), |
|
| 328 | - 'total_invoices' => array( |
|
| 329 | - 'description' => __( 'Number of paid invoices.', 'invoicing' ), |
|
| 330 | - 'label' => __( 'Paid Invoices', 'invoicing' ), |
|
| 331 | - ), |
|
| 332 | - 'total_items' => array( |
|
| 333 | - 'description' => __( 'Number of items purchased.', 'invoicing' ), |
|
| 334 | - 'label' => __( 'Purchased Items', 'invoicing' ), |
|
| 335 | - ), |
|
| 336 | - 'refunded_items' => array( |
|
| 337 | - 'description' => __( 'Number of items refunded.', 'invoicing' ), |
|
| 338 | - 'label' => __( 'Refunded Items', 'invoicing' ), |
|
| 339 | - ), |
|
| 340 | - 'total_tax' => array( |
|
| 341 | - 'description' => __( 'Total charged for taxes.', 'invoicing' ), |
|
| 342 | - 'label' => __( 'Tax', 'invoicing' ), |
|
| 343 | - ), |
|
| 344 | - 'total_refunded_tax' => array( |
|
| 345 | - 'description' => __( 'Total refunded for taxes.', 'invoicing' ), |
|
| 346 | - 'label' => __( 'Refunded Tax', 'invoicing' ), |
|
| 347 | - ), |
|
| 348 | - 'total_fees' => array( |
|
| 349 | - 'description' => __( 'Total fees charged.', 'invoicing' ), |
|
| 350 | - 'label' => __( 'Fees', 'invoicing' ), |
|
| 351 | - ), |
|
| 352 | - 'total_refunds' => array( |
|
| 353 | - 'description' => __( 'Total of refunded invoices.', 'invoicing' ), |
|
| 354 | - 'label' => __( 'Refunded', 'invoicing' ), |
|
| 355 | - ), |
|
| 356 | - 'total_discount' => array( |
|
| 357 | - 'description' => __( 'Total of discounts used.', 'invoicing' ), |
|
| 358 | - 'label' => __( 'Discounted', 'invoicing' ), |
|
| 359 | - ), |
|
| 360 | - ); |
|
| 361 | - |
|
| 362 | - return apply_filters( 'wpinv_report_cards', $cards ); |
|
| 363 | - } |
|
| 302 | + do_action( 'getpaid_reports_display_right', $this ); |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + /** |
|
| 306 | + * Returns a list of report cards. |
|
| 307 | + * |
|
| 308 | + */ |
|
| 309 | + public function get_cards() { |
|
| 310 | + |
|
| 311 | + $cards = array( |
|
| 312 | + 'total_sales' => array( |
|
| 313 | + 'description' => __( 'Gross sales in the period.', 'invoicing' ), |
|
| 314 | + 'label' => __( 'Gross Revenue', 'invoicing' ), |
|
| 315 | + ), |
|
| 316 | + 'net_sales' => array( |
|
| 317 | + 'description' => __( 'Net sales in the period.', 'invoicing' ), |
|
| 318 | + 'label' => __( 'Net Revenue', 'invoicing' ), |
|
| 319 | + ), |
|
| 320 | + 'average_sales' => array( |
|
| 321 | + 'description' => __( 'Average net daily/monthly sales.', 'invoicing' ), |
|
| 322 | + 'label' => __( 'Avg. Net Sales', 'invoicing' ), |
|
| 323 | + ), |
|
| 324 | + 'average_total_sales' => array( |
|
| 325 | + 'description' => __( 'Average gross daily/monthly sales.', 'invoicing' ), |
|
| 326 | + 'label' => __( 'Avg. Gross Sales', 'invoicing' ), |
|
| 327 | + ), |
|
| 328 | + 'total_invoices' => array( |
|
| 329 | + 'description' => __( 'Number of paid invoices.', 'invoicing' ), |
|
| 330 | + 'label' => __( 'Paid Invoices', 'invoicing' ), |
|
| 331 | + ), |
|
| 332 | + 'total_items' => array( |
|
| 333 | + 'description' => __( 'Number of items purchased.', 'invoicing' ), |
|
| 334 | + 'label' => __( 'Purchased Items', 'invoicing' ), |
|
| 335 | + ), |
|
| 336 | + 'refunded_items' => array( |
|
| 337 | + 'description' => __( 'Number of items refunded.', 'invoicing' ), |
|
| 338 | + 'label' => __( 'Refunded Items', 'invoicing' ), |
|
| 339 | + ), |
|
| 340 | + 'total_tax' => array( |
|
| 341 | + 'description' => __( 'Total charged for taxes.', 'invoicing' ), |
|
| 342 | + 'label' => __( 'Tax', 'invoicing' ), |
|
| 343 | + ), |
|
| 344 | + 'total_refunded_tax' => array( |
|
| 345 | + 'description' => __( 'Total refunded for taxes.', 'invoicing' ), |
|
| 346 | + 'label' => __( 'Refunded Tax', 'invoicing' ), |
|
| 347 | + ), |
|
| 348 | + 'total_fees' => array( |
|
| 349 | + 'description' => __( 'Total fees charged.', 'invoicing' ), |
|
| 350 | + 'label' => __( 'Fees', 'invoicing' ), |
|
| 351 | + ), |
|
| 352 | + 'total_refunds' => array( |
|
| 353 | + 'description' => __( 'Total of refunded invoices.', 'invoicing' ), |
|
| 354 | + 'label' => __( 'Refunded', 'invoicing' ), |
|
| 355 | + ), |
|
| 356 | + 'total_discount' => array( |
|
| 357 | + 'description' => __( 'Total of discounts used.', 'invoicing' ), |
|
| 358 | + 'label' => __( 'Discounted', 'invoicing' ), |
|
| 359 | + ), |
|
| 360 | + ); |
|
| 361 | + |
|
| 362 | + return apply_filters( 'wpinv_report_cards', $cards ); |
|
| 363 | + } |
|
| 364 | 364 | |
| 365 | 365 | |
| 366 | 366 | |
@@ -5,7 +5,7 @@ discard block |
||
| 5 | 5 | * |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | -defined( 'ABSPATH' ) || exit; |
|
| 8 | +defined('ABSPATH') || exit; |
|
| 9 | 9 | |
| 10 | 10 | /** |
| 11 | 11 | * GetPaid_Reports_Report Class. |
@@ -23,26 +23,26 @@ discard block |
||
| 23 | 23 | */ |
| 24 | 24 | public function __construct() { |
| 25 | 25 | |
| 26 | - $this->views = array( |
|
| 26 | + $this->views = array( |
|
| 27 | 27 | |
| 28 | 28 | 'items' => array( |
| 29 | - 'label' => __( 'Items', 'invoicing' ), |
|
| 29 | + 'label' => __('Items', 'invoicing'), |
|
| 30 | 30 | 'class' => 'GetPaid_Reports_Report_Items', |
| 31 | 31 | ), |
| 32 | 32 | |
| 33 | 33 | 'gateways' => array( |
| 34 | - 'label' => __( 'Payment Methods', 'invoicing' ), |
|
| 34 | + 'label' => __('Payment Methods', 'invoicing'), |
|
| 35 | 35 | 'class' => 'GetPaid_Reports_Report_Gateways', |
| 36 | 36 | ), |
| 37 | 37 | |
| 38 | 38 | 'discounts' => array( |
| 39 | - 'label' => __( 'Discount Codes', 'invoicing' ), |
|
| 39 | + 'label' => __('Discount Codes', 'invoicing'), |
|
| 40 | 40 | 'class' => 'GetPaid_Reports_Report_Discounts', |
| 41 | 41 | ), |
| 42 | 42 | |
| 43 | 43 | ); |
| 44 | 44 | |
| 45 | - $this->views = apply_filters( 'wpinv_report_views', $this->views ); |
|
| 45 | + $this->views = apply_filters('wpinv_report_views', $this->views); |
|
| 46 | 46 | |
| 47 | 47 | } |
| 48 | 48 | |
@@ -53,8 +53,8 @@ discard block |
||
| 53 | 53 | public function get_range() { |
| 54 | 54 | $valid_ranges = $this->get_periods(); |
| 55 | 55 | |
| 56 | - if ( isset( $_GET['date_range'] ) && array_key_exists( $_GET['date_range'], $valid_ranges ) ) { |
|
| 57 | - return sanitize_key( $_GET['date_range'] ); |
|
| 56 | + if (isset($_GET['date_range']) && array_key_exists($_GET['date_range'], $valid_ranges)) { |
|
| 57 | + return sanitize_key($_GET['date_range']); |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | return '7_days'; |
@@ -68,22 +68,22 @@ discard block |
||
| 68 | 68 | public function get_periods() { |
| 69 | 69 | |
| 70 | 70 | $periods = array( |
| 71 | - 'today' => __( 'Today', 'invoicing' ), |
|
| 72 | - 'yesterday' => __( 'Yesterday', 'invoicing' ), |
|
| 73 | - 'week' => __( 'This week', 'invoicing' ), |
|
| 74 | - 'last_week' => __( 'Last week', 'invoicing' ), |
|
| 75 | - '7_days' => __( 'Last 7 days', 'invoicing' ), |
|
| 76 | - 'month' => __( 'This month', 'invoicing' ), |
|
| 77 | - 'last_month' => __( 'Last month', 'invoicing' ), |
|
| 78 | - '30_days' => __( 'Last 30 days', 'invoicing' ), |
|
| 79 | - 'quarter' => __( 'This Quarter', 'invoicing' ), |
|
| 80 | - 'last_quarter' => __( 'Last Quarter', 'invoicing' ), |
|
| 81 | - 'year' => __( 'This year', 'invoicing' ), |
|
| 82 | - 'last_year' => __( 'Last Year', 'invoicing' ), |
|
| 83 | - 'custom' => __( 'Custom Date Range', 'invoicing' ), |
|
| 71 | + 'today' => __('Today', 'invoicing'), |
|
| 72 | + 'yesterday' => __('Yesterday', 'invoicing'), |
|
| 73 | + 'week' => __('This week', 'invoicing'), |
|
| 74 | + 'last_week' => __('Last week', 'invoicing'), |
|
| 75 | + '7_days' => __('Last 7 days', 'invoicing'), |
|
| 76 | + 'month' => __('This month', 'invoicing'), |
|
| 77 | + 'last_month' => __('Last month', 'invoicing'), |
|
| 78 | + '30_days' => __('Last 30 days', 'invoicing'), |
|
| 79 | + 'quarter' => __('This Quarter', 'invoicing'), |
|
| 80 | + 'last_quarter' => __('Last Quarter', 'invoicing'), |
|
| 81 | + 'year' => __('This year', 'invoicing'), |
|
| 82 | + 'last_year' => __('Last Year', 'invoicing'), |
|
| 83 | + 'custom' => __('Custom Date Range', 'invoicing'), |
|
| 84 | 84 | ); |
| 85 | 85 | |
| 86 | - return apply_filters( 'getpaid_earning_periods', $periods ); |
|
| 86 | + return apply_filters('getpaid_earning_periods', $periods); |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | /** |
@@ -96,21 +96,21 @@ discard block |
||
| 96 | 96 | ?> |
| 97 | 97 | |
| 98 | 98 | <form method="get" class="getpaid-filter-earnings float-right"> |
| 99 | - <?php getpaid_hidden_field( 'page', isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : 'wpinv-reports' ); ?> |
|
| 100 | - <?php getpaid_hidden_field( 'tab', 'reports' ); ?> |
|
| 99 | + <?php getpaid_hidden_field('page', isset($_GET['page']) ? sanitize_text_field($_GET['page']) : 'wpinv-reports'); ?> |
|
| 100 | + <?php getpaid_hidden_field('tab', 'reports'); ?> |
|
| 101 | 101 | <select name='date_range'> |
| 102 | - <?php foreach ( $this->get_periods() as $key => $label ) : ?> |
|
| 103 | - <option value="<?php echo esc_attr( $key ); ?>" <?php selected( $key, $range ); ?>><?php echo esc_html( $label ); ?></option> |
|
| 102 | + <?php foreach ($this->get_periods() as $key => $label) : ?> |
|
| 103 | + <option value="<?php echo esc_attr($key); ?>" <?php selected($key, $range); ?>><?php echo esc_html($label); ?></option> |
|
| 104 | 104 | <?php endforeach; ?> |
| 105 | 105 | </select> |
| 106 | 106 | <span class="getpaid-date-range-picker <?php echo 'custom' == $range ? '' : 'd-none'; ?>"> |
| 107 | 107 | <input type="text" name="from" class="getpaid-from align-middle" /> |
| 108 | - <?php esc_html_e( 'to', 'invoicing' ); ?> |
|
| 108 | + <?php esc_html_e('to', 'invoicing'); ?> |
|
| 109 | 109 | <input type="text" name="to" class="getpaid-to align-middle" /> |
| 110 | 110 | </span> |
| 111 | 111 | <button type="submit" class="button button-primary"> |
| 112 | 112 | <i class="fa fa-chevron-right fa-lg"></i> |
| 113 | - <span class="screen-reader-text"><?php esc_html_e( 'View Reports', 'invoicing' ); ?></span> |
|
| 113 | + <span class="screen-reader-text"><?php esc_html_e('View Reports', 'invoicing'); ?></span> |
|
| 114 | 114 | </button> |
| 115 | 115 | </form> |
| 116 | 116 | |
@@ -159,17 +159,17 @@ discard block |
||
| 159 | 159 | |
| 160 | 160 | <div class="col-12 col-md-4"> |
| 161 | 161 | <div class="row getpaid-report-cards"> |
| 162 | - <?php foreach ( $this->get_cards() as $key => $card ) : ?> |
|
| 162 | + <?php foreach ($this->get_cards() as $key => $card) : ?> |
|
| 163 | 163 | <div class="col-12 mb-4"> |
| 164 | 164 | |
| 165 | - <!-- <?php echo esc_html( $card['label'] ); ?> Card --> |
|
| 166 | - <div class="card p-0 m-0 shadow-none <?php echo esc_attr( $key ); ?>"> |
|
| 165 | + <!-- <?php echo esc_html($card['label']); ?> Card --> |
|
| 166 | + <div class="card p-0 m-0 shadow-none <?php echo esc_attr($key); ?>"> |
|
| 167 | 167 | |
| 168 | 168 | <div class="card-body"> |
| 169 | 169 | |
| 170 | 170 | <p class="getpaid-current text-uppercase small mb-2"> |
| 171 | - <strong><?php echo esc_html( $card['label'] ); ?></strong> |
|
| 172 | - <span title="<?php echo esc_attr( $card['description'] ); ?>" class="wpi-help-tip dashicons dashicons-editor-help text-muted" style="margin-top: -2px;"></span> |
|
| 171 | + <strong><?php echo esc_html($card['label']); ?></strong> |
|
| 172 | + <span title="<?php echo esc_attr($card['description']); ?>" class="wpi-help-tip dashicons dashicons-editor-help text-muted" style="margin-top: -2px;"></span> |
|
| 173 | 173 | </p> |
| 174 | 174 | <h5 class="font-weight-bold mb-0"> |
| 175 | 175 | <span class="getpaid-report-card-value"> |
@@ -180,7 +180,7 @@ discard block |
||
| 180 | 180 | |
| 181 | 181 | <hr> |
| 182 | 182 | |
| 183 | - <p class="getpaid-previous text-uppercase text-muted small mb-2"><strong><?php esc_html_e( 'Previous Period', 'invoicing' ); ?></strong></p> |
|
| 183 | + <p class="getpaid-previous text-uppercase text-muted small mb-2"><strong><?php esc_html_e('Previous Period', 'invoicing'); ?></strong></p> |
|
| 184 | 184 | <h5 class="getpaid-report-card-previous-value font-weight-bold text-muted mb-0"> |
| 185 | 185 | <span class="spinner is-active float-none"></span> |
| 186 | 186 | </h5> |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | </div> |
| 189 | 189 | |
| 190 | 190 | </div> |
| 191 | - <!-- <?php echo esc_html( $card['label'] ); ?> Card --> |
|
| 191 | + <!-- <?php echo esc_html($card['label']); ?> Card --> |
|
| 192 | 192 | |
| 193 | 193 | </div> |
| 194 | 194 | <?php endforeach; ?> |
@@ -213,15 +213,15 @@ discard block |
||
| 213 | 213 | |
| 214 | 214 | ?> |
| 215 | 215 | |
| 216 | - <?php foreach ( $graphs as $key => $graph ) : ?> |
|
| 216 | + <?php foreach ($graphs as $key => $graph) : ?> |
|
| 217 | 217 | <div class="row mb-4"> |
| 218 | 218 | <div class="col-12"> |
| 219 | 219 | <div class="card m-0 p-0 single-report-card" style="max-width:100%"> |
| 220 | 220 | <div class="card-header"> |
| 221 | - <strong><?php echo esc_html( $graph ); ?></strong> |
|
| 221 | + <strong><?php echo esc_html($graph); ?></strong> |
|
| 222 | 222 | </div> |
| 223 | 223 | <div class="card-body"> |
| 224 | - <canvas id="getpaid-chartjs-<?php echo esc_attr( $key ); ?>"></canvas> |
|
| 224 | + <canvas id="getpaid-chartjs-<?php echo esc_attr($key); ?>"></canvas> |
|
| 225 | 225 | </div> |
| 226 | 226 | </div> |
| 227 | 227 | </div> |
@@ -236,14 +236,14 @@ discard block |
||
| 236 | 236 | * Retrieves the download url. |
| 237 | 237 | * |
| 238 | 238 | */ |
| 239 | - public function get_download_url( $graph, $file_type ) { |
|
| 239 | + public function get_download_url($graph, $file_type) { |
|
| 240 | 240 | |
| 241 | 241 | return wp_nonce_url( |
| 242 | 242 | add_query_arg( |
| 243 | 243 | array( |
| 244 | 244 | 'getpaid-admin-action' => 'download_graph', |
| 245 | - 'file_type' => urlencode( $file_type ), |
|
| 246 | - 'graph' => urlencode( $graph ), |
|
| 245 | + 'file_type' => urlencode($file_type), |
|
| 246 | + 'graph' => urlencode($graph), |
|
| 247 | 247 | ) |
| 248 | 248 | ), |
| 249 | 249 | 'getpaid-nonce', |
@@ -260,27 +260,27 @@ discard block |
||
| 260 | 260 | |
| 261 | 261 | ?> |
| 262 | 262 | |
| 263 | - <?php foreach ( $this->views as $key => $view ) : ?> |
|
| 263 | + <?php foreach ($this->views as $key => $view) : ?> |
|
| 264 | 264 | <div class="row mb-4"> |
| 265 | 265 | <div class="col-12"> |
| 266 | 266 | <div class="card m-0 p-0" style="max-width:100%"> |
| 267 | 267 | <div class="card-header"> |
| 268 | 268 | <div class="row"> |
| 269 | - <div class="<?php echo empty( $view['disable-downloads'] ) ? 'col-9' : 'col-12'; ?>"> |
|
| 270 | - <strong><?php echo esc_html( $view['label'] ); ?></strong> |
|
| 269 | + <div class="<?php echo empty($view['disable-downloads']) ? 'col-9' : 'col-12'; ?>"> |
|
| 270 | + <strong><?php echo esc_html($view['label']); ?></strong> |
|
| 271 | 271 | </div> |
| 272 | - <div class="<?php echo empty( $view['disable-downloads'] ) ? 'col-3' : 'd-none'; ?>"> |
|
| 273 | - <a title="<?php esc_attr_e( 'Download JSON', 'invoicing' ); ?>" href="<?php echo esc_url( $this->get_download_url( $key, 'json' ) ); ?>"> |
|
| 272 | + <div class="<?php echo empty($view['disable-downloads']) ? 'col-3' : 'd-none'; ?>"> |
|
| 273 | + <a title="<?php esc_attr_e('Download JSON', 'invoicing'); ?>" href="<?php echo esc_url($this->get_download_url($key, 'json')); ?>"> |
|
| 274 | 274 | <i class="fa fa-download text-dark" style="font-size: 16px" aria-hidden="true"></i> |
| 275 | - <span class="screen-reader-text"><?php esc_html_e( 'Download JSON', 'invoicing' ); ?></span> |
|
| 275 | + <span class="screen-reader-text"><?php esc_html_e('Download JSON', 'invoicing'); ?></span> |
|
| 276 | 276 | </a> |
| 277 | - <a title="<?php esc_attr_e( 'Download CSV', 'invoicing' ); ?>" href="<?php echo esc_url( $this->get_download_url( $key, 'csv' ) ); ?>"> |
|
| 277 | + <a title="<?php esc_attr_e('Download CSV', 'invoicing'); ?>" href="<?php echo esc_url($this->get_download_url($key, 'csv')); ?>"> |
|
| 278 | 278 | <i class="fa fa-file-csv text-dark" style="font-size: 16px" aria-hidden="true"></i> |
| 279 | - <span class="screen-reader-text"><?php esc_html_e( 'Download CSV', 'invoicing' ); ?></span> |
|
| 279 | + <span class="screen-reader-text"><?php esc_html_e('Download CSV', 'invoicing'); ?></span> |
|
| 280 | 280 | </a> |
| 281 | - <a title="<?php esc_attr_e( 'Download XML', 'invoicing' ); ?>" href="<?php echo esc_url( $this->get_download_url( $key, 'xml' ) ); ?>"> |
|
| 281 | + <a title="<?php esc_attr_e('Download XML', 'invoicing'); ?>" href="<?php echo esc_url($this->get_download_url($key, 'xml')); ?>"> |
|
| 282 | 282 | <i class="fa fa-file-code text-dark" style="font-size: 16px" aria-hidden="true"></i> |
| 283 | - <span class="screen-reader-text"><?php esc_html_e( 'Download XML', 'invoicing' ); ?></span> |
|
| 283 | + <span class="screen-reader-text"><?php esc_html_e('Download XML', 'invoicing'); ?></span> |
|
| 284 | 284 | </a> |
| 285 | 285 | </div> |
| 286 | 286 | </div> |
@@ -299,7 +299,7 @@ discard block |
||
| 299 | 299 | |
| 300 | 300 | <?php |
| 301 | 301 | |
| 302 | - do_action( 'getpaid_reports_display_right', $this ); |
|
| 302 | + do_action('getpaid_reports_display_right', $this); |
|
| 303 | 303 | } |
| 304 | 304 | |
| 305 | 305 | /** |
@@ -310,56 +310,56 @@ discard block |
||
| 310 | 310 | |
| 311 | 311 | $cards = array( |
| 312 | 312 | 'total_sales' => array( |
| 313 | - 'description' => __( 'Gross sales in the period.', 'invoicing' ), |
|
| 314 | - 'label' => __( 'Gross Revenue', 'invoicing' ), |
|
| 313 | + 'description' => __('Gross sales in the period.', 'invoicing'), |
|
| 314 | + 'label' => __('Gross Revenue', 'invoicing'), |
|
| 315 | 315 | ), |
| 316 | 316 | 'net_sales' => array( |
| 317 | - 'description' => __( 'Net sales in the period.', 'invoicing' ), |
|
| 318 | - 'label' => __( 'Net Revenue', 'invoicing' ), |
|
| 317 | + 'description' => __('Net sales in the period.', 'invoicing'), |
|
| 318 | + 'label' => __('Net Revenue', 'invoicing'), |
|
| 319 | 319 | ), |
| 320 | 320 | 'average_sales' => array( |
| 321 | - 'description' => __( 'Average net daily/monthly sales.', 'invoicing' ), |
|
| 322 | - 'label' => __( 'Avg. Net Sales', 'invoicing' ), |
|
| 321 | + 'description' => __('Average net daily/monthly sales.', 'invoicing'), |
|
| 322 | + 'label' => __('Avg. Net Sales', 'invoicing'), |
|
| 323 | 323 | ), |
| 324 | 324 | 'average_total_sales' => array( |
| 325 | - 'description' => __( 'Average gross daily/monthly sales.', 'invoicing' ), |
|
| 326 | - 'label' => __( 'Avg. Gross Sales', 'invoicing' ), |
|
| 325 | + 'description' => __('Average gross daily/monthly sales.', 'invoicing'), |
|
| 326 | + 'label' => __('Avg. Gross Sales', 'invoicing'), |
|
| 327 | 327 | ), |
| 328 | 328 | 'total_invoices' => array( |
| 329 | - 'description' => __( 'Number of paid invoices.', 'invoicing' ), |
|
| 330 | - 'label' => __( 'Paid Invoices', 'invoicing' ), |
|
| 329 | + 'description' => __('Number of paid invoices.', 'invoicing'), |
|
| 330 | + 'label' => __('Paid Invoices', 'invoicing'), |
|
| 331 | 331 | ), |
| 332 | 332 | 'total_items' => array( |
| 333 | - 'description' => __( 'Number of items purchased.', 'invoicing' ), |
|
| 334 | - 'label' => __( 'Purchased Items', 'invoicing' ), |
|
| 333 | + 'description' => __('Number of items purchased.', 'invoicing'), |
|
| 334 | + 'label' => __('Purchased Items', 'invoicing'), |
|
| 335 | 335 | ), |
| 336 | 336 | 'refunded_items' => array( |
| 337 | - 'description' => __( 'Number of items refunded.', 'invoicing' ), |
|
| 338 | - 'label' => __( 'Refunded Items', 'invoicing' ), |
|
| 337 | + 'description' => __('Number of items refunded.', 'invoicing'), |
|
| 338 | + 'label' => __('Refunded Items', 'invoicing'), |
|
| 339 | 339 | ), |
| 340 | 340 | 'total_tax' => array( |
| 341 | - 'description' => __( 'Total charged for taxes.', 'invoicing' ), |
|
| 342 | - 'label' => __( 'Tax', 'invoicing' ), |
|
| 341 | + 'description' => __('Total charged for taxes.', 'invoicing'), |
|
| 342 | + 'label' => __('Tax', 'invoicing'), |
|
| 343 | 343 | ), |
| 344 | 344 | 'total_refunded_tax' => array( |
| 345 | - 'description' => __( 'Total refunded for taxes.', 'invoicing' ), |
|
| 346 | - 'label' => __( 'Refunded Tax', 'invoicing' ), |
|
| 345 | + 'description' => __('Total refunded for taxes.', 'invoicing'), |
|
| 346 | + 'label' => __('Refunded Tax', 'invoicing'), |
|
| 347 | 347 | ), |
| 348 | 348 | 'total_fees' => array( |
| 349 | - 'description' => __( 'Total fees charged.', 'invoicing' ), |
|
| 350 | - 'label' => __( 'Fees', 'invoicing' ), |
|
| 349 | + 'description' => __('Total fees charged.', 'invoicing'), |
|
| 350 | + 'label' => __('Fees', 'invoicing'), |
|
| 351 | 351 | ), |
| 352 | 352 | 'total_refunds' => array( |
| 353 | - 'description' => __( 'Total of refunded invoices.', 'invoicing' ), |
|
| 354 | - 'label' => __( 'Refunded', 'invoicing' ), |
|
| 353 | + 'description' => __('Total of refunded invoices.', 'invoicing'), |
|
| 354 | + 'label' => __('Refunded', 'invoicing'), |
|
| 355 | 355 | ), |
| 356 | 356 | 'total_discount' => array( |
| 357 | - 'description' => __( 'Total of discounts used.', 'invoicing' ), |
|
| 358 | - 'label' => __( 'Discounted', 'invoicing' ), |
|
| 357 | + 'description' => __('Total of discounts used.', 'invoicing'), |
|
| 358 | + 'label' => __('Discounted', 'invoicing'), |
|
| 359 | 359 | ), |
| 360 | 360 | ); |
| 361 | 361 | |
| 362 | - return apply_filters( 'wpinv_report_cards', $cards ); |
|
| 362 | + return apply_filters('wpinv_report_cards', $cards); |
|
| 363 | 363 | } |
| 364 | 364 | |
| 365 | 365 | |
@@ -12,194 +12,194 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class GetPaid_Invoice_Exporter extends GetPaid_Graph_Downloader { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Retrieves invoices query args. |
|
| 17 | - * |
|
| 18 | - * @param string $post_type post type to retrieve. |
|
| 19 | - * @param array $args Args to search for. |
|
| 20 | - * @return array |
|
| 21 | - */ |
|
| 22 | - public function get_invoice_query_args( $post_type, $args ) { |
|
| 23 | - |
|
| 24 | - $query_args = array( |
|
| 25 | - 'post_type' => $post_type, |
|
| 26 | - 'post_status' => array_keys( wpinv_get_invoice_statuses( true, false, $post_type ) ), |
|
| 27 | - 'posts_per_page' => -1, |
|
| 28 | - 'no_found_rows' => true, |
|
| 29 | - 'update_post_term_cache' => false, |
|
| 30 | - 'fields' => 'ids', |
|
| 31 | - ); |
|
| 32 | - |
|
| 33 | - if ( ! empty( $args['status'] ) && in_array( $args['status'], $query_args['post_status'], true ) ) { |
|
| 34 | - $query_args['post_status'] = wpinv_clean( wpinv_parse_list( $args['status'] ) ); |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - $date_query = array(); |
|
| 38 | - if ( ! empty( $args['to_date'] ) ) { |
|
| 39 | - $date_query['before'] = wpinv_clean( $args['to_date'] ); |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - if ( ! empty( $args['from_date'] ) ) { |
|
| 43 | - $date_query['after'] = wpinv_clean( $args['from_date'] ); |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - if ( ! empty( $date_query ) ) { |
|
| 47 | - $date_query['inclusive'] = true; |
|
| 48 | - $query_args['date_query'] = array( $date_query ); |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - return $query_args; |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * Retrieves invoices. |
|
| 56 | - * |
|
| 57 | - * @param array $query_args WP_Query args. |
|
| 58 | - * @return WPInv_Invoice[] |
|
| 59 | - */ |
|
| 60 | - public function get_invoices( $query_args ) { |
|
| 61 | - |
|
| 62 | - // Get invoices. |
|
| 63 | - $invoices = new WP_Query( $query_args ); |
|
| 64 | - |
|
| 65 | - // Prepare the results. |
|
| 66 | - return array_map( 'wpinv_get_invoice', $invoices->posts ); |
|
| 67 | - |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * Handles the actual download. |
|
| 72 | - * |
|
| 73 | - */ |
|
| 74 | - public function export( $post_type, $args ) { |
|
| 75 | - |
|
| 76 | - $invoices = $this->get_invoices( $this->get_invoice_query_args( $post_type, $args ) ); |
|
| 77 | - $stream = $this->prepare_output(); |
|
| 78 | - $headers = $this->get_export_fields( $post_type ); |
|
| 79 | - $file_type = $this->prepare_file_type( strtolower( getpaid_get_post_type_label( $post_type ) ) ); |
|
| 80 | - |
|
| 81 | - if ( 'csv' == $file_type ) { |
|
| 82 | - $this->download_csv( $invoices, $stream, $headers ); |
|
| 83 | - } elseif ( 'xml' == $file_type ) { |
|
| 84 | - $this->download_xml( $invoices, $stream, $headers ); |
|
| 85 | - } else { |
|
| 86 | - $this->download_json( $invoices, $stream, $headers ); |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - fclose( $stream ); |
|
| 90 | - exit; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * Prepares a single invoice for download. |
|
| 95 | - * |
|
| 96 | - * @param WPInv_Invoice $invoice The invoice to prepare.. |
|
| 97 | - * @param array $fields The fields to stream. |
|
| 98 | - * @since 1.0.19 |
|
| 99 | - * @return array |
|
| 100 | - */ |
|
| 101 | - public function prepare_row( $invoice, $fields ) { |
|
| 102 | - |
|
| 103 | - $prepared = array(); |
|
| 104 | - $amount_fields = $this->get_amount_fields( $invoice->get_post_type() ); |
|
| 105 | - |
|
| 106 | - foreach ( $fields as $field ) { |
|
| 107 | - |
|
| 108 | - $value = ''; |
|
| 109 | - $method = "get_$field"; |
|
| 110 | - |
|
| 111 | - if ( method_exists( $invoice, $method ) ) { |
|
| 112 | - $value = $invoice->$method(); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - if ( in_array( $field, $amount_fields ) ) { |
|
| 116 | - $value = wpinv_round_amount( wpinv_sanitize_amount( $value ) ); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - $prepared[ $field ] = wpinv_clean( $value ); |
|
| 120 | - |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - return $prepared; |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * Retrieves export fields. |
|
| 128 | - * |
|
| 129 | - * @param string $post_type |
|
| 130 | - * @since 1.0.19 |
|
| 131 | - * @return array |
|
| 132 | - */ |
|
| 133 | - public function get_export_fields( $post_type ) { |
|
| 134 | - |
|
| 135 | - $fields = array( |
|
| 136 | - 'id', |
|
| 137 | - 'parent_id', |
|
| 138 | - 'status', |
|
| 139 | - 'date_created', |
|
| 140 | - 'date_modified', |
|
| 141 | - 'date_due', |
|
| 142 | - 'date_completed', |
|
| 143 | - 'number', |
|
| 144 | - 'key', |
|
| 145 | - 'description', |
|
| 146 | - 'post_type', |
|
| 147 | - 'mode', |
|
| 148 | - 'customer_id', |
|
| 149 | - 'customer_first_name', |
|
| 150 | - 'customer_last_name', |
|
| 151 | - 'customer_phone', |
|
| 152 | - 'customer_email', |
|
| 153 | - 'customer_country', |
|
| 154 | - 'customer_city', |
|
| 155 | - 'customer_state', |
|
| 156 | - 'customer_zip', |
|
| 157 | - 'customer_company', |
|
| 158 | - 'customer_vat_number', |
|
| 159 | - 'customer_address', |
|
| 160 | - 'subtotal', |
|
| 161 | - 'total_discount', |
|
| 162 | - 'total_tax', |
|
| 163 | - 'total_fees', |
|
| 164 | - 'fees', |
|
| 165 | - 'discounts', |
|
| 166 | - 'taxes', |
|
| 167 | - 'cart_details', |
|
| 168 | - 'item_ids', |
|
| 169 | - 'payment_form', |
|
| 170 | - 'discount_code', |
|
| 171 | - 'gateway', |
|
| 172 | - 'transaction_id', |
|
| 173 | - 'currency', |
|
| 174 | - 'disable_taxes', |
|
| 175 | - 'subscription_id', |
|
| 176 | - 'remote_subscription_id', |
|
| 177 | - 'is_viewed', |
|
| 178 | - 'email_cc', |
|
| 179 | - 'template', |
|
| 180 | - 'created_via', |
|
| 181 | - ); |
|
| 182 | - |
|
| 183 | - return apply_filters( 'getpaid_invoice_exporter_get_fields', $fields, $post_type ); |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - /** |
|
| 187 | - * Retrieves amount fields. |
|
| 188 | - * |
|
| 189 | - * @param string $post_type |
|
| 190 | - * @since 1.0.19 |
|
| 191 | - * @return array |
|
| 192 | - */ |
|
| 193 | - public function get_amount_fields( $post_type ) { |
|
| 194 | - |
|
| 195 | - $fields = array( |
|
| 196 | - 'subtotal', |
|
| 197 | - 'total_discount', |
|
| 198 | - 'total_tax', |
|
| 199 | - 'total_fees', |
|
| 200 | - ); |
|
| 201 | - |
|
| 202 | - return apply_filters( 'getpaid_invoice_exporter_get_amount_fields', $fields, $post_type ); |
|
| 203 | - } |
|
| 15 | + /** |
|
| 16 | + * Retrieves invoices query args. |
|
| 17 | + * |
|
| 18 | + * @param string $post_type post type to retrieve. |
|
| 19 | + * @param array $args Args to search for. |
|
| 20 | + * @return array |
|
| 21 | + */ |
|
| 22 | + public function get_invoice_query_args( $post_type, $args ) { |
|
| 23 | + |
|
| 24 | + $query_args = array( |
|
| 25 | + 'post_type' => $post_type, |
|
| 26 | + 'post_status' => array_keys( wpinv_get_invoice_statuses( true, false, $post_type ) ), |
|
| 27 | + 'posts_per_page' => -1, |
|
| 28 | + 'no_found_rows' => true, |
|
| 29 | + 'update_post_term_cache' => false, |
|
| 30 | + 'fields' => 'ids', |
|
| 31 | + ); |
|
| 32 | + |
|
| 33 | + if ( ! empty( $args['status'] ) && in_array( $args['status'], $query_args['post_status'], true ) ) { |
|
| 34 | + $query_args['post_status'] = wpinv_clean( wpinv_parse_list( $args['status'] ) ); |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + $date_query = array(); |
|
| 38 | + if ( ! empty( $args['to_date'] ) ) { |
|
| 39 | + $date_query['before'] = wpinv_clean( $args['to_date'] ); |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + if ( ! empty( $args['from_date'] ) ) { |
|
| 43 | + $date_query['after'] = wpinv_clean( $args['from_date'] ); |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + if ( ! empty( $date_query ) ) { |
|
| 47 | + $date_query['inclusive'] = true; |
|
| 48 | + $query_args['date_query'] = array( $date_query ); |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + return $query_args; |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * Retrieves invoices. |
|
| 56 | + * |
|
| 57 | + * @param array $query_args WP_Query args. |
|
| 58 | + * @return WPInv_Invoice[] |
|
| 59 | + */ |
|
| 60 | + public function get_invoices( $query_args ) { |
|
| 61 | + |
|
| 62 | + // Get invoices. |
|
| 63 | + $invoices = new WP_Query( $query_args ); |
|
| 64 | + |
|
| 65 | + // Prepare the results. |
|
| 66 | + return array_map( 'wpinv_get_invoice', $invoices->posts ); |
|
| 67 | + |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * Handles the actual download. |
|
| 72 | + * |
|
| 73 | + */ |
|
| 74 | + public function export( $post_type, $args ) { |
|
| 75 | + |
|
| 76 | + $invoices = $this->get_invoices( $this->get_invoice_query_args( $post_type, $args ) ); |
|
| 77 | + $stream = $this->prepare_output(); |
|
| 78 | + $headers = $this->get_export_fields( $post_type ); |
|
| 79 | + $file_type = $this->prepare_file_type( strtolower( getpaid_get_post_type_label( $post_type ) ) ); |
|
| 80 | + |
|
| 81 | + if ( 'csv' == $file_type ) { |
|
| 82 | + $this->download_csv( $invoices, $stream, $headers ); |
|
| 83 | + } elseif ( 'xml' == $file_type ) { |
|
| 84 | + $this->download_xml( $invoices, $stream, $headers ); |
|
| 85 | + } else { |
|
| 86 | + $this->download_json( $invoices, $stream, $headers ); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + fclose( $stream ); |
|
| 90 | + exit; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * Prepares a single invoice for download. |
|
| 95 | + * |
|
| 96 | + * @param WPInv_Invoice $invoice The invoice to prepare.. |
|
| 97 | + * @param array $fields The fields to stream. |
|
| 98 | + * @since 1.0.19 |
|
| 99 | + * @return array |
|
| 100 | + */ |
|
| 101 | + public function prepare_row( $invoice, $fields ) { |
|
| 102 | + |
|
| 103 | + $prepared = array(); |
|
| 104 | + $amount_fields = $this->get_amount_fields( $invoice->get_post_type() ); |
|
| 105 | + |
|
| 106 | + foreach ( $fields as $field ) { |
|
| 107 | + |
|
| 108 | + $value = ''; |
|
| 109 | + $method = "get_$field"; |
|
| 110 | + |
|
| 111 | + if ( method_exists( $invoice, $method ) ) { |
|
| 112 | + $value = $invoice->$method(); |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + if ( in_array( $field, $amount_fields ) ) { |
|
| 116 | + $value = wpinv_round_amount( wpinv_sanitize_amount( $value ) ); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + $prepared[ $field ] = wpinv_clean( $value ); |
|
| 120 | + |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + return $prepared; |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * Retrieves export fields. |
|
| 128 | + * |
|
| 129 | + * @param string $post_type |
|
| 130 | + * @since 1.0.19 |
|
| 131 | + * @return array |
|
| 132 | + */ |
|
| 133 | + public function get_export_fields( $post_type ) { |
|
| 134 | + |
|
| 135 | + $fields = array( |
|
| 136 | + 'id', |
|
| 137 | + 'parent_id', |
|
| 138 | + 'status', |
|
| 139 | + 'date_created', |
|
| 140 | + 'date_modified', |
|
| 141 | + 'date_due', |
|
| 142 | + 'date_completed', |
|
| 143 | + 'number', |
|
| 144 | + 'key', |
|
| 145 | + 'description', |
|
| 146 | + 'post_type', |
|
| 147 | + 'mode', |
|
| 148 | + 'customer_id', |
|
| 149 | + 'customer_first_name', |
|
| 150 | + 'customer_last_name', |
|
| 151 | + 'customer_phone', |
|
| 152 | + 'customer_email', |
|
| 153 | + 'customer_country', |
|
| 154 | + 'customer_city', |
|
| 155 | + 'customer_state', |
|
| 156 | + 'customer_zip', |
|
| 157 | + 'customer_company', |
|
| 158 | + 'customer_vat_number', |
|
| 159 | + 'customer_address', |
|
| 160 | + 'subtotal', |
|
| 161 | + 'total_discount', |
|
| 162 | + 'total_tax', |
|
| 163 | + 'total_fees', |
|
| 164 | + 'fees', |
|
| 165 | + 'discounts', |
|
| 166 | + 'taxes', |
|
| 167 | + 'cart_details', |
|
| 168 | + 'item_ids', |
|
| 169 | + 'payment_form', |
|
| 170 | + 'discount_code', |
|
| 171 | + 'gateway', |
|
| 172 | + 'transaction_id', |
|
| 173 | + 'currency', |
|
| 174 | + 'disable_taxes', |
|
| 175 | + 'subscription_id', |
|
| 176 | + 'remote_subscription_id', |
|
| 177 | + 'is_viewed', |
|
| 178 | + 'email_cc', |
|
| 179 | + 'template', |
|
| 180 | + 'created_via', |
|
| 181 | + ); |
|
| 182 | + |
|
| 183 | + return apply_filters( 'getpaid_invoice_exporter_get_fields', $fields, $post_type ); |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + /** |
|
| 187 | + * Retrieves amount fields. |
|
| 188 | + * |
|
| 189 | + * @param string $post_type |
|
| 190 | + * @since 1.0.19 |
|
| 191 | + * @return array |
|
| 192 | + */ |
|
| 193 | + public function get_amount_fields( $post_type ) { |
|
| 194 | + |
|
| 195 | + $fields = array( |
|
| 196 | + 'subtotal', |
|
| 197 | + 'total_discount', |
|
| 198 | + 'total_tax', |
|
| 199 | + 'total_fees', |
|
| 200 | + ); |
|
| 201 | + |
|
| 202 | + return apply_filters( 'getpaid_invoice_exporter_get_amount_fields', $fields, $post_type ); |
|
| 203 | + } |
|
| 204 | 204 | |
| 205 | 205 | } |
@@ -5,7 +5,7 @@ discard block |
||
| 5 | 5 | * |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | -defined( 'ABSPATH' ) || exit; |
|
| 8 | +defined('ABSPATH') || exit; |
|
| 9 | 9 | |
| 10 | 10 | /** |
| 11 | 11 | * GetPaid_Invoice_Exporter Class. |
@@ -19,33 +19,33 @@ discard block |
||
| 19 | 19 | * @param array $args Args to search for. |
| 20 | 20 | * @return array |
| 21 | 21 | */ |
| 22 | - public function get_invoice_query_args( $post_type, $args ) { |
|
| 22 | + public function get_invoice_query_args($post_type, $args) { |
|
| 23 | 23 | |
| 24 | 24 | $query_args = array( |
| 25 | 25 | 'post_type' => $post_type, |
| 26 | - 'post_status' => array_keys( wpinv_get_invoice_statuses( true, false, $post_type ) ), |
|
| 26 | + 'post_status' => array_keys(wpinv_get_invoice_statuses(true, false, $post_type)), |
|
| 27 | 27 | 'posts_per_page' => -1, |
| 28 | 28 | 'no_found_rows' => true, |
| 29 | 29 | 'update_post_term_cache' => false, |
| 30 | 30 | 'fields' => 'ids', |
| 31 | 31 | ); |
| 32 | 32 | |
| 33 | - if ( ! empty( $args['status'] ) && in_array( $args['status'], $query_args['post_status'], true ) ) { |
|
| 34 | - $query_args['post_status'] = wpinv_clean( wpinv_parse_list( $args['status'] ) ); |
|
| 33 | + if (!empty($args['status']) && in_array($args['status'], $query_args['post_status'], true)) { |
|
| 34 | + $query_args['post_status'] = wpinv_clean(wpinv_parse_list($args['status'])); |
|
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | $date_query = array(); |
| 38 | - if ( ! empty( $args['to_date'] ) ) { |
|
| 39 | - $date_query['before'] = wpinv_clean( $args['to_date'] ); |
|
| 38 | + if (!empty($args['to_date'])) { |
|
| 39 | + $date_query['before'] = wpinv_clean($args['to_date']); |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | - if ( ! empty( $args['from_date'] ) ) { |
|
| 43 | - $date_query['after'] = wpinv_clean( $args['from_date'] ); |
|
| 42 | + if (!empty($args['from_date'])) { |
|
| 43 | + $date_query['after'] = wpinv_clean($args['from_date']); |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | - if ( ! empty( $date_query ) ) { |
|
| 46 | + if (!empty($date_query)) { |
|
| 47 | 47 | $date_query['inclusive'] = true; |
| 48 | - $query_args['date_query'] = array( $date_query ); |
|
| 48 | + $query_args['date_query'] = array($date_query); |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | return $query_args; |
@@ -57,13 +57,13 @@ discard block |
||
| 57 | 57 | * @param array $query_args WP_Query args. |
| 58 | 58 | * @return WPInv_Invoice[] |
| 59 | 59 | */ |
| 60 | - public function get_invoices( $query_args ) { |
|
| 60 | + public function get_invoices($query_args) { |
|
| 61 | 61 | |
| 62 | 62 | // Get invoices. |
| 63 | - $invoices = new WP_Query( $query_args ); |
|
| 63 | + $invoices = new WP_Query($query_args); |
|
| 64 | 64 | |
| 65 | 65 | // Prepare the results. |
| 66 | - return array_map( 'wpinv_get_invoice', $invoices->posts ); |
|
| 66 | + return array_map('wpinv_get_invoice', $invoices->posts); |
|
| 67 | 67 | |
| 68 | 68 | } |
| 69 | 69 | |
@@ -71,22 +71,22 @@ discard block |
||
| 71 | 71 | * Handles the actual download. |
| 72 | 72 | * |
| 73 | 73 | */ |
| 74 | - public function export( $post_type, $args ) { |
|
| 74 | + public function export($post_type, $args) { |
|
| 75 | 75 | |
| 76 | - $invoices = $this->get_invoices( $this->get_invoice_query_args( $post_type, $args ) ); |
|
| 76 | + $invoices = $this->get_invoices($this->get_invoice_query_args($post_type, $args)); |
|
| 77 | 77 | $stream = $this->prepare_output(); |
| 78 | - $headers = $this->get_export_fields( $post_type ); |
|
| 79 | - $file_type = $this->prepare_file_type( strtolower( getpaid_get_post_type_label( $post_type ) ) ); |
|
| 78 | + $headers = $this->get_export_fields($post_type); |
|
| 79 | + $file_type = $this->prepare_file_type(strtolower(getpaid_get_post_type_label($post_type))); |
|
| 80 | 80 | |
| 81 | - if ( 'csv' == $file_type ) { |
|
| 82 | - $this->download_csv( $invoices, $stream, $headers ); |
|
| 83 | - } elseif ( 'xml' == $file_type ) { |
|
| 84 | - $this->download_xml( $invoices, $stream, $headers ); |
|
| 81 | + if ('csv' == $file_type) { |
|
| 82 | + $this->download_csv($invoices, $stream, $headers); |
|
| 83 | + } elseif ('xml' == $file_type) { |
|
| 84 | + $this->download_xml($invoices, $stream, $headers); |
|
| 85 | 85 | } else { |
| 86 | - $this->download_json( $invoices, $stream, $headers ); |
|
| 86 | + $this->download_json($invoices, $stream, $headers); |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | - fclose( $stream ); |
|
| 89 | + fclose($stream); |
|
| 90 | 90 | exit; |
| 91 | 91 | } |
| 92 | 92 | |
@@ -98,25 +98,25 @@ discard block |
||
| 98 | 98 | * @since 1.0.19 |
| 99 | 99 | * @return array |
| 100 | 100 | */ |
| 101 | - public function prepare_row( $invoice, $fields ) { |
|
| 101 | + public function prepare_row($invoice, $fields) { |
|
| 102 | 102 | |
| 103 | 103 | $prepared = array(); |
| 104 | - $amount_fields = $this->get_amount_fields( $invoice->get_post_type() ); |
|
| 104 | + $amount_fields = $this->get_amount_fields($invoice->get_post_type()); |
|
| 105 | 105 | |
| 106 | - foreach ( $fields as $field ) { |
|
| 106 | + foreach ($fields as $field) { |
|
| 107 | 107 | |
| 108 | 108 | $value = ''; |
| 109 | 109 | $method = "get_$field"; |
| 110 | 110 | |
| 111 | - if ( method_exists( $invoice, $method ) ) { |
|
| 112 | - $value = $invoice->$method(); |
|
| 111 | + if (method_exists($invoice, $method)) { |
|
| 112 | + $value = $invoice->$method(); |
|
| 113 | 113 | } |
| 114 | 114 | |
| 115 | - if ( in_array( $field, $amount_fields ) ) { |
|
| 116 | - $value = wpinv_round_amount( wpinv_sanitize_amount( $value ) ); |
|
| 115 | + if (in_array($field, $amount_fields)) { |
|
| 116 | + $value = wpinv_round_amount(wpinv_sanitize_amount($value)); |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | - $prepared[ $field ] = wpinv_clean( $value ); |
|
| 119 | + $prepared[$field] = wpinv_clean($value); |
|
| 120 | 120 | |
| 121 | 121 | } |
| 122 | 122 | |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | * @since 1.0.19 |
| 131 | 131 | * @return array |
| 132 | 132 | */ |
| 133 | - public function get_export_fields( $post_type ) { |
|
| 133 | + public function get_export_fields($post_type) { |
|
| 134 | 134 | |
| 135 | 135 | $fields = array( |
| 136 | 136 | 'id', |
@@ -180,7 +180,7 @@ discard block |
||
| 180 | 180 | 'created_via', |
| 181 | 181 | ); |
| 182 | 182 | |
| 183 | - return apply_filters( 'getpaid_invoice_exporter_get_fields', $fields, $post_type ); |
|
| 183 | + return apply_filters('getpaid_invoice_exporter_get_fields', $fields, $post_type); |
|
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | /** |
@@ -190,7 +190,7 @@ discard block |
||
| 190 | 190 | * @since 1.0.19 |
| 191 | 191 | * @return array |
| 192 | 192 | */ |
| 193 | - public function get_amount_fields( $post_type ) { |
|
| 193 | + public function get_amount_fields($post_type) { |
|
| 194 | 194 | |
| 195 | 195 | $fields = array( |
| 196 | 196 | 'subtotal', |
@@ -199,7 +199,7 @@ discard block |
||
| 199 | 199 | 'total_fees', |
| 200 | 200 | ); |
| 201 | 201 | |
| 202 | - return apply_filters( 'getpaid_invoice_exporter_get_amount_fields', $fields, $post_type ); |
|
| 202 | + return apply_filters('getpaid_invoice_exporter_get_amount_fields', $fields, $post_type); |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | } |
@@ -12,176 +12,176 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class GetPaid_Subscription_Exporter extends GetPaid_Graph_Downloader { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Retrieves subscription query args. |
|
| 17 | - * |
|
| 18 | - * @param array $args Args to search for. |
|
| 19 | - * @return array |
|
| 20 | - */ |
|
| 21 | - public function get_subscription_query_args( $args ) { |
|
| 22 | - |
|
| 23 | - $query_args = array( |
|
| 24 | - 'status' => 'all', |
|
| 25 | - 'number' => -1, |
|
| 26 | - 'count_total' => false, |
|
| 27 | - 'fields' => 'all', |
|
| 28 | - ); |
|
| 29 | - |
|
| 30 | - if ( ! empty( $args['status'] ) && in_array( $args['status'], array_keys( getpaid_get_subscription_statuses() ), true ) ) { |
|
| 31 | - $query_args['status'] = wpinv_clean( wpinv_parse_list( $args['status'] ) ); |
|
| 32 | - } |
|
| 33 | - |
|
| 34 | - $date_query = array(); |
|
| 35 | - if ( ! empty( $args['to_date'] ) ) { |
|
| 36 | - $date_query['before'] = wpinv_clean( $args['to_date'] ); |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - if ( ! empty( $args['from_date'] ) ) { |
|
| 40 | - $date_query['after'] = wpinv_clean( $args['from_date'] ); |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - if ( ! empty( $date_query ) ) { |
|
| 44 | - $date_query['inclusive'] = true; |
|
| 45 | - $query_args['date_created_query'] = array( $date_query ); |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - return $query_args; |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * Retrieves subscriptions. |
|
| 53 | - * |
|
| 54 | - * @param array $query_args GetPaid_Subscriptions_Query args. |
|
| 55 | - * @return WPInv_Subscription[] |
|
| 56 | - */ |
|
| 57 | - public function get_subscriptions( $query_args ) { |
|
| 58 | - |
|
| 59 | - // Get subscriptions. |
|
| 60 | - $subscriptions = new GetPaid_Subscriptions_Query( $query_args ); |
|
| 61 | - |
|
| 62 | - // Prepare the results. |
|
| 63 | - return $subscriptions->get_results(); |
|
| 64 | - |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * Handles the actual download. |
|
| 69 | - * |
|
| 70 | - */ |
|
| 71 | - public function export( $post_type, $args ) { |
|
| 72 | - |
|
| 73 | - $subscriptions = $this->get_subscriptions( $this->get_subscription_query_args( $args ) ); |
|
| 74 | - $stream = $this->prepare_output(); |
|
| 75 | - $headers = $this->get_export_fields(); |
|
| 76 | - $file_type = $this->prepare_file_type( 'subscriptions' ); |
|
| 77 | - |
|
| 78 | - if ( 'csv' == $file_type ) { |
|
| 79 | - $this->download_csv( $subscriptions, $stream, $headers ); |
|
| 80 | - } elseif ( 'xml' == $file_type ) { |
|
| 81 | - $this->download_xml( $subscriptions, $stream, $headers ); |
|
| 82 | - } else { |
|
| 83 | - $this->download_json( $subscriptions, $stream, $headers ); |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - fclose( $stream ); |
|
| 87 | - exit; |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * Prepares a single subscription for download. |
|
| 92 | - * |
|
| 93 | - * @param WPInv_Subscription $subscription The subscription to prepare.. |
|
| 94 | - * @param array $fields The fields to stream. |
|
| 95 | - * @since 1.0.19 |
|
| 96 | - * @return array |
|
| 97 | - */ |
|
| 98 | - public function prepare_row( $subscription, $fields ) { |
|
| 99 | - |
|
| 100 | - $prepared = array(); |
|
| 101 | - $amount_fields = $this->get_amount_fields(); |
|
| 102 | - $invoice = $subscription->get_parent_payment(); |
|
| 103 | - |
|
| 104 | - foreach ( $fields as $field ) { |
|
| 105 | - |
|
| 106 | - $value = ''; |
|
| 107 | - $method = "get_$field"; |
|
| 108 | - |
|
| 109 | - if ( 0 === stripos( $field, 'customer' ) || 'currency' === $field ) { |
|
| 110 | - |
|
| 111 | - if ( method_exists( $invoice, $method ) ) { |
|
| 112 | - $value = $invoice->$method(); |
|
| 113 | - } |
|
| 15 | + /** |
|
| 16 | + * Retrieves subscription query args. |
|
| 17 | + * |
|
| 18 | + * @param array $args Args to search for. |
|
| 19 | + * @return array |
|
| 20 | + */ |
|
| 21 | + public function get_subscription_query_args( $args ) { |
|
| 22 | + |
|
| 23 | + $query_args = array( |
|
| 24 | + 'status' => 'all', |
|
| 25 | + 'number' => -1, |
|
| 26 | + 'count_total' => false, |
|
| 27 | + 'fields' => 'all', |
|
| 28 | + ); |
|
| 29 | + |
|
| 30 | + if ( ! empty( $args['status'] ) && in_array( $args['status'], array_keys( getpaid_get_subscription_statuses() ), true ) ) { |
|
| 31 | + $query_args['status'] = wpinv_clean( wpinv_parse_list( $args['status'] ) ); |
|
| 32 | + } |
|
| 33 | + |
|
| 34 | + $date_query = array(); |
|
| 35 | + if ( ! empty( $args['to_date'] ) ) { |
|
| 36 | + $date_query['before'] = wpinv_clean( $args['to_date'] ); |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + if ( ! empty( $args['from_date'] ) ) { |
|
| 40 | + $date_query['after'] = wpinv_clean( $args['from_date'] ); |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + if ( ! empty( $date_query ) ) { |
|
| 44 | + $date_query['inclusive'] = true; |
|
| 45 | + $query_args['date_created_query'] = array( $date_query ); |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + return $query_args; |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * Retrieves subscriptions. |
|
| 53 | + * |
|
| 54 | + * @param array $query_args GetPaid_Subscriptions_Query args. |
|
| 55 | + * @return WPInv_Subscription[] |
|
| 56 | + */ |
|
| 57 | + public function get_subscriptions( $query_args ) { |
|
| 58 | + |
|
| 59 | + // Get subscriptions. |
|
| 60 | + $subscriptions = new GetPaid_Subscriptions_Query( $query_args ); |
|
| 61 | + |
|
| 62 | + // Prepare the results. |
|
| 63 | + return $subscriptions->get_results(); |
|
| 64 | + |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * Handles the actual download. |
|
| 69 | + * |
|
| 70 | + */ |
|
| 71 | + public function export( $post_type, $args ) { |
|
| 72 | + |
|
| 73 | + $subscriptions = $this->get_subscriptions( $this->get_subscription_query_args( $args ) ); |
|
| 74 | + $stream = $this->prepare_output(); |
|
| 75 | + $headers = $this->get_export_fields(); |
|
| 76 | + $file_type = $this->prepare_file_type( 'subscriptions' ); |
|
| 77 | + |
|
| 78 | + if ( 'csv' == $file_type ) { |
|
| 79 | + $this->download_csv( $subscriptions, $stream, $headers ); |
|
| 80 | + } elseif ( 'xml' == $file_type ) { |
|
| 81 | + $this->download_xml( $subscriptions, $stream, $headers ); |
|
| 82 | + } else { |
|
| 83 | + $this->download_json( $subscriptions, $stream, $headers ); |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + fclose( $stream ); |
|
| 87 | + exit; |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * Prepares a single subscription for download. |
|
| 92 | + * |
|
| 93 | + * @param WPInv_Subscription $subscription The subscription to prepare.. |
|
| 94 | + * @param array $fields The fields to stream. |
|
| 95 | + * @since 1.0.19 |
|
| 96 | + * @return array |
|
| 97 | + */ |
|
| 98 | + public function prepare_row( $subscription, $fields ) { |
|
| 99 | + |
|
| 100 | + $prepared = array(); |
|
| 101 | + $amount_fields = $this->get_amount_fields(); |
|
| 102 | + $invoice = $subscription->get_parent_payment(); |
|
| 103 | + |
|
| 104 | + foreach ( $fields as $field ) { |
|
| 105 | + |
|
| 106 | + $value = ''; |
|
| 107 | + $method = "get_$field"; |
|
| 108 | + |
|
| 109 | + if ( 0 === stripos( $field, 'customer' ) || 'currency' === $field ) { |
|
| 110 | + |
|
| 111 | + if ( method_exists( $invoice, $method ) ) { |
|
| 112 | + $value = $invoice->$method(); |
|
| 113 | + } |
|
| 114 | 114 | } elseif ( method_exists( $subscription, $method ) ) { |
| 115 | - $value = $subscription->$method(); |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - if ( in_array( $field, $amount_fields ) ) { |
|
| 119 | - $value = wpinv_round_amount( wpinv_sanitize_amount( $value ) ); |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - $prepared[ $field ] = wpinv_clean( $value ); |
|
| 123 | - |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - return $prepared; |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * Retrieves export fields. |
|
| 131 | - * |
|
| 132 | - * @since 1.0.19 |
|
| 133 | - * @return array |
|
| 134 | - */ |
|
| 135 | - public function get_export_fields() { |
|
| 136 | - |
|
| 137 | - $fields = array( |
|
| 138 | - 'id', |
|
| 139 | - 'currency', |
|
| 140 | - 'initial_amount', |
|
| 141 | - 'recurring_amount', |
|
| 142 | - 'trial_period', |
|
| 143 | - 'frequency', |
|
| 144 | - 'period', |
|
| 145 | - 'bill_times', |
|
| 146 | - 'parent_payment_id', |
|
| 147 | - 'profile_id', |
|
| 148 | - 'product_id', |
|
| 149 | - 'status', |
|
| 150 | - 'date_created', |
|
| 151 | - 'date_expires', |
|
| 152 | - |
|
| 153 | - 'customer_id', |
|
| 154 | - 'customer_first_name', |
|
| 155 | - 'customer_last_name', |
|
| 156 | - 'customer_phone', |
|
| 157 | - 'customer_email', |
|
| 158 | - 'customer_country', |
|
| 159 | - 'customer_city', |
|
| 160 | - 'customer_state', |
|
| 161 | - 'customer_zip', |
|
| 162 | - 'customer_company', |
|
| 163 | - 'customer_vat_number', |
|
| 164 | - 'customer_address', |
|
| 165 | - |
|
| 166 | - ); |
|
| 167 | - |
|
| 168 | - return apply_filters( 'getpaid_subscription_exporter_get_fields', $fields ); |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * Retrieves amount fields. |
|
| 173 | - * |
|
| 174 | - * @since 1.0.19 |
|
| 175 | - * @return array |
|
| 176 | - */ |
|
| 177 | - public function get_amount_fields() { |
|
| 178 | - |
|
| 179 | - $fields = array( |
|
| 180 | - 'initial_amount', |
|
| 181 | - 'recurring_amount', |
|
| 182 | - ); |
|
| 183 | - |
|
| 184 | - return apply_filters( 'getpaid_subscription_exporter_get_amount_fields', $fields ); |
|
| 185 | - } |
|
| 115 | + $value = $subscription->$method(); |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + if ( in_array( $field, $amount_fields ) ) { |
|
| 119 | + $value = wpinv_round_amount( wpinv_sanitize_amount( $value ) ); |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + $prepared[ $field ] = wpinv_clean( $value ); |
|
| 123 | + |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + return $prepared; |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * Retrieves export fields. |
|
| 131 | + * |
|
| 132 | + * @since 1.0.19 |
|
| 133 | + * @return array |
|
| 134 | + */ |
|
| 135 | + public function get_export_fields() { |
|
| 136 | + |
|
| 137 | + $fields = array( |
|
| 138 | + 'id', |
|
| 139 | + 'currency', |
|
| 140 | + 'initial_amount', |
|
| 141 | + 'recurring_amount', |
|
| 142 | + 'trial_period', |
|
| 143 | + 'frequency', |
|
| 144 | + 'period', |
|
| 145 | + 'bill_times', |
|
| 146 | + 'parent_payment_id', |
|
| 147 | + 'profile_id', |
|
| 148 | + 'product_id', |
|
| 149 | + 'status', |
|
| 150 | + 'date_created', |
|
| 151 | + 'date_expires', |
|
| 152 | + |
|
| 153 | + 'customer_id', |
|
| 154 | + 'customer_first_name', |
|
| 155 | + 'customer_last_name', |
|
| 156 | + 'customer_phone', |
|
| 157 | + 'customer_email', |
|
| 158 | + 'customer_country', |
|
| 159 | + 'customer_city', |
|
| 160 | + 'customer_state', |
|
| 161 | + 'customer_zip', |
|
| 162 | + 'customer_company', |
|
| 163 | + 'customer_vat_number', |
|
| 164 | + 'customer_address', |
|
| 165 | + |
|
| 166 | + ); |
|
| 167 | + |
|
| 168 | + return apply_filters( 'getpaid_subscription_exporter_get_fields', $fields ); |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + /** |
|
| 172 | + * Retrieves amount fields. |
|
| 173 | + * |
|
| 174 | + * @since 1.0.19 |
|
| 175 | + * @return array |
|
| 176 | + */ |
|
| 177 | + public function get_amount_fields() { |
|
| 178 | + |
|
| 179 | + $fields = array( |
|
| 180 | + 'initial_amount', |
|
| 181 | + 'recurring_amount', |
|
| 182 | + ); |
|
| 183 | + |
|
| 184 | + return apply_filters( 'getpaid_subscription_exporter_get_amount_fields', $fields ); |
|
| 185 | + } |
|
| 186 | 186 | |
| 187 | 187 | } |
@@ -5,7 +5,7 @@ discard block |
||
| 5 | 5 | * |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | -defined( 'ABSPATH' ) || exit; |
|
| 8 | +defined('ABSPATH') || exit; |
|
| 9 | 9 | |
| 10 | 10 | /** |
| 11 | 11 | * GetPaid_Subscription_Exporter Class. |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | * @param array $args Args to search for. |
| 19 | 19 | * @return array |
| 20 | 20 | */ |
| 21 | - public function get_subscription_query_args( $args ) { |
|
| 21 | + public function get_subscription_query_args($args) { |
|
| 22 | 22 | |
| 23 | 23 | $query_args = array( |
| 24 | 24 | 'status' => 'all', |
@@ -27,22 +27,22 @@ discard block |
||
| 27 | 27 | 'fields' => 'all', |
| 28 | 28 | ); |
| 29 | 29 | |
| 30 | - if ( ! empty( $args['status'] ) && in_array( $args['status'], array_keys( getpaid_get_subscription_statuses() ), true ) ) { |
|
| 31 | - $query_args['status'] = wpinv_clean( wpinv_parse_list( $args['status'] ) ); |
|
| 30 | + if (!empty($args['status']) && in_array($args['status'], array_keys(getpaid_get_subscription_statuses()), true)) { |
|
| 31 | + $query_args['status'] = wpinv_clean(wpinv_parse_list($args['status'])); |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | $date_query = array(); |
| 35 | - if ( ! empty( $args['to_date'] ) ) { |
|
| 36 | - $date_query['before'] = wpinv_clean( $args['to_date'] ); |
|
| 35 | + if (!empty($args['to_date'])) { |
|
| 36 | + $date_query['before'] = wpinv_clean($args['to_date']); |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | - if ( ! empty( $args['from_date'] ) ) { |
|
| 40 | - $date_query['after'] = wpinv_clean( $args['from_date'] ); |
|
| 39 | + if (!empty($args['from_date'])) { |
|
| 40 | + $date_query['after'] = wpinv_clean($args['from_date']); |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | - if ( ! empty( $date_query ) ) { |
|
| 43 | + if (!empty($date_query)) { |
|
| 44 | 44 | $date_query['inclusive'] = true; |
| 45 | - $query_args['date_created_query'] = array( $date_query ); |
|
| 45 | + $query_args['date_created_query'] = array($date_query); |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | return $query_args; |
@@ -54,10 +54,10 @@ discard block |
||
| 54 | 54 | * @param array $query_args GetPaid_Subscriptions_Query args. |
| 55 | 55 | * @return WPInv_Subscription[] |
| 56 | 56 | */ |
| 57 | - public function get_subscriptions( $query_args ) { |
|
| 57 | + public function get_subscriptions($query_args) { |
|
| 58 | 58 | |
| 59 | 59 | // Get subscriptions. |
| 60 | - $subscriptions = new GetPaid_Subscriptions_Query( $query_args ); |
|
| 60 | + $subscriptions = new GetPaid_Subscriptions_Query($query_args); |
|
| 61 | 61 | |
| 62 | 62 | // Prepare the results. |
| 63 | 63 | return $subscriptions->get_results(); |
@@ -68,22 +68,22 @@ discard block |
||
| 68 | 68 | * Handles the actual download. |
| 69 | 69 | * |
| 70 | 70 | */ |
| 71 | - public function export( $post_type, $args ) { |
|
| 71 | + public function export($post_type, $args) { |
|
| 72 | 72 | |
| 73 | - $subscriptions = $this->get_subscriptions( $this->get_subscription_query_args( $args ) ); |
|
| 73 | + $subscriptions = $this->get_subscriptions($this->get_subscription_query_args($args)); |
|
| 74 | 74 | $stream = $this->prepare_output(); |
| 75 | 75 | $headers = $this->get_export_fields(); |
| 76 | - $file_type = $this->prepare_file_type( 'subscriptions' ); |
|
| 76 | + $file_type = $this->prepare_file_type('subscriptions'); |
|
| 77 | 77 | |
| 78 | - if ( 'csv' == $file_type ) { |
|
| 79 | - $this->download_csv( $subscriptions, $stream, $headers ); |
|
| 80 | - } elseif ( 'xml' == $file_type ) { |
|
| 81 | - $this->download_xml( $subscriptions, $stream, $headers ); |
|
| 78 | + if ('csv' == $file_type) { |
|
| 79 | + $this->download_csv($subscriptions, $stream, $headers); |
|
| 80 | + } elseif ('xml' == $file_type) { |
|
| 81 | + $this->download_xml($subscriptions, $stream, $headers); |
|
| 82 | 82 | } else { |
| 83 | - $this->download_json( $subscriptions, $stream, $headers ); |
|
| 83 | + $this->download_json($subscriptions, $stream, $headers); |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | - fclose( $stream ); |
|
| 86 | + fclose($stream); |
|
| 87 | 87 | exit; |
| 88 | 88 | } |
| 89 | 89 | |
@@ -95,31 +95,31 @@ discard block |
||
| 95 | 95 | * @since 1.0.19 |
| 96 | 96 | * @return array |
| 97 | 97 | */ |
| 98 | - public function prepare_row( $subscription, $fields ) { |
|
| 98 | + public function prepare_row($subscription, $fields) { |
|
| 99 | 99 | |
| 100 | 100 | $prepared = array(); |
| 101 | 101 | $amount_fields = $this->get_amount_fields(); |
| 102 | 102 | $invoice = $subscription->get_parent_payment(); |
| 103 | 103 | |
| 104 | - foreach ( $fields as $field ) { |
|
| 104 | + foreach ($fields as $field) { |
|
| 105 | 105 | |
| 106 | 106 | $value = ''; |
| 107 | 107 | $method = "get_$field"; |
| 108 | 108 | |
| 109 | - if ( 0 === stripos( $field, 'customer' ) || 'currency' === $field ) { |
|
| 109 | + if (0 === stripos($field, 'customer') || 'currency' === $field) { |
|
| 110 | 110 | |
| 111 | - if ( method_exists( $invoice, $method ) ) { |
|
| 112 | - $value = $invoice->$method(); |
|
| 111 | + if (method_exists($invoice, $method)) { |
|
| 112 | + $value = $invoice->$method(); |
|
| 113 | 113 | } |
| 114 | -} elseif ( method_exists( $subscription, $method ) ) { |
|
| 115 | - $value = $subscription->$method(); |
|
| 114 | +} elseif (method_exists($subscription, $method)) { |
|
| 115 | + $value = $subscription->$method(); |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | - if ( in_array( $field, $amount_fields ) ) { |
|
| 119 | - $value = wpinv_round_amount( wpinv_sanitize_amount( $value ) ); |
|
| 118 | + if (in_array($field, $amount_fields)) { |
|
| 119 | + $value = wpinv_round_amount(wpinv_sanitize_amount($value)); |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | - $prepared[ $field ] = wpinv_clean( $value ); |
|
| 122 | + $prepared[$field] = wpinv_clean($value); |
|
| 123 | 123 | |
| 124 | 124 | } |
| 125 | 125 | |
@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | |
| 166 | 166 | ); |
| 167 | 167 | |
| 168 | - return apply_filters( 'getpaid_subscription_exporter_get_fields', $fields ); |
|
| 168 | + return apply_filters('getpaid_subscription_exporter_get_fields', $fields); |
|
| 169 | 169 | } |
| 170 | 170 | |
| 171 | 171 | /** |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | 'recurring_amount', |
| 182 | 182 | ); |
| 183 | 183 | |
| 184 | - return apply_filters( 'getpaid_subscription_exporter_get_amount_fields', $fields ); |
|
| 184 | + return apply_filters('getpaid_subscription_exporter_get_amount_fields', $fields); |
|
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | } |
@@ -12,22 +12,22 @@ discard block |
||
| 12 | 12 | */ |
| 13 | 13 | class GetPaid_Reports_Report_Gateways extends GetPaid_Reports_Abstract_Report { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * @var string |
|
| 17 | - */ |
|
| 18 | - public $field = 'gateway'; |
|
| 19 | - |
|
| 20 | - /** |
|
| 21 | - * Retrieves the earning sql. |
|
| 22 | - * |
|
| 23 | - */ |
|
| 24 | - public function get_sql( $range ) { |
|
| 25 | - global $wpdb; |
|
| 26 | - |
|
| 27 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
| 28 | - $clauses = $this->get_range_sql( $range ); |
|
| 29 | - |
|
| 30 | - $sql = "SELECT |
|
| 15 | + /** |
|
| 16 | + * @var string |
|
| 17 | + */ |
|
| 18 | + public $field = 'gateway'; |
|
| 19 | + |
|
| 20 | + /** |
|
| 21 | + * Retrieves the earning sql. |
|
| 22 | + * |
|
| 23 | + */ |
|
| 24 | + public function get_sql( $range ) { |
|
| 25 | + global $wpdb; |
|
| 26 | + |
|
| 27 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
| 28 | + $clauses = $this->get_range_sql( $range ); |
|
| 29 | + |
|
| 30 | + $sql = "SELECT |
|
| 31 | 31 | meta.gateway AS gateway, |
| 32 | 32 | SUM(total) as total |
| 33 | 33 | FROM $wpdb->posts |
@@ -40,91 +40,91 @@ discard block |
||
| 40 | 40 | ORDER BY total DESC |
| 41 | 41 | "; |
| 42 | 42 | |
| 43 | - return apply_filters( 'getpaid_gateways_graphs_get_sql', $sql, $range ); |
|
| 43 | + return apply_filters( 'getpaid_gateways_graphs_get_sql', $sql, $range ); |
|
| 44 | 44 | |
| 45 | - } |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * Prepares the report stats. |
|
| 49 | - * |
|
| 50 | - */ |
|
| 51 | - public function prepare_stats() { |
|
| 52 | - global $wpdb; |
|
| 53 | - $this->stats = $wpdb->get_results( $this->get_sql( $this->get_range() ) ); |
|
| 54 | - $this->stats = $this->normalize_stats( $this->stats ); |
|
| 55 | - } |
|
| 47 | + /** |
|
| 48 | + * Prepares the report stats. |
|
| 49 | + * |
|
| 50 | + */ |
|
| 51 | + public function prepare_stats() { |
|
| 52 | + global $wpdb; |
|
| 53 | + $this->stats = $wpdb->get_results( $this->get_sql( $this->get_range() ) ); |
|
| 54 | + $this->stats = $this->normalize_stats( $this->stats ); |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * Normalizes the report stats. |
|
| 59 | - * |
|
| 60 | - */ |
|
| 61 | - public function normalize_stats( $stats ) { |
|
| 62 | - $normalized = array(); |
|
| 63 | - $others = 0; |
|
| 64 | - $did = 0; |
|
| 57 | + /** |
|
| 58 | + * Normalizes the report stats. |
|
| 59 | + * |
|
| 60 | + */ |
|
| 61 | + public function normalize_stats( $stats ) { |
|
| 62 | + $normalized = array(); |
|
| 63 | + $others = 0; |
|
| 64 | + $did = 0; |
|
| 65 | 65 | |
| 66 | - foreach ( $stats as $stat ) { |
|
| 66 | + foreach ( $stats as $stat ) { |
|
| 67 | 67 | |
| 68 | - if ( $did > 4 ) { |
|
| 68 | + if ( $did > 4 ) { |
|
| 69 | 69 | |
| 70 | - $others += wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ); |
|
| 70 | + $others += wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ); |
|
| 71 | 71 | |
| 72 | - } else { |
|
| 72 | + } else { |
|
| 73 | 73 | |
| 74 | - $normalized[] = array( |
|
| 75 | - 'total' => wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ), |
|
| 76 | - 'gateway' => strip_tags( wpinv_get_gateway_admin_label( $stat->gateway ) ), |
|
| 77 | - ); |
|
| 74 | + $normalized[] = array( |
|
| 75 | + 'total' => wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ), |
|
| 76 | + 'gateway' => strip_tags( wpinv_get_gateway_admin_label( $stat->gateway ) ), |
|
| 77 | + ); |
|
| 78 | 78 | |
| 79 | - } |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - $did++; |
|
| 82 | - } |
|
| 81 | + $did++; |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - if ( $others > 0 ) { |
|
| 84 | + if ( $others > 0 ) { |
|
| 85 | 85 | |
| 86 | - $normalized[] = array( |
|
| 87 | - 'total' => wpinv_round_amount( wpinv_sanitize_amount( $others ) ), |
|
| 88 | - 'gateway' => esc_html__( 'Others', 'invoicing' ), |
|
| 89 | - ); |
|
| 86 | + $normalized[] = array( |
|
| 87 | + 'total' => wpinv_round_amount( wpinv_sanitize_amount( $others ) ), |
|
| 88 | + 'gateway' => esc_html__( 'Others', 'invoicing' ), |
|
| 89 | + ); |
|
| 90 | 90 | |
| 91 | - } |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - return $normalized; |
|
| 94 | - } |
|
| 93 | + return $normalized; |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | - /** |
|
| 97 | - * Retrieves report data. |
|
| 98 | - * |
|
| 99 | - */ |
|
| 100 | - public function get_data() { |
|
| 96 | + /** |
|
| 97 | + * Retrieves report data. |
|
| 98 | + * |
|
| 99 | + */ |
|
| 100 | + public function get_data() { |
|
| 101 | 101 | |
| 102 | - $data = wp_list_pluck( $this->stats, 'total' ); |
|
| 103 | - $colors = array( '#009688', '#4caf50', '#8bc34a', '#00bcd4', '#03a9f4', '#2196f3' ); |
|
| 102 | + $data = wp_list_pluck( $this->stats, 'total' ); |
|
| 103 | + $colors = array( '#009688', '#4caf50', '#8bc34a', '#00bcd4', '#03a9f4', '#2196f3' ); |
|
| 104 | 104 | |
| 105 | - shuffle( $colors ); |
|
| 105 | + shuffle( $colors ); |
|
| 106 | 106 | |
| 107 | - return array( |
|
| 108 | - 'data' => $data, |
|
| 109 | - 'backgroundColor' => $colors, |
|
| 110 | - ); |
|
| 107 | + return array( |
|
| 108 | + 'data' => $data, |
|
| 109 | + 'backgroundColor' => $colors, |
|
| 110 | + ); |
|
| 111 | 111 | |
| 112 | - } |
|
| 112 | + } |
|
| 113 | 113 | |
| 114 | - /** |
|
| 115 | - * Retrieves report labels. |
|
| 116 | - * |
|
| 117 | - */ |
|
| 118 | - public function get_labels() { |
|
| 119 | - return wp_list_pluck( $this->stats, 'gateway' ); |
|
| 120 | - } |
|
| 114 | + /** |
|
| 115 | + * Retrieves report labels. |
|
| 116 | + * |
|
| 117 | + */ |
|
| 118 | + public function get_labels() { |
|
| 119 | + return wp_list_pluck( $this->stats, 'gateway' ); |
|
| 120 | + } |
|
| 121 | 121 | |
| 122 | - /** |
|
| 123 | - * Displays the actual report. |
|
| 124 | - * |
|
| 125 | - */ |
|
| 126 | - public function display_stats() { |
|
| 127 | - ?> |
|
| 122 | + /** |
|
| 123 | + * Displays the actual report. |
|
| 124 | + * |
|
| 125 | + */ |
|
| 126 | + public function display_stats() { |
|
| 127 | + ?> |
|
| 128 | 128 | |
| 129 | 129 | <canvas id="getpaid-chartjs-earnings-gateways"></canvas> |
| 130 | 130 | |
@@ -153,6 +153,6 @@ discard block |
||
| 153 | 153 | </script> |
| 154 | 154 | |
| 155 | 155 | <?php |
| 156 | - } |
|
| 156 | + } |
|
| 157 | 157 | |
| 158 | 158 | } |
@@ -5,7 +5,7 @@ discard block |
||
| 5 | 5 | * |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | -defined( 'ABSPATH' ) || exit; |
|
| 8 | +defined('ABSPATH') || exit; |
|
| 9 | 9 | |
| 10 | 10 | /** |
| 11 | 11 | * GetPaid_Reports_Report_Items Class. |
@@ -21,11 +21,11 @@ discard block |
||
| 21 | 21 | * Retrieves the earning sql. |
| 22 | 22 | * |
| 23 | 23 | */ |
| 24 | - public function get_sql( $range ) { |
|
| 24 | + public function get_sql($range) { |
|
| 25 | 25 | global $wpdb; |
| 26 | 26 | |
| 27 | 27 | $table = $wpdb->prefix . 'getpaid_invoices'; |
| 28 | - $clauses = $this->get_range_sql( $range ); |
|
| 28 | + $clauses = $this->get_range_sql($range); |
|
| 29 | 29 | |
| 30 | 30 | $sql = "SELECT |
| 31 | 31 | meta.gateway AS gateway, |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | ORDER BY total DESC |
| 41 | 41 | "; |
| 42 | 42 | |
| 43 | - return apply_filters( 'getpaid_gateways_graphs_get_sql', $sql, $range ); |
|
| 43 | + return apply_filters('getpaid_gateways_graphs_get_sql', $sql, $range); |
|
| 44 | 44 | |
| 45 | 45 | } |
| 46 | 46 | |
@@ -50,30 +50,30 @@ discard block |
||
| 50 | 50 | */ |
| 51 | 51 | public function prepare_stats() { |
| 52 | 52 | global $wpdb; |
| 53 | - $this->stats = $wpdb->get_results( $this->get_sql( $this->get_range() ) ); |
|
| 54 | - $this->stats = $this->normalize_stats( $this->stats ); |
|
| 53 | + $this->stats = $wpdb->get_results($this->get_sql($this->get_range())); |
|
| 54 | + $this->stats = $this->normalize_stats($this->stats); |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | /** |
| 58 | 58 | * Normalizes the report stats. |
| 59 | 59 | * |
| 60 | 60 | */ |
| 61 | - public function normalize_stats( $stats ) { |
|
| 61 | + public function normalize_stats($stats) { |
|
| 62 | 62 | $normalized = array(); |
| 63 | 63 | $others = 0; |
| 64 | 64 | $did = 0; |
| 65 | 65 | |
| 66 | - foreach ( $stats as $stat ) { |
|
| 66 | + foreach ($stats as $stat) { |
|
| 67 | 67 | |
| 68 | - if ( $did > 4 ) { |
|
| 68 | + if ($did > 4) { |
|
| 69 | 69 | |
| 70 | - $others += wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ); |
|
| 70 | + $others += wpinv_round_amount(wpinv_sanitize_amount($stat->total)); |
|
| 71 | 71 | |
| 72 | 72 | } else { |
| 73 | 73 | |
| 74 | 74 | $normalized[] = array( |
| 75 | - 'total' => wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ), |
|
| 76 | - 'gateway' => strip_tags( wpinv_get_gateway_admin_label( $stat->gateway ) ), |
|
| 75 | + 'total' => wpinv_round_amount(wpinv_sanitize_amount($stat->total)), |
|
| 76 | + 'gateway' => strip_tags(wpinv_get_gateway_admin_label($stat->gateway)), |
|
| 77 | 77 | ); |
| 78 | 78 | |
| 79 | 79 | } |
@@ -81,11 +81,11 @@ discard block |
||
| 81 | 81 | $did++; |
| 82 | 82 | } |
| 83 | 83 | |
| 84 | - if ( $others > 0 ) { |
|
| 84 | + if ($others > 0) { |
|
| 85 | 85 | |
| 86 | 86 | $normalized[] = array( |
| 87 | - 'total' => wpinv_round_amount( wpinv_sanitize_amount( $others ) ), |
|
| 88 | - 'gateway' => esc_html__( 'Others', 'invoicing' ), |
|
| 87 | + 'total' => wpinv_round_amount(wpinv_sanitize_amount($others)), |
|
| 88 | + 'gateway' => esc_html__('Others', 'invoicing'), |
|
| 89 | 89 | ); |
| 90 | 90 | |
| 91 | 91 | } |
@@ -99,10 +99,10 @@ discard block |
||
| 99 | 99 | */ |
| 100 | 100 | public function get_data() { |
| 101 | 101 | |
| 102 | - $data = wp_list_pluck( $this->stats, 'total' ); |
|
| 103 | - $colors = array( '#009688', '#4caf50', '#8bc34a', '#00bcd4', '#03a9f4', '#2196f3' ); |
|
| 102 | + $data = wp_list_pluck($this->stats, 'total'); |
|
| 103 | + $colors = array('#009688', '#4caf50', '#8bc34a', '#00bcd4', '#03a9f4', '#2196f3'); |
|
| 104 | 104 | |
| 105 | - shuffle( $colors ); |
|
| 105 | + shuffle($colors); |
|
| 106 | 106 | |
| 107 | 107 | return array( |
| 108 | 108 | 'data' => $data, |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | * |
| 117 | 117 | */ |
| 118 | 118 | public function get_labels() { |
| 119 | - return wp_list_pluck( $this->stats, 'gateway' ); |
|
| 119 | + return wp_list_pluck($this->stats, 'gateway'); |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | /** |
@@ -137,8 +137,8 @@ discard block |
||
| 137 | 137 | { |
| 138 | 138 | type: 'doughnut', |
| 139 | 139 | data: { |
| 140 | - 'labels': <?php echo wp_json_encode( wp_kses_post_deep( $this->get_labels() ) ); ?>, |
|
| 141 | - 'datasets': [ <?php echo wp_json_encode( wp_kses_post_deep( $this->get_data() ) ); ?> ] |
|
| 140 | + 'labels': <?php echo wp_json_encode(wp_kses_post_deep($this->get_labels())); ?>, |
|
| 141 | + 'datasets': [ <?php echo wp_json_encode(wp_kses_post_deep($this->get_data())); ?> ] |
|
| 142 | 142 | }, |
| 143 | 143 | options: { |
| 144 | 144 | legend: { |
@@ -136,13 +136,13 @@ discard block |
||
| 136 | 136 | */ |
| 137 | 137 | function wpinv_get_invoice_statuses( $draft = false, $trashed = false, $invoice = false ) { |
| 138 | 138 | |
| 139 | - $invoice_statuses = array( |
|
| 140 | - 'wpi-pending' => _x( 'Pending payment', 'Invoice status', 'invoicing' ), |
|
| 139 | + $invoice_statuses = array( |
|
| 140 | + 'wpi-pending' => _x( 'Pending payment', 'Invoice status', 'invoicing' ), |
|
| 141 | 141 | 'publish' => _x( 'Paid', 'Invoice status', 'invoicing' ), |
| 142 | 142 | 'wpi-processing' => _x( 'Processing', 'Invoice status', 'invoicing' ), |
| 143 | - 'wpi-onhold' => _x( 'On hold', 'Invoice status', 'invoicing' ), |
|
| 144 | - 'wpi-cancelled' => _x( 'Cancelled', 'Invoice status', 'invoicing' ), |
|
| 145 | - 'wpi-refunded' => _x( 'Refunded', 'Invoice status', 'invoicing' ), |
|
| 143 | + 'wpi-onhold' => _x( 'On hold', 'Invoice status', 'invoicing' ), |
|
| 144 | + 'wpi-cancelled' => _x( 'Cancelled', 'Invoice status', 'invoicing' ), |
|
| 145 | + 'wpi-refunded' => _x( 'Refunded', 'Invoice status', 'invoicing' ), |
|
| 146 | 146 | 'wpi-failed' => _x( 'Failed', 'Invoice status', 'invoicing' ), |
| 147 | 147 | 'wpi-renewal' => _x( 'Renewal Payment', 'Invoice status', 'invoicing' ), |
| 148 | 148 | ); |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | $invoice = $invoice->get_post_type(); |
| 160 | 160 | } |
| 161 | 161 | |
| 162 | - return apply_filters( 'wpinv_statuses', $invoice_statuses, $invoice ); |
|
| 162 | + return apply_filters( 'wpinv_statuses', $invoice_statuses, $invoice ); |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | /** |
@@ -277,25 +277,25 @@ discard block |
||
| 277 | 277 | * @return string |
| 278 | 278 | */ |
| 279 | 279 | function getpaid_get_price_format() { |
| 280 | - $currency_pos = wpinv_currency_position(); |
|
| 281 | - $format = '%1$s%2$s'; |
|
| 282 | - |
|
| 283 | - switch ( $currency_pos ) { |
|
| 284 | - case 'left': |
|
| 285 | - $format = '%1$s%2$s'; |
|
| 286 | - break; |
|
| 287 | - case 'right': |
|
| 288 | - $format = '%2$s%1$s'; |
|
| 289 | - break; |
|
| 290 | - case 'left_space': |
|
| 291 | - $format = '%1$s %2$s'; |
|
| 292 | - break; |
|
| 293 | - case 'right_space': |
|
| 294 | - $format = '%2$s %1$s'; |
|
| 295 | - break; |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - return apply_filters( 'getpaid_price_format', $format, $currency_pos ); |
|
| 280 | + $currency_pos = wpinv_currency_position(); |
|
| 281 | + $format = '%1$s%2$s'; |
|
| 282 | + |
|
| 283 | + switch ( $currency_pos ) { |
|
| 284 | + case 'left': |
|
| 285 | + $format = '%1$s%2$s'; |
|
| 286 | + break; |
|
| 287 | + case 'right': |
|
| 288 | + $format = '%2$s%1$s'; |
|
| 289 | + break; |
|
| 290 | + case 'left_space': |
|
| 291 | + $format = '%1$s %2$s'; |
|
| 292 | + break; |
|
| 293 | + case 'right_space': |
|
| 294 | + $format = '%2$s %1$s'; |
|
| 295 | + break; |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + return apply_filters( 'getpaid_price_format', $format, $currency_pos ); |
|
| 299 | 299 | } |
| 300 | 300 | |
| 301 | 301 | /** |
@@ -390,13 +390,13 @@ discard block |
||
| 390 | 390 | * @param mixed $value Value. |
| 391 | 391 | */ |
| 392 | 392 | function getpaid_maybe_define_constant( $name, $value ) { |
| 393 | - if ( ! defined( $name ) ) { |
|
| 394 | - define( $name, $value ); |
|
| 395 | - } |
|
| 393 | + if ( ! defined( $name ) ) { |
|
| 394 | + define( $name, $value ); |
|
| 395 | + } |
|
| 396 | 396 | } |
| 397 | 397 | |
| 398 | 398 | function wpinv_get_php_arg_separator_output() { |
| 399 | - return ini_get( 'arg_separator.output' ); |
|
| 399 | + return ini_get( 'arg_separator.output' ); |
|
| 400 | 400 | } |
| 401 | 401 | |
| 402 | 402 | function wpinv_rgb_from_hex( $color ) { |
@@ -698,16 +698,16 @@ discard block |
||
| 698 | 698 | return wp_kses( |
| 699 | 699 | html_entity_decode( $var ), |
| 700 | 700 | array( |
| 701 | - 'br' => array(), |
|
| 702 | - 'em' => array(), |
|
| 703 | - 'strong' => array(), |
|
| 704 | - 'b' => array(), |
|
| 705 | - 'small' => array(), |
|
| 706 | - 'span' => array(), |
|
| 707 | - 'ul' => array(), |
|
| 708 | - 'li' => array(), |
|
| 709 | - 'ol' => array(), |
|
| 710 | - 'p' => array(), |
|
| 701 | + 'br' => array(), |
|
| 702 | + 'em' => array(), |
|
| 703 | + 'strong' => array(), |
|
| 704 | + 'b' => array(), |
|
| 705 | + 'small' => array(), |
|
| 706 | + 'span' => array(), |
|
| 707 | + 'ul' => array(), |
|
| 708 | + 'li' => array(), |
|
| 709 | + 'ol' => array(), |
|
| 710 | + 'p' => array(), |
|
| 711 | 711 | ) |
| 712 | 712 | ); |
| 713 | 713 | } |
@@ -758,11 +758,11 @@ discard block |
||
| 758 | 758 | $list = array(); |
| 759 | 759 | } |
| 760 | 760 | |
| 761 | - if ( ! is_array( $list ) ) { |
|
| 762 | - return preg_split( '/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY ); |
|
| 763 | - } |
|
| 761 | + if ( ! is_array( $list ) ) { |
|
| 762 | + return preg_split( '/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY ); |
|
| 763 | + } |
|
| 764 | 764 | |
| 765 | - return $list; |
|
| 765 | + return $list; |
|
| 766 | 766 | } |
| 767 | 767 | |
| 768 | 768 | /** |
@@ -782,9 +782,9 @@ discard block |
||
| 782 | 782 | } |
| 783 | 783 | |
| 784 | 784 | $data = apply_filters( "wpinv_get_$key", include WPINV_PLUGIN_DIR . "includes/data/$key.php" ); |
| 785 | - wp_cache_set( "wpinv-data-$key", $data, 'wpinv' ); |
|
| 785 | + wp_cache_set( "wpinv-data-$key", $data, 'wpinv' ); |
|
| 786 | 786 | |
| 787 | - return $data; |
|
| 787 | + return $data; |
|
| 788 | 788 | } |
| 789 | 789 | |
| 790 | 790 | /** |
@@ -813,17 +813,17 @@ discard block |
||
| 813 | 813 | */ |
| 814 | 814 | function wpinv_clean( $var ) { |
| 815 | 815 | |
| 816 | - if ( is_array( $var ) ) { |
|
| 817 | - return array_map( 'wpinv_clean', $var ); |
|
| 816 | + if ( is_array( $var ) ) { |
|
| 817 | + return array_map( 'wpinv_clean', $var ); |
|
| 818 | 818 | } |
| 819 | 819 | |
| 820 | 820 | if ( is_object( $var ) ) { |
| 821 | - $object_vars = get_object_vars( $var ); |
|
| 822 | - foreach ( $object_vars as $property_name => $property_value ) { |
|
| 823 | - $var->$property_name = wpinv_clean( $property_value ); |
|
| 821 | + $object_vars = get_object_vars( $var ); |
|
| 822 | + foreach ( $object_vars as $property_name => $property_value ) { |
|
| 823 | + $var->$property_name = wpinv_clean( $property_value ); |
|
| 824 | 824 | } |
| 825 | 825 | return $var; |
| 826 | - } |
|
| 826 | + } |
|
| 827 | 827 | |
| 828 | 828 | return is_string( $var ) ? sanitize_text_field( stripslashes( $var ) ) : $var; |
| 829 | 829 | } |
@@ -836,7 +836,7 @@ discard block |
||
| 836 | 836 | */ |
| 837 | 837 | function getpaid_convert_price_string_to_options( $str ) { |
| 838 | 838 | |
| 839 | - $raw_options = array_map( 'trim', explode( ',', $str ) ); |
|
| 839 | + $raw_options = array_map( 'trim', explode( ',', $str ) ); |
|
| 840 | 840 | $options = array(); |
| 841 | 841 | |
| 842 | 842 | foreach ( $raw_options as $option ) { |
@@ -919,7 +919,7 @@ discard block |
||
| 919 | 919 | * @return string |
| 920 | 920 | */ |
| 921 | 921 | function getpaid_date_format() { |
| 922 | - return apply_filters( 'getpaid_date_format', get_option( 'date_format' ) ); |
|
| 922 | + return apply_filters( 'getpaid_date_format', get_option( 'date_format' ) ); |
|
| 923 | 923 | } |
| 924 | 924 | |
| 925 | 925 | /** |
@@ -928,7 +928,7 @@ discard block |
||
| 928 | 928 | * @return string |
| 929 | 929 | */ |
| 930 | 930 | function getpaid_time_format() { |
| 931 | - return apply_filters( 'getpaid_time_format', get_option( 'time_format' ) ); |
|
| 931 | + return apply_filters( 'getpaid_time_format', get_option( 'time_format' ) ); |
|
| 932 | 932 | } |
| 933 | 933 | |
| 934 | 934 | /** |
@@ -941,15 +941,15 @@ discard block |
||
| 941 | 941 | function getpaid_limit_length( $string, $limit ) { |
| 942 | 942 | $str_limit = $limit - 3; |
| 943 | 943 | |
| 944 | - if ( function_exists( 'mb_strimwidth' ) ) { |
|
| 945 | - if ( mb_strlen( $string ) > $limit ) { |
|
| 946 | - $string = mb_strimwidth( $string, 0, $str_limit ) . '...'; |
|
| 947 | - } |
|
| 948 | - } else { |
|
| 949 | - if ( strlen( $string ) > $limit ) { |
|
| 950 | - $string = substr( $string, 0, $str_limit ) . '...'; |
|
| 951 | - } |
|
| 952 | - } |
|
| 944 | + if ( function_exists( 'mb_strimwidth' ) ) { |
|
| 945 | + if ( mb_strlen( $string ) > $limit ) { |
|
| 946 | + $string = mb_strimwidth( $string, 0, $str_limit ) . '...'; |
|
| 947 | + } |
|
| 948 | + } else { |
|
| 949 | + if ( strlen( $string ) > $limit ) { |
|
| 950 | + $string = substr( $string, 0, $str_limit ) . '...'; |
|
| 951 | + } |
|
| 952 | + } |
|
| 953 | 953 | return $string; |
| 954 | 954 | |
| 955 | 955 | } |
@@ -1079,12 +1079,12 @@ discard block |
||
| 1079 | 1079 | $types = get_allowed_mime_types(); |
| 1080 | 1080 | |
| 1081 | 1081 | if ( isset( $types['htm|html'] ) ) { |
| 1082 | - unset( $types['htm|html'] ); |
|
| 1083 | - } |
|
| 1082 | + unset( $types['htm|html'] ); |
|
| 1083 | + } |
|
| 1084 | 1084 | |
| 1085 | 1085 | if ( isset( $types['js'] ) ) { |
| 1086 | - unset( $types['js'] ); |
|
| 1087 | - } |
|
| 1086 | + unset( $types['js'] ); |
|
| 1087 | + } |
|
| 1088 | 1088 | |
| 1089 | 1089 | return $types; |
| 1090 | 1090 | |
@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | * @package Invoicing |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | -defined( 'ABSPATH' ) || exit; |
|
| 9 | +defined('ABSPATH') || exit; |
|
| 10 | 10 | |
| 11 | 11 | /** |
| 12 | 12 | * Are we supporting item quantities? |
@@ -20,35 +20,35 @@ discard block |
||
| 20 | 20 | */ |
| 21 | 21 | function wpinv_get_ip() { |
| 22 | 22 | |
| 23 | - if ( isset( $_SERVER['HTTP_X_REAL_IP'] ) ) { |
|
| 24 | - return sanitize_text_field( wp_unslash( $_SERVER['HTTP_X_REAL_IP'] ) ); |
|
| 23 | + if (isset($_SERVER['HTTP_X_REAL_IP'])) { |
|
| 24 | + return sanitize_text_field(wp_unslash($_SERVER['HTTP_X_REAL_IP'])); |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | - if ( isset( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) { |
|
| 27 | + if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { |
|
| 28 | 28 | // Proxy servers can send through this header like this: X-Forwarded-For: client1, proxy1, proxy2 |
| 29 | 29 | // Make sure we always only send through the first IP in the list which should always be the client IP. |
| 30 | - return (string) rest_is_ip_address( trim( current( preg_split( '/,/', sanitize_text_field( wp_unslash( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) ) ) ) ); |
|
| 30 | + return (string) rest_is_ip_address(trim(current(preg_split('/,/', sanitize_text_field(wp_unslash($_SERVER['HTTP_X_FORWARDED_FOR'])))))); |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | - if ( isset( $_SERVER['HTTP_CLIENT_IP'] ) ) { |
|
| 34 | - return sanitize_text_field( wp_unslash( $_SERVER['HTTP_CLIENT_IP'] ) ); |
|
| 33 | + if (isset($_SERVER['HTTP_CLIENT_IP'])) { |
|
| 34 | + return sanitize_text_field(wp_unslash($_SERVER['HTTP_CLIENT_IP'])); |
|
| 35 | 35 | } |
| 36 | 36 | |
| 37 | - if ( isset( $_SERVER['REMOTE_ADDR'] ) ) { |
|
| 38 | - return sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ); |
|
| 37 | + if (isset($_SERVER['REMOTE_ADDR'])) { |
|
| 38 | + return sanitize_text_field(wp_unslash($_SERVER['REMOTE_ADDR'])); |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | return ''; |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | function wpinv_get_user_agent() { |
| 45 | - if ( ! empty( $_SERVER['HTTP_USER_AGENT'] ) ) { |
|
| 46 | - $user_agent = sanitize_text_field( $_SERVER['HTTP_USER_AGENT'] ); |
|
| 45 | + if (!empty($_SERVER['HTTP_USER_AGENT'])) { |
|
| 46 | + $user_agent = sanitize_text_field($_SERVER['HTTP_USER_AGENT']); |
|
| 47 | 47 | } else { |
| 48 | 48 | $user_agent = ''; |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | - return apply_filters( 'wpinv_get_user_agent', $user_agent ); |
|
| 51 | + return apply_filters('wpinv_get_user_agent', $user_agent); |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | /** |
@@ -57,16 +57,16 @@ discard block |
||
| 57 | 57 | * @param string $amount The amount to sanitize. |
| 58 | 58 | * @return float |
| 59 | 59 | */ |
| 60 | -function getpaid_standardize_amount( $amount ) { |
|
| 60 | +function getpaid_standardize_amount($amount) { |
|
| 61 | 61 | |
| 62 | - $amount = str_replace( wpinv_thousands_separator(), '', $amount ); |
|
| 63 | - $amount = str_replace( wpinv_decimal_separator(), '.', $amount ); |
|
| 64 | - if ( is_numeric( $amount ) ) { |
|
| 65 | - return floatval( $amount ); |
|
| 62 | + $amount = str_replace(wpinv_thousands_separator(), '', $amount); |
|
| 63 | + $amount = str_replace(wpinv_decimal_separator(), '.', $amount); |
|
| 64 | + if (is_numeric($amount)) { |
|
| 65 | + return floatval($amount); |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | // Cast the remaining to a float. |
| 69 | - return wpinv_round_amount( preg_replace( '/[^0-9\.\-]/', '', $amount ) ); |
|
| 69 | + return wpinv_round_amount(preg_replace('/[^0-9\.\-]/', '', $amount)); |
|
| 70 | 70 | |
| 71 | 71 | } |
| 72 | 72 | |
@@ -75,8 +75,8 @@ discard block |
||
| 75 | 75 | * |
| 76 | 76 | * @param string $amount The amount to sanitize. |
| 77 | 77 | */ |
| 78 | -function getpaid_unstandardize_amount( $amount ) { |
|
| 79 | - return str_replace( '.', wpinv_decimal_separator(), $amount ); |
|
| 78 | +function getpaid_unstandardize_amount($amount) { |
|
| 79 | + return str_replace('.', wpinv_decimal_separator(), $amount); |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | /** |
@@ -84,23 +84,23 @@ discard block |
||
| 84 | 84 | * |
| 85 | 85 | * @param string $amount The amount to sanitize. |
| 86 | 86 | */ |
| 87 | -function wpinv_sanitize_amount( $amount ) { |
|
| 87 | +function wpinv_sanitize_amount($amount) { |
|
| 88 | 88 | |
| 89 | - if ( is_numeric( $amount ) ) { |
|
| 90 | - return floatval( $amount ); |
|
| 89 | + if (is_numeric($amount)) { |
|
| 90 | + return floatval($amount); |
|
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | // Separate the decimals and thousands. |
| 94 | - $amount = explode( wpinv_decimal_separator(), $amount ); |
|
| 94 | + $amount = explode(wpinv_decimal_separator(), $amount); |
|
| 95 | 95 | |
| 96 | 96 | // Remove thousands. |
| 97 | - $amount[0] = str_replace( wpinv_thousands_separator(), '', $amount[0] ); |
|
| 97 | + $amount[0] = str_replace(wpinv_thousands_separator(), '', $amount[0]); |
|
| 98 | 98 | |
| 99 | 99 | // Convert back to string. |
| 100 | - $amount = count( $amount ) > 1 ? "{$amount[0]}.{$amount[1]}" : $amount[0]; |
|
| 100 | + $amount = count($amount) > 1 ? "{$amount[0]}.{$amount[1]}" : $amount[0]; |
|
| 101 | 101 | |
| 102 | 102 | // Cast the remaining to a float. |
| 103 | - return (float) preg_replace( '/[^0-9\.\-]/', '', $amount ); |
|
| 103 | + return (float) preg_replace('/[^0-9\.\-]/', '', $amount); |
|
| 104 | 104 | |
| 105 | 105 | } |
| 106 | 106 | |
@@ -110,19 +110,19 @@ discard block |
||
| 110 | 110 | * @param float $amount |
| 111 | 111 | * @param float|string|int|null $decimals |
| 112 | 112 | */ |
| 113 | -function wpinv_round_amount( $amount, $decimals = null, $use_sprintf = false ) { |
|
| 113 | +function wpinv_round_amount($amount, $decimals = null, $use_sprintf = false) { |
|
| 114 | 114 | |
| 115 | - if ( $decimals === null ) { |
|
| 115 | + if ($decimals === null) { |
|
| 116 | 116 | $decimals = wpinv_decimals(); |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | - if ( $use_sprintf ) { |
|
| 120 | - $amount = sprintf( "%.{$decimals}f", (float) $amount ); |
|
| 119 | + if ($use_sprintf) { |
|
| 120 | + $amount = sprintf("%.{$decimals}f", (float) $amount); |
|
| 121 | 121 | } else { |
| 122 | - $amount = round( (float) $amount, absint( $decimals ) ); |
|
| 122 | + $amount = round((float) $amount, absint($decimals)); |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | - return apply_filters( 'wpinv_round_amount', $amount, $decimals ); |
|
| 125 | + return apply_filters('wpinv_round_amount', $amount, $decimals); |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | /** |
@@ -134,32 +134,32 @@ discard block |
||
| 134 | 134 | * @param string|WPInv_Invoice $invoice The invoice object|post type|type |
| 135 | 135 | * @return array |
| 136 | 136 | */ |
| 137 | -function wpinv_get_invoice_statuses( $draft = false, $trashed = false, $invoice = false ) { |
|
| 137 | +function wpinv_get_invoice_statuses($draft = false, $trashed = false, $invoice = false) { |
|
| 138 | 138 | |
| 139 | 139 | $invoice_statuses = array( |
| 140 | - 'wpi-pending' => _x( 'Pending payment', 'Invoice status', 'invoicing' ), |
|
| 141 | - 'publish' => _x( 'Paid', 'Invoice status', 'invoicing' ), |
|
| 142 | - 'wpi-processing' => _x( 'Processing', 'Invoice status', 'invoicing' ), |
|
| 143 | - 'wpi-onhold' => _x( 'On hold', 'Invoice status', 'invoicing' ), |
|
| 144 | - 'wpi-cancelled' => _x( 'Cancelled', 'Invoice status', 'invoicing' ), |
|
| 145 | - 'wpi-refunded' => _x( 'Refunded', 'Invoice status', 'invoicing' ), |
|
| 146 | - 'wpi-failed' => _x( 'Failed', 'Invoice status', 'invoicing' ), |
|
| 147 | - 'wpi-renewal' => _x( 'Renewal Payment', 'Invoice status', 'invoicing' ), |
|
| 140 | + 'wpi-pending' => _x('Pending payment', 'Invoice status', 'invoicing'), |
|
| 141 | + 'publish' => _x('Paid', 'Invoice status', 'invoicing'), |
|
| 142 | + 'wpi-processing' => _x('Processing', 'Invoice status', 'invoicing'), |
|
| 143 | + 'wpi-onhold' => _x('On hold', 'Invoice status', 'invoicing'), |
|
| 144 | + 'wpi-cancelled' => _x('Cancelled', 'Invoice status', 'invoicing'), |
|
| 145 | + 'wpi-refunded' => _x('Refunded', 'Invoice status', 'invoicing'), |
|
| 146 | + 'wpi-failed' => _x('Failed', 'Invoice status', 'invoicing'), |
|
| 147 | + 'wpi-renewal' => _x('Renewal Payment', 'Invoice status', 'invoicing'), |
|
| 148 | 148 | ); |
| 149 | 149 | |
| 150 | - if ( $draft ) { |
|
| 151 | - $invoice_statuses['draft'] = __( 'Draft', 'invoicing' ); |
|
| 150 | + if ($draft) { |
|
| 151 | + $invoice_statuses['draft'] = __('Draft', 'invoicing'); |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | - if ( $trashed ) { |
|
| 155 | - $invoice_statuses['trash'] = __( 'Trash', 'invoicing' ); |
|
| 154 | + if ($trashed) { |
|
| 155 | + $invoice_statuses['trash'] = __('Trash', 'invoicing'); |
|
| 156 | 156 | } |
| 157 | 157 | |
| 158 | - if ( $invoice instanceof WPInv_Invoice ) { |
|
| 158 | + if ($invoice instanceof WPInv_Invoice) { |
|
| 159 | 159 | $invoice = $invoice->get_post_type(); |
| 160 | 160 | } |
| 161 | 161 | |
| 162 | - return apply_filters( 'wpinv_statuses', $invoice_statuses, $invoice ); |
|
| 162 | + return apply_filters('wpinv_statuses', $invoice_statuses, $invoice); |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | /** |
@@ -168,11 +168,11 @@ discard block |
||
| 168 | 168 | * @param string $status The raw status |
| 169 | 169 | * @param string|WPInv_Invoice $invoice The invoice object|post type|type |
| 170 | 170 | */ |
| 171 | -function wpinv_status_nicename( $status, $invoice = false ) { |
|
| 172 | - $statuses = wpinv_get_invoice_statuses( true, true, $invoice ); |
|
| 173 | - $status = isset( $statuses[ $status ] ) ? $statuses[ $status ] : $status; |
|
| 171 | +function wpinv_status_nicename($status, $invoice = false) { |
|
| 172 | + $statuses = wpinv_get_invoice_statuses(true, true, $invoice); |
|
| 173 | + $status = isset($statuses[$status]) ? $statuses[$status] : $status; |
|
| 174 | 174 | |
| 175 | - return sanitize_text_field( $status ); |
|
| 175 | + return sanitize_text_field($status); |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | /** |
@@ -180,13 +180,13 @@ discard block |
||
| 180 | 180 | * |
| 181 | 181 | * @param string $current |
| 182 | 182 | */ |
| 183 | -function wpinv_get_currency( $current = '' ) { |
|
| 183 | +function wpinv_get_currency($current = '') { |
|
| 184 | 184 | |
| 185 | - if ( empty( $current ) ) { |
|
| 186 | - $current = apply_filters( 'wpinv_currency', wpinv_get_option( 'currency', 'USD' ) ); |
|
| 185 | + if (empty($current)) { |
|
| 186 | + $current = apply_filters('wpinv_currency', wpinv_get_option('currency', 'USD')); |
|
| 187 | 187 | } |
| 188 | 188 | |
| 189 | - return trim( strtoupper( $current ) ); |
|
| 189 | + return trim(strtoupper($current)); |
|
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 192 | /** |
@@ -194,25 +194,25 @@ discard block |
||
| 194 | 194 | * |
| 195 | 195 | * @param string|null $currency The currency code. Defaults to the default currency. |
| 196 | 196 | */ |
| 197 | -function wpinv_currency_symbol( $currency = null ) { |
|
| 197 | +function wpinv_currency_symbol($currency = null) { |
|
| 198 | 198 | |
| 199 | 199 | // Prepare the currency. |
| 200 | - $currency = empty( $currency ) ? wpinv_get_currency() : wpinv_clean( $currency ); |
|
| 200 | + $currency = empty($currency) ? wpinv_get_currency() : wpinv_clean($currency); |
|
| 201 | 201 | |
| 202 | 202 | // Fetch all symbols. |
| 203 | 203 | $symbols = wpinv_get_currency_symbols(); |
| 204 | 204 | |
| 205 | 205 | // Fetch this currencies symbol. |
| 206 | - $currency_symbol = isset( $symbols[ $currency ] ) ? $symbols[ $currency ] : $currency; |
|
| 206 | + $currency_symbol = isset($symbols[$currency]) ? $symbols[$currency] : $currency; |
|
| 207 | 207 | |
| 208 | 208 | // Filter the symbol. |
| 209 | - return apply_filters( 'wpinv_currency_symbol', $currency_symbol, $currency ); |
|
| 209 | + return apply_filters('wpinv_currency_symbol', $currency_symbol, $currency); |
|
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | function wpinv_currency_position() { |
| 213 | - $position = wpinv_get_option( 'currency_position', 'left' ); |
|
| 213 | + $position = wpinv_get_option('currency_position', 'left'); |
|
| 214 | 214 | |
| 215 | - return apply_filters( 'wpinv_currency_position', $position ); |
|
| 215 | + return apply_filters('wpinv_currency_position', $position); |
|
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | /** |
@@ -220,13 +220,13 @@ discard block |
||
| 220 | 220 | * |
| 221 | 221 | * @param $string|null $current |
| 222 | 222 | */ |
| 223 | -function wpinv_thousands_separator( $current = null ) { |
|
| 223 | +function wpinv_thousands_separator($current = null) { |
|
| 224 | 224 | |
| 225 | - if ( null == $current ) { |
|
| 226 | - $current = wpinv_get_option( 'thousands_separator', ',' ); |
|
| 225 | + if (null == $current) { |
|
| 226 | + $current = wpinv_get_option('thousands_separator', ','); |
|
| 227 | 227 | } |
| 228 | 228 | |
| 229 | - return trim( $current ); |
|
| 229 | + return trim($current); |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | /** |
@@ -234,13 +234,13 @@ discard block |
||
| 234 | 234 | * |
| 235 | 235 | * @param $string|null $current |
| 236 | 236 | */ |
| 237 | -function wpinv_decimal_separator( $current = null ) { |
|
| 237 | +function wpinv_decimal_separator($current = null) { |
|
| 238 | 238 | |
| 239 | - if ( null == $current ) { |
|
| 240 | - $current = wpinv_get_option( 'decimal_separator', '.' ); |
|
| 239 | + if (null == $current) { |
|
| 240 | + $current = wpinv_get_option('decimal_separator', '.'); |
|
| 241 | 241 | } |
| 242 | 242 | |
| 243 | - return trim( $current ); |
|
| 243 | + return trim($current); |
|
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | /** |
@@ -248,27 +248,27 @@ discard block |
||
| 248 | 248 | * |
| 249 | 249 | * @param $string|null $current |
| 250 | 250 | */ |
| 251 | -function wpinv_decimals( $current = null ) { |
|
| 251 | +function wpinv_decimals($current = null) { |
|
| 252 | 252 | |
| 253 | - if ( null == $current ) { |
|
| 254 | - $current = wpinv_get_option( 'decimals', 2 ); |
|
| 253 | + if (null == $current) { |
|
| 254 | + $current = wpinv_get_option('decimals', 2); |
|
| 255 | 255 | } |
| 256 | 256 | |
| 257 | - return absint( $current ); |
|
| 257 | + return absint($current); |
|
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | /** |
| 261 | 261 | * Retrieves a list of all supported currencies. |
| 262 | 262 | */ |
| 263 | 263 | function wpinv_get_currencies() { |
| 264 | - return apply_filters( 'wpinv_currencies', wpinv_get_data( 'currencies' ) ); |
|
| 264 | + return apply_filters('wpinv_currencies', wpinv_get_data('currencies')); |
|
| 265 | 265 | } |
| 266 | 266 | |
| 267 | 267 | /** |
| 268 | 268 | * Retrieves a list of all currency symbols. |
| 269 | 269 | */ |
| 270 | 270 | function wpinv_get_currency_symbols() { |
| 271 | - return apply_filters( 'wpinv_currency_symbols', wpinv_get_data( 'currency-symbols' ) ); |
|
| 271 | + return apply_filters('wpinv_currency_symbols', wpinv_get_data('currency-symbols')); |
|
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | /** |
@@ -280,7 +280,7 @@ discard block |
||
| 280 | 280 | $currency_pos = wpinv_currency_position(); |
| 281 | 281 | $format = '%1$s%2$s'; |
| 282 | 282 | |
| 283 | - switch ( $currency_pos ) { |
|
| 283 | + switch ($currency_pos) { |
|
| 284 | 284 | case 'left': |
| 285 | 285 | $format = '%1$s%2$s'; |
| 286 | 286 | break; |
@@ -295,7 +295,7 @@ discard block |
||
| 295 | 295 | break; |
| 296 | 296 | } |
| 297 | 297 | |
| 298 | - return apply_filters( 'getpaid_price_format', $format, $currency_pos ); |
|
| 298 | + return apply_filters('getpaid_price_format', $format, $currency_pos); |
|
| 299 | 299 | } |
| 300 | 300 | |
| 301 | 301 | /** |
@@ -305,8 +305,8 @@ discard block |
||
| 305 | 305 | * @param string $currency Currency. |
| 306 | 306 | * @return string |
| 307 | 307 | */ |
| 308 | -function wpinv_the_price( $amount = 0, $currency = '' ) { |
|
| 309 | - echo wp_kses_post( wpinv_price( $amount, $currency ) ); |
|
| 308 | +function wpinv_the_price($amount = 0, $currency = '') { |
|
| 309 | + echo wp_kses_post(wpinv_price($amount, $currency)); |
|
| 310 | 310 | } |
| 311 | 311 | |
| 312 | 312 | /** |
@@ -316,25 +316,25 @@ discard block |
||
| 316 | 316 | * @param string $currency Currency. |
| 317 | 317 | * @return string |
| 318 | 318 | */ |
| 319 | -function wpinv_price( $amount = 0, $currency = '' ) { |
|
| 319 | +function wpinv_price($amount = 0, $currency = '') { |
|
| 320 | 320 | |
| 321 | 321 | // Backwards compatibility. |
| 322 | - $amount = wpinv_sanitize_amount( $amount ); |
|
| 322 | + $amount = wpinv_sanitize_amount($amount); |
|
| 323 | 323 | |
| 324 | 324 | // Prepare variables. |
| 325 | - $currency = wpinv_get_currency( $currency ); |
|
| 325 | + $currency = wpinv_get_currency($currency); |
|
| 326 | 326 | $amount = (float) $amount; |
| 327 | 327 | $unformatted_amount = $amount; |
| 328 | 328 | $negative = $amount < 0; |
| 329 | - $amount = apply_filters( 'getpaid_raw_amount', floatval( $negative ? $amount * -1 : $amount ) ); |
|
| 330 | - $amount = wpinv_format_amount( $amount ); |
|
| 329 | + $amount = apply_filters('getpaid_raw_amount', floatval($negative ? $amount * -1 : $amount)); |
|
| 330 | + $amount = wpinv_format_amount($amount); |
|
| 331 | 331 | |
| 332 | 332 | // Format the amount. |
| 333 | 333 | $format = getpaid_get_price_format(); |
| 334 | - $formatted_amount = ( $negative ? '-' : '' ) . sprintf( $format, '<span class="getpaid-currency__symbol">' . wpinv_currency_symbol( $currency ) . '</span>', $amount ); |
|
| 334 | + $formatted_amount = ($negative ? '-' : '') . sprintf($format, '<span class="getpaid-currency__symbol">' . wpinv_currency_symbol($currency) . '</span>', $amount); |
|
| 335 | 335 | |
| 336 | 336 | // Filter the formatting. |
| 337 | - return apply_filters( 'wpinv_price', $formatted_amount, $amount, $currency, $unformatted_amount ); |
|
| 337 | + return apply_filters('wpinv_price', $formatted_amount, $amount, $currency, $unformatted_amount); |
|
| 338 | 338 | } |
| 339 | 339 | |
| 340 | 340 | /** |
@@ -345,25 +345,25 @@ discard block |
||
| 345 | 345 | * @param bool $calculate Whether or not to apply separators. |
| 346 | 346 | * @return string |
| 347 | 347 | */ |
| 348 | -function wpinv_format_amount( $amount, $decimals = null, $calculate = false ) { |
|
| 348 | +function wpinv_format_amount($amount, $decimals = null, $calculate = false) { |
|
| 349 | 349 | $thousands_sep = wpinv_thousands_separator(); |
| 350 | 350 | $decimal_sep = wpinv_decimal_separator(); |
| 351 | - $decimals = wpinv_decimals( $decimals ); |
|
| 352 | - $amount = wpinv_sanitize_amount( $amount ); |
|
| 351 | + $decimals = wpinv_decimals($decimals); |
|
| 352 | + $amount = wpinv_sanitize_amount($amount); |
|
| 353 | 353 | |
| 354 | - if ( $calculate ) { |
|
| 354 | + if ($calculate) { |
|
| 355 | 355 | return $amount; |
| 356 | 356 | } |
| 357 | 357 | |
| 358 | 358 | // Fomart the amount. |
| 359 | - return number_format( $amount, $decimals, $decimal_sep, $thousands_sep ); |
|
| 359 | + return number_format($amount, $decimals, $decimal_sep, $thousands_sep); |
|
| 360 | 360 | } |
| 361 | 361 | |
| 362 | -function wpinv_sanitize_key( $key ) { |
|
| 362 | +function wpinv_sanitize_key($key) { |
|
| 363 | 363 | $raw_key = $key; |
| 364 | - $key = preg_replace( '/[^a-zA-Z0-9_\-\.\:\/]/', '', $key ); |
|
| 364 | + $key = preg_replace('/[^a-zA-Z0-9_\-\.\:\/]/', '', $key); |
|
| 365 | 365 | |
| 366 | - return apply_filters( 'wpinv_sanitize_key', $key, $raw_key ); |
|
| 366 | + return apply_filters('wpinv_sanitize_key', $key, $raw_key); |
|
| 367 | 367 | } |
| 368 | 368 | |
| 369 | 369 | /** |
@@ -371,8 +371,8 @@ discard block |
||
| 371 | 371 | * |
| 372 | 372 | * @param $str the file whose extension should be retrieved. |
| 373 | 373 | */ |
| 374 | -function wpinv_get_file_extension( $str ) { |
|
| 375 | - $filetype = wp_check_filetype( $str ); |
|
| 374 | +function wpinv_get_file_extension($str) { |
|
| 375 | + $filetype = wp_check_filetype($str); |
|
| 376 | 376 | return $filetype['ext']; |
| 377 | 377 | } |
| 378 | 378 | |
@@ -381,16 +381,16 @@ discard block |
||
| 381 | 381 | * |
| 382 | 382 | * @param string $string |
| 383 | 383 | */ |
| 384 | -function wpinv_string_is_image_url( $string ) { |
|
| 385 | - $extension = strtolower( wpinv_get_file_extension( $string ) ); |
|
| 386 | - return in_array( $extension, array( 'jpeg', 'jpg', 'png', 'gif', 'ico' ), true ); |
|
| 384 | +function wpinv_string_is_image_url($string) { |
|
| 385 | + $extension = strtolower(wpinv_get_file_extension($string)); |
|
| 386 | + return in_array($extension, array('jpeg', 'jpg', 'png', 'gif', 'ico'), true); |
|
| 387 | 387 | } |
| 388 | 388 | |
| 389 | 389 | /** |
| 390 | 390 | * Returns the current URL. |
| 391 | 391 | */ |
| 392 | 392 | function wpinv_get_current_page_url() { |
| 393 | - return esc_url( add_query_arg( array() ) ); |
|
| 393 | + return esc_url(add_query_arg(array())); |
|
| 394 | 394 | } |
| 395 | 395 | |
| 396 | 396 | /** |
@@ -400,46 +400,46 @@ discard block |
||
| 400 | 400 | * @param string $name Constant name. |
| 401 | 401 | * @param mixed $value Value. |
| 402 | 402 | */ |
| 403 | -function getpaid_maybe_define_constant( $name, $value ) { |
|
| 404 | - if ( ! defined( $name ) ) { |
|
| 405 | - define( $name, $value ); |
|
| 403 | +function getpaid_maybe_define_constant($name, $value) { |
|
| 404 | + if (!defined($name)) { |
|
| 405 | + define($name, $value); |
|
| 406 | 406 | } |
| 407 | 407 | } |
| 408 | 408 | |
| 409 | 409 | function wpinv_get_php_arg_separator_output() { |
| 410 | - return ini_get( 'arg_separator.output' ); |
|
| 410 | + return ini_get('arg_separator.output'); |
|
| 411 | 411 | } |
| 412 | 412 | |
| 413 | -function wpinv_rgb_from_hex( $color ) { |
|
| 414 | - $color = str_replace( '#', '', $color ); |
|
| 413 | +function wpinv_rgb_from_hex($color) { |
|
| 414 | + $color = str_replace('#', '', $color); |
|
| 415 | 415 | |
| 416 | 416 | // Convert shorthand colors to full format, e.g. "FFF" -> "FFFFFF" |
| 417 | - $color = preg_replace( '~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color ); |
|
| 418 | - if ( empty( $color ) ) { |
|
| 417 | + $color = preg_replace('~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color); |
|
| 418 | + if (empty($color)) { |
|
| 419 | 419 | return null; |
| 420 | 420 | } |
| 421 | 421 | |
| 422 | - $color = str_split( $color ); |
|
| 422 | + $color = str_split($color); |
|
| 423 | 423 | |
| 424 | 424 | $rgb = array(); |
| 425 | - $rgb['R'] = hexdec( $color[0] . $color[1] ); |
|
| 426 | - $rgb['G'] = hexdec( $color[2] . $color[3] ); |
|
| 427 | - $rgb['B'] = hexdec( $color[4] . $color[5] ); |
|
| 425 | + $rgb['R'] = hexdec($color[0] . $color[1]); |
|
| 426 | + $rgb['G'] = hexdec($color[2] . $color[3]); |
|
| 427 | + $rgb['B'] = hexdec($color[4] . $color[5]); |
|
| 428 | 428 | |
| 429 | 429 | return $rgb; |
| 430 | 430 | } |
| 431 | 431 | |
| 432 | -function wpinv_hex_darker( $color, $factor = 30 ) { |
|
| 433 | - $base = wpinv_rgb_from_hex( $color ); |
|
| 432 | +function wpinv_hex_darker($color, $factor = 30) { |
|
| 433 | + $base = wpinv_rgb_from_hex($color); |
|
| 434 | 434 | $color = '#'; |
| 435 | 435 | |
| 436 | - foreach ( $base as $k => $v ) { |
|
| 436 | + foreach ($base as $k => $v) { |
|
| 437 | 437 | $amount = $v / 100; |
| 438 | - $amount = round( $amount * $factor ); |
|
| 438 | + $amount = round($amount * $factor); |
|
| 439 | 439 | $new_decimal = $v - $amount; |
| 440 | 440 | |
| 441 | - $new_hex_component = dechex( $new_decimal ); |
|
| 442 | - if ( strlen( $new_hex_component ) < 2 ) { |
|
| 441 | + $new_hex_component = dechex($new_decimal); |
|
| 442 | + if (strlen($new_hex_component) < 2) { |
|
| 443 | 443 | $new_hex_component = '0' . $new_hex_component; |
| 444 | 444 | } |
| 445 | 445 | $color .= $new_hex_component; |
@@ -448,18 +448,18 @@ discard block |
||
| 448 | 448 | return $color; |
| 449 | 449 | } |
| 450 | 450 | |
| 451 | -function wpinv_hex_lighter( $color, $factor = 30 ) { |
|
| 452 | - $base = wpinv_rgb_from_hex( $color ); |
|
| 451 | +function wpinv_hex_lighter($color, $factor = 30) { |
|
| 452 | + $base = wpinv_rgb_from_hex($color); |
|
| 453 | 453 | $color = '#'; |
| 454 | 454 | |
| 455 | - foreach ( $base as $k => $v ) { |
|
| 455 | + foreach ($base as $k => $v) { |
|
| 456 | 456 | $amount = 255 - $v; |
| 457 | 457 | $amount = $amount / 100; |
| 458 | - $amount = round( $amount * $factor ); |
|
| 458 | + $amount = round($amount * $factor); |
|
| 459 | 459 | $new_decimal = $v + $amount; |
| 460 | 460 | |
| 461 | - $new_hex_component = dechex( $new_decimal ); |
|
| 462 | - if ( strlen( $new_hex_component ) < 2 ) { |
|
| 461 | + $new_hex_component = dechex($new_decimal); |
|
| 462 | + if (strlen($new_hex_component) < 2) { |
|
| 463 | 463 | $new_hex_component = '0' . $new_hex_component; |
| 464 | 464 | } |
| 465 | 465 | $color .= $new_hex_component; |
@@ -468,22 +468,22 @@ discard block |
||
| 468 | 468 | return $color; |
| 469 | 469 | } |
| 470 | 470 | |
| 471 | -function wpinv_light_or_dark( $color, $dark = '#000000', $light = '#FFFFFF' ) { |
|
| 472 | - $hex = str_replace( '#', '', $color ); |
|
| 471 | +function wpinv_light_or_dark($color, $dark = '#000000', $light = '#FFFFFF') { |
|
| 472 | + $hex = str_replace('#', '', $color); |
|
| 473 | 473 | |
| 474 | - $c_r = hexdec( substr( $hex, 0, 2 ) ); |
|
| 475 | - $c_g = hexdec( substr( $hex, 2, 2 ) ); |
|
| 476 | - $c_b = hexdec( substr( $hex, 4, 2 ) ); |
|
| 474 | + $c_r = hexdec(substr($hex, 0, 2)); |
|
| 475 | + $c_g = hexdec(substr($hex, 2, 2)); |
|
| 476 | + $c_b = hexdec(substr($hex, 4, 2)); |
|
| 477 | 477 | |
| 478 | - $brightness = ( ( $c_r * 299 ) + ( $c_g * 587 ) + ( $c_b * 114 ) ) / 1000; |
|
| 478 | + $brightness = (($c_r * 299) + ($c_g * 587) + ($c_b * 114)) / 1000; |
|
| 479 | 479 | |
| 480 | 480 | return $brightness > 155 ? $dark : $light; |
| 481 | 481 | } |
| 482 | 482 | |
| 483 | -function wpinv_format_hex( $hex ) { |
|
| 484 | - $hex = trim( str_replace( '#', '', $hex ) ); |
|
| 483 | +function wpinv_format_hex($hex) { |
|
| 484 | + $hex = trim(str_replace('#', '', $hex)); |
|
| 485 | 485 | |
| 486 | - if ( strlen( $hex ) == 3 ) { |
|
| 486 | + if (strlen($hex) == 3) { |
|
| 487 | 487 | $hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2]; |
| 488 | 488 | } |
| 489 | 489 | |
@@ -503,12 +503,12 @@ discard block |
||
| 503 | 503 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
| 504 | 504 | * @return string |
| 505 | 505 | */ |
| 506 | -function wpinv_utf8_strimwidth( $str, $start, $width, $trimmaker = '', $encoding = 'UTF-8' ) { |
|
| 507 | - if ( function_exists( 'mb_strimwidth' ) ) { |
|
| 508 | - return mb_strimwidth( $str, $start, $width, $trimmaker, $encoding ); |
|
| 506 | +function wpinv_utf8_strimwidth($str, $start, $width, $trimmaker = '', $encoding = 'UTF-8') { |
|
| 507 | + if (function_exists('mb_strimwidth')) { |
|
| 508 | + return mb_strimwidth($str, $start, $width, $trimmaker, $encoding); |
|
| 509 | 509 | } |
| 510 | 510 | |
| 511 | - return wpinv_utf8_substr( $str, $start, $width, $encoding ) . $trimmaker; |
|
| 511 | + return wpinv_utf8_substr($str, $start, $width, $encoding) . $trimmaker; |
|
| 512 | 512 | } |
| 513 | 513 | |
| 514 | 514 | /** |
@@ -520,28 +520,28 @@ discard block |
||
| 520 | 520 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
| 521 | 521 | * @return int Returns the number of characters in string. |
| 522 | 522 | */ |
| 523 | -function wpinv_utf8_strlen( $str, $encoding = 'UTF-8' ) { |
|
| 524 | - if ( function_exists( 'mb_strlen' ) ) { |
|
| 525 | - return mb_strlen( $str, $encoding ); |
|
| 523 | +function wpinv_utf8_strlen($str, $encoding = 'UTF-8') { |
|
| 524 | + if (function_exists('mb_strlen')) { |
|
| 525 | + return mb_strlen($str, $encoding); |
|
| 526 | 526 | } |
| 527 | 527 | |
| 528 | - return strlen( $str ); |
|
| 528 | + return strlen($str); |
|
| 529 | 529 | } |
| 530 | 530 | |
| 531 | -function wpinv_utf8_strtolower( $str, $encoding = 'UTF-8' ) { |
|
| 532 | - if ( function_exists( 'mb_strtolower' ) ) { |
|
| 533 | - return mb_strtolower( $str, $encoding ); |
|
| 531 | +function wpinv_utf8_strtolower($str, $encoding = 'UTF-8') { |
|
| 532 | + if (function_exists('mb_strtolower')) { |
|
| 533 | + return mb_strtolower($str, $encoding); |
|
| 534 | 534 | } |
| 535 | 535 | |
| 536 | - return strtolower( $str ); |
|
| 536 | + return strtolower($str); |
|
| 537 | 537 | } |
| 538 | 538 | |
| 539 | -function wpinv_utf8_strtoupper( $str, $encoding = 'UTF-8' ) { |
|
| 540 | - if ( function_exists( 'mb_strtoupper' ) ) { |
|
| 541 | - return mb_strtoupper( $str, $encoding ); |
|
| 539 | +function wpinv_utf8_strtoupper($str, $encoding = 'UTF-8') { |
|
| 540 | + if (function_exists('mb_strtoupper')) { |
|
| 541 | + return mb_strtoupper($str, $encoding); |
|
| 542 | 542 | } |
| 543 | 543 | |
| 544 | - return strtoupper( $str ); |
|
| 544 | + return strtoupper($str); |
|
| 545 | 545 | } |
| 546 | 546 | |
| 547 | 547 | /** |
@@ -555,12 +555,12 @@ discard block |
||
| 555 | 555 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
| 556 | 556 | * @return int Returns the position of the first occurrence of search in the string. |
| 557 | 557 | */ |
| 558 | -function wpinv_utf8_strpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) { |
|
| 559 | - if ( function_exists( 'mb_strpos' ) ) { |
|
| 560 | - return mb_strpos( $str, $find, $offset, $encoding ); |
|
| 558 | +function wpinv_utf8_strpos($str, $find, $offset = 0, $encoding = 'UTF-8') { |
|
| 559 | + if (function_exists('mb_strpos')) { |
|
| 560 | + return mb_strpos($str, $find, $offset, $encoding); |
|
| 561 | 561 | } |
| 562 | 562 | |
| 563 | - return strpos( $str, $find, $offset ); |
|
| 563 | + return strpos($str, $find, $offset); |
|
| 564 | 564 | } |
| 565 | 565 | |
| 566 | 566 | /** |
@@ -574,12 +574,12 @@ discard block |
||
| 574 | 574 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
| 575 | 575 | * @return int Returns the position of the last occurrence of search. |
| 576 | 576 | */ |
| 577 | -function wpinv_utf8_strrpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) { |
|
| 578 | - if ( function_exists( 'mb_strrpos' ) ) { |
|
| 579 | - return mb_strrpos( $str, $find, $offset, $encoding ); |
|
| 577 | +function wpinv_utf8_strrpos($str, $find, $offset = 0, $encoding = 'UTF-8') { |
|
| 578 | + if (function_exists('mb_strrpos')) { |
|
| 579 | + return mb_strrpos($str, $find, $offset, $encoding); |
|
| 580 | 580 | } |
| 581 | 581 | |
| 582 | - return strrpos( $str, $find, $offset ); |
|
| 582 | + return strrpos($str, $find, $offset); |
|
| 583 | 583 | } |
| 584 | 584 | |
| 585 | 585 | /** |
@@ -594,16 +594,16 @@ discard block |
||
| 594 | 594 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
| 595 | 595 | * @return string |
| 596 | 596 | */ |
| 597 | -function wpinv_utf8_substr( $str, $start, $length = null, $encoding = 'UTF-8' ) { |
|
| 598 | - if ( function_exists( 'mb_substr' ) ) { |
|
| 599 | - if ( $length === null ) { |
|
| 600 | - return mb_substr( $str, $start, wpinv_utf8_strlen( $str, $encoding ), $encoding ); |
|
| 597 | +function wpinv_utf8_substr($str, $start, $length = null, $encoding = 'UTF-8') { |
|
| 598 | + if (function_exists('mb_substr')) { |
|
| 599 | + if ($length === null) { |
|
| 600 | + return mb_substr($str, $start, wpinv_utf8_strlen($str, $encoding), $encoding); |
|
| 601 | 601 | } else { |
| 602 | - return mb_substr( $str, $start, $length, $encoding ); |
|
| 602 | + return mb_substr($str, $start, $length, $encoding); |
|
| 603 | 603 | } |
| 604 | 604 | } |
| 605 | 605 | |
| 606 | - return substr( $str, $start, $length ); |
|
| 606 | + return substr($str, $start, $length); |
|
| 607 | 607 | } |
| 608 | 608 | |
| 609 | 609 | /** |
@@ -615,48 +615,48 @@ discard block |
||
| 615 | 615 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
| 616 | 616 | * @return string The width of string. |
| 617 | 617 | */ |
| 618 | -function wpinv_utf8_strwidth( $str, $encoding = 'UTF-8' ) { |
|
| 619 | - if ( function_exists( 'mb_strwidth' ) ) { |
|
| 620 | - return mb_strwidth( $str, $encoding ); |
|
| 618 | +function wpinv_utf8_strwidth($str, $encoding = 'UTF-8') { |
|
| 619 | + if (function_exists('mb_strwidth')) { |
|
| 620 | + return mb_strwidth($str, $encoding); |
|
| 621 | 621 | } |
| 622 | 622 | |
| 623 | - return wpinv_utf8_strlen( $str, $encoding ); |
|
| 623 | + return wpinv_utf8_strlen($str, $encoding); |
|
| 624 | 624 | } |
| 625 | 625 | |
| 626 | -function wpinv_utf8_ucfirst( $str, $lower_str_end = false, $encoding = 'UTF-8' ) { |
|
| 627 | - if ( function_exists( 'mb_strlen' ) ) { |
|
| 628 | - $first_letter = wpinv_utf8_strtoupper( wpinv_utf8_substr( $str, 0, 1, $encoding ), $encoding ); |
|
| 626 | +function wpinv_utf8_ucfirst($str, $lower_str_end = false, $encoding = 'UTF-8') { |
|
| 627 | + if (function_exists('mb_strlen')) { |
|
| 628 | + $first_letter = wpinv_utf8_strtoupper(wpinv_utf8_substr($str, 0, 1, $encoding), $encoding); |
|
| 629 | 629 | $str_end = ''; |
| 630 | 630 | |
| 631 | - if ( $lower_str_end ) { |
|
| 632 | - $str_end = wpinv_utf8_strtolower( wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding ), $encoding ); |
|
| 631 | + if ($lower_str_end) { |
|
| 632 | + $str_end = wpinv_utf8_strtolower(wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding), $encoding); |
|
| 633 | 633 | } else { |
| 634 | - $str_end = wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding ); |
|
| 634 | + $str_end = wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding); |
|
| 635 | 635 | } |
| 636 | 636 | |
| 637 | 637 | return $first_letter . $str_end; |
| 638 | 638 | } |
| 639 | 639 | |
| 640 | - return ucfirst( $str ); |
|
| 640 | + return ucfirst($str); |
|
| 641 | 641 | } |
| 642 | 642 | |
| 643 | -function wpinv_utf8_ucwords( $str, $encoding = 'UTF-8' ) { |
|
| 644 | - if ( function_exists( 'mb_convert_case' ) ) { |
|
| 645 | - return mb_convert_case( $str, MB_CASE_TITLE, $encoding ); |
|
| 643 | +function wpinv_utf8_ucwords($str, $encoding = 'UTF-8') { |
|
| 644 | + if (function_exists('mb_convert_case')) { |
|
| 645 | + return mb_convert_case($str, MB_CASE_TITLE, $encoding); |
|
| 646 | 646 | } |
| 647 | 647 | |
| 648 | - return ucwords( $str ); |
|
| 648 | + return ucwords($str); |
|
| 649 | 649 | } |
| 650 | 650 | |
| 651 | -function wpinv_period_in_days( $period, $unit ) { |
|
| 652 | - $period = absint( $period ); |
|
| 651 | +function wpinv_period_in_days($period, $unit) { |
|
| 652 | + $period = absint($period); |
|
| 653 | 653 | |
| 654 | - if ( $period > 0 ) { |
|
| 655 | - if ( in_array( strtolower( $unit ), array( 'w', 'week', 'weeks' ) ) ) { |
|
| 654 | + if ($period > 0) { |
|
| 655 | + if (in_array(strtolower($unit), array('w', 'week', 'weeks'))) { |
|
| 656 | 656 | $period = $period * 7; |
| 657 | - } elseif ( in_array( strtolower( $unit ), array( 'm', 'month', 'months' ) ) ) { |
|
| 657 | + } elseif (in_array(strtolower($unit), array('m', 'month', 'months'))) { |
|
| 658 | 658 | $period = $period * 30; |
| 659 | - } elseif ( in_array( strtolower( $unit ), array( 'y', 'year', 'years' ) ) ) { |
|
| 659 | + } elseif (in_array(strtolower($unit), array('y', 'year', 'years'))) { |
|
| 660 | 660 | $period = $period * 365; |
| 661 | 661 | } |
| 662 | 662 | } |
@@ -664,14 +664,14 @@ discard block |
||
| 664 | 664 | return $period; |
| 665 | 665 | } |
| 666 | 666 | |
| 667 | -function wpinv_cal_days_in_month( $calendar, $month, $year ) { |
|
| 668 | - if ( function_exists( 'cal_days_in_month' ) ) { |
|
| 669 | - return cal_days_in_month( $calendar, $month, $year ); |
|
| 667 | +function wpinv_cal_days_in_month($calendar, $month, $year) { |
|
| 668 | + if (function_exists('cal_days_in_month')) { |
|
| 669 | + return cal_days_in_month($calendar, $month, $year); |
|
| 670 | 670 | } |
| 671 | 671 | |
| 672 | 672 | // Fallback in case the calendar extension is not loaded in PHP |
| 673 | 673 | // Only supports Gregorian calendar |
| 674 | - return date( 't', mktime( 0, 0, 0, $month, 1, $year ) ); |
|
| 674 | + return date('t', mktime(0, 0, 0, $month, 1, $year)); |
|
| 675 | 675 | } |
| 676 | 676 | |
| 677 | 677 | /** |
@@ -682,27 +682,27 @@ discard block |
||
| 682 | 682 | * |
| 683 | 683 | * @return string |
| 684 | 684 | */ |
| 685 | -function wpi_help_tip( $tip, $allow_html = false, $is_vue = false, $echo = false ) { |
|
| 685 | +function wpi_help_tip($tip, $allow_html = false, $is_vue = false, $echo = false) { |
|
| 686 | 686 | |
| 687 | - if ( $allow_html ) { |
|
| 688 | - $tip = wpi_sanitize_tooltip( $tip ); |
|
| 687 | + if ($allow_html) { |
|
| 688 | + $tip = wpi_sanitize_tooltip($tip); |
|
| 689 | 689 | } else { |
| 690 | - $tip = strip_tags( $tip ); |
|
| 690 | + $tip = strip_tags($tip); |
|
| 691 | 691 | } |
| 692 | 692 | |
| 693 | - if ( $is_vue ) { |
|
| 693 | + if ($is_vue) { |
|
| 694 | 694 | |
| 695 | - if ( $echo ) { |
|
| 696 | - echo '<span class="dashicons dashicons-editor-help" title="' . esc_attr( $tip ) . '"></span>'; |
|
| 695 | + if ($echo) { |
|
| 696 | + echo '<span class="dashicons dashicons-editor-help" title="' . esc_attr($tip) . '"></span>'; |
|
| 697 | 697 | } else { |
| 698 | - return '<span class="dashicons dashicons-editor-help" title="' . esc_attr( $tip ) . '"></span>'; |
|
| 698 | + return '<span class="dashicons dashicons-editor-help" title="' . esc_attr($tip) . '"></span>'; |
|
| 699 | 699 | } |
| 700 | 700 | } |
| 701 | 701 | |
| 702 | - if ( $echo ) { |
|
| 703 | - echo '<span class="wpi-help-tip dashicons dashicons-editor-help" title="' . esc_attr( $tip ) . '"></span>'; |
|
| 702 | + if ($echo) { |
|
| 703 | + echo '<span class="wpi-help-tip dashicons dashicons-editor-help" title="' . esc_attr($tip) . '"></span>'; |
|
| 704 | 704 | } else { |
| 705 | - return '<span class="wpi-help-tip dashicons dashicons-editor-help" title="' . esc_attr( $tip ) . '"></span>'; |
|
| 705 | + return '<span class="wpi-help-tip dashicons dashicons-editor-help" title="' . esc_attr($tip) . '"></span>'; |
|
| 706 | 706 | } |
| 707 | 707 | } |
| 708 | 708 | |
@@ -714,9 +714,9 @@ discard block |
||
| 714 | 714 | * @param string $var |
| 715 | 715 | * @return string |
| 716 | 716 | */ |
| 717 | -function wpi_sanitize_tooltip( $var ) { |
|
| 717 | +function wpi_sanitize_tooltip($var) { |
|
| 718 | 718 | return wp_kses( |
| 719 | - html_entity_decode( $var ), |
|
| 719 | + html_entity_decode($var), |
|
| 720 | 720 | array( |
| 721 | 721 | 'br' => array(), |
| 722 | 722 | 'em' => array(), |
@@ -739,7 +739,7 @@ discard block |
||
| 739 | 739 | */ |
| 740 | 740 | function wpinv_get_screen_ids() { |
| 741 | 741 | |
| 742 | - $screen_id = sanitize_title( __( 'Invoicing', 'invoicing' ) ); |
|
| 742 | + $screen_id = sanitize_title(__('Invoicing', 'invoicing')); |
|
| 743 | 743 | |
| 744 | 744 | $screen_ids = array( |
| 745 | 745 | 'toplevel_page_' . $screen_id, |
@@ -761,7 +761,7 @@ discard block |
||
| 761 | 761 | 'gp-setup', // setup wizard |
| 762 | 762 | ); |
| 763 | 763 | |
| 764 | - return apply_filters( 'wpinv_screen_ids', $screen_ids ); |
|
| 764 | + return apply_filters('wpinv_screen_ids', $screen_ids); |
|
| 765 | 765 | } |
| 766 | 766 | |
| 767 | 767 | /** |
@@ -772,14 +772,14 @@ discard block |
||
| 772 | 772 | * @param array|string $list List of values. |
| 773 | 773 | * @return array Sanitized array of values. |
| 774 | 774 | */ |
| 775 | -function wpinv_parse_list( $list ) { |
|
| 775 | +function wpinv_parse_list($list) { |
|
| 776 | 776 | |
| 777 | - if ( empty( $list ) ) { |
|
| 777 | + if (empty($list)) { |
|
| 778 | 778 | $list = array(); |
| 779 | 779 | } |
| 780 | 780 | |
| 781 | - if ( ! is_array( $list ) ) { |
|
| 782 | - return preg_split( '/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY ); |
|
| 781 | + if (!is_array($list)) { |
|
| 782 | + return preg_split('/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY); |
|
| 783 | 783 | } |
| 784 | 784 | |
| 785 | 785 | return $list; |
@@ -793,16 +793,16 @@ discard block |
||
| 793 | 793 | * @param string $key Type of data to fetch. |
| 794 | 794 | * @return mixed Fetched data. |
| 795 | 795 | */ |
| 796 | -function wpinv_get_data( $key ) { |
|
| 796 | +function wpinv_get_data($key) { |
|
| 797 | 797 | |
| 798 | 798 | // Try fetching it from the cache. |
| 799 | - $data = wp_cache_get( "wpinv-data-$key", 'wpinv' ); |
|
| 800 | - if ( $data ) { |
|
| 799 | + $data = wp_cache_get("wpinv-data-$key", 'wpinv'); |
|
| 800 | + if ($data) { |
|
| 801 | 801 | return $data; |
| 802 | 802 | } |
| 803 | 803 | |
| 804 | - $data = apply_filters( "wpinv_get_$key", include WPINV_PLUGIN_DIR . "includes/data/$key.php" ); |
|
| 805 | - wp_cache_set( "wpinv-data-$key", $data, 'wpinv' ); |
|
| 804 | + $data = apply_filters("wpinv_get_$key", include WPINV_PLUGIN_DIR . "includes/data/$key.php"); |
|
| 805 | + wp_cache_set("wpinv-data-$key", $data, 'wpinv'); |
|
| 806 | 806 | |
| 807 | 807 | return $data; |
| 808 | 808 | } |
@@ -816,10 +816,10 @@ discard block |
||
| 816 | 816 | * @param bool $first_empty Whether or not the first item in the list should be empty |
| 817 | 817 | * @return mixed Fetched data. |
| 818 | 818 | */ |
| 819 | -function wpinv_maybe_add_empty_option( $options, $first_empty ) { |
|
| 819 | +function wpinv_maybe_add_empty_option($options, $first_empty) { |
|
| 820 | 820 | |
| 821 | - if ( ! empty( $options ) && $first_empty ) { |
|
| 822 | - return array_merge( array( '' => '' ), $options ); |
|
| 821 | + if (!empty($options) && $first_empty) { |
|
| 822 | + return array_merge(array('' => ''), $options); |
|
| 823 | 823 | } |
| 824 | 824 | return $options; |
| 825 | 825 | |
@@ -831,21 +831,21 @@ discard block |
||
| 831 | 831 | * @param mixed $var Data to sanitize. |
| 832 | 832 | * @return string|array |
| 833 | 833 | */ |
| 834 | -function wpinv_clean( $var ) { |
|
| 834 | +function wpinv_clean($var) { |
|
| 835 | 835 | |
| 836 | - if ( is_array( $var ) ) { |
|
| 837 | - return array_map( 'wpinv_clean', $var ); |
|
| 836 | + if (is_array($var)) { |
|
| 837 | + return array_map('wpinv_clean', $var); |
|
| 838 | 838 | } |
| 839 | 839 | |
| 840 | - if ( is_object( $var ) ) { |
|
| 841 | - $object_vars = get_object_vars( $var ); |
|
| 842 | - foreach ( $object_vars as $property_name => $property_value ) { |
|
| 843 | - $var->$property_name = wpinv_clean( $property_value ); |
|
| 840 | + if (is_object($var)) { |
|
| 841 | + $object_vars = get_object_vars($var); |
|
| 842 | + foreach ($object_vars as $property_name => $property_value) { |
|
| 843 | + $var->$property_name = wpinv_clean($property_value); |
|
| 844 | 844 | } |
| 845 | 845 | return $var; |
| 846 | 846 | } |
| 847 | 847 | |
| 848 | - return is_string( $var ) ? sanitize_text_field( stripslashes( $var ) ) : $var; |
|
| 848 | + return is_string($var) ? sanitize_text_field(stripslashes($var)) : $var; |
|
| 849 | 849 | } |
| 850 | 850 | |
| 851 | 851 | /** |
@@ -854,43 +854,43 @@ discard block |
||
| 854 | 854 | * @param string $str Data to convert. |
| 855 | 855 | * @return string|array |
| 856 | 856 | */ |
| 857 | -function getpaid_convert_price_string_to_options( $str ) { |
|
| 857 | +function getpaid_convert_price_string_to_options($str) { |
|
| 858 | 858 | |
| 859 | - $raw_options = array_map( 'trim', explode( ',', $str ) ); |
|
| 860 | - $options = array(); |
|
| 859 | + $raw_options = array_map('trim', explode(',', $str)); |
|
| 860 | + $options = array(); |
|
| 861 | 861 | |
| 862 | - foreach ( $raw_options as $option ) { |
|
| 862 | + foreach ($raw_options as $option) { |
|
| 863 | 863 | |
| 864 | - if ( '' == $option ) { |
|
| 864 | + if ('' == $option) { |
|
| 865 | 865 | continue; |
| 866 | 866 | } |
| 867 | 867 | |
| 868 | - $option = array_map( 'trim', explode( '|', $option ) ); |
|
| 868 | + $option = array_map('trim', explode('|', $option)); |
|
| 869 | 869 | |
| 870 | 870 | $price = null; |
| 871 | 871 | $label = null; |
| 872 | 872 | |
| 873 | - if ( isset( $option[0] ) && '' != $option[0] ) { |
|
| 874 | - $label = $option[0]; |
|
| 873 | + if (isset($option[0]) && '' != $option[0]) { |
|
| 874 | + $label = $option[0]; |
|
| 875 | 875 | } |
| 876 | 876 | |
| 877 | - if ( isset( $option[1] ) && '' != $option[1] ) { |
|
| 877 | + if (isset($option[1]) && '' != $option[1]) { |
|
| 878 | 878 | $price = $option[1]; |
| 879 | 879 | } |
| 880 | 880 | |
| 881 | - if ( ! isset( $price ) ) { |
|
| 881 | + if (!isset($price)) { |
|
| 882 | 882 | $price = $label; |
| 883 | 883 | } |
| 884 | 884 | |
| 885 | - if ( ! isset( $price ) || ! is_numeric( $price ) ) { |
|
| 885 | + if (!isset($price) || !is_numeric($price)) { |
|
| 886 | 886 | continue; |
| 887 | 887 | } |
| 888 | 888 | |
| 889 | - if ( ! isset( $label ) ) { |
|
| 889 | + if (!isset($label)) { |
|
| 890 | 890 | $label = $price; |
| 891 | 891 | } |
| 892 | 892 | |
| 893 | - $options[ "$label|$price" ] = $label; |
|
| 893 | + $options["$label|$price"] = $label; |
|
| 894 | 894 | } |
| 895 | 895 | |
| 896 | 896 | return $options; |
@@ -899,14 +899,14 @@ discard block |
||
| 899 | 899 | /** |
| 900 | 900 | * Returns the help tip. |
| 901 | 901 | */ |
| 902 | -function getpaid_get_help_tip( $tip, $additional_classes = '', $echo = false ) { |
|
| 902 | +function getpaid_get_help_tip($tip, $additional_classes = '', $echo = false) { |
|
| 903 | 903 | $classes = 'wpi-help-tip dashicons dashicons-editor-help ' . $additional_classes; |
| 904 | - $tip = esc_attr( $tip ); |
|
| 904 | + $tip = esc_attr($tip); |
|
| 905 | 905 | |
| 906 | - if ( $echo ) { |
|
| 907 | - echo '<span class="' . esc_attr( $classes ) . '" data-tip="' . esc_attr( $tip ) . '"></span>'; |
|
| 906 | + if ($echo) { |
|
| 907 | + echo '<span class="' . esc_attr($classes) . '" data-tip="' . esc_attr($tip) . '"></span>'; |
|
| 908 | 908 | } else { |
| 909 | - return '<span class="' . esc_attr( $classes ) . '" data-tip="' . esc_attr( $tip ) . '"></span>'; |
|
| 909 | + return '<span class="' . esc_attr($classes) . '" data-tip="' . esc_attr($tip) . '"></span>'; |
|
| 910 | 910 | } |
| 911 | 911 | |
| 912 | 912 | } |
@@ -914,18 +914,18 @@ discard block |
||
| 914 | 914 | /** |
| 915 | 915 | * Formats a date |
| 916 | 916 | */ |
| 917 | -function getpaid_format_date( $date, $with_time = false ) { |
|
| 917 | +function getpaid_format_date($date, $with_time = false) { |
|
| 918 | 918 | |
| 919 | - if ( empty( $date ) || $date == '0000-00-00 00:00:00' ) { |
|
| 919 | + if (empty($date) || $date == '0000-00-00 00:00:00') { |
|
| 920 | 920 | return ''; |
| 921 | 921 | } |
| 922 | 922 | |
| 923 | 923 | $format = getpaid_date_format(); |
| 924 | 924 | |
| 925 | - if ( $with_time ) { |
|
| 925 | + if ($with_time) { |
|
| 926 | 926 | $format .= ' ' . getpaid_time_format(); |
| 927 | 927 | } |
| 928 | - return date_i18n( $format, strtotime( $date ) ); |
|
| 928 | + return date_i18n($format, strtotime($date)); |
|
| 929 | 929 | |
| 930 | 930 | } |
| 931 | 931 | |
@@ -934,9 +934,9 @@ discard block |
||
| 934 | 934 | * |
| 935 | 935 | * @return string |
| 936 | 936 | */ |
| 937 | -function getpaid_format_date_value( $date, $default = '—', $with_time = false ) { |
|
| 938 | - $date = getpaid_format_date( $date, $with_time ); |
|
| 939 | - return empty( $date ) ? $default : $date; |
|
| 937 | +function getpaid_format_date_value($date, $default = '—', $with_time = false) { |
|
| 938 | + $date = getpaid_format_date($date, $with_time); |
|
| 939 | + return empty($date) ? $default : $date; |
|
| 940 | 940 | } |
| 941 | 941 | |
| 942 | 942 | /** |
@@ -945,7 +945,7 @@ discard block |
||
| 945 | 945 | * @return string |
| 946 | 946 | */ |
| 947 | 947 | function getpaid_date_format() { |
| 948 | - return apply_filters( 'getpaid_date_format', get_option( 'date_format' ) ); |
|
| 948 | + return apply_filters('getpaid_date_format', get_option('date_format')); |
|
| 949 | 949 | } |
| 950 | 950 | |
| 951 | 951 | /** |
@@ -954,7 +954,7 @@ discard block |
||
| 954 | 954 | * @return string |
| 955 | 955 | */ |
| 956 | 956 | function getpaid_time_format() { |
| 957 | - return apply_filters( 'getpaid_time_format', get_option( 'time_format' ) ); |
|
| 957 | + return apply_filters('getpaid_time_format', get_option('time_format')); |
|
| 958 | 958 | } |
| 959 | 959 | |
| 960 | 960 | /** |
@@ -964,16 +964,16 @@ discard block |
||
| 964 | 964 | * @param integer $limit Limit size in characters. |
| 965 | 965 | * @return string |
| 966 | 966 | */ |
| 967 | -function getpaid_limit_length( $string, $limit ) { |
|
| 967 | +function getpaid_limit_length($string, $limit) { |
|
| 968 | 968 | $str_limit = $limit - 3; |
| 969 | 969 | |
| 970 | - if ( function_exists( 'mb_strimwidth' ) ) { |
|
| 971 | - if ( mb_strlen( $string ) > $limit ) { |
|
| 972 | - $string = mb_strimwidth( $string, 0, $str_limit ) . '...'; |
|
| 970 | + if (function_exists('mb_strimwidth')) { |
|
| 971 | + if (mb_strlen($string) > $limit) { |
|
| 972 | + $string = mb_strimwidth($string, 0, $str_limit) . '...'; |
|
| 973 | 973 | } |
| 974 | 974 | } else { |
| 975 | - if ( strlen( $string ) > $limit ) { |
|
| 976 | - $string = substr( $string, 0, $str_limit ) . '...'; |
|
| 975 | + if (strlen($string) > $limit) { |
|
| 976 | + $string = substr($string, 0, $str_limit) . '...'; |
|
| 977 | 977 | } |
| 978 | 978 | } |
| 979 | 979 | return $string; |
@@ -987,7 +987,7 @@ discard block |
||
| 987 | 987 | * @since 1.0.19 |
| 988 | 988 | */ |
| 989 | 989 | function getpaid_api() { |
| 990 | - return getpaid()->get( 'api' ); |
|
| 990 | + return getpaid()->get('api'); |
|
| 991 | 991 | } |
| 992 | 992 | |
| 993 | 993 | /** |
@@ -997,7 +997,7 @@ discard block |
||
| 997 | 997 | * @since 1.0.19 |
| 998 | 998 | */ |
| 999 | 999 | function getpaid_post_types() { |
| 1000 | - return getpaid()->get( 'post_types' ); |
|
| 1000 | + return getpaid()->get('post_types'); |
|
| 1001 | 1001 | } |
| 1002 | 1002 | |
| 1003 | 1003 | /** |
@@ -1007,7 +1007,7 @@ discard block |
||
| 1007 | 1007 | * @since 1.0.19 |
| 1008 | 1008 | */ |
| 1009 | 1009 | function getpaid_session() { |
| 1010 | - return getpaid()->get( 'session' ); |
|
| 1010 | + return getpaid()->get('session'); |
|
| 1011 | 1011 | } |
| 1012 | 1012 | |
| 1013 | 1013 | /** |
@@ -1017,7 +1017,7 @@ discard block |
||
| 1017 | 1017 | * @since 1.0.19 |
| 1018 | 1018 | */ |
| 1019 | 1019 | function getpaid_notes() { |
| 1020 | - return getpaid()->get( 'notes' ); |
|
| 1020 | + return getpaid()->get('notes'); |
|
| 1021 | 1021 | } |
| 1022 | 1022 | |
| 1023 | 1023 | /** |
@@ -1026,7 +1026,7 @@ discard block |
||
| 1026 | 1026 | * @return GetPaid_Admin |
| 1027 | 1027 | */ |
| 1028 | 1028 | function getpaid_admin() { |
| 1029 | - return getpaid()->get( 'admin' ); |
|
| 1029 | + return getpaid()->get('admin'); |
|
| 1030 | 1030 | } |
| 1031 | 1031 | |
| 1032 | 1032 | /** |
@@ -1036,8 +1036,8 @@ discard block |
||
| 1036 | 1036 | * @param string $base the base url |
| 1037 | 1037 | * @return string |
| 1038 | 1038 | */ |
| 1039 | -function getpaid_get_authenticated_action_url( $action, $base = false ) { |
|
| 1040 | - return wp_nonce_url( add_query_arg( 'getpaid-action', $action, $base ), 'getpaid-nonce', 'getpaid-nonce' ); |
|
| 1039 | +function getpaid_get_authenticated_action_url($action, $base = false) { |
|
| 1040 | + return wp_nonce_url(add_query_arg('getpaid-action', $action, $base), 'getpaid-nonce', 'getpaid-nonce'); |
|
| 1041 | 1041 | } |
| 1042 | 1042 | |
| 1043 | 1043 | /** |
@@ -1045,11 +1045,11 @@ discard block |
||
| 1045 | 1045 | * |
| 1046 | 1046 | * @return string |
| 1047 | 1047 | */ |
| 1048 | -function getpaid_get_post_type_label( $post_type, $plural = true ) { |
|
| 1048 | +function getpaid_get_post_type_label($post_type, $plural = true) { |
|
| 1049 | 1049 | |
| 1050 | - $post_type = get_post_type_object( $post_type ); |
|
| 1050 | + $post_type = get_post_type_object($post_type); |
|
| 1051 | 1051 | |
| 1052 | - if ( ! is_object( $post_type ) ) { |
|
| 1052 | + if (!is_object($post_type)) { |
|
| 1053 | 1053 | return null; |
| 1054 | 1054 | } |
| 1055 | 1055 | |
@@ -1062,18 +1062,18 @@ discard block |
||
| 1062 | 1062 | * |
| 1063 | 1063 | * @return mixed|null |
| 1064 | 1064 | */ |
| 1065 | -function getpaid_get_array_field( $array, $key, $secondary_key = null ) { |
|
| 1065 | +function getpaid_get_array_field($array, $key, $secondary_key = null) { |
|
| 1066 | 1066 | |
| 1067 | - if ( ! is_array( $array ) ) { |
|
| 1067 | + if (!is_array($array)) { |
|
| 1068 | 1068 | return null; |
| 1069 | 1069 | } |
| 1070 | 1070 | |
| 1071 | - if ( ! empty( $secondary_key ) ) { |
|
| 1072 | - $array = isset( $array[ $secondary_key ] ) ? $array[ $secondary_key ] : array(); |
|
| 1073 | - return getpaid_get_array_field( $array, $key ); |
|
| 1071 | + if (!empty($secondary_key)) { |
|
| 1072 | + $array = isset($array[$secondary_key]) ? $array[$secondary_key] : array(); |
|
| 1073 | + return getpaid_get_array_field($array, $key); |
|
| 1074 | 1074 | } |
| 1075 | 1075 | |
| 1076 | - return isset( $array[ $key ] ) ? $array[ $key ] : null; |
|
| 1076 | + return isset($array[$key]) ? $array[$key] : null; |
|
| 1077 | 1077 | |
| 1078 | 1078 | } |
| 1079 | 1079 | |
@@ -1082,12 +1082,12 @@ discard block |
||
| 1082 | 1082 | * |
| 1083 | 1083 | * @return array |
| 1084 | 1084 | */ |
| 1085 | -function getpaid_array_merge_if_empty( $args, $defaults ) { |
|
| 1085 | +function getpaid_array_merge_if_empty($args, $defaults) { |
|
| 1086 | 1086 | |
| 1087 | - foreach ( $defaults as $key => $value ) { |
|
| 1087 | + foreach ($defaults as $key => $value) { |
|
| 1088 | 1088 | |
| 1089 | - if ( empty( $args[ $key ] ) ) { |
|
| 1090 | - $args[ $key ] = $value; |
|
| 1089 | + if (empty($args[$key])) { |
|
| 1090 | + $args[$key] = $value; |
|
| 1091 | 1091 | } |
| 1092 | 1092 | } |
| 1093 | 1093 | |
@@ -1104,12 +1104,12 @@ discard block |
||
| 1104 | 1104 | |
| 1105 | 1105 | $types = get_allowed_mime_types(); |
| 1106 | 1106 | |
| 1107 | - if ( isset( $types['htm|html'] ) ) { |
|
| 1108 | - unset( $types['htm|html'] ); |
|
| 1107 | + if (isset($types['htm|html'])) { |
|
| 1108 | + unset($types['htm|html']); |
|
| 1109 | 1109 | } |
| 1110 | 1110 | |
| 1111 | - if ( isset( $types['js'] ) ) { |
|
| 1112 | - unset( $types['js'] ); |
|
| 1111 | + if (isset($types['js'])) { |
|
| 1112 | + unset($types['js']); |
|
| 1113 | 1113 | } |
| 1114 | 1114 | |
| 1115 | 1115 | return $types; |
@@ -1117,34 +1117,34 @@ discard block |
||
| 1117 | 1117 | } |
| 1118 | 1118 | |
| 1119 | 1119 | |
| 1120 | -function getpaid_user_delete_invoice( $data ) { |
|
| 1120 | +function getpaid_user_delete_invoice($data) { |
|
| 1121 | 1121 | |
| 1122 | 1122 | // Ensure there is an invoice to delete. |
| 1123 | - if ( empty( $data['invoice_id'] ) ) { |
|
| 1123 | + if (empty($data['invoice_id'])) { |
|
| 1124 | 1124 | return; |
| 1125 | 1125 | } |
| 1126 | 1126 | |
| 1127 | - $invoice = new WPInv_Invoice( (int) $data['invoice_id'] ); |
|
| 1127 | + $invoice = new WPInv_Invoice((int) $data['invoice_id']); |
|
| 1128 | 1128 | |
| 1129 | 1129 | // Ensure that it exists and that it belongs to the current user. |
| 1130 | - if ( ! $invoice->exists() || $invoice->get_customer_id() != get_current_user_id() ) { |
|
| 1131 | - wpinv_set_error( 'invalid_invoice', __( 'You do not have permission to delete this invoice', 'invoicing' ) ); |
|
| 1130 | + if (!$invoice->exists() || $invoice->get_customer_id() != get_current_user_id()) { |
|
| 1131 | + wpinv_set_error('invalid_invoice', __('You do not have permission to delete this invoice', 'invoicing')); |
|
| 1132 | 1132 | |
| 1133 | 1133 | // Can it be deleted? |
| 1134 | - } elseif ( ! $invoice->needs_payment() ) { |
|
| 1135 | - wpinv_set_error( 'cannot_delete', __( 'This invoice cannot be deleted as it has already been paid.', 'invoicing' ) ); |
|
| 1134 | + } elseif (!$invoice->needs_payment()) { |
|
| 1135 | + wpinv_set_error('cannot_delete', __('This invoice cannot be deleted as it has already been paid.', 'invoicing')); |
|
| 1136 | 1136 | |
| 1137 | 1137 | // Delete it. |
| 1138 | 1138 | } else { |
| 1139 | 1139 | |
| 1140 | 1140 | $invoice->delete(); |
| 1141 | - wpinv_set_error( 'delete', __( 'The invoice has been deleted.', 'invoicing' ), 'info' ); |
|
| 1141 | + wpinv_set_error('delete', __('The invoice has been deleted.', 'invoicing'), 'info'); |
|
| 1142 | 1142 | } |
| 1143 | 1143 | |
| 1144 | - $redirect = remove_query_arg( array( 'getpaid-action', 'getpaid-nonce', 'invoice_id' ) ); |
|
| 1144 | + $redirect = remove_query_arg(array('getpaid-action', 'getpaid-nonce', 'invoice_id')); |
|
| 1145 | 1145 | |
| 1146 | - wp_safe_redirect( $redirect ); |
|
| 1146 | + wp_safe_redirect($redirect); |
|
| 1147 | 1147 | exit; |
| 1148 | 1148 | |
| 1149 | 1149 | } |
| 1150 | -add_action( 'getpaid_authenticated_action_delete_invoice', 'getpaid_user_delete_invoice' ); |
|
| 1150 | +add_action('getpaid_authenticated_action_delete_invoice', 'getpaid_user_delete_invoice'); |
|
@@ -13,261 +13,261 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class GetPaid_Geolocation { |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * Holds the current user's IP Address. |
|
| 18 | - * |
|
| 19 | - * @var string |
|
| 20 | - */ |
|
| 21 | - public static $current_user_ip; |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * API endpoints for looking up a user IP address. |
|
| 25 | - * |
|
| 26 | - * For example, in case a user is on localhost. |
|
| 27 | - * |
|
| 28 | - * @var array |
|
| 29 | - */ |
|
| 30 | - protected static $ip_lookup_apis = array( |
|
| 31 | - 'ipify' => 'http://api.ipify.org/', |
|
| 32 | - 'ipecho' => 'http://ipecho.net/plain', |
|
| 33 | - 'ident' => 'http://ident.me', |
|
| 34 | - 'whatismyipaddress' => 'http://bot.whatismyipaddress.com', |
|
| 35 | - ); |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * API endpoints for geolocating an IP address |
|
| 39 | - * |
|
| 40 | - * @var array |
|
| 41 | - */ |
|
| 42 | - protected static $geoip_apis = array( |
|
| 43 | - 'ip-api.com' => 'http://ip-api.com/json/%s', |
|
| 44 | - 'ipinfo.io' => 'https://ipinfo.io/%s/json', |
|
| 45 | - ); |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * Get current user IP Address. |
|
| 49 | - * |
|
| 50 | - * @return string |
|
| 51 | - */ |
|
| 52 | - public static function get_ip_address() { |
|
| 53 | - return wpinv_get_ip(); |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * Get user IP Address using an external service. |
|
| 58 | - * This can be used as a fallback for users on localhost where |
|
| 59 | - * get_ip_address() will be a local IP and non-geolocatable. |
|
| 60 | - * |
|
| 61 | - * @return string |
|
| 62 | - */ |
|
| 63 | - public static function get_external_ip_address() { |
|
| 64 | - |
|
| 65 | - $transient_name = 'external_ip_address_0.0.0.0'; |
|
| 66 | - |
|
| 67 | - if ( '' !== self::get_ip_address() ) { |
|
| 68 | - $transient_name = 'external_ip_address_' . self::get_ip_address(); |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - // Try retrieving from cache. |
|
| 72 | - $external_ip_address = get_transient( $transient_name ); |
|
| 73 | - |
|
| 74 | - if ( false === $external_ip_address ) { |
|
| 75 | - $external_ip_address = '0.0.0.0'; |
|
| 76 | - $ip_lookup_services = apply_filters( 'getpaid_geolocation_ip_lookup_apis', self::$ip_lookup_apis ); |
|
| 77 | - $ip_lookup_services_keys = array_keys( $ip_lookup_services ); |
|
| 78 | - shuffle( $ip_lookup_services_keys ); |
|
| 79 | - |
|
| 80 | - foreach ( $ip_lookup_services_keys as $service_name ) { |
|
| 81 | - $service_endpoint = $ip_lookup_services[ $service_name ]; |
|
| 82 | - $response = wp_safe_remote_get( $service_endpoint, array( 'timeout' => 2 ) ); |
|
| 83 | - |
|
| 84 | - if ( ! is_wp_error( $response ) && rest_is_ip_address( $response['body'] ) ) { |
|
| 85 | - $external_ip_address = apply_filters( 'getpaid_geolocation_ip_lookup_api_response', wpinv_clean( $response['body'] ), $service_name ); |
|
| 86 | - break; |
|
| 87 | - } |
|
| 16 | + /** |
|
| 17 | + * Holds the current user's IP Address. |
|
| 18 | + * |
|
| 19 | + * @var string |
|
| 20 | + */ |
|
| 21 | + public static $current_user_ip; |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * API endpoints for looking up a user IP address. |
|
| 25 | + * |
|
| 26 | + * For example, in case a user is on localhost. |
|
| 27 | + * |
|
| 28 | + * @var array |
|
| 29 | + */ |
|
| 30 | + protected static $ip_lookup_apis = array( |
|
| 31 | + 'ipify' => 'http://api.ipify.org/', |
|
| 32 | + 'ipecho' => 'http://ipecho.net/plain', |
|
| 33 | + 'ident' => 'http://ident.me', |
|
| 34 | + 'whatismyipaddress' => 'http://bot.whatismyipaddress.com', |
|
| 35 | + ); |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * API endpoints for geolocating an IP address |
|
| 39 | + * |
|
| 40 | + * @var array |
|
| 41 | + */ |
|
| 42 | + protected static $geoip_apis = array( |
|
| 43 | + 'ip-api.com' => 'http://ip-api.com/json/%s', |
|
| 44 | + 'ipinfo.io' => 'https://ipinfo.io/%s/json', |
|
| 45 | + ); |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * Get current user IP Address. |
|
| 49 | + * |
|
| 50 | + * @return string |
|
| 51 | + */ |
|
| 52 | + public static function get_ip_address() { |
|
| 53 | + return wpinv_get_ip(); |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * Get user IP Address using an external service. |
|
| 58 | + * This can be used as a fallback for users on localhost where |
|
| 59 | + * get_ip_address() will be a local IP and non-geolocatable. |
|
| 60 | + * |
|
| 61 | + * @return string |
|
| 62 | + */ |
|
| 63 | + public static function get_external_ip_address() { |
|
| 64 | + |
|
| 65 | + $transient_name = 'external_ip_address_0.0.0.0'; |
|
| 66 | + |
|
| 67 | + if ( '' !== self::get_ip_address() ) { |
|
| 68 | + $transient_name = 'external_ip_address_' . self::get_ip_address(); |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + // Try retrieving from cache. |
|
| 72 | + $external_ip_address = get_transient( $transient_name ); |
|
| 73 | + |
|
| 74 | + if ( false === $external_ip_address ) { |
|
| 75 | + $external_ip_address = '0.0.0.0'; |
|
| 76 | + $ip_lookup_services = apply_filters( 'getpaid_geolocation_ip_lookup_apis', self::$ip_lookup_apis ); |
|
| 77 | + $ip_lookup_services_keys = array_keys( $ip_lookup_services ); |
|
| 78 | + shuffle( $ip_lookup_services_keys ); |
|
| 79 | + |
|
| 80 | + foreach ( $ip_lookup_services_keys as $service_name ) { |
|
| 81 | + $service_endpoint = $ip_lookup_services[ $service_name ]; |
|
| 82 | + $response = wp_safe_remote_get( $service_endpoint, array( 'timeout' => 2 ) ); |
|
| 83 | + |
|
| 84 | + if ( ! is_wp_error( $response ) && rest_is_ip_address( $response['body'] ) ) { |
|
| 85 | + $external_ip_address = apply_filters( 'getpaid_geolocation_ip_lookup_api_response', wpinv_clean( $response['body'] ), $service_name ); |
|
| 86 | + break; |
|
| 87 | + } |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | - set_transient( $transient_name, $external_ip_address, WEEK_IN_SECONDS ); |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - return $external_ip_address; |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * Geolocate an IP address. |
|
| 98 | - * |
|
| 99 | - * @param string $ip_address IP Address. |
|
| 100 | - * @param bool $fallback If true, fallbacks to alternative IP detection (can be slower). |
|
| 101 | - * @param bool $api_fallback If true, uses geolocation APIs if the database file doesn't exist (can be slower). |
|
| 102 | - * @return array |
|
| 103 | - */ |
|
| 104 | - public static function geolocate_ip( $ip_address = '', $fallback = false, $api_fallback = true ) { |
|
| 105 | - |
|
| 106 | - if ( empty( $ip_address ) ) { |
|
| 107 | - $ip_address = self::get_ip_address(); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - // Update the current user's IP Address. |
|
| 111 | - self::$current_user_ip = $ip_address; |
|
| 112 | - |
|
| 113 | - // Filter to allow custom geolocation of the IP address. |
|
| 114 | - $country_code = apply_filters( 'getpaid_geolocate_ip', false, $ip_address, $fallback, $api_fallback ); |
|
| 115 | - |
|
| 116 | - if ( false !== $country_code ) { |
|
| 117 | - |
|
| 118 | - return array( |
|
| 119 | - 'country' => $country_code, |
|
| 120 | - 'state' => '', |
|
| 121 | - 'city' => '', |
|
| 122 | - 'postcode' => '', |
|
| 123 | - ); |
|
| 124 | - |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - $country_code = self::get_country_code_from_headers(); |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * Get geolocation filter. |
|
| 131 | - * |
|
| 132 | - * @since 1.0.19 |
|
| 133 | - * @param array $geolocation Geolocation data, including country, state, city, and postcode. |
|
| 134 | - * @param string $ip_address IP Address. |
|
| 135 | - */ |
|
| 136 | - $geolocation = apply_filters( |
|
| 137 | - 'getpaid_get_geolocation', |
|
| 138 | - array( |
|
| 139 | - 'country' => $country_code, |
|
| 140 | - 'state' => '', |
|
| 141 | - 'city' => '', |
|
| 142 | - 'postcode' => '', |
|
| 143 | - ), |
|
| 144 | - $ip_address |
|
| 145 | - ); |
|
| 146 | - |
|
| 147 | - // If we still haven't found a country code, let's consider doing an API lookup. |
|
| 148 | - if ( '' === $geolocation['country'] && $api_fallback ) { |
|
| 149 | - $geolocation['country'] = self::geolocate_via_api( $ip_address ); |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - // It's possible that we're in a local environment, in which case the geolocation needs to be done from the |
|
| 153 | - // external address. |
|
| 154 | - if ( '' === $geolocation['country'] && $fallback ) { |
|
| 155 | - $external_ip_address = self::get_external_ip_address(); |
|
| 156 | - |
|
| 157 | - // Only bother with this if the external IP differs. |
|
| 158 | - if ( '0.0.0.0' !== $external_ip_address && $external_ip_address !== $ip_address ) { |
|
| 159 | - return self::geolocate_ip( $external_ip_address, false, $api_fallback ); |
|
| 160 | - } |
|
| 90 | + set_transient( $transient_name, $external_ip_address, WEEK_IN_SECONDS ); |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + return $external_ip_address; |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * Geolocate an IP address. |
|
| 98 | + * |
|
| 99 | + * @param string $ip_address IP Address. |
|
| 100 | + * @param bool $fallback If true, fallbacks to alternative IP detection (can be slower). |
|
| 101 | + * @param bool $api_fallback If true, uses geolocation APIs if the database file doesn't exist (can be slower). |
|
| 102 | + * @return array |
|
| 103 | + */ |
|
| 104 | + public static function geolocate_ip( $ip_address = '', $fallback = false, $api_fallback = true ) { |
|
| 105 | + |
|
| 106 | + if ( empty( $ip_address ) ) { |
|
| 107 | + $ip_address = self::get_ip_address(); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + // Update the current user's IP Address. |
|
| 111 | + self::$current_user_ip = $ip_address; |
|
| 112 | + |
|
| 113 | + // Filter to allow custom geolocation of the IP address. |
|
| 114 | + $country_code = apply_filters( 'getpaid_geolocate_ip', false, $ip_address, $fallback, $api_fallback ); |
|
| 115 | + |
|
| 116 | + if ( false !== $country_code ) { |
|
| 117 | + |
|
| 118 | + return array( |
|
| 119 | + 'country' => $country_code, |
|
| 120 | + 'state' => '', |
|
| 121 | + 'city' => '', |
|
| 122 | + 'postcode' => '', |
|
| 123 | + ); |
|
| 124 | + |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + $country_code = self::get_country_code_from_headers(); |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * Get geolocation filter. |
|
| 131 | + * |
|
| 132 | + * @since 1.0.19 |
|
| 133 | + * @param array $geolocation Geolocation data, including country, state, city, and postcode. |
|
| 134 | + * @param string $ip_address IP Address. |
|
| 135 | + */ |
|
| 136 | + $geolocation = apply_filters( |
|
| 137 | + 'getpaid_get_geolocation', |
|
| 138 | + array( |
|
| 139 | + 'country' => $country_code, |
|
| 140 | + 'state' => '', |
|
| 141 | + 'city' => '', |
|
| 142 | + 'postcode' => '', |
|
| 143 | + ), |
|
| 144 | + $ip_address |
|
| 145 | + ); |
|
| 146 | + |
|
| 147 | + // If we still haven't found a country code, let's consider doing an API lookup. |
|
| 148 | + if ( '' === $geolocation['country'] && $api_fallback ) { |
|
| 149 | + $geolocation['country'] = self::geolocate_via_api( $ip_address ); |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + // It's possible that we're in a local environment, in which case the geolocation needs to be done from the |
|
| 153 | + // external address. |
|
| 154 | + if ( '' === $geolocation['country'] && $fallback ) { |
|
| 155 | + $external_ip_address = self::get_external_ip_address(); |
|
| 156 | + |
|
| 157 | + // Only bother with this if the external IP differs. |
|
| 158 | + if ( '0.0.0.0' !== $external_ip_address && $external_ip_address !== $ip_address ) { |
|
| 159 | + return self::geolocate_ip( $external_ip_address, false, $api_fallback ); |
|
| 160 | + } |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | - return array( |
|
| 164 | - 'country' => $geolocation['country'], |
|
| 165 | - 'state' => $geolocation['state'], |
|
| 166 | - 'city' => $geolocation['city'], |
|
| 167 | - 'postcode' => $geolocation['postcode'], |
|
| 168 | - ); |
|
| 169 | - |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - /** |
|
| 173 | - * Fetches the country code from the request headers, if one is available. |
|
| 174 | - * |
|
| 175 | - * @since 1.0.19 |
|
| 176 | - * @return string The country code pulled from the headers, or empty string if one was not found. |
|
| 177 | - */ |
|
| 178 | - protected static function get_country_code_from_headers() { |
|
| 179 | - $country_code = ''; |
|
| 180 | - |
|
| 181 | - $headers = array( |
|
| 182 | - 'MM_COUNTRY_CODE', |
|
| 183 | - 'GEOIP_COUNTRY_CODE', |
|
| 184 | - 'HTTP_CF_IPCOUNTRY', |
|
| 185 | - 'HTTP_X_COUNTRY_CODE', |
|
| 186 | - ); |
|
| 187 | - |
|
| 188 | - foreach ( $headers as $header ) { |
|
| 189 | - if ( empty( $_SERVER[ $header ] ) ) { |
|
| 190 | - continue; |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - $country_code = strtoupper( sanitize_text_field( wp_unslash( $_SERVER[ $header ] ) ) ); |
|
| 194 | - break; |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - return $country_code; |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - /** |
|
| 201 | - * Use APIs to Geolocate the user. |
|
| 202 | - * |
|
| 203 | - * Geolocation APIs can be added through the use of the getpaid_geolocation_geoip_apis filter. |
|
| 204 | - * Provide a name=>value pair for service-slug=>endpoint. |
|
| 205 | - * |
|
| 206 | - * If APIs are defined, one will be chosen at random to fulfil the request. After completing, the result |
|
| 207 | - * will be cached in a transient. |
|
| 208 | - * |
|
| 209 | - * @param string $ip_address IP address. |
|
| 210 | - * @return string |
|
| 211 | - */ |
|
| 212 | - protected static function geolocate_via_api( $ip_address ) { |
|
| 213 | - |
|
| 214 | - // Retrieve from cache... |
|
| 215 | - $country_code = get_transient( 'geoip_' . $ip_address ); |
|
| 216 | - |
|
| 217 | - // If missing, retrieve from the API. |
|
| 218 | - if ( false === $country_code ) { |
|
| 219 | - $geoip_services = apply_filters( 'getpaid_geolocation_geoip_apis', self::$geoip_apis ); |
|
| 220 | - |
|
| 221 | - if ( empty( $geoip_services ) ) { |
|
| 222 | - return ''; |
|
| 223 | - } |
|
| 224 | - |
|
| 225 | - $geoip_services_keys = array_keys( $geoip_services ); |
|
| 226 | - |
|
| 227 | - shuffle( $geoip_services_keys ); |
|
| 228 | - |
|
| 229 | - foreach ( $geoip_services_keys as $service_name ) { |
|
| 230 | - |
|
| 231 | - $service_endpoint = $geoip_services[ $service_name ]; |
|
| 232 | - $response = wp_safe_remote_get( sprintf( $service_endpoint, $ip_address ), array( 'timeout' => 2 ) ); |
|
| 233 | - $country_code = sanitize_text_field( strtoupper( self::handle_geolocation_response( $response, $service_name ) ) ); |
|
| 234 | - |
|
| 235 | - if ( ! empty( $country_code ) ) { |
|
| 236 | - break; |
|
| 237 | - } |
|
| 163 | + return array( |
|
| 164 | + 'country' => $geolocation['country'], |
|
| 165 | + 'state' => $geolocation['state'], |
|
| 166 | + 'city' => $geolocation['city'], |
|
| 167 | + 'postcode' => $geolocation['postcode'], |
|
| 168 | + ); |
|
| 169 | + |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + /** |
|
| 173 | + * Fetches the country code from the request headers, if one is available. |
|
| 174 | + * |
|
| 175 | + * @since 1.0.19 |
|
| 176 | + * @return string The country code pulled from the headers, or empty string if one was not found. |
|
| 177 | + */ |
|
| 178 | + protected static function get_country_code_from_headers() { |
|
| 179 | + $country_code = ''; |
|
| 180 | + |
|
| 181 | + $headers = array( |
|
| 182 | + 'MM_COUNTRY_CODE', |
|
| 183 | + 'GEOIP_COUNTRY_CODE', |
|
| 184 | + 'HTTP_CF_IPCOUNTRY', |
|
| 185 | + 'HTTP_X_COUNTRY_CODE', |
|
| 186 | + ); |
|
| 187 | + |
|
| 188 | + foreach ( $headers as $header ) { |
|
| 189 | + if ( empty( $_SERVER[ $header ] ) ) { |
|
| 190 | + continue; |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + $country_code = strtoupper( sanitize_text_field( wp_unslash( $_SERVER[ $header ] ) ) ); |
|
| 194 | + break; |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + return $country_code; |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + /** |
|
| 201 | + * Use APIs to Geolocate the user. |
|
| 202 | + * |
|
| 203 | + * Geolocation APIs can be added through the use of the getpaid_geolocation_geoip_apis filter. |
|
| 204 | + * Provide a name=>value pair for service-slug=>endpoint. |
|
| 205 | + * |
|
| 206 | + * If APIs are defined, one will be chosen at random to fulfil the request. After completing, the result |
|
| 207 | + * will be cached in a transient. |
|
| 208 | + * |
|
| 209 | + * @param string $ip_address IP address. |
|
| 210 | + * @return string |
|
| 211 | + */ |
|
| 212 | + protected static function geolocate_via_api( $ip_address ) { |
|
| 213 | + |
|
| 214 | + // Retrieve from cache... |
|
| 215 | + $country_code = get_transient( 'geoip_' . $ip_address ); |
|
| 216 | + |
|
| 217 | + // If missing, retrieve from the API. |
|
| 218 | + if ( false === $country_code ) { |
|
| 219 | + $geoip_services = apply_filters( 'getpaid_geolocation_geoip_apis', self::$geoip_apis ); |
|
| 220 | + |
|
| 221 | + if ( empty( $geoip_services ) ) { |
|
| 222 | + return ''; |
|
| 223 | + } |
|
| 224 | + |
|
| 225 | + $geoip_services_keys = array_keys( $geoip_services ); |
|
| 226 | + |
|
| 227 | + shuffle( $geoip_services_keys ); |
|
| 228 | + |
|
| 229 | + foreach ( $geoip_services_keys as $service_name ) { |
|
| 230 | + |
|
| 231 | + $service_endpoint = $geoip_services[ $service_name ]; |
|
| 232 | + $response = wp_safe_remote_get( sprintf( $service_endpoint, $ip_address ), array( 'timeout' => 2 ) ); |
|
| 233 | + $country_code = sanitize_text_field( strtoupper( self::handle_geolocation_response( $response, $service_name ) ) ); |
|
| 234 | + |
|
| 235 | + if ( ! empty( $country_code ) ) { |
|
| 236 | + break; |
|
| 237 | + } |
|
| 238 | 238 | } |
| 239 | 239 | |
| 240 | - set_transient( 'geoip_' . $ip_address, $country_code, WEEK_IN_SECONDS ); |
|
| 241 | - } |
|
| 240 | + set_transient( 'geoip_' . $ip_address, $country_code, WEEK_IN_SECONDS ); |
|
| 241 | + } |
|
| 242 | 242 | |
| 243 | - return $country_code; |
|
| 244 | - } |
|
| 243 | + return $country_code; |
|
| 244 | + } |
|
| 245 | 245 | |
| 246 | - /** |
|
| 247 | - * Handles geolocation response |
|
| 248 | - * |
|
| 249 | - * @param WP_Error|String $geolocation_response |
|
| 250 | - * @param String $geolocation_service |
|
| 251 | - * @return string Country code |
|
| 252 | - */ |
|
| 253 | - protected static function handle_geolocation_response( $geolocation_response, $geolocation_service ) { |
|
| 246 | + /** |
|
| 247 | + * Handles geolocation response |
|
| 248 | + * |
|
| 249 | + * @param WP_Error|String $geolocation_response |
|
| 250 | + * @param String $geolocation_service |
|
| 251 | + * @return string Country code |
|
| 252 | + */ |
|
| 253 | + protected static function handle_geolocation_response( $geolocation_response, $geolocation_service ) { |
|
| 254 | 254 | |
| 255 | - if ( is_wp_error( $geolocation_response ) || empty( $geolocation_response['body'] ) ) { |
|
| 256 | - return ''; |
|
| 257 | - } |
|
| 255 | + if ( is_wp_error( $geolocation_response ) || empty( $geolocation_response['body'] ) ) { |
|
| 256 | + return ''; |
|
| 257 | + } |
|
| 258 | 258 | |
| 259 | - if ( $geolocation_service === 'ipinfo.io' ) { |
|
| 260 | - $data = json_decode( $geolocation_response['body'] ); |
|
| 261 | - return empty( $data ) || empty( $data->country ) ? '' : $data->country; |
|
| 262 | - } |
|
| 259 | + if ( $geolocation_service === 'ipinfo.io' ) { |
|
| 260 | + $data = json_decode( $geolocation_response['body'] ); |
|
| 261 | + return empty( $data ) || empty( $data->country ) ? '' : $data->country; |
|
| 262 | + } |
|
| 263 | 263 | |
| 264 | - if ( $geolocation_service === 'ip-api.com' ) { |
|
| 265 | - $data = json_decode( $geolocation_response['body'] ); |
|
| 266 | - return empty( $data ) || empty( $data->countryCode ) ? '' : $data->countryCode; |
|
| 267 | - } |
|
| 264 | + if ( $geolocation_service === 'ip-api.com' ) { |
|
| 265 | + $data = json_decode( $geolocation_response['body'] ); |
|
| 266 | + return empty( $data ) || empty( $data->countryCode ) ? '' : $data->countryCode; |
|
| 267 | + } |
|
| 268 | 268 | |
| 269 | - return apply_filters( 'getpaid_geolocation_geoip_response_' . $geolocation_service, '', $geolocation_response['body'] ); |
|
| 269 | + return apply_filters( 'getpaid_geolocation_geoip_response_' . $geolocation_service, '', $geolocation_response['body'] ); |
|
| 270 | 270 | |
| 271 | - } |
|
| 271 | + } |
|
| 272 | 272 | |
| 273 | 273 | } |
@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | * |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | -defined( 'ABSPATH' ) || exit; |
|
| 9 | +defined('ABSPATH') || exit; |
|
| 10 | 10 | |
| 11 | 11 | /** |
| 12 | 12 | * GetPaid_Geolocation Class. |
@@ -64,30 +64,30 @@ discard block |
||
| 64 | 64 | |
| 65 | 65 | $transient_name = 'external_ip_address_0.0.0.0'; |
| 66 | 66 | |
| 67 | - if ( '' !== self::get_ip_address() ) { |
|
| 68 | - $transient_name = 'external_ip_address_' . self::get_ip_address(); |
|
| 67 | + if ('' !== self::get_ip_address()) { |
|
| 68 | + $transient_name = 'external_ip_address_' . self::get_ip_address(); |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | // Try retrieving from cache. |
| 72 | - $external_ip_address = get_transient( $transient_name ); |
|
| 72 | + $external_ip_address = get_transient($transient_name); |
|
| 73 | 73 | |
| 74 | - if ( false === $external_ip_address ) { |
|
| 74 | + if (false === $external_ip_address) { |
|
| 75 | 75 | $external_ip_address = '0.0.0.0'; |
| 76 | - $ip_lookup_services = apply_filters( 'getpaid_geolocation_ip_lookup_apis', self::$ip_lookup_apis ); |
|
| 77 | - $ip_lookup_services_keys = array_keys( $ip_lookup_services ); |
|
| 78 | - shuffle( $ip_lookup_services_keys ); |
|
| 76 | + $ip_lookup_services = apply_filters('getpaid_geolocation_ip_lookup_apis', self::$ip_lookup_apis); |
|
| 77 | + $ip_lookup_services_keys = array_keys($ip_lookup_services); |
|
| 78 | + shuffle($ip_lookup_services_keys); |
|
| 79 | 79 | |
| 80 | - foreach ( $ip_lookup_services_keys as $service_name ) { |
|
| 81 | - $service_endpoint = $ip_lookup_services[ $service_name ]; |
|
| 82 | - $response = wp_safe_remote_get( $service_endpoint, array( 'timeout' => 2 ) ); |
|
| 80 | + foreach ($ip_lookup_services_keys as $service_name) { |
|
| 81 | + $service_endpoint = $ip_lookup_services[$service_name]; |
|
| 82 | + $response = wp_safe_remote_get($service_endpoint, array('timeout' => 2)); |
|
| 83 | 83 | |
| 84 | - if ( ! is_wp_error( $response ) && rest_is_ip_address( $response['body'] ) ) { |
|
| 85 | - $external_ip_address = apply_filters( 'getpaid_geolocation_ip_lookup_api_response', wpinv_clean( $response['body'] ), $service_name ); |
|
| 84 | + if (!is_wp_error($response) && rest_is_ip_address($response['body'])) { |
|
| 85 | + $external_ip_address = apply_filters('getpaid_geolocation_ip_lookup_api_response', wpinv_clean($response['body']), $service_name); |
|
| 86 | 86 | break; |
| 87 | 87 | } |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | - set_transient( $transient_name, $external_ip_address, WEEK_IN_SECONDS ); |
|
| 90 | + set_transient($transient_name, $external_ip_address, WEEK_IN_SECONDS); |
|
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | return $external_ip_address; |
@@ -101,9 +101,9 @@ discard block |
||
| 101 | 101 | * @param bool $api_fallback If true, uses geolocation APIs if the database file doesn't exist (can be slower). |
| 102 | 102 | * @return array |
| 103 | 103 | */ |
| 104 | - public static function geolocate_ip( $ip_address = '', $fallback = false, $api_fallback = true ) { |
|
| 104 | + public static function geolocate_ip($ip_address = '', $fallback = false, $api_fallback = true) { |
|
| 105 | 105 | |
| 106 | - if ( empty( $ip_address ) ) { |
|
| 106 | + if (empty($ip_address)) { |
|
| 107 | 107 | $ip_address = self::get_ip_address(); |
| 108 | 108 | } |
| 109 | 109 | |
@@ -111,9 +111,9 @@ discard block |
||
| 111 | 111 | self::$current_user_ip = $ip_address; |
| 112 | 112 | |
| 113 | 113 | // Filter to allow custom geolocation of the IP address. |
| 114 | - $country_code = apply_filters( 'getpaid_geolocate_ip', false, $ip_address, $fallback, $api_fallback ); |
|
| 114 | + $country_code = apply_filters('getpaid_geolocate_ip', false, $ip_address, $fallback, $api_fallback); |
|
| 115 | 115 | |
| 116 | - if ( false !== $country_code ) { |
|
| 116 | + if (false !== $country_code) { |
|
| 117 | 117 | |
| 118 | 118 | return array( |
| 119 | 119 | 'country' => $country_code, |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | * @param array $geolocation Geolocation data, including country, state, city, and postcode. |
| 134 | 134 | * @param string $ip_address IP Address. |
| 135 | 135 | */ |
| 136 | - $geolocation = apply_filters( |
|
| 136 | + $geolocation = apply_filters( |
|
| 137 | 137 | 'getpaid_get_geolocation', |
| 138 | 138 | array( |
| 139 | 139 | 'country' => $country_code, |
@@ -145,18 +145,18 @@ discard block |
||
| 145 | 145 | ); |
| 146 | 146 | |
| 147 | 147 | // If we still haven't found a country code, let's consider doing an API lookup. |
| 148 | - if ( '' === $geolocation['country'] && $api_fallback ) { |
|
| 149 | - $geolocation['country'] = self::geolocate_via_api( $ip_address ); |
|
| 148 | + if ('' === $geolocation['country'] && $api_fallback) { |
|
| 149 | + $geolocation['country'] = self::geolocate_via_api($ip_address); |
|
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | // It's possible that we're in a local environment, in which case the geolocation needs to be done from the |
| 153 | 153 | // external address. |
| 154 | - if ( '' === $geolocation['country'] && $fallback ) { |
|
| 154 | + if ('' === $geolocation['country'] && $fallback) { |
|
| 155 | 155 | $external_ip_address = self::get_external_ip_address(); |
| 156 | 156 | |
| 157 | 157 | // Only bother with this if the external IP differs. |
| 158 | - if ( '0.0.0.0' !== $external_ip_address && $external_ip_address !== $ip_address ) { |
|
| 159 | - return self::geolocate_ip( $external_ip_address, false, $api_fallback ); |
|
| 158 | + if ('0.0.0.0' !== $external_ip_address && $external_ip_address !== $ip_address) { |
|
| 159 | + return self::geolocate_ip($external_ip_address, false, $api_fallback); |
|
| 160 | 160 | } |
| 161 | 161 | } |
| 162 | 162 | |
@@ -185,12 +185,12 @@ discard block |
||
| 185 | 185 | 'HTTP_X_COUNTRY_CODE', |
| 186 | 186 | ); |
| 187 | 187 | |
| 188 | - foreach ( $headers as $header ) { |
|
| 189 | - if ( empty( $_SERVER[ $header ] ) ) { |
|
| 188 | + foreach ($headers as $header) { |
|
| 189 | + if (empty($_SERVER[$header])) { |
|
| 190 | 190 | continue; |
| 191 | 191 | } |
| 192 | 192 | |
| 193 | - $country_code = strtoupper( sanitize_text_field( wp_unslash( $_SERVER[ $header ] ) ) ); |
|
| 193 | + $country_code = strtoupper(sanitize_text_field(wp_unslash($_SERVER[$header]))); |
|
| 194 | 194 | break; |
| 195 | 195 | } |
| 196 | 196 | |
@@ -209,35 +209,35 @@ discard block |
||
| 209 | 209 | * @param string $ip_address IP address. |
| 210 | 210 | * @return string |
| 211 | 211 | */ |
| 212 | - protected static function geolocate_via_api( $ip_address ) { |
|
| 212 | + protected static function geolocate_via_api($ip_address) { |
|
| 213 | 213 | |
| 214 | 214 | // Retrieve from cache... |
| 215 | - $country_code = get_transient( 'geoip_' . $ip_address ); |
|
| 215 | + $country_code = get_transient('geoip_' . $ip_address); |
|
| 216 | 216 | |
| 217 | 217 | // If missing, retrieve from the API. |
| 218 | - if ( false === $country_code ) { |
|
| 219 | - $geoip_services = apply_filters( 'getpaid_geolocation_geoip_apis', self::$geoip_apis ); |
|
| 218 | + if (false === $country_code) { |
|
| 219 | + $geoip_services = apply_filters('getpaid_geolocation_geoip_apis', self::$geoip_apis); |
|
| 220 | 220 | |
| 221 | - if ( empty( $geoip_services ) ) { |
|
| 221 | + if (empty($geoip_services)) { |
|
| 222 | 222 | return ''; |
| 223 | 223 | } |
| 224 | 224 | |
| 225 | - $geoip_services_keys = array_keys( $geoip_services ); |
|
| 225 | + $geoip_services_keys = array_keys($geoip_services); |
|
| 226 | 226 | |
| 227 | - shuffle( $geoip_services_keys ); |
|
| 227 | + shuffle($geoip_services_keys); |
|
| 228 | 228 | |
| 229 | - foreach ( $geoip_services_keys as $service_name ) { |
|
| 229 | + foreach ($geoip_services_keys as $service_name) { |
|
| 230 | 230 | |
| 231 | - $service_endpoint = $geoip_services[ $service_name ]; |
|
| 232 | - $response = wp_safe_remote_get( sprintf( $service_endpoint, $ip_address ), array( 'timeout' => 2 ) ); |
|
| 233 | - $country_code = sanitize_text_field( strtoupper( self::handle_geolocation_response( $response, $service_name ) ) ); |
|
| 231 | + $service_endpoint = $geoip_services[$service_name]; |
|
| 232 | + $response = wp_safe_remote_get(sprintf($service_endpoint, $ip_address), array('timeout' => 2)); |
|
| 233 | + $country_code = sanitize_text_field(strtoupper(self::handle_geolocation_response($response, $service_name))); |
|
| 234 | 234 | |
| 235 | - if ( ! empty( $country_code ) ) { |
|
| 235 | + if (!empty($country_code)) { |
|
| 236 | 236 | break; |
| 237 | 237 | } |
| 238 | 238 | } |
| 239 | 239 | |
| 240 | - set_transient( 'geoip_' . $ip_address, $country_code, WEEK_IN_SECONDS ); |
|
| 240 | + set_transient('geoip_' . $ip_address, $country_code, WEEK_IN_SECONDS); |
|
| 241 | 241 | } |
| 242 | 242 | |
| 243 | 243 | return $country_code; |
@@ -250,23 +250,23 @@ discard block |
||
| 250 | 250 | * @param String $geolocation_service |
| 251 | 251 | * @return string Country code |
| 252 | 252 | */ |
| 253 | - protected static function handle_geolocation_response( $geolocation_response, $geolocation_service ) { |
|
| 253 | + protected static function handle_geolocation_response($geolocation_response, $geolocation_service) { |
|
| 254 | 254 | |
| 255 | - if ( is_wp_error( $geolocation_response ) || empty( $geolocation_response['body'] ) ) { |
|
| 255 | + if (is_wp_error($geolocation_response) || empty($geolocation_response['body'])) { |
|
| 256 | 256 | return ''; |
| 257 | 257 | } |
| 258 | 258 | |
| 259 | - if ( $geolocation_service === 'ipinfo.io' ) { |
|
| 260 | - $data = json_decode( $geolocation_response['body'] ); |
|
| 261 | - return empty( $data ) || empty( $data->country ) ? '' : $data->country; |
|
| 259 | + if ($geolocation_service === 'ipinfo.io') { |
|
| 260 | + $data = json_decode($geolocation_response['body']); |
|
| 261 | + return empty($data) || empty($data->country) ? '' : $data->country; |
|
| 262 | 262 | } |
| 263 | 263 | |
| 264 | - if ( $geolocation_service === 'ip-api.com' ) { |
|
| 265 | - $data = json_decode( $geolocation_response['body'] ); |
|
| 266 | - return empty( $data ) || empty( $data->countryCode ) ? '' : $data->countryCode; |
|
| 264 | + if ($geolocation_service === 'ip-api.com') { |
|
| 265 | + $data = json_decode($geolocation_response['body']); |
|
| 266 | + return empty($data) || empty($data->countryCode) ? '' : $data->countryCode; |
|
| 267 | 267 | } |
| 268 | 268 | |
| 269 | - return apply_filters( 'getpaid_geolocation_geoip_response_' . $geolocation_service, '', $geolocation_response['body'] ); |
|
| 269 | + return apply_filters('getpaid_geolocation_geoip_response_' . $geolocation_service, '', $geolocation_response['body']); |
|
| 270 | 270 | |
| 271 | 271 | } |
| 272 | 272 | |