1
|
|
|
<?php |
2
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
3
|
|
|
exit; |
4
|
|
|
} |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Invoice widget. |
8
|
|
|
*/ |
9
|
|
|
class WPInv_Invoice_Widget extends WP_Super_Duper { |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Register the widget with WordPress. |
13
|
|
|
* |
14
|
|
|
*/ |
15
|
|
|
public function __construct() { |
16
|
|
|
|
17
|
|
|
|
18
|
|
|
$options = array( |
19
|
|
|
'textdomain' => 'invoicing', |
20
|
|
|
'block-icon' => 'admin-site', |
21
|
|
|
'block-category'=> 'widgets', |
22
|
|
|
'block-keywords'=> "['invoicing','invoice']", |
23
|
|
|
'class_name' => __CLASS__, |
24
|
|
|
'base_id' => 'getpaid_invoice', |
25
|
|
|
'name' => __( 'GetPaid > Single Invoice','invoicing' ), |
26
|
|
|
'widget_ops' => array( |
27
|
|
|
'classname' => 'wpinv-invoice-class bsui', |
28
|
|
|
'description' => esc_html__('Displays a single invoice.','invoicing'), |
29
|
|
|
), |
30
|
|
|
'arguments' => array( |
31
|
|
|
'title' => array( |
32
|
|
|
'title' => __( 'Widget title', 'invoicing' ), |
33
|
|
|
'desc' => __( 'Enter widget title.', 'invoicing' ), |
34
|
|
|
'type' => 'text', |
35
|
|
|
'desc_tip' => true, |
36
|
|
|
'default' => '', |
37
|
|
|
'advanced' => false |
38
|
|
|
), |
39
|
|
|
'id' => array( |
40
|
|
|
'title' => __( 'Invoice', 'invoicing' ), |
41
|
|
|
'desc' => __( 'Enter the invoice ID', 'invoicing' ), |
42
|
|
|
'type' => 'text', |
43
|
|
|
'desc_tip' => true, |
44
|
|
|
'default' => '', |
45
|
|
|
'placeholder' => __('1','invoicing'), |
46
|
|
|
'advanced' => false |
47
|
|
|
), |
48
|
|
|
) |
49
|
|
|
|
50
|
|
|
); |
51
|
|
|
|
52
|
|
|
|
53
|
|
|
parent::__construct( $options ); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* The Super block output function. |
58
|
|
|
* |
59
|
|
|
* @param array $args |
60
|
|
|
* @param array $widget_args |
61
|
|
|
* @param string $content |
62
|
|
|
* |
63
|
|
|
* @return mixed|string|bool |
64
|
|
|
*/ |
65
|
|
|
public function output( $args = array(), $widget_args = array(), $content = '' ) { |
66
|
|
|
|
67
|
|
|
// Is the shortcode set up correctly? |
68
|
|
|
if ( empty( $args['id'] ) ) { |
69
|
|
|
return aui()->alert( |
70
|
|
|
array( |
71
|
|
|
'type' => 'warning', |
72
|
|
|
'content' => __( 'Missing invoice ID', 'invoicing' ), |
73
|
|
|
) |
74
|
|
|
); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
$invoice = wpinv_get_invoice( (int) $args['id'] ); |
78
|
|
|
|
79
|
|
|
if ( $invoice ) { |
80
|
|
|
ob_start(); |
81
|
|
|
getpaid_invoice( $invoice ); |
82
|
|
|
return ob_get_clean(); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
return aui()->alert( |
86
|
|
|
array( |
87
|
|
|
'type' => 'danger', |
88
|
|
|
'content' => __( 'Invoice not found', 'invoicing' ), |
89
|
|
|
) |
90
|
|
|
); |
91
|
|
|
|
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
} |
95
|
|
|
|