@@ -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. |
@@ -16,11 +16,11 @@ discard block |
||
| 16 | 16 | * Retrieves the discounts sql. |
| 17 | 17 | * |
| 18 | 18 | */ |
| 19 | - public function get_sql( $range ) { |
|
| 19 | + public function get_sql($range) { |
|
| 20 | 20 | global $wpdb; |
| 21 | 21 | |
| 22 | 22 | $table = $wpdb->prefix . 'getpaid_invoices'; |
| 23 | - $clauses = $this->get_range_sql( $range ); |
|
| 23 | + $clauses = $this->get_range_sql($range); |
|
| 24 | 24 | |
| 25 | 25 | $sql = "SELECT |
| 26 | 26 | meta.discount_code AS discount_code, |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | ORDER BY total DESC |
| 37 | 37 | "; |
| 38 | 38 | |
| 39 | - return apply_filters( 'getpaid_discounts_graphs_get_sql', $sql, $range ); |
|
| 39 | + return apply_filters('getpaid_discounts_graphs_get_sql', $sql, $range); |
|
| 40 | 40 | |
| 41 | 41 | } |
| 42 | 42 | |
@@ -46,30 +46,30 @@ discard block |
||
| 46 | 46 | */ |
| 47 | 47 | public function prepare_stats() { |
| 48 | 48 | global $wpdb; |
| 49 | - $this->stats = $wpdb->get_results( $this->get_sql( $this->get_range() ) ); |
|
| 50 | - $this->stats = $this->normalize_stats( $this->stats ); |
|
| 49 | + $this->stats = $wpdb->get_results($this->get_sql($this->get_range())); |
|
| 50 | + $this->stats = $this->normalize_stats($this->stats); |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | /** |
| 54 | 54 | * Normalizes the report stats. |
| 55 | 55 | * |
| 56 | 56 | */ |
| 57 | - public function normalize_stats( $stats ) { |
|
| 57 | + public function normalize_stats($stats) { |
|
| 58 | 58 | $normalized = array(); |
| 59 | 59 | $others = 0; |
| 60 | 60 | $did = 0; |
| 61 | 61 | |
| 62 | - foreach ( $stats as $stat ) { |
|
| 62 | + foreach ($stats as $stat) { |
|
| 63 | 63 | |
| 64 | - if ( $did > 4 ) { |
|
| 64 | + if ($did > 4) { |
|
| 65 | 65 | |
| 66 | - $others += wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ); |
|
| 66 | + $others += wpinv_round_amount(wpinv_sanitize_amount($stat->total)); |
|
| 67 | 67 | |
| 68 | 68 | } else { |
| 69 | 69 | |
| 70 | 70 | $normalized[] = array( |
| 71 | - 'total' => wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ), |
|
| 72 | - 'discount_code' => strip_tags( $stat->discount_code ), |
|
| 71 | + 'total' => wpinv_round_amount(wpinv_sanitize_amount($stat->total)), |
|
| 72 | + 'discount_code' => strip_tags($stat->discount_code), |
|
| 73 | 73 | ); |
| 74 | 74 | |
| 75 | 75 | } |
@@ -77,11 +77,11 @@ discard block |
||
| 77 | 77 | $did++; |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | - if ( $others > 0 ) { |
|
| 80 | + if ($others > 0) { |
|
| 81 | 81 | |
| 82 | 82 | $normalized[] = array( |
| 83 | - 'total' => wpinv_round_amount( wpinv_sanitize_amount( $others ) ), |
|
| 84 | - 'discount_code' => esc_html__( 'Others', 'invoicing' ), |
|
| 83 | + 'total' => wpinv_round_amount(wpinv_sanitize_amount($others)), |
|
| 84 | + 'discount_code' => esc_html__('Others', 'invoicing'), |
|
| 85 | 85 | ); |
| 86 | 86 | |
| 87 | 87 | } |
@@ -95,10 +95,10 @@ discard block |
||
| 95 | 95 | */ |
| 96 | 96 | public function get_data() { |
| 97 | 97 | |
| 98 | - $data = wp_list_pluck( $this->stats, 'total' ); |
|
| 99 | - $colors = array( '#009688','#4caf50','#8bc34a','#00bcd4','#03a9f4','#2196f3' ); |
|
| 98 | + $data = wp_list_pluck($this->stats, 'total'); |
|
| 99 | + $colors = array('#009688', '#4caf50', '#8bc34a', '#00bcd4', '#03a9f4', '#2196f3'); |
|
| 100 | 100 | |
| 101 | - shuffle( $colors ); |
|
| 101 | + shuffle($colors); |
|
| 102 | 102 | |
| 103 | 103 | return array( |
| 104 | 104 | 'data' => $data, |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | * |
| 113 | 113 | */ |
| 114 | 114 | public function get_labels() { |
| 115 | - return wp_list_pluck( $this->stats, 'discount_code' ); |
|
| 115 | + return wp_list_pluck($this->stats, 'discount_code'); |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | /** |
@@ -133,8 +133,8 @@ discard block |
||
| 133 | 133 | { |
| 134 | 134 | type: 'doughnut', |
| 135 | 135 | data: { |
| 136 | - 'labels': <?php echo wp_json_encode( $this->get_labels() ); ?>, |
|
| 137 | - 'datasets': [ <?php echo wp_json_encode( $this->get_data() ); ?> ] |
|
| 136 | + 'labels': <?php echo wp_json_encode($this->get_labels()); ?>, |
|
| 137 | + 'datasets': [ <?php echo wp_json_encode($this->get_data()); ?> ] |
|
| 138 | 138 | }, |
| 139 | 139 | options: { |
| 140 | 140 | legend: { |
@@ -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_Items Class. |
@@ -16,12 +16,12 @@ discard block |
||
| 16 | 16 | * Retrieves the earning sql. |
| 17 | 17 | * |
| 18 | 18 | */ |
| 19 | - public function get_sql( $range ) { |
|
| 19 | + public function get_sql($range) { |
|
| 20 | 20 | global $wpdb; |
| 21 | 21 | |
| 22 | 22 | $table = $wpdb->prefix . 'getpaid_invoices'; |
| 23 | 23 | $table2 = $wpdb->prefix . 'getpaid_invoice_items'; |
| 24 | - $clauses = $this->get_range_sql( $range ); |
|
| 24 | + $clauses = $this->get_range_sql($range); |
|
| 25 | 25 | |
| 26 | 26 | $sql = "SELECT |
| 27 | 27 | item.item_name AS item_name, |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | ORDER BY total DESC |
| 39 | 39 | "; |
| 40 | 40 | |
| 41 | - return apply_filters( 'getpaid_items_graphs_get_sql', $sql, $range ); |
|
| 41 | + return apply_filters('getpaid_items_graphs_get_sql', $sql, $range); |
|
| 42 | 42 | |
| 43 | 43 | } |
| 44 | 44 | |
@@ -48,30 +48,30 @@ discard block |
||
| 48 | 48 | */ |
| 49 | 49 | public function prepare_stats() { |
| 50 | 50 | global $wpdb; |
| 51 | - $this->stats = $wpdb->get_results( $this->get_sql( $this->get_range() ) ); |
|
| 52 | - $this->stats = $this->normalize_stats( $this->stats ); |
|
| 51 | + $this->stats = $wpdb->get_results($this->get_sql($this->get_range())); |
|
| 52 | + $this->stats = $this->normalize_stats($this->stats); |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | /** |
| 56 | 56 | * Normalizes the report stats. |
| 57 | 57 | * |
| 58 | 58 | */ |
| 59 | - public function normalize_stats( $stats ) { |
|
| 59 | + public function normalize_stats($stats) { |
|
| 60 | 60 | $normalized = array(); |
| 61 | 61 | $others = 0; |
| 62 | 62 | $did = 0; |
| 63 | 63 | |
| 64 | - foreach ( $stats as $stat ) { |
|
| 64 | + foreach ($stats as $stat) { |
|
| 65 | 65 | |
| 66 | - if ( $did > 4 ) { |
|
| 66 | + if ($did > 4) { |
|
| 67 | 67 | |
| 68 | - $others += wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ); |
|
| 68 | + $others += wpinv_round_amount(wpinv_sanitize_amount($stat->total)); |
|
| 69 | 69 | |
| 70 | 70 | } else { |
| 71 | 71 | |
| 72 | 72 | $normalized[] = array( |
| 73 | - 'total' => wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ), |
|
| 74 | - 'item_name' => strip_tags( $stat->item_name ), |
|
| 73 | + 'total' => wpinv_round_amount(wpinv_sanitize_amount($stat->total)), |
|
| 74 | + 'item_name' => strip_tags($stat->item_name), |
|
| 75 | 75 | ); |
| 76 | 76 | |
| 77 | 77 | } |
@@ -79,11 +79,11 @@ discard block |
||
| 79 | 79 | $did++; |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | - if ( $others > 0 ) { |
|
| 82 | + if ($others > 0) { |
|
| 83 | 83 | |
| 84 | 84 | $normalized[] = array( |
| 85 | - 'total' => wpinv_round_amount( wpinv_sanitize_amount( $others ) ), |
|
| 86 | - 'item_name' => esc_html__( 'Others', 'invoicing' ), |
|
| 85 | + 'total' => wpinv_round_amount(wpinv_sanitize_amount($others)), |
|
| 86 | + 'item_name' => esc_html__('Others', 'invoicing'), |
|
| 87 | 87 | ); |
| 88 | 88 | |
| 89 | 89 | } |
@@ -97,10 +97,10 @@ discard block |
||
| 97 | 97 | */ |
| 98 | 98 | public function get_data() { |
| 99 | 99 | |
| 100 | - $data = wp_list_pluck( $this->stats, 'total' ); |
|
| 101 | - $colors = array( '#009688','#4caf50','#8bc34a','#00bcd4','#03a9f4','#2196f3' ); |
|
| 100 | + $data = wp_list_pluck($this->stats, 'total'); |
|
| 101 | + $colors = array('#009688', '#4caf50', '#8bc34a', '#00bcd4', '#03a9f4', '#2196f3'); |
|
| 102 | 102 | |
| 103 | - shuffle( $colors ); |
|
| 103 | + shuffle($colors); |
|
| 104 | 104 | |
| 105 | 105 | return array( |
| 106 | 106 | 'data' => $data, |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | * |
| 115 | 115 | */ |
| 116 | 116 | public function get_labels() { |
| 117 | - return wp_list_pluck( $this->stats, 'item_name' ); |
|
| 117 | + return wp_list_pluck($this->stats, 'item_name'); |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | /** |
@@ -135,8 +135,8 @@ discard block |
||
| 135 | 135 | { |
| 136 | 136 | type: 'doughnut', |
| 137 | 137 | data: { |
| 138 | - 'labels': <?php echo wp_json_encode( $this->get_labels() ); ?>, |
|
| 139 | - 'datasets': [ <?php echo wp_json_encode( $this->get_data() ); ?> ] |
|
| 138 | + 'labels': <?php echo wp_json_encode($this->get_labels()); ?>, |
|
| 139 | + 'datasets': [ <?php echo wp_json_encode($this->get_data()); ?> ] |
|
| 140 | 140 | }, |
| 141 | 141 | options: { |
| 142 | 142 | legend: { |
@@ -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 | } |
@@ -12,219 +12,219 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class GetPaid_Graph_Downloader { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * @var GetPaid_Reports_Report |
|
| 17 | - */ |
|
| 18 | - public $handler; |
|
| 19 | - |
|
| 20 | - /** |
|
| 21 | - * Class constructor. |
|
| 22 | - * |
|
| 23 | - */ |
|
| 24 | - public function __construct() { |
|
| 25 | - $this->handler = new GetPaid_Reports_Report(); |
|
| 26 | - } |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * Prepares the datastore handler. |
|
| 30 | - * |
|
| 31 | - * @return GetPaid_Reports_Report_Items|GetPaid_Reports_Report_Gateways|GetPaid_Reports_Report_Discounts |
|
| 32 | - */ |
|
| 33 | - public function prepare_handler( $graph ) { |
|
| 34 | - |
|
| 35 | - if ( empty( $this->handler->views[ $graph ] ) ) { |
|
| 36 | - wp_die( __( 'Invalid Graph', 'invoicing' ), 400 ); |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - return new $this->handler->views[ $graph ]['class'](); |
|
| 40 | - |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * Prepares the output stream. |
|
| 45 | - * |
|
| 46 | - * @return resource |
|
| 47 | - */ |
|
| 48 | - public function prepare_output() { |
|
| 49 | - |
|
| 50 | - $output = fopen( 'php://output', 'w' ); |
|
| 51 | - |
|
| 52 | - if ( false === $output ) { |
|
| 53 | - wp_die( __( 'Unsupported server', 'invoicing' ), 500 ); |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - return $output; |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * Prepares the file type. |
|
| 61 | - * |
|
| 62 | - * @return string |
|
| 63 | - */ |
|
| 64 | - public function prepare_file_type( $graph ) { |
|
| 65 | - |
|
| 66 | - $file_type = empty( $_REQUEST['file_type'] ) ? 'csv' : sanitize_text_field( $_REQUEST['file_type'] ); |
|
| 67 | - $file_name = wpinv_sanitize_key( "getpaid-$graph-" . current_time( 'Y-m-d' ) ); |
|
| 68 | - |
|
| 69 | - header( "Content-Type:application/$file_type" ); |
|
| 70 | - header( "Content-Disposition:attachment;filename=$file_name.$file_type" ); |
|
| 71 | - |
|
| 72 | - return $file_type; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * Handles the actual download. |
|
| 77 | - * |
|
| 78 | - */ |
|
| 79 | - public function download( $graph ) { |
|
| 80 | - global $wpdb; |
|
| 81 | - |
|
| 82 | - $handler = $this->prepare_handler( $graph ); |
|
| 83 | - $stream = $this->prepare_output(); |
|
| 84 | - $stats = $wpdb->get_results( $handler->get_sql( $handler->get_range() ) ); |
|
| 85 | - $headers = array( $handler->field, 'total', 'total_raw' ); |
|
| 86 | - $file_type = $this->prepare_file_type( $graph ); |
|
| 87 | - |
|
| 88 | - if ( 'csv' == $file_type ) { |
|
| 89 | - $this->download_csv( $stats, $stream, $headers ); |
|
| 90 | - } else if( 'xml' == $file_type ) { |
|
| 91 | - $this->download_xml( $stats, $stream, $headers ); |
|
| 92 | - } else { |
|
| 93 | - $this->download_json( $stats, $stream, $headers ); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - fclose( $stream ); |
|
| 97 | - exit; |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * Downloads graph as csv |
|
| 102 | - * |
|
| 103 | - * @param array $stats The stats being downloaded. |
|
| 104 | - * @param resource $stream The stream to output to. |
|
| 105 | - * @param array $headers The fields to stream. |
|
| 106 | - * @since 1.0.19 |
|
| 107 | - */ |
|
| 108 | - public function download_csv( $stats, $stream, $headers ) { |
|
| 109 | - |
|
| 110 | - // Output the csv column headers. |
|
| 111 | - fputcsv( $stream, $headers ); |
|
| 112 | - |
|
| 113 | - // Loop through |
|
| 114 | - foreach ( $stats as $stat ) { |
|
| 115 | - $row = array_values( $this->prepare_row( $stat, $headers ) ); |
|
| 116 | - $row = array_map( 'maybe_serialize', $row ); |
|
| 117 | - fputcsv( $stream, $row ); |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * Downloads graph as json |
|
| 124 | - * |
|
| 125 | - * @param array $stats The stats being downloaded. |
|
| 126 | - * @param resource $stream The stream to output to. |
|
| 127 | - * @param array $headers The fields to stream. |
|
| 128 | - * @since 1.0.19 |
|
| 129 | - */ |
|
| 130 | - public function download_json( $stats, $stream, $headers ) { |
|
| 131 | - |
|
| 132 | - $prepared = array(); |
|
| 133 | - |
|
| 134 | - // Loop through |
|
| 135 | - foreach ( $stats as $stat ) { |
|
| 136 | - $prepared[] = $this->prepare_row( $stat, $headers ); |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - fwrite( $stream, wp_json_encode( $prepared ) ); |
|
| 140 | - |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * Downloads graph as xml |
|
| 145 | - * |
|
| 146 | - * @param array $stats The stats being downloaded. |
|
| 147 | - * @param resource $stream The stream to output to. |
|
| 148 | - * @param array $headers The fields to stream. |
|
| 149 | - * @since 1.0.19 |
|
| 150 | - */ |
|
| 151 | - public function download_xml( $stats, $stream, $headers ) { |
|
| 152 | - |
|
| 153 | - $prepared = array(); |
|
| 154 | - |
|
| 155 | - // Loop through |
|
| 156 | - foreach ( $stats as $stat ) { |
|
| 157 | - $prepared[] = $this->prepare_row( $stat, $headers ); |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - $xml = new SimpleXMLElement('<?xml version="1.0"?><data></data>'); |
|
| 161 | - $this->convert_array_xml( $prepared, $xml ); |
|
| 162 | - |
|
| 163 | - fwrite( $stream, $xml->asXML() ); |
|
| 164 | - |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * Converts stats array to xml |
|
| 169 | - * |
|
| 170 | - * @access public |
|
| 171 | - * @since 1.0.19 |
|
| 172 | - */ |
|
| 173 | - public function convert_array_xml( $data, $xml ) { |
|
| 174 | - |
|
| 175 | - // Loop through |
|
| 176 | - foreach ( $data as $key => $value ) { |
|
| 177 | - |
|
| 178 | - $key = preg_replace( "/[^A-Za-z0-9_\-]/", '', $key ); |
|
| 179 | - |
|
| 180 | - if ( is_array( $value ) ) { |
|
| 181 | - |
|
| 182 | - if ( is_numeric( $key ) ){ |
|
| 183 | - $key = 'item'.$key; //dealing with <0/>..<n/> issues |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - $subnode = $xml->addChild( $key ); |
|
| 187 | - $this->convert_array_xml( $value, $subnode ); |
|
| 188 | - |
|
| 189 | - } else { |
|
| 190 | - $xml->addChild( $key, htmlspecialchars( $value ) ); |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - } |
|
| 15 | + /** |
|
| 16 | + * @var GetPaid_Reports_Report |
|
| 17 | + */ |
|
| 18 | + public $handler; |
|
| 19 | + |
|
| 20 | + /** |
|
| 21 | + * Class constructor. |
|
| 22 | + * |
|
| 23 | + */ |
|
| 24 | + public function __construct() { |
|
| 25 | + $this->handler = new GetPaid_Reports_Report(); |
|
| 26 | + } |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * Prepares the datastore handler. |
|
| 30 | + * |
|
| 31 | + * @return GetPaid_Reports_Report_Items|GetPaid_Reports_Report_Gateways|GetPaid_Reports_Report_Discounts |
|
| 32 | + */ |
|
| 33 | + public function prepare_handler( $graph ) { |
|
| 34 | + |
|
| 35 | + if ( empty( $this->handler->views[ $graph ] ) ) { |
|
| 36 | + wp_die( __( 'Invalid Graph', 'invoicing' ), 400 ); |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + return new $this->handler->views[ $graph ]['class'](); |
|
| 40 | + |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * Prepares the output stream. |
|
| 45 | + * |
|
| 46 | + * @return resource |
|
| 47 | + */ |
|
| 48 | + public function prepare_output() { |
|
| 49 | + |
|
| 50 | + $output = fopen( 'php://output', 'w' ); |
|
| 51 | + |
|
| 52 | + if ( false === $output ) { |
|
| 53 | + wp_die( __( 'Unsupported server', 'invoicing' ), 500 ); |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + return $output; |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * Prepares the file type. |
|
| 61 | + * |
|
| 62 | + * @return string |
|
| 63 | + */ |
|
| 64 | + public function prepare_file_type( $graph ) { |
|
| 65 | + |
|
| 66 | + $file_type = empty( $_REQUEST['file_type'] ) ? 'csv' : sanitize_text_field( $_REQUEST['file_type'] ); |
|
| 67 | + $file_name = wpinv_sanitize_key( "getpaid-$graph-" . current_time( 'Y-m-d' ) ); |
|
| 68 | + |
|
| 69 | + header( "Content-Type:application/$file_type" ); |
|
| 70 | + header( "Content-Disposition:attachment;filename=$file_name.$file_type" ); |
|
| 71 | + |
|
| 72 | + return $file_type; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * Handles the actual download. |
|
| 77 | + * |
|
| 78 | + */ |
|
| 79 | + public function download( $graph ) { |
|
| 80 | + global $wpdb; |
|
| 81 | + |
|
| 82 | + $handler = $this->prepare_handler( $graph ); |
|
| 83 | + $stream = $this->prepare_output(); |
|
| 84 | + $stats = $wpdb->get_results( $handler->get_sql( $handler->get_range() ) ); |
|
| 85 | + $headers = array( $handler->field, 'total', 'total_raw' ); |
|
| 86 | + $file_type = $this->prepare_file_type( $graph ); |
|
| 87 | + |
|
| 88 | + if ( 'csv' == $file_type ) { |
|
| 89 | + $this->download_csv( $stats, $stream, $headers ); |
|
| 90 | + } else if( 'xml' == $file_type ) { |
|
| 91 | + $this->download_xml( $stats, $stream, $headers ); |
|
| 92 | + } else { |
|
| 93 | + $this->download_json( $stats, $stream, $headers ); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + fclose( $stream ); |
|
| 97 | + exit; |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * Downloads graph as csv |
|
| 102 | + * |
|
| 103 | + * @param array $stats The stats being downloaded. |
|
| 104 | + * @param resource $stream The stream to output to. |
|
| 105 | + * @param array $headers The fields to stream. |
|
| 106 | + * @since 1.0.19 |
|
| 107 | + */ |
|
| 108 | + public function download_csv( $stats, $stream, $headers ) { |
|
| 109 | + |
|
| 110 | + // Output the csv column headers. |
|
| 111 | + fputcsv( $stream, $headers ); |
|
| 112 | + |
|
| 113 | + // Loop through |
|
| 114 | + foreach ( $stats as $stat ) { |
|
| 115 | + $row = array_values( $this->prepare_row( $stat, $headers ) ); |
|
| 116 | + $row = array_map( 'maybe_serialize', $row ); |
|
| 117 | + fputcsv( $stream, $row ); |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * Downloads graph as json |
|
| 124 | + * |
|
| 125 | + * @param array $stats The stats being downloaded. |
|
| 126 | + * @param resource $stream The stream to output to. |
|
| 127 | + * @param array $headers The fields to stream. |
|
| 128 | + * @since 1.0.19 |
|
| 129 | + */ |
|
| 130 | + public function download_json( $stats, $stream, $headers ) { |
|
| 131 | + |
|
| 132 | + $prepared = array(); |
|
| 133 | + |
|
| 134 | + // Loop through |
|
| 135 | + foreach ( $stats as $stat ) { |
|
| 136 | + $prepared[] = $this->prepare_row( $stat, $headers ); |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + fwrite( $stream, wp_json_encode( $prepared ) ); |
|
| 140 | + |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * Downloads graph as xml |
|
| 145 | + * |
|
| 146 | + * @param array $stats The stats being downloaded. |
|
| 147 | + * @param resource $stream The stream to output to. |
|
| 148 | + * @param array $headers The fields to stream. |
|
| 149 | + * @since 1.0.19 |
|
| 150 | + */ |
|
| 151 | + public function download_xml( $stats, $stream, $headers ) { |
|
| 152 | + |
|
| 153 | + $prepared = array(); |
|
| 154 | + |
|
| 155 | + // Loop through |
|
| 156 | + foreach ( $stats as $stat ) { |
|
| 157 | + $prepared[] = $this->prepare_row( $stat, $headers ); |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + $xml = new SimpleXMLElement('<?xml version="1.0"?><data></data>'); |
|
| 161 | + $this->convert_array_xml( $prepared, $xml ); |
|
| 162 | + |
|
| 163 | + fwrite( $stream, $xml->asXML() ); |
|
| 164 | + |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * Converts stats array to xml |
|
| 169 | + * |
|
| 170 | + * @access public |
|
| 171 | + * @since 1.0.19 |
|
| 172 | + */ |
|
| 173 | + public function convert_array_xml( $data, $xml ) { |
|
| 174 | + |
|
| 175 | + // Loop through |
|
| 176 | + foreach ( $data as $key => $value ) { |
|
| 177 | + |
|
| 178 | + $key = preg_replace( "/[^A-Za-z0-9_\-]/", '', $key ); |
|
| 179 | + |
|
| 180 | + if ( is_array( $value ) ) { |
|
| 181 | + |
|
| 182 | + if ( is_numeric( $key ) ){ |
|
| 183 | + $key = 'item'.$key; //dealing with <0/>..<n/> issues |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + $subnode = $xml->addChild( $key ); |
|
| 187 | + $this->convert_array_xml( $value, $subnode ); |
|
| 188 | + |
|
| 189 | + } else { |
|
| 190 | + $xml->addChild( $key, htmlspecialchars( $value ) ); |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + } |
|
| 194 | 194 | |
| 195 | - } |
|
| 196 | - |
|
| 197 | - /** |
|
| 198 | - * Prepares a single row for download. |
|
| 199 | - * |
|
| 200 | - * @param stdClass|array $row The row to prepare.. |
|
| 201 | - * @param array $fields The fields to stream. |
|
| 202 | - * @since 1.0.19 |
|
| 203 | - * @return array |
|
| 204 | - */ |
|
| 205 | - public function prepare_row( $row, $fields ) { |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + /** |
|
| 198 | + * Prepares a single row for download. |
|
| 199 | + * |
|
| 200 | + * @param stdClass|array $row The row to prepare.. |
|
| 201 | + * @param array $fields The fields to stream. |
|
| 202 | + * @since 1.0.19 |
|
| 203 | + * @return array |
|
| 204 | + */ |
|
| 205 | + public function prepare_row( $row, $fields ) { |
|
| 206 | 206 | |
| 207 | - $prepared = array(); |
|
| 208 | - $row = (array) $row; |
|
| 207 | + $prepared = array(); |
|
| 208 | + $row = (array) $row; |
|
| 209 | 209 | |
| 210 | - foreach ( $fields as $field ) { |
|
| 210 | + foreach ( $fields as $field ) { |
|
| 211 | 211 | |
| 212 | - if ( $field === 'total' ) { |
|
| 213 | - $prepared[ $field ] = html_entity_decode( strip_tags( wpinv_price( $row['total'] ) ), ENT_QUOTES ); |
|
| 214 | - continue; |
|
| 215 | - } |
|
| 212 | + if ( $field === 'total' ) { |
|
| 213 | + $prepared[ $field ] = html_entity_decode( strip_tags( wpinv_price( $row['total'] ) ), ENT_QUOTES ); |
|
| 214 | + continue; |
|
| 215 | + } |
|
| 216 | 216 | |
| 217 | - if ( $field === 'total_raw' ) { |
|
| 218 | - $prepared[ $field ] = wpinv_round_amount( wpinv_sanitize_amount( $row['total'] ) ); |
|
| 219 | - continue; |
|
| 220 | - } |
|
| 217 | + if ( $field === 'total_raw' ) { |
|
| 218 | + $prepared[ $field ] = wpinv_round_amount( wpinv_sanitize_amount( $row['total'] ) ); |
|
| 219 | + continue; |
|
| 220 | + } |
|
| 221 | 221 | |
| 222 | - $prepared[ $field ] = strip_tags( $row[ $field ] ); |
|
| 222 | + $prepared[ $field ] = strip_tags( $row[ $field ] ); |
|
| 223 | 223 | |
| 224 | - } |
|
| 224 | + } |
|
| 225 | 225 | |
| 226 | - return $prepared; |
|
| 227 | - } |
|
| 226 | + return $prepared; |
|
| 227 | + } |
|
| 228 | 228 | |
| 229 | 229 | |
| 230 | 230 | } |
@@ -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_Graph_Downloader Class. |
@@ -30,13 +30,13 @@ discard block |
||
| 30 | 30 | * |
| 31 | 31 | * @return GetPaid_Reports_Report_Items|GetPaid_Reports_Report_Gateways|GetPaid_Reports_Report_Discounts |
| 32 | 32 | */ |
| 33 | - public function prepare_handler( $graph ) { |
|
| 33 | + public function prepare_handler($graph) { |
|
| 34 | 34 | |
| 35 | - if ( empty( $this->handler->views[ $graph ] ) ) { |
|
| 36 | - wp_die( __( 'Invalid Graph', 'invoicing' ), 400 ); |
|
| 35 | + if (empty($this->handler->views[$graph])) { |
|
| 36 | + wp_die(__('Invalid Graph', 'invoicing'), 400); |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | - return new $this->handler->views[ $graph ]['class'](); |
|
| 39 | + return new $this->handler->views[$graph]['class'](); |
|
| 40 | 40 | |
| 41 | 41 | } |
| 42 | 42 | |
@@ -47,10 +47,10 @@ discard block |
||
| 47 | 47 | */ |
| 48 | 48 | public function prepare_output() { |
| 49 | 49 | |
| 50 | - $output = fopen( 'php://output', 'w' ); |
|
| 50 | + $output = fopen('php://output', 'w'); |
|
| 51 | 51 | |
| 52 | - if ( false === $output ) { |
|
| 53 | - wp_die( __( 'Unsupported server', 'invoicing' ), 500 ); |
|
| 52 | + if (false === $output) { |
|
| 53 | + wp_die(__('Unsupported server', 'invoicing'), 500); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | return $output; |
@@ -61,13 +61,13 @@ discard block |
||
| 61 | 61 | * |
| 62 | 62 | * @return string |
| 63 | 63 | */ |
| 64 | - public function prepare_file_type( $graph ) { |
|
| 64 | + public function prepare_file_type($graph) { |
|
| 65 | 65 | |
| 66 | - $file_type = empty( $_REQUEST['file_type'] ) ? 'csv' : sanitize_text_field( $_REQUEST['file_type'] ); |
|
| 67 | - $file_name = wpinv_sanitize_key( "getpaid-$graph-" . current_time( 'Y-m-d' ) ); |
|
| 66 | + $file_type = empty($_REQUEST['file_type']) ? 'csv' : sanitize_text_field($_REQUEST['file_type']); |
|
| 67 | + $file_name = wpinv_sanitize_key("getpaid-$graph-" . current_time('Y-m-d')); |
|
| 68 | 68 | |
| 69 | - header( "Content-Type:application/$file_type" ); |
|
| 70 | - header( "Content-Disposition:attachment;filename=$file_name.$file_type" ); |
|
| 69 | + header("Content-Type:application/$file_type"); |
|
| 70 | + header("Content-Disposition:attachment;filename=$file_name.$file_type"); |
|
| 71 | 71 | |
| 72 | 72 | return $file_type; |
| 73 | 73 | } |
@@ -76,24 +76,24 @@ discard block |
||
| 76 | 76 | * Handles the actual download. |
| 77 | 77 | * |
| 78 | 78 | */ |
| 79 | - public function download( $graph ) { |
|
| 79 | + public function download($graph) { |
|
| 80 | 80 | global $wpdb; |
| 81 | 81 | |
| 82 | - $handler = $this->prepare_handler( $graph ); |
|
| 82 | + $handler = $this->prepare_handler($graph); |
|
| 83 | 83 | $stream = $this->prepare_output(); |
| 84 | - $stats = $wpdb->get_results( $handler->get_sql( $handler->get_range() ) ); |
|
| 85 | - $headers = array( $handler->field, 'total', 'total_raw' ); |
|
| 86 | - $file_type = $this->prepare_file_type( $graph ); |
|
| 87 | - |
|
| 88 | - if ( 'csv' == $file_type ) { |
|
| 89 | - $this->download_csv( $stats, $stream, $headers ); |
|
| 90 | - } else if( 'xml' == $file_type ) { |
|
| 91 | - $this->download_xml( $stats, $stream, $headers ); |
|
| 84 | + $stats = $wpdb->get_results($handler->get_sql($handler->get_range())); |
|
| 85 | + $headers = array($handler->field, 'total', 'total_raw'); |
|
| 86 | + $file_type = $this->prepare_file_type($graph); |
|
| 87 | + |
|
| 88 | + if ('csv' == $file_type) { |
|
| 89 | + $this->download_csv($stats, $stream, $headers); |
|
| 90 | + } else if ('xml' == $file_type) { |
|
| 91 | + $this->download_xml($stats, $stream, $headers); |
|
| 92 | 92 | } else { |
| 93 | - $this->download_json( $stats, $stream, $headers ); |
|
| 93 | + $this->download_json($stats, $stream, $headers); |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | - fclose( $stream ); |
|
| 96 | + fclose($stream); |
|
| 97 | 97 | exit; |
| 98 | 98 | } |
| 99 | 99 | |
@@ -105,16 +105,16 @@ discard block |
||
| 105 | 105 | * @param array $headers The fields to stream. |
| 106 | 106 | * @since 1.0.19 |
| 107 | 107 | */ |
| 108 | - public function download_csv( $stats, $stream, $headers ) { |
|
| 108 | + public function download_csv($stats, $stream, $headers) { |
|
| 109 | 109 | |
| 110 | 110 | // Output the csv column headers. |
| 111 | - fputcsv( $stream, $headers ); |
|
| 111 | + fputcsv($stream, $headers); |
|
| 112 | 112 | |
| 113 | 113 | // Loop through |
| 114 | - foreach ( $stats as $stat ) { |
|
| 115 | - $row = array_values( $this->prepare_row( $stat, $headers ) ); |
|
| 116 | - $row = array_map( 'maybe_serialize', $row ); |
|
| 117 | - fputcsv( $stream, $row ); |
|
| 114 | + foreach ($stats as $stat) { |
|
| 115 | + $row = array_values($this->prepare_row($stat, $headers)); |
|
| 116 | + $row = array_map('maybe_serialize', $row); |
|
| 117 | + fputcsv($stream, $row); |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | } |
@@ -127,16 +127,16 @@ discard block |
||
| 127 | 127 | * @param array $headers The fields to stream. |
| 128 | 128 | * @since 1.0.19 |
| 129 | 129 | */ |
| 130 | - public function download_json( $stats, $stream, $headers ) { |
|
| 130 | + public function download_json($stats, $stream, $headers) { |
|
| 131 | 131 | |
| 132 | 132 | $prepared = array(); |
| 133 | 133 | |
| 134 | 134 | // Loop through |
| 135 | - foreach ( $stats as $stat ) { |
|
| 136 | - $prepared[] = $this->prepare_row( $stat, $headers ); |
|
| 135 | + foreach ($stats as $stat) { |
|
| 136 | + $prepared[] = $this->prepare_row($stat, $headers); |
|
| 137 | 137 | } |
| 138 | 138 | |
| 139 | - fwrite( $stream, wp_json_encode( $prepared ) ); |
|
| 139 | + fwrite($stream, wp_json_encode($prepared)); |
|
| 140 | 140 | |
| 141 | 141 | } |
| 142 | 142 | |
@@ -148,19 +148,19 @@ discard block |
||
| 148 | 148 | * @param array $headers The fields to stream. |
| 149 | 149 | * @since 1.0.19 |
| 150 | 150 | */ |
| 151 | - public function download_xml( $stats, $stream, $headers ) { |
|
| 151 | + public function download_xml($stats, $stream, $headers) { |
|
| 152 | 152 | |
| 153 | 153 | $prepared = array(); |
| 154 | 154 | |
| 155 | 155 | // Loop through |
| 156 | - foreach ( $stats as $stat ) { |
|
| 157 | - $prepared[] = $this->prepare_row( $stat, $headers ); |
|
| 156 | + foreach ($stats as $stat) { |
|
| 157 | + $prepared[] = $this->prepare_row($stat, $headers); |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | $xml = new SimpleXMLElement('<?xml version="1.0"?><data></data>'); |
| 161 | - $this->convert_array_xml( $prepared, $xml ); |
|
| 161 | + $this->convert_array_xml($prepared, $xml); |
|
| 162 | 162 | |
| 163 | - fwrite( $stream, $xml->asXML() ); |
|
| 163 | + fwrite($stream, $xml->asXML()); |
|
| 164 | 164 | |
| 165 | 165 | } |
| 166 | 166 | |
@@ -170,24 +170,24 @@ discard block |
||
| 170 | 170 | * @access public |
| 171 | 171 | * @since 1.0.19 |
| 172 | 172 | */ |
| 173 | - public function convert_array_xml( $data, $xml ) { |
|
| 173 | + public function convert_array_xml($data, $xml) { |
|
| 174 | 174 | |
| 175 | 175 | // Loop through |
| 176 | - foreach ( $data as $key => $value ) { |
|
| 176 | + foreach ($data as $key => $value) { |
|
| 177 | 177 | |
| 178 | - $key = preg_replace( "/[^A-Za-z0-9_\-]/", '', $key ); |
|
| 178 | + $key = preg_replace("/[^A-Za-z0-9_\-]/", '', $key); |
|
| 179 | 179 | |
| 180 | - if ( is_array( $value ) ) { |
|
| 180 | + if (is_array($value)) { |
|
| 181 | 181 | |
| 182 | - if ( is_numeric( $key ) ){ |
|
| 183 | - $key = 'item'.$key; //dealing with <0/>..<n/> issues |
|
| 182 | + if (is_numeric($key)) { |
|
| 183 | + $key = 'item' . $key; //dealing with <0/>..<n/> issues |
|
| 184 | 184 | } |
| 185 | 185 | |
| 186 | - $subnode = $xml->addChild( $key ); |
|
| 187 | - $this->convert_array_xml( $value, $subnode ); |
|
| 186 | + $subnode = $xml->addChild($key); |
|
| 187 | + $this->convert_array_xml($value, $subnode); |
|
| 188 | 188 | |
| 189 | 189 | } else { |
| 190 | - $xml->addChild( $key, htmlspecialchars( $value ) ); |
|
| 190 | + $xml->addChild($key, htmlspecialchars($value)); |
|
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | } |
@@ -202,24 +202,24 @@ discard block |
||
| 202 | 202 | * @since 1.0.19 |
| 203 | 203 | * @return array |
| 204 | 204 | */ |
| 205 | - public function prepare_row( $row, $fields ) { |
|
| 205 | + public function prepare_row($row, $fields) { |
|
| 206 | 206 | |
| 207 | 207 | $prepared = array(); |
| 208 | 208 | $row = (array) $row; |
| 209 | 209 | |
| 210 | - foreach ( $fields as $field ) { |
|
| 210 | + foreach ($fields as $field) { |
|
| 211 | 211 | |
| 212 | - if ( $field === 'total' ) { |
|
| 213 | - $prepared[ $field ] = html_entity_decode( strip_tags( wpinv_price( $row['total'] ) ), ENT_QUOTES ); |
|
| 212 | + if ($field === 'total') { |
|
| 213 | + $prepared[$field] = html_entity_decode(strip_tags(wpinv_price($row['total'])), ENT_QUOTES); |
|
| 214 | 214 | continue; |
| 215 | 215 | } |
| 216 | 216 | |
| 217 | - if ( $field === 'total_raw' ) { |
|
| 218 | - $prepared[ $field ] = wpinv_round_amount( wpinv_sanitize_amount( $row['total'] ) ); |
|
| 217 | + if ($field === 'total_raw') { |
|
| 218 | + $prepared[$field] = wpinv_round_amount(wpinv_sanitize_amount($row['total'])); |
|
| 219 | 219 | continue; |
| 220 | 220 | } |
| 221 | 221 | |
| 222 | - $prepared[ $field ] = strip_tags( $row[ $field ] ); |
|
| 222 | + $prepared[$field] = strip_tags($row[$field]); |
|
| 223 | 223 | |
| 224 | 224 | } |
| 225 | 225 | |
@@ -12,46 +12,46 @@ discard block |
||
| 12 | 12 | */ |
| 13 | 13 | class GetPaid_Reports_Export { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Displays the reports tab. |
|
| 17 | - * |
|
| 18 | - */ |
|
| 19 | - public function display() { |
|
| 20 | - |
|
| 21 | - echo "<div class='row mt-4' style='max-width: 920px;' >"; |
|
| 22 | - foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) { |
|
| 23 | - $this->display_post_type_export( $post_type ); |
|
| 24 | - } |
|
| 25 | - echo "</div>"; |
|
| 26 | - |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * Retrieves the download url. |
|
| 31 | - * |
|
| 32 | - */ |
|
| 33 | - public function get_download_url( $post_type ) { |
|
| 34 | - |
|
| 35 | - return wp_nonce_url( |
|
| 36 | - add_query_arg( |
|
| 37 | - array( |
|
| 38 | - 'getpaid-admin-action' => 'export_invoices', |
|
| 39 | - 'post_type' => urlencode( $post_type ), |
|
| 40 | - ) |
|
| 41 | - ), |
|
| 42 | - 'getpaid-nonce', |
|
| 43 | - 'getpaid-nonce' |
|
| 44 | - ); |
|
| 45 | - |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * Displays a single post type export card. |
|
| 50 | - * |
|
| 51 | - */ |
|
| 52 | - public function display_post_type_export( $post_type ) { |
|
| 53 | - |
|
| 54 | - ?> |
|
| 15 | + /** |
|
| 16 | + * Displays the reports tab. |
|
| 17 | + * |
|
| 18 | + */ |
|
| 19 | + public function display() { |
|
| 20 | + |
|
| 21 | + echo "<div class='row mt-4' style='max-width: 920px;' >"; |
|
| 22 | + foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) { |
|
| 23 | + $this->display_post_type_export( $post_type ); |
|
| 24 | + } |
|
| 25 | + echo "</div>"; |
|
| 26 | + |
|
| 27 | + } |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * Retrieves the download url. |
|
| 31 | + * |
|
| 32 | + */ |
|
| 33 | + public function get_download_url( $post_type ) { |
|
| 34 | + |
|
| 35 | + return wp_nonce_url( |
|
| 36 | + add_query_arg( |
|
| 37 | + array( |
|
| 38 | + 'getpaid-admin-action' => 'export_invoices', |
|
| 39 | + 'post_type' => urlencode( $post_type ), |
|
| 40 | + ) |
|
| 41 | + ), |
|
| 42 | + 'getpaid-nonce', |
|
| 43 | + 'getpaid-nonce' |
|
| 44 | + ); |
|
| 45 | + |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * Displays a single post type export card. |
|
| 50 | + * |
|
| 51 | + */ |
|
| 52 | + public function display_post_type_export( $post_type ) { |
|
| 53 | + |
|
| 54 | + ?> |
|
| 55 | 55 | |
| 56 | 56 | <div class="col-12 col-md-6"> |
| 57 | 57 | <div class="card m-0 p-0" style="max-width:100%"> |
@@ -59,11 +59,11 @@ discard block |
||
| 59 | 59 | <div class="card-header"> |
| 60 | 60 | <strong> |
| 61 | 61 | <?php |
| 62 | - printf( |
|
| 63 | - __( 'Export %s', 'invoicing' ), |
|
| 64 | - sanitize_text_field( getpaid_get_post_type_label( $post_type ) ) |
|
| 65 | - ); |
|
| 66 | - ?> |
|
| 62 | + printf( |
|
| 63 | + __( 'Export %s', 'invoicing' ), |
|
| 64 | + sanitize_text_field( getpaid_get_post_type_label( $post_type ) ) |
|
| 65 | + ); |
|
| 66 | + ?> |
|
| 67 | 67 | </strong> |
| 68 | 68 | </div> |
| 69 | 69 | |
@@ -72,12 +72,12 @@ discard block |
||
| 72 | 72 | <form method="post" action="<?php echo esc_url( $this->get_download_url( $post_type ) ); ?>"> |
| 73 | 73 | |
| 74 | 74 | <?php |
| 75 | - $this->display_markup( $this->generate_from_date( $post_type ) ); |
|
| 76 | - $this->display_markup( $this->generate_to_date( $post_type ) ); |
|
| 77 | - $this->display_markup( $this->generate_post_status_select( $post_type ) ); |
|
| 78 | - $this->display_markup( $this->generate_file_type_select( $post_type ) ); |
|
| 79 | - submit_button( __( 'Download', 'invoicing' ) ); |
|
| 80 | - ?> |
|
| 75 | + $this->display_markup( $this->generate_from_date( $post_type ) ); |
|
| 76 | + $this->display_markup( $this->generate_to_date( $post_type ) ); |
|
| 77 | + $this->display_markup( $this->generate_post_status_select( $post_type ) ); |
|
| 78 | + $this->display_markup( $this->generate_file_type_select( $post_type ) ); |
|
| 79 | + submit_button( __( 'Download', 'invoicing' ) ); |
|
| 80 | + ?> |
|
| 81 | 81 | |
| 82 | 82 | </form> |
| 83 | 83 | |
@@ -88,107 +88,107 @@ discard block |
||
| 88 | 88 | |
| 89 | 89 | <?php |
| 90 | 90 | |
| 91 | - } |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * Generates the from date input field. |
|
| 95 | - * |
|
| 96 | - */ |
|
| 97 | - public function generate_from_date( $post_type ) { |
|
| 98 | - |
|
| 99 | - return aui()->input( |
|
| 100 | - array( |
|
| 101 | - 'name' => 'from_date', |
|
| 102 | - 'id' => esc_attr( "$post_type-from_date" ), |
|
| 103 | - 'placeholder'=> 'yy-mm-dd', |
|
| 104 | - 'label' => __( 'From Date', 'invoicing' ), |
|
| 105 | - 'label_type' => 'vertical', |
|
| 106 | - 'label_class' => 'd-block', |
|
| 107 | - 'type' => 'datepicker', |
|
| 108 | - ) |
|
| 109 | - ); |
|
| 110 | - |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * Generates the to date input field. |
|
| 115 | - * |
|
| 116 | - */ |
|
| 117 | - public function generate_to_date( $post_type ) { |
|
| 118 | - |
|
| 119 | - return aui()->input( |
|
| 120 | - array( |
|
| 121 | - 'name' => 'to_date', |
|
| 122 | - 'id' => esc_attr( "$post_type-to_date" ), |
|
| 123 | - 'placeholder'=> 'yy-mm-dd', |
|
| 124 | - 'label' => __( 'To Date', 'invoicing' ), |
|
| 125 | - 'label_type' => 'vertical', |
|
| 126 | - 'label_class' => 'd-block', |
|
| 127 | - 'type' => 'datepicker', |
|
| 128 | - ) |
|
| 129 | - ); |
|
| 130 | - |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * Generates the to post status select field. |
|
| 135 | - * |
|
| 136 | - */ |
|
| 137 | - public function generate_post_status_select( $post_type ) { |
|
| 138 | - |
|
| 139 | - return aui()->select( |
|
| 140 | - array( |
|
| 141 | - 'name' => 'status', |
|
| 142 | - 'id' => esc_attr( "$post_type-status" ), |
|
| 143 | - 'placeholder' => __( 'All Statuses', 'invoicing' ), |
|
| 144 | - 'label' => __( 'Status', 'invoicing' ), |
|
| 145 | - 'label_type' => 'vertical', |
|
| 146 | - 'label_class' => 'd-block', |
|
| 147 | - 'options' => wpinv_get_invoice_statuses( true, false, $post_type ), |
|
| 148 | - ) |
|
| 149 | - ); |
|
| 150 | - |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * Generates the to file type select field. |
|
| 155 | - * |
|
| 156 | - */ |
|
| 157 | - public function generate_file_type_select( $post_type ) { |
|
| 158 | - |
|
| 159 | - return aui()->select( |
|
| 160 | - array( |
|
| 161 | - 'name' => 'file_type', |
|
| 162 | - 'id' => esc_attr( "$post_type-file_type" ), |
|
| 163 | - 'placeholder' => __( 'Select File Type', 'invoicing' ), |
|
| 164 | - 'label' => __( 'Export File', 'invoicing' ), |
|
| 165 | - 'label_type' => 'vertical', |
|
| 166 | - 'label_class' => 'd-block', |
|
| 167 | - 'options' => array( |
|
| 168 | - 'csv' => __( 'CSV', 'invoicing' ), |
|
| 169 | - 'xml' => __( 'XML', 'invoicing' ), |
|
| 170 | - 'json' => __( 'JSON', 'invoicing' ), |
|
| 171 | - ), |
|
| 172 | - ) |
|
| 173 | - ); |
|
| 174 | - |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * Displays a field's markup. |
|
| 179 | - * |
|
| 180 | - */ |
|
| 181 | - public function display_markup( $markup ) { |
|
| 182 | - |
|
| 183 | - echo str_replace( |
|
| 184 | - array( |
|
| 185 | - 'form-control', |
|
| 186 | - 'custom-select' |
|
| 187 | - ), |
|
| 188 | - 'regular-text', |
|
| 189 | - $markup |
|
| 190 | - ); |
|
| 191 | - |
|
| 192 | - } |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * Generates the from date input field. |
|
| 95 | + * |
|
| 96 | + */ |
|
| 97 | + public function generate_from_date( $post_type ) { |
|
| 98 | + |
|
| 99 | + return aui()->input( |
|
| 100 | + array( |
|
| 101 | + 'name' => 'from_date', |
|
| 102 | + 'id' => esc_attr( "$post_type-from_date" ), |
|
| 103 | + 'placeholder'=> 'yy-mm-dd', |
|
| 104 | + 'label' => __( 'From Date', 'invoicing' ), |
|
| 105 | + 'label_type' => 'vertical', |
|
| 106 | + 'label_class' => 'd-block', |
|
| 107 | + 'type' => 'datepicker', |
|
| 108 | + ) |
|
| 109 | + ); |
|
| 110 | + |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * Generates the to date input field. |
|
| 115 | + * |
|
| 116 | + */ |
|
| 117 | + public function generate_to_date( $post_type ) { |
|
| 118 | + |
|
| 119 | + return aui()->input( |
|
| 120 | + array( |
|
| 121 | + 'name' => 'to_date', |
|
| 122 | + 'id' => esc_attr( "$post_type-to_date" ), |
|
| 123 | + 'placeholder'=> 'yy-mm-dd', |
|
| 124 | + 'label' => __( 'To Date', 'invoicing' ), |
|
| 125 | + 'label_type' => 'vertical', |
|
| 126 | + 'label_class' => 'd-block', |
|
| 127 | + 'type' => 'datepicker', |
|
| 128 | + ) |
|
| 129 | + ); |
|
| 130 | + |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * Generates the to post status select field. |
|
| 135 | + * |
|
| 136 | + */ |
|
| 137 | + public function generate_post_status_select( $post_type ) { |
|
| 138 | + |
|
| 139 | + return aui()->select( |
|
| 140 | + array( |
|
| 141 | + 'name' => 'status', |
|
| 142 | + 'id' => esc_attr( "$post_type-status" ), |
|
| 143 | + 'placeholder' => __( 'All Statuses', 'invoicing' ), |
|
| 144 | + 'label' => __( 'Status', 'invoicing' ), |
|
| 145 | + 'label_type' => 'vertical', |
|
| 146 | + 'label_class' => 'd-block', |
|
| 147 | + 'options' => wpinv_get_invoice_statuses( true, false, $post_type ), |
|
| 148 | + ) |
|
| 149 | + ); |
|
| 150 | + |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * Generates the to file type select field. |
|
| 155 | + * |
|
| 156 | + */ |
|
| 157 | + public function generate_file_type_select( $post_type ) { |
|
| 158 | + |
|
| 159 | + return aui()->select( |
|
| 160 | + array( |
|
| 161 | + 'name' => 'file_type', |
|
| 162 | + 'id' => esc_attr( "$post_type-file_type" ), |
|
| 163 | + 'placeholder' => __( 'Select File Type', 'invoicing' ), |
|
| 164 | + 'label' => __( 'Export File', 'invoicing' ), |
|
| 165 | + 'label_type' => 'vertical', |
|
| 166 | + 'label_class' => 'd-block', |
|
| 167 | + 'options' => array( |
|
| 168 | + 'csv' => __( 'CSV', 'invoicing' ), |
|
| 169 | + 'xml' => __( 'XML', 'invoicing' ), |
|
| 170 | + 'json' => __( 'JSON', 'invoicing' ), |
|
| 171 | + ), |
|
| 172 | + ) |
|
| 173 | + ); |
|
| 174 | + |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + /** |
|
| 178 | + * Displays a field's markup. |
|
| 179 | + * |
|
| 180 | + */ |
|
| 181 | + public function display_markup( $markup ) { |
|
| 182 | + |
|
| 183 | + echo str_replace( |
|
| 184 | + array( |
|
| 185 | + 'form-control', |
|
| 186 | + 'custom-select' |
|
| 187 | + ), |
|
| 188 | + 'regular-text', |
|
| 189 | + $markup |
|
| 190 | + ); |
|
| 191 | + |
|
| 192 | + } |
|
| 193 | 193 | |
| 194 | 194 | } |
@@ -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_Export Class. |
@@ -19,8 +19,8 @@ discard block |
||
| 19 | 19 | public function display() { |
| 20 | 20 | |
| 21 | 21 | echo "<div class='row mt-4' style='max-width: 920px;' >"; |
| 22 | - foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) { |
|
| 23 | - $this->display_post_type_export( $post_type ); |
|
| 22 | + foreach (array_keys(getpaid_get_invoice_post_types()) as $post_type) { |
|
| 23 | + $this->display_post_type_export($post_type); |
|
| 24 | 24 | } |
| 25 | 25 | echo "</div>"; |
| 26 | 26 | |
@@ -30,13 +30,13 @@ discard block |
||
| 30 | 30 | * Retrieves the download url. |
| 31 | 31 | * |
| 32 | 32 | */ |
| 33 | - public function get_download_url( $post_type ) { |
|
| 33 | + public function get_download_url($post_type) { |
|
| 34 | 34 | |
| 35 | 35 | return wp_nonce_url( |
| 36 | 36 | add_query_arg( |
| 37 | 37 | array( |
| 38 | 38 | 'getpaid-admin-action' => 'export_invoices', |
| 39 | - 'post_type' => urlencode( $post_type ), |
|
| 39 | + 'post_type' => urlencode($post_type), |
|
| 40 | 40 | ) |
| 41 | 41 | ), |
| 42 | 42 | 'getpaid-nonce', |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | * Displays a single post type export card. |
| 50 | 50 | * |
| 51 | 51 | */ |
| 52 | - public function display_post_type_export( $post_type ) { |
|
| 52 | + public function display_post_type_export($post_type) { |
|
| 53 | 53 | |
| 54 | 54 | ?> |
| 55 | 55 | |
@@ -60,8 +60,8 @@ discard block |
||
| 60 | 60 | <strong> |
| 61 | 61 | <?php |
| 62 | 62 | printf( |
| 63 | - __( 'Export %s', 'invoicing' ), |
|
| 64 | - sanitize_text_field( getpaid_get_post_type_label( $post_type ) ) |
|
| 63 | + __('Export %s', 'invoicing'), |
|
| 64 | + sanitize_text_field(getpaid_get_post_type_label($post_type)) |
|
| 65 | 65 | ); |
| 66 | 66 | ?> |
| 67 | 67 | </strong> |
@@ -69,14 +69,14 @@ discard block |
||
| 69 | 69 | |
| 70 | 70 | <div class="card-body"> |
| 71 | 71 | |
| 72 | - <form method="post" action="<?php echo esc_url( $this->get_download_url( $post_type ) ); ?>"> |
|
| 72 | + <form method="post" action="<?php echo esc_url($this->get_download_url($post_type)); ?>"> |
|
| 73 | 73 | |
| 74 | 74 | <?php |
| 75 | - $this->display_markup( $this->generate_from_date( $post_type ) ); |
|
| 76 | - $this->display_markup( $this->generate_to_date( $post_type ) ); |
|
| 77 | - $this->display_markup( $this->generate_post_status_select( $post_type ) ); |
|
| 78 | - $this->display_markup( $this->generate_file_type_select( $post_type ) ); |
|
| 79 | - submit_button( __( 'Download', 'invoicing' ) ); |
|
| 75 | + $this->display_markup($this->generate_from_date($post_type)); |
|
| 76 | + $this->display_markup($this->generate_to_date($post_type)); |
|
| 77 | + $this->display_markup($this->generate_post_status_select($post_type)); |
|
| 78 | + $this->display_markup($this->generate_file_type_select($post_type)); |
|
| 79 | + submit_button(__('Download', 'invoicing')); |
|
| 80 | 80 | ?> |
| 81 | 81 | |
| 82 | 82 | </form> |
@@ -94,14 +94,14 @@ discard block |
||
| 94 | 94 | * Generates the from date input field. |
| 95 | 95 | * |
| 96 | 96 | */ |
| 97 | - public function generate_from_date( $post_type ) { |
|
| 97 | + public function generate_from_date($post_type) { |
|
| 98 | 98 | |
| 99 | 99 | return aui()->input( |
| 100 | 100 | array( |
| 101 | 101 | 'name' => 'from_date', |
| 102 | - 'id' => esc_attr( "$post_type-from_date" ), |
|
| 102 | + 'id' => esc_attr("$post_type-from_date"), |
|
| 103 | 103 | 'placeholder'=> 'yy-mm-dd', |
| 104 | - 'label' => __( 'From Date', 'invoicing' ), |
|
| 104 | + 'label' => __('From Date', 'invoicing'), |
|
| 105 | 105 | 'label_type' => 'vertical', |
| 106 | 106 | 'label_class' => 'd-block', |
| 107 | 107 | 'type' => 'datepicker', |
@@ -114,14 +114,14 @@ discard block |
||
| 114 | 114 | * Generates the to date input field. |
| 115 | 115 | * |
| 116 | 116 | */ |
| 117 | - public function generate_to_date( $post_type ) { |
|
| 117 | + public function generate_to_date($post_type) { |
|
| 118 | 118 | |
| 119 | 119 | return aui()->input( |
| 120 | 120 | array( |
| 121 | 121 | 'name' => 'to_date', |
| 122 | - 'id' => esc_attr( "$post_type-to_date" ), |
|
| 122 | + 'id' => esc_attr("$post_type-to_date"), |
|
| 123 | 123 | 'placeholder'=> 'yy-mm-dd', |
| 124 | - 'label' => __( 'To Date', 'invoicing' ), |
|
| 124 | + 'label' => __('To Date', 'invoicing'), |
|
| 125 | 125 | 'label_type' => 'vertical', |
| 126 | 126 | 'label_class' => 'd-block', |
| 127 | 127 | 'type' => 'datepicker', |
@@ -134,17 +134,17 @@ discard block |
||
| 134 | 134 | * Generates the to post status select field. |
| 135 | 135 | * |
| 136 | 136 | */ |
| 137 | - public function generate_post_status_select( $post_type ) { |
|
| 137 | + public function generate_post_status_select($post_type) { |
|
| 138 | 138 | |
| 139 | 139 | return aui()->select( |
| 140 | 140 | array( |
| 141 | 141 | 'name' => 'status', |
| 142 | - 'id' => esc_attr( "$post_type-status" ), |
|
| 143 | - 'placeholder' => __( 'All Statuses', 'invoicing' ), |
|
| 144 | - 'label' => __( 'Status', 'invoicing' ), |
|
| 142 | + 'id' => esc_attr("$post_type-status"), |
|
| 143 | + 'placeholder' => __('All Statuses', 'invoicing'), |
|
| 144 | + 'label' => __('Status', 'invoicing'), |
|
| 145 | 145 | 'label_type' => 'vertical', |
| 146 | 146 | 'label_class' => 'd-block', |
| 147 | - 'options' => wpinv_get_invoice_statuses( true, false, $post_type ), |
|
| 147 | + 'options' => wpinv_get_invoice_statuses(true, false, $post_type), |
|
| 148 | 148 | ) |
| 149 | 149 | ); |
| 150 | 150 | |
@@ -154,20 +154,20 @@ discard block |
||
| 154 | 154 | * Generates the to file type select field. |
| 155 | 155 | * |
| 156 | 156 | */ |
| 157 | - public function generate_file_type_select( $post_type ) { |
|
| 157 | + public function generate_file_type_select($post_type) { |
|
| 158 | 158 | |
| 159 | 159 | return aui()->select( |
| 160 | 160 | array( |
| 161 | 161 | 'name' => 'file_type', |
| 162 | - 'id' => esc_attr( "$post_type-file_type" ), |
|
| 163 | - 'placeholder' => __( 'Select File Type', 'invoicing' ), |
|
| 164 | - 'label' => __( 'Export File', 'invoicing' ), |
|
| 162 | + 'id' => esc_attr("$post_type-file_type"), |
|
| 163 | + 'placeholder' => __('Select File Type', 'invoicing'), |
|
| 164 | + 'label' => __('Export File', 'invoicing'), |
|
| 165 | 165 | 'label_type' => 'vertical', |
| 166 | 166 | 'label_class' => 'd-block', |
| 167 | 167 | 'options' => array( |
| 168 | - 'csv' => __( 'CSV', 'invoicing' ), |
|
| 169 | - 'xml' => __( 'XML', 'invoicing' ), |
|
| 170 | - 'json' => __( 'JSON', 'invoicing' ), |
|
| 168 | + 'csv' => __('CSV', 'invoicing'), |
|
| 169 | + 'xml' => __('XML', 'invoicing'), |
|
| 170 | + 'json' => __('JSON', 'invoicing'), |
|
| 171 | 171 | ), |
| 172 | 172 | ) |
| 173 | 173 | ); |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | * Displays a field's markup. |
| 179 | 179 | * |
| 180 | 180 | */ |
| 181 | - public function display_markup( $markup ) { |
|
| 181 | + public function display_markup($markup) { |
|
| 182 | 182 | |
| 183 | 183 | echo str_replace( |
| 184 | 184 | array( |
@@ -7,20 +7,20 @@ discard block |
||
| 7 | 7 | * @version 1.0.19 |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | -defined( 'ABSPATH' ) || exit; |
|
| 10 | +defined('ABSPATH') || exit; |
|
| 11 | 11 | |
| 12 | -$class = empty( $class ) ? 'btn-primary' : sanitize_html_class( $class ); |
|
| 13 | -$label = empty( $label ) ? esc_attr__( 'Pay %price% »', 'invoicing' ) : esc_attr( $label ); |
|
| 14 | -$free = empty( $free ) ? esc_attr__( 'Continue »', 'invoicing' ) : esc_attr( $free ); |
|
| 12 | +$class = empty($class) ? 'btn-primary' : sanitize_html_class($class); |
|
| 13 | +$label = empty($label) ? esc_attr__('Pay %price% »', 'invoicing') : esc_attr($label); |
|
| 14 | +$free = empty($free) ? esc_attr__('Continue »', 'invoicing') : esc_attr($free); |
|
| 15 | 15 | |
| 16 | -do_action( 'getpaid_before_payment_form_pay_button', $form ); |
|
| 16 | +do_action('getpaid_before_payment_form_pay_button', $form); |
|
| 17 | 17 | |
| 18 | 18 | echo aui()->input( |
| 19 | 19 | array( |
| 20 | - 'name' => esc_attr( $id ), |
|
| 21 | - 'id' => esc_attr( $id ) . uniqid( '_' ), |
|
| 20 | + 'name' => esc_attr($id), |
|
| 21 | + 'id' => esc_attr($id) . uniqid('_'), |
|
| 22 | 22 | 'value' => $label, |
| 23 | - 'help_text' => empty( $description ) ? '' : wp_kses_post( $description ), |
|
| 23 | + 'help_text' => empty($description) ? '' : wp_kses_post($description), |
|
| 24 | 24 | 'type' => 'submit', |
| 25 | 25 | 'class' => 'getpaid-payment-form-submit btn btn-block submit-button ' . $class, |
| 26 | 26 | 'extra_attributes' => array( |
@@ -30,4 +30,4 @@ discard block |
||
| 30 | 30 | ) |
| 31 | 31 | ); |
| 32 | 32 | |
| 33 | -do_action( 'getpaid_after_payment_form_pay_button', $form ); |
|
| 34 | 33 | \ No newline at end of file |
| 34 | +do_action('getpaid_after_payment_form_pay_button', $form); |
|
| 35 | 35 | \ No newline at end of file |
@@ -256,8 +256,9 @@ |
||
| 256 | 256 | } |
| 257 | 257 | |
| 258 | 258 | function wpinv_cart_needs_tax_address_fields() { |
| 259 | - if( !wpinv_is_cart_taxed() ) |
|
| 260 | - return false; |
|
| 259 | + if( !wpinv_is_cart_taxed() ) { |
|
| 260 | + return false; |
|
| 261 | + } |
|
| 261 | 262 | |
| 262 | 263 | return ! did_action( 'wpinv_after_cc_fields', 'wpinv_default_cc_address_fields' ); |
| 263 | 264 | } |
@@ -215,16 +215,16 @@ discard block |
||
| 215 | 215 | function getpaid_prepare_item_tax( $item, $tax_name, $tax_amount, $recurring_tax_amount ) { |
| 216 | 216 | |
| 217 | 217 | $initial_tax = $tax_amount; |
| 218 | - $recurring_tax = 0; |
|
| 218 | + $recurring_tax = 0; |
|
| 219 | 219 | |
| 220 | 220 | if ( $item->is_recurring() ) { |
| 221 | - $recurring_tax = $recurring_tax_amount; |
|
| 222 | - } |
|
| 221 | + $recurring_tax = $recurring_tax_amount; |
|
| 222 | + } |
|
| 223 | 223 | |
| 224 | - return array( |
|
| 225 | - 'name' => sanitize_text_field( $tax_name ), |
|
| 226 | - 'initial_tax' => $initial_tax, |
|
| 227 | - 'recurring_tax' => $recurring_tax, |
|
| 224 | + return array( |
|
| 225 | + 'name' => sanitize_text_field( $tax_name ), |
|
| 226 | + 'initial_tax' => $initial_tax, |
|
| 227 | + 'recurring_tax' => $recurring_tax, |
|
| 228 | 228 | ); |
| 229 | 229 | |
| 230 | 230 | } |
@@ -328,7 +328,7 @@ discard block |
||
| 328 | 328 | */ |
| 329 | 329 | function wpinv_should_validate_vat_number() { |
| 330 | 330 | $validate = wpinv_get_option( 'validate_vat_number' ); |
| 331 | - return ! empty( $validate ); |
|
| 331 | + return ! empty( $validate ); |
|
| 332 | 332 | } |
| 333 | 333 | |
| 334 | 334 | function wpinv_sales_tax_for_year( $year = null ) { |
@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | * |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | -defined( 'ABSPATH' ) || exit; |
|
| 7 | +defined('ABSPATH') || exit; |
|
| 8 | 8 | |
| 9 | 9 | /** |
| 10 | 10 | * Returns an array of eu states. |
@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | * @return array |
| 13 | 13 | */ |
| 14 | 14 | function getpaid_get_eu_states() { |
| 15 | - return wpinv_get_data( 'eu-states' ); |
|
| 15 | + return wpinv_get_data('eu-states'); |
|
| 16 | 16 | } |
| 17 | 17 | |
| 18 | 18 | /** |
@@ -20,8 +20,8 @@ discard block |
||
| 20 | 20 | * |
| 21 | 21 | * @return bool |
| 22 | 22 | */ |
| 23 | -function getpaid_is_eu_state( $country ) { |
|
| 24 | - return ! empty( $country ) && in_array( strtoupper( $country ), getpaid_get_eu_states() ) ? true : false; |
|
| 23 | +function getpaid_is_eu_state($country) { |
|
| 24 | + return !empty($country) && in_array(strtoupper($country), getpaid_get_eu_states()) ? true : false; |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | /** |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | * @return array |
| 31 | 31 | */ |
| 32 | 32 | function getpaid_get_gst_states() { |
| 33 | - return array( 'AU', 'NZ', 'CA', 'CN' ); |
|
| 33 | + return array('AU', 'NZ', 'CA', 'CN'); |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | /** |
@@ -38,8 +38,8 @@ discard block |
||
| 38 | 38 | * |
| 39 | 39 | * @return bool |
| 40 | 40 | */ |
| 41 | -function getpaid_is_gst_country( $country ) { |
|
| 42 | - return ! empty( $country ) && in_array( strtoupper( $country ), getpaid_get_gst_states() ) ? true : false; |
|
| 41 | +function getpaid_is_gst_country($country) { |
|
| 42 | + return !empty($country) && in_array(strtoupper($country), getpaid_get_gst_states()) ? true : false; |
|
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | /** |
@@ -49,8 +49,8 @@ discard block |
||
| 49 | 49 | */ |
| 50 | 50 | function wpinv_use_taxes() { |
| 51 | 51 | |
| 52 | - $ret = wpinv_get_option( 'enable_taxes', false ); |
|
| 53 | - return (bool) apply_filters( 'wpinv_use_taxes', ! empty( $ret ) ); |
|
| 52 | + $ret = wpinv_get_option('enable_taxes', false); |
|
| 53 | + return (bool) apply_filters('wpinv_use_taxes', !empty($ret)); |
|
| 54 | 54 | |
| 55 | 55 | } |
| 56 | 56 | |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | * @param WPInv_Invoice $invoice |
| 61 | 61 | * @return bool |
| 62 | 62 | */ |
| 63 | -function wpinv_is_invoice_taxable( $invoice ) { |
|
| 63 | +function wpinv_is_invoice_taxable($invoice) { |
|
| 64 | 64 | return $invoice->is_taxable(); |
| 65 | 65 | } |
| 66 | 66 | |
@@ -70,11 +70,11 @@ discard block |
||
| 70 | 70 | * @param string $country |
| 71 | 71 | * @return bool |
| 72 | 72 | */ |
| 73 | -function wpinv_is_country_taxable( $country ) { |
|
| 74 | - $is_eu = getpaid_is_eu_state( $country ); |
|
| 75 | - $is_exempt = ! $is_eu && wpinv_is_base_country( $country ) && wpinv_same_country_exempt_vat(); |
|
| 73 | +function wpinv_is_country_taxable($country) { |
|
| 74 | + $is_eu = getpaid_is_eu_state($country); |
|
| 75 | + $is_exempt = !$is_eu && wpinv_is_base_country($country) && wpinv_same_country_exempt_vat(); |
|
| 76 | 76 | |
| 77 | - return (bool) apply_filters( 'wpinv_is_country_taxable', ! $is_exempt, $country ); |
|
| 77 | + return (bool) apply_filters('wpinv_is_country_taxable', !$is_exempt, $country); |
|
| 78 | 78 | |
| 79 | 79 | } |
| 80 | 80 | |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | * @param WPInv_Item|GetPaid_Form_Item $item |
| 85 | 85 | * @return bool |
| 86 | 86 | */ |
| 87 | -function wpinv_is_item_taxable( $item ) { |
|
| 87 | +function wpinv_is_item_taxable($item) { |
|
| 88 | 88 | return '_exempt' != $item->get_vat_rule(); |
| 89 | 89 | } |
| 90 | 90 | |
@@ -94,8 +94,8 @@ discard block |
||
| 94 | 94 | * @return bool |
| 95 | 95 | */ |
| 96 | 96 | function wpinv_use_store_address_as_tax_base() { |
| 97 | - $use_base = wpinv_get_option( 'tax_base', 'billing' ) == 'base'; |
|
| 98 | - return (bool) apply_filters( 'wpinv_use_store_address_as_tax_base', $use_base ); |
|
| 97 | + $use_base = wpinv_get_option('tax_base', 'billing') == 'base'; |
|
| 98 | + return (bool) apply_filters('wpinv_use_store_address_as_tax_base', $use_base); |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | /** |
@@ -104,8 +104,8 @@ discard block |
||
| 104 | 104 | * @return bool |
| 105 | 105 | */ |
| 106 | 106 | function wpinv_prices_include_tax() { |
| 107 | - $is_inclusive = wpinv_get_option( 'prices_include_tax', 'no' ) == 'yes'; |
|
| 108 | - return (bool) apply_filters( 'wpinv_prices_include_tax', $is_inclusive ); |
|
| 107 | + $is_inclusive = wpinv_get_option('prices_include_tax', 'no') == 'yes'; |
|
| 108 | + return (bool) apply_filters('wpinv_prices_include_tax', $is_inclusive); |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | /** |
@@ -114,8 +114,8 @@ discard block |
||
| 114 | 114 | * @return bool |
| 115 | 115 | */ |
| 116 | 116 | function wpinv_round_tax_per_tax_rate() { |
| 117 | - $subtotal_rounding = wpinv_get_option( 'tax_subtotal_rounding', 1 ); |
|
| 118 | - return (bool) apply_filters( 'wpinv_round_tax_per_tax_rate', empty( $subtotal_rounding ) ); |
|
| 117 | + $subtotal_rounding = wpinv_get_option('tax_subtotal_rounding', 1); |
|
| 118 | + return (bool) apply_filters('wpinv_round_tax_per_tax_rate', empty($subtotal_rounding)); |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | /** |
@@ -124,8 +124,8 @@ discard block |
||
| 124 | 124 | * @return bool |
| 125 | 125 | */ |
| 126 | 126 | function wpinv_display_individual_tax_rates() { |
| 127 | - $individual = wpinv_get_option( 'tax_display_totals', 'single' ) == 'individual'; |
|
| 128 | - return (bool) apply_filters( 'wpinv_display_individual_tax_rates', $individual ); |
|
| 127 | + $individual = wpinv_get_option('tax_display_totals', 'single') == 'individual'; |
|
| 128 | + return (bool) apply_filters('wpinv_display_individual_tax_rates', $individual); |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | /** |
@@ -134,8 +134,8 @@ discard block |
||
| 134 | 134 | * @return float |
| 135 | 135 | */ |
| 136 | 136 | function wpinv_get_default_tax_rate() { |
| 137 | - $rate = wpinv_get_option( 'tax_rate', 0 ); |
|
| 138 | - return (float) apply_filters( 'wpinv_get_default_tax_rate', floatval( $rate ) ); |
|
| 137 | + $rate = wpinv_get_option('tax_rate', 0); |
|
| 138 | + return (float) apply_filters('wpinv_get_default_tax_rate', floatval($rate)); |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | /** |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | * @return bool |
| 145 | 145 | */ |
| 146 | 146 | function wpinv_same_country_exempt_vat() { |
| 147 | - return 'no' == wpinv_get_option( 'vat_same_country_rule', 'vat_too' ); |
|
| 147 | + return 'no' == wpinv_get_option('vat_same_country_rule', 'vat_too'); |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | /** |
@@ -164,28 +164,28 @@ discard block |
||
| 164 | 164 | * @param string $state |
| 165 | 165 | * @return array |
| 166 | 166 | */ |
| 167 | -function getpaid_get_item_tax_rates( $item, $country = '', $state = '' ) { |
|
| 167 | +function getpaid_get_item_tax_rates($item, $country = '', $state = '') { |
|
| 168 | 168 | |
| 169 | 169 | // Abort if the item is not taxable. |
| 170 | - if ( ! wpinv_is_item_taxable( $item ) ) { |
|
| 170 | + if (!wpinv_is_item_taxable($item)) { |
|
| 171 | 171 | return array(); |
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | // Maybe use the store address. |
| 175 | - if ( wpinv_use_store_address_as_tax_base() ) { |
|
| 175 | + if (wpinv_use_store_address_as_tax_base()) { |
|
| 176 | 176 | $country = wpinv_get_default_country(); |
| 177 | 177 | $state = wpinv_get_default_state(); |
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | // Retrieve tax rates. |
| 181 | - $tax_rates = GetPaid_Tax::get_address_tax_rates( $country, $state ); |
|
| 181 | + $tax_rates = GetPaid_Tax::get_address_tax_rates($country, $state); |
|
| 182 | 182 | |
| 183 | 183 | // Fallback to the default tax rates if non were found. |
| 184 | - if ( empty( $tax_rates ) ) { |
|
| 184 | + if (empty($tax_rates)) { |
|
| 185 | 185 | $tax_rates = GetPaid_Tax::get_default_tax_rates(); |
| 186 | 186 | } |
| 187 | 187 | |
| 188 | - return apply_filters( 'getpaid_get_item_tax_rates', $tax_rates, $item, $country, $state ); |
|
| 188 | + return apply_filters('getpaid_get_item_tax_rates', $tax_rates, $item, $country, $state); |
|
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | /** |
@@ -195,23 +195,23 @@ discard block |
||
| 195 | 195 | * @param array $rates |
| 196 | 196 | * @return array |
| 197 | 197 | */ |
| 198 | -function getpaid_filter_item_tax_rates( $item, $rates ) { |
|
| 198 | +function getpaid_filter_item_tax_rates($item, $rates) { |
|
| 199 | 199 | |
| 200 | 200 | $tax_class = $item->get_vat_class(); |
| 201 | 201 | |
| 202 | - foreach ( $rates as $i => $rate ) { |
|
| 202 | + foreach ($rates as $i => $rate) { |
|
| 203 | 203 | |
| 204 | - if ( $tax_class == '_reduced' ) { |
|
| 205 | - $rates[ $i ]['rate'] = empty( $rate['reduced_rate'] ) ? 0 : $rate['reduced_rate']; |
|
| 204 | + if ($tax_class == '_reduced') { |
|
| 205 | + $rates[$i]['rate'] = empty($rate['reduced_rate']) ? 0 : $rate['reduced_rate']; |
|
| 206 | 206 | } |
| 207 | 207 | |
| 208 | - if ( $tax_class == '_exempt' ) { |
|
| 209 | - $rates[ $i ]['rate'] = 0; |
|
| 208 | + if ($tax_class == '_exempt') { |
|
| 209 | + $rates[$i]['rate'] = 0; |
|
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | } |
| 213 | 213 | |
| 214 | - return apply_filters( 'getpaid_filter_item_tax_rates', $rates, $item ); |
|
| 214 | + return apply_filters('getpaid_filter_item_tax_rates', $rates, $item); |
|
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | /** |
@@ -221,12 +221,12 @@ discard block |
||
| 221 | 221 | * @param array $rates |
| 222 | 222 | * @return array |
| 223 | 223 | */ |
| 224 | -function getpaid_calculate_item_taxes( $amount, $rates ) { |
|
| 224 | +function getpaid_calculate_item_taxes($amount, $rates) { |
|
| 225 | 225 | |
| 226 | 226 | $is_inclusive = wpinv_prices_include_tax(); |
| 227 | - $taxes = GetPaid_Tax::calc_tax( $amount, $rates, $is_inclusive ); |
|
| 227 | + $taxes = GetPaid_Tax::calc_tax($amount, $rates, $is_inclusive); |
|
| 228 | 228 | |
| 229 | - return apply_filters( 'getpaid_calculate_taxes', $taxes, $amount, $rates ); |
|
| 229 | + return apply_filters('getpaid_calculate_taxes', $taxes, $amount, $rates); |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | /** |
@@ -238,17 +238,17 @@ discard block |
||
| 238 | 238 | * @param float $recurring_tax_amount |
| 239 | 239 | * @return array |
| 240 | 240 | */ |
| 241 | -function getpaid_prepare_item_tax( $item, $tax_name, $tax_amount, $recurring_tax_amount ) { |
|
| 241 | +function getpaid_prepare_item_tax($item, $tax_name, $tax_amount, $recurring_tax_amount) { |
|
| 242 | 242 | |
| 243 | - $initial_tax = $tax_amount; |
|
| 243 | + $initial_tax = $tax_amount; |
|
| 244 | 244 | $recurring_tax = 0; |
| 245 | 245 | |
| 246 | - if ( $item->is_recurring() ) { |
|
| 246 | + if ($item->is_recurring()) { |
|
| 247 | 247 | $recurring_tax = $recurring_tax_amount; |
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | return array( |
| 251 | - 'name' => sanitize_text_field( $tax_name ), |
|
| 251 | + 'name' => sanitize_text_field($tax_name), |
|
| 252 | 252 | 'initial_tax' => $initial_tax, |
| 253 | 253 | 'recurring_tax' => $recurring_tax, |
| 254 | 254 | ); |
@@ -261,8 +261,8 @@ discard block |
||
| 261 | 261 | * @param string $vat_number |
| 262 | 262 | * @return string |
| 263 | 263 | */ |
| 264 | -function wpinv_sanitize_vat_number( $vat_number ) { |
|
| 265 | - return str_replace( array(' ', '.', '-', '_', ',' ), '', strtoupper( trim( $vat_number ) ) ); |
|
| 264 | +function wpinv_sanitize_vat_number($vat_number) { |
|
| 265 | + return str_replace(array(' ', '.', '-', '_', ','), '', strtoupper(trim($vat_number))); |
|
| 266 | 266 | } |
| 267 | 267 | |
| 268 | 268 | /** |
@@ -271,22 +271,22 @@ discard block |
||
| 271 | 271 | * @param string $vat_number |
| 272 | 272 | * @return bool |
| 273 | 273 | */ |
| 274 | -function wpinv_regex_validate_vat_number( $vat_number ) { |
|
| 274 | +function wpinv_regex_validate_vat_number($vat_number) { |
|
| 275 | 275 | |
| 276 | - $country = substr( $vat_number, 0, 2 ); |
|
| 277 | - $vatin = substr( $vat_number, 2 ); |
|
| 278 | - $regexes = wpinv_get_data( 'vat-number-regexes' ); |
|
| 276 | + $country = substr($vat_number, 0, 2); |
|
| 277 | + $vatin = substr($vat_number, 2); |
|
| 278 | + $regexes = wpinv_get_data('vat-number-regexes'); |
|
| 279 | 279 | |
| 280 | - if ( isset( $regexes[ $country ] ) ) { |
|
| 280 | + if (isset($regexes[$country])) { |
|
| 281 | 281 | |
| 282 | - $regex = $regexes[ $country ]; |
|
| 282 | + $regex = $regexes[$country]; |
|
| 283 | 283 | $regex = '/^(?:' . $regex . ')$/'; |
| 284 | - return 1 === preg_match( $regex, $vatin ); |
|
| 284 | + return 1 === preg_match($regex, $vatin); |
|
| 285 | 285 | |
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | // Not an EU state, use filters to validate the number. |
| 289 | - return apply_filters( 'wpinv_regex_validate_vat_number', true, $vat_number ); |
|
| 289 | + return apply_filters('wpinv_regex_validate_vat_number', true, $vat_number); |
|
| 290 | 290 | } |
| 291 | 291 | |
| 292 | 292 | /** |
@@ -295,29 +295,29 @@ discard block |
||
| 295 | 295 | * @param string $vat_number |
| 296 | 296 | * @return bool |
| 297 | 297 | */ |
| 298 | -function wpinv_vies_validate_vat_number( $vat_number ) { |
|
| 298 | +function wpinv_vies_validate_vat_number($vat_number) { |
|
| 299 | 299 | |
| 300 | - $country = substr( $vat_number, 0, 2 ); |
|
| 301 | - $vatin = substr( $vat_number, 2 ); |
|
| 300 | + $country = substr($vat_number, 0, 2); |
|
| 301 | + $vatin = substr($vat_number, 2); |
|
| 302 | 302 | |
| 303 | 303 | $url = add_query_arg( |
| 304 | 304 | array( |
| 305 | - 'ms' => urlencode( $country ), |
|
| 306 | - 'iso' => urlencode( $country ), |
|
| 307 | - 'vat' => urlencode( $vatin ), |
|
| 305 | + 'ms' => urlencode($country), |
|
| 306 | + 'iso' => urlencode($country), |
|
| 307 | + 'vat' => urlencode($vatin), |
|
| 308 | 308 | ), |
| 309 | 309 | 'http://ec.europa.eu/taxation_customs/vies/viesquer.do' |
| 310 | 310 | ); |
| 311 | 311 | |
| 312 | - $response = wp_remote_get( $url ); |
|
| 313 | - $response = wp_remote_retrieve_body( $response ); |
|
| 312 | + $response = wp_remote_get($url); |
|
| 313 | + $response = wp_remote_retrieve_body($response); |
|
| 314 | 314 | |
| 315 | 315 | // Fallback gracefully if the VIES website is down. |
| 316 | - if ( empty( $response ) ) { |
|
| 316 | + if (empty($response)) { |
|
| 317 | 317 | return true; |
| 318 | 318 | } |
| 319 | 319 | |
| 320 | - return 1 !== preg_match( '/invalid VAT number/i', $response ); |
|
| 320 | + return 1 !== preg_match('/invalid VAT number/i', $response); |
|
| 321 | 321 | |
| 322 | 322 | } |
| 323 | 323 | |
@@ -328,18 +328,18 @@ discard block |
||
| 328 | 328 | * @param string $country |
| 329 | 329 | * @return bool |
| 330 | 330 | */ |
| 331 | -function wpinv_validate_vat_number( $vat_number, $country ) { |
|
| 331 | +function wpinv_validate_vat_number($vat_number, $country) { |
|
| 332 | 332 | |
| 333 | 333 | // In case the vat number does not have a country code... |
| 334 | - $vat_number = wpinv_sanitize_vat_number( $vat_number ); |
|
| 335 | - $_country = substr( $vat_number, 0, 2 ); |
|
| 336 | - $_country = $_country == wpinv_country_name( $_country ); |
|
| 334 | + $vat_number = wpinv_sanitize_vat_number($vat_number); |
|
| 335 | + $_country = substr($vat_number, 0, 2); |
|
| 336 | + $_country = $_country == wpinv_country_name($_country); |
|
| 337 | 337 | |
| 338 | - if ( $_country ) { |
|
| 339 | - $vat_number = strtoupper( $country ) . $vat_number; |
|
| 338 | + if ($_country) { |
|
| 339 | + $vat_number = strtoupper($country) . $vat_number; |
|
| 340 | 340 | } |
| 341 | 341 | |
| 342 | - return wpinv_regex_validate_vat_number( $vat_number ) && wpinv_vies_validate_vat_number( $vat_number ); |
|
| 342 | + return wpinv_regex_validate_vat_number($vat_number) && wpinv_vies_validate_vat_number($vat_number); |
|
| 343 | 343 | } |
| 344 | 344 | |
| 345 | 345 | /** |
@@ -348,40 +348,40 @@ discard block |
||
| 348 | 348 | * @return bool |
| 349 | 349 | */ |
| 350 | 350 | function wpinv_should_validate_vat_number() { |
| 351 | - $validate = wpinv_get_option( 'validate_vat_number' ); |
|
| 352 | - return ! empty( $validate ); |
|
| 351 | + $validate = wpinv_get_option('validate_vat_number'); |
|
| 352 | + return !empty($validate); |
|
| 353 | 353 | } |
| 354 | 354 | |
| 355 | -function wpinv_sales_tax_for_year( $year = null ) { |
|
| 356 | - return wpinv_price( wpinv_get_sales_tax_for_year( $year ) ); |
|
| 355 | +function wpinv_sales_tax_for_year($year = null) { |
|
| 356 | + return wpinv_price(wpinv_get_sales_tax_for_year($year)); |
|
| 357 | 357 | } |
| 358 | 358 | |
| 359 | -function wpinv_get_sales_tax_for_year( $year = null ) { |
|
| 359 | +function wpinv_get_sales_tax_for_year($year = null) { |
|
| 360 | 360 | global $wpdb; |
| 361 | 361 | |
| 362 | 362 | // Start at zero |
| 363 | 363 | $tax = 0; |
| 364 | 364 | |
| 365 | - if ( ! empty( $year ) ) { |
|
| 365 | + if (!empty($year)) { |
|
| 366 | 366 | $args = array( |
| 367 | 367 | 'post_type' => 'wpi_invoice', |
| 368 | - 'post_status' => array( 'publish' ), |
|
| 368 | + 'post_status' => array('publish'), |
|
| 369 | 369 | 'posts_per_page' => -1, |
| 370 | 370 | 'year' => $year, |
| 371 | 371 | 'fields' => 'ids' |
| 372 | 372 | ); |
| 373 | 373 | |
| 374 | - $payments = get_posts( $args ); |
|
| 375 | - $payment_ids = implode( ',', $payments ); |
|
| 374 | + $payments = get_posts($args); |
|
| 375 | + $payment_ids = implode(',', $payments); |
|
| 376 | 376 | |
| 377 | - if ( count( $payments ) > 0 ) { |
|
| 377 | + if (count($payments) > 0) { |
|
| 378 | 378 | $sql = "SELECT SUM( meta_value ) FROM $wpdb->postmeta WHERE meta_key = '_wpinv_tax' AND post_id IN( $payment_ids )"; |
| 379 | - $tax = $wpdb->get_var( $sql ); |
|
| 379 | + $tax = $wpdb->get_var($sql); |
|
| 380 | 380 | } |
| 381 | 381 | |
| 382 | 382 | } |
| 383 | 383 | |
| 384 | - return apply_filters( 'wpinv_get_sales_tax_for_year', $tax, $year ); |
|
| 384 | + return apply_filters('wpinv_get_sales_tax_for_year', $tax, $year); |
|
| 385 | 385 | } |
| 386 | 386 | |
| 387 | 387 | function wpinv_is_cart_taxed() { |
@@ -390,33 +390,33 @@ discard block |
||
| 390 | 390 | |
| 391 | 391 | function wpinv_prices_show_tax_on_checkout() { |
| 392 | 392 | return false; // TODO |
| 393 | - $ret = ( wpinv_get_option( 'checkout_include_tax', false ) == 'yes' && wpinv_use_taxes() ); |
|
| 393 | + $ret = (wpinv_get_option('checkout_include_tax', false) == 'yes' && wpinv_use_taxes()); |
|
| 394 | 394 | |
| 395 | - return apply_filters( 'wpinv_taxes_on_prices_on_checkout', $ret ); |
|
| 395 | + return apply_filters('wpinv_taxes_on_prices_on_checkout', $ret); |
|
| 396 | 396 | } |
| 397 | 397 | |
| 398 | 398 | function wpinv_display_tax_rate() { |
| 399 | - $ret = wpinv_use_taxes() && wpinv_get_option( 'display_tax_rate', false ); |
|
| 399 | + $ret = wpinv_use_taxes() && wpinv_get_option('display_tax_rate', false); |
|
| 400 | 400 | |
| 401 | - return apply_filters( 'wpinv_display_tax_rate', $ret ); |
|
| 401 | + return apply_filters('wpinv_display_tax_rate', $ret); |
|
| 402 | 402 | } |
| 403 | 403 | |
| 404 | 404 | function wpinv_cart_needs_tax_address_fields() { |
| 405 | - if( !wpinv_is_cart_taxed() ) |
|
| 405 | + if (!wpinv_is_cart_taxed()) |
|
| 406 | 406 | return false; |
| 407 | 407 | |
| 408 | - return ! did_action( 'wpinv_after_cc_fields', 'wpinv_default_cc_address_fields' ); |
|
| 408 | + return !did_action('wpinv_after_cc_fields', 'wpinv_default_cc_address_fields'); |
|
| 409 | 409 | } |
| 410 | 410 | |
| 411 | -function wpinv_item_is_tax_exclusive( $item_id = 0 ) { |
|
| 412 | - $ret = (bool)get_post_meta( $item_id, '_wpinv_tax_exclusive', false ); |
|
| 413 | - return apply_filters( 'wpinv_is_tax_exclusive', $ret, $item_id ); |
|
| 411 | +function wpinv_item_is_tax_exclusive($item_id = 0) { |
|
| 412 | + $ret = (bool) get_post_meta($item_id, '_wpinv_tax_exclusive', false); |
|
| 413 | + return apply_filters('wpinv_is_tax_exclusive', $ret, $item_id); |
|
| 414 | 414 | } |
| 415 | 415 | |
| 416 | -function wpinv_currency_decimal_filter( $decimals = 2 ) { |
|
| 416 | +function wpinv_currency_decimal_filter($decimals = 2) { |
|
| 417 | 417 | $currency = wpinv_get_currency(); |
| 418 | 418 | |
| 419 | - switch ( $currency ) { |
|
| 419 | + switch ($currency) { |
|
| 420 | 420 | case 'RIAL' : |
| 421 | 421 | case 'JPY' : |
| 422 | 422 | case 'TWD' : |
@@ -425,13 +425,13 @@ discard block |
||
| 425 | 425 | break; |
| 426 | 426 | } |
| 427 | 427 | |
| 428 | - return apply_filters( 'wpinv_currency_decimal_count', $decimals, $currency ); |
|
| 428 | + return apply_filters('wpinv_currency_decimal_count', $decimals, $currency); |
|
| 429 | 429 | } |
| 430 | 430 | |
| 431 | 431 | function wpinv_tax_amount() { |
| 432 | 432 | $output = 0.00; |
| 433 | 433 | |
| 434 | - return apply_filters( 'wpinv_tax_amount', $output ); |
|
| 434 | + return apply_filters('wpinv_tax_amount', $output); |
|
| 435 | 435 | } |
| 436 | 436 | |
| 437 | 437 | /** |
@@ -439,25 +439,25 @@ discard block |
||
| 439 | 439 | * |
| 440 | 440 | * @param string|bool|null $vat_rule |
| 441 | 441 | */ |
| 442 | -function getpaid_filter_vat_rule( $vat_rule ) { |
|
| 442 | +function getpaid_filter_vat_rule($vat_rule) { |
|
| 443 | 443 | |
| 444 | - if ( empty( $vat_rule ) ) { |
|
| 444 | + if (empty($vat_rule)) { |
|
| 445 | 445 | return 'digital'; |
| 446 | 446 | } |
| 447 | 447 | |
| 448 | 448 | return $vat_rule; |
| 449 | 449 | } |
| 450 | -add_filter( 'wpinv_get_item_vat_rule', 'getpaid_filter_vat_rule' ); |
|
| 450 | +add_filter('wpinv_get_item_vat_rule', 'getpaid_filter_vat_rule'); |
|
| 451 | 451 | |
| 452 | 452 | /** |
| 453 | 453 | * Filters the VAT class to ensure that each item has a VAT class. |
| 454 | 454 | * |
| 455 | 455 | * @param string|bool|null $vat_rule |
| 456 | 456 | */ |
| 457 | -function getpaid_filter_vat_class( $vat_class ) { |
|
| 458 | - return empty( $vat_class ) ? '_standard' : $vat_class; |
|
| 457 | +function getpaid_filter_vat_class($vat_class) { |
|
| 458 | + return empty($vat_class) ? '_standard' : $vat_class; |
|
| 459 | 459 | } |
| 460 | -add_filter( 'wpinv_get_item_vat_class', 'getpaid_filter_vat_class' ); |
|
| 460 | +add_filter('wpinv_get_item_vat_class', 'getpaid_filter_vat_class'); |
|
| 461 | 461 | |
| 462 | 462 | /** |
| 463 | 463 | * Returns a list of all tax classes. |
@@ -469,9 +469,9 @@ discard block |
||
| 469 | 469 | return apply_filters( |
| 470 | 470 | 'getpaid_tax_classes', |
| 471 | 471 | array( |
| 472 | - '_standard' => __( 'Standard Tax Rate', 'invoicing' ), |
|
| 473 | - '_reduced' => __( 'Reduced Tax Rate', 'invoicing' ), |
|
| 474 | - '_exempt' => __( 'Tax Exempt', 'invoicing' ), |
|
| 472 | + '_standard' => __('Standard Tax Rate', 'invoicing'), |
|
| 473 | + '_reduced' => __('Reduced Tax Rate', 'invoicing'), |
|
| 474 | + '_exempt' => __('Tax Exempt', 'invoicing'), |
|
| 475 | 475 | ) |
| 476 | 476 | ); |
| 477 | 477 | |
@@ -487,8 +487,8 @@ discard block |
||
| 487 | 487 | return apply_filters( |
| 488 | 488 | 'getpaid_tax_rules', |
| 489 | 489 | array( |
| 490 | - 'physical' => __( 'Physical Item', 'invoicing' ), |
|
| 491 | - 'digital' => __( 'Digital Item', 'invoicing' ), |
|
| 490 | + 'physical' => __('Physical Item', 'invoicing'), |
|
| 491 | + 'digital' => __('Digital Item', 'invoicing'), |
|
| 492 | 492 | ) |
| 493 | 493 | ); |
| 494 | 494 | |
@@ -500,15 +500,15 @@ discard block |
||
| 500 | 500 | * @param string $tax_class |
| 501 | 501 | * @return string |
| 502 | 502 | */ |
| 503 | -function getpaid_get_tax_class_label( $tax_class ) { |
|
| 503 | +function getpaid_get_tax_class_label($tax_class) { |
|
| 504 | 504 | |
| 505 | 505 | $classes = getpaid_get_tax_classes(); |
| 506 | 506 | |
| 507 | - if ( isset( $classes[ $tax_class ] ) ) { |
|
| 508 | - return sanitize_text_field( $classes[ $tax_class ] ); |
|
| 507 | + if (isset($classes[$tax_class])) { |
|
| 508 | + return sanitize_text_field($classes[$tax_class]); |
|
| 509 | 509 | } |
| 510 | 510 | |
| 511 | - return sanitize_text_field( $tax_class ); |
|
| 511 | + return sanitize_text_field($tax_class); |
|
| 512 | 512 | |
| 513 | 513 | } |
| 514 | 514 | |
@@ -518,15 +518,15 @@ discard block |
||
| 518 | 518 | * @param string $tax_rule |
| 519 | 519 | * @return string |
| 520 | 520 | */ |
| 521 | -function getpaid_get_tax_rule_label( $tax_rule ) { |
|
| 521 | +function getpaid_get_tax_rule_label($tax_rule) { |
|
| 522 | 522 | |
| 523 | 523 | $rules = getpaid_get_tax_rules(); |
| 524 | 524 | |
| 525 | - if ( isset( $rules[ $tax_rule ] ) ) { |
|
| 526 | - return sanitize_text_field( $rules[ $tax_rule ] ); |
|
| 525 | + if (isset($rules[$tax_rule])) { |
|
| 526 | + return sanitize_text_field($rules[$tax_rule]); |
|
| 527 | 527 | } |
| 528 | 528 | |
| 529 | - return sanitize_text_field( $tax_rule ); |
|
| 529 | + return sanitize_text_field($tax_rule); |
|
| 530 | 530 | |
| 531 | 531 | } |
| 532 | 532 | |
@@ -537,11 +537,11 @@ discard block |
||
| 537 | 537 | * @param string $recurring |
| 538 | 538 | * @return string |
| 539 | 539 | */ |
| 540 | -function getpaid_get_taxable_amount( $item, $recurring = false ) { |
|
| 540 | +function getpaid_get_taxable_amount($item, $recurring = false) { |
|
| 541 | 541 | |
| 542 | 542 | $taxable_amount = $recurring ? $item->get_recurring_sub_total() : $item->get_sub_total(); |
| 543 | 543 | $taxable_amount -= $recurring ? $item->recurring_item_discount : $item->item_discount; |
| 544 | - $taxable_amount = max( 0, $taxable_amount ); |
|
| 545 | - return apply_filters( 'getpaid_taxable_amount', $taxable_amount, $item, $recurring ); |
|
| 544 | + $taxable_amount = max(0, $taxable_amount); |
|
| 545 | + return apply_filters('getpaid_taxable_amount', $taxable_amount, $item, $recurring); |
|
| 546 | 546 | |
| 547 | 547 | } |
@@ -97,13 +97,13 @@ discard block |
||
| 97 | 97 | */ |
| 98 | 98 | function wpinv_get_invoice_statuses( $draft = false, $trashed = false, $invoice = false ) { |
| 99 | 99 | |
| 100 | - $invoice_statuses = array( |
|
| 101 | - 'wpi-pending' => _x( 'Pending payment', 'Invoice status', 'invoicing' ), |
|
| 100 | + $invoice_statuses = array( |
|
| 101 | + 'wpi-pending' => _x( 'Pending payment', 'Invoice status', 'invoicing' ), |
|
| 102 | 102 | 'publish' => _x( 'Paid', 'Invoice status', 'invoicing' ), |
| 103 | 103 | 'wpi-processing' => _x( 'Processing', 'Invoice status', 'invoicing' ), |
| 104 | - 'wpi-onhold' => _x( 'On hold', 'Invoice status', 'invoicing' ), |
|
| 105 | - 'wpi-cancelled' => _x( 'Cancelled', 'Invoice status', 'invoicing' ), |
|
| 106 | - 'wpi-refunded' => _x( 'Refunded', 'Invoice status', 'invoicing' ), |
|
| 104 | + 'wpi-onhold' => _x( 'On hold', 'Invoice status', 'invoicing' ), |
|
| 105 | + 'wpi-cancelled' => _x( 'Cancelled', 'Invoice status', 'invoicing' ), |
|
| 106 | + 'wpi-refunded' => _x( 'Refunded', 'Invoice status', 'invoicing' ), |
|
| 107 | 107 | 'wpi-failed' => _x( 'Failed', 'Invoice status', 'invoicing' ), |
| 108 | 108 | 'wpi-renewal' => _x( 'Renewal Payment', 'Invoice status', 'invoicing' ), |
| 109 | 109 | ); |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | $invoice = $invoice->get_post_type(); |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | - return apply_filters( 'wpinv_statuses', $invoice_statuses, $invoice ); |
|
| 123 | + return apply_filters( 'wpinv_statuses', $invoice_statuses, $invoice ); |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | /** |
@@ -238,25 +238,25 @@ discard block |
||
| 238 | 238 | * @return string |
| 239 | 239 | */ |
| 240 | 240 | function getpaid_get_price_format() { |
| 241 | - $currency_pos = wpinv_currency_position(); |
|
| 242 | - $format = '%1$s%2$s'; |
|
| 243 | - |
|
| 244 | - switch ( $currency_pos ) { |
|
| 245 | - case 'left': |
|
| 246 | - $format = '%1$s%2$s'; |
|
| 247 | - break; |
|
| 248 | - case 'right': |
|
| 249 | - $format = '%2$s%1$s'; |
|
| 250 | - break; |
|
| 251 | - case 'left_space': |
|
| 252 | - $format = '%1$s %2$s'; |
|
| 253 | - break; |
|
| 254 | - case 'right_space': |
|
| 255 | - $format = '%2$s %1$s'; |
|
| 256 | - break; |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - return apply_filters( 'getpaid_price_format', $format, $currency_pos ); |
|
| 241 | + $currency_pos = wpinv_currency_position(); |
|
| 242 | + $format = '%1$s%2$s'; |
|
| 243 | + |
|
| 244 | + switch ( $currency_pos ) { |
|
| 245 | + case 'left': |
|
| 246 | + $format = '%1$s%2$s'; |
|
| 247 | + break; |
|
| 248 | + case 'right': |
|
| 249 | + $format = '%2$s%1$s'; |
|
| 250 | + break; |
|
| 251 | + case 'left_space': |
|
| 252 | + $format = '%1$s %2$s'; |
|
| 253 | + break; |
|
| 254 | + case 'right_space': |
|
| 255 | + $format = '%2$s %1$s'; |
|
| 256 | + break; |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + return apply_filters( 'getpaid_price_format', $format, $currency_pos ); |
|
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | /** |
@@ -359,13 +359,13 @@ discard block |
||
| 359 | 359 | * @param mixed $value Value. |
| 360 | 360 | */ |
| 361 | 361 | function getpaid_maybe_define_constant( $name, $value ) { |
| 362 | - if ( ! defined( $name ) ) { |
|
| 363 | - define( $name, $value ); |
|
| 364 | - } |
|
| 362 | + if ( ! defined( $name ) ) { |
|
| 363 | + define( $name, $value ); |
|
| 364 | + } |
|
| 365 | 365 | } |
| 366 | 366 | |
| 367 | 367 | function wpinv_get_php_arg_separator_output() { |
| 368 | - return ini_get( 'arg_separator.output' ); |
|
| 368 | + return ini_get( 'arg_separator.output' ); |
|
| 369 | 369 | } |
| 370 | 370 | |
| 371 | 371 | function wpinv_rgb_from_hex( $color ) { |
@@ -716,11 +716,11 @@ discard block |
||
| 716 | 716 | $list = array(); |
| 717 | 717 | } |
| 718 | 718 | |
| 719 | - if ( ! is_array( $list ) ) { |
|
| 720 | - return preg_split( '/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY ); |
|
| 721 | - } |
|
| 719 | + if ( ! is_array( $list ) ) { |
|
| 720 | + return preg_split( '/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY ); |
|
| 721 | + } |
|
| 722 | 722 | |
| 723 | - return $list; |
|
| 723 | + return $list; |
|
| 724 | 724 | } |
| 725 | 725 | |
| 726 | 726 | /** |
@@ -740,9 +740,9 @@ discard block |
||
| 740 | 740 | } |
| 741 | 741 | |
| 742 | 742 | $data = apply_filters( "wpinv_get_$key", include WPINV_PLUGIN_DIR . "includes/data/$key.php" ); |
| 743 | - wp_cache_set( "wpinv-data-$key", $data, 'wpinv' ); |
|
| 743 | + wp_cache_set( "wpinv-data-$key", $data, 'wpinv' ); |
|
| 744 | 744 | |
| 745 | - return $data; |
|
| 745 | + return $data; |
|
| 746 | 746 | } |
| 747 | 747 | |
| 748 | 748 | /** |
@@ -771,17 +771,17 @@ discard block |
||
| 771 | 771 | */ |
| 772 | 772 | function wpinv_clean( $var ) { |
| 773 | 773 | |
| 774 | - if ( is_array( $var ) ) { |
|
| 775 | - return array_map( 'wpinv_clean', $var ); |
|
| 774 | + if ( is_array( $var ) ) { |
|
| 775 | + return array_map( 'wpinv_clean', $var ); |
|
| 776 | 776 | } |
| 777 | 777 | |
| 778 | 778 | if ( is_object( $var ) ) { |
| 779 | - $object_vars = get_object_vars( $var ); |
|
| 780 | - foreach ( $object_vars as $property_name => $property_value ) { |
|
| 781 | - $var->$property_name = wpinv_clean( $property_value ); |
|
| 779 | + $object_vars = get_object_vars( $var ); |
|
| 780 | + foreach ( $object_vars as $property_name => $property_value ) { |
|
| 781 | + $var->$property_name = wpinv_clean( $property_value ); |
|
| 782 | 782 | } |
| 783 | 783 | return $var; |
| 784 | - } |
|
| 784 | + } |
|
| 785 | 785 | |
| 786 | 786 | return is_string( $var ) ? sanitize_text_field( $var ) : $var; |
| 787 | 787 | } |
@@ -794,7 +794,7 @@ discard block |
||
| 794 | 794 | */ |
| 795 | 795 | function getpaid_convert_price_string_to_options( $str ) { |
| 796 | 796 | |
| 797 | - $raw_options = array_map( 'trim', explode( ',', $str ) ); |
|
| 797 | + $raw_options = array_map( 'trim', explode( ',', $str ) ); |
|
| 798 | 798 | $options = array(); |
| 799 | 799 | |
| 800 | 800 | foreach ( $raw_options as $option ) { |
@@ -872,7 +872,7 @@ discard block |
||
| 872 | 872 | * @return string |
| 873 | 873 | */ |
| 874 | 874 | function getpaid_date_format() { |
| 875 | - return apply_filters( 'getpaid_date_format', get_option( 'date_format' ) ); |
|
| 875 | + return apply_filters( 'getpaid_date_format', get_option( 'date_format' ) ); |
|
| 876 | 876 | } |
| 877 | 877 | |
| 878 | 878 | /** |
@@ -881,7 +881,7 @@ discard block |
||
| 881 | 881 | * @return string |
| 882 | 882 | */ |
| 883 | 883 | function getpaid_time_format() { |
| 884 | - return apply_filters( 'getpaid_time_format', get_option( 'time_format' ) ); |
|
| 884 | + return apply_filters( 'getpaid_time_format', get_option( 'time_format' ) ); |
|
| 885 | 885 | } |
| 886 | 886 | |
| 887 | 887 | /** |
@@ -894,15 +894,15 @@ discard block |
||
| 894 | 894 | function getpaid_limit_length( $string, $limit ) { |
| 895 | 895 | $str_limit = $limit - 3; |
| 896 | 896 | |
| 897 | - if ( function_exists( 'mb_strimwidth' ) ) { |
|
| 898 | - if ( mb_strlen( $string ) > $limit ) { |
|
| 899 | - $string = mb_strimwidth( $string, 0, $str_limit ) . '...'; |
|
| 900 | - } |
|
| 901 | - } else { |
|
| 902 | - if ( strlen( $string ) > $limit ) { |
|
| 903 | - $string = substr( $string, 0, $str_limit ) . '...'; |
|
| 904 | - } |
|
| 905 | - } |
|
| 897 | + if ( function_exists( 'mb_strimwidth' ) ) { |
|
| 898 | + if ( mb_strlen( $string ) > $limit ) { |
|
| 899 | + $string = mb_strimwidth( $string, 0, $str_limit ) . '...'; |
|
| 900 | + } |
|
| 901 | + } else { |
|
| 902 | + if ( strlen( $string ) > $limit ) { |
|
| 903 | + $string = substr( $string, 0, $str_limit ) . '...'; |
|
| 904 | + } |
|
| 905 | + } |
|
| 906 | 906 | return $string; |
| 907 | 907 | |
| 908 | 908 | } |
@@ -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 | /** |
@@ -56,23 +56,23 @@ discard block |
||
| 56 | 56 | * |
| 57 | 57 | * @param string $amount The amount to sanitize. |
| 58 | 58 | */ |
| 59 | -function wpinv_sanitize_amount( $amount ) { |
|
| 59 | +function wpinv_sanitize_amount($amount) { |
|
| 60 | 60 | |
| 61 | - if ( is_numeric( $amount ) ) { |
|
| 62 | - return floatval( $amount ); |
|
| 61 | + if (is_numeric($amount)) { |
|
| 62 | + return floatval($amount); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | // Separate the decimals and thousands. |
| 66 | - $amount = explode( wpinv_decimal_separator(), $amount ); |
|
| 66 | + $amount = explode(wpinv_decimal_separator(), $amount); |
|
| 67 | 67 | |
| 68 | 68 | // Remove thousands. |
| 69 | - $amount[0] = str_replace( wpinv_thousands_separator(), '', $amount[0] ); |
|
| 69 | + $amount[0] = str_replace(wpinv_thousands_separator(), '', $amount[0]); |
|
| 70 | 70 | |
| 71 | 71 | // Convert back to string. |
| 72 | - $amount = count( $amount ) > 1 ? "{$amount[0]}.{$amount[1]}" : $amount[0]; |
|
| 72 | + $amount = count($amount) > 1 ? "{$amount[0]}.{$amount[1]}" : $amount[0]; |
|
| 73 | 73 | |
| 74 | 74 | // Cast the remaining to a float. |
| 75 | - return (float) preg_replace( '/[^0-9\.\-]/', '', $amount ); |
|
| 75 | + return (float) preg_replace('/[^0-9\.\-]/', '', $amount); |
|
| 76 | 76 | |
| 77 | 77 | } |
| 78 | 78 | |
@@ -82,19 +82,19 @@ discard block |
||
| 82 | 82 | * @param float $amount |
| 83 | 83 | * @param float|string|int|null $decimals |
| 84 | 84 | */ |
| 85 | -function wpinv_round_amount( $amount, $decimals = null, $use_sprintf = false ) { |
|
| 85 | +function wpinv_round_amount($amount, $decimals = null, $use_sprintf = false) { |
|
| 86 | 86 | |
| 87 | - if ( $decimals === null ) { |
|
| 87 | + if ($decimals === null) { |
|
| 88 | 88 | $decimals = wpinv_decimals(); |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | - if ( $use_sprintf ) { |
|
| 92 | - $amount = sprintf( "%.{$decimals}f", (float) $amount ); |
|
| 91 | + if ($use_sprintf) { |
|
| 92 | + $amount = sprintf("%.{$decimals}f", (float) $amount); |
|
| 93 | 93 | } else { |
| 94 | - $amount = round( (float) $amount, absint( $decimals ) ); |
|
| 94 | + $amount = round((float) $amount, absint($decimals)); |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | - return apply_filters( 'wpinv_round_amount', $amount, $decimals ); |
|
| 97 | + return apply_filters('wpinv_round_amount', $amount, $decimals); |
|
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | /** |
@@ -106,32 +106,32 @@ discard block |
||
| 106 | 106 | * @param string|WPInv_Invoice $invoice The invoice object|post type|type |
| 107 | 107 | * @return array |
| 108 | 108 | */ |
| 109 | -function wpinv_get_invoice_statuses( $draft = false, $trashed = false, $invoice = false ) { |
|
| 109 | +function wpinv_get_invoice_statuses($draft = false, $trashed = false, $invoice = false) { |
|
| 110 | 110 | |
| 111 | 111 | $invoice_statuses = array( |
| 112 | - 'wpi-pending' => _x( 'Pending payment', 'Invoice status', 'invoicing' ), |
|
| 113 | - 'publish' => _x( 'Paid', 'Invoice status', 'invoicing' ), |
|
| 114 | - 'wpi-processing' => _x( 'Processing', 'Invoice status', 'invoicing' ), |
|
| 115 | - 'wpi-onhold' => _x( 'On hold', 'Invoice status', 'invoicing' ), |
|
| 116 | - 'wpi-cancelled' => _x( 'Cancelled', 'Invoice status', 'invoicing' ), |
|
| 117 | - 'wpi-refunded' => _x( 'Refunded', 'Invoice status', 'invoicing' ), |
|
| 118 | - 'wpi-failed' => _x( 'Failed', 'Invoice status', 'invoicing' ), |
|
| 119 | - 'wpi-renewal' => _x( 'Renewal Payment', 'Invoice status', 'invoicing' ), |
|
| 112 | + 'wpi-pending' => _x('Pending payment', 'Invoice status', 'invoicing'), |
|
| 113 | + 'publish' => _x('Paid', 'Invoice status', 'invoicing'), |
|
| 114 | + 'wpi-processing' => _x('Processing', 'Invoice status', 'invoicing'), |
|
| 115 | + 'wpi-onhold' => _x('On hold', 'Invoice status', 'invoicing'), |
|
| 116 | + 'wpi-cancelled' => _x('Cancelled', 'Invoice status', 'invoicing'), |
|
| 117 | + 'wpi-refunded' => _x('Refunded', 'Invoice status', 'invoicing'), |
|
| 118 | + 'wpi-failed' => _x('Failed', 'Invoice status', 'invoicing'), |
|
| 119 | + 'wpi-renewal' => _x('Renewal Payment', 'Invoice status', 'invoicing'), |
|
| 120 | 120 | ); |
| 121 | 121 | |
| 122 | - if ( $draft ) { |
|
| 123 | - $invoice_statuses['draft'] = __( 'Draft', 'invoicing' ); |
|
| 122 | + if ($draft) { |
|
| 123 | + $invoice_statuses['draft'] = __('Draft', 'invoicing'); |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | - if ( $trashed ) { |
|
| 127 | - $invoice_statuses['trash'] = __( 'Trash', 'invoicing' ); |
|
| 126 | + if ($trashed) { |
|
| 127 | + $invoice_statuses['trash'] = __('Trash', 'invoicing'); |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | - if ( $invoice instanceof WPInv_Invoice ) { |
|
| 130 | + if ($invoice instanceof WPInv_Invoice) { |
|
| 131 | 131 | $invoice = $invoice->get_post_type(); |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | - return apply_filters( 'wpinv_statuses', $invoice_statuses, $invoice ); |
|
| 134 | + return apply_filters('wpinv_statuses', $invoice_statuses, $invoice); |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | /** |
@@ -140,11 +140,11 @@ discard block |
||
| 140 | 140 | * @param string $status The raw status |
| 141 | 141 | * @param string|WPInv_Invoice $invoice The invoice object|post type|type |
| 142 | 142 | */ |
| 143 | -function wpinv_status_nicename( $status, $invoice = false ) { |
|
| 144 | - $statuses = wpinv_get_invoice_statuses( true, true, $invoice ); |
|
| 145 | - $status = isset( $statuses[$status] ) ? $statuses[$status] : $status; |
|
| 143 | +function wpinv_status_nicename($status, $invoice = false) { |
|
| 144 | + $statuses = wpinv_get_invoice_statuses(true, true, $invoice); |
|
| 145 | + $status = isset($statuses[$status]) ? $statuses[$status] : $status; |
|
| 146 | 146 | |
| 147 | - return sanitize_text_field( $status ); |
|
| 147 | + return sanitize_text_field($status); |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | /** |
@@ -152,13 +152,13 @@ discard block |
||
| 152 | 152 | * |
| 153 | 153 | * @param string $current |
| 154 | 154 | */ |
| 155 | -function wpinv_get_currency( $current = '' ) { |
|
| 155 | +function wpinv_get_currency($current = '') { |
|
| 156 | 156 | |
| 157 | - if ( empty( $current ) ) { |
|
| 158 | - $current = apply_filters( 'wpinv_currency', wpinv_get_option( 'currency', 'USD' ) ); |
|
| 157 | + if (empty($current)) { |
|
| 158 | + $current = apply_filters('wpinv_currency', wpinv_get_option('currency', 'USD')); |
|
| 159 | 159 | } |
| 160 | 160 | |
| 161 | - return trim( strtoupper( $current ) ); |
|
| 161 | + return trim(strtoupper($current)); |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | /** |
@@ -166,25 +166,25 @@ discard block |
||
| 166 | 166 | * |
| 167 | 167 | * @param string|null $currency The currency code. Defaults to the default currency. |
| 168 | 168 | */ |
| 169 | -function wpinv_currency_symbol( $currency = null ) { |
|
| 169 | +function wpinv_currency_symbol($currency = null) { |
|
| 170 | 170 | |
| 171 | 171 | // Prepare the currency. |
| 172 | - $currency = empty( $currency ) ? wpinv_get_currency() : wpinv_clean( $currency ); |
|
| 172 | + $currency = empty($currency) ? wpinv_get_currency() : wpinv_clean($currency); |
|
| 173 | 173 | |
| 174 | 174 | // Fetch all symbols. |
| 175 | 175 | $symbols = wpinv_get_currency_symbols(); |
| 176 | 176 | |
| 177 | 177 | // Fetch this currencies symbol. |
| 178 | - $currency_symbol = isset( $symbols[$currency] ) ? $symbols[$currency] : $currency; |
|
| 178 | + $currency_symbol = isset($symbols[$currency]) ? $symbols[$currency] : $currency; |
|
| 179 | 179 | |
| 180 | 180 | // Filter the symbol. |
| 181 | - return apply_filters( 'wpinv_currency_symbol', $currency_symbol, $currency ); |
|
| 181 | + return apply_filters('wpinv_currency_symbol', $currency_symbol, $currency); |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | function wpinv_currency_position() { |
| 185 | - $position = wpinv_get_option( 'currency_position', 'left' ); |
|
| 185 | + $position = wpinv_get_option('currency_position', 'left'); |
|
| 186 | 186 | |
| 187 | - return apply_filters( 'wpinv_currency_position', $position ); |
|
| 187 | + return apply_filters('wpinv_currency_position', $position); |
|
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | /** |
@@ -192,13 +192,13 @@ discard block |
||
| 192 | 192 | * |
| 193 | 193 | * @param $string|null $current |
| 194 | 194 | */ |
| 195 | -function wpinv_thousands_separator( $current = null ) { |
|
| 195 | +function wpinv_thousands_separator($current = null) { |
|
| 196 | 196 | |
| 197 | - if ( null == $current ) { |
|
| 198 | - $current = wpinv_get_option( 'thousands_separator', ',' ); |
|
| 197 | + if (null == $current) { |
|
| 198 | + $current = wpinv_get_option('thousands_separator', ','); |
|
| 199 | 199 | } |
| 200 | 200 | |
| 201 | - return trim( $current ); |
|
| 201 | + return trim($current); |
|
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | /** |
@@ -206,13 +206,13 @@ discard block |
||
| 206 | 206 | * |
| 207 | 207 | * @param $string|null $current |
| 208 | 208 | */ |
| 209 | -function wpinv_decimal_separator( $current = null ) { |
|
| 209 | +function wpinv_decimal_separator($current = null) { |
|
| 210 | 210 | |
| 211 | - if ( null == $current ) { |
|
| 212 | - $current = wpinv_get_option( 'decimal_separator', '.' ); |
|
| 211 | + if (null == $current) { |
|
| 212 | + $current = wpinv_get_option('decimal_separator', '.'); |
|
| 213 | 213 | } |
| 214 | 214 | |
| 215 | - return trim( $current ); |
|
| 215 | + return trim($current); |
|
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | /** |
@@ -220,27 +220,27 @@ discard block |
||
| 220 | 220 | * |
| 221 | 221 | * @param $string|null $current |
| 222 | 222 | */ |
| 223 | -function wpinv_decimals( $current = null ) { |
|
| 223 | +function wpinv_decimals($current = null) { |
|
| 224 | 224 | |
| 225 | - if ( null == $current ) { |
|
| 226 | - $current = wpinv_get_option( 'decimals', 2 ); |
|
| 225 | + if (null == $current) { |
|
| 226 | + $current = wpinv_get_option('decimals', 2); |
|
| 227 | 227 | } |
| 228 | 228 | |
| 229 | - return absint( $current ); |
|
| 229 | + return absint($current); |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | /** |
| 233 | 233 | * Retrieves a list of all supported currencies. |
| 234 | 234 | */ |
| 235 | 235 | function wpinv_get_currencies() { |
| 236 | - return apply_filters( 'wpinv_currencies', wpinv_get_data( 'currencies' ) ); |
|
| 236 | + return apply_filters('wpinv_currencies', wpinv_get_data('currencies')); |
|
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | /** |
| 240 | 240 | * Retrieves a list of all currency symbols. |
| 241 | 241 | */ |
| 242 | 242 | function wpinv_get_currency_symbols() { |
| 243 | - return apply_filters( 'wpinv_currency_symbols', wpinv_get_data( 'currency-symbols' ) ); |
|
| 243 | + return apply_filters('wpinv_currency_symbols', wpinv_get_data('currency-symbols')); |
|
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | /** |
@@ -252,7 +252,7 @@ discard block |
||
| 252 | 252 | $currency_pos = wpinv_currency_position(); |
| 253 | 253 | $format = '%1$s%2$s'; |
| 254 | 254 | |
| 255 | - switch ( $currency_pos ) { |
|
| 255 | + switch ($currency_pos) { |
|
| 256 | 256 | case 'left': |
| 257 | 257 | $format = '%1$s%2$s'; |
| 258 | 258 | break; |
@@ -267,7 +267,7 @@ discard block |
||
| 267 | 267 | break; |
| 268 | 268 | } |
| 269 | 269 | |
| 270 | - return apply_filters( 'getpaid_price_format', $format, $currency_pos ); |
|
| 270 | + return apply_filters('getpaid_price_format', $format, $currency_pos); |
|
| 271 | 271 | } |
| 272 | 272 | |
| 273 | 273 | /** |
@@ -277,25 +277,25 @@ discard block |
||
| 277 | 277 | * @param string $currency Currency. |
| 278 | 278 | * @return string |
| 279 | 279 | */ |
| 280 | -function wpinv_price( $amount = 0, $currency = '' ) { |
|
| 280 | +function wpinv_price($amount = 0, $currency = '') { |
|
| 281 | 281 | |
| 282 | 282 | // Backwards compatibility. |
| 283 | - $amount = wpinv_sanitize_amount( $amount ); |
|
| 283 | + $amount = wpinv_sanitize_amount($amount); |
|
| 284 | 284 | |
| 285 | 285 | // Prepare variables. |
| 286 | - $currency = wpinv_get_currency( $currency ); |
|
| 286 | + $currency = wpinv_get_currency($currency); |
|
| 287 | 287 | $amount = (float) $amount; |
| 288 | 288 | $unformatted_amount = $amount; |
| 289 | 289 | $negative = $amount < 0; |
| 290 | - $amount = apply_filters( 'getpaid_raw_amount', floatval( $negative ? $amount * -1 : $amount ) ); |
|
| 291 | - $amount = wpinv_format_amount( $amount ); |
|
| 290 | + $amount = apply_filters('getpaid_raw_amount', floatval($negative ? $amount * -1 : $amount)); |
|
| 291 | + $amount = wpinv_format_amount($amount); |
|
| 292 | 292 | |
| 293 | 293 | // Format the amount. |
| 294 | 294 | $format = getpaid_get_price_format(); |
| 295 | - $formatted_amount = ( $negative ? '-' : '' ) . sprintf( $format, '<span class="getpaid-currency__symbol">' . wpinv_currency_symbol( $currency ) . '</span>', $amount ); |
|
| 295 | + $formatted_amount = ($negative ? '-' : '') . sprintf($format, '<span class="getpaid-currency__symbol">' . wpinv_currency_symbol($currency) . '</span>', $amount); |
|
| 296 | 296 | |
| 297 | 297 | // Filter the formatting. |
| 298 | - return apply_filters( 'wpinv_price', $formatted_amount, $amount, $currency, $unformatted_amount ); |
|
| 298 | + return apply_filters('wpinv_price', $formatted_amount, $amount, $currency, $unformatted_amount); |
|
| 299 | 299 | } |
| 300 | 300 | |
| 301 | 301 | /** |
@@ -306,25 +306,25 @@ discard block |
||
| 306 | 306 | * @param bool $calculate Whether or not to apply separators. |
| 307 | 307 | * @return string |
| 308 | 308 | */ |
| 309 | -function wpinv_format_amount( $amount, $decimals = null, $calculate = false ) { |
|
| 309 | +function wpinv_format_amount($amount, $decimals = null, $calculate = false) { |
|
| 310 | 310 | $thousands_sep = wpinv_thousands_separator(); |
| 311 | 311 | $decimal_sep = wpinv_decimal_separator(); |
| 312 | - $decimals = wpinv_decimals( $decimals ); |
|
| 313 | - $amount = wpinv_sanitize_amount( $amount ); |
|
| 312 | + $decimals = wpinv_decimals($decimals); |
|
| 313 | + $amount = wpinv_sanitize_amount($amount); |
|
| 314 | 314 | |
| 315 | - if ( $calculate ) { |
|
| 315 | + if ($calculate) { |
|
| 316 | 316 | return $amount; |
| 317 | 317 | } |
| 318 | 318 | |
| 319 | 319 | // Fomart the amount. |
| 320 | - return number_format( $amount, $decimals, $decimal_sep, $thousands_sep ); |
|
| 320 | + return number_format($amount, $decimals, $decimal_sep, $thousands_sep); |
|
| 321 | 321 | } |
| 322 | 322 | |
| 323 | -function wpinv_sanitize_key( $key ) { |
|
| 323 | +function wpinv_sanitize_key($key) { |
|
| 324 | 324 | $raw_key = $key; |
| 325 | - $key = preg_replace( '/[^a-zA-Z0-9_\-\.\:\/]/', '', $key ); |
|
| 325 | + $key = preg_replace('/[^a-zA-Z0-9_\-\.\:\/]/', '', $key); |
|
| 326 | 326 | |
| 327 | - return apply_filters( 'wpinv_sanitize_key', $key, $raw_key ); |
|
| 327 | + return apply_filters('wpinv_sanitize_key', $key, $raw_key); |
|
| 328 | 328 | } |
| 329 | 329 | |
| 330 | 330 | /** |
@@ -332,8 +332,8 @@ discard block |
||
| 332 | 332 | * |
| 333 | 333 | * @param $str the file whose extension should be retrieved. |
| 334 | 334 | */ |
| 335 | -function wpinv_get_file_extension( $str ) { |
|
| 336 | - $filetype = wp_check_filetype( $str ); |
|
| 335 | +function wpinv_get_file_extension($str) { |
|
| 336 | + $filetype = wp_check_filetype($str); |
|
| 337 | 337 | return $filetype['ext']; |
| 338 | 338 | } |
| 339 | 339 | |
@@ -342,16 +342,16 @@ discard block |
||
| 342 | 342 | * |
| 343 | 343 | * @param string $string |
| 344 | 344 | */ |
| 345 | -function wpinv_string_is_image_url( $string ) { |
|
| 346 | - $extension = strtolower( wpinv_get_file_extension( $string ) ); |
|
| 347 | - return in_array( $extension, array( 'jpeg', 'jpg', 'png', 'gif', 'ico' ), true ); |
|
| 345 | +function wpinv_string_is_image_url($string) { |
|
| 346 | + $extension = strtolower(wpinv_get_file_extension($string)); |
|
| 347 | + return in_array($extension, array('jpeg', 'jpg', 'png', 'gif', 'ico'), true); |
|
| 348 | 348 | } |
| 349 | 349 | |
| 350 | 350 | /** |
| 351 | 351 | * Returns the current URL. |
| 352 | 352 | */ |
| 353 | 353 | function wpinv_get_current_page_url() { |
| 354 | - return ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; |
|
| 354 | + return (is_ssl() ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; |
|
| 355 | 355 | } |
| 356 | 356 | |
| 357 | 357 | /** |
@@ -361,46 +361,46 @@ discard block |
||
| 361 | 361 | * @param string $name Constant name. |
| 362 | 362 | * @param mixed $value Value. |
| 363 | 363 | */ |
| 364 | -function getpaid_maybe_define_constant( $name, $value ) { |
|
| 365 | - if ( ! defined( $name ) ) { |
|
| 366 | - define( $name, $value ); |
|
| 364 | +function getpaid_maybe_define_constant($name, $value) { |
|
| 365 | + if (!defined($name)) { |
|
| 366 | + define($name, $value); |
|
| 367 | 367 | } |
| 368 | 368 | } |
| 369 | 369 | |
| 370 | 370 | function wpinv_get_php_arg_separator_output() { |
| 371 | - return ini_get( 'arg_separator.output' ); |
|
| 371 | + return ini_get('arg_separator.output'); |
|
| 372 | 372 | } |
| 373 | 373 | |
| 374 | -function wpinv_rgb_from_hex( $color ) { |
|
| 375 | - $color = str_replace( '#', '', $color ); |
|
| 374 | +function wpinv_rgb_from_hex($color) { |
|
| 375 | + $color = str_replace('#', '', $color); |
|
| 376 | 376 | |
| 377 | 377 | // Convert shorthand colors to full format, e.g. "FFF" -> "FFFFFF" |
| 378 | - $color = preg_replace( '~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color ); |
|
| 379 | - if ( empty( $color ) ) { |
|
| 378 | + $color = preg_replace('~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color); |
|
| 379 | + if (empty($color)) { |
|
| 380 | 380 | return NULL; |
| 381 | 381 | } |
| 382 | 382 | |
| 383 | - $color = str_split( $color ); |
|
| 383 | + $color = str_split($color); |
|
| 384 | 384 | |
| 385 | 385 | $rgb = array(); |
| 386 | - $rgb['R'] = hexdec( $color[0] . $color[1] ); |
|
| 387 | - $rgb['G'] = hexdec( $color[2] . $color[3] ); |
|
| 388 | - $rgb['B'] = hexdec( $color[4] . $color[5] ); |
|
| 386 | + $rgb['R'] = hexdec($color[0] . $color[1]); |
|
| 387 | + $rgb['G'] = hexdec($color[2] . $color[3]); |
|
| 388 | + $rgb['B'] = hexdec($color[4] . $color[5]); |
|
| 389 | 389 | |
| 390 | 390 | return $rgb; |
| 391 | 391 | } |
| 392 | 392 | |
| 393 | -function wpinv_hex_darker( $color, $factor = 30 ) { |
|
| 394 | - $base = wpinv_rgb_from_hex( $color ); |
|
| 393 | +function wpinv_hex_darker($color, $factor = 30) { |
|
| 394 | + $base = wpinv_rgb_from_hex($color); |
|
| 395 | 395 | $color = '#'; |
| 396 | 396 | |
| 397 | - foreach ( $base as $k => $v ) { |
|
| 397 | + foreach ($base as $k => $v) { |
|
| 398 | 398 | $amount = $v / 100; |
| 399 | - $amount = round( $amount * $factor ); |
|
| 399 | + $amount = round($amount * $factor); |
|
| 400 | 400 | $new_decimal = $v - $amount; |
| 401 | 401 | |
| 402 | - $new_hex_component = dechex( $new_decimal ); |
|
| 403 | - if ( strlen( $new_hex_component ) < 2 ) { |
|
| 402 | + $new_hex_component = dechex($new_decimal); |
|
| 403 | + if (strlen($new_hex_component) < 2) { |
|
| 404 | 404 | $new_hex_component = "0" . $new_hex_component; |
| 405 | 405 | } |
| 406 | 406 | $color .= $new_hex_component; |
@@ -409,18 +409,18 @@ discard block |
||
| 409 | 409 | return $color; |
| 410 | 410 | } |
| 411 | 411 | |
| 412 | -function wpinv_hex_lighter( $color, $factor = 30 ) { |
|
| 413 | - $base = wpinv_rgb_from_hex( $color ); |
|
| 412 | +function wpinv_hex_lighter($color, $factor = 30) { |
|
| 413 | + $base = wpinv_rgb_from_hex($color); |
|
| 414 | 414 | $color = '#'; |
| 415 | 415 | |
| 416 | - foreach ( $base as $k => $v ) { |
|
| 416 | + foreach ($base as $k => $v) { |
|
| 417 | 417 | $amount = 255 - $v; |
| 418 | 418 | $amount = $amount / 100; |
| 419 | - $amount = round( $amount * $factor ); |
|
| 419 | + $amount = round($amount * $factor); |
|
| 420 | 420 | $new_decimal = $v + $amount; |
| 421 | 421 | |
| 422 | - $new_hex_component = dechex( $new_decimal ); |
|
| 423 | - if ( strlen( $new_hex_component ) < 2 ) { |
|
| 422 | + $new_hex_component = dechex($new_decimal); |
|
| 423 | + if (strlen($new_hex_component) < 2) { |
|
| 424 | 424 | $new_hex_component = "0" . $new_hex_component; |
| 425 | 425 | } |
| 426 | 426 | $color .= $new_hex_component; |
@@ -429,22 +429,22 @@ discard block |
||
| 429 | 429 | return $color; |
| 430 | 430 | } |
| 431 | 431 | |
| 432 | -function wpinv_light_or_dark( $color, $dark = '#000000', $light = '#FFFFFF' ) { |
|
| 433 | - $hex = str_replace( '#', '', $color ); |
|
| 432 | +function wpinv_light_or_dark($color, $dark = '#000000', $light = '#FFFFFF') { |
|
| 433 | + $hex = str_replace('#', '', $color); |
|
| 434 | 434 | |
| 435 | - $c_r = hexdec( substr( $hex, 0, 2 ) ); |
|
| 436 | - $c_g = hexdec( substr( $hex, 2, 2 ) ); |
|
| 437 | - $c_b = hexdec( substr( $hex, 4, 2 ) ); |
|
| 435 | + $c_r = hexdec(substr($hex, 0, 2)); |
|
| 436 | + $c_g = hexdec(substr($hex, 2, 2)); |
|
| 437 | + $c_b = hexdec(substr($hex, 4, 2)); |
|
| 438 | 438 | |
| 439 | - $brightness = ( ( $c_r * 299 ) + ( $c_g * 587 ) + ( $c_b * 114 ) ) / 1000; |
|
| 439 | + $brightness = (($c_r * 299) + ($c_g * 587) + ($c_b * 114)) / 1000; |
|
| 440 | 440 | |
| 441 | 441 | return $brightness > 155 ? $dark : $light; |
| 442 | 442 | } |
| 443 | 443 | |
| 444 | -function wpinv_format_hex( $hex ) { |
|
| 445 | - $hex = trim( str_replace( '#', '', $hex ) ); |
|
| 444 | +function wpinv_format_hex($hex) { |
|
| 445 | + $hex = trim(str_replace('#', '', $hex)); |
|
| 446 | 446 | |
| 447 | - if ( strlen( $hex ) == 3 ) { |
|
| 447 | + if (strlen($hex) == 3) { |
|
| 448 | 448 | $hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2]; |
| 449 | 449 | } |
| 450 | 450 | |
@@ -464,12 +464,12 @@ discard block |
||
| 464 | 464 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
| 465 | 465 | * @return string |
| 466 | 466 | */ |
| 467 | -function wpinv_utf8_strimwidth( $str, $start, $width, $trimmaker = '', $encoding = 'UTF-8' ) { |
|
| 468 | - if ( function_exists( 'mb_strimwidth' ) ) { |
|
| 469 | - return mb_strimwidth( $str, $start, $width, $trimmaker, $encoding ); |
|
| 467 | +function wpinv_utf8_strimwidth($str, $start, $width, $trimmaker = '', $encoding = 'UTF-8') { |
|
| 468 | + if (function_exists('mb_strimwidth')) { |
|
| 469 | + return mb_strimwidth($str, $start, $width, $trimmaker, $encoding); |
|
| 470 | 470 | } |
| 471 | 471 | |
| 472 | - return wpinv_utf8_substr( $str, $start, $width, $encoding ) . $trimmaker; |
|
| 472 | + return wpinv_utf8_substr($str, $start, $width, $encoding) . $trimmaker; |
|
| 473 | 473 | } |
| 474 | 474 | |
| 475 | 475 | /** |
@@ -481,28 +481,28 @@ discard block |
||
| 481 | 481 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
| 482 | 482 | * @return int Returns the number of characters in string. |
| 483 | 483 | */ |
| 484 | -function wpinv_utf8_strlen( $str, $encoding = 'UTF-8' ) { |
|
| 485 | - if ( function_exists( 'mb_strlen' ) ) { |
|
| 486 | - return mb_strlen( $str, $encoding ); |
|
| 484 | +function wpinv_utf8_strlen($str, $encoding = 'UTF-8') { |
|
| 485 | + if (function_exists('mb_strlen')) { |
|
| 486 | + return mb_strlen($str, $encoding); |
|
| 487 | 487 | } |
| 488 | 488 | |
| 489 | - return strlen( $str ); |
|
| 489 | + return strlen($str); |
|
| 490 | 490 | } |
| 491 | 491 | |
| 492 | -function wpinv_utf8_strtolower( $str, $encoding = 'UTF-8' ) { |
|
| 493 | - if ( function_exists( 'mb_strtolower' ) ) { |
|
| 494 | - return mb_strtolower( $str, $encoding ); |
|
| 492 | +function wpinv_utf8_strtolower($str, $encoding = 'UTF-8') { |
|
| 493 | + if (function_exists('mb_strtolower')) { |
|
| 494 | + return mb_strtolower($str, $encoding); |
|
| 495 | 495 | } |
| 496 | 496 | |
| 497 | - return strtolower( $str ); |
|
| 497 | + return strtolower($str); |
|
| 498 | 498 | } |
| 499 | 499 | |
| 500 | -function wpinv_utf8_strtoupper( $str, $encoding = 'UTF-8' ) { |
|
| 501 | - if ( function_exists( 'mb_strtoupper' ) ) { |
|
| 502 | - return mb_strtoupper( $str, $encoding ); |
|
| 500 | +function wpinv_utf8_strtoupper($str, $encoding = 'UTF-8') { |
|
| 501 | + if (function_exists('mb_strtoupper')) { |
|
| 502 | + return mb_strtoupper($str, $encoding); |
|
| 503 | 503 | } |
| 504 | 504 | |
| 505 | - return strtoupper( $str ); |
|
| 505 | + return strtoupper($str); |
|
| 506 | 506 | } |
| 507 | 507 | |
| 508 | 508 | /** |
@@ -516,12 +516,12 @@ discard block |
||
| 516 | 516 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
| 517 | 517 | * @return int Returns the position of the first occurrence of search in the string. |
| 518 | 518 | */ |
| 519 | -function wpinv_utf8_strpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) { |
|
| 520 | - if ( function_exists( 'mb_strpos' ) ) { |
|
| 521 | - return mb_strpos( $str, $find, $offset, $encoding ); |
|
| 519 | +function wpinv_utf8_strpos($str, $find, $offset = 0, $encoding = 'UTF-8') { |
|
| 520 | + if (function_exists('mb_strpos')) { |
|
| 521 | + return mb_strpos($str, $find, $offset, $encoding); |
|
| 522 | 522 | } |
| 523 | 523 | |
| 524 | - return strpos( $str, $find, $offset ); |
|
| 524 | + return strpos($str, $find, $offset); |
|
| 525 | 525 | } |
| 526 | 526 | |
| 527 | 527 | /** |
@@ -535,12 +535,12 @@ discard block |
||
| 535 | 535 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
| 536 | 536 | * @return int Returns the position of the last occurrence of search. |
| 537 | 537 | */ |
| 538 | -function wpinv_utf8_strrpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) { |
|
| 539 | - if ( function_exists( 'mb_strrpos' ) ) { |
|
| 540 | - return mb_strrpos( $str, $find, $offset, $encoding ); |
|
| 538 | +function wpinv_utf8_strrpos($str, $find, $offset = 0, $encoding = 'UTF-8') { |
|
| 539 | + if (function_exists('mb_strrpos')) { |
|
| 540 | + return mb_strrpos($str, $find, $offset, $encoding); |
|
| 541 | 541 | } |
| 542 | 542 | |
| 543 | - return strrpos( $str, $find, $offset ); |
|
| 543 | + return strrpos($str, $find, $offset); |
|
| 544 | 544 | } |
| 545 | 545 | |
| 546 | 546 | /** |
@@ -555,16 +555,16 @@ discard block |
||
| 555 | 555 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
| 556 | 556 | * @return string |
| 557 | 557 | */ |
| 558 | -function wpinv_utf8_substr( $str, $start, $length = null, $encoding = 'UTF-8' ) { |
|
| 559 | - if ( function_exists( 'mb_substr' ) ) { |
|
| 560 | - if ( $length === null ) { |
|
| 561 | - return mb_substr( $str, $start, wpinv_utf8_strlen( $str, $encoding ), $encoding ); |
|
| 558 | +function wpinv_utf8_substr($str, $start, $length = null, $encoding = 'UTF-8') { |
|
| 559 | + if (function_exists('mb_substr')) { |
|
| 560 | + if ($length === null) { |
|
| 561 | + return mb_substr($str, $start, wpinv_utf8_strlen($str, $encoding), $encoding); |
|
| 562 | 562 | } else { |
| 563 | - return mb_substr( $str, $start, $length, $encoding ); |
|
| 563 | + return mb_substr($str, $start, $length, $encoding); |
|
| 564 | 564 | } |
| 565 | 565 | } |
| 566 | 566 | |
| 567 | - return substr( $str, $start, $length ); |
|
| 567 | + return substr($str, $start, $length); |
|
| 568 | 568 | } |
| 569 | 569 | |
| 570 | 570 | /** |
@@ -576,48 +576,48 @@ discard block |
||
| 576 | 576 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
| 577 | 577 | * @return string The width of string. |
| 578 | 578 | */ |
| 579 | -function wpinv_utf8_strwidth( $str, $encoding = 'UTF-8' ) { |
|
| 580 | - if ( function_exists( 'mb_strwidth' ) ) { |
|
| 581 | - return mb_strwidth( $str, $encoding ); |
|
| 579 | +function wpinv_utf8_strwidth($str, $encoding = 'UTF-8') { |
|
| 580 | + if (function_exists('mb_strwidth')) { |
|
| 581 | + return mb_strwidth($str, $encoding); |
|
| 582 | 582 | } |
| 583 | 583 | |
| 584 | - return wpinv_utf8_strlen( $str, $encoding ); |
|
| 584 | + return wpinv_utf8_strlen($str, $encoding); |
|
| 585 | 585 | } |
| 586 | 586 | |
| 587 | -function wpinv_utf8_ucfirst( $str, $lower_str_end = false, $encoding = 'UTF-8' ) { |
|
| 588 | - if ( function_exists( 'mb_strlen' ) ) { |
|
| 589 | - $first_letter = wpinv_utf8_strtoupper( wpinv_utf8_substr( $str, 0, 1, $encoding ), $encoding ); |
|
| 587 | +function wpinv_utf8_ucfirst($str, $lower_str_end = false, $encoding = 'UTF-8') { |
|
| 588 | + if (function_exists('mb_strlen')) { |
|
| 589 | + $first_letter = wpinv_utf8_strtoupper(wpinv_utf8_substr($str, 0, 1, $encoding), $encoding); |
|
| 590 | 590 | $str_end = ""; |
| 591 | 591 | |
| 592 | - if ( $lower_str_end ) { |
|
| 593 | - $str_end = wpinv_utf8_strtolower( wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding ), $encoding ); |
|
| 592 | + if ($lower_str_end) { |
|
| 593 | + $str_end = wpinv_utf8_strtolower(wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding), $encoding); |
|
| 594 | 594 | } else { |
| 595 | - $str_end = wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding ); |
|
| 595 | + $str_end = wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding); |
|
| 596 | 596 | } |
| 597 | 597 | |
| 598 | 598 | return $first_letter . $str_end; |
| 599 | 599 | } |
| 600 | 600 | |
| 601 | - return ucfirst( $str ); |
|
| 601 | + return ucfirst($str); |
|
| 602 | 602 | } |
| 603 | 603 | |
| 604 | -function wpinv_utf8_ucwords( $str, $encoding = 'UTF-8' ) { |
|
| 605 | - if ( function_exists( 'mb_convert_case' ) ) { |
|
| 606 | - return mb_convert_case( $str, MB_CASE_TITLE, $encoding ); |
|
| 604 | +function wpinv_utf8_ucwords($str, $encoding = 'UTF-8') { |
|
| 605 | + if (function_exists('mb_convert_case')) { |
|
| 606 | + return mb_convert_case($str, MB_CASE_TITLE, $encoding); |
|
| 607 | 607 | } |
| 608 | 608 | |
| 609 | - return ucwords( $str ); |
|
| 609 | + return ucwords($str); |
|
| 610 | 610 | } |
| 611 | 611 | |
| 612 | -function wpinv_period_in_days( $period, $unit ) { |
|
| 613 | - $period = absint( $period ); |
|
| 612 | +function wpinv_period_in_days($period, $unit) { |
|
| 613 | + $period = absint($period); |
|
| 614 | 614 | |
| 615 | - if ( $period > 0 ) { |
|
| 616 | - if ( in_array( strtolower( $unit ), array( 'w', 'week', 'weeks' ) ) ) { |
|
| 615 | + if ($period > 0) { |
|
| 616 | + if (in_array(strtolower($unit), array('w', 'week', 'weeks'))) { |
|
| 617 | 617 | $period = $period * 7; |
| 618 | - } else if ( in_array( strtolower( $unit ), array( 'm', 'month', 'months' ) ) ) { |
|
| 618 | + } else if (in_array(strtolower($unit), array('m', 'month', 'months'))) { |
|
| 619 | 619 | $period = $period * 30; |
| 620 | - } else if ( in_array( strtolower( $unit ), array( 'y', 'year', 'years' ) ) ) { |
|
| 620 | + } else if (in_array(strtolower($unit), array('y', 'year', 'years'))) { |
|
| 621 | 621 | $period = $period * 365; |
| 622 | 622 | } |
| 623 | 623 | } |
@@ -625,14 +625,14 @@ discard block |
||
| 625 | 625 | return $period; |
| 626 | 626 | } |
| 627 | 627 | |
| 628 | -function wpinv_cal_days_in_month( $calendar, $month, $year ) { |
|
| 629 | - if ( function_exists( 'cal_days_in_month' ) ) { |
|
| 630 | - return cal_days_in_month( $calendar, $month, $year ); |
|
| 628 | +function wpinv_cal_days_in_month($calendar, $month, $year) { |
|
| 629 | + if (function_exists('cal_days_in_month')) { |
|
| 630 | + return cal_days_in_month($calendar, $month, $year); |
|
| 631 | 631 | } |
| 632 | 632 | |
| 633 | 633 | // Fallback in case the calendar extension is not loaded in PHP |
| 634 | 634 | // Only supports Gregorian calendar |
| 635 | - return date( 't', mktime( 0, 0, 0, $month, 1, $year ) ); |
|
| 635 | + return date('t', mktime(0, 0, 0, $month, 1, $year)); |
|
| 636 | 636 | } |
| 637 | 637 | |
| 638 | 638 | /** |
@@ -643,12 +643,12 @@ discard block |
||
| 643 | 643 | * |
| 644 | 644 | * @return string |
| 645 | 645 | */ |
| 646 | -function wpi_help_tip( $tip, $allow_html = false ) { |
|
| 646 | +function wpi_help_tip($tip, $allow_html = false) { |
|
| 647 | 647 | |
| 648 | - if ( $allow_html ) { |
|
| 649 | - $tip = wpi_sanitize_tooltip( $tip ); |
|
| 648 | + if ($allow_html) { |
|
| 649 | + $tip = wpi_sanitize_tooltip($tip); |
|
| 650 | 650 | } else { |
| 651 | - $tip = esc_attr( $tip ); |
|
| 651 | + $tip = esc_attr($tip); |
|
| 652 | 652 | } |
| 653 | 653 | |
| 654 | 654 | return '<span class="wpi-help-tip dashicons dashicons-editor-help" title="' . $tip . '"></span>'; |
@@ -662,8 +662,8 @@ discard block |
||
| 662 | 662 | * @param string $var |
| 663 | 663 | * @return string |
| 664 | 664 | */ |
| 665 | -function wpi_sanitize_tooltip( $var ) { |
|
| 666 | - return wp_kses( html_entity_decode( $var ), array( |
|
| 665 | +function wpi_sanitize_tooltip($var) { |
|
| 666 | + return wp_kses(html_entity_decode($var), array( |
|
| 667 | 667 | 'br' => array(), |
| 668 | 668 | 'em' => array(), |
| 669 | 669 | 'strong' => array(), |
@@ -674,7 +674,7 @@ discard block |
||
| 674 | 674 | 'li' => array(), |
| 675 | 675 | 'ol' => array(), |
| 676 | 676 | 'p' => array(), |
| 677 | - ) ); |
|
| 677 | + )); |
|
| 678 | 678 | } |
| 679 | 679 | |
| 680 | 680 | /** |
@@ -684,7 +684,7 @@ discard block |
||
| 684 | 684 | */ |
| 685 | 685 | function wpinv_get_screen_ids() { |
| 686 | 686 | |
| 687 | - $screen_id = sanitize_title( __( 'Invoicing', 'invoicing' ) ); |
|
| 687 | + $screen_id = sanitize_title(__('Invoicing', 'invoicing')); |
|
| 688 | 688 | |
| 689 | 689 | $screen_ids = array( |
| 690 | 690 | 'toplevel_page_' . $screen_id, |
@@ -705,7 +705,7 @@ discard block |
||
| 705 | 705 | 'getpaid_page_wpinv-customers', |
| 706 | 706 | ); |
| 707 | 707 | |
| 708 | - return apply_filters( 'wpinv_screen_ids', $screen_ids ); |
|
| 708 | + return apply_filters('wpinv_screen_ids', $screen_ids); |
|
| 709 | 709 | } |
| 710 | 710 | |
| 711 | 711 | /** |
@@ -716,14 +716,14 @@ discard block |
||
| 716 | 716 | * @param array|string $list List of values. |
| 717 | 717 | * @return array Sanitized array of values. |
| 718 | 718 | */ |
| 719 | -function wpinv_parse_list( $list ) { |
|
| 719 | +function wpinv_parse_list($list) { |
|
| 720 | 720 | |
| 721 | - if ( empty( $list ) ) { |
|
| 721 | + if (empty($list)) { |
|
| 722 | 722 | $list = array(); |
| 723 | 723 | } |
| 724 | 724 | |
| 725 | - if ( ! is_array( $list ) ) { |
|
| 726 | - return preg_split( '/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY ); |
|
| 725 | + if (!is_array($list)) { |
|
| 726 | + return preg_split('/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY); |
|
| 727 | 727 | } |
| 728 | 728 | |
| 729 | 729 | return $list; |
@@ -737,16 +737,16 @@ discard block |
||
| 737 | 737 | * @param string $key Type of data to fetch. |
| 738 | 738 | * @return mixed Fetched data. |
| 739 | 739 | */ |
| 740 | -function wpinv_get_data( $key ) { |
|
| 740 | +function wpinv_get_data($key) { |
|
| 741 | 741 | |
| 742 | 742 | // Try fetching it from the cache. |
| 743 | - $data = wp_cache_get( "wpinv-data-$key", 'wpinv' ); |
|
| 744 | - if( $data ) { |
|
| 743 | + $data = wp_cache_get("wpinv-data-$key", 'wpinv'); |
|
| 744 | + if ($data) { |
|
| 745 | 745 | return $data; |
| 746 | 746 | } |
| 747 | 747 | |
| 748 | - $data = apply_filters( "wpinv_get_$key", include WPINV_PLUGIN_DIR . "includes/data/$key.php" ); |
|
| 749 | - wp_cache_set( "wpinv-data-$key", $data, 'wpinv' ); |
|
| 748 | + $data = apply_filters("wpinv_get_$key", include WPINV_PLUGIN_DIR . "includes/data/$key.php"); |
|
| 749 | + wp_cache_set("wpinv-data-$key", $data, 'wpinv'); |
|
| 750 | 750 | |
| 751 | 751 | return $data; |
| 752 | 752 | } |
@@ -760,10 +760,10 @@ discard block |
||
| 760 | 760 | * @param bool $first_empty Whether or not the first item in the list should be empty |
| 761 | 761 | * @return mixed Fetched data. |
| 762 | 762 | */ |
| 763 | -function wpinv_maybe_add_empty_option( $options, $first_empty ) { |
|
| 763 | +function wpinv_maybe_add_empty_option($options, $first_empty) { |
|
| 764 | 764 | |
| 765 | - if ( ! empty( $options ) && $first_empty ) { |
|
| 766 | - return array_merge( array( '' => '' ), $options ); |
|
| 765 | + if (!empty($options) && $first_empty) { |
|
| 766 | + return array_merge(array('' => ''), $options); |
|
| 767 | 767 | } |
| 768 | 768 | return $options; |
| 769 | 769 | |
@@ -775,21 +775,21 @@ discard block |
||
| 775 | 775 | * @param mixed $var Data to sanitize. |
| 776 | 776 | * @return string|array |
| 777 | 777 | */ |
| 778 | -function wpinv_clean( $var ) { |
|
| 778 | +function wpinv_clean($var) { |
|
| 779 | 779 | |
| 780 | - if ( is_array( $var ) ) { |
|
| 781 | - return array_map( 'wpinv_clean', $var ); |
|
| 780 | + if (is_array($var)) { |
|
| 781 | + return array_map('wpinv_clean', $var); |
|
| 782 | 782 | } |
| 783 | 783 | |
| 784 | - if ( is_object( $var ) ) { |
|
| 785 | - $object_vars = get_object_vars( $var ); |
|
| 786 | - foreach ( $object_vars as $property_name => $property_value ) { |
|
| 787 | - $var->$property_name = wpinv_clean( $property_value ); |
|
| 784 | + if (is_object($var)) { |
|
| 785 | + $object_vars = get_object_vars($var); |
|
| 786 | + foreach ($object_vars as $property_name => $property_value) { |
|
| 787 | + $var->$property_name = wpinv_clean($property_value); |
|
| 788 | 788 | } |
| 789 | 789 | return $var; |
| 790 | 790 | } |
| 791 | 791 | |
| 792 | - return is_string( $var ) ? sanitize_text_field( $var ) : $var; |
|
| 792 | + return is_string($var) ? sanitize_text_field($var) : $var; |
|
| 793 | 793 | } |
| 794 | 794 | |
| 795 | 795 | /** |
@@ -798,43 +798,43 @@ discard block |
||
| 798 | 798 | * @param string $str Data to convert. |
| 799 | 799 | * @return string|array |
| 800 | 800 | */ |
| 801 | -function getpaid_convert_price_string_to_options( $str ) { |
|
| 801 | +function getpaid_convert_price_string_to_options($str) { |
|
| 802 | 802 | |
| 803 | - $raw_options = array_map( 'trim', explode( ',', $str ) ); |
|
| 804 | - $options = array(); |
|
| 803 | + $raw_options = array_map('trim', explode(',', $str)); |
|
| 804 | + $options = array(); |
|
| 805 | 805 | |
| 806 | - foreach ( $raw_options as $option ) { |
|
| 806 | + foreach ($raw_options as $option) { |
|
| 807 | 807 | |
| 808 | - if ( '' == $option ) { |
|
| 808 | + if ('' == $option) { |
|
| 809 | 809 | continue; |
| 810 | 810 | } |
| 811 | 811 | |
| 812 | - $option = array_map( 'trim', explode( '|', $option ) ); |
|
| 812 | + $option = array_map('trim', explode('|', $option)); |
|
| 813 | 813 | |
| 814 | 814 | $price = null; |
| 815 | 815 | $label = null; |
| 816 | 816 | |
| 817 | - if ( isset( $option[0] ) && '' != $option[0] ) { |
|
| 818 | - $label = $option[0]; |
|
| 817 | + if (isset($option[0]) && '' != $option[0]) { |
|
| 818 | + $label = $option[0]; |
|
| 819 | 819 | } |
| 820 | 820 | |
| 821 | - if ( isset( $option[1] ) && '' != $option[1] ) { |
|
| 821 | + if (isset($option[1]) && '' != $option[1]) { |
|
| 822 | 822 | $price = $option[1]; |
| 823 | 823 | } |
| 824 | 824 | |
| 825 | - if ( ! isset( $price ) ) { |
|
| 825 | + if (!isset($price)) { |
|
| 826 | 826 | $price = $label; |
| 827 | 827 | } |
| 828 | 828 | |
| 829 | - if ( ! isset( $price ) || ! is_numeric( $price ) ) { |
|
| 829 | + if (!isset($price) || !is_numeric($price)) { |
|
| 830 | 830 | continue; |
| 831 | 831 | } |
| 832 | 832 | |
| 833 | - if ( ! isset( $label ) ) { |
|
| 833 | + if (!isset($label)) { |
|
| 834 | 834 | $label = $price; |
| 835 | 835 | } |
| 836 | 836 | |
| 837 | - $options[ $price ] = $label; |
|
| 837 | + $options[$price] = $label; |
|
| 838 | 838 | } |
| 839 | 839 | |
| 840 | 840 | return $options; |
@@ -843,27 +843,27 @@ discard block |
||
| 843 | 843 | /** |
| 844 | 844 | * Returns the help tip. |
| 845 | 845 | */ |
| 846 | -function getpaid_get_help_tip( $tip, $additional_classes = '' ) { |
|
| 847 | - $additional_classes = sanitize_html_class( $additional_classes ); |
|
| 848 | - $tip = esc_attr__( $tip ); |
|
| 846 | +function getpaid_get_help_tip($tip, $additional_classes = '') { |
|
| 847 | + $additional_classes = sanitize_html_class($additional_classes); |
|
| 848 | + $tip = esc_attr__($tip); |
|
| 849 | 849 | return "<span class='wpi-help-tip dashicons dashicons-editor-help $additional_classes' title='$tip'></span>"; |
| 850 | 850 | } |
| 851 | 851 | |
| 852 | 852 | /** |
| 853 | 853 | * Formats a date |
| 854 | 854 | */ |
| 855 | -function getpaid_format_date( $date, $with_time = false ) { |
|
| 855 | +function getpaid_format_date($date, $with_time = false) { |
|
| 856 | 856 | |
| 857 | - if ( empty( $date ) || $date == '0000-00-00 00:00:00' ) { |
|
| 857 | + if (empty($date) || $date == '0000-00-00 00:00:00') { |
|
| 858 | 858 | return ''; |
| 859 | 859 | } |
| 860 | 860 | |
| 861 | 861 | $format = getpaid_date_format(); |
| 862 | 862 | |
| 863 | - if ( $with_time ) { |
|
| 863 | + if ($with_time) { |
|
| 864 | 864 | $format .= ' ' . getpaid_time_format(); |
| 865 | 865 | } |
| 866 | - return date_i18n( $format, strtotime( $date ) ); |
|
| 866 | + return date_i18n($format, strtotime($date)); |
|
| 867 | 867 | |
| 868 | 868 | } |
| 869 | 869 | |
@@ -872,9 +872,9 @@ discard block |
||
| 872 | 872 | * |
| 873 | 873 | * @return string |
| 874 | 874 | */ |
| 875 | -function getpaid_format_date_value( $date, $default = "—", $with_time = false ) { |
|
| 876 | - $date = getpaid_format_date( $date, $with_time ); |
|
| 877 | - return empty( $date ) ? $default : $date; |
|
| 875 | +function getpaid_format_date_value($date, $default = "—", $with_time = false) { |
|
| 876 | + $date = getpaid_format_date($date, $with_time); |
|
| 877 | + return empty($date) ? $default : $date; |
|
| 878 | 878 | } |
| 879 | 879 | |
| 880 | 880 | /** |
@@ -883,7 +883,7 @@ discard block |
||
| 883 | 883 | * @return string |
| 884 | 884 | */ |
| 885 | 885 | function getpaid_date_format() { |
| 886 | - return apply_filters( 'getpaid_date_format', get_option( 'date_format' ) ); |
|
| 886 | + return apply_filters('getpaid_date_format', get_option('date_format')); |
|
| 887 | 887 | } |
| 888 | 888 | |
| 889 | 889 | /** |
@@ -892,7 +892,7 @@ discard block |
||
| 892 | 892 | * @return string |
| 893 | 893 | */ |
| 894 | 894 | function getpaid_time_format() { |
| 895 | - return apply_filters( 'getpaid_time_format', get_option( 'time_format' ) ); |
|
| 895 | + return apply_filters('getpaid_time_format', get_option('time_format')); |
|
| 896 | 896 | } |
| 897 | 897 | |
| 898 | 898 | /** |
@@ -902,16 +902,16 @@ discard block |
||
| 902 | 902 | * @param integer $limit Limit size in characters. |
| 903 | 903 | * @return string |
| 904 | 904 | */ |
| 905 | -function getpaid_limit_length( $string, $limit ) { |
|
| 905 | +function getpaid_limit_length($string, $limit) { |
|
| 906 | 906 | $str_limit = $limit - 3; |
| 907 | 907 | |
| 908 | - if ( function_exists( 'mb_strimwidth' ) ) { |
|
| 909 | - if ( mb_strlen( $string ) > $limit ) { |
|
| 910 | - $string = mb_strimwidth( $string, 0, $str_limit ) . '...'; |
|
| 908 | + if (function_exists('mb_strimwidth')) { |
|
| 909 | + if (mb_strlen($string) > $limit) { |
|
| 910 | + $string = mb_strimwidth($string, 0, $str_limit) . '...'; |
|
| 911 | 911 | } |
| 912 | 912 | } else { |
| 913 | - if ( strlen( $string ) > $limit ) { |
|
| 914 | - $string = substr( $string, 0, $str_limit ) . '...'; |
|
| 913 | + if (strlen($string) > $limit) { |
|
| 914 | + $string = substr($string, 0, $str_limit) . '...'; |
|
| 915 | 915 | } |
| 916 | 916 | } |
| 917 | 917 | return $string; |
@@ -925,7 +925,7 @@ discard block |
||
| 925 | 925 | * @since 1.0.19 |
| 926 | 926 | */ |
| 927 | 927 | function getpaid_api() { |
| 928 | - return getpaid()->get( 'api' ); |
|
| 928 | + return getpaid()->get('api'); |
|
| 929 | 929 | } |
| 930 | 930 | |
| 931 | 931 | /** |
@@ -935,7 +935,7 @@ discard block |
||
| 935 | 935 | * @since 1.0.19 |
| 936 | 936 | */ |
| 937 | 937 | function getpaid_post_types() { |
| 938 | - return getpaid()->get( 'post_types' ); |
|
| 938 | + return getpaid()->get('post_types'); |
|
| 939 | 939 | } |
| 940 | 940 | |
| 941 | 941 | /** |
@@ -945,7 +945,7 @@ discard block |
||
| 945 | 945 | * @since 1.0.19 |
| 946 | 946 | */ |
| 947 | 947 | function getpaid_session() { |
| 948 | - return getpaid()->get( 'session' ); |
|
| 948 | + return getpaid()->get('session'); |
|
| 949 | 949 | } |
| 950 | 950 | |
| 951 | 951 | /** |
@@ -955,7 +955,7 @@ discard block |
||
| 955 | 955 | * @since 1.0.19 |
| 956 | 956 | */ |
| 957 | 957 | function getpaid_notes() { |
| 958 | - return getpaid()->get( 'notes' ); |
|
| 958 | + return getpaid()->get('notes'); |
|
| 959 | 959 | } |
| 960 | 960 | |
| 961 | 961 | /** |
@@ -964,7 +964,7 @@ discard block |
||
| 964 | 964 | * @return GetPaid_Admin |
| 965 | 965 | */ |
| 966 | 966 | function getpaid_admin() { |
| 967 | - return getpaid()->get( 'admin' ); |
|
| 967 | + return getpaid()->get('admin'); |
|
| 968 | 968 | } |
| 969 | 969 | |
| 970 | 970 | /** |
@@ -974,8 +974,8 @@ discard block |
||
| 974 | 974 | * @param string $base the base url |
| 975 | 975 | * @return string |
| 976 | 976 | */ |
| 977 | -function getpaid_get_authenticated_action_url( $action, $base = false ) { |
|
| 978 | - return wp_nonce_url( add_query_arg( 'getpaid-action', $action, $base ), 'getpaid-nonce', 'getpaid-nonce' ); |
|
| 977 | +function getpaid_get_authenticated_action_url($action, $base = false) { |
|
| 978 | + return wp_nonce_url(add_query_arg('getpaid-action', $action, $base), 'getpaid-nonce', 'getpaid-nonce'); |
|
| 979 | 979 | } |
| 980 | 980 | |
| 981 | 981 | /** |
@@ -983,11 +983,11 @@ discard block |
||
| 983 | 983 | * |
| 984 | 984 | * @return string |
| 985 | 985 | */ |
| 986 | -function getpaid_get_post_type_label( $post_type, $plural = true ) { |
|
| 986 | +function getpaid_get_post_type_label($post_type, $plural = true) { |
|
| 987 | 987 | |
| 988 | - $post_type = get_post_type_object( $post_type ); |
|
| 988 | + $post_type = get_post_type_object($post_type); |
|
| 989 | 989 | |
| 990 | - if ( ! is_object( $post_type ) ) { |
|
| 990 | + if (!is_object($post_type)) { |
|
| 991 | 991 | return null; |
| 992 | 992 | } |
| 993 | 993 | |
@@ -1000,18 +1000,18 @@ discard block |
||
| 1000 | 1000 | * |
| 1001 | 1001 | * @return mixed|null |
| 1002 | 1002 | */ |
| 1003 | -function getpaid_get_array_field( $array, $key, $secondary_key = null ) { |
|
| 1003 | +function getpaid_get_array_field($array, $key, $secondary_key = null) { |
|
| 1004 | 1004 | |
| 1005 | - if ( ! is_array( $array ) ) { |
|
| 1005 | + if (!is_array($array)) { |
|
| 1006 | 1006 | return null; |
| 1007 | 1007 | } |
| 1008 | 1008 | |
| 1009 | - if ( ! empty( $secondary_key ) ) { |
|
| 1010 | - $array = isset( $array[ $secondary_key ] ) ? $array[ $secondary_key ] : array(); |
|
| 1011 | - return getpaid_get_array_field( $array, $key ); |
|
| 1009 | + if (!empty($secondary_key)) { |
|
| 1010 | + $array = isset($array[$secondary_key]) ? $array[$secondary_key] : array(); |
|
| 1011 | + return getpaid_get_array_field($array, $key); |
|
| 1012 | 1012 | } |
| 1013 | 1013 | |
| 1014 | - return isset( $array[ $key ] ) ? $array[ $key ] : null; |
|
| 1014 | + return isset($array[$key]) ? $array[$key] : null; |
|
| 1015 | 1015 | |
| 1016 | 1016 | } |
| 1017 | 1017 | |
@@ -1020,12 +1020,12 @@ discard block |
||
| 1020 | 1020 | * |
| 1021 | 1021 | * @return array |
| 1022 | 1022 | */ |
| 1023 | -function getpaid_array_merge_if_empty( $args, $defaults ) { |
|
| 1023 | +function getpaid_array_merge_if_empty($args, $defaults) { |
|
| 1024 | 1024 | |
| 1025 | - foreach ( $defaults as $key => $value ) { |
|
| 1025 | + foreach ($defaults as $key => $value) { |
|
| 1026 | 1026 | |
| 1027 | - if ( array_key_exists( $key, $args ) && empty( $args[ $key ] ) ) { |
|
| 1028 | - $args[ $key ] = $value; |
|
| 1027 | + if (array_key_exists($key, $args) && empty($args[$key])) { |
|
| 1028 | + $args[$key] = $value; |
|
| 1029 | 1029 | } |
| 1030 | 1030 | |
| 1031 | 1031 | } |
@@ -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 | - } else if( '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 | + } else if( '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 | - } else if( 'xml' == $file_type ) { |
|
| 84 | - $this->download_xml( $invoices, $stream, $headers ); |
|
| 81 | + if ('csv' == $file_type) { |
|
| 82 | + $this->download_csv($invoices, $stream, $headers); |
|
| 83 | + } else if ('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 | } |
@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | * |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | -defined( 'ABSPATH' ) || exit; |
|
| 7 | +defined('ABSPATH') || exit; |
|
| 8 | 8 | |
| 9 | 9 | $tax_rates = GetPaid_Tax::get_all_tax_rates(); |
| 10 | 10 | $dummy_rate = array( |
@@ -13,12 +13,12 @@ discard block |
||
| 13 | 13 | 'global' => true, |
| 14 | 14 | 'rate' => wpinv_get_default_tax_rate(), |
| 15 | 15 | 'reduced_rate' => 5, |
| 16 | - 'name' => __( 'VAT', 'invoicing' ), |
|
| 16 | + 'name' => __('VAT', 'invoicing'), |
|
| 17 | 17 | ); |
| 18 | 18 | |
| 19 | 19 | $reset_url = esc_url( |
| 20 | 20 | wp_nonce_url( |
| 21 | - add_query_arg( 'getpaid-admin-action', 'reset_tax_rates' ), |
|
| 21 | + add_query_arg('getpaid-admin-action', 'reset_tax_rates'), |
|
| 22 | 22 | 'getpaid-nonce', |
| 23 | 23 | 'getpaid-nonce' |
| 24 | 24 | ) |
@@ -27,34 +27,34 @@ discard block |
||
| 27 | 27 | ?> |
| 28 | 28 | <div class="table-responsive"> |
| 29 | 29 | <table id="wpinv_tax_rates" class="widefat fixed table"> |
| 30 | - <caption><?php echo esc_html_e( 'Enter tax rates for specific regions.', 'invoicing' ); ?></caption> |
|
| 30 | + <caption><?php echo esc_html_e('Enter tax rates for specific regions.', 'invoicing'); ?></caption> |
|
| 31 | 31 | |
| 32 | 32 | <thead> |
| 33 | 33 | <tr class="table-light"> |
| 34 | 34 | |
| 35 | 35 | <th scope="col" class="border-bottom border-top"> |
| 36 | - <?php _e( 'Country', 'invoicing' ); ?> |
|
| 37 | - <?php echo getpaid_get_help_tip( __( 'Optionally limit this tax rate to a specific country.', 'invoicing' ), 'position-static' ); ?> |
|
| 36 | + <?php _e('Country', 'invoicing'); ?> |
|
| 37 | + <?php echo getpaid_get_help_tip(__('Optionally limit this tax rate to a specific country.', 'invoicing'), 'position-static'); ?> |
|
| 38 | 38 | </th> |
| 39 | 39 | |
| 40 | 40 | <th scope="col" class="border-bottom border-top"> |
| 41 | - <?php _e( 'State', 'invoicing' ); ?> |
|
| 42 | - <?php echo getpaid_get_help_tip( __( 'Separate state codes using a comma or leave blank to apply country wide.', 'invoicing' ), 'position-static' ); ?> |
|
| 41 | + <?php _e('State', 'invoicing'); ?> |
|
| 42 | + <?php echo getpaid_get_help_tip(__('Separate state codes using a comma or leave blank to apply country wide.', 'invoicing'), 'position-static'); ?> |
|
| 43 | 43 | </th> |
| 44 | 44 | |
| 45 | 45 | <th scope="col" class="border-bottom border-top"> |
| 46 | - <?php _e( 'Standard Rate %', 'invoicing' ); ?> |
|
| 47 | - <?php echo getpaid_get_help_tip( __( 'The tax rate (percentage) to charge on items that use the "Standard rate" tax class.', 'invoicing' ), 'position-static' ); ?> |
|
| 46 | + <?php _e('Standard Rate %', 'invoicing'); ?> |
|
| 47 | + <?php echo getpaid_get_help_tip(__('The tax rate (percentage) to charge on items that use the "Standard rate" tax class.', 'invoicing'), 'position-static'); ?> |
|
| 48 | 48 | </th> |
| 49 | 49 | |
| 50 | 50 | <th scope="col" class="border-bottom border-top"> |
| 51 | - <?php _e( 'Reduced Rate %', 'invoicing' ); ?> |
|
| 52 | - <?php echo getpaid_get_help_tip( __( 'The tax rate (percentage) to charge on items that use the "Reduced rate" tax class.', 'invoicing' ), 'position-static' ); ?> |
|
| 51 | + <?php _e('Reduced Rate %', 'invoicing'); ?> |
|
| 52 | + <?php echo getpaid_get_help_tip(__('The tax rate (percentage) to charge on items that use the "Reduced rate" tax class.', 'invoicing'), 'position-static'); ?> |
|
| 53 | 53 | </th> |
| 54 | 54 | |
| 55 | 55 | <th scope="col" class="border-bottom border-top"> |
| 56 | - <?php _e( 'Tax Name', 'invoicing' ); ?> |
|
| 57 | - <?php echo getpaid_get_help_tip( __( 'The name of this tax, e.g VAT.', 'invoicing' ), 'position-static' ); ?> |
|
| 56 | + <?php _e('Tax Name', 'invoicing'); ?> |
|
| 57 | + <?php echo getpaid_get_help_tip(__('The name of this tax, e.g VAT.', 'invoicing'), 'position-static'); ?> |
|
| 58 | 58 | </th> |
| 59 | 59 | |
| 60 | 60 | <th scope="col" class="border-bottom border-top" style="width:32px"> </th> |
@@ -63,19 +63,19 @@ discard block |
||
| 63 | 63 | </thead> |
| 64 | 64 | |
| 65 | 65 | <tbody> |
| 66 | - <?php array_walk( $tax_rates, 'wpinv_tax_rate_callback' ); ?> |
|
| 66 | + <?php array_walk($tax_rates, 'wpinv_tax_rate_callback'); ?> |
|
| 67 | 67 | </tbody> |
| 68 | 68 | |
| 69 | 69 | <tfoot> |
| 70 | 70 | <tr class="table-light"> |
| 71 | 71 | <td colspan="6" class="border-top"> |
| 72 | 72 | |
| 73 | - <button type="button" class="button button-secondary wpinv_add_tax_rate" aria-label="<?php esc_attr_e( 'Add Tax Rate', 'invoicing' ); ?>"> |
|
| 74 | - <span><?php _e( 'Add Tax Rate', 'invoicing' ); ?></span> |
|
| 73 | + <button type="button" class="button button-secondary wpinv_add_tax_rate" aria-label="<?php esc_attr_e('Add Tax Rate', 'invoicing'); ?>"> |
|
| 74 | + <span><?php _e('Add Tax Rate', 'invoicing'); ?></span> |
|
| 75 | 75 | </button> |
| 76 | 76 | |
| 77 | - <a href="<?php echo $reset_url; ?>" class="button button-secondary wpinv_reset_tax_rates" aria-label="<?php esc_attr_e( 'Reset Tax Rates', 'invoicing' ); ?>"> |
|
| 78 | - <span><?php _e( 'Reset Tax Rates', 'invoicing' ); ?></span> |
|
| 77 | + <a href="<?php echo $reset_url; ?>" class="button button-secondary wpinv_reset_tax_rates" aria-label="<?php esc_attr_e('Reset Tax Rates', 'invoicing'); ?>"> |
|
| 78 | + <span><?php _e('Reset Tax Rates', 'invoicing'); ?></span> |
|
| 79 | 79 | </a> |
| 80 | 80 | </td> |
| 81 | 81 | </tr> |
@@ -84,6 +84,6 @@ discard block |
||
| 84 | 84 | </div> |
| 85 | 85 | |
| 86 | 86 | <script type="text/html" id="tmpl-wpinv-tax-rate-row"> |
| 87 | - <?php echo wpinv_tax_rate_callback( $dummy_rate, 0, false ); ?> |
|
| 87 | + <?php echo wpinv_tax_rate_callback($dummy_rate, 0, false); ?> |
|
| 88 | 88 | </script> |
| 89 | 89 | |