@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | * @param string $default_path The root path to the default template. Defaults to invoicing/templates |
| 141 | 141 | */ |
| 142 | 142 | function wpinv_get_template_html( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
| 143 | - return getpaid_template()->get_template( $template_name, $args, $template_path, $default_path ); |
|
| 143 | + return getpaid_template()->get_template( $template_name, $args, $template_path, $default_path ); |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | /** |
@@ -158,7 +158,7 @@ discard block |
||
| 158 | 158 | * @return string |
| 159 | 159 | */ |
| 160 | 160 | function wpinv_get_theme_template_dir_name() { |
| 161 | - return trailingslashit( apply_filters( 'wpinv_templates_dir', 'invoicing' ) ); |
|
| 161 | + return trailingslashit( apply_filters( 'wpinv_templates_dir', 'invoicing' ) ); |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | /** |
@@ -175,122 +175,122 @@ discard block |
||
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | function wpinv_get_template_part( $slug, $name = null, $load = true ) { |
| 178 | - do_action( 'get_template_part_' . $slug, $slug, $name ); |
|
| 178 | + do_action( 'get_template_part_' . $slug, $slug, $name ); |
|
| 179 | 179 | |
| 180 | - // Setup possible parts |
|
| 181 | - $templates = array(); |
|
| 182 | - if ( isset( $name ) ) |
|
| 183 | - $templates[] = $slug . '-' . $name . '.php'; |
|
| 184 | - $templates[] = $slug . '.php'; |
|
| 180 | + // Setup possible parts |
|
| 181 | + $templates = array(); |
|
| 182 | + if ( isset( $name ) ) |
|
| 183 | + $templates[] = $slug . '-' . $name . '.php'; |
|
| 184 | + $templates[] = $slug . '.php'; |
|
| 185 | 185 | |
| 186 | - // Allow template parts to be filtered |
|
| 187 | - $templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name ); |
|
| 186 | + // Allow template parts to be filtered |
|
| 187 | + $templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name ); |
|
| 188 | 188 | |
| 189 | - // Return the part that is found |
|
| 190 | - return wpinv_locate_tmpl( $templates, $load, false ); |
|
| 189 | + // Return the part that is found |
|
| 190 | + return wpinv_locate_tmpl( $templates, $load, false ); |
|
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | function wpinv_locate_tmpl( $template_names, $load = false, $require_once = true ) { |
| 194 | - // No file found yet |
|
| 195 | - $located = false; |
|
| 194 | + // No file found yet |
|
| 195 | + $located = false; |
|
| 196 | 196 | |
| 197 | - // Try to find a template file |
|
| 198 | - foreach ( (array)$template_names as $template_name ) { |
|
| 197 | + // Try to find a template file |
|
| 198 | + foreach ( (array)$template_names as $template_name ) { |
|
| 199 | 199 | |
| 200 | - // Continue if template is empty |
|
| 201 | - if ( empty( $template_name ) ) |
|
| 202 | - continue; |
|
| 200 | + // Continue if template is empty |
|
| 201 | + if ( empty( $template_name ) ) |
|
| 202 | + continue; |
|
| 203 | 203 | |
| 204 | - // Trim off any slashes from the template name |
|
| 205 | - $template_name = ltrim( $template_name, '/' ); |
|
| 204 | + // Trim off any slashes from the template name |
|
| 205 | + $template_name = ltrim( $template_name, '/' ); |
|
| 206 | 206 | |
| 207 | - // try locating this template file by looping through the template paths |
|
| 208 | - foreach( wpinv_get_theme_template_paths() as $template_path ) { |
|
| 207 | + // try locating this template file by looping through the template paths |
|
| 208 | + foreach( wpinv_get_theme_template_paths() as $template_path ) { |
|
| 209 | 209 | |
| 210 | - if( file_exists( $template_path . $template_name ) ) { |
|
| 211 | - $located = $template_path . $template_name; |
|
| 212 | - break; |
|
| 213 | - } |
|
| 214 | - } |
|
| 210 | + if( file_exists( $template_path . $template_name ) ) { |
|
| 211 | + $located = $template_path . $template_name; |
|
| 212 | + break; |
|
| 213 | + } |
|
| 214 | + } |
|
| 215 | 215 | |
| 216 | - if( !empty( $located ) ) { |
|
| 217 | - break; |
|
| 218 | - } |
|
| 219 | - } |
|
| 216 | + if( !empty( $located ) ) { |
|
| 217 | + break; |
|
| 218 | + } |
|
| 219 | + } |
|
| 220 | 220 | |
| 221 | - if ( ( true == $load ) && ! empty( $located ) ) |
|
| 222 | - load_template( $located, $require_once ); |
|
| 221 | + if ( ( true == $load ) && ! empty( $located ) ) |
|
| 222 | + load_template( $located, $require_once ); |
|
| 223 | 223 | |
| 224 | - return $located; |
|
| 224 | + return $located; |
|
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | function wpinv_get_theme_template_paths() { |
| 228 | - $template_dir = wpinv_get_theme_template_dir_name(); |
|
| 228 | + $template_dir = wpinv_get_theme_template_dir_name(); |
|
| 229 | 229 | |
| 230 | - $file_paths = array( |
|
| 231 | - 1 => trailingslashit( get_stylesheet_directory() ) . $template_dir, |
|
| 232 | - 10 => trailingslashit( get_template_directory() ) . $template_dir, |
|
| 233 | - 100 => wpinv_get_templates_dir() |
|
| 234 | - ); |
|
| 230 | + $file_paths = array( |
|
| 231 | + 1 => trailingslashit( get_stylesheet_directory() ) . $template_dir, |
|
| 232 | + 10 => trailingslashit( get_template_directory() ) . $template_dir, |
|
| 233 | + 100 => wpinv_get_templates_dir() |
|
| 234 | + ); |
|
| 235 | 235 | |
| 236 | - $file_paths = apply_filters( 'wpinv_template_paths', $file_paths ); |
|
| 236 | + $file_paths = apply_filters( 'wpinv_template_paths', $file_paths ); |
|
| 237 | 237 | |
| 238 | - // sort the file paths based on priority |
|
| 239 | - ksort( $file_paths, SORT_NUMERIC ); |
|
| 238 | + // sort the file paths based on priority |
|
| 239 | + ksort( $file_paths, SORT_NUMERIC ); |
|
| 240 | 240 | |
| 241 | - return array_map( 'trailingslashit', $file_paths ); |
|
| 241 | + return array_map( 'trailingslashit', $file_paths ); |
|
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | function wpinv_checkout_meta_tags() { |
| 245 | 245 | |
| 246 | - $pages = array(); |
|
| 247 | - $pages[] = wpinv_get_option( 'success_page' ); |
|
| 248 | - $pages[] = wpinv_get_option( 'failure_page' ); |
|
| 249 | - $pages[] = wpinv_get_option( 'invoice_history_page' ); |
|
| 250 | - $pages[] = wpinv_get_option( 'invoice_subscription_page' ); |
|
| 246 | + $pages = array(); |
|
| 247 | + $pages[] = wpinv_get_option( 'success_page' ); |
|
| 248 | + $pages[] = wpinv_get_option( 'failure_page' ); |
|
| 249 | + $pages[] = wpinv_get_option( 'invoice_history_page' ); |
|
| 250 | + $pages[] = wpinv_get_option( 'invoice_subscription_page' ); |
|
| 251 | 251 | |
| 252 | - if( !wpinv_is_checkout() && !is_page( $pages ) ) { |
|
| 253 | - return; |
|
| 254 | - } |
|
| 252 | + if( !wpinv_is_checkout() && !is_page( $pages ) ) { |
|
| 253 | + return; |
|
| 254 | + } |
|
| 255 | 255 | |
| 256 | - echo '<meta name="robots" content="noindex,nofollow" />' . "\n"; |
|
| 256 | + echo '<meta name="robots" content="noindex,nofollow" />' . "\n"; |
|
| 257 | 257 | } |
| 258 | 258 | add_action( 'wp_head', 'wpinv_checkout_meta_tags' ); |
| 259 | 259 | |
| 260 | 260 | function wpinv_add_body_classes( $class ) { |
| 261 | - $classes = (array)$class; |
|
| 261 | + $classes = (array)$class; |
|
| 262 | 262 | |
| 263 | - if( wpinv_is_checkout() ) { |
|
| 264 | - $classes[] = 'wpinv-checkout'; |
|
| 265 | - $classes[] = 'wpinv-page'; |
|
| 266 | - } |
|
| 263 | + if( wpinv_is_checkout() ) { |
|
| 264 | + $classes[] = 'wpinv-checkout'; |
|
| 265 | + $classes[] = 'wpinv-page'; |
|
| 266 | + } |
|
| 267 | 267 | |
| 268 | - if( wpinv_is_success_page() ) { |
|
| 269 | - $classes[] = 'wpinv-success'; |
|
| 270 | - $classes[] = 'wpinv-page'; |
|
| 271 | - } |
|
| 268 | + if( wpinv_is_success_page() ) { |
|
| 269 | + $classes[] = 'wpinv-success'; |
|
| 270 | + $classes[] = 'wpinv-page'; |
|
| 271 | + } |
|
| 272 | 272 | |
| 273 | - if( wpinv_is_failed_transaction_page() ) { |
|
| 274 | - $classes[] = 'wpinv-failed-transaction'; |
|
| 275 | - $classes[] = 'wpinv-page'; |
|
| 276 | - } |
|
| 273 | + if( wpinv_is_failed_transaction_page() ) { |
|
| 274 | + $classes[] = 'wpinv-failed-transaction'; |
|
| 275 | + $classes[] = 'wpinv-page'; |
|
| 276 | + } |
|
| 277 | 277 | |
| 278 | - if( wpinv_is_invoice_history_page() ) { |
|
| 279 | - $classes[] = 'wpinv-history'; |
|
| 280 | - $classes[] = 'wpinv-page'; |
|
| 281 | - } |
|
| 278 | + if( wpinv_is_invoice_history_page() ) { |
|
| 279 | + $classes[] = 'wpinv-history'; |
|
| 280 | + $classes[] = 'wpinv-page'; |
|
| 281 | + } |
|
| 282 | 282 | |
| 283 | - if( wpinv_is_subscriptions_history_page() ) { |
|
| 284 | - $classes[] = 'wpinv-subscription'; |
|
| 285 | - $classes[] = 'wpinv-page'; |
|
| 286 | - } |
|
| 283 | + if( wpinv_is_subscriptions_history_page() ) { |
|
| 284 | + $classes[] = 'wpinv-subscription'; |
|
| 285 | + $classes[] = 'wpinv-page'; |
|
| 286 | + } |
|
| 287 | 287 | |
| 288 | - if( wpinv_is_test_mode() ) { |
|
| 289 | - $classes[] = 'wpinv-test-mode'; |
|
| 290 | - $classes[] = 'wpinv-page'; |
|
| 291 | - } |
|
| 288 | + if( wpinv_is_test_mode() ) { |
|
| 289 | + $classes[] = 'wpinv-test-mode'; |
|
| 290 | + $classes[] = 'wpinv-page'; |
|
| 291 | + } |
|
| 292 | 292 | |
| 293 | - return array_unique( $classes ); |
|
| 293 | + return array_unique( $classes ); |
|
| 294 | 294 | } |
| 295 | 295 | add_filter( 'body_class', 'wpinv_add_body_classes' ); |
| 296 | 296 | |
@@ -821,21 +821,21 @@ discard block |
||
| 821 | 821 | |
| 822 | 822 | $formatted_address = str_ireplace( array_keys( $replacements ), $replacements, $format ); |
| 823 | 823 | |
| 824 | - // Remove unavailable tags. |
|
| 824 | + // Remove unavailable tags. |
|
| 825 | 825 | $formatted_address = preg_replace( "/\{\{\w+\}\}/", '', $formatted_address ); |
| 826 | 826 | |
| 827 | 827 | // Clean up white space. |
| 828 | - $formatted_address = preg_replace( '/ +/', ' ', trim( $formatted_address ) ); |
|
| 828 | + $formatted_address = preg_replace( '/ +/', ' ', trim( $formatted_address ) ); |
|
| 829 | 829 | $formatted_address = preg_replace( '/\n\n+/', "\n", $formatted_address ); |
| 830 | 830 | |
| 831 | 831 | // Break newlines apart and remove empty lines/trim commas and white space. |
| 832 | - $formatted_address = array_filter( array_map( 'wpinv_trim_formatted_address_line', explode( "\n", $formatted_address ) ) ); |
|
| 832 | + $formatted_address = array_filter( array_map( 'wpinv_trim_formatted_address_line', explode( "\n", $formatted_address ) ) ); |
|
| 833 | 833 | |
| 834 | 834 | // Add html breaks. |
| 835 | - $formatted_address = implode( $separator, $formatted_address ); |
|
| 835 | + $formatted_address = implode( $separator, $formatted_address ); |
|
| 836 | 836 | |
| 837 | - // We're done! |
|
| 838 | - return $formatted_address; |
|
| 837 | + // We're done! |
|
| 838 | + return $formatted_address; |
|
| 839 | 839 | |
| 840 | 840 | } |
| 841 | 841 | |
@@ -881,7 +881,7 @@ discard block |
||
| 881 | 881 | function getpaid_display_invoice_subscriptions( $invoice ) { |
| 882 | 882 | |
| 883 | 883 | // Subscriptions. |
| 884 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
| 884 | + $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
| 885 | 885 | |
| 886 | 886 | if ( empty( $subscriptions ) || ! $invoice->is_recurring() ) { |
| 887 | 887 | return; |
@@ -1089,7 +1089,7 @@ discard block |
||
| 1089 | 1089 | } |
| 1090 | 1090 | |
| 1091 | 1091 | function wpinv_empty_cart_message() { |
| 1092 | - return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' ); |
|
| 1092 | + return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' ); |
|
| 1093 | 1093 | } |
| 1094 | 1094 | |
| 1095 | 1095 | /** |
@@ -1281,10 +1281,10 @@ discard block |
||
| 1281 | 1281 | |
| 1282 | 1282 | if ( 0 == count( $form->get_items() ) ) { |
| 1283 | 1283 | echo aui()->alert( |
| 1284 | - array( |
|
| 1285 | - 'type' => 'warning', |
|
| 1286 | - 'content' => __( 'No published items found', 'invoicing' ), |
|
| 1287 | - ) |
|
| 1284 | + array( |
|
| 1285 | + 'type' => 'warning', |
|
| 1286 | + 'content' => __( 'No published items found', 'invoicing' ), |
|
| 1287 | + ) |
|
| 1288 | 1288 | ); |
| 1289 | 1289 | return; |
| 1290 | 1290 | } |
@@ -1302,21 +1302,21 @@ discard block |
||
| 1302 | 1302 | $invoice = wpinv_get_invoice( $invoice_id ); |
| 1303 | 1303 | |
| 1304 | 1304 | if ( empty( $invoice ) ) { |
| 1305 | - echo aui()->alert( |
|
| 1306 | - array( |
|
| 1307 | - 'type' => 'warning', |
|
| 1308 | - 'content' => __( 'Invoice not found', 'invoicing' ), |
|
| 1309 | - ) |
|
| 1305 | + echo aui()->alert( |
|
| 1306 | + array( |
|
| 1307 | + 'type' => 'warning', |
|
| 1308 | + 'content' => __( 'Invoice not found', 'invoicing' ), |
|
| 1309 | + ) |
|
| 1310 | 1310 | ); |
| 1311 | 1311 | return; |
| 1312 | 1312 | } |
| 1313 | 1313 | |
| 1314 | 1314 | if ( $invoice->is_paid() ) { |
| 1315 | - echo aui()->alert( |
|
| 1316 | - array( |
|
| 1317 | - 'type' => 'warning', |
|
| 1318 | - 'content' => __( 'Invoice has already been paid', 'invoicing' ), |
|
| 1319 | - ) |
|
| 1315 | + echo aui()->alert( |
|
| 1316 | + array( |
|
| 1317 | + 'type' => 'warning', |
|
| 1318 | + 'content' => __( 'Invoice has already been paid', 'invoicing' ), |
|
| 1319 | + ) |
|
| 1320 | 1320 | ); |
| 1321 | 1321 | return; |
| 1322 | 1322 | } |
@@ -1378,7 +1378,7 @@ discard block |
||
| 1378 | 1378 | return "<button class='btn btn-primary getpaid-payment-button' type='button' data-form='$form'>$label</button>"; |
| 1379 | 1379 | } |
| 1380 | 1380 | |
| 1381 | - if ( ! empty( $items ) ) { |
|
| 1381 | + if ( ! empty( $items ) ) { |
|
| 1382 | 1382 | $items = esc_attr( $items ); |
| 1383 | 1383 | return "<button class='btn btn-primary getpaid-payment-button' type='button' data-item='$items'>$label</button>"; |
| 1384 | 1384 | } |
@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | if ( ! defined( 'ABSPATH' ) ) exit; |
| 7 | 7 | |
| 8 | 8 | if ( ! class_exists( 'WP_List_Table' ) ) { |
| 9 | - include_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
| 9 | + include_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
| 10 | 10 | } |
| 11 | 11 | |
| 12 | 12 | /** |
@@ -14,406 +14,406 @@ discard block |
||
| 14 | 14 | */ |
| 15 | 15 | class WPInv_Subscriptions_List_Table extends WP_List_Table { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * URL of this page |
|
| 19 | - * |
|
| 20 | - * @var string |
|
| 21 | - * @since 1.0.19 |
|
| 22 | - */ |
|
| 23 | - public $base_url; |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * Query |
|
| 27 | - * |
|
| 28 | - * @var GetPaid_Subscriptions_Query |
|
| 29 | - * @since 1.0.19 |
|
| 30 | - */ |
|
| 31 | - public $query; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * Total subscriptions |
|
| 35 | - * |
|
| 36 | - * @var string |
|
| 37 | - * @since 1.0.0 |
|
| 38 | - */ |
|
| 39 | - public $total_count; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * Current status subscriptions |
|
| 43 | - * |
|
| 44 | - * @var string |
|
| 45 | - * @since 1.0.0 |
|
| 46 | - */ |
|
| 47 | - public $current_total_count; |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * Status counts |
|
| 51 | - * |
|
| 52 | - * @var array |
|
| 53 | - * @since 1.0.19 |
|
| 54 | - */ |
|
| 55 | - public $status_counts; |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * Number of results to show per page |
|
| 59 | - * |
|
| 60 | - * @var int |
|
| 61 | - * @since 1.0.0 |
|
| 62 | - */ |
|
| 63 | - public $per_page = 10; |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * Constructor function. |
|
| 67 | - */ |
|
| 68 | - public function __construct() { |
|
| 69 | - |
|
| 70 | - parent::__construct( |
|
| 71 | - array( |
|
| 72 | - 'singular' => 'subscription', |
|
| 73 | - 'plural' => 'subscriptions', |
|
| 74 | - ) |
|
| 75 | - ); |
|
| 76 | - |
|
| 77 | - $this->process_bulk_action(); |
|
| 78 | - |
|
| 79 | - $this->prepare_query(); |
|
| 80 | - |
|
| 81 | - $this->base_url = remove_query_arg( 'status' ); |
|
| 82 | - |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * Prepares the display query |
|
| 87 | - */ |
|
| 88 | - public function prepare_query() { |
|
| 89 | - |
|
| 90 | - // Prepare query args. |
|
| 91 | - $query = array( |
|
| 92 | - 'number' => $this->per_page, |
|
| 93 | - 'paged' => $this->get_paged(), |
|
| 94 | - 'status' => ( isset( $_GET['status'] ) && array_key_exists( $_GET['status'], getpaid_get_subscription_statuses() ) ) ? $_GET['status'] : 'all', |
|
| 95 | - 'orderby' => ( isset( $_GET['orderby'] ) ) ? $_GET['orderby'] : 'id', |
|
| 96 | - 'order' => ( isset( $_GET['order'] ) ) ? $_GET['order'] : 'DESC', |
|
| 97 | - ); |
|
| 98 | - |
|
| 99 | - // Prepare class properties. |
|
| 100 | - $this->query = new GetPaid_Subscriptions_Query( $query ); |
|
| 101 | - $this->total_count = $this->query->get_total(); |
|
| 102 | - $this->current_total_count = $this->query->get_total(); |
|
| 103 | - $this->items = $this->query->get_results(); |
|
| 104 | - $this->status_counts = getpaid_get_subscription_status_counts( $query ); |
|
| 105 | - |
|
| 106 | - if ( 'all' != $query['status'] ) { |
|
| 107 | - unset( $query['status'] ); |
|
| 108 | - $this->total_count = getpaid_get_subscriptions( $query, 'count' ); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * Gets the list of views available on this table. |
|
| 115 | - * |
|
| 116 | - * The format is an associative array: |
|
| 117 | - * - `'id' => 'link'` |
|
| 118 | - * |
|
| 119 | - * @since 1.0.0 |
|
| 120 | - * |
|
| 121 | - * @return array |
|
| 122 | - */ |
|
| 123 | - public function get_views() { |
|
| 124 | - |
|
| 125 | - $current = isset( $_GET['status'] ) ? $_GET['status'] : 'all'; |
|
| 126 | - $views = array( |
|
| 127 | - |
|
| 128 | - 'all' => sprintf( |
|
| 129 | - '<a href="%s" %s>%s <span class="count">(%d)</span></a>', |
|
| 130 | - esc_url( add_query_arg( 'status', false, $this->base_url ) ), |
|
| 131 | - $current === 'all' ? ' class="current"' : '', |
|
| 132 | - __('All','invoicing' ), |
|
| 133 | - $this->total_count |
|
| 134 | - ) |
|
| 135 | - |
|
| 136 | - ); |
|
| 137 | - |
|
| 138 | - foreach ( array_filter( $this->status_counts ) as $status => $count ) { |
|
| 139 | - |
|
| 140 | - $views[ $status ] = sprintf( |
|
| 141 | - '<a href="%s" %s>%s <span class="count">(%d)</span></a>', |
|
| 142 | - esc_url( add_query_arg( 'status', urlencode( $status ), $this->base_url ) ), |
|
| 143 | - $current === $status ? ' class="current"' : '', |
|
| 144 | - sanitize_text_field( getpaid_get_subscription_status_label( $status ) ), |
|
| 145 | - $count |
|
| 146 | - ); |
|
| 147 | - |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - return $views; |
|
| 151 | - |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - /** |
|
| 155 | - * Render most columns |
|
| 156 | - * |
|
| 157 | - * @access private |
|
| 158 | - * @since 1.0.0 |
|
| 159 | - * @return string |
|
| 160 | - */ |
|
| 161 | - public function column_default( $item, $column_name ) { |
|
| 162 | - return apply_filters( "getpaid_subscriptions_table_column_$column_name", $item->$column_name ); |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - /** |
|
| 166 | - * This is how checkbox column renders. |
|
| 167 | - * |
|
| 168 | - * @param WPInv_Subscription $item |
|
| 169 | - * @return string |
|
| 170 | - */ |
|
| 171 | - public function column_cb( $item ) { |
|
| 172 | - return sprintf( '<input type="checkbox" name="id[]" value="%s" />', esc_html( $item->get_id() ) ); |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - /** |
|
| 176 | - * Status column |
|
| 177 | - * |
|
| 178 | - * @param WPInv_Subscription $item |
|
| 179 | - * @since 1.0.0 |
|
| 180 | - * @return string |
|
| 181 | - */ |
|
| 182 | - public function column_status( $item ) { |
|
| 183 | - return $item->get_status_label_html(); |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - /** |
|
| 187 | - * Subscription column |
|
| 188 | - * |
|
| 189 | - * @param WPInv_Subscription $item |
|
| 190 | - * @since 1.0.0 |
|
| 191 | - * @return string |
|
| 192 | - */ |
|
| 193 | - public function column_subscription( $item ) { |
|
| 194 | - |
|
| 195 | - $username = __( '(Missing User)', 'invoicing' ); |
|
| 196 | - |
|
| 197 | - $user = get_userdata( $item->get_customer_id() ); |
|
| 198 | - if ( $user ) { |
|
| 199 | - |
|
| 200 | - $username = sprintf( |
|
| 201 | - '<a href="user-edit.php?user_id=%s">%s</a>', |
|
| 202 | - absint( $user->ID ), |
|
| 203 | - ! empty( $user->display_name ) ? sanitize_text_field( $user->display_name ) : sanitize_email( $user->user_email ) |
|
| 204 | - ); |
|
| 205 | - |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - // translators: $1: is opening link, $2: is subscription id number, $3: is closing link tag, $4: is user's name |
|
| 209 | - $column_content = sprintf( |
|
| 210 | - _x( '%1$s#%2$s%3$s for %4$s', 'Subscription title on admin table. (e.g.: #211 for John Doe)', 'invoicing' ), |
|
| 211 | - '<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $item->get_id() ) ) ) . '">', |
|
| 212 | - '<strong>' . esc_attr( $item->get_id() ) . '</strong>', '</a>', |
|
| 213 | - $username |
|
| 214 | - ); |
|
| 215 | - |
|
| 216 | - $row_actions = array(); |
|
| 217 | - |
|
| 218 | - // View subscription. |
|
| 219 | - $view_url = esc_url( add_query_arg( 'id', $item->get_id(), admin_url( 'admin.php?page=wpinv-subscriptions' ) )); |
|
| 220 | - $row_actions['view'] = '<a href="' . $view_url . '">' . __( 'View Subscription', 'invoicing' ) . '</a>'; |
|
| 221 | - |
|
| 222 | - // View invoice. |
|
| 223 | - $invoice = get_post( $item->get_parent_invoice_id() ); |
|
| 224 | - |
|
| 225 | - if ( ! empty( $invoice ) ) { |
|
| 226 | - $invoice_url = get_edit_post_link( $invoice ); |
|
| 227 | - $row_actions['invoice'] = '<a href="' . $invoice_url . '">' . __( 'View Invoice', 'invoicing' ) . '</a>'; |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - $delete_url = esc_url( |
|
| 231 | - wp_nonce_url( |
|
| 232 | - add_query_arg( |
|
| 233 | - array( |
|
| 234 | - 'getpaid-admin-action' => 'subscription_manual_delete', |
|
| 235 | - 'id' => $item->get_id(), |
|
| 236 | - ) |
|
| 237 | - ), |
|
| 238 | - 'getpaid-nonce', |
|
| 239 | - 'getpaid-nonce' |
|
| 240 | - ) |
|
| 241 | - ); |
|
| 242 | - $row_actions['delete'] = '<a class="text-danger" href="' . $delete_url . '">' . __( 'Delete Subscription', 'invoicing' ) . '</a>'; |
|
| 243 | - |
|
| 244 | - $row_actions = $this->row_actions( apply_filters( 'getpaid_subscription_table_row_actions', $row_actions, $item ) ); |
|
| 245 | - |
|
| 246 | - return "<strong>$column_content</strong>" . $this->column_amount( $item ) . $row_actions; |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - /** |
|
| 250 | - * Renewal date column |
|
| 251 | - * |
|
| 252 | - * @param WPInv_Subscription $item |
|
| 253 | - * @since 1.0.0 |
|
| 254 | - * @return string |
|
| 255 | - */ |
|
| 256 | - public function column_renewal_date( $item ) { |
|
| 257 | - return getpaid_format_date_value( $item->get_expiration() ); |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - /** |
|
| 261 | - * Start date column |
|
| 262 | - * |
|
| 263 | - * @param WPInv_Subscription $item |
|
| 264 | - * @since 1.0.0 |
|
| 265 | - * @return string |
|
| 266 | - */ |
|
| 267 | - public function column_start_date( $item ) { |
|
| 268 | - return getpaid_format_date_value( $item->get_date_created() ); |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - /** |
|
| 272 | - * Amount column |
|
| 273 | - * |
|
| 274 | - * @param WPInv_Subscription $item |
|
| 275 | - * @since 1.0.19 |
|
| 276 | - * @return string |
|
| 277 | - */ |
|
| 278 | - public static function column_amount( $item ) { |
|
| 279 | - $amount = getpaid_get_formatted_subscription_amount( $item ); |
|
| 280 | - return "<span class='text-muted form-text mt-2 mb-2'>$amount</span>"; |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - /** |
|
| 284 | - * Billing Times column |
|
| 285 | - * |
|
| 286 | - * @param WPInv_Subscription $item |
|
| 287 | - * @since 1.0.0 |
|
| 288 | - * @return string |
|
| 289 | - */ |
|
| 290 | - public function column_renewals( $item ) { |
|
| 291 | - $max_bills = $item->get_bill_times(); |
|
| 292 | - return $item->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "∞" : $max_bills ); |
|
| 293 | - } |
|
| 294 | - |
|
| 295 | - /** |
|
| 296 | - * Product ID column |
|
| 297 | - * |
|
| 298 | - * @param WPInv_Subscription $item |
|
| 299 | - * @since 1.0.0 |
|
| 300 | - * @return string |
|
| 301 | - */ |
|
| 302 | - public function column_item( $item ) { |
|
| 303 | - $subscription_group = getpaid_get_invoice_subscription_group( $item->get_parent_invoice_id(), $item->get_id() ); |
|
| 304 | - |
|
| 305 | - if ( empty( $subscription_group ) ) { |
|
| 306 | - return $this->generate_item_markup( $item->get_product_id() ); |
|
| 307 | - } |
|
| 308 | - |
|
| 309 | - $markup = array_map( array( $this, 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
| 310 | - return implode( ' | ', $markup ); |
|
| 311 | - |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - /** |
|
| 315 | - * Generates the items markup. |
|
| 316 | - * |
|
| 317 | - * @param int $item_id |
|
| 318 | - * @since 1.0.0 |
|
| 319 | - * @return string |
|
| 320 | - */ |
|
| 321 | - public static function generate_item_markup( $item_id ) { |
|
| 322 | - $item = get_post( $item_id ); |
|
| 323 | - |
|
| 324 | - if ( ! empty( $item ) ) { |
|
| 325 | - $link = get_edit_post_link( $item ); |
|
| 326 | - $link = esc_url( $link ); |
|
| 327 | - $name = esc_html( get_the_title( $item ) ); |
|
| 328 | - return wpinv_current_user_can_manage_invoicing() ? "<a href='$link'>$name</a>" : $name; |
|
| 329 | - } else { |
|
| 330 | - return sprintf( __( 'Item #%s', 'invoicing' ), $item_id ); |
|
| 331 | - } |
|
| 332 | - |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - /** |
|
| 336 | - * Retrieve the current page number |
|
| 337 | - * |
|
| 338 | - * @return int |
|
| 339 | - */ |
|
| 340 | - public function get_paged() { |
|
| 341 | - return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
| 342 | - } |
|
| 343 | - |
|
| 344 | - /** |
|
| 345 | - * Setup the final data for the table |
|
| 346 | - * |
|
| 347 | - */ |
|
| 348 | - public function prepare_items() { |
|
| 349 | - |
|
| 350 | - $columns = $this->get_columns(); |
|
| 351 | - $hidden = array(); |
|
| 352 | - $sortable = $this->get_sortable_columns(); |
|
| 353 | - |
|
| 354 | - $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
| 355 | - |
|
| 356 | - $this->set_pagination_args( |
|
| 357 | - array( |
|
| 358 | - 'total_items' => $this->current_total_count, |
|
| 359 | - 'per_page' => $this->per_page, |
|
| 360 | - 'total_pages' => ceil( $this->current_total_count / $this->per_page ) |
|
| 361 | - ) |
|
| 362 | - ); |
|
| 363 | - } |
|
| 364 | - |
|
| 365 | - /** |
|
| 366 | - * Table columns |
|
| 367 | - * |
|
| 368 | - * @return array |
|
| 369 | - */ |
|
| 370 | - public function get_columns(){ |
|
| 371 | - $columns = array( |
|
| 372 | - 'cb' => '<input type="checkbox" />', |
|
| 373 | - 'subscription' => __( 'Subscription', 'invoicing' ), |
|
| 374 | - 'start_date' => __( 'Start Date', 'invoicing' ), |
|
| 375 | - 'renewal_date' => __( 'Next Payment', 'invoicing' ), |
|
| 376 | - 'renewals' => __( 'Payments', 'invoicing' ), |
|
| 377 | - 'item' => __( 'Items', 'invoicing' ), |
|
| 378 | - 'status' => __( 'Status', 'invoicing' ), |
|
| 379 | - ); |
|
| 380 | - |
|
| 381 | - return apply_filters( 'manage_getpaid_subscriptions_table_columns', $columns ); |
|
| 382 | - } |
|
| 383 | - |
|
| 384 | - /** |
|
| 385 | - * Sortable table columns. |
|
| 386 | - * |
|
| 387 | - * @return array |
|
| 388 | - */ |
|
| 389 | - public function get_sortable_columns() { |
|
| 390 | - $sortable = array( |
|
| 391 | - 'subscription' => array( 'id', true ), |
|
| 392 | - 'start_date' => array( 'created', true ), |
|
| 393 | - 'renewal_date' => array( 'expiration', true ), |
|
| 394 | - 'renewals' => array( 'bill_times', true ), |
|
| 395 | - 'item' => array( 'product_id', true ), |
|
| 396 | - 'status' => array( 'status', true ), |
|
| 397 | - ); |
|
| 398 | - |
|
| 399 | - return apply_filters( 'manage_getpaid_subscriptions_sortable_table_columns', $sortable ); |
|
| 400 | - } |
|
| 401 | - |
|
| 402 | - /** |
|
| 403 | - * Whether the table has items to display or not |
|
| 404 | - * |
|
| 405 | - * @return bool |
|
| 406 | - */ |
|
| 407 | - public function has_items() { |
|
| 408 | - return ! empty( $this->current_total_count ); |
|
| 409 | - } |
|
| 410 | - |
|
| 411 | - /** |
|
| 412 | - * Processes bulk actions. |
|
| 413 | - * |
|
| 414 | - */ |
|
| 415 | - public function process_bulk_action() { |
|
| 416 | - |
|
| 417 | - } |
|
| 17 | + /** |
|
| 18 | + * URL of this page |
|
| 19 | + * |
|
| 20 | + * @var string |
|
| 21 | + * @since 1.0.19 |
|
| 22 | + */ |
|
| 23 | + public $base_url; |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * Query |
|
| 27 | + * |
|
| 28 | + * @var GetPaid_Subscriptions_Query |
|
| 29 | + * @since 1.0.19 |
|
| 30 | + */ |
|
| 31 | + public $query; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * Total subscriptions |
|
| 35 | + * |
|
| 36 | + * @var string |
|
| 37 | + * @since 1.0.0 |
|
| 38 | + */ |
|
| 39 | + public $total_count; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * Current status subscriptions |
|
| 43 | + * |
|
| 44 | + * @var string |
|
| 45 | + * @since 1.0.0 |
|
| 46 | + */ |
|
| 47 | + public $current_total_count; |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * Status counts |
|
| 51 | + * |
|
| 52 | + * @var array |
|
| 53 | + * @since 1.0.19 |
|
| 54 | + */ |
|
| 55 | + public $status_counts; |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * Number of results to show per page |
|
| 59 | + * |
|
| 60 | + * @var int |
|
| 61 | + * @since 1.0.0 |
|
| 62 | + */ |
|
| 63 | + public $per_page = 10; |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * Constructor function. |
|
| 67 | + */ |
|
| 68 | + public function __construct() { |
|
| 69 | + |
|
| 70 | + parent::__construct( |
|
| 71 | + array( |
|
| 72 | + 'singular' => 'subscription', |
|
| 73 | + 'plural' => 'subscriptions', |
|
| 74 | + ) |
|
| 75 | + ); |
|
| 76 | + |
|
| 77 | + $this->process_bulk_action(); |
|
| 78 | + |
|
| 79 | + $this->prepare_query(); |
|
| 80 | + |
|
| 81 | + $this->base_url = remove_query_arg( 'status' ); |
|
| 82 | + |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * Prepares the display query |
|
| 87 | + */ |
|
| 88 | + public function prepare_query() { |
|
| 89 | + |
|
| 90 | + // Prepare query args. |
|
| 91 | + $query = array( |
|
| 92 | + 'number' => $this->per_page, |
|
| 93 | + 'paged' => $this->get_paged(), |
|
| 94 | + 'status' => ( isset( $_GET['status'] ) && array_key_exists( $_GET['status'], getpaid_get_subscription_statuses() ) ) ? $_GET['status'] : 'all', |
|
| 95 | + 'orderby' => ( isset( $_GET['orderby'] ) ) ? $_GET['orderby'] : 'id', |
|
| 96 | + 'order' => ( isset( $_GET['order'] ) ) ? $_GET['order'] : 'DESC', |
|
| 97 | + ); |
|
| 98 | + |
|
| 99 | + // Prepare class properties. |
|
| 100 | + $this->query = new GetPaid_Subscriptions_Query( $query ); |
|
| 101 | + $this->total_count = $this->query->get_total(); |
|
| 102 | + $this->current_total_count = $this->query->get_total(); |
|
| 103 | + $this->items = $this->query->get_results(); |
|
| 104 | + $this->status_counts = getpaid_get_subscription_status_counts( $query ); |
|
| 105 | + |
|
| 106 | + if ( 'all' != $query['status'] ) { |
|
| 107 | + unset( $query['status'] ); |
|
| 108 | + $this->total_count = getpaid_get_subscriptions( $query, 'count' ); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * Gets the list of views available on this table. |
|
| 115 | + * |
|
| 116 | + * The format is an associative array: |
|
| 117 | + * - `'id' => 'link'` |
|
| 118 | + * |
|
| 119 | + * @since 1.0.0 |
|
| 120 | + * |
|
| 121 | + * @return array |
|
| 122 | + */ |
|
| 123 | + public function get_views() { |
|
| 124 | + |
|
| 125 | + $current = isset( $_GET['status'] ) ? $_GET['status'] : 'all'; |
|
| 126 | + $views = array( |
|
| 127 | + |
|
| 128 | + 'all' => sprintf( |
|
| 129 | + '<a href="%s" %s>%s <span class="count">(%d)</span></a>', |
|
| 130 | + esc_url( add_query_arg( 'status', false, $this->base_url ) ), |
|
| 131 | + $current === 'all' ? ' class="current"' : '', |
|
| 132 | + __('All','invoicing' ), |
|
| 133 | + $this->total_count |
|
| 134 | + ) |
|
| 135 | + |
|
| 136 | + ); |
|
| 137 | + |
|
| 138 | + foreach ( array_filter( $this->status_counts ) as $status => $count ) { |
|
| 139 | + |
|
| 140 | + $views[ $status ] = sprintf( |
|
| 141 | + '<a href="%s" %s>%s <span class="count">(%d)</span></a>', |
|
| 142 | + esc_url( add_query_arg( 'status', urlencode( $status ), $this->base_url ) ), |
|
| 143 | + $current === $status ? ' class="current"' : '', |
|
| 144 | + sanitize_text_field( getpaid_get_subscription_status_label( $status ) ), |
|
| 145 | + $count |
|
| 146 | + ); |
|
| 147 | + |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + return $views; |
|
| 151 | + |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + /** |
|
| 155 | + * Render most columns |
|
| 156 | + * |
|
| 157 | + * @access private |
|
| 158 | + * @since 1.0.0 |
|
| 159 | + * @return string |
|
| 160 | + */ |
|
| 161 | + public function column_default( $item, $column_name ) { |
|
| 162 | + return apply_filters( "getpaid_subscriptions_table_column_$column_name", $item->$column_name ); |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + /** |
|
| 166 | + * This is how checkbox column renders. |
|
| 167 | + * |
|
| 168 | + * @param WPInv_Subscription $item |
|
| 169 | + * @return string |
|
| 170 | + */ |
|
| 171 | + public function column_cb( $item ) { |
|
| 172 | + return sprintf( '<input type="checkbox" name="id[]" value="%s" />', esc_html( $item->get_id() ) ); |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + /** |
|
| 176 | + * Status column |
|
| 177 | + * |
|
| 178 | + * @param WPInv_Subscription $item |
|
| 179 | + * @since 1.0.0 |
|
| 180 | + * @return string |
|
| 181 | + */ |
|
| 182 | + public function column_status( $item ) { |
|
| 183 | + return $item->get_status_label_html(); |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + /** |
|
| 187 | + * Subscription column |
|
| 188 | + * |
|
| 189 | + * @param WPInv_Subscription $item |
|
| 190 | + * @since 1.0.0 |
|
| 191 | + * @return string |
|
| 192 | + */ |
|
| 193 | + public function column_subscription( $item ) { |
|
| 194 | + |
|
| 195 | + $username = __( '(Missing User)', 'invoicing' ); |
|
| 196 | + |
|
| 197 | + $user = get_userdata( $item->get_customer_id() ); |
|
| 198 | + if ( $user ) { |
|
| 199 | + |
|
| 200 | + $username = sprintf( |
|
| 201 | + '<a href="user-edit.php?user_id=%s">%s</a>', |
|
| 202 | + absint( $user->ID ), |
|
| 203 | + ! empty( $user->display_name ) ? sanitize_text_field( $user->display_name ) : sanitize_email( $user->user_email ) |
|
| 204 | + ); |
|
| 205 | + |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + // translators: $1: is opening link, $2: is subscription id number, $3: is closing link tag, $4: is user's name |
|
| 209 | + $column_content = sprintf( |
|
| 210 | + _x( '%1$s#%2$s%3$s for %4$s', 'Subscription title on admin table. (e.g.: #211 for John Doe)', 'invoicing' ), |
|
| 211 | + '<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $item->get_id() ) ) ) . '">', |
|
| 212 | + '<strong>' . esc_attr( $item->get_id() ) . '</strong>', '</a>', |
|
| 213 | + $username |
|
| 214 | + ); |
|
| 215 | + |
|
| 216 | + $row_actions = array(); |
|
| 217 | + |
|
| 218 | + // View subscription. |
|
| 219 | + $view_url = esc_url( add_query_arg( 'id', $item->get_id(), admin_url( 'admin.php?page=wpinv-subscriptions' ) )); |
|
| 220 | + $row_actions['view'] = '<a href="' . $view_url . '">' . __( 'View Subscription', 'invoicing' ) . '</a>'; |
|
| 221 | + |
|
| 222 | + // View invoice. |
|
| 223 | + $invoice = get_post( $item->get_parent_invoice_id() ); |
|
| 224 | + |
|
| 225 | + if ( ! empty( $invoice ) ) { |
|
| 226 | + $invoice_url = get_edit_post_link( $invoice ); |
|
| 227 | + $row_actions['invoice'] = '<a href="' . $invoice_url . '">' . __( 'View Invoice', 'invoicing' ) . '</a>'; |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + $delete_url = esc_url( |
|
| 231 | + wp_nonce_url( |
|
| 232 | + add_query_arg( |
|
| 233 | + array( |
|
| 234 | + 'getpaid-admin-action' => 'subscription_manual_delete', |
|
| 235 | + 'id' => $item->get_id(), |
|
| 236 | + ) |
|
| 237 | + ), |
|
| 238 | + 'getpaid-nonce', |
|
| 239 | + 'getpaid-nonce' |
|
| 240 | + ) |
|
| 241 | + ); |
|
| 242 | + $row_actions['delete'] = '<a class="text-danger" href="' . $delete_url . '">' . __( 'Delete Subscription', 'invoicing' ) . '</a>'; |
|
| 243 | + |
|
| 244 | + $row_actions = $this->row_actions( apply_filters( 'getpaid_subscription_table_row_actions', $row_actions, $item ) ); |
|
| 245 | + |
|
| 246 | + return "<strong>$column_content</strong>" . $this->column_amount( $item ) . $row_actions; |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + /** |
|
| 250 | + * Renewal date column |
|
| 251 | + * |
|
| 252 | + * @param WPInv_Subscription $item |
|
| 253 | + * @since 1.0.0 |
|
| 254 | + * @return string |
|
| 255 | + */ |
|
| 256 | + public function column_renewal_date( $item ) { |
|
| 257 | + return getpaid_format_date_value( $item->get_expiration() ); |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + /** |
|
| 261 | + * Start date column |
|
| 262 | + * |
|
| 263 | + * @param WPInv_Subscription $item |
|
| 264 | + * @since 1.0.0 |
|
| 265 | + * @return string |
|
| 266 | + */ |
|
| 267 | + public function column_start_date( $item ) { |
|
| 268 | + return getpaid_format_date_value( $item->get_date_created() ); |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + /** |
|
| 272 | + * Amount column |
|
| 273 | + * |
|
| 274 | + * @param WPInv_Subscription $item |
|
| 275 | + * @since 1.0.19 |
|
| 276 | + * @return string |
|
| 277 | + */ |
|
| 278 | + public static function column_amount( $item ) { |
|
| 279 | + $amount = getpaid_get_formatted_subscription_amount( $item ); |
|
| 280 | + return "<span class='text-muted form-text mt-2 mb-2'>$amount</span>"; |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + /** |
|
| 284 | + * Billing Times column |
|
| 285 | + * |
|
| 286 | + * @param WPInv_Subscription $item |
|
| 287 | + * @since 1.0.0 |
|
| 288 | + * @return string |
|
| 289 | + */ |
|
| 290 | + public function column_renewals( $item ) { |
|
| 291 | + $max_bills = $item->get_bill_times(); |
|
| 292 | + return $item->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "∞" : $max_bills ); |
|
| 293 | + } |
|
| 294 | + |
|
| 295 | + /** |
|
| 296 | + * Product ID column |
|
| 297 | + * |
|
| 298 | + * @param WPInv_Subscription $item |
|
| 299 | + * @since 1.0.0 |
|
| 300 | + * @return string |
|
| 301 | + */ |
|
| 302 | + public function column_item( $item ) { |
|
| 303 | + $subscription_group = getpaid_get_invoice_subscription_group( $item->get_parent_invoice_id(), $item->get_id() ); |
|
| 304 | + |
|
| 305 | + if ( empty( $subscription_group ) ) { |
|
| 306 | + return $this->generate_item_markup( $item->get_product_id() ); |
|
| 307 | + } |
|
| 308 | + |
|
| 309 | + $markup = array_map( array( $this, 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
| 310 | + return implode( ' | ', $markup ); |
|
| 311 | + |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + /** |
|
| 315 | + * Generates the items markup. |
|
| 316 | + * |
|
| 317 | + * @param int $item_id |
|
| 318 | + * @since 1.0.0 |
|
| 319 | + * @return string |
|
| 320 | + */ |
|
| 321 | + public static function generate_item_markup( $item_id ) { |
|
| 322 | + $item = get_post( $item_id ); |
|
| 323 | + |
|
| 324 | + if ( ! empty( $item ) ) { |
|
| 325 | + $link = get_edit_post_link( $item ); |
|
| 326 | + $link = esc_url( $link ); |
|
| 327 | + $name = esc_html( get_the_title( $item ) ); |
|
| 328 | + return wpinv_current_user_can_manage_invoicing() ? "<a href='$link'>$name</a>" : $name; |
|
| 329 | + } else { |
|
| 330 | + return sprintf( __( 'Item #%s', 'invoicing' ), $item_id ); |
|
| 331 | + } |
|
| 332 | + |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + /** |
|
| 336 | + * Retrieve the current page number |
|
| 337 | + * |
|
| 338 | + * @return int |
|
| 339 | + */ |
|
| 340 | + public function get_paged() { |
|
| 341 | + return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
| 342 | + } |
|
| 343 | + |
|
| 344 | + /** |
|
| 345 | + * Setup the final data for the table |
|
| 346 | + * |
|
| 347 | + */ |
|
| 348 | + public function prepare_items() { |
|
| 349 | + |
|
| 350 | + $columns = $this->get_columns(); |
|
| 351 | + $hidden = array(); |
|
| 352 | + $sortable = $this->get_sortable_columns(); |
|
| 353 | + |
|
| 354 | + $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
| 355 | + |
|
| 356 | + $this->set_pagination_args( |
|
| 357 | + array( |
|
| 358 | + 'total_items' => $this->current_total_count, |
|
| 359 | + 'per_page' => $this->per_page, |
|
| 360 | + 'total_pages' => ceil( $this->current_total_count / $this->per_page ) |
|
| 361 | + ) |
|
| 362 | + ); |
|
| 363 | + } |
|
| 364 | + |
|
| 365 | + /** |
|
| 366 | + * Table columns |
|
| 367 | + * |
|
| 368 | + * @return array |
|
| 369 | + */ |
|
| 370 | + public function get_columns(){ |
|
| 371 | + $columns = array( |
|
| 372 | + 'cb' => '<input type="checkbox" />', |
|
| 373 | + 'subscription' => __( 'Subscription', 'invoicing' ), |
|
| 374 | + 'start_date' => __( 'Start Date', 'invoicing' ), |
|
| 375 | + 'renewal_date' => __( 'Next Payment', 'invoicing' ), |
|
| 376 | + 'renewals' => __( 'Payments', 'invoicing' ), |
|
| 377 | + 'item' => __( 'Items', 'invoicing' ), |
|
| 378 | + 'status' => __( 'Status', 'invoicing' ), |
|
| 379 | + ); |
|
| 380 | + |
|
| 381 | + return apply_filters( 'manage_getpaid_subscriptions_table_columns', $columns ); |
|
| 382 | + } |
|
| 383 | + |
|
| 384 | + /** |
|
| 385 | + * Sortable table columns. |
|
| 386 | + * |
|
| 387 | + * @return array |
|
| 388 | + */ |
|
| 389 | + public function get_sortable_columns() { |
|
| 390 | + $sortable = array( |
|
| 391 | + 'subscription' => array( 'id', true ), |
|
| 392 | + 'start_date' => array( 'created', true ), |
|
| 393 | + 'renewal_date' => array( 'expiration', true ), |
|
| 394 | + 'renewals' => array( 'bill_times', true ), |
|
| 395 | + 'item' => array( 'product_id', true ), |
|
| 396 | + 'status' => array( 'status', true ), |
|
| 397 | + ); |
|
| 398 | + |
|
| 399 | + return apply_filters( 'manage_getpaid_subscriptions_sortable_table_columns', $sortable ); |
|
| 400 | + } |
|
| 401 | + |
|
| 402 | + /** |
|
| 403 | + * Whether the table has items to display or not |
|
| 404 | + * |
|
| 405 | + * @return bool |
|
| 406 | + */ |
|
| 407 | + public function has_items() { |
|
| 408 | + return ! empty( $this->current_total_count ); |
|
| 409 | + } |
|
| 410 | + |
|
| 411 | + /** |
|
| 412 | + * Processes bulk actions. |
|
| 413 | + * |
|
| 414 | + */ |
|
| 415 | + public function process_bulk_action() { |
|
| 416 | + |
|
| 417 | + } |
|
| 418 | 418 | |
| 419 | 419 | } |
@@ -14,7 +14,7 @@ discard block |
||
| 14 | 14 | */ |
| 15 | 15 | function wpinv_subscriptions_page() { |
| 16 | 16 | |
| 17 | - ?> |
|
| 17 | + ?> |
|
| 18 | 18 | |
| 19 | 19 | <div class="wrap"> |
| 20 | 20 | <h1><?php echo esc_html( get_admin_page_title() ); ?></h1> |
@@ -22,27 +22,27 @@ discard block |
||
| 22 | 22 | |
| 23 | 23 | <?php |
| 24 | 24 | |
| 25 | - // Verify user permissions. |
|
| 26 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
| 25 | + // Verify user permissions. |
|
| 26 | + if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
| 27 | 27 | |
| 28 | - echo aui()->alert( |
|
| 29 | - array( |
|
| 30 | - 'type' => 'danger', |
|
| 31 | - 'content' => __( 'You are not permitted to view this page.', 'invoicing' ), |
|
| 32 | - ) |
|
| 33 | - ); |
|
| 28 | + echo aui()->alert( |
|
| 29 | + array( |
|
| 30 | + 'type' => 'danger', |
|
| 31 | + 'content' => __( 'You are not permitted to view this page.', 'invoicing' ), |
|
| 32 | + ) |
|
| 33 | + ); |
|
| 34 | 34 | |
| 35 | - } else if ( ! empty( $_GET['id'] ) && is_numeric( $_GET['id'] ) ) { |
|
| 35 | + } else if ( ! empty( $_GET['id'] ) && is_numeric( $_GET['id'] ) ) { |
|
| 36 | 36 | |
| 37 | - // Display a single subscription. |
|
| 38 | - wpinv_recurring_subscription_details(); |
|
| 39 | - } else { |
|
| 37 | + // Display a single subscription. |
|
| 38 | + wpinv_recurring_subscription_details(); |
|
| 39 | + } else { |
|
| 40 | 40 | |
| 41 | - // Display a list of available subscriptions. |
|
| 42 | - getpaid_print_subscriptions_list(); |
|
| 43 | - } |
|
| 41 | + // Display a list of available subscriptions. |
|
| 42 | + getpaid_print_subscriptions_list(); |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - ?> |
|
| 45 | + ?> |
|
| 46 | 46 | |
| 47 | 47 | </div> |
| 48 | 48 | </div> |
@@ -59,10 +59,10 @@ discard block |
||
| 59 | 59 | */ |
| 60 | 60 | function getpaid_print_subscriptions_list() { |
| 61 | 61 | |
| 62 | - $subscribers_table = new WPInv_Subscriptions_List_Table(); |
|
| 63 | - $subscribers_table->prepare_items(); |
|
| 62 | + $subscribers_table = new WPInv_Subscriptions_List_Table(); |
|
| 63 | + $subscribers_table->prepare_items(); |
|
| 64 | 64 | |
| 65 | - ?> |
|
| 65 | + ?> |
|
| 66 | 66 | <form id="subscribers-filter" class="bsui" method="get"> |
| 67 | 67 | <input type="hidden" name="page" value="wpinv-subscriptions" /> |
| 68 | 68 | <?php $subscribers_table->views(); ?> |
@@ -80,41 +80,41 @@ discard block |
||
| 80 | 80 | */ |
| 81 | 81 | function wpinv_recurring_subscription_details() { |
| 82 | 82 | |
| 83 | - // Fetch the subscription. |
|
| 84 | - $sub = new WPInv_Subscription( (int) $_GET['id'] ); |
|
| 85 | - if ( ! $sub->exists() ) { |
|
| 83 | + // Fetch the subscription. |
|
| 84 | + $sub = new WPInv_Subscription( (int) $_GET['id'] ); |
|
| 85 | + if ( ! $sub->exists() ) { |
|
| 86 | 86 | |
| 87 | - echo aui()->alert( |
|
| 88 | - array( |
|
| 89 | - 'type' => 'danger', |
|
| 90 | - 'content' => __( 'Subscription not found.', 'invoicing' ), |
|
| 91 | - ) |
|
| 92 | - ); |
|
| 87 | + echo aui()->alert( |
|
| 88 | + array( |
|
| 89 | + 'type' => 'danger', |
|
| 90 | + 'content' => __( 'Subscription not found.', 'invoicing' ), |
|
| 91 | + ) |
|
| 92 | + ); |
|
| 93 | 93 | |
| 94 | - return; |
|
| 95 | - } |
|
| 94 | + return; |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - // Use metaboxes to display the subscription details. |
|
| 98 | - add_meta_box( 'getpaid_admin_subscription_details_metabox', __( 'Subscription Details', 'invoicing' ), 'getpaid_admin_subscription_details_metabox', get_current_screen(), 'normal', 'high' ); |
|
| 99 | - add_meta_box( 'getpaid_admin_subscription_update_metabox', __( 'Change Status', 'invoicing' ), 'getpaid_admin_subscription_update_metabox', get_current_screen(), 'side' ); |
|
| 97 | + // Use metaboxes to display the subscription details. |
|
| 98 | + add_meta_box( 'getpaid_admin_subscription_details_metabox', __( 'Subscription Details', 'invoicing' ), 'getpaid_admin_subscription_details_metabox', get_current_screen(), 'normal', 'high' ); |
|
| 99 | + add_meta_box( 'getpaid_admin_subscription_update_metabox', __( 'Change Status', 'invoicing' ), 'getpaid_admin_subscription_update_metabox', get_current_screen(), 'side' ); |
|
| 100 | 100 | |
| 101 | - $subscription_id = $sub->get_id(); |
|
| 102 | - $subscription_groups = getpaid_get_invoice_subscription_groups( $sub->get_parent_invoice_id() ); |
|
| 103 | - $subscription_group = wp_list_filter( $subscription_groups, compact( 'subscription_id' ) ); |
|
| 101 | + $subscription_id = $sub->get_id(); |
|
| 102 | + $subscription_groups = getpaid_get_invoice_subscription_groups( $sub->get_parent_invoice_id() ); |
|
| 103 | + $subscription_group = wp_list_filter( $subscription_groups, compact( 'subscription_id' ) ); |
|
| 104 | 104 | |
| 105 | - if ( 1 < count( $subscription_groups ) ) { |
|
| 106 | - add_meta_box( 'getpaid_admin_subscription_related_subscriptions_metabox', __( 'Related Subscriptions', 'invoicing' ), 'getpaid_admin_subscription_related_subscriptions_metabox', get_current_screen(), 'advanced' ); |
|
| 107 | - } |
|
| 105 | + if ( 1 < count( $subscription_groups ) ) { |
|
| 106 | + add_meta_box( 'getpaid_admin_subscription_related_subscriptions_metabox', __( 'Related Subscriptions', 'invoicing' ), 'getpaid_admin_subscription_related_subscriptions_metabox', get_current_screen(), 'advanced' ); |
|
| 107 | + } |
|
| 108 | 108 | |
| 109 | - if ( ! empty( $subscription_group ) ) { |
|
| 110 | - add_meta_box( 'getpaid_admin_subscription_item_details_metabox', __( 'Subscription Items', 'invoicing' ), 'getpaid_admin_subscription_item_details_metabox', get_current_screen(), 'normal', 'low' ); |
|
| 111 | - } |
|
| 109 | + if ( ! empty( $subscription_group ) ) { |
|
| 110 | + add_meta_box( 'getpaid_admin_subscription_item_details_metabox', __( 'Subscription Items', 'invoicing' ), 'getpaid_admin_subscription_item_details_metabox', get_current_screen(), 'normal', 'low' ); |
|
| 111 | + } |
|
| 112 | 112 | |
| 113 | - add_meta_box( 'getpaid_admin_subscription_invoice_details_metabox', __( 'Related Invoices', 'invoicing' ), 'getpaid_admin_subscription_invoice_details_metabox', get_current_screen(), 'advanced' ); |
|
| 113 | + add_meta_box( 'getpaid_admin_subscription_invoice_details_metabox', __( 'Related Invoices', 'invoicing' ), 'getpaid_admin_subscription_invoice_details_metabox', get_current_screen(), 'advanced' ); |
|
| 114 | 114 | |
| 115 | - do_action( 'getpaid_admin_single_subscription_register_metabox', $sub ); |
|
| 115 | + do_action( 'getpaid_admin_single_subscription_register_metabox', $sub ); |
|
| 116 | 116 | |
| 117 | - ?> |
|
| 117 | + ?> |
|
| 118 | 118 | |
| 119 | 119 | <form method="post" action="<?php echo admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $sub->get_id() ) ); ?>"> |
| 120 | 120 | |
@@ -154,45 +154,45 @@ discard block |
||
| 154 | 154 | */ |
| 155 | 155 | function getpaid_admin_subscription_details_metabox( $sub ) { |
| 156 | 156 | |
| 157 | - // Subscription items. |
|
| 158 | - $subscription_group = getpaid_get_invoice_subscription_group( $sub->get_parent_invoice_id(), $sub->get_id() ); |
|
| 159 | - $items_count = empty( $subscription_group ) ? 1 : count( $subscription_group['items'] ); |
|
| 160 | - |
|
| 161 | - // Prepare subscription detail columns. |
|
| 162 | - $fields = apply_filters( |
|
| 163 | - 'getpaid_subscription_admin_page_fields', |
|
| 164 | - array( |
|
| 165 | - 'subscription' => __( 'Subscription', 'invoicing' ), |
|
| 166 | - 'customer' => __( 'Customer', 'invoicing' ), |
|
| 167 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
| 168 | - 'start_date' => __( 'Start Date', 'invoicing' ), |
|
| 169 | - 'renews_on' => __( 'Next Payment', 'invoicing' ), |
|
| 170 | - 'renewals' => __( 'Payments', 'invoicing' ), |
|
| 171 | - 'item' => _n( 'Item', 'Items', $items_count, 'invoicing' ), |
|
| 172 | - 'gateway' => __( 'Payment Method', 'invoicing' ), |
|
| 173 | - 'profile_id' => __( 'Profile ID', 'invoicing' ), |
|
| 174 | - 'status' => __( 'Status', 'invoicing' ), |
|
| 175 | - ) |
|
| 176 | - ); |
|
| 177 | - |
|
| 178 | - if ( ! $sub->is_active() ) { |
|
| 179 | - |
|
| 180 | - if ( isset( $fields['renews_on'] ) ) { |
|
| 181 | - unset( $fields['renews_on'] ); |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - if ( isset( $fields['gateway'] ) ) { |
|
| 185 | - unset( $fields['gateway'] ); |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - $profile_id = $sub->get_profile_id(); |
|
| 191 | - if ( empty( $profile_id ) && isset( $fields['profile_id'] ) ) { |
|
| 192 | - unset( $fields['profile_id'] ); |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - ?> |
|
| 157 | + // Subscription items. |
|
| 158 | + $subscription_group = getpaid_get_invoice_subscription_group( $sub->get_parent_invoice_id(), $sub->get_id() ); |
|
| 159 | + $items_count = empty( $subscription_group ) ? 1 : count( $subscription_group['items'] ); |
|
| 160 | + |
|
| 161 | + // Prepare subscription detail columns. |
|
| 162 | + $fields = apply_filters( |
|
| 163 | + 'getpaid_subscription_admin_page_fields', |
|
| 164 | + array( |
|
| 165 | + 'subscription' => __( 'Subscription', 'invoicing' ), |
|
| 166 | + 'customer' => __( 'Customer', 'invoicing' ), |
|
| 167 | + 'amount' => __( 'Amount', 'invoicing' ), |
|
| 168 | + 'start_date' => __( 'Start Date', 'invoicing' ), |
|
| 169 | + 'renews_on' => __( 'Next Payment', 'invoicing' ), |
|
| 170 | + 'renewals' => __( 'Payments', 'invoicing' ), |
|
| 171 | + 'item' => _n( 'Item', 'Items', $items_count, 'invoicing' ), |
|
| 172 | + 'gateway' => __( 'Payment Method', 'invoicing' ), |
|
| 173 | + 'profile_id' => __( 'Profile ID', 'invoicing' ), |
|
| 174 | + 'status' => __( 'Status', 'invoicing' ), |
|
| 175 | + ) |
|
| 176 | + ); |
|
| 177 | + |
|
| 178 | + if ( ! $sub->is_active() ) { |
|
| 179 | + |
|
| 180 | + if ( isset( $fields['renews_on'] ) ) { |
|
| 181 | + unset( $fields['renews_on'] ); |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + if ( isset( $fields['gateway'] ) ) { |
|
| 185 | + unset( $fields['gateway'] ); |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + $profile_id = $sub->get_profile_id(); |
|
| 191 | + if ( empty( $profile_id ) && isset( $fields['profile_id'] ) ) { |
|
| 192 | + unset( $fields['profile_id'] ); |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + ?> |
|
| 196 | 196 | |
| 197 | 197 | <table class="table table-borderless" style="font-size: 14px;"> |
| 198 | 198 | <tbody> |
@@ -226,20 +226,20 @@ discard block |
||
| 226 | 226 | */ |
| 227 | 227 | function getpaid_admin_subscription_metabox_display_customer( $subscription ) { |
| 228 | 228 | |
| 229 | - $username = __( '(Missing User)', 'invoicing' ); |
|
| 229 | + $username = __( '(Missing User)', 'invoicing' ); |
|
| 230 | 230 | |
| 231 | - $user = get_userdata( $subscription->get_customer_id() ); |
|
| 232 | - if ( $user ) { |
|
| 231 | + $user = get_userdata( $subscription->get_customer_id() ); |
|
| 232 | + if ( $user ) { |
|
| 233 | 233 | |
| 234 | - $username = sprintf( |
|
| 235 | - '<a href="user-edit.php?user_id=%s">%s</a>', |
|
| 236 | - absint( $user->ID ), |
|
| 237 | - ! empty( $user->display_name ) ? sanitize_text_field( $user->display_name ) : sanitize_email( $user->user_email ) |
|
| 238 | - ); |
|
| 234 | + $username = sprintf( |
|
| 235 | + '<a href="user-edit.php?user_id=%s">%s</a>', |
|
| 236 | + absint( $user->ID ), |
|
| 237 | + ! empty( $user->display_name ) ? sanitize_text_field( $user->display_name ) : sanitize_email( $user->user_email ) |
|
| 238 | + ); |
|
| 239 | 239 | |
| 240 | - } |
|
| 240 | + } |
|
| 241 | 241 | |
| 242 | - echo $username; |
|
| 242 | + echo $username; |
|
| 243 | 243 | } |
| 244 | 244 | add_action( 'getpaid_subscription_admin_display_customer', 'getpaid_admin_subscription_metabox_display_customer' ); |
| 245 | 245 | |
@@ -249,8 +249,8 @@ discard block |
||
| 249 | 249 | * @param WPInv_Subscription $subscription |
| 250 | 250 | */ |
| 251 | 251 | function getpaid_admin_subscription_metabox_display_amount( $subscription ) { |
| 252 | - $amount = sanitize_text_field( getpaid_get_formatted_subscription_amount( $subscription ) ); |
|
| 253 | - echo "<span>$amount</span>"; |
|
| 252 | + $amount = sanitize_text_field( getpaid_get_formatted_subscription_amount( $subscription ) ); |
|
| 253 | + echo "<span>$amount</span>"; |
|
| 254 | 254 | } |
| 255 | 255 | add_action( 'getpaid_subscription_admin_display_amount', 'getpaid_admin_subscription_metabox_display_amount' ); |
| 256 | 256 | |
@@ -260,7 +260,7 @@ discard block |
||
| 260 | 260 | * @param WPInv_Subscription $subscription |
| 261 | 261 | */ |
| 262 | 262 | function getpaid_admin_subscription_metabox_display_id( $subscription ) { |
| 263 | - echo '#' . absint( $subscription->get_id() ); |
|
| 263 | + echo '#' . absint( $subscription->get_id() ); |
|
| 264 | 264 | } |
| 265 | 265 | add_action( 'getpaid_subscription_admin_display_subscription', 'getpaid_admin_subscription_metabox_display_id' ); |
| 266 | 266 | |
@@ -270,7 +270,7 @@ discard block |
||
| 270 | 270 | * @param WPInv_Subscription $subscription |
| 271 | 271 | */ |
| 272 | 272 | function getpaid_admin_subscription_metabox_display_start_date( $subscription ) { |
| 273 | - echo getpaid_format_date_value( $subscription->get_date_created() ); |
|
| 273 | + echo getpaid_format_date_value( $subscription->get_date_created() ); |
|
| 274 | 274 | } |
| 275 | 275 | add_action( 'getpaid_subscription_admin_display_start_date', 'getpaid_admin_subscription_metabox_display_start_date' ); |
| 276 | 276 | |
@@ -280,7 +280,7 @@ discard block |
||
| 280 | 280 | * @param WPInv_Subscription $subscription |
| 281 | 281 | */ |
| 282 | 282 | function getpaid_admin_subscription_metabox_display_renews_on( $subscription ) { |
| 283 | - echo getpaid_format_date_value( $subscription->get_expiration() ); |
|
| 283 | + echo getpaid_format_date_value( $subscription->get_expiration() ); |
|
| 284 | 284 | } |
| 285 | 285 | add_action( 'getpaid_subscription_admin_display_renews_on', 'getpaid_admin_subscription_metabox_display_renews_on' ); |
| 286 | 286 | |
@@ -290,8 +290,8 @@ discard block |
||
| 290 | 290 | * @param WPInv_Subscription $subscription |
| 291 | 291 | */ |
| 292 | 292 | function getpaid_admin_subscription_metabox_display_renewals( $subscription ) { |
| 293 | - $max_bills = $subscription->get_bill_times(); |
|
| 294 | - echo $subscription->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "∞" : $max_bills ); |
|
| 293 | + $max_bills = $subscription->get_bill_times(); |
|
| 294 | + echo $subscription->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "∞" : $max_bills ); |
|
| 295 | 295 | } |
| 296 | 296 | add_action( 'getpaid_subscription_admin_display_renewals', 'getpaid_admin_subscription_metabox_display_renewals' ); |
| 297 | 297 | /** |
@@ -302,13 +302,13 @@ discard block |
||
| 302 | 302 | */ |
| 303 | 303 | function getpaid_admin_subscription_metabox_display_item( $subscription, $subscription_group = false ) { |
| 304 | 304 | |
| 305 | - if ( empty( $subscription_group ) ) { |
|
| 306 | - echo WPInv_Subscriptions_List_Table::generate_item_markup( $subscription->get_product_id() ); |
|
| 307 | - return; |
|
| 308 | - } |
|
| 305 | + if ( empty( $subscription_group ) ) { |
|
| 306 | + echo WPInv_Subscriptions_List_Table::generate_item_markup( $subscription->get_product_id() ); |
|
| 307 | + return; |
|
| 308 | + } |
|
| 309 | 309 | |
| 310 | - $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
| 311 | - echo implode( ' | ', $markup ); |
|
| 310 | + $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
| 311 | + echo implode( ' | ', $markup ); |
|
| 312 | 312 | |
| 313 | 313 | } |
| 314 | 314 | add_action( 'getpaid_subscription_admin_display_item', 'getpaid_admin_subscription_metabox_display_item', 10, 2 ); |
@@ -320,13 +320,13 @@ discard block |
||
| 320 | 320 | */ |
| 321 | 321 | function getpaid_admin_subscription_metabox_display_gateway( $subscription ) { |
| 322 | 322 | |
| 323 | - $gateway = $subscription->get_gateway(); |
|
| 323 | + $gateway = $subscription->get_gateway(); |
|
| 324 | 324 | |
| 325 | - if ( ! empty( $gateway ) ) { |
|
| 326 | - echo sanitize_text_field( wpinv_get_gateway_admin_label( $gateway ) ); |
|
| 327 | - } else { |
|
| 328 | - echo "—"; |
|
| 329 | - } |
|
| 325 | + if ( ! empty( $gateway ) ) { |
|
| 326 | + echo sanitize_text_field( wpinv_get_gateway_admin_label( $gateway ) ); |
|
| 327 | + } else { |
|
| 328 | + echo "—"; |
|
| 329 | + } |
|
| 330 | 330 | |
| 331 | 331 | } |
| 332 | 332 | add_action( 'getpaid_subscription_admin_display_gateway', 'getpaid_admin_subscription_metabox_display_gateway' ); |
@@ -337,7 +337,7 @@ discard block |
||
| 337 | 337 | * @param WPInv_Subscription $subscription |
| 338 | 338 | */ |
| 339 | 339 | function getpaid_admin_subscription_metabox_display_status( $subscription ) { |
| 340 | - echo $subscription->get_status_label_html(); |
|
| 340 | + echo $subscription->get_status_label_html(); |
|
| 341 | 341 | } |
| 342 | 342 | add_action( 'getpaid_subscription_admin_display_status', 'getpaid_admin_subscription_metabox_display_status' ); |
| 343 | 343 | |
@@ -348,29 +348,29 @@ discard block |
||
| 348 | 348 | */ |
| 349 | 349 | function getpaid_admin_subscription_metabox_display_profile_id( $subscription ) { |
| 350 | 350 | |
| 351 | - $profile_id = $subscription->get_profile_id(); |
|
| 352 | - |
|
| 353 | - $input = aui()->input( |
|
| 354 | - array( |
|
| 355 | - 'type' => 'text', |
|
| 356 | - 'id' => 'wpinv_subscription_profile_id', |
|
| 357 | - 'name' => 'wpinv_subscription_profile_id', |
|
| 358 | - 'label' => __( 'Profile Id', 'invoicing' ), |
|
| 359 | - 'label_type' => 'hidden', |
|
| 360 | - 'placeholder' => __( 'Profile Id', 'invoicing' ), |
|
| 361 | - 'value' => sanitize_text_field( $profile_id ), |
|
| 362 | - 'input_group_right' => '', |
|
| 363 | - 'no_wrap' => true, |
|
| 364 | - ) |
|
| 365 | - ); |
|
| 366 | - |
|
| 367 | - echo str_ireplace( 'form-control', 'regular-text', $input ); |
|
| 368 | - |
|
| 369 | - $url = apply_filters( 'getpaid_remote_subscription_profile_url', '', $subscription ); |
|
| 370 | - if ( ! empty( $url ) ) { |
|
| 371 | - $url = esc_url_raw( $url ); |
|
| 372 | - echo ' <a href="' . $url . '" title="' . __( 'View in Gateway', 'invoicing' ) . '" target="_blank"><i class="fas fa-external-link-alt fa-xs fa-fw align-top"></i></a>'; |
|
| 373 | - } |
|
| 351 | + $profile_id = $subscription->get_profile_id(); |
|
| 352 | + |
|
| 353 | + $input = aui()->input( |
|
| 354 | + array( |
|
| 355 | + 'type' => 'text', |
|
| 356 | + 'id' => 'wpinv_subscription_profile_id', |
|
| 357 | + 'name' => 'wpinv_subscription_profile_id', |
|
| 358 | + 'label' => __( 'Profile Id', 'invoicing' ), |
|
| 359 | + 'label_type' => 'hidden', |
|
| 360 | + 'placeholder' => __( 'Profile Id', 'invoicing' ), |
|
| 361 | + 'value' => sanitize_text_field( $profile_id ), |
|
| 362 | + 'input_group_right' => '', |
|
| 363 | + 'no_wrap' => true, |
|
| 364 | + ) |
|
| 365 | + ); |
|
| 366 | + |
|
| 367 | + echo str_ireplace( 'form-control', 'regular-text', $input ); |
|
| 368 | + |
|
| 369 | + $url = apply_filters( 'getpaid_remote_subscription_profile_url', '', $subscription ); |
|
| 370 | + if ( ! empty( $url ) ) { |
|
| 371 | + $url = esc_url_raw( $url ); |
|
| 372 | + echo ' <a href="' . $url . '" title="' . __( 'View in Gateway', 'invoicing' ) . '" target="_blank"><i class="fas fa-external-link-alt fa-xs fa-fw align-top"></i></a>'; |
|
| 373 | + } |
|
| 374 | 374 | |
| 375 | 375 | } |
| 376 | 376 | add_action( 'getpaid_subscription_admin_display_profile_id', 'getpaid_admin_subscription_metabox_display_profile_id' ); |
@@ -382,39 +382,39 @@ discard block |
||
| 382 | 382 | */ |
| 383 | 383 | function getpaid_admin_subscription_update_metabox( $subscription ) { |
| 384 | 384 | |
| 385 | - ?> |
|
| 385 | + ?> |
|
| 386 | 386 | <div class="mt-3"> |
| 387 | 387 | |
| 388 | 388 | <?php |
| 389 | - echo aui()->select( |
|
| 390 | - array( |
|
| 391 | - 'options' => getpaid_get_subscription_statuses(), |
|
| 392 | - 'name' => 'subscription_status', |
|
| 393 | - 'id' => 'subscription_status_update_select', |
|
| 394 | - 'required' => true, |
|
| 395 | - 'no_wrap' => false, |
|
| 396 | - 'label' => __( 'Subscription Status', 'invoicing' ), |
|
| 397 | - 'help_text' => __( 'Updating the status will trigger related actions and hooks', 'invoicing' ), |
|
| 398 | - 'select2' => true, |
|
| 399 | - 'value' => $subscription->get_status( 'edit' ), |
|
| 400 | - ) |
|
| 401 | - ); |
|
| 402 | - ?> |
|
| 389 | + echo aui()->select( |
|
| 390 | + array( |
|
| 391 | + 'options' => getpaid_get_subscription_statuses(), |
|
| 392 | + 'name' => 'subscription_status', |
|
| 393 | + 'id' => 'subscription_status_update_select', |
|
| 394 | + 'required' => true, |
|
| 395 | + 'no_wrap' => false, |
|
| 396 | + 'label' => __( 'Subscription Status', 'invoicing' ), |
|
| 397 | + 'help_text' => __( 'Updating the status will trigger related actions and hooks', 'invoicing' ), |
|
| 398 | + 'select2' => true, |
|
| 399 | + 'value' => $subscription->get_status( 'edit' ), |
|
| 400 | + ) |
|
| 401 | + ); |
|
| 402 | + ?> |
|
| 403 | 403 | |
| 404 | 404 | <div class="mt-2 px-3 py-2 bg-light border-top" style="margin: -12px;"> |
| 405 | 405 | |
| 406 | 406 | <?php |
| 407 | - submit_button( __( 'Update', 'invoicing' ), 'primary', 'submit', false ); |
|
| 407 | + submit_button( __( 'Update', 'invoicing' ), 'primary', 'submit', false ); |
|
| 408 | 408 | |
| 409 | - $url = esc_url( wp_nonce_url( add_query_arg( 'getpaid-admin-action', 'subscription_manual_renew' ), 'getpaid-nonce', 'getpaid-nonce' ) ); |
|
| 410 | - $anchor = __( 'Renew Subscription', 'invoicing' ); |
|
| 411 | - $title = esc_attr__( 'Are you sure you want to extend the subscription and generate a new invoice that will be automatically marked as paid?', 'invoicing' ); |
|
| 409 | + $url = esc_url( wp_nonce_url( add_query_arg( 'getpaid-admin-action', 'subscription_manual_renew' ), 'getpaid-nonce', 'getpaid-nonce' ) ); |
|
| 410 | + $anchor = __( 'Renew Subscription', 'invoicing' ); |
|
| 411 | + $title = esc_attr__( 'Are you sure you want to extend the subscription and generate a new invoice that will be automatically marked as paid?', 'invoicing' ); |
|
| 412 | 412 | |
| 413 | - if ( $subscription->is_active() ) { |
|
| 414 | - echo "<a href='$url' class='float-right text-muted' onclick='return confirm(\"$title\")'>$anchor</a>"; |
|
| 415 | - } |
|
| 413 | + if ( $subscription->is_active() ) { |
|
| 414 | + echo "<a href='$url' class='float-right text-muted' onclick='return confirm(\"$title\")'>$anchor</a>"; |
|
| 415 | + } |
|
| 416 | 416 | |
| 417 | - echo '</div></div>'; |
|
| 417 | + echo '</div></div>'; |
|
| 418 | 418 | } |
| 419 | 419 | |
| 420 | 420 | /** |
@@ -425,33 +425,33 @@ discard block |
||
| 425 | 425 | */ |
| 426 | 426 | function getpaid_admin_subscription_invoice_details_metabox( $subscription, $strict = true ) { |
| 427 | 427 | |
| 428 | - $columns = apply_filters( |
|
| 429 | - 'getpaid_subscription_related_invoices_columns', |
|
| 430 | - array( |
|
| 431 | - 'invoice' => __( 'Invoice', 'invoicing' ), |
|
| 432 | - 'relationship' => __( 'Relationship', 'invoicing' ), |
|
| 433 | - 'date' => __( 'Date', 'invoicing' ), |
|
| 434 | - 'status' => __( 'Status', 'invoicing' ), |
|
| 435 | - 'total' => __( 'Total', 'invoicing' ), |
|
| 436 | - ), |
|
| 437 | - $subscription |
|
| 438 | - ); |
|
| 439 | - |
|
| 440 | - // Prepare the invoices. |
|
| 441 | - $payments = $subscription->get_child_payments( ! is_admin() ); |
|
| 442 | - $parent = $subscription->get_parent_invoice(); |
|
| 443 | - |
|
| 444 | - if ( $parent->exists() ) { |
|
| 445 | - $payments = array_merge( array( $parent ), $payments ); |
|
| 446 | - } |
|
| 447 | - |
|
| 448 | - $table_class = 'w-100 bg-white'; |
|
| 449 | - |
|
| 450 | - if ( ! is_admin() ) { |
|
| 451 | - $table_class = 'table table-bordered'; |
|
| 452 | - } |
|
| 453 | - |
|
| 454 | - ?> |
|
| 428 | + $columns = apply_filters( |
|
| 429 | + 'getpaid_subscription_related_invoices_columns', |
|
| 430 | + array( |
|
| 431 | + 'invoice' => __( 'Invoice', 'invoicing' ), |
|
| 432 | + 'relationship' => __( 'Relationship', 'invoicing' ), |
|
| 433 | + 'date' => __( 'Date', 'invoicing' ), |
|
| 434 | + 'status' => __( 'Status', 'invoicing' ), |
|
| 435 | + 'total' => __( 'Total', 'invoicing' ), |
|
| 436 | + ), |
|
| 437 | + $subscription |
|
| 438 | + ); |
|
| 439 | + |
|
| 440 | + // Prepare the invoices. |
|
| 441 | + $payments = $subscription->get_child_payments( ! is_admin() ); |
|
| 442 | + $parent = $subscription->get_parent_invoice(); |
|
| 443 | + |
|
| 444 | + if ( $parent->exists() ) { |
|
| 445 | + $payments = array_merge( array( $parent ), $payments ); |
|
| 446 | + } |
|
| 447 | + |
|
| 448 | + $table_class = 'w-100 bg-white'; |
|
| 449 | + |
|
| 450 | + if ( ! is_admin() ) { |
|
| 451 | + $table_class = 'table table-bordered'; |
|
| 452 | + } |
|
| 453 | + |
|
| 454 | + ?> |
|
| 455 | 455 | <div class="m-0" style="overflow: auto;"> |
| 456 | 456 | |
| 457 | 457 | <table class="<?php echo $table_class; ?>"> |
@@ -459,14 +459,14 @@ discard block |
||
| 459 | 459 | <thead> |
| 460 | 460 | <tr> |
| 461 | 461 | <?php |
| 462 | - foreach ( $columns as $key => $label ) { |
|
| 463 | - $key = esc_attr( $key ); |
|
| 464 | - $label = sanitize_text_field( $label ); |
|
| 465 | - $class = 'text-left'; |
|
| 466 | - |
|
| 467 | - echo "<th class='subscription-invoice-field-$key bg-light p-2 $class color-dark font-weight-bold'>$label</th>"; |
|
| 468 | - } |
|
| 469 | - ?> |
|
| 462 | + foreach ( $columns as $key => $label ) { |
|
| 463 | + $key = esc_attr( $key ); |
|
| 464 | + $label = sanitize_text_field( $label ); |
|
| 465 | + $class = 'text-left'; |
|
| 466 | + |
|
| 467 | + echo "<th class='subscription-invoice-field-$key bg-light p-2 $class color-dark font-weight-bold'>$label</th>"; |
|
| 468 | + } |
|
| 469 | + ?> |
|
| 470 | 470 | </tr> |
| 471 | 471 | </thead> |
| 472 | 472 | |
@@ -482,73 +482,73 @@ discard block |
||
| 482 | 482 | |
| 483 | 483 | <?php |
| 484 | 484 | |
| 485 | - foreach( $payments as $payment ) : |
|
| 485 | + foreach( $payments as $payment ) : |
|
| 486 | 486 | |
| 487 | - // Ensure that we have an invoice. |
|
| 488 | - $payment = new WPInv_Invoice( $payment ); |
|
| 487 | + // Ensure that we have an invoice. |
|
| 488 | + $payment = new WPInv_Invoice( $payment ); |
|
| 489 | 489 | |
| 490 | - // Abort if the invoice is invalid... |
|
| 491 | - if ( ! $payment->exists() ) { |
|
| 492 | - continue; |
|
| 493 | - } |
|
| 490 | + // Abort if the invoice is invalid... |
|
| 491 | + if ( ! $payment->exists() ) { |
|
| 492 | + continue; |
|
| 493 | + } |
|
| 494 | 494 | |
| 495 | - // ... or belongs to a different subscription. |
|
| 496 | - if ( $strict && $payment->is_renewal() && $payment->get_subscription_id() && $payment->get_subscription_id() != $subscription->get_id() ) { |
|
| 497 | - continue; |
|
| 498 | - } |
|
| 495 | + // ... or belongs to a different subscription. |
|
| 496 | + if ( $strict && $payment->is_renewal() && $payment->get_subscription_id() && $payment->get_subscription_id() != $subscription->get_id() ) { |
|
| 497 | + continue; |
|
| 498 | + } |
|
| 499 | 499 | |
| 500 | - echo '<tr>'; |
|
| 500 | + echo '<tr>'; |
|
| 501 | 501 | |
| 502 | - foreach ( array_keys( $columns ) as $key ) { |
|
| 502 | + foreach ( array_keys( $columns ) as $key ) { |
|
| 503 | 503 | |
| 504 | - $class = 'text-left'; |
|
| 504 | + $class = 'text-left'; |
|
| 505 | 505 | |
| 506 | - echo "<td class='p-2 $class'>"; |
|
| 506 | + echo "<td class='p-2 $class'>"; |
|
| 507 | 507 | |
| 508 | - switch( $key ) { |
|
| 508 | + switch( $key ) { |
|
| 509 | 509 | |
| 510 | - case 'total': |
|
| 511 | - echo '<strong>' . wpinv_price( $payment->get_total(), $payment->get_currency() ) . '</strong>'; |
|
| 512 | - break; |
|
| 510 | + case 'total': |
|
| 511 | + echo '<strong>' . wpinv_price( $payment->get_total(), $payment->get_currency() ) . '</strong>'; |
|
| 512 | + break; |
|
| 513 | 513 | |
| 514 | - case 'relationship': |
|
| 515 | - echo $payment->is_renewal() ? __( 'Renewal Invoice', 'invoicing' ) : __( 'Initial Invoice', 'invoicing' ); |
|
| 516 | - break; |
|
| 514 | + case 'relationship': |
|
| 515 | + echo $payment->is_renewal() ? __( 'Renewal Invoice', 'invoicing' ) : __( 'Initial Invoice', 'invoicing' ); |
|
| 516 | + break; |
|
| 517 | 517 | |
| 518 | - case 'date': |
|
| 519 | - echo getpaid_format_date_value( $payment->get_date_created() ); |
|
| 520 | - break; |
|
| 518 | + case 'date': |
|
| 519 | + echo getpaid_format_date_value( $payment->get_date_created() ); |
|
| 520 | + break; |
|
| 521 | 521 | |
| 522 | - case 'status': |
|
| 522 | + case 'status': |
|
| 523 | 523 | |
| 524 | - $status = $payment->get_status_nicename(); |
|
| 525 | - if ( is_admin() ) { |
|
| 526 | - $status = $payment->get_status_label_html(); |
|
| 527 | - } |
|
| 524 | + $status = $payment->get_status_nicename(); |
|
| 525 | + if ( is_admin() ) { |
|
| 526 | + $status = $payment->get_status_label_html(); |
|
| 527 | + } |
|
| 528 | 528 | |
| 529 | - echo $status; |
|
| 530 | - break; |
|
| 529 | + echo $status; |
|
| 530 | + break; |
|
| 531 | 531 | |
| 532 | - case 'invoice': |
|
| 533 | - $link = esc_url( get_edit_post_link( $payment->get_id() ) ); |
|
| 532 | + case 'invoice': |
|
| 533 | + $link = esc_url( get_edit_post_link( $payment->get_id() ) ); |
|
| 534 | 534 | |
| 535 | - if ( ! is_admin() ) { |
|
| 536 | - $link = esc_url( $payment->get_view_url() ); |
|
| 537 | - } |
|
| 535 | + if ( ! is_admin() ) { |
|
| 536 | + $link = esc_url( $payment->get_view_url() ); |
|
| 537 | + } |
|
| 538 | 538 | |
| 539 | - $invoice = sanitize_text_field( $payment->get_number() ); |
|
| 540 | - echo "<a href='$link'>$invoice</a>"; |
|
| 541 | - break; |
|
| 542 | - } |
|
| 539 | + $invoice = sanitize_text_field( $payment->get_number() ); |
|
| 540 | + echo "<a href='$link'>$invoice</a>"; |
|
| 541 | + break; |
|
| 542 | + } |
|
| 543 | 543 | |
| 544 | - echo '</td>'; |
|
| 544 | + echo '</td>'; |
|
| 545 | 545 | |
| 546 | - } |
|
| 546 | + } |
|
| 547 | 547 | |
| 548 | - echo '</tr>'; |
|
| 548 | + echo '</tr>'; |
|
| 549 | 549 | |
| 550 | - endforeach; |
|
| 551 | - ?> |
|
| 550 | + endforeach; |
|
| 551 | + ?> |
|
| 552 | 552 | |
| 553 | 553 | </tbody> |
| 554 | 554 | |
@@ -566,42 +566,42 @@ discard block |
||
| 566 | 566 | */ |
| 567 | 567 | function getpaid_admin_subscription_item_details_metabox( $subscription ) { |
| 568 | 568 | |
| 569 | - // Fetch the subscription group. |
|
| 570 | - $subscription_group = getpaid_get_invoice_subscription_group( $subscription->get_parent_payment_id(), $subscription->get_id() ); |
|
| 569 | + // Fetch the subscription group. |
|
| 570 | + $subscription_group = getpaid_get_invoice_subscription_group( $subscription->get_parent_payment_id(), $subscription->get_id() ); |
|
| 571 | 571 | |
| 572 | - if ( empty( $subscription_group ) || empty( $subscription_group['items'] ) ) { |
|
| 573 | - return; |
|
| 574 | - } |
|
| 572 | + if ( empty( $subscription_group ) || empty( $subscription_group['items'] ) ) { |
|
| 573 | + return; |
|
| 574 | + } |
|
| 575 | 575 | |
| 576 | - // Prepare table columns. |
|
| 577 | - $columns = apply_filters( |
|
| 578 | - 'getpaid_subscription_item_details_columns', |
|
| 579 | - array( |
|
| 580 | - 'item_name' => __( 'Item', 'invoicing' ), |
|
| 581 | - 'price' => __( 'Price', 'invoicing' ), |
|
| 582 | - 'tax' => __( 'Tax', 'invoicing' ), |
|
| 583 | - 'discount' => __( 'Discount', 'invoicing' ), |
|
| 584 | - 'initial' => __( 'Initial Amount', 'invoicing' ), |
|
| 585 | - 'recurring' => __( 'Recurring Amount', 'invoicing' ), |
|
| 586 | - ), |
|
| 587 | - $subscription |
|
| 588 | - ); |
|
| 576 | + // Prepare table columns. |
|
| 577 | + $columns = apply_filters( |
|
| 578 | + 'getpaid_subscription_item_details_columns', |
|
| 579 | + array( |
|
| 580 | + 'item_name' => __( 'Item', 'invoicing' ), |
|
| 581 | + 'price' => __( 'Price', 'invoicing' ), |
|
| 582 | + 'tax' => __( 'Tax', 'invoicing' ), |
|
| 583 | + 'discount' => __( 'Discount', 'invoicing' ), |
|
| 584 | + 'initial' => __( 'Initial Amount', 'invoicing' ), |
|
| 585 | + 'recurring' => __( 'Recurring Amount', 'invoicing' ), |
|
| 586 | + ), |
|
| 587 | + $subscription |
|
| 588 | + ); |
|
| 589 | 589 | |
| 590 | - // Prepare the invoices. |
|
| 590 | + // Prepare the invoices. |
|
| 591 | 591 | |
| 592 | - $invoice = $subscription->get_parent_invoice(); |
|
| 592 | + $invoice = $subscription->get_parent_invoice(); |
|
| 593 | 593 | |
| 594 | - if ( ( ! wpinv_use_taxes() || ! $invoice->is_taxable() ) && isset( $columns['tax'] ) ) { |
|
| 595 | - unset( $columns['tax'] ); |
|
| 596 | - } |
|
| 594 | + if ( ( ! wpinv_use_taxes() || ! $invoice->is_taxable() ) && isset( $columns['tax'] ) ) { |
|
| 595 | + unset( $columns['tax'] ); |
|
| 596 | + } |
|
| 597 | 597 | |
| 598 | - $table_class = 'w-100 bg-white'; |
|
| 598 | + $table_class = 'w-100 bg-white'; |
|
| 599 | 599 | |
| 600 | - if ( ! is_admin() ) { |
|
| 601 | - $table_class = 'table table-bordered'; |
|
| 602 | - } |
|
| 600 | + if ( ! is_admin() ) { |
|
| 601 | + $table_class = 'table table-bordered'; |
|
| 602 | + } |
|
| 603 | 603 | |
| 604 | - ?> |
|
| 604 | + ?> |
|
| 605 | 605 | <div class="m-0" style="overflow: auto;"> |
| 606 | 606 | |
| 607 | 607 | <table class="<?php echo $table_class; ?>"> |
@@ -610,14 +610,14 @@ discard block |
||
| 610 | 610 | <tr> |
| 611 | 611 | <?php |
| 612 | 612 | |
| 613 | - foreach ( $columns as $key => $label ) { |
|
| 614 | - $key = esc_attr( $key ); |
|
| 615 | - $label = sanitize_text_field( $label ); |
|
| 616 | - $class = 'text-left'; |
|
| 613 | + foreach ( $columns as $key => $label ) { |
|
| 614 | + $key = esc_attr( $key ); |
|
| 615 | + $label = sanitize_text_field( $label ); |
|
| 616 | + $class = 'text-left'; |
|
| 617 | 617 | |
| 618 | - echo "<th class='subscription-item-field-$key bg-light p-2 $class color-dark font-weight-bold'>$label</th>"; |
|
| 619 | - } |
|
| 620 | - ?> |
|
| 618 | + echo "<th class='subscription-item-field-$key bg-light p-2 $class color-dark font-weight-bold'>$label</th>"; |
|
| 619 | + } |
|
| 620 | + ?> |
|
| 621 | 621 | </tr> |
| 622 | 622 | </thead> |
| 623 | 623 | |
@@ -625,106 +625,106 @@ discard block |
||
| 625 | 625 | |
| 626 | 626 | <?php |
| 627 | 627 | |
| 628 | - foreach( $subscription_group['items'] as $subscription_group_item ) : |
|
| 628 | + foreach( $subscription_group['items'] as $subscription_group_item ) : |
|
| 629 | 629 | |
| 630 | - echo '<tr>'; |
|
| 630 | + echo '<tr>'; |
|
| 631 | 631 | |
| 632 | - foreach ( array_keys( $columns ) as $key ) { |
|
| 632 | + foreach ( array_keys( $columns ) as $key ) { |
|
| 633 | 633 | |
| 634 | - $class = 'text-left'; |
|
| 634 | + $class = 'text-left'; |
|
| 635 | 635 | |
| 636 | - echo "<td class='p-2 $class'>"; |
|
| 636 | + echo "<td class='p-2 $class'>"; |
|
| 637 | 637 | |
| 638 | - switch( $key ) { |
|
| 638 | + switch( $key ) { |
|
| 639 | 639 | |
| 640 | - case 'item_name': |
|
| 641 | - $item_name = get_the_title( $subscription_group_item['item_id'] ); |
|
| 642 | - $item_name = empty( $item_name ) ? $subscription_group_item['item_name'] : $item_name; |
|
| 640 | + case 'item_name': |
|
| 641 | + $item_name = get_the_title( $subscription_group_item['item_id'] ); |
|
| 642 | + $item_name = empty( $item_name ) ? $subscription_group_item['item_name'] : $item_name; |
|
| 643 | 643 | |
| 644 | - if ( $invoice->get_template() == 'amount' || 1 === (int) $subscription_group_item['quantity'] ) { |
|
| 645 | - echo sanitize_text_field( $item_name ); |
|
| 646 | - } else { |
|
| 647 | - printf( '%1$s x %2$d', sanitize_text_field( $item_name ), (int) $subscription_group_item['quantity'] ); |
|
| 648 | - } |
|
| 644 | + if ( $invoice->get_template() == 'amount' || 1 === (int) $subscription_group_item['quantity'] ) { |
|
| 645 | + echo sanitize_text_field( $item_name ); |
|
| 646 | + } else { |
|
| 647 | + printf( '%1$s x %2$d', sanitize_text_field( $item_name ), (int) $subscription_group_item['quantity'] ); |
|
| 648 | + } |
|
| 649 | 649 | |
| 650 | - break; |
|
| 650 | + break; |
|
| 651 | 651 | |
| 652 | - case 'price': |
|
| 653 | - echo wpinv_price( $subscription_group_item['price'], $invoice->get_currency() ); |
|
| 654 | - break; |
|
| 652 | + case 'price': |
|
| 653 | + echo wpinv_price( $subscription_group_item['price'], $invoice->get_currency() ); |
|
| 654 | + break; |
|
| 655 | 655 | |
| 656 | - case 'tax': |
|
| 657 | - echo wpinv_price( $subscription_group_item['tax'], $invoice->get_currency() ); |
|
| 658 | - break; |
|
| 656 | + case 'tax': |
|
| 657 | + echo wpinv_price( $subscription_group_item['tax'], $invoice->get_currency() ); |
|
| 658 | + break; |
|
| 659 | 659 | |
| 660 | - case 'discount': |
|
| 661 | - echo wpinv_price( $subscription_group_item['discount'], $invoice->get_currency() ); |
|
| 662 | - break; |
|
| 660 | + case 'discount': |
|
| 661 | + echo wpinv_price( $subscription_group_item['discount'], $invoice->get_currency() ); |
|
| 662 | + break; |
|
| 663 | 663 | |
| 664 | - case 'initial': |
|
| 665 | - echo wpinv_price( $subscription_group_item['subtotal'], $invoice->get_currency() ); |
|
| 666 | - break; |
|
| 664 | + case 'initial': |
|
| 665 | + echo wpinv_price( $subscription_group_item['subtotal'], $invoice->get_currency() ); |
|
| 666 | + break; |
|
| 667 | 667 | |
| 668 | - case 'recurring': |
|
| 669 | - echo '<strong>' . wpinv_price( $subscription_group_item['price'] * $subscription_group_item['quantity'], $invoice->get_currency() ) . '</strong>'; |
|
| 670 | - break; |
|
| 668 | + case 'recurring': |
|
| 669 | + echo '<strong>' . wpinv_price( $subscription_group_item['price'] * $subscription_group_item['quantity'], $invoice->get_currency() ) . '</strong>'; |
|
| 670 | + break; |
|
| 671 | 671 | |
| 672 | - } |
|
| 672 | + } |
|
| 673 | 673 | |
| 674 | - echo '</td>'; |
|
| 674 | + echo '</td>'; |
|
| 675 | 675 | |
| 676 | - } |
|
| 676 | + } |
|
| 677 | 677 | |
| 678 | - echo '</tr>'; |
|
| 678 | + echo '</tr>'; |
|
| 679 | 679 | |
| 680 | - endforeach; |
|
| 680 | + endforeach; |
|
| 681 | 681 | |
| 682 | - foreach( $subscription_group['fees'] as $subscription_group_fee ) : |
|
| 682 | + foreach( $subscription_group['fees'] as $subscription_group_fee ) : |
|
| 683 | 683 | |
| 684 | - echo '<tr>'; |
|
| 684 | + echo '<tr>'; |
|
| 685 | 685 | |
| 686 | - foreach ( array_keys( $columns ) as $key ) { |
|
| 686 | + foreach ( array_keys( $columns ) as $key ) { |
|
| 687 | 687 | |
| 688 | - $class = 'text-left'; |
|
| 688 | + $class = 'text-left'; |
|
| 689 | 689 | |
| 690 | - echo "<td class='p-2 $class'>"; |
|
| 690 | + echo "<td class='p-2 $class'>"; |
|
| 691 | 691 | |
| 692 | - switch( $key ) { |
|
| 692 | + switch( $key ) { |
|
| 693 | 693 | |
| 694 | - case 'item_name': |
|
| 695 | - echo sanitize_text_field( $subscription_group_fee['name'] ); |
|
| 696 | - break; |
|
| 694 | + case 'item_name': |
|
| 695 | + echo sanitize_text_field( $subscription_group_fee['name'] ); |
|
| 696 | + break; |
|
| 697 | 697 | |
| 698 | - case 'price': |
|
| 699 | - echo wpinv_price( $subscription_group_fee['initial_fee'], $invoice->get_currency() ); |
|
| 700 | - break; |
|
| 698 | + case 'price': |
|
| 699 | + echo wpinv_price( $subscription_group_fee['initial_fee'], $invoice->get_currency() ); |
|
| 700 | + break; |
|
| 701 | 701 | |
| 702 | - case 'tax': |
|
| 703 | - echo "—"; |
|
| 704 | - break; |
|
| 702 | + case 'tax': |
|
| 703 | + echo "—"; |
|
| 704 | + break; |
|
| 705 | 705 | |
| 706 | - case 'discount': |
|
| 707 | - echo "—"; |
|
| 708 | - break; |
|
| 706 | + case 'discount': |
|
| 707 | + echo "—"; |
|
| 708 | + break; |
|
| 709 | 709 | |
| 710 | - case 'initial': |
|
| 711 | - echo wpinv_price( $subscription_group_fee['initial_fee'], $invoice->get_currency() ); |
|
| 712 | - break; |
|
| 710 | + case 'initial': |
|
| 711 | + echo wpinv_price( $subscription_group_fee['initial_fee'], $invoice->get_currency() ); |
|
| 712 | + break; |
|
| 713 | 713 | |
| 714 | - case 'recurring': |
|
| 715 | - echo '<strong>' . wpinv_price( $subscription_group_fee['recurring_fee'], $invoice->get_currency() ) . '</strong>'; |
|
| 716 | - break; |
|
| 714 | + case 'recurring': |
|
| 715 | + echo '<strong>' . wpinv_price( $subscription_group_fee['recurring_fee'], $invoice->get_currency() ) . '</strong>'; |
|
| 716 | + break; |
|
| 717 | 717 | |
| 718 | - } |
|
| 718 | + } |
|
| 719 | 719 | |
| 720 | - echo '</td>'; |
|
| 720 | + echo '</td>'; |
|
| 721 | 721 | |
| 722 | - } |
|
| 722 | + } |
|
| 723 | 723 | |
| 724 | - echo '</tr>'; |
|
| 724 | + echo '</tr>'; |
|
| 725 | 725 | |
| 726 | - endforeach; |
|
| 727 | - ?> |
|
| 726 | + endforeach; |
|
| 727 | + ?> |
|
| 728 | 728 | |
| 729 | 729 | </tbody> |
| 730 | 730 | |
@@ -743,34 +743,34 @@ discard block |
||
| 743 | 743 | */ |
| 744 | 744 | function getpaid_admin_subscription_related_subscriptions_metabox( $subscription, $skip_current = true ) { |
| 745 | 745 | |
| 746 | - // Fetch the subscription groups. |
|
| 747 | - $subscription_groups = getpaid_get_invoice_subscription_groups( $subscription->get_parent_payment_id() ); |
|
| 748 | - |
|
| 749 | - if ( empty( $subscription_groups ) ) { |
|
| 750 | - return; |
|
| 751 | - } |
|
| 752 | - |
|
| 753 | - // Prepare table columns. |
|
| 754 | - $columns = apply_filters( |
|
| 755 | - 'getpaid_subscription_related_subscriptions_columns', |
|
| 756 | - array( |
|
| 757 | - 'subscription' => __( 'Subscription', 'invoicing' ), |
|
| 758 | - 'start_date' => __( 'Start Date', 'invoicing' ), |
|
| 759 | - 'renewal_date' => __( 'Next Payment', 'invoicing' ), |
|
| 760 | - 'renewals' => __( 'Payments', 'invoicing' ), |
|
| 761 | - 'item' => __( 'Items', 'invoicing' ), |
|
| 762 | - 'status' => __( 'Status', 'invoicing' ), |
|
| 763 | - ), |
|
| 764 | - $subscription |
|
| 765 | - ); |
|
| 766 | - |
|
| 767 | - $table_class = 'w-100 bg-white'; |
|
| 768 | - |
|
| 769 | - if ( ! is_admin() ) { |
|
| 770 | - $table_class = 'table table-bordered'; |
|
| 771 | - } |
|
| 772 | - |
|
| 773 | - ?> |
|
| 746 | + // Fetch the subscription groups. |
|
| 747 | + $subscription_groups = getpaid_get_invoice_subscription_groups( $subscription->get_parent_payment_id() ); |
|
| 748 | + |
|
| 749 | + if ( empty( $subscription_groups ) ) { |
|
| 750 | + return; |
|
| 751 | + } |
|
| 752 | + |
|
| 753 | + // Prepare table columns. |
|
| 754 | + $columns = apply_filters( |
|
| 755 | + 'getpaid_subscription_related_subscriptions_columns', |
|
| 756 | + array( |
|
| 757 | + 'subscription' => __( 'Subscription', 'invoicing' ), |
|
| 758 | + 'start_date' => __( 'Start Date', 'invoicing' ), |
|
| 759 | + 'renewal_date' => __( 'Next Payment', 'invoicing' ), |
|
| 760 | + 'renewals' => __( 'Payments', 'invoicing' ), |
|
| 761 | + 'item' => __( 'Items', 'invoicing' ), |
|
| 762 | + 'status' => __( 'Status', 'invoicing' ), |
|
| 763 | + ), |
|
| 764 | + $subscription |
|
| 765 | + ); |
|
| 766 | + |
|
| 767 | + $table_class = 'w-100 bg-white'; |
|
| 768 | + |
|
| 769 | + if ( ! is_admin() ) { |
|
| 770 | + $table_class = 'table table-bordered'; |
|
| 771 | + } |
|
| 772 | + |
|
| 773 | + ?> |
|
| 774 | 774 | <div class="m-0" style="overflow: auto;"> |
| 775 | 775 | |
| 776 | 776 | <table class="<?php echo $table_class; ?>"> |
@@ -779,14 +779,14 @@ discard block |
||
| 779 | 779 | <tr> |
| 780 | 780 | <?php |
| 781 | 781 | |
| 782 | - foreach ( $columns as $key => $label ) { |
|
| 783 | - $key = esc_attr( $key ); |
|
| 784 | - $label = sanitize_text_field( $label ); |
|
| 785 | - $class = 'text-left'; |
|
| 782 | + foreach ( $columns as $key => $label ) { |
|
| 783 | + $key = esc_attr( $key ); |
|
| 784 | + $label = sanitize_text_field( $label ); |
|
| 785 | + $class = 'text-left'; |
|
| 786 | 786 | |
| 787 | - echo "<th class='related-subscription-field-$key bg-light p-2 $class color-dark font-weight-bold'>$label</th>"; |
|
| 788 | - } |
|
| 789 | - ?> |
|
| 787 | + echo "<th class='related-subscription-field-$key bg-light p-2 $class color-dark font-weight-bold'>$label</th>"; |
|
| 788 | + } |
|
| 789 | + ?> |
|
| 790 | 790 | </tr> |
| 791 | 791 | </thead> |
| 792 | 792 | |
@@ -794,74 +794,74 @@ discard block |
||
| 794 | 794 | |
| 795 | 795 | <?php |
| 796 | 796 | |
| 797 | - foreach( $subscription_groups as $subscription_group ) : |
|
| 797 | + foreach( $subscription_groups as $subscription_group ) : |
|
| 798 | 798 | |
| 799 | - // Do not list current subscription. |
|
| 800 | - if ( $skip_current && (int) $subscription_group['subscription_id'] === $subscription->get_id() ) { |
|
| 801 | - continue; |
|
| 802 | - } |
|
| 799 | + // Do not list current subscription. |
|
| 800 | + if ( $skip_current && (int) $subscription_group['subscription_id'] === $subscription->get_id() ) { |
|
| 801 | + continue; |
|
| 802 | + } |
|
| 803 | 803 | |
| 804 | - // Ensure the subscription exists. |
|
| 805 | - $_suscription = new WPInv_Subscription( $subscription_group['subscription_id'] ); |
|
| 804 | + // Ensure the subscription exists. |
|
| 805 | + $_suscription = new WPInv_Subscription( $subscription_group['subscription_id'] ); |
|
| 806 | 806 | |
| 807 | - if ( ! $_suscription->exists() ) { |
|
| 808 | - continue; |
|
| 809 | - } |
|
| 807 | + if ( ! $_suscription->exists() ) { |
|
| 808 | + continue; |
|
| 809 | + } |
|
| 810 | 810 | |
| 811 | - echo '<tr>'; |
|
| 811 | + echo '<tr>'; |
|
| 812 | 812 | |
| 813 | - foreach ( array_keys( $columns ) as $key ) { |
|
| 813 | + foreach ( array_keys( $columns ) as $key ) { |
|
| 814 | 814 | |
| 815 | - $class = 'text-left'; |
|
| 815 | + $class = 'text-left'; |
|
| 816 | 816 | |
| 817 | - echo "<td class='p-2 $class'>"; |
|
| 817 | + echo "<td class='p-2 $class'>"; |
|
| 818 | 818 | |
| 819 | - switch( $key ) { |
|
| 819 | + switch( $key ) { |
|
| 820 | 820 | |
| 821 | - case 'status': |
|
| 822 | - echo $_suscription->get_status_label_html(); |
|
| 823 | - break; |
|
| 821 | + case 'status': |
|
| 822 | + echo $_suscription->get_status_label_html(); |
|
| 823 | + break; |
|
| 824 | 824 | |
| 825 | - case 'item': |
|
| 826 | - $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
| 827 | - echo implode( ' | ', $markup ); |
|
| 828 | - break; |
|
| 825 | + case 'item': |
|
| 826 | + $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
| 827 | + echo implode( ' | ', $markup ); |
|
| 828 | + break; |
|
| 829 | 829 | |
| 830 | - case 'renewals': |
|
| 831 | - $max_bills = $_suscription->get_bill_times(); |
|
| 832 | - echo $_suscription->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "∞" : $max_bills ); |
|
| 833 | - break; |
|
| 830 | + case 'renewals': |
|
| 831 | + $max_bills = $_suscription->get_bill_times(); |
|
| 832 | + echo $_suscription->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "∞" : $max_bills ); |
|
| 833 | + break; |
|
| 834 | 834 | |
| 835 | - case 'renewal_date': |
|
| 836 | - echo $_suscription->is_active() ? getpaid_format_date_value( $_suscription->get_expiration() ) : "—"; |
|
| 837 | - break; |
|
| 835 | + case 'renewal_date': |
|
| 836 | + echo $_suscription->is_active() ? getpaid_format_date_value( $_suscription->get_expiration() ) : "—"; |
|
| 837 | + break; |
|
| 838 | 838 | |
| 839 | - case 'start_date': |
|
| 840 | - echo getpaid_format_date_value( $_suscription->get_date_created() ); |
|
| 841 | - break; |
|
| 839 | + case 'start_date': |
|
| 840 | + echo getpaid_format_date_value( $_suscription->get_date_created() ); |
|
| 841 | + break; |
|
| 842 | 842 | |
| 843 | - case 'subscription': |
|
| 844 | - $url = is_admin() ? admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $_suscription->get_id() ) ) : $_suscription->get_view_url(); |
|
| 845 | - printf( |
|
| 846 | - '%1$s#%2$s%3$s', |
|
| 847 | - '<a href="' . esc_url( $url ) . '">', |
|
| 848 | - '<strong>' . intval( $_suscription->get_id() ) . '</strong>', |
|
| 849 | - '</a>' |
|
| 850 | - ); |
|
| 843 | + case 'subscription': |
|
| 844 | + $url = is_admin() ? admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $_suscription->get_id() ) ) : $_suscription->get_view_url(); |
|
| 845 | + printf( |
|
| 846 | + '%1$s#%2$s%3$s', |
|
| 847 | + '<a href="' . esc_url( $url ) . '">', |
|
| 848 | + '<strong>' . intval( $_suscription->get_id() ) . '</strong>', |
|
| 849 | + '</a>' |
|
| 850 | + ); |
|
| 851 | 851 | |
| 852 | - echo WPInv_Subscriptions_List_Table::column_amount( $_suscription ); |
|
| 853 | - break; |
|
| 852 | + echo WPInv_Subscriptions_List_Table::column_amount( $_suscription ); |
|
| 853 | + break; |
|
| 854 | 854 | |
| 855 | - } |
|
| 855 | + } |
|
| 856 | 856 | |
| 857 | - echo '</td>'; |
|
| 857 | + echo '</td>'; |
|
| 858 | 858 | |
| 859 | - } |
|
| 859 | + } |
|
| 860 | 860 | |
| 861 | - echo '</tr>'; |
|
| 861 | + echo '</tr>'; |
|
| 862 | 862 | |
| 863 | - endforeach; |
|
| 864 | - ?> |
|
| 863 | + endforeach; |
|
| 864 | + ?> |
|
| 865 | 865 | |
| 866 | 866 | </tbody> |
| 867 | 867 | |