@@ -46,25 +46,25 @@ |
||
46 | 46 | parent::__construct( $options ); |
47 | 47 | } |
48 | 48 | |
49 | - /** |
|
50 | - * The Super block output function. |
|
51 | - * |
|
52 | - * @param array $args |
|
53 | - * @param array $widget_args |
|
54 | - * @param string $content |
|
55 | - * |
|
56 | - * @return mixed|string|bool |
|
57 | - */ |
|
49 | + /** |
|
50 | + * The Super block output function. |
|
51 | + * |
|
52 | + * @param array $args |
|
53 | + * @param array $widget_args |
|
54 | + * @param string $content |
|
55 | + * |
|
56 | + * @return mixed|string|bool |
|
57 | + */ |
|
58 | 58 | public function output( $args = array(), $widget_args = array(), $content = '' ) { |
59 | 59 | |
60 | - ob_start(); |
|
60 | + ob_start(); |
|
61 | 61 | |
62 | - do_action( 'wpinv_before_user_invoice_history' ); |
|
63 | - wpinv_get_template_part( 'wpinv-invoice-history' ); |
|
64 | - do_action( 'wpinv_after_user_invoice_history' ); |
|
62 | + do_action( 'wpinv_before_user_invoice_history' ); |
|
63 | + wpinv_get_template_part( 'wpinv-invoice-history' ); |
|
64 | + do_action( 'wpinv_after_user_invoice_history' ); |
|
65 | 65 | |
66 | - $output = ob_get_clean(); |
|
67 | - return trim($output); |
|
66 | + $output = ob_get_clean(); |
|
67 | + return trim($output); |
|
68 | 68 | |
69 | 69 | } |
70 | 70 |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if (!defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -22,15 +22,15 @@ discard block |
||
22 | 22 | 'block-keywords'=> "['invoicing','history']", |
23 | 23 | 'class_name' => __CLASS__, |
24 | 24 | 'base_id' => 'wpinv_history', |
25 | - 'name' => __('Invoicing > Invoice History','invoicing'), |
|
25 | + 'name' => __('Invoicing > Invoice History', 'invoicing'), |
|
26 | 26 | 'widget_ops' => array( |
27 | 27 | 'classname' => 'wpinv-history-class wpi-g', |
28 | - 'description' => esc_html__('Displays invoice history.','invoicing'), |
|
28 | + 'description' => esc_html__('Displays invoice history.', 'invoicing'), |
|
29 | 29 | ), |
30 | 30 | 'arguments' => array( |
31 | 31 | 'title' => array( |
32 | - 'title' => __( 'Widget title', 'invoicing' ), |
|
33 | - 'desc' => __( 'Enter widget title.', 'invoicing' ), |
|
32 | + 'title' => __('Widget title', 'invoicing'), |
|
33 | + 'desc' => __('Enter widget title.', 'invoicing'), |
|
34 | 34 | 'type' => 'text', |
35 | 35 | 'desc_tip' => true, |
36 | 36 | 'default' => '', |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | ); |
42 | 42 | |
43 | 43 | |
44 | - parent::__construct( $options ); |
|
44 | + parent::__construct($options); |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | /** |
@@ -53,13 +53,13 @@ discard block |
||
53 | 53 | * |
54 | 54 | * @return mixed|string|bool |
55 | 55 | */ |
56 | - public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
56 | + public function output($args = array(), $widget_args = array(), $content = '') { |
|
57 | 57 | |
58 | 58 | ob_start(); |
59 | 59 | |
60 | - do_action( 'wpinv_before_user_invoice_history' ); |
|
61 | - wpinv_get_template_part( 'wpinv-invoice-history' ); |
|
62 | - do_action( 'wpinv_after_user_invoice_history' ); |
|
60 | + do_action('wpinv_before_user_invoice_history'); |
|
61 | + wpinv_get_template_part('wpinv-invoice-history'); |
|
62 | + do_action('wpinv_after_user_invoice_history'); |
|
63 | 63 | |
64 | 64 | $output = ob_get_clean(); |
65 | 65 | return trim($output); |
@@ -44,22 +44,22 @@ |
||
44 | 44 | parent::__construct( $options ); |
45 | 45 | } |
46 | 46 | |
47 | - /** |
|
48 | - * The Super block output function. |
|
49 | - * |
|
50 | - * @param array $args |
|
51 | - * @param array $widget_args |
|
52 | - * @param string $content |
|
53 | - * |
|
54 | - * @return mixed|string|bool |
|
55 | - */ |
|
47 | + /** |
|
48 | + * The Super block output function. |
|
49 | + * |
|
50 | + * @param array $args |
|
51 | + * @param array $widget_args |
|
52 | + * @param string $content |
|
53 | + * |
|
54 | + * @return mixed|string|bool |
|
55 | + */ |
|
56 | 56 | public function output( $args = array(), $widget_args = array(), $content = '' ) { |
57 | 57 | |
58 | - ob_start(); |
|
58 | + ob_start(); |
|
59 | 59 | |
60 | - wpinv_print_errors(); |
|
60 | + wpinv_print_errors(); |
|
61 | 61 | |
62 | - return '<div class="wpinv">' . ob_get_clean() . '</div>'; |
|
62 | + return '<div class="wpinv">' . ob_get_clean() . '</div>'; |
|
63 | 63 | |
64 | 64 | } |
65 | 65 |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if (!defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -22,15 +22,15 @@ discard block |
||
22 | 22 | 'block-keywords'=> "['invoicing','history']", |
23 | 23 | 'class_name' => __CLASS__, |
24 | 24 | 'base_id' => 'wpinv_messages', |
25 | - 'name' => __('Invoicing > Invoice Messages','invoicing'), |
|
25 | + 'name' => __('Invoicing > Invoice Messages', 'invoicing'), |
|
26 | 26 | 'widget_ops' => array( |
27 | 27 | 'classname' => 'wpinv-messages-class wpi-g', |
28 | - 'description' => esc_html__('Displays invoice error and warning messages on checkout page.','invoicing'), |
|
28 | + 'description' => esc_html__('Displays invoice error and warning messages on checkout page.', 'invoicing'), |
|
29 | 29 | ), |
30 | 30 | 'arguments' => array( |
31 | 31 | 'title' => array( |
32 | - 'title' => __( 'Widget title', 'invoicing' ), |
|
33 | - 'desc' => __( 'Enter widget title.', 'invoicing' ), |
|
32 | + 'title' => __('Widget title', 'invoicing'), |
|
33 | + 'desc' => __('Enter widget title.', 'invoicing'), |
|
34 | 34 | 'type' => 'text', |
35 | 35 | 'desc_tip' => true, |
36 | 36 | 'default' => '', |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | ); |
42 | 42 | |
43 | 43 | |
44 | - parent::__construct( $options ); |
|
44 | + parent::__construct($options); |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | /** |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | * |
54 | 54 | * @return mixed|string|bool |
55 | 55 | */ |
56 | - public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
56 | + public function output($args = array(), $widget_args = array(), $content = '') { |
|
57 | 57 | |
58 | 58 | ob_start(); |
59 | 59 |
@@ -46,18 +46,18 @@ |
||
46 | 46 | parent::__construct( $options ); |
47 | 47 | } |
48 | 48 | |
49 | - /** |
|
50 | - * The Super block output function. |
|
51 | - * |
|
52 | - * @param array $args |
|
53 | - * @param array $widget_args |
|
54 | - * @param string $content |
|
55 | - * |
|
56 | - * @return mixed|string|bool |
|
57 | - */ |
|
49 | + /** |
|
50 | + * The Super block output function. |
|
51 | + * |
|
52 | + * @param array $args |
|
53 | + * @param array $widget_args |
|
54 | + * @param string $content |
|
55 | + * |
|
56 | + * @return mixed|string|bool |
|
57 | + */ |
|
58 | 58 | public function output( $args = array(), $widget_args = array(), $content = '' ) { |
59 | 59 | |
60 | - return wpinv_checkout_form(); |
|
60 | + return wpinv_checkout_form(); |
|
61 | 61 | |
62 | 62 | } |
63 | 63 |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if (!defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -23,15 +23,15 @@ discard block |
||
23 | 23 | 'block-keywords'=> "['invoicing','checkout']", |
24 | 24 | 'class_name' => __CLASS__, |
25 | 25 | 'base_id' => 'wpinv_checkout', |
26 | - 'name' => __('Invoicing > Checkout','invoicing'), |
|
26 | + 'name' => __('Invoicing > Checkout', 'invoicing'), |
|
27 | 27 | 'widget_ops' => array( |
28 | 28 | 'classname' => 'wpinv-checkout-class wpi-g', |
29 | - 'description' => esc_html__('Displays checkout form.','invoicing'), |
|
29 | + 'description' => esc_html__('Displays checkout form.', 'invoicing'), |
|
30 | 30 | ), |
31 | 31 | 'arguments' => array( |
32 | 32 | 'title' => array( |
33 | - 'title' => __( 'Widget title', 'invoicing' ), |
|
34 | - 'desc' => __( 'Enter widget title.', 'invoicing' ), |
|
33 | + 'title' => __('Widget title', 'invoicing'), |
|
34 | + 'desc' => __('Enter widget title.', 'invoicing'), |
|
35 | 35 | 'type' => 'text', |
36 | 36 | 'desc_tip' => true, |
37 | 37 | 'default' => '', |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | ); |
43 | 43 | |
44 | 44 | |
45 | - parent::__construct( $options ); |
|
45 | + parent::__construct($options); |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | /** |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | * |
55 | 55 | * @return mixed|string|bool |
56 | 56 | */ |
57 | - public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
57 | + public function output($args = array(), $widget_args = array(), $content = '') { |
|
58 | 58 | |
59 | 59 | return wpinv_checkout_form(); |
60 | 60 |
@@ -46,25 +46,25 @@ |
||
46 | 46 | parent::__construct( $options ); |
47 | 47 | } |
48 | 48 | |
49 | - /** |
|
50 | - * The Super block output function. |
|
51 | - * |
|
52 | - * @param array $args |
|
53 | - * @param array $widget_args |
|
54 | - * @param string $content |
|
55 | - * |
|
56 | - * @return mixed|string|bool |
|
57 | - */ |
|
49 | + /** |
|
50 | + * The Super block output function. |
|
51 | + * |
|
52 | + * @param array $args |
|
53 | + * @param array $widget_args |
|
54 | + * @param string $content |
|
55 | + * |
|
56 | + * @return mixed|string|bool |
|
57 | + */ |
|
58 | 58 | public function output( $args = array(), $widget_args = array(), $content = '' ) { |
59 | 59 | |
60 | - ob_start(); |
|
60 | + ob_start(); |
|
61 | 61 | |
62 | - do_action( 'wpinv_before_user_subscriptions' ); |
|
63 | - wpinv_get_template_part( 'wpinv-subscriptions-history' ); |
|
64 | - do_action( 'wpinv_after_user_subscriptions' ); |
|
62 | + do_action( 'wpinv_before_user_subscriptions' ); |
|
63 | + wpinv_get_template_part( 'wpinv-subscriptions-history' ); |
|
64 | + do_action( 'wpinv_after_user_subscriptions' ); |
|
65 | 65 | |
66 | - $output = ob_get_clean(); |
|
67 | - return trim($output); |
|
66 | + $output = ob_get_clean(); |
|
67 | + return trim($output); |
|
68 | 68 | |
69 | 69 | } |
70 | 70 |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if (!defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -22,15 +22,15 @@ discard block |
||
22 | 22 | 'block-keywords'=> "['invoicing','subscriptions']", |
23 | 23 | 'class_name' => __CLASS__, |
24 | 24 | 'base_id' => 'wpinv_subscriptions', |
25 | - 'name' => __('Invoicing > Subscriptions History','invoicing'), |
|
25 | + 'name' => __('Invoicing > Subscriptions History', 'invoicing'), |
|
26 | 26 | 'widget_ops' => array( |
27 | 27 | 'classname' => 'wpinv-checkout-class wpi-g', |
28 | - 'description' => esc_html__('Displays subscriptions history.','invoicing'), |
|
28 | + 'description' => esc_html__('Displays subscriptions history.', 'invoicing'), |
|
29 | 29 | ), |
30 | 30 | 'arguments' => array( |
31 | 31 | 'title' => array( |
32 | - 'title' => __( 'Widget title', 'invoicing' ), |
|
33 | - 'desc' => __( 'Enter widget title.', 'invoicing' ), |
|
32 | + 'title' => __('Widget title', 'invoicing'), |
|
33 | + 'desc' => __('Enter widget title.', 'invoicing'), |
|
34 | 34 | 'type' => 'text', |
35 | 35 | 'desc_tip' => true, |
36 | 36 | 'default' => '', |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | ); |
42 | 42 | |
43 | 43 | |
44 | - parent::__construct( $options ); |
|
44 | + parent::__construct($options); |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | /** |
@@ -53,13 +53,13 @@ discard block |
||
53 | 53 | * |
54 | 54 | * @return mixed|string|bool |
55 | 55 | */ |
56 | - public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
56 | + public function output($args = array(), $widget_args = array(), $content = '') { |
|
57 | 57 | |
58 | 58 | ob_start(); |
59 | 59 | |
60 | - do_action( 'wpinv_before_user_subscriptions' ); |
|
61 | - wpinv_get_template_part( 'wpinv-subscriptions-history' ); |
|
62 | - do_action( 'wpinv_after_user_subscriptions' ); |
|
60 | + do_action('wpinv_before_user_subscriptions'); |
|
61 | + wpinv_get_template_part('wpinv-subscriptions-history'); |
|
62 | + do_action('wpinv_after_user_subscriptions'); |
|
63 | 63 | |
64 | 64 | $output = ob_get_clean(); |
65 | 65 | return trim($output); |
@@ -44,25 +44,25 @@ |
||
44 | 44 | parent::__construct( $options ); |
45 | 45 | } |
46 | 46 | |
47 | - /** |
|
48 | - * The Super block output function. |
|
49 | - * |
|
50 | - * @param array $args |
|
51 | - * @param array $widget_args |
|
52 | - * @param string $content |
|
53 | - * |
|
54 | - * @return mixed|string|bool |
|
55 | - */ |
|
47 | + /** |
|
48 | + * The Super block output function. |
|
49 | + * |
|
50 | + * @param array $args |
|
51 | + * @param array $widget_args |
|
52 | + * @param string $content |
|
53 | + * |
|
54 | + * @return mixed|string|bool |
|
55 | + */ |
|
56 | 56 | public function output( $args = array(), $widget_args = array(), $content = '' ) { |
57 | 57 | |
58 | - ob_start(); |
|
58 | + ob_start(); |
|
59 | 59 | |
60 | - do_action( 'wpinv_success_content_before' ); |
|
61 | - echo wpinv_payment_receipt( $args ); |
|
62 | - do_action( 'wpinv_success_content_after' ); |
|
60 | + do_action( 'wpinv_success_content_before' ); |
|
61 | + echo wpinv_payment_receipt( $args ); |
|
62 | + do_action( 'wpinv_success_content_after' ); |
|
63 | 63 | |
64 | - $output = ob_get_clean(); |
|
65 | - return trim($output); |
|
64 | + $output = ob_get_clean(); |
|
65 | + return trim($output); |
|
66 | 66 | |
67 | 67 | } |
68 | 68 |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if (!defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -22,15 +22,15 @@ discard block |
||
22 | 22 | 'block-keywords'=> "['invoicing','receipt']", |
23 | 23 | 'class_name' => __CLASS__, |
24 | 24 | 'base_id' => 'wpinv_receipt', |
25 | - 'name' => __('Invoicing > Invoice Receipt','invoicing'), |
|
25 | + 'name' => __('Invoicing > Invoice Receipt', 'invoicing'), |
|
26 | 26 | 'widget_ops' => array( |
27 | 27 | 'classname' => 'wpinv-receipt-class wpi-g', |
28 | - 'description' => esc_html__('Displays invoice receipt after checkout.','invoicing'), |
|
28 | + 'description' => esc_html__('Displays invoice receipt after checkout.', 'invoicing'), |
|
29 | 29 | ), |
30 | 30 | 'arguments' => array( |
31 | 31 | 'title' => array( |
32 | - 'title' => __( 'Widget title', 'invoicing' ), |
|
33 | - 'desc' => __( 'Enter widget title.', 'invoicing' ), |
|
32 | + 'title' => __('Widget title', 'invoicing'), |
|
33 | + 'desc' => __('Enter widget title.', 'invoicing'), |
|
34 | 34 | 'type' => 'text', |
35 | 35 | 'desc_tip' => true, |
36 | 36 | 'default' => '', |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | ); |
42 | 42 | |
43 | 43 | |
44 | - parent::__construct( $options ); |
|
44 | + parent::__construct($options); |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | /** |
@@ -53,13 +53,13 @@ discard block |
||
53 | 53 | * |
54 | 54 | * @return mixed|string|bool |
55 | 55 | */ |
56 | - public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
56 | + public function output($args = array(), $widget_args = array(), $content = '') { |
|
57 | 57 | |
58 | 58 | ob_start(); |
59 | 59 | |
60 | - do_action( 'wpinv_success_content_before' ); |
|
61 | - echo wpinv_payment_receipt( $args ); |
|
62 | - do_action( 'wpinv_success_content_after' ); |
|
60 | + do_action('wpinv_success_content_before'); |
|
61 | + echo wpinv_payment_receipt($args); |
|
62 | + do_action('wpinv_success_content_after'); |
|
63 | 63 | |
64 | 64 | $output = ob_get_clean(); |
65 | 65 | return trim($output); |
@@ -139,12 +139,12 @@ discard block |
||
139 | 139 | require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' ); |
140 | 140 | require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' ); |
141 | 141 | require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' ); |
142 | - require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' ); |
|
143 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' ); |
|
144 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' ); |
|
145 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' ); |
|
146 | - require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' ); |
|
147 | - require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' ); |
|
142 | + require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' ); |
|
143 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' ); |
|
144 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' ); |
|
145 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' ); |
|
146 | + require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' ); |
|
147 | + require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' ); |
|
148 | 148 | |
149 | 149 | if ( !class_exists( 'WPInv_EUVat' ) ) { |
150 | 150 | require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' ); |
@@ -420,16 +420,16 @@ discard block |
||
420 | 420 | require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' ); |
421 | 421 | } |
422 | 422 | |
423 | - /** |
|
424 | - * Register widgets |
|
425 | - * |
|
426 | - */ |
|
427 | - public function register_widgets() { |
|
428 | - register_widget( "WPInv_Checkout_Widget" ); |
|
429 | - register_widget( "WPInv_History_Widget" ); |
|
430 | - register_widget( "WPInv_Receipt_Widget" ); |
|
431 | - register_widget( "WPInv_Subscriptions_Widget" ); |
|
432 | - register_widget( "WPInv_Buy_Item_Widget" ); |
|
433 | - register_widget( "WPInv_Messages_Widget" ); |
|
434 | - } |
|
423 | + /** |
|
424 | + * Register widgets |
|
425 | + * |
|
426 | + */ |
|
427 | + public function register_widgets() { |
|
428 | + register_widget( "WPInv_Checkout_Widget" ); |
|
429 | + register_widget( "WPInv_History_Widget" ); |
|
430 | + register_widget( "WPInv_Receipt_Widget" ); |
|
431 | + register_widget( "WPInv_Subscriptions_Widget" ); |
|
432 | + register_widget( "WPInv_Buy_Item_Widget" ); |
|
433 | + register_widget( "WPInv_Messages_Widget" ); |
|
434 | + } |
|
435 | 435 | } |
436 | 436 | \ No newline at end of file |
@@ -7,15 +7,15 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | // MUST have WordPress. |
10 | -if ( !defined( 'WPINC' ) ) { |
|
11 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
10 | +if (!defined('WPINC')) { |
|
11 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | class WPInv_Plugin { |
15 | 15 | private static $instance; |
16 | 16 | |
17 | 17 | public static function run() { |
18 | - if ( !isset( self::$instance ) && !( self::$instance instanceof WPInv_Plugin ) ) { |
|
18 | + if (!isset(self::$instance) && !(self::$instance instanceof WPInv_Plugin)) { |
|
19 | 19 | self::$instance = new WPInv_Plugin; |
20 | 20 | self::$instance->includes(); |
21 | 21 | self::$instance->actions(); |
@@ -32,31 +32,31 @@ discard block |
||
32 | 32 | } |
33 | 33 | |
34 | 34 | public function define_constants() { |
35 | - define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
36 | - define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
35 | + define('WPINV_PLUGIN_DIR', plugin_dir_path(WPINV_PLUGIN_FILE)); |
|
36 | + define('WPINV_PLUGIN_URL', plugin_dir_url(WPINV_PLUGIN_FILE)); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | private function actions() { |
40 | 40 | /* Internationalize the text strings used. */ |
41 | - add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
41 | + add_action('plugins_loaded', array(&$this, 'plugins_loaded')); |
|
42 | 42 | |
43 | 43 | /* Perform actions on admin initialization. */ |
44 | - add_action( 'admin_init', array( &$this, 'admin_init') ); |
|
45 | - add_action( 'init', array( &$this, 'init' ), 3 ); |
|
46 | - add_action( 'init', array( &$this, 'wpinv_actions' ) ); |
|
44 | + add_action('admin_init', array(&$this, 'admin_init')); |
|
45 | + add_action('init', array(&$this, 'init'), 3); |
|
46 | + add_action('init', array(&$this, 'wpinv_actions')); |
|
47 | 47 | |
48 | - if ( class_exists( 'BuddyPress' ) ) { |
|
49 | - add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) ); |
|
48 | + if (class_exists('BuddyPress')) { |
|
49 | + add_action('bp_include', array(&$this, 'bp_invoicing_init')); |
|
50 | 50 | } |
51 | 51 | |
52 | - add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) ); |
|
53 | - add_action( 'widgets_init', array( &$this, 'register_widgets' ) ); |
|
52 | + add_action('wp_enqueue_scripts', array(&$this, 'enqueue_scripts')); |
|
53 | + add_action('widgets_init', array(&$this, 'register_widgets')); |
|
54 | 54 | |
55 | - if ( is_admin() ) { |
|
56 | - add_action( 'admin_enqueue_scripts', array( &$this, 'admin_enqueue_scripts' ) ); |
|
57 | - add_action( 'admin_body_class', array( &$this, 'admin_body_class' ) ); |
|
55 | + if (is_admin()) { |
|
56 | + add_action('admin_enqueue_scripts', array(&$this, 'admin_enqueue_scripts')); |
|
57 | + add_action('admin_body_class', array(&$this, 'admin_body_class')); |
|
58 | 58 | } else { |
59 | - add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
59 | + add_filter('pre_get_posts', array(&$this, 'pre_get_posts')); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | /** |
@@ -66,19 +66,19 @@ discard block |
||
66 | 66 | * |
67 | 67 | * @param WPInv_Plugin $this. Current WPInv_Plugin instance. Passed by reference. |
68 | 68 | */ |
69 | - do_action_ref_array( 'wpinv_actions', array( &$this ) ); |
|
69 | + do_action_ref_array('wpinv_actions', array(&$this)); |
|
70 | 70 | |
71 | - add_action( 'admin_init', array( &$this, 'activation_redirect') ); |
|
71 | + add_action('admin_init', array(&$this, 'activation_redirect')); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | public function plugins_loaded() { |
75 | 75 | /* Internationalize the text strings used. */ |
76 | 76 | $this->load_textdomain(); |
77 | 77 | |
78 | - do_action( 'wpinv_loaded' ); |
|
78 | + do_action('wpinv_loaded'); |
|
79 | 79 | |
80 | 80 | // Fix oxygen page builder conflict |
81 | - if ( function_exists( 'ct_css_output' ) ) { |
|
81 | + if (function_exists('ct_css_output')) { |
|
82 | 82 | wpinv_oxygen_fix_conflict(); |
83 | 83 | } |
84 | 84 | } |
@@ -88,228 +88,228 @@ discard block |
||
88 | 88 | * |
89 | 89 | * @since 1.0 |
90 | 90 | */ |
91 | - public function load_textdomain( $locale = NULL ) { |
|
92 | - if ( empty( $locale ) ) { |
|
93 | - $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale(); |
|
91 | + public function load_textdomain($locale = NULL) { |
|
92 | + if (empty($locale)) { |
|
93 | + $locale = is_admin() && function_exists('get_user_locale') ? get_user_locale() : get_locale(); |
|
94 | 94 | } |
95 | 95 | |
96 | - $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
96 | + $locale = apply_filters('plugin_locale', $locale, 'invoicing'); |
|
97 | 97 | |
98 | - unload_textdomain( 'invoicing' ); |
|
99 | - load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
100 | - load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' ); |
|
98 | + unload_textdomain('invoicing'); |
|
99 | + load_textdomain('invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo'); |
|
100 | + load_plugin_textdomain('invoicing', false, WPINV_PLUGIN_DIR . 'languages'); |
|
101 | 101 | |
102 | 102 | /** |
103 | 103 | * Define language constants. |
104 | 104 | */ |
105 | - require_once( WPINV_PLUGIN_DIR . 'language.php' ); |
|
105 | + require_once(WPINV_PLUGIN_DIR . 'language.php'); |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | public function includes() { |
109 | 109 | global $wpinv_options; |
110 | 110 | |
111 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
|
111 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php'); |
|
112 | 112 | $wpinv_options = wpinv_get_settings(); |
113 | 113 | |
114 | - require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' ); |
|
115 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' ); |
|
116 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' ); |
|
117 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' ); |
|
118 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' ); |
|
119 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' ); |
|
120 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' ); |
|
121 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-invoice-functions.php' ); |
|
122 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' ); |
|
123 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' ); |
|
124 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' ); |
|
125 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' ); |
|
126 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' ); |
|
127 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php' ); |
|
128 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-post-types.php' ); |
|
129 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php' ); |
|
130 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php' ); |
|
131 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php' ); |
|
132 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' ); |
|
133 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' ); |
|
134 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' ); |
|
135 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' ); |
|
136 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' ); |
|
137 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' ); |
|
138 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' ); |
|
139 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
|
140 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' ); |
|
141 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions.php' ); |
|
142 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' ); |
|
143 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-subscriptions-list-table.php' ); |
|
144 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' ); |
|
145 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' ); |
|
146 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' ); |
|
147 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' ); |
|
148 | - require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' ); |
|
149 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' ); |
|
150 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' ); |
|
151 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' ); |
|
152 | - require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' ); |
|
153 | - require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' ); |
|
154 | - |
|
155 | - if ( !class_exists( 'WPInv_EUVat' ) ) { |
|
156 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' ); |
|
114 | + require_once(WPINV_PLUGIN_DIR . 'vendor/autoload.php'); |
|
115 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php'); |
|
116 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php'); |
|
117 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php'); |
|
118 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php'); |
|
119 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php'); |
|
120 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php'); |
|
121 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-invoice-functions.php'); |
|
122 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php'); |
|
123 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php'); |
|
124 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php'); |
|
125 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php'); |
|
126 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php'); |
|
127 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php'); |
|
128 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-post-types.php'); |
|
129 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php'); |
|
130 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php'); |
|
131 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php'); |
|
132 | + require_once(WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php'); |
|
133 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php'); |
|
134 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php'); |
|
135 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php'); |
|
136 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php'); |
|
137 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php'); |
|
138 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php'); |
|
139 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php'); |
|
140 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php'); |
|
141 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions.php'); |
|
142 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php'); |
|
143 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-subscriptions-list-table.php'); |
|
144 | + require_once(WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php'); |
|
145 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php'); |
|
146 | + require_once(WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php'); |
|
147 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php'); |
|
148 | + require_once(WPINV_PLUGIN_DIR . 'widgets/checkout.php'); |
|
149 | + require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-history.php'); |
|
150 | + require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php'); |
|
151 | + require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php'); |
|
152 | + require_once(WPINV_PLUGIN_DIR . 'widgets/subscriptions.php'); |
|
153 | + require_once(WPINV_PLUGIN_DIR . 'widgets/buy-item.php'); |
|
154 | + |
|
155 | + if (!class_exists('WPInv_EUVat')) { |
|
156 | + require_once(WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php'); |
|
157 | 157 | } |
158 | 158 | |
159 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
160 | - if ( !empty( $gateways ) ) { |
|
161 | - foreach ( $gateways as $gateway ) { |
|
162 | - if ( $gateway == 'manual' ) { |
|
159 | + $gateways = array_keys(wpinv_get_enabled_payment_gateways()); |
|
160 | + if (!empty($gateways)) { |
|
161 | + foreach ($gateways as $gateway) { |
|
162 | + if ($gateway == 'manual') { |
|
163 | 163 | continue; |
164 | 164 | } |
165 | 165 | |
166 | 166 | $gateway_file = WPINV_PLUGIN_DIR . 'includes/gateways/' . $gateway . '.php'; |
167 | 167 | |
168 | - if ( file_exists( $gateway_file ) ) { |
|
169 | - require_once( $gateway_file ); |
|
168 | + if (file_exists($gateway_file)) { |
|
169 | + require_once($gateway_file); |
|
170 | 170 | } |
171 | 171 | } |
172 | 172 | } |
173 | - require_once( WPINV_PLUGIN_DIR . 'includes/gateways/manual.php' ); |
|
173 | + require_once(WPINV_PLUGIN_DIR . 'includes/gateways/manual.php'); |
|
174 | 174 | |
175 | - if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
176 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' ); |
|
177 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' ); |
|
178 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-meta-boxes.php' ); |
|
175 | + if (is_admin() || (defined('WP_CLI') && WP_CLI)) { |
|
176 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php'); |
|
177 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php'); |
|
178 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-meta-boxes.php'); |
|
179 | 179 | //require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-recurring-admin.php' ); |
180 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-details.php' ); |
|
181 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-items.php' ); |
|
182 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' ); |
|
183 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-address.php' ); |
|
184 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' ); |
|
185 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' ); |
|
186 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' ); |
|
180 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-details.php'); |
|
181 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-items.php'); |
|
182 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php'); |
|
183 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-address.php'); |
|
184 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php'); |
|
185 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php'); |
|
186 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php'); |
|
187 | 187 | //require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
188 | 188 | // load the user class only on the users.php page |
189 | 189 | global $pagenow; |
190 | - if($pagenow=='users.php'){ |
|
190 | + if ($pagenow == 'users.php') { |
|
191 | 191 | new WPInv_Admin_Users(); |
192 | 192 | } |
193 | 193 | } |
194 | 194 | |
195 | 195 | // Register cli commands |
196 | - if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
197 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' ); |
|
198 | - WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
196 | + if (defined('WP_CLI') && WP_CLI) { |
|
197 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php'); |
|
198 | + WP_CLI::add_command('invoicing', 'WPInv_CLI'); |
|
199 | 199 | } |
200 | 200 | |
201 | 201 | // include css inliner |
202 | - if ( ! class_exists( 'Emogrifier' ) && class_exists( 'DOMDocument' ) ) { |
|
203 | - include_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php' ); |
|
202 | + if (!class_exists('Emogrifier') && class_exists('DOMDocument')) { |
|
203 | + include_once(WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php'); |
|
204 | 204 | } |
205 | 205 | |
206 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' ); |
|
206 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/install.php'); |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | public function init() { |
210 | 210 | } |
211 | 211 | |
212 | 212 | public function admin_init() { |
213 | - add_action( 'admin_print_scripts-edit.php', array( &$this, 'admin_print_scripts_edit_php' ) ); |
|
213 | + add_action('admin_print_scripts-edit.php', array(&$this, 'admin_print_scripts_edit_php')); |
|
214 | 214 | } |
215 | 215 | |
216 | 216 | public function activation_redirect() { |
217 | 217 | // Bail if no activation redirect |
218 | - if ( !get_transient( '_wpinv_activation_redirect' ) ) { |
|
218 | + if (!get_transient('_wpinv_activation_redirect')) { |
|
219 | 219 | return; |
220 | 220 | } |
221 | 221 | |
222 | 222 | // Delete the redirect transient |
223 | - delete_transient( '_wpinv_activation_redirect' ); |
|
223 | + delete_transient('_wpinv_activation_redirect'); |
|
224 | 224 | |
225 | 225 | // Bail if activating from network, or bulk |
226 | - if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
226 | + if (is_network_admin() || isset($_GET['activate-multi'])) { |
|
227 | 227 | return; |
228 | 228 | } |
229 | 229 | |
230 | - wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) ); |
|
230 | + wp_safe_redirect(admin_url('admin.php?page=wpinv-settings&tab=general')); |
|
231 | 231 | exit; |
232 | 232 | } |
233 | 233 | |
234 | 234 | public function enqueue_scripts() { |
235 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
235 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
236 | 236 | |
237 | - wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), WPINV_VERSION ); |
|
238 | - wp_enqueue_style( 'wpinv_front_style' ); |
|
237 | + wp_register_style('wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), WPINV_VERSION); |
|
238 | + wp_enqueue_style('wpinv_front_style'); |
|
239 | 239 | |
240 | 240 | // Register scripts |
241 | - wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
242 | - wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array( 'jquery' ), WPINV_VERSION ); |
|
241 | + wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true); |
|
242 | + wp_register_script('wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array('jquery'), WPINV_VERSION); |
|
243 | 243 | |
244 | 244 | $localize = array(); |
245 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
246 | - $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
245 | + $localize['ajax_url'] = admin_url('admin-ajax.php'); |
|
246 | + $localize['nonce'] = wp_create_nonce('wpinv-nonce'); |
|
247 | 247 | $localize['currency_symbol'] = wpinv_currency_symbol(); |
248 | 248 | $localize['currency_pos'] = wpinv_currency_position(); |
249 | 249 | $localize['thousand_sep'] = wpinv_thousands_separator(); |
250 | 250 | $localize['decimal_sep'] = wpinv_decimal_separator(); |
251 | 251 | $localize['decimals'] = wpinv_decimals(); |
252 | - $localize['txtComplete'] = __( 'Complete', 'invoicing' ); |
|
252 | + $localize['txtComplete'] = __('Complete', 'invoicing'); |
|
253 | 253 | $localize['UseTaxes'] = wpinv_use_taxes(); |
254 | - $localize['checkoutNonce'] = wp_create_nonce( 'wpinv_checkout_nonce' ); |
|
254 | + $localize['checkoutNonce'] = wp_create_nonce('wpinv_checkout_nonce'); |
|
255 | 255 | |
256 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
256 | + $localize = apply_filters('wpinv_front_js_localize', $localize); |
|
257 | 257 | |
258 | - wp_enqueue_script( 'jquery-blockui' ); |
|
258 | + wp_enqueue_script('jquery-blockui'); |
|
259 | 259 | $autofill_api = wpinv_get_option('address_autofill_api'); |
260 | 260 | $autofill_active = wpinv_get_option('address_autofill_active'); |
261 | - if ( isset( $autofill_active ) && 1 == $autofill_active && !empty( $autofill_api ) && wpinv_is_checkout() ) { |
|
262 | - if ( wp_script_is( 'google-maps-api', 'enqueued' ) ) { |
|
263 | - wp_dequeue_script( 'google-maps-api' ); |
|
261 | + if (isset($autofill_active) && 1 == $autofill_active && !empty($autofill_api) && wpinv_is_checkout()) { |
|
262 | + if (wp_script_is('google-maps-api', 'enqueued')) { |
|
263 | + wp_dequeue_script('google-maps-api'); |
|
264 | 264 | } |
265 | - wp_enqueue_script( 'google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array( 'jquery' ), '', false ); |
|
266 | - wp_enqueue_script( 'google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array( 'jquery', 'google-maps-api' ), '', true ); |
|
265 | + wp_enqueue_script('google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array('jquery'), '', false); |
|
266 | + wp_enqueue_script('google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array('jquery', 'google-maps-api'), '', true); |
|
267 | 267 | } |
268 | 268 | |
269 | - wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all' ); |
|
270 | - wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
269 | + wp_enqueue_style("select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all'); |
|
270 | + wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array('jquery'), WPINV_VERSION); |
|
271 | 271 | |
272 | - wp_enqueue_script( 'wpinv-front-script' ); |
|
273 | - wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
272 | + wp_enqueue_script('wpinv-front-script'); |
|
273 | + wp_localize_script('wpinv-front-script', 'WPInv', $localize); |
|
274 | 274 | } |
275 | 275 | |
276 | 276 | public function admin_enqueue_scripts() { |
277 | 277 | global $post, $pagenow; |
278 | 278 | |
279 | 279 | $post_type = wpinv_admin_post_type(); |
280 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
281 | - $page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : ''; |
|
280 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
281 | + $page = isset($_GET['page']) ? strtolower($_GET['page']) : ''; |
|
282 | 282 | |
283 | 283 | $jquery_ui_css = false; |
284 | - if ( ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $post_type == 'wpi_discount' ) && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) ) { |
|
284 | + if (($post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $post_type == 'wpi_discount') && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) { |
|
285 | 285 | $jquery_ui_css = true; |
286 | - } else if ( $page == 'wpinv-settings' || $page == 'wpinv-reports' ) { |
|
286 | + } else if ($page == 'wpinv-settings' || $page == 'wpinv-reports') { |
|
287 | 287 | $jquery_ui_css = true; |
288 | 288 | } |
289 | - if ( $jquery_ui_css ) { |
|
290 | - wp_register_style( 'jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16' ); |
|
291 | - wp_enqueue_style( 'jquery-ui-css' ); |
|
289 | + if ($jquery_ui_css) { |
|
290 | + wp_register_style('jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16'); |
|
291 | + wp_enqueue_style('jquery-ui-css'); |
|
292 | 292 | } |
293 | 293 | |
294 | - wp_register_style( 'wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION ); |
|
295 | - wp_enqueue_style( 'wpinv_meta_box_style' ); |
|
294 | + wp_register_style('wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION); |
|
295 | + wp_enqueue_style('wpinv_meta_box_style'); |
|
296 | 296 | |
297 | - wp_register_style( 'wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), WPINV_VERSION ); |
|
298 | - wp_enqueue_style( 'wpinv_admin_style' ); |
|
297 | + wp_register_style('wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), WPINV_VERSION); |
|
298 | + wp_enqueue_style('wpinv_admin_style'); |
|
299 | 299 | |
300 | - $enqueue = ( $post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) ); |
|
301 | - if ( $page == 'wpinv-subscriptions' ) { |
|
302 | - wp_enqueue_script( 'jquery-ui-datepicker' ); |
|
300 | + $enqueue = ($post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ($pagenow == 'post-new.php' || $pagenow == 'post.php')); |
|
301 | + if ($page == 'wpinv-subscriptions') { |
|
302 | + wp_enqueue_script('jquery-ui-datepicker'); |
|
303 | 303 | } |
304 | 304 | |
305 | - if ( $enqueue_datepicker = apply_filters( 'wpinv_admin_enqueue_jquery_ui_datepicker', $enqueue ) ) { |
|
306 | - wp_enqueue_script( 'jquery-ui-datepicker' ); |
|
305 | + if ($enqueue_datepicker = apply_filters('wpinv_admin_enqueue_jquery_ui_datepicker', $enqueue)) { |
|
306 | + wp_enqueue_script('jquery-ui-datepicker'); |
|
307 | 307 | } |
308 | 308 | |
309 | - wp_enqueue_style( 'wp-color-picker' ); |
|
310 | - wp_enqueue_script( 'wp-color-picker' ); |
|
309 | + wp_enqueue_style('wp-color-picker'); |
|
310 | + wp_enqueue_script('wp-color-picker'); |
|
311 | 311 | |
312 | - wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
312 | + wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true); |
|
313 | 313 | |
314 | 314 | if (($post_type == 'wpi_invoice' || $post_type == 'wpi_quote') && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) { |
315 | 315 | $autofill_api = wpinv_get_option('address_autofill_api'); |
@@ -320,20 +320,20 @@ discard block |
||
320 | 320 | } |
321 | 321 | } |
322 | 322 | |
323 | - wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all' ); |
|
324 | - wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
323 | + wp_enqueue_style("select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all'); |
|
324 | + wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array('jquery'), WPINV_VERSION); |
|
325 | 325 | |
326 | - wp_register_script( 'wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array( 'jquery', 'jquery-blockui','jquery-ui-tooltip' ), WPINV_VERSION ); |
|
327 | - wp_enqueue_script( 'wpinv-admin-script' ); |
|
326 | + wp_register_script('wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array('jquery', 'jquery-blockui', 'jquery-ui-tooltip'), WPINV_VERSION); |
|
327 | + wp_enqueue_script('wpinv-admin-script'); |
|
328 | 328 | |
329 | 329 | $localize = array(); |
330 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
331 | - $localize['post_ID'] = isset( $post->ID ) ? $post->ID : ''; |
|
332 | - $localize['wpinv_nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
333 | - $localize['add_invoice_note_nonce'] = wp_create_nonce( 'add-invoice-note' ); |
|
334 | - $localize['delete_invoice_note_nonce'] = wp_create_nonce( 'delete-invoice-note' ); |
|
335 | - $localize['invoice_item_nonce'] = wp_create_nonce( 'invoice-item' ); |
|
336 | - $localize['billing_details_nonce'] = wp_create_nonce( 'get-billing-details' ); |
|
330 | + $localize['ajax_url'] = admin_url('admin-ajax.php'); |
|
331 | + $localize['post_ID'] = isset($post->ID) ? $post->ID : ''; |
|
332 | + $localize['wpinv_nonce'] = wp_create_nonce('wpinv-nonce'); |
|
333 | + $localize['add_invoice_note_nonce'] = wp_create_nonce('add-invoice-note'); |
|
334 | + $localize['delete_invoice_note_nonce'] = wp_create_nonce('delete-invoice-note'); |
|
335 | + $localize['invoice_item_nonce'] = wp_create_nonce('invoice-item'); |
|
336 | + $localize['billing_details_nonce'] = wp_create_nonce('get-billing-details'); |
|
337 | 337 | $localize['tax'] = wpinv_tax_amount(); |
338 | 338 | $localize['discount'] = wpinv_discount_amount(); |
339 | 339 | $localize['currency_symbol'] = wpinv_currency_symbol(); |
@@ -341,69 +341,69 @@ discard block |
||
341 | 341 | $localize['thousand_sep'] = wpinv_thousands_separator(); |
342 | 342 | $localize['decimal_sep'] = wpinv_decimal_separator(); |
343 | 343 | $localize['decimals'] = wpinv_decimals(); |
344 | - $localize['save_invoice'] = __( 'Save Invoice', 'invoicing' ); |
|
345 | - $localize['status_publish'] = wpinv_status_nicename( 'publish' ); |
|
346 | - $localize['status_pending'] = wpinv_status_nicename( 'wpi-pending' ); |
|
347 | - $localize['delete_tax_rate'] = __( 'Are you sure you wish to delete this tax rate?', 'invoicing' ); |
|
348 | - $localize['OneItemMin'] = __( 'Invoice must contain at least one item', 'invoicing' ); |
|
349 | - $localize['DeleteInvoiceItem'] = __( 'Are you sure you wish to delete this item?', 'invoicing' ); |
|
350 | - $localize['FillBillingDetails'] = __( 'Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing' ); |
|
351 | - $localize['confirmCalcTotals'] = __( 'Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing' ); |
|
352 | - $localize['AreYouSure'] = __( 'Are you sure?', 'invoicing' ); |
|
353 | - $localize['emptyInvoice'] = __( 'Add at least one item to save invoice!', 'invoicing' ); |
|
354 | - $localize['errDeleteItem'] = __( 'This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing' ); |
|
355 | - $localize['delete_subscription'] = __( 'Are you sure you want to delete this subscription?', 'invoicing' ); |
|
356 | - $localize['action_edit'] = __( 'Edit', 'invoicing' ); |
|
357 | - $localize['action_cancel'] = __( 'Cancel', 'invoicing' ); |
|
358 | - |
|
359 | - $localize = apply_filters( 'wpinv_admin_js_localize', $localize ); |
|
360 | - |
|
361 | - wp_localize_script( 'wpinv-admin-script', 'WPInv_Admin', $localize ); |
|
362 | - |
|
363 | - if ( $page == 'wpinv-subscriptions' ) { |
|
364 | - wp_register_script( 'wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array( 'wpinv-admin-script' ), WPINV_VERSION ); |
|
365 | - wp_enqueue_script( 'wpinv-sub-admin-script' ); |
|
344 | + $localize['save_invoice'] = __('Save Invoice', 'invoicing'); |
|
345 | + $localize['status_publish'] = wpinv_status_nicename('publish'); |
|
346 | + $localize['status_pending'] = wpinv_status_nicename('wpi-pending'); |
|
347 | + $localize['delete_tax_rate'] = __('Are you sure you wish to delete this tax rate?', 'invoicing'); |
|
348 | + $localize['OneItemMin'] = __('Invoice must contain at least one item', 'invoicing'); |
|
349 | + $localize['DeleteInvoiceItem'] = __('Are you sure you wish to delete this item?', 'invoicing'); |
|
350 | + $localize['FillBillingDetails'] = __('Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing'); |
|
351 | + $localize['confirmCalcTotals'] = __('Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing'); |
|
352 | + $localize['AreYouSure'] = __('Are you sure?', 'invoicing'); |
|
353 | + $localize['emptyInvoice'] = __('Add at least one item to save invoice!', 'invoicing'); |
|
354 | + $localize['errDeleteItem'] = __('This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing'); |
|
355 | + $localize['delete_subscription'] = __('Are you sure you want to delete this subscription?', 'invoicing'); |
|
356 | + $localize['action_edit'] = __('Edit', 'invoicing'); |
|
357 | + $localize['action_cancel'] = __('Cancel', 'invoicing'); |
|
358 | + |
|
359 | + $localize = apply_filters('wpinv_admin_js_localize', $localize); |
|
360 | + |
|
361 | + wp_localize_script('wpinv-admin-script', 'WPInv_Admin', $localize); |
|
362 | + |
|
363 | + if ($page == 'wpinv-subscriptions') { |
|
364 | + wp_register_script('wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array('wpinv-admin-script'), WPINV_VERSION); |
|
365 | + wp_enqueue_script('wpinv-sub-admin-script'); |
|
366 | 366 | } |
367 | 367 | } |
368 | 368 | |
369 | - public function admin_body_class( $classes ) { |
|
369 | + public function admin_body_class($classes) { |
|
370 | 370 | global $pagenow, $post, $current_screen; |
371 | 371 | |
372 | - if ( !empty( $current_screen->post_type ) && ( $current_screen->post_type == 'wpi_invoice' || $current_screen->post_type == 'wpi_quote' ) ) { |
|
372 | + if (!empty($current_screen->post_type) && ($current_screen->post_type == 'wpi_invoice' || $current_screen->post_type == 'wpi_quote')) { |
|
373 | 373 | $classes .= ' wpinv-cpt'; |
374 | 374 | } |
375 | 375 | |
376 | - $page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : false; |
|
376 | + $page = isset($_GET['page']) ? strtolower($_GET['page']) : false; |
|
377 | 377 | |
378 | - $add_class = $page && $pagenow == 'admin.php' && strpos( $page, 'wpinv-' ) === 0 ? true : false; |
|
379 | - if ( $add_class ) { |
|
380 | - $classes .= ' wpi-' . wpinv_sanitize_key( $page ); |
|
378 | + $add_class = $page && $pagenow == 'admin.php' && strpos($page, 'wpinv-') === 0 ? true : false; |
|
379 | + if ($add_class) { |
|
380 | + $classes .= ' wpi-' . wpinv_sanitize_key($page); |
|
381 | 381 | } |
382 | 382 | |
383 | 383 | $settings_class = array(); |
384 | - if ( $page == 'wpinv-settings' ) { |
|
385 | - if ( !empty( $_REQUEST['tab'] ) ) { |
|
386 | - $settings_class[] = sanitize_text_field( $_REQUEST['tab'] ); |
|
384 | + if ($page == 'wpinv-settings') { |
|
385 | + if (!empty($_REQUEST['tab'])) { |
|
386 | + $settings_class[] = sanitize_text_field($_REQUEST['tab']); |
|
387 | 387 | } |
388 | 388 | |
389 | - if ( !empty( $_REQUEST['section'] ) ) { |
|
390 | - $settings_class[] = sanitize_text_field( $_REQUEST['section'] ); |
|
389 | + if (!empty($_REQUEST['section'])) { |
|
390 | + $settings_class[] = sanitize_text_field($_REQUEST['section']); |
|
391 | 391 | } |
392 | 392 | |
393 | - $settings_class[] = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field( $_REQUEST['wpi_sub'] ) : 'main'; |
|
393 | + $settings_class[] = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field($_REQUEST['wpi_sub']) : 'main'; |
|
394 | 394 | } |
395 | 395 | |
396 | - if ( !empty( $settings_class ) ) { |
|
397 | - $classes .= ' wpi-' . wpinv_sanitize_key( implode( $settings_class, '-' ) ); |
|
396 | + if (!empty($settings_class)) { |
|
397 | + $classes .= ' wpi-' . wpinv_sanitize_key(implode($settings_class, '-')); |
|
398 | 398 | } |
399 | 399 | |
400 | 400 | $post_type = wpinv_admin_post_type(); |
401 | 401 | |
402 | - if ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false ) { |
|
402 | + if ($post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false) { |
|
403 | 403 | return $classes .= ' wpinv'; |
404 | 404 | } |
405 | 405 | |
406 | - if ( $pagenow == 'post.php' && $post_type == 'wpi_item' && !empty( $post ) && !wpinv_item_is_editable( $post ) ) { |
|
406 | + if ($pagenow == 'post.php' && $post_type == 'wpi_item' && !empty($post) && !wpinv_item_is_editable($post)) { |
|
407 | 407 | $classes .= ' wpi-editable-n'; |
408 | 408 | } |
409 | 409 | |
@@ -415,21 +415,21 @@ discard block |
||
415 | 415 | } |
416 | 416 | |
417 | 417 | public function wpinv_actions() { |
418 | - if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
419 | - do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
418 | + if (isset($_REQUEST['wpi_action'])) { |
|
419 | + do_action('wpinv_' . wpinv_sanitize_key($_REQUEST['wpi_action']), $_REQUEST); |
|
420 | 420 | } |
421 | 421 | } |
422 | 422 | |
423 | - public function pre_get_posts( $wp_query ) { |
|
424 | - if ( !empty( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
425 | - $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses() ); |
|
423 | + public function pre_get_posts($wp_query) { |
|
424 | + if (!empty($wp_query->query_vars['post_type']) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query()) { |
|
425 | + $wp_query->query_vars['post_status'] = array_keys(wpinv_get_invoice_statuses()); |
|
426 | 426 | } |
427 | 427 | |
428 | 428 | return $wp_query; |
429 | 429 | } |
430 | 430 | |
431 | 431 | public function bp_invoicing_init() { |
432 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' ); |
|
432 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php'); |
|
433 | 433 | } |
434 | 434 | |
435 | 435 | /** |
@@ -437,11 +437,11 @@ discard block |
||
437 | 437 | * |
438 | 438 | */ |
439 | 439 | public function register_widgets() { |
440 | - register_widget( "WPInv_Checkout_Widget" ); |
|
441 | - register_widget( "WPInv_History_Widget" ); |
|
442 | - register_widget( "WPInv_Receipt_Widget" ); |
|
443 | - register_widget( "WPInv_Subscriptions_Widget" ); |
|
444 | - register_widget( "WPInv_Buy_Item_Widget" ); |
|
445 | - register_widget( "WPInv_Messages_Widget" ); |
|
440 | + register_widget("WPInv_Checkout_Widget"); |
|
441 | + register_widget("WPInv_History_Widget"); |
|
442 | + register_widget("WPInv_Receipt_Widget"); |
|
443 | + register_widget("WPInv_Subscriptions_Widget"); |
|
444 | + register_widget("WPInv_Buy_Item_Widget"); |
|
445 | + register_widget("WPInv_Messages_Widget"); |
|
446 | 446 | } |
447 | 447 | } |
448 | 448 | \ No newline at end of file |
@@ -101,9 +101,9 @@ discard block |
||
101 | 101 | case 'status' : |
102 | 102 | $value = $wpi_invoice->get_status( true ) . ( $wpi_invoice->is_recurring() && $wpi_invoice->is_parent() ? ' <span class="wpi-suffix">' . __( '(r)', 'invoicing' ) . '</span>' : '' ); |
103 | 103 | $is_viewed = wpinv_is_invoice_viewed( $wpi_invoice->ID ); |
104 | - $gateway_title = wpinv_get_gateway_admin_label( $wpi_invoice->get_gateway() ); |
|
105 | - $offline_gateways = apply_filters('wpinv_offline_payments', array('bank_transfer', 'cheque', 'cod')); |
|
106 | - $is_offline_payment = in_array($wpi_invoice->get_gateway(), $offline_gateways) ? true : false; |
|
104 | + $gateway_title = wpinv_get_gateway_admin_label( $wpi_invoice->get_gateway() ); |
|
105 | + $offline_gateways = apply_filters('wpinv_offline_payments', array('bank_transfer', 'cheque', 'cod')); |
|
106 | + $is_offline_payment = in_array($wpi_invoice->get_gateway(), $offline_gateways) ? true : false; |
|
107 | 107 | |
108 | 108 | if ( 1 == $is_viewed ) { |
109 | 109 | $value .= ' <i class="fa fa-eye" title="'.__( 'Viewed by Customer', 'invoicing' ).'"></i>'; |
@@ -174,69 +174,69 @@ discard block |
||
174 | 174 | } |
175 | 175 | |
176 | 176 | function wpinv_admin_messages() { |
177 | - global $wpinv_options, $pagenow, $post; |
|
177 | + global $wpinv_options, $pagenow, $post; |
|
178 | 178 | |
179 | - if ( isset( $_GET['wpinv-message'] ) && 'discount_added' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
180 | - add_settings_error( 'wpinv-notices', 'wpinv-discount-added', __( 'Discount code added.', 'invoicing' ), 'updated' ); |
|
181 | - } |
|
179 | + if ( isset( $_GET['wpinv-message'] ) && 'discount_added' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
180 | + add_settings_error( 'wpinv-notices', 'wpinv-discount-added', __( 'Discount code added.', 'invoicing' ), 'updated' ); |
|
181 | + } |
|
182 | 182 | |
183 | - if ( isset( $_GET['wpinv-message'] ) && 'discount_add_failed' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
184 | - add_settings_error( 'wpinv-notices', 'wpinv-discount-add-fail', __( 'There was a problem adding your discount code, please try again.', 'invoicing' ), 'error' ); |
|
185 | - } |
|
183 | + if ( isset( $_GET['wpinv-message'] ) && 'discount_add_failed' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
184 | + add_settings_error( 'wpinv-notices', 'wpinv-discount-add-fail', __( 'There was a problem adding your discount code, please try again.', 'invoicing' ), 'error' ); |
|
185 | + } |
|
186 | 186 | |
187 | - if ( isset( $_GET['wpinv-message'] ) && 'discount_exists' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
188 | - add_settings_error( 'wpinv-notices', 'wpinv-discount-exists', __( 'A discount with that code already exists, please use a different code.', 'invoicing' ), 'error' ); |
|
189 | - } |
|
187 | + if ( isset( $_GET['wpinv-message'] ) && 'discount_exists' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
188 | + add_settings_error( 'wpinv-notices', 'wpinv-discount-exists', __( 'A discount with that code already exists, please use a different code.', 'invoicing' ), 'error' ); |
|
189 | + } |
|
190 | 190 | |
191 | - if ( isset( $_GET['wpinv-message'] ) && 'discount_updated' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
192 | - add_settings_error( 'wpinv-notices', 'wpinv-discount-updated', __( 'Discount code updated.', 'invoicing' ), 'updated' ); |
|
193 | - } |
|
191 | + if ( isset( $_GET['wpinv-message'] ) && 'discount_updated' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
192 | + add_settings_error( 'wpinv-notices', 'wpinv-discount-updated', __( 'Discount code updated.', 'invoicing' ), 'updated' ); |
|
193 | + } |
|
194 | 194 | |
195 | - if ( isset( $_GET['wpinv-message'] ) && 'discount_update_failed' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
196 | - add_settings_error( 'wpinv-notices', 'wpinv-discount-updated-fail', __( 'There was a problem updating your discount code, please try again.', 'invoicing' ), 'error' ); |
|
197 | - } |
|
195 | + if ( isset( $_GET['wpinv-message'] ) && 'discount_update_failed' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
196 | + add_settings_error( 'wpinv-notices', 'wpinv-discount-updated-fail', __( 'There was a problem updating your discount code, please try again.', 'invoicing' ), 'error' ); |
|
197 | + } |
|
198 | 198 | |
199 | - if ( isset( $_GET['wpinv-message'] ) && 'invoice_deleted' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
200 | - add_settings_error( 'wpinv-notices', 'wpinv-deleted', __( 'The invoice has been deleted.', 'invoicing' ), 'updated' ); |
|
201 | - } |
|
199 | + if ( isset( $_GET['wpinv-message'] ) && 'invoice_deleted' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
200 | + add_settings_error( 'wpinv-notices', 'wpinv-deleted', __( 'The invoice has been deleted.', 'invoicing' ), 'updated' ); |
|
201 | + } |
|
202 | 202 | |
203 | - if ( isset( $_GET['wpinv-message'] ) && 'email_disabled' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
204 | - add_settings_error( 'wpinv-notices', 'wpinv-sent-fail', __( 'Email notification is disabled. Please check settings.', 'invoicing' ), 'error' ); |
|
205 | - } |
|
203 | + if ( isset( $_GET['wpinv-message'] ) && 'email_disabled' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
204 | + add_settings_error( 'wpinv-notices', 'wpinv-sent-fail', __( 'Email notification is disabled. Please check settings.', 'invoicing' ), 'error' ); |
|
205 | + } |
|
206 | 206 | |
207 | - if ( isset( $_GET['wpinv-message'] ) && 'email_sent' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
208 | - add_settings_error( 'wpinv-notices', 'wpinv-sent', __( 'The email has been sent to customer.', 'invoicing' ), 'updated' ); |
|
207 | + if ( isset( $_GET['wpinv-message'] ) && 'email_sent' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
208 | + add_settings_error( 'wpinv-notices', 'wpinv-sent', __( 'The email has been sent to customer.', 'invoicing' ), 'updated' ); |
|
209 | 209 | } |
210 | 210 | |
211 | 211 | if ( isset( $_GET['wpinv-message'] ) && 'email_fail' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
212 | - add_settings_error( 'wpinv-notices', 'wpinv-sent-fail', __( 'Fail to send email to the customer.', 'invoicing' ), 'error' ); |
|
212 | + add_settings_error( 'wpinv-notices', 'wpinv-sent-fail', __( 'Fail to send email to the customer.', 'invoicing' ), 'error' ); |
|
213 | 213 | } |
214 | 214 | |
215 | 215 | if ( isset( $_GET['wpinv-message'] ) && 'invoice-note-deleted' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
216 | 216 | add_settings_error( 'wpinv-notices', 'wpinv-note-deleted', __( 'The invoice note has been deleted.', 'invoicing' ), 'updated' ); |
217 | 217 | } |
218 | 218 | |
219 | - if ( isset( $_GET['wpinv-message'] ) && 'settings-imported' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
220 | - add_settings_error( 'wpinv-notices', 'wpinv-settings-imported', __( 'The settings have been imported.', 'invoicing' ), 'updated' ); |
|
221 | - } |
|
219 | + if ( isset( $_GET['wpinv-message'] ) && 'settings-imported' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
220 | + add_settings_error( 'wpinv-notices', 'wpinv-settings-imported', __( 'The settings have been imported.', 'invoicing' ), 'updated' ); |
|
221 | + } |
|
222 | 222 | |
223 | - if ( isset( $_GET['wpinv-message'] ) && 'note-added' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
224 | - add_settings_error( 'wpinv-notices', 'wpinv-note-added', __( 'The invoice note has been added successfully.', 'invoicing' ), 'updated' ); |
|
225 | - } |
|
223 | + if ( isset( $_GET['wpinv-message'] ) && 'note-added' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
224 | + add_settings_error( 'wpinv-notices', 'wpinv-note-added', __( 'The invoice note has been added successfully.', 'invoicing' ), 'updated' ); |
|
225 | + } |
|
226 | 226 | |
227 | - if ( isset( $_GET['wpinv-message'] ) && 'invoice-updated' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
228 | - add_settings_error( 'wpinv-notices', 'wpinv-updated', __( 'The invoice has been successfully updated.', 'invoicing' ), 'updated' ); |
|
229 | - } |
|
227 | + if ( isset( $_GET['wpinv-message'] ) && 'invoice-updated' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
228 | + add_settings_error( 'wpinv-notices', 'wpinv-updated', __( 'The invoice has been successfully updated.', 'invoicing' ), 'updated' ); |
|
229 | + } |
|
230 | 230 | |
231 | - if ( $pagenow == 'post.php' && !empty( $post->post_type ) && $post->post_type == 'wpi_item' && !wpinv_item_is_editable( $post ) ) { |
|
232 | - $message = apply_filters( 'wpinv_item_non_editable_message', __( 'This item in not editable.', 'invoicing' ), $post->ID ); |
|
231 | + if ( $pagenow == 'post.php' && !empty( $post->post_type ) && $post->post_type == 'wpi_item' && !wpinv_item_is_editable( $post ) ) { |
|
232 | + $message = apply_filters( 'wpinv_item_non_editable_message', __( 'This item in not editable.', 'invoicing' ), $post->ID ); |
|
233 | 233 | |
234 | - if ( !empty( $message ) ) { |
|
235 | - add_settings_error( 'wpinv-notices', 'wpinv-edit-n', $message, 'updated' ); |
|
236 | - } |
|
237 | - } |
|
234 | + if ( !empty( $message ) ) { |
|
235 | + add_settings_error( 'wpinv-notices', 'wpinv-edit-n', $message, 'updated' ); |
|
236 | + } |
|
237 | + } |
|
238 | 238 | |
239 | - settings_errors( 'wpinv-notices' ); |
|
239 | + settings_errors( 'wpinv-notices' ); |
|
240 | 240 | } |
241 | 241 | add_action( 'admin_notices', 'wpinv_admin_messages' ); |
242 | 242 | |
@@ -326,7 +326,7 @@ discard block |
||
326 | 326 | break; |
327 | 327 | case 'id' : |
328 | 328 | echo $post->ID; |
329 | - echo '<div class="hidden" id="wpinv_inline-' . $post->ID . '"> |
|
329 | + echo '<div class="hidden" id="wpinv_inline-' . $post->ID . '"> |
|
330 | 330 | <div class="price">' . wpinv_get_item_price( $post->ID ) . '</div>'; |
331 | 331 | if ( $wpinv_euvat->allow_vat_rules() ) { |
332 | 332 | echo '<div class="vat_rule">' . $wpinv_euvat->get_item_rule( $post->ID ) . '</div>'; |
@@ -7,245 +7,245 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | // MUST have WordPress. |
10 | -if ( !defined( 'WPINC' ) ) { |
|
11 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
10 | +if (!defined('WPINC')) { |
|
11 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
12 | 12 | } |
13 | 13 | |
14 | -function wpinv_columns( $columns ) { |
|
14 | +function wpinv_columns($columns) { |
|
15 | 15 | $columns = array( |
16 | 16 | 'cb' => $columns['cb'], |
17 | - 'number' => __( 'Number', 'invoicing' ), |
|
18 | - 'customer' => __( 'Customer', 'invoicing' ), |
|
19 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
20 | - 'invoice_date' => __( 'Created Date', 'invoicing' ), |
|
21 | - 'payment_date' => __( 'Payment Date', 'invoicing' ), |
|
22 | - 'status' => __( 'Status', 'invoicing' ), |
|
23 | - 'ID' => __( 'ID', 'invoicing' ), |
|
24 | - 'wpi_actions' => __( 'Actions', 'invoicing' ), |
|
17 | + 'number' => __('Number', 'invoicing'), |
|
18 | + 'customer' => __('Customer', 'invoicing'), |
|
19 | + 'amount' => __('Amount', 'invoicing'), |
|
20 | + 'invoice_date' => __('Created Date', 'invoicing'), |
|
21 | + 'payment_date' => __('Payment Date', 'invoicing'), |
|
22 | + 'status' => __('Status', 'invoicing'), |
|
23 | + 'ID' => __('ID', 'invoicing'), |
|
24 | + 'wpi_actions' => __('Actions', 'invoicing'), |
|
25 | 25 | ); |
26 | 26 | |
27 | - return apply_filters( 'wpi_invoice_table_columns', $columns ); |
|
27 | + return apply_filters('wpi_invoice_table_columns', $columns); |
|
28 | 28 | } |
29 | -add_filter( 'manage_wpi_invoice_posts_columns', 'wpinv_columns' ); |
|
29 | +add_filter('manage_wpi_invoice_posts_columns', 'wpinv_columns'); |
|
30 | 30 | |
31 | -function wpinv_bulk_actions( $actions ) { |
|
32 | - if ( isset( $actions['edit'] ) ) { |
|
33 | - unset( $actions['edit'] ); |
|
31 | +function wpinv_bulk_actions($actions) { |
|
32 | + if (isset($actions['edit'])) { |
|
33 | + unset($actions['edit']); |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | return $actions; |
37 | 37 | } |
38 | -add_filter( 'bulk_actions-edit-wpi_invoice', 'wpinv_bulk_actions' ); |
|
39 | -add_filter( 'bulk_actions-edit-wpi_item', 'wpinv_bulk_actions' ); |
|
38 | +add_filter('bulk_actions-edit-wpi_invoice', 'wpinv_bulk_actions'); |
|
39 | +add_filter('bulk_actions-edit-wpi_item', 'wpinv_bulk_actions'); |
|
40 | 40 | |
41 | -function wpinv_sortable_columns( $columns ) { |
|
41 | +function wpinv_sortable_columns($columns) { |
|
42 | 42 | $columns = array( |
43 | - 'ID' => array( 'ID', true ), |
|
44 | - 'number' => array( 'number', false ), |
|
45 | - 'amount' => array( 'amount', false ), |
|
46 | - 'invoice_date' => array( 'date', false ), |
|
47 | - 'payment_date' => array( 'payment_date', true ), |
|
48 | - 'customer' => array( 'customer', false ), |
|
49 | - 'status' => array( 'status', false ), |
|
43 | + 'ID' => array('ID', true), |
|
44 | + 'number' => array('number', false), |
|
45 | + 'amount' => array('amount', false), |
|
46 | + 'invoice_date' => array('date', false), |
|
47 | + 'payment_date' => array('payment_date', true), |
|
48 | + 'customer' => array('customer', false), |
|
49 | + 'status' => array('status', false), |
|
50 | 50 | ); |
51 | 51 | |
52 | - return apply_filters( 'wpi_invoice_table_sortable_columns', $columns ); |
|
52 | + return apply_filters('wpi_invoice_table_sortable_columns', $columns); |
|
53 | 53 | } |
54 | -add_filter( 'manage_edit-wpi_invoice_sortable_columns', 'wpinv_sortable_columns' ); |
|
54 | +add_filter('manage_edit-wpi_invoice_sortable_columns', 'wpinv_sortable_columns'); |
|
55 | 55 | |
56 | -add_action( 'manage_wpi_invoice_posts_custom_column', 'wpinv_posts_custom_column'); |
|
57 | -function wpinv_posts_custom_column( $column_name, $post_id = 0 ) { |
|
56 | +add_action('manage_wpi_invoice_posts_custom_column', 'wpinv_posts_custom_column'); |
|
57 | +function wpinv_posts_custom_column($column_name, $post_id = 0) { |
|
58 | 58 | global $post, $wpi_invoice; |
59 | 59 | |
60 | - if ( empty( $wpi_invoice ) || ( !empty( $wpi_invoice ) && $post->ID != $wpi_invoice->ID ) ) { |
|
61 | - $wpi_invoice = new WPInv_Invoice( $post->ID ); |
|
60 | + if (empty($wpi_invoice) || (!empty($wpi_invoice) && $post->ID != $wpi_invoice->ID)) { |
|
61 | + $wpi_invoice = new WPInv_Invoice($post->ID); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | $value = NULL; |
65 | 65 | |
66 | - switch ( $column_name ) { |
|
66 | + switch ($column_name) { |
|
67 | 67 | case 'email' : |
68 | - $value = $wpi_invoice->get_email(); |
|
68 | + $value = $wpi_invoice->get_email(); |
|
69 | 69 | break; |
70 | 70 | case 'customer' : |
71 | 71 | $customer_name = $wpi_invoice->get_user_full_name(); |
72 | - $customer_name = $customer_name != '' ? $customer_name : __( 'Customer', 'invoicing' ); |
|
73 | - $value = '<a href="' . esc_url( get_edit_user_link( $wpi_invoice->get_user_id() ) ) . '">' . $customer_name . '</a>'; |
|
74 | - if ( $email = $wpi_invoice->get_email() ) { |
|
72 | + $customer_name = $customer_name != '' ? $customer_name : __('Customer', 'invoicing'); |
|
73 | + $value = '<a href="' . esc_url(get_edit_user_link($wpi_invoice->get_user_id())) . '">' . $customer_name . '</a>'; |
|
74 | + if ($email = $wpi_invoice->get_email()) { |
|
75 | 75 | $value .= '<br><a class="email" href="mailto:' . $email . '">' . $email . '</a>'; |
76 | 76 | } |
77 | 77 | break; |
78 | 78 | case 'amount' : |
79 | - echo $wpi_invoice->get_total( true ); |
|
79 | + echo $wpi_invoice->get_total(true); |
|
80 | 80 | break; |
81 | 81 | case 'invoice_date' : |
82 | - $date_format = get_option( 'date_format' ); |
|
82 | + $date_format = get_option('date_format'); |
|
83 | 83 | |
84 | 84 | $m_time = $post->post_date; |
85 | - $h_time = mysql2date( $date_format, $m_time ); |
|
85 | + $h_time = mysql2date($date_format, $m_time); |
|
86 | 86 | |
87 | - $value = '<abbr title="' . $m_time . '">' . $h_time . '</abbr>'; |
|
87 | + $value = '<abbr title="' . $m_time . '">' . $h_time . '</abbr>'; |
|
88 | 88 | break; |
89 | 89 | case 'payment_date' : |
90 | - if ( $date_completed = $wpi_invoice->get_meta( '_wpinv_completed_date', true ) ) { |
|
91 | - $date_format = get_option( 'date_format' ); |
|
90 | + if ($date_completed = $wpi_invoice->get_meta('_wpinv_completed_date', true)) { |
|
91 | + $date_format = get_option('date_format'); |
|
92 | 92 | |
93 | 93 | $m_time = $date_completed; |
94 | - $h_time = mysql2date( $date_format, $m_time ); |
|
94 | + $h_time = mysql2date($date_format, $m_time); |
|
95 | 95 | |
96 | - $value = '<abbr title="' . $m_time . '">' . $h_time . '</abbr>'; |
|
96 | + $value = '<abbr title="' . $m_time . '">' . $h_time . '</abbr>'; |
|
97 | 97 | } else { |
98 | 98 | $value = '-'; |
99 | 99 | } |
100 | 100 | break; |
101 | 101 | case 'status' : |
102 | - $value = $wpi_invoice->get_status( true ) . ( $wpi_invoice->is_recurring() && $wpi_invoice->is_parent() ? ' <span class="wpi-suffix">' . __( '(r)', 'invoicing' ) . '</span>' : '' ); |
|
103 | - $is_viewed = wpinv_is_invoice_viewed( $wpi_invoice->ID ); |
|
104 | - $gateway_title = wpinv_get_gateway_admin_label( $wpi_invoice->get_gateway() ); |
|
102 | + $value = $wpi_invoice->get_status(true) . ($wpi_invoice->is_recurring() && $wpi_invoice->is_parent() ? ' <span class="wpi-suffix">' . __('(r)', 'invoicing') . '</span>' : ''); |
|
103 | + $is_viewed = wpinv_is_invoice_viewed($wpi_invoice->ID); |
|
104 | + $gateway_title = wpinv_get_gateway_admin_label($wpi_invoice->get_gateway()); |
|
105 | 105 | $offline_gateways = apply_filters('wpinv_offline_payments', array('bank_transfer', 'cheque', 'cod')); |
106 | 106 | $is_offline_payment = in_array($wpi_invoice->get_gateway(), $offline_gateways) ? true : false; |
107 | 107 | |
108 | - if ( 1 == $is_viewed ) { |
|
109 | - $value .= ' <i class="fa fa-eye" title="'.__( 'Viewed by Customer', 'invoicing' ).'"></i>'; |
|
108 | + if (1 == $is_viewed) { |
|
109 | + $value .= ' <i class="fa fa-eye" title="' . __('Viewed by Customer', 'invoicing') . '"></i>'; |
|
110 | 110 | } |
111 | - if ( ( $wpi_invoice->is_paid() || $wpi_invoice->is_refunded() || $is_offline_payment ) && ( isset( $gateway_title ) ) ) { |
|
112 | - $value .= '<br><small class="meta gateway">' . wp_sprintf( __( 'Via %s', 'invoicing' ), $gateway_title ) . '</small>'; |
|
111 | + if (($wpi_invoice->is_paid() || $wpi_invoice->is_refunded() || $is_offline_payment) && (isset($gateway_title))) { |
|
112 | + $value .= '<br><small class="meta gateway">' . wp_sprintf(__('Via %s', 'invoicing'), $gateway_title) . '</small>'; |
|
113 | 113 | } |
114 | 114 | break; |
115 | 115 | case 'number' : |
116 | - $edit_link = get_edit_post_link( $post->ID ); |
|
117 | - $value = '<a title="' . esc_attr__( 'View Invoice Details', 'invoicing' ) . '" href="' . esc_url( $edit_link ) . '">' . $wpi_invoice->get_number() . '</a>'; |
|
116 | + $edit_link = get_edit_post_link($post->ID); |
|
117 | + $value = '<a title="' . esc_attr__('View Invoice Details', 'invoicing') . '" href="' . esc_url($edit_link) . '">' . $wpi_invoice->get_number() . '</a>'; |
|
118 | 118 | break; |
119 | 119 | case 'wpi_actions' : |
120 | 120 | $value = ''; |
121 | - if ( !empty( $post->post_name ) ) { |
|
122 | - $value .= '<a title="' . esc_attr__( 'Print invoice', 'invoicing' ) . '" href="' . esc_url( get_permalink( $post->ID ) ) . '" class="button ui-tip column-act-btn" title="" target="_blank"><span class="dashicons dashicons-print"><i style="" class="fa fa-print"></i></span></a>'; |
|
121 | + if (!empty($post->post_name)) { |
|
122 | + $value .= '<a title="' . esc_attr__('Print invoice', 'invoicing') . '" href="' . esc_url(get_permalink($post->ID)) . '" class="button ui-tip column-act-btn" title="" target="_blank"><span class="dashicons dashicons-print"><i style="" class="fa fa-print"></i></span></a>'; |
|
123 | 123 | } |
124 | 124 | |
125 | - if ( $email = $wpi_invoice->get_email() ) { |
|
126 | - $value .= '<a title="' . esc_attr__( 'Send invoice to customer', 'invoicing' ) . '" href="' . esc_url( add_query_arg( array( 'wpi_action' => 'send_invoice', 'invoice_id' => $post->ID ) ) ) . '" class="button ui-tip column-act-btn"><span class="dashicons dashicons-email-alt"></span></a>'; |
|
125 | + if ($email = $wpi_invoice->get_email()) { |
|
126 | + $value .= '<a title="' . esc_attr__('Send invoice to customer', 'invoicing') . '" href="' . esc_url(add_query_arg(array('wpi_action' => 'send_invoice', 'invoice_id' => $post->ID))) . '" class="button ui-tip column-act-btn"><span class="dashicons dashicons-email-alt"></span></a>'; |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | break; |
130 | 130 | default: |
131 | - $value = isset( $post->$column_name ) ? $post->$column_name : ''; |
|
131 | + $value = isset($post->$column_name) ? $post->$column_name : ''; |
|
132 | 132 | break; |
133 | 133 | |
134 | 134 | } |
135 | - $value = apply_filters( 'wpinv_payments_table_column', $value, $post->ID, $column_name ); |
|
135 | + $value = apply_filters('wpinv_payments_table_column', $value, $post->ID, $column_name); |
|
136 | 136 | |
137 | - if ( $value !== NULL ) { |
|
137 | + if ($value !== NULL) { |
|
138 | 138 | echo $value; |
139 | 139 | } |
140 | 140 | } |
141 | 141 | |
142 | -function wpinv_admin_post_id( $id = 0 ) { |
|
142 | +function wpinv_admin_post_id($id = 0) { |
|
143 | 143 | global $post; |
144 | 144 | |
145 | - if ( isset( $id ) && ! empty( $id ) ) { |
|
146 | - return (int)$id; |
|
147 | - } else if ( get_the_ID() ) { |
|
145 | + if (isset($id) && !empty($id)) { |
|
146 | + return (int) $id; |
|
147 | + } else if (get_the_ID()) { |
|
148 | 148 | return (int) get_the_ID(); |
149 | - } else if ( isset( $post->ID ) && !empty( $post->ID ) ) { |
|
149 | + } else if (isset($post->ID) && !empty($post->ID)) { |
|
150 | 150 | return (int) $post->ID; |
151 | - } else if ( isset( $_GET['post'] ) && !empty( $_GET['post'] ) ) { |
|
151 | + } else if (isset($_GET['post']) && !empty($_GET['post'])) { |
|
152 | 152 | return (int) $_GET['post']; |
153 | - } else if ( isset( $_GET['id'] ) && !empty( $_GET['id'] ) ) { |
|
153 | + } else if (isset($_GET['id']) && !empty($_GET['id'])) { |
|
154 | 154 | return (int) $_GET['id']; |
155 | - } else if ( isset( $_POST['id'] ) && !empty( $_POST['id'] ) ) { |
|
155 | + } else if (isset($_POST['id']) && !empty($_POST['id'])) { |
|
156 | 156 | return (int) $_POST['id']; |
157 | 157 | } |
158 | 158 | |
159 | 159 | return null; |
160 | 160 | } |
161 | 161 | |
162 | -function wpinv_admin_post_type( $id = 0 ) { |
|
163 | - if ( !$id ) { |
|
162 | +function wpinv_admin_post_type($id = 0) { |
|
163 | + if (!$id) { |
|
164 | 164 | $id = wpinv_admin_post_id(); |
165 | 165 | } |
166 | 166 | |
167 | - $type = get_post_type( $id ); |
|
167 | + $type = get_post_type($id); |
|
168 | 168 | |
169 | - if ( !$type ) { |
|
170 | - $type = isset( $_GET['post_type'] ) && !empty( $_GET['post_type'] ) ? $_GET['post_type'] : null; |
|
169 | + if (!$type) { |
|
170 | + $type = isset($_GET['post_type']) && !empty($_GET['post_type']) ? $_GET['post_type'] : null; |
|
171 | 171 | } |
172 | 172 | |
173 | - return apply_filters( 'wpinv_admin_post_type', $type, $id ); |
|
173 | + return apply_filters('wpinv_admin_post_type', $type, $id); |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | function wpinv_admin_messages() { |
177 | 177 | global $wpinv_options, $pagenow, $post; |
178 | 178 | |
179 | - if ( isset( $_GET['wpinv-message'] ) && 'discount_added' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
180 | - add_settings_error( 'wpinv-notices', 'wpinv-discount-added', __( 'Discount code added.', 'invoicing' ), 'updated' ); |
|
179 | + if (isset($_GET['wpinv-message']) && 'discount_added' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) { |
|
180 | + add_settings_error('wpinv-notices', 'wpinv-discount-added', __('Discount code added.', 'invoicing'), 'updated'); |
|
181 | 181 | } |
182 | 182 | |
183 | - if ( isset( $_GET['wpinv-message'] ) && 'discount_add_failed' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
184 | - add_settings_error( 'wpinv-notices', 'wpinv-discount-add-fail', __( 'There was a problem adding your discount code, please try again.', 'invoicing' ), 'error' ); |
|
183 | + if (isset($_GET['wpinv-message']) && 'discount_add_failed' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) { |
|
184 | + add_settings_error('wpinv-notices', 'wpinv-discount-add-fail', __('There was a problem adding your discount code, please try again.', 'invoicing'), 'error'); |
|
185 | 185 | } |
186 | 186 | |
187 | - if ( isset( $_GET['wpinv-message'] ) && 'discount_exists' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
188 | - add_settings_error( 'wpinv-notices', 'wpinv-discount-exists', __( 'A discount with that code already exists, please use a different code.', 'invoicing' ), 'error' ); |
|
187 | + if (isset($_GET['wpinv-message']) && 'discount_exists' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) { |
|
188 | + add_settings_error('wpinv-notices', 'wpinv-discount-exists', __('A discount with that code already exists, please use a different code.', 'invoicing'), 'error'); |
|
189 | 189 | } |
190 | 190 | |
191 | - if ( isset( $_GET['wpinv-message'] ) && 'discount_updated' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
192 | - add_settings_error( 'wpinv-notices', 'wpinv-discount-updated', __( 'Discount code updated.', 'invoicing' ), 'updated' ); |
|
191 | + if (isset($_GET['wpinv-message']) && 'discount_updated' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) { |
|
192 | + add_settings_error('wpinv-notices', 'wpinv-discount-updated', __('Discount code updated.', 'invoicing'), 'updated'); |
|
193 | 193 | } |
194 | 194 | |
195 | - if ( isset( $_GET['wpinv-message'] ) && 'discount_update_failed' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
196 | - add_settings_error( 'wpinv-notices', 'wpinv-discount-updated-fail', __( 'There was a problem updating your discount code, please try again.', 'invoicing' ), 'error' ); |
|
195 | + if (isset($_GET['wpinv-message']) && 'discount_update_failed' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) { |
|
196 | + add_settings_error('wpinv-notices', 'wpinv-discount-updated-fail', __('There was a problem updating your discount code, please try again.', 'invoicing'), 'error'); |
|
197 | 197 | } |
198 | 198 | |
199 | - if ( isset( $_GET['wpinv-message'] ) && 'invoice_deleted' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
200 | - add_settings_error( 'wpinv-notices', 'wpinv-deleted', __( 'The invoice has been deleted.', 'invoicing' ), 'updated' ); |
|
199 | + if (isset($_GET['wpinv-message']) && 'invoice_deleted' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) { |
|
200 | + add_settings_error('wpinv-notices', 'wpinv-deleted', __('The invoice has been deleted.', 'invoicing'), 'updated'); |
|
201 | 201 | } |
202 | 202 | |
203 | - if ( isset( $_GET['wpinv-message'] ) && 'email_disabled' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
204 | - add_settings_error( 'wpinv-notices', 'wpinv-sent-fail', __( 'Email notification is disabled. Please check settings.', 'invoicing' ), 'error' ); |
|
203 | + if (isset($_GET['wpinv-message']) && 'email_disabled' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) { |
|
204 | + add_settings_error('wpinv-notices', 'wpinv-sent-fail', __('Email notification is disabled. Please check settings.', 'invoicing'), 'error'); |
|
205 | 205 | } |
206 | 206 | |
207 | - if ( isset( $_GET['wpinv-message'] ) && 'email_sent' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
208 | - add_settings_error( 'wpinv-notices', 'wpinv-sent', __( 'The email has been sent to customer.', 'invoicing' ), 'updated' ); |
|
207 | + if (isset($_GET['wpinv-message']) && 'email_sent' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) { |
|
208 | + add_settings_error('wpinv-notices', 'wpinv-sent', __('The email has been sent to customer.', 'invoicing'), 'updated'); |
|
209 | 209 | } |
210 | 210 | |
211 | - if ( isset( $_GET['wpinv-message'] ) && 'email_fail' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
212 | - add_settings_error( 'wpinv-notices', 'wpinv-sent-fail', __( 'Fail to send email to the customer.', 'invoicing' ), 'error' ); |
|
211 | + if (isset($_GET['wpinv-message']) && 'email_fail' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) { |
|
212 | + add_settings_error('wpinv-notices', 'wpinv-sent-fail', __('Fail to send email to the customer.', 'invoicing'), 'error'); |
|
213 | 213 | } |
214 | 214 | |
215 | - if ( isset( $_GET['wpinv-message'] ) && 'invoice-note-deleted' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
216 | - add_settings_error( 'wpinv-notices', 'wpinv-note-deleted', __( 'The invoice note has been deleted.', 'invoicing' ), 'updated' ); |
|
215 | + if (isset($_GET['wpinv-message']) && 'invoice-note-deleted' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) { |
|
216 | + add_settings_error('wpinv-notices', 'wpinv-note-deleted', __('The invoice note has been deleted.', 'invoicing'), 'updated'); |
|
217 | 217 | } |
218 | 218 | |
219 | - if ( isset( $_GET['wpinv-message'] ) && 'settings-imported' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
220 | - add_settings_error( 'wpinv-notices', 'wpinv-settings-imported', __( 'The settings have been imported.', 'invoicing' ), 'updated' ); |
|
219 | + if (isset($_GET['wpinv-message']) && 'settings-imported' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) { |
|
220 | + add_settings_error('wpinv-notices', 'wpinv-settings-imported', __('The settings have been imported.', 'invoicing'), 'updated'); |
|
221 | 221 | } |
222 | 222 | |
223 | - if ( isset( $_GET['wpinv-message'] ) && 'note-added' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
224 | - add_settings_error( 'wpinv-notices', 'wpinv-note-added', __( 'The invoice note has been added successfully.', 'invoicing' ), 'updated' ); |
|
223 | + if (isset($_GET['wpinv-message']) && 'note-added' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) { |
|
224 | + add_settings_error('wpinv-notices', 'wpinv-note-added', __('The invoice note has been added successfully.', 'invoicing'), 'updated'); |
|
225 | 225 | } |
226 | 226 | |
227 | - if ( isset( $_GET['wpinv-message'] ) && 'invoice-updated' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
228 | - add_settings_error( 'wpinv-notices', 'wpinv-updated', __( 'The invoice has been successfully updated.', 'invoicing' ), 'updated' ); |
|
227 | + if (isset($_GET['wpinv-message']) && 'invoice-updated' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) { |
|
228 | + add_settings_error('wpinv-notices', 'wpinv-updated', __('The invoice has been successfully updated.', 'invoicing'), 'updated'); |
|
229 | 229 | } |
230 | 230 | |
231 | - if ( $pagenow == 'post.php' && !empty( $post->post_type ) && $post->post_type == 'wpi_item' && !wpinv_item_is_editable( $post ) ) { |
|
232 | - $message = apply_filters( 'wpinv_item_non_editable_message', __( 'This item in not editable.', 'invoicing' ), $post->ID ); |
|
231 | + if ($pagenow == 'post.php' && !empty($post->post_type) && $post->post_type == 'wpi_item' && !wpinv_item_is_editable($post)) { |
|
232 | + $message = apply_filters('wpinv_item_non_editable_message', __('This item in not editable.', 'invoicing'), $post->ID); |
|
233 | 233 | |
234 | - if ( !empty( $message ) ) { |
|
235 | - add_settings_error( 'wpinv-notices', 'wpinv-edit-n', $message, 'updated' ); |
|
234 | + if (!empty($message)) { |
|
235 | + add_settings_error('wpinv-notices', 'wpinv-edit-n', $message, 'updated'); |
|
236 | 236 | } |
237 | 237 | } |
238 | 238 | |
239 | - settings_errors( 'wpinv-notices' ); |
|
239 | + settings_errors('wpinv-notices'); |
|
240 | 240 | } |
241 | -add_action( 'admin_notices', 'wpinv_admin_messages' ); |
|
241 | +add_action('admin_notices', 'wpinv_admin_messages'); |
|
242 | 242 | |
243 | -add_action( 'admin_init', 'wpinv_show_test_payment_gateway_notice' ); |
|
244 | -function wpinv_show_test_payment_gateway_notice(){ |
|
245 | - add_action( 'admin_notices', 'wpinv_test_payment_gateway_messages' ); |
|
243 | +add_action('admin_init', 'wpinv_show_test_payment_gateway_notice'); |
|
244 | +function wpinv_show_test_payment_gateway_notice() { |
|
245 | + add_action('admin_notices', 'wpinv_test_payment_gateway_messages'); |
|
246 | 246 | } |
247 | 247 | |
248 | -function wpinv_test_payment_gateway_messages(){ |
|
248 | +function wpinv_test_payment_gateway_messages() { |
|
249 | 249 | $gateways = wpinv_get_enabled_payment_gateways(); |
250 | 250 | $name = array(); $test_gateways = ''; |
251 | 251 | if ($gateways) { |
@@ -256,9 +256,9 @@ discard block |
||
256 | 256 | } |
257 | 257 | $test_gateways = implode(', ', $name); |
258 | 258 | } |
259 | - if(isset($test_gateways) && !empty($test_gateways)){ |
|
259 | + if (isset($test_gateways) && !empty($test_gateways)) { |
|
260 | 260 | $link = admin_url('admin.php?page=wpinv-settings&tab=gateways'); |
261 | - $notice = wp_sprintf( __('<strong>Important:</strong> Payment Gateway(s) %s are in testing mode and will not receive real payments. Go to <a href="%s"> Gateway Settings</a>.', 'invoicing'), $test_gateways, $link ); |
|
261 | + $notice = wp_sprintf(__('<strong>Important:</strong> Payment Gateway(s) %s are in testing mode and will not receive real payments. Go to <a href="%s"> Gateway Settings</a>.', 'invoicing'), $test_gateways, $link); |
|
262 | 262 | ?> |
263 | 263 | <div class="notice notice-warning is-dismissible"> |
264 | 264 | <p><?php echo $notice; ?></p> |
@@ -267,29 +267,29 @@ discard block |
||
267 | 267 | } |
268 | 268 | } |
269 | 269 | |
270 | -function wpinv_items_columns( $existing_columns ) { |
|
270 | +function wpinv_items_columns($existing_columns) { |
|
271 | 271 | global $wpinv_euvat; |
272 | 272 | |
273 | 273 | $columns = array(); |
274 | 274 | $columns['cb'] = $existing_columns['cb']; |
275 | - $columns['title'] = __( 'Title', 'invoicing' ); |
|
276 | - $columns['price'] = __( 'Price', 'invoicing' ); |
|
277 | - if ( $wpinv_euvat->allow_vat_rules() ) { |
|
278 | - $columns['vat_rule'] = __( 'VAT rule type', 'invoicing' ); |
|
275 | + $columns['title'] = __('Title', 'invoicing'); |
|
276 | + $columns['price'] = __('Price', 'invoicing'); |
|
277 | + if ($wpinv_euvat->allow_vat_rules()) { |
|
278 | + $columns['vat_rule'] = __('VAT rule type', 'invoicing'); |
|
279 | 279 | } |
280 | - if ( $wpinv_euvat->allow_vat_classes() ) { |
|
281 | - $columns['vat_class'] = __( 'VAT class', 'invoicing' ); |
|
280 | + if ($wpinv_euvat->allow_vat_classes()) { |
|
281 | + $columns['vat_class'] = __('VAT class', 'invoicing'); |
|
282 | 282 | } |
283 | - $columns['type'] = __( 'Type', 'invoicing' ); |
|
284 | - $columns['recurring'] = __( 'Recurring', 'invoicing' ); |
|
285 | - $columns['date'] = __( 'Date', 'invoicing' ); |
|
286 | - $columns['id'] = __( 'ID', 'invoicing' ); |
|
283 | + $columns['type'] = __('Type', 'invoicing'); |
|
284 | + $columns['recurring'] = __('Recurring', 'invoicing'); |
|
285 | + $columns['date'] = __('Date', 'invoicing'); |
|
286 | + $columns['id'] = __('ID', 'invoicing'); |
|
287 | 287 | |
288 | - return apply_filters( 'wpinv_items_columns', $columns ); |
|
288 | + return apply_filters('wpinv_items_columns', $columns); |
|
289 | 289 | } |
290 | -add_filter( 'manage_wpi_item_posts_columns', 'wpinv_items_columns' ); |
|
290 | +add_filter('manage_wpi_item_posts_columns', 'wpinv_items_columns'); |
|
291 | 291 | |
292 | -function wpinv_items_sortable_columns( $columns ) { |
|
292 | +function wpinv_items_sortable_columns($columns) { |
|
293 | 293 | $columns['price'] = 'price'; |
294 | 294 | $columns['vat_rule'] = 'vat_rule'; |
295 | 295 | $columns['vat_class'] = 'vat_class'; |
@@ -299,175 +299,175 @@ discard block |
||
299 | 299 | |
300 | 300 | return $columns; |
301 | 301 | } |
302 | -add_filter( 'manage_edit-wpi_item_sortable_columns', 'wpinv_items_sortable_columns' ); |
|
302 | +add_filter('manage_edit-wpi_item_sortable_columns', 'wpinv_items_sortable_columns'); |
|
303 | 303 | |
304 | -function wpinv_items_table_custom_column( $column ) { |
|
304 | +function wpinv_items_table_custom_column($column) { |
|
305 | 305 | global $wpinv_euvat, $post, $wpi_item; |
306 | 306 | |
307 | - if ( empty( $wpi_item ) || ( !empty( $wpi_item ) && $post->ID != $wpi_item->ID ) ) { |
|
308 | - $wpi_item = new WPInv_Item( $post->ID ); |
|
307 | + if (empty($wpi_item) || (!empty($wpi_item) && $post->ID != $wpi_item->ID)) { |
|
308 | + $wpi_item = new WPInv_Item($post->ID); |
|
309 | 309 | } |
310 | 310 | |
311 | - switch ( $column ) { |
|
311 | + switch ($column) { |
|
312 | 312 | case 'price' : |
313 | - echo wpinv_item_price( $post->ID ); |
|
313 | + echo wpinv_item_price($post->ID); |
|
314 | 314 | break; |
315 | 315 | case 'vat_rule' : |
316 | - echo $wpinv_euvat->item_rule_label( $post->ID ); |
|
316 | + echo $wpinv_euvat->item_rule_label($post->ID); |
|
317 | 317 | break; |
318 | 318 | case 'vat_class' : |
319 | - echo $wpinv_euvat->item_class_label( $post->ID ); |
|
319 | + echo $wpinv_euvat->item_class_label($post->ID); |
|
320 | 320 | break; |
321 | 321 | case 'type' : |
322 | - echo wpinv_item_type( $post->ID ) . '<span class="meta">' . $wpi_item->get_custom_singular_name() . '</span>'; |
|
322 | + echo wpinv_item_type($post->ID) . '<span class="meta">' . $wpi_item->get_custom_singular_name() . '</span>'; |
|
323 | 323 | break; |
324 | 324 | case 'recurring' : |
325 | - echo ( wpinv_is_recurring_item( $post->ID ) ? '<i class="fa fa-check fa-recurring-y"></i>' : '<i class="fa fa-close fa-recurring-n"></i>' ); |
|
325 | + echo (wpinv_is_recurring_item($post->ID) ? '<i class="fa fa-check fa-recurring-y"></i>' : '<i class="fa fa-close fa-recurring-n"></i>'); |
|
326 | 326 | break; |
327 | 327 | case 'id' : |
328 | 328 | echo $post->ID; |
329 | 329 | echo '<div class="hidden" id="wpinv_inline-' . $post->ID . '"> |
330 | - <div class="price">' . wpinv_get_item_price( $post->ID ) . '</div>'; |
|
331 | - if ( $wpinv_euvat->allow_vat_rules() ) { |
|
332 | - echo '<div class="vat_rule">' . $wpinv_euvat->get_item_rule( $post->ID ) . '</div>'; |
|
330 | + <div class="price">' . wpinv_get_item_price($post->ID) . '</div>'; |
|
331 | + if ($wpinv_euvat->allow_vat_rules()) { |
|
332 | + echo '<div class="vat_rule">' . $wpinv_euvat->get_item_rule($post->ID) . '</div>'; |
|
333 | 333 | } |
334 | - if ( $wpinv_euvat->allow_vat_classes() ) { |
|
335 | - echo '<div class="vat_class">' . $wpinv_euvat->get_item_class( $post->ID ) . '</div>'; |
|
334 | + if ($wpinv_euvat->allow_vat_classes()) { |
|
335 | + echo '<div class="vat_class">' . $wpinv_euvat->get_item_class($post->ID) . '</div>'; |
|
336 | 336 | } |
337 | - echo '<div class="type">' . wpinv_get_item_type( $post->ID ) . '</div> |
|
337 | + echo '<div class="type">' . wpinv_get_item_type($post->ID) . '</div> |
|
338 | 338 | </div>'; |
339 | 339 | break; |
340 | 340 | } |
341 | 341 | |
342 | - do_action( 'wpinv_items_table_column_item_' . $column, $wpi_item, $post ); |
|
342 | + do_action('wpinv_items_table_column_item_' . $column, $wpi_item, $post); |
|
343 | 343 | } |
344 | -add_action( 'manage_wpi_item_posts_custom_column', 'wpinv_items_table_custom_column' ); |
|
344 | +add_action('manage_wpi_item_posts_custom_column', 'wpinv_items_table_custom_column'); |
|
345 | 345 | |
346 | 346 | function wpinv_add_items_filters() { |
347 | 347 | global $wpinv_euvat, $typenow; |
348 | 348 | |
349 | 349 | // Checks if the current post type is 'item' |
350 | - if ( $typenow == 'wpi_item') { |
|
351 | - if ( $wpinv_euvat->allow_vat_rules() ) { |
|
350 | + if ($typenow == 'wpi_item') { |
|
351 | + if ($wpinv_euvat->allow_vat_rules()) { |
|
352 | 352 | |
353 | 353 | // Sanitize selected vat rule. |
354 | - $vat_rule = ''; |
|
355 | - if( isset( $_GET['vat_rule'] ) && array_key_exists( $_GET['type'], $wpinv_euvat->get_rules() ) ) { |
|
356 | - $class = $_GET['type']; |
|
354 | + $vat_rule = ''; |
|
355 | + if (isset($_GET['vat_rule']) && array_key_exists($_GET['type'], $wpinv_euvat->get_rules())) { |
|
356 | + $class = $_GET['type']; |
|
357 | 357 | } |
358 | 358 | |
359 | - echo wpinv_html_select( array( |
|
360 | - 'options' => array_merge( array( '' => __( 'All VAT rules', 'invoicing' ) ), $wpinv_euvat->get_rules() ), |
|
359 | + echo wpinv_html_select(array( |
|
360 | + 'options' => array_merge(array('' => __('All VAT rules', 'invoicing')), $wpinv_euvat->get_rules()), |
|
361 | 361 | 'name' => 'vat_rule', |
362 | 362 | 'id' => 'vat_rule', |
363 | - 'selected' => ( isset( $_GET['vat_rule'] ) ? $_GET['vat_rule'] : '' ), |
|
363 | + 'selected' => (isset($_GET['vat_rule']) ? $_GET['vat_rule'] : ''), |
|
364 | 364 | 'show_option_all' => false, |
365 | 365 | 'show_option_none' => false, |
366 | 366 | 'class' => 'gdmbx2-text-medium wpi_select2', |
367 | - 'placeholder' => __( 'Select VAT rule', 'invoicing' ), |
|
368 | - ) ); |
|
367 | + 'placeholder' => __('Select VAT rule', 'invoicing'), |
|
368 | + )); |
|
369 | 369 | } |
370 | 370 | |
371 | - if ( $wpinv_euvat->allow_vat_classes() ) { |
|
371 | + if ($wpinv_euvat->allow_vat_classes()) { |
|
372 | 372 | |
373 | 373 | $classes = $wpinv_euvat->get_all_classes(); |
374 | 374 | |
375 | 375 | // Sanitize selected vat class. |
376 | 376 | $class = ''; |
377 | - if( isset( $_GET['vat_class'] ) && array_key_exists( $_GET['vat_class'], $classes ) ) { |
|
378 | - $class = $_GET['vat_class']; |
|
377 | + if (isset($_GET['vat_class']) && array_key_exists($_GET['vat_class'], $classes)) { |
|
378 | + $class = $_GET['vat_class']; |
|
379 | 379 | } |
380 | 380 | |
381 | - echo wpinv_html_select( array( |
|
382 | - 'options' => array_merge( array( '' => __( 'All VAT classes', 'invoicing' ) ), $classes ), |
|
381 | + echo wpinv_html_select(array( |
|
382 | + 'options' => array_merge(array('' => __('All VAT classes', 'invoicing')), $classes), |
|
383 | 383 | 'name' => 'vat_class', |
384 | 384 | 'id' => 'vat_class', |
385 | 385 | 'selected' => $class, |
386 | 386 | 'show_option_all' => false, |
387 | 387 | 'show_option_none' => false, |
388 | 388 | 'class' => 'gdmbx2-text-medium wpi_select2', |
389 | - 'placeholder' => __( 'Select VAT class', 'invoicing' ), |
|
390 | - ) ); |
|
389 | + 'placeholder' => __('Select VAT class', 'invoicing'), |
|
390 | + )); |
|
391 | 391 | } |
392 | 392 | |
393 | 393 | // Sanitize selected item type. |
394 | - $type = ''; |
|
395 | - if( isset( $_GET['type'] ) && array_key_exists( $_GET['type'], wpinv_get_item_types() ) ) { |
|
396 | - $class = $_GET['type']; |
|
394 | + $type = ''; |
|
395 | + if (isset($_GET['type']) && array_key_exists($_GET['type'], wpinv_get_item_types())) { |
|
396 | + $class = $_GET['type']; |
|
397 | 397 | } |
398 | 398 | |
399 | - echo wpinv_html_select( array( |
|
400 | - 'options' => array_merge( array( '' => __( 'All item types', 'invoicing' ) ), wpinv_get_item_types() ), |
|
399 | + echo wpinv_html_select(array( |
|
400 | + 'options' => array_merge(array('' => __('All item types', 'invoicing')), wpinv_get_item_types()), |
|
401 | 401 | 'name' => 'type', |
402 | 402 | 'id' => 'type', |
403 | 403 | 'selected' => $type, |
404 | 404 | 'show_option_all' => false, |
405 | 405 | 'show_option_none' => false, |
406 | 406 | 'class' => 'gdmbx2-text-medium', |
407 | - ) ); |
|
407 | + )); |
|
408 | 408 | |
409 | - if ( isset( $_REQUEST['all_posts'] ) && '1' === $_REQUEST['all_posts'] ) { |
|
409 | + if (isset($_REQUEST['all_posts']) && '1' === $_REQUEST['all_posts']) { |
|
410 | 410 | echo '<input type="hidden" name="all_posts" value="1" />'; |
411 | 411 | } |
412 | 412 | } |
413 | 413 | } |
414 | -add_action( 'restrict_manage_posts', 'wpinv_add_items_filters', 100 ); |
|
414 | +add_action('restrict_manage_posts', 'wpinv_add_items_filters', 100); |
|
415 | 415 | |
416 | -function wpinv_send_invoice_after_save( $invoice ) { |
|
417 | - if ( empty( $_POST['wpi_save_send'] ) ) { |
|
416 | +function wpinv_send_invoice_after_save($invoice) { |
|
417 | + if (empty($_POST['wpi_save_send'])) { |
|
418 | 418 | return; |
419 | 419 | } |
420 | 420 | |
421 | - if ( !empty( $invoice->ID ) && !empty( $invoice->post_type ) && 'wpi_invoice' == $invoice->post_type ) { |
|
422 | - wpinv_user_invoice_notification( $invoice->ID ); |
|
421 | + if (!empty($invoice->ID) && !empty($invoice->post_type) && 'wpi_invoice' == $invoice->post_type) { |
|
422 | + wpinv_user_invoice_notification($invoice->ID); |
|
423 | 423 | } |
424 | 424 | } |
425 | -add_action( 'wpinv_invoice_metabox_saved', 'wpinv_send_invoice_after_save', 100, 1 ); |
|
425 | +add_action('wpinv_invoice_metabox_saved', 'wpinv_send_invoice_after_save', 100, 1); |
|
426 | 426 | |
427 | -function wpinv_send_register_new_user( $data, $postarr ) { |
|
428 | - if ( wpinv_current_user_can_manage_invoicing() && !empty( $data['post_type'] ) && ( 'wpi_invoice' == $data['post_type'] || 'wpi_quote' == $data['post_type'] ) ) { |
|
429 | - $is_new_user = !empty( $postarr['wpinv_new_user'] ) ? true : false; |
|
430 | - $email = !empty( $postarr['wpinv_email'] ) && $postarr['wpinv_email'] && is_email( $postarr['wpinv_email'] ) ? $postarr['wpinv_email'] : NULL; |
|
427 | +function wpinv_send_register_new_user($data, $postarr) { |
|
428 | + if (wpinv_current_user_can_manage_invoicing() && !empty($data['post_type']) && ('wpi_invoice' == $data['post_type'] || 'wpi_quote' == $data['post_type'])) { |
|
429 | + $is_new_user = !empty($postarr['wpinv_new_user']) ? true : false; |
|
430 | + $email = !empty($postarr['wpinv_email']) && $postarr['wpinv_email'] && is_email($postarr['wpinv_email']) ? $postarr['wpinv_email'] : NULL; |
|
431 | 431 | |
432 | - if ( $is_new_user && $email && !email_exists( $email ) ) { |
|
433 | - $first_name = !empty( $postarr['wpinv_first_name'] ) ? sanitize_text_field( $postarr['wpinv_first_name'] ) : ''; |
|
434 | - $last_name = !empty( $postarr['wpinv_last_name'] ) ? sanitize_text_field( $postarr['wpinv_last_name'] ) : ''; |
|
435 | - $display_name = $first_name || $last_name ? trim( $first_name . ' ' . $last_name ) : ''; |
|
436 | - $user_nicename = $display_name ? trim( $display_name ) : $email; |
|
437 | - $user_company = !empty( $postarr['wpinv_company'] ) ? sanitize_text_field( $postarr['wpinv_company'] ) : ''; |
|
432 | + if ($is_new_user && $email && !email_exists($email)) { |
|
433 | + $first_name = !empty($postarr['wpinv_first_name']) ? sanitize_text_field($postarr['wpinv_first_name']) : ''; |
|
434 | + $last_name = !empty($postarr['wpinv_last_name']) ? sanitize_text_field($postarr['wpinv_last_name']) : ''; |
|
435 | + $display_name = $first_name || $last_name ? trim($first_name . ' ' . $last_name) : ''; |
|
436 | + $user_nicename = $display_name ? trim($display_name) : $email; |
|
437 | + $user_company = !empty($postarr['wpinv_company']) ? sanitize_text_field($postarr['wpinv_company']) : ''; |
|
438 | 438 | |
439 | - $user_login = sanitize_user( str_replace( ' ', '', $display_name ), true ); |
|
440 | - if ( !( validate_username( $user_login ) && !username_exists( $user_login ) ) ) { |
|
439 | + $user_login = sanitize_user(str_replace(' ', '', $display_name), true); |
|
440 | + if (!(validate_username($user_login) && !username_exists($user_login))) { |
|
441 | 441 | $new_user_login = strstr($email, '@', true); |
442 | - if ( validate_username( $user_login ) && username_exists( $user_login ) ) { |
|
443 | - $user_login = sanitize_user($new_user_login, true ); |
|
442 | + if (validate_username($user_login) && username_exists($user_login)) { |
|
443 | + $user_login = sanitize_user($new_user_login, true); |
|
444 | 444 | } |
445 | - if ( validate_username( $user_login ) && username_exists( $user_login ) ) { |
|
446 | - $user_append_text = rand(10,1000); |
|
447 | - $user_login = sanitize_user($new_user_login.$user_append_text, true ); |
|
445 | + if (validate_username($user_login) && username_exists($user_login)) { |
|
446 | + $user_append_text = rand(10, 1000); |
|
447 | + $user_login = sanitize_user($new_user_login . $user_append_text, true); |
|
448 | 448 | } |
449 | 449 | |
450 | - if ( !( validate_username( $user_login ) && !username_exists( $user_login ) ) ) { |
|
450 | + if (!(validate_username($user_login) && !username_exists($user_login))) { |
|
451 | 451 | $user_login = $email; |
452 | 452 | } |
453 | 453 | } |
454 | 454 | |
455 | 455 | $userdata = array( |
456 | 456 | 'user_login' => $user_login, |
457 | - 'user_pass' => wp_generate_password( 12, false ), |
|
458 | - 'user_email' => sanitize_text_field( $email ), |
|
457 | + 'user_pass' => wp_generate_password(12, false), |
|
458 | + 'user_email' => sanitize_text_field($email), |
|
459 | 459 | 'first_name' => $first_name, |
460 | 460 | 'last_name' => $last_name, |
461 | - 'user_nicename' => wpinv_utf8_substr( $user_nicename, 0, 50 ), |
|
461 | + 'user_nicename' => wpinv_utf8_substr($user_nicename, 0, 50), |
|
462 | 462 | 'nickname' => $display_name, |
463 | 463 | 'display_name' => $display_name, |
464 | 464 | ); |
465 | 465 | |
466 | - $userdata = apply_filters( 'wpinv_register_new_user_data', $userdata ); |
|
466 | + $userdata = apply_filters('wpinv_register_new_user_data', $userdata); |
|
467 | 467 | |
468 | - $new_user_id = wp_insert_user( $userdata ); |
|
468 | + $new_user_id = wp_insert_user($userdata); |
|
469 | 469 | |
470 | - if ( !is_wp_error( $new_user_id ) ) { |
|
470 | + if (!is_wp_error($new_user_id)) { |
|
471 | 471 | $data['post_author'] = $new_user_id; |
472 | 472 | $_POST['post_author'] = $new_user_id; |
473 | 473 | $_POST['post_author_override'] = $new_user_id; |
@@ -488,72 +488,72 @@ discard block |
||
488 | 488 | |
489 | 489 | $meta = array(); |
490 | 490 | ///$meta['_wpinv_user_id'] = $new_user_id; |
491 | - foreach ( $meta_fields as $field ) { |
|
492 | - $meta['_wpinv_' . $field] = isset( $postarr['wpinv_' . $field] ) ? sanitize_text_field( $postarr['wpinv_' . $field] ) : ''; |
|
491 | + foreach ($meta_fields as $field) { |
|
492 | + $meta['_wpinv_' . $field] = isset($postarr['wpinv_' . $field]) ? sanitize_text_field($postarr['wpinv_' . $field]) : ''; |
|
493 | 493 | } |
494 | 494 | |
495 | - $meta = apply_filters( 'wpinv_register_new_user_meta', $meta, $new_user_id ); |
|
495 | + $meta = apply_filters('wpinv_register_new_user_meta', $meta, $new_user_id); |
|
496 | 496 | |
497 | 497 | // Update user meta. |
498 | - foreach ( $meta as $key => $value ) { |
|
499 | - update_user_meta( $new_user_id, $key, $value ); |
|
498 | + foreach ($meta as $key => $value) { |
|
499 | + update_user_meta($new_user_id, $key, $value); |
|
500 | 500 | } |
501 | 501 | |
502 | - if ( function_exists( 'wp_send_new_user_notifications' ) ) { |
|
502 | + if (function_exists('wp_send_new_user_notifications')) { |
|
503 | 503 | // Send email notifications related to the creation of new user. |
504 | - wp_send_new_user_notifications( $new_user_id, 'user' ); |
|
504 | + wp_send_new_user_notifications($new_user_id, 'user'); |
|
505 | 505 | } |
506 | 506 | } else { |
507 | - wpinv_error_log( $new_user_id->get_error_message(), 'Invoice add new user', __FILE__, __LINE__ ); |
|
507 | + wpinv_error_log($new_user_id->get_error_message(), 'Invoice add new user', __FILE__, __LINE__); |
|
508 | 508 | } |
509 | 509 | } |
510 | 510 | } |
511 | 511 | |
512 | 512 | return $data; |
513 | 513 | } |
514 | -add_filter( 'wp_insert_post_data', 'wpinv_send_register_new_user', 10, 2 ); |
|
514 | +add_filter('wp_insert_post_data', 'wpinv_send_register_new_user', 10, 2); |
|
515 | 515 | |
516 | -function wpinv_show_recurring_supported_gateways( $item_ID ) { |
|
516 | +function wpinv_show_recurring_supported_gateways($item_ID) { |
|
517 | 517 | $all_gateways = wpinv_get_payment_gateways(); |
518 | 518 | |
519 | - if ( !empty( $all_gateways ) ) { |
|
519 | + if (!empty($all_gateways)) { |
|
520 | 520 | $gateways = array(); |
521 | 521 | |
522 | - foreach ( $all_gateways as $key => $gateway ) { |
|
523 | - if ( wpinv_gateway_support_subscription( $key ) ) { |
|
522 | + foreach ($all_gateways as $key => $gateway) { |
|
523 | + if (wpinv_gateway_support_subscription($key)) { |
|
524 | 524 | $gateways[] = $gateway['admin_label']; |
525 | 525 | } |
526 | 526 | } |
527 | 527 | |
528 | - if ( !empty( $gateways ) ) { |
|
528 | + if (!empty($gateways)) { |
|
529 | 529 | ?> |
530 | - <span class="description"><?php echo wp_sprintf( __( 'Recurring payments only supported by: %s', 'invoicing' ), implode( ', ', $gateways ) ); ?></span> |
|
530 | + <span class="description"><?php echo wp_sprintf(__('Recurring payments only supported by: %s', 'invoicing'), implode(', ', $gateways)); ?></span> |
|
531 | 531 | <?php |
532 | 532 | } |
533 | 533 | } |
534 | 534 | } |
535 | -add_action( 'wpinv_item_price_field', 'wpinv_show_recurring_supported_gateways', -10, 1 ); |
|
535 | +add_action('wpinv_item_price_field', 'wpinv_show_recurring_supported_gateways', -10, 1); |
|
536 | 536 | |
537 | -function wpinv_post_updated_messages( $messages ) { |
|
537 | +function wpinv_post_updated_messages($messages) { |
|
538 | 538 | global $post, $post_ID; |
539 | 539 | |
540 | 540 | $messages['wpi_discount'] = array( |
541 | 541 | 0 => '', |
542 | - 1 => __( 'Discount updated.', 'invoicing' ), |
|
543 | - 2 => __( 'Custom field updated.', 'invoicing' ), |
|
544 | - 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
545 | - 4 => __( 'Discount updated.', 'invoicing' ), |
|
546 | - 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
547 | - 6 => __( 'Discount updated.', 'invoicing' ), |
|
548 | - 7 => __( 'Discount saved.', 'invoicing' ), |
|
549 | - 8 => __( 'Discount submitted.', 'invoicing' ), |
|
550 | - 9 => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
551 | - 10 => __( 'Discount draft updated.', 'invoicing' ), |
|
542 | + 1 => __('Discount updated.', 'invoicing'), |
|
543 | + 2 => __('Custom field updated.', 'invoicing'), |
|
544 | + 3 => __('Custom field deleted.', 'invoicing'), |
|
545 | + 4 => __('Discount updated.', 'invoicing'), |
|
546 | + 5 => isset($_GET['revision']) ? wp_sprintf(__('Discount restored to revision from %s', 'invoicing'), wp_post_revision_title((int) $_GET['revision'], false)) : false, |
|
547 | + 6 => __('Discount updated.', 'invoicing'), |
|
548 | + 7 => __('Discount saved.', 'invoicing'), |
|
549 | + 8 => __('Discount submitted.', 'invoicing'), |
|
550 | + 9 => wp_sprintf(__('Discount scheduled for: <strong>%1$s</strong>.', 'invoicing'), date_i18n(__('M j, Y @ G:i', 'invoicing'), strtotime($post->post_date))), |
|
551 | + 10 => __('Discount draft updated.', 'invoicing'), |
|
552 | 552 | ); |
553 | 553 | |
554 | 554 | return $messages; |
555 | 555 | } |
556 | -add_filter( 'post_updated_messages', 'wpinv_post_updated_messages', 10, 1 ); |
|
556 | +add_filter('post_updated_messages', 'wpinv_post_updated_messages', 10, 1); |
|
557 | 557 | |
558 | 558 | add_action('admin_init', 'admin_init_example_type'); |
559 | 559 | |
@@ -563,7 +563,7 @@ discard block |
||
563 | 563 | function admin_init_example_type() { |
564 | 564 | global $typenow; |
565 | 565 | |
566 | - if ($typenow === 'wpi_invoice' || $typenow === 'wpi_quote' ) { |
|
566 | + if ($typenow === 'wpi_invoice' || $typenow === 'wpi_quote') { |
|
567 | 567 | add_filter('posts_search', 'posts_search_example_type', 10, 2); |
568 | 568 | } |
569 | 569 | } |
@@ -578,9 +578,9 @@ discard block |
||
578 | 578 | global $wpdb; |
579 | 579 | |
580 | 580 | if ($query->is_main_query() && !empty($query->query['s'])) { |
581 | - $conditions_str = "{$wpdb->posts}.post_author IN ( SELECT ID FROM {$wpdb->users} WHERE user_email LIKE '%" . esc_sql( $query->query['s'] ) . "%' )"; |
|
582 | - if ( ! empty( $search ) ) { |
|
583 | - $search = preg_replace( '/^ AND /', '', $search ); |
|
581 | + $conditions_str = "{$wpdb->posts}.post_author IN ( SELECT ID FROM {$wpdb->users} WHERE user_email LIKE '%" . esc_sql($query->query['s']) . "%' )"; |
|
582 | + if (!empty($search)) { |
|
583 | + $search = preg_replace('/^ AND /', '', $search); |
|
584 | 584 | $search = " AND ( {$search} OR ( {$conditions_str} ) )"; |
585 | 585 | } else { |
586 | 586 | $search = " AND ( {$conditions_str} )"; |
@@ -590,9 +590,9 @@ discard block |
||
590 | 590 | return $search; |
591 | 591 | } |
592 | 592 | |
593 | -add_action( 'admin_init', 'wpinv_reset_invoice_count' ); |
|
594 | -function wpinv_reset_invoice_count(){ |
|
595 | - if(isset($_GET['reset_invoice_count']) && 1 == $_GET['reset_invoice_count'] && isset($_GET['_nonce']) && wp_verify_nonce($_GET['_nonce'], 'reset_invoice_count')) { |
|
593 | +add_action('admin_init', 'wpinv_reset_invoice_count'); |
|
594 | +function wpinv_reset_invoice_count() { |
|
595 | + if (isset($_GET['reset_invoice_count']) && 1 == $_GET['reset_invoice_count'] && isset($_GET['_nonce']) && wp_verify_nonce($_GET['_nonce'], 'reset_invoice_count')) { |
|
596 | 596 | wpinv_update_option('invoice_sequence_start', 1); |
597 | 597 | delete_option('wpinv_last_invoice_number'); |
598 | 598 | $url = add_query_arg(array('reset_invoice_done' => 1)); |
@@ -603,8 +603,8 @@ discard block |
||
603 | 603 | } |
604 | 604 | |
605 | 605 | add_action('admin_notices', 'wpinv_invoice_count_reset_message'); |
606 | -function wpinv_invoice_count_reset_message(){ |
|
607 | - if(isset($_GET['reset_invoice_done']) && 1 == $_GET['reset_invoice_done']) { |
|
606 | +function wpinv_invoice_count_reset_message() { |
|
607 | + if (isset($_GET['reset_invoice_done']) && 1 == $_GET['reset_invoice_done']) { |
|
608 | 608 | $notice = __('Invoice number sequence reset successfully.', 'invoicing'); |
609 | 609 | ?> |
610 | 610 | <div class="notice notice-success is-dismissible"> |
@@ -52,14 +52,14 @@ |
||
52 | 52 | } |
53 | 53 | |
54 | 54 | |
55 | - /** |
|
56 | - * Registers routes |
|
57 | - * |
|
55 | + /** |
|
56 | + * Registers routes |
|
57 | + * |
|
58 | 58 | * @since 1.0.13 |
59 | - */ |
|
60 | - public function register_rest_routes() { |
|
59 | + */ |
|
60 | + public function register_rest_routes() { |
|
61 | 61 | |
62 | - // Invoices. |
|
62 | + // Invoices. |
|
63 | 63 | $this->invoices_controller->register_routes(); |
64 | 64 | |
65 | 65 | // Items. |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | // MUST have WordPress. |
10 | -if ( !defined( 'WPINC' ) ) { |
|
10 | +if (!defined('WPINC')) { |
|
11 | 11 | exit; |
12 | 12 | } |
13 | 13 | |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | /** |
20 | 20 | * @param string A prefix for our REST routes |
21 | 21 | */ |
22 | - public $api_namespace = ''; |
|
22 | + public $api_namespace = ''; |
|
23 | 23 | |
24 | 24 | /** |
25 | 25 | * @param WPInv_REST_Invoice_Controller Invoices controller |
@@ -37,19 +37,19 @@ discard block |
||
37 | 37 | * @since 1.0.13 |
38 | 38 | * Sets the API namespace and inits hooks |
39 | 39 | */ |
40 | - public function __construct( $api_namespace = 'invoicing/v1' ) { |
|
40 | + public function __construct($api_namespace = 'invoicing/v1') { |
|
41 | 41 | |
42 | 42 | // Include controllers and related files |
43 | 43 | $this->includes(); |
44 | 44 | |
45 | 45 | // Set up class variables |
46 | - $this->api_namespace = apply_filters( 'wpinv_rest_api_namespace', $api_namespace ); |
|
47 | - $this->invoices_controller = new WPInv_REST_Invoice_Controller( $this->api_namespace ); |
|
48 | - $this->items_controller = new WPInv_REST_Items_Controller( $this->api_namespace ); |
|
49 | - $this->discounts_controller= new WPInv_REST_Discounts_Controller( $this->api_namespace ); |
|
46 | + $this->api_namespace = apply_filters('wpinv_rest_api_namespace', $api_namespace); |
|
47 | + $this->invoices_controller = new WPInv_REST_Invoice_Controller($this->api_namespace); |
|
48 | + $this->items_controller = new WPInv_REST_Items_Controller($this->api_namespace); |
|
49 | + $this->discounts_controller = new WPInv_REST_Discounts_Controller($this->api_namespace); |
|
50 | 50 | |
51 | 51 | //Register REST routes |
52 | - add_action( 'rest_api_init', array( $this, 'register_rest_routes' ) ); |
|
52 | + add_action('rest_api_init', array($this, 'register_rest_routes')); |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | |
@@ -80,13 +80,13 @@ discard block |
||
80 | 80 | protected function includes() { |
81 | 81 | |
82 | 82 | // Invoices |
83 | - require_once( WPINV_PLUGIN_DIR . 'includes/api/class-wpinv-rest-invoice-controller.php' ); |
|
83 | + require_once(WPINV_PLUGIN_DIR . 'includes/api/class-wpinv-rest-invoice-controller.php'); |
|
84 | 84 | |
85 | 85 | // Items |
86 | - require_once( WPINV_PLUGIN_DIR . 'includes/api/class-wpinv-rest-items-controller.php' ); |
|
86 | + require_once(WPINV_PLUGIN_DIR . 'includes/api/class-wpinv-rest-items-controller.php'); |
|
87 | 87 | |
88 | 88 | // Discounts |
89 | - require_once( WPINV_PLUGIN_DIR . 'includes/api/class-wpinv-rest-discounts-controller.php' ); |
|
89 | + require_once(WPINV_PLUGIN_DIR . 'includes/api/class-wpinv-rest-discounts-controller.php'); |
|
90 | 90 | |
91 | 91 | } |
92 | 92 |
@@ -20,31 +20,31 @@ discard block |
||
20 | 20 | class WPInv_REST_Invoice_Controller extends WP_REST_Posts_Controller { |
21 | 21 | |
22 | 22 | /** |
23 | - * Post type. |
|
24 | - * |
|
25 | - * @var string |
|
26 | - */ |
|
27 | - protected $post_type = 'wpi_invoice'; |
|
23 | + * Post type. |
|
24 | + * |
|
25 | + * @var string |
|
26 | + */ |
|
27 | + protected $post_type = 'wpi_invoice'; |
|
28 | 28 | |
29 | - /** |
|
30 | - * Cached results of get_item_schema. |
|
31 | - * |
|
32 | - * @since 1.0.13 |
|
33 | - * @var array |
|
34 | - */ |
|
35 | - protected $schema; |
|
29 | + /** |
|
30 | + * Cached results of get_item_schema. |
|
31 | + * |
|
32 | + * @since 1.0.13 |
|
33 | + * @var array |
|
34 | + */ |
|
35 | + protected $schema; |
|
36 | 36 | |
37 | 37 | /** |
38 | - * Constructor. |
|
39 | - * |
|
40 | - * @since 1.0.13 |
|
41 | - * |
|
42 | - * @param string $namespace Api Namespace |
|
43 | - */ |
|
44 | - public function __construct( $namespace ) { |
|
38 | + * Constructor. |
|
39 | + * |
|
40 | + * @since 1.0.13 |
|
41 | + * |
|
42 | + * @param string $namespace Api Namespace |
|
43 | + */ |
|
44 | + public function __construct( $namespace ) { |
|
45 | 45 | |
46 | 46 | // Set api namespace... |
47 | - $this->namespace = $namespace; |
|
47 | + $this->namespace = $namespace; |
|
48 | 48 | |
49 | 49 | // ... and the rest base |
50 | 50 | $this->rest_base = 'invoices'; |
@@ -52,39 +52,39 @@ discard block |
||
52 | 52 | } |
53 | 53 | |
54 | 54 | /** |
55 | - * Checks if a given request has access to read invoices. |
|
55 | + * Checks if a given request has access to read invoices. |
|
56 | 56 | * |
57 | - * |
|
58 | - * @since 1.0.13 |
|
59 | - * |
|
60 | - * @param WP_REST_Request $request Full details about the request. |
|
61 | - * @return true|WP_Error True if the request has read access, WP_Error object otherwise. |
|
62 | - */ |
|
63 | - public function get_items_permissions_check( $request ) { |
|
57 | + * |
|
58 | + * @since 1.0.13 |
|
59 | + * |
|
60 | + * @param WP_REST_Request $request Full details about the request. |
|
61 | + * @return true|WP_Error True if the request has read access, WP_Error object otherwise. |
|
62 | + */ |
|
63 | + public function get_items_permissions_check( $request ) { |
|
64 | 64 | |
65 | 65 | $post_type = get_post_type_object( $this->post_type ); |
66 | 66 | |
67 | - if ( 'edit' === $request['context'] && ! current_user_can( $post_type->cap->edit_posts ) ) { |
|
68 | - return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to edit invoices.', 'invoicing' ), array( 'status' => rest_authorization_required_code() ) ); |
|
69 | - } |
|
67 | + if ( 'edit' === $request['context'] && ! current_user_can( $post_type->cap->edit_posts ) ) { |
|
68 | + return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to edit invoices.', 'invoicing' ), array( 'status' => rest_authorization_required_code() ) ); |
|
69 | + } |
|
70 | 70 | |
71 | - // Read checks will be evaluated on a per invoice basis |
|
71 | + // Read checks will be evaluated on a per invoice basis |
|
72 | 72 | |
73 | - return true; |
|
73 | + return true; |
|
74 | 74 | |
75 | 75 | } |
76 | 76 | |
77 | 77 | /** |
78 | - * Retrieves a collection of invoices. |
|
79 | - * |
|
80 | - * @since 1.0.13 |
|
81 | - * |
|
82 | - * @param WP_REST_Request $request Full details about the request. |
|
83 | - * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. |
|
84 | - */ |
|
85 | - public function get_items( $request ) { |
|
78 | + * Retrieves a collection of invoices. |
|
79 | + * |
|
80 | + * @since 1.0.13 |
|
81 | + * |
|
82 | + * @param WP_REST_Request $request Full details about the request. |
|
83 | + * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. |
|
84 | + */ |
|
85 | + public function get_items( $request ) { |
|
86 | 86 | |
87 | - // Retrieve the list of registered invoice query parameters. |
|
87 | + // Retrieve the list of registered invoice query parameters. |
|
88 | 88 | $registered = $this->get_collection_params(); |
89 | 89 | |
90 | 90 | $args = array(); |
@@ -97,54 +97,54 @@ discard block |
||
97 | 97 | |
98 | 98 | } |
99 | 99 | |
100 | - /** |
|
101 | - * Filters the wpinv_get_invoices arguments for invoices requests. |
|
102 | - * |
|
103 | - * |
|
104 | - * @since 1.0.13 |
|
105 | - * |
|
106 | - * |
|
107 | - * @param array $args Key value array of query var to query value. |
|
108 | - * @param WP_REST_Request $request The request used. |
|
109 | - */ |
|
100 | + /** |
|
101 | + * Filters the wpinv_get_invoices arguments for invoices requests. |
|
102 | + * |
|
103 | + * |
|
104 | + * @since 1.0.13 |
|
105 | + * |
|
106 | + * |
|
107 | + * @param array $args Key value array of query var to query value. |
|
108 | + * @param WP_REST_Request $request The request used. |
|
109 | + */ |
|
110 | 110 | $args = apply_filters( "wpinv_rest_get_invoices_arguments", $args, $request, $this ); |
111 | 111 | |
112 | - // Special args |
|
113 | - $args[ 'return' ] = 'objects'; |
|
114 | - $args[ 'paginate' ] = true; |
|
112 | + // Special args |
|
113 | + $args[ 'return' ] = 'objects'; |
|
114 | + $args[ 'paginate' ] = true; |
|
115 | 115 | |
116 | 116 | // Run the query. |
117 | - $query = wpinv_get_invoices( $args ); |
|
117 | + $query = wpinv_get_invoices( $args ); |
|
118 | 118 | |
119 | - // Prepare the retrieved invoices |
|
120 | - $invoices = array(); |
|
121 | - foreach( $query->invoices as $invoice ) { |
|
122 | - |
|
123 | - if ( ! $this->check_read_permission( $invoice ) ) { |
|
124 | - continue; |
|
125 | - } |
|
126 | - |
|
127 | - $data = $this->prepare_item_for_response( $invoice, $request ); |
|
128 | - $invoices[] = $this->prepare_response_for_collection( $data ); |
|
129 | - |
|
130 | - } |
|
131 | - |
|
132 | - // Prepare the response. |
|
133 | - $response = rest_ensure_response( $invoices ); |
|
134 | - $response->header( 'X-WP-Total', (int) $query->total ); |
|
135 | - $response->header( 'X-WP-TotalPages', (int) $query->max_num_pages ); |
|
136 | - |
|
137 | - /** |
|
138 | - * Filters the responses for invoices requests. |
|
139 | - * |
|
140 | - * |
|
141 | - * @since 1.0.13 |
|
142 | - * |
|
143 | - * |
|
144 | - * @param arrWP_REST_Response $response Response object. |
|
145 | - * @param WP_REST_Request $request The request used. |
|
119 | + // Prepare the retrieved invoices |
|
120 | + $invoices = array(); |
|
121 | + foreach( $query->invoices as $invoice ) { |
|
122 | + |
|
123 | + if ( ! $this->check_read_permission( $invoice ) ) { |
|
124 | + continue; |
|
125 | + } |
|
126 | + |
|
127 | + $data = $this->prepare_item_for_response( $invoice, $request ); |
|
128 | + $invoices[] = $this->prepare_response_for_collection( $data ); |
|
129 | + |
|
130 | + } |
|
131 | + |
|
132 | + // Prepare the response. |
|
133 | + $response = rest_ensure_response( $invoices ); |
|
134 | + $response->header( 'X-WP-Total', (int) $query->total ); |
|
135 | + $response->header( 'X-WP-TotalPages', (int) $query->max_num_pages ); |
|
136 | + |
|
137 | + /** |
|
138 | + * Filters the responses for invoices requests. |
|
139 | + * |
|
140 | + * |
|
141 | + * @since 1.0.13 |
|
142 | + * |
|
143 | + * |
|
144 | + * @param arrWP_REST_Response $response Response object. |
|
145 | + * @param WP_REST_Request $request The request used. |
|
146 | 146 | * @param array $args Array of args used to retrieve the invoices |
147 | - */ |
|
147 | + */ |
|
148 | 148 | $response = apply_filters( "wpinv_rest_invoices_response", $response, $request, $args ); |
149 | 149 | |
150 | 150 | return rest_ensure_response( $response ); |
@@ -152,25 +152,25 @@ discard block |
||
152 | 152 | } |
153 | 153 | |
154 | 154 | /** |
155 | - * Get the post, if the ID is valid. |
|
156 | - * |
|
157 | - * @since 1.0.13 |
|
158 | - * |
|
159 | - * @param int $invoice_id Supplied ID. |
|
160 | - * @return WPInv_Invoice|WP_Error Invoice object if ID is valid, WP_Error otherwise. |
|
161 | - */ |
|
162 | - protected function get_post( $invoice_id ) { |
|
155 | + * Get the post, if the ID is valid. |
|
156 | + * |
|
157 | + * @since 1.0.13 |
|
158 | + * |
|
159 | + * @param int $invoice_id Supplied ID. |
|
160 | + * @return WPInv_Invoice|WP_Error Invoice object if ID is valid, WP_Error otherwise. |
|
161 | + */ |
|
162 | + protected function get_post( $invoice_id ) { |
|
163 | 163 | |
164 | - $error = new WP_Error( 'rest_invoice_invalid_id', __( 'Invalid invoice ID.', 'invoicing' ), array( 'status' => 404 ) ); |
|
164 | + $error = new WP_Error( 'rest_invoice_invalid_id', __( 'Invalid invoice ID.', 'invoicing' ), array( 'status' => 404 ) ); |
|
165 | 165 | |
166 | 166 | // Ids start from 1 |
167 | 167 | if ( (int) $invoice_id <= 0 ) { |
168 | - return $error; |
|
169 | - } |
|
168 | + return $error; |
|
169 | + } |
|
170 | 170 | |
171 | - $invoice = wpinv_get_invoice( (int) $invoice_id ); |
|
172 | - if ( empty( $invoice ) ) { |
|
173 | - return $error; |
|
171 | + $invoice = wpinv_get_invoice( (int) $invoice_id ); |
|
172 | + if ( empty( $invoice ) ) { |
|
173 | + return $error; |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | return $invoice; |
@@ -178,77 +178,77 @@ discard block |
||
178 | 178 | } |
179 | 179 | |
180 | 180 | /** |
181 | - * Checks if a given request has access to read an invoice. |
|
182 | - * |
|
183 | - * @since 1.0.13 |
|
184 | - * |
|
185 | - * @param WP_REST_Request $request Full details about the request. |
|
186 | - * @return bool|WP_Error True if the request has read access for the invoice, WP_Error object otherwise. |
|
187 | - */ |
|
188 | - public function get_item_permissions_check( $request ) { |
|
181 | + * Checks if a given request has access to read an invoice. |
|
182 | + * |
|
183 | + * @since 1.0.13 |
|
184 | + * |
|
185 | + * @param WP_REST_Request $request Full details about the request. |
|
186 | + * @return bool|WP_Error True if the request has read access for the invoice, WP_Error object otherwise. |
|
187 | + */ |
|
188 | + public function get_item_permissions_check( $request ) { |
|
189 | 189 | |
190 | 190 | // Retrieve the invoice object. |
191 | 191 | $invoice = $this->get_post( $request['id'] ); |
192 | 192 | |
193 | 193 | // Ensure it is valid. |
194 | - if ( is_wp_error( $invoice ) ) { |
|
195 | - return $invoice; |
|
196 | - } |
|
194 | + if ( is_wp_error( $invoice ) ) { |
|
195 | + return $invoice; |
|
196 | + } |
|
197 | 197 | |
198 | - if ( $invoice ) { |
|
199 | - return $this->check_read_permission( $invoice ); |
|
200 | - } |
|
198 | + if ( $invoice ) { |
|
199 | + return $this->check_read_permission( $invoice ); |
|
200 | + } |
|
201 | 201 | |
202 | - return true; |
|
202 | + return true; |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | /** |
206 | - * Checks if an invoice can be read. |
|
207 | - * |
|
208 | - * An invoice can be read by site admins and owners of the invoice |
|
209 | - * |
|
210 | - * |
|
211 | - * @since 1.0.13 |
|
212 | - * |
|
213 | - * @param WPInv_Invoice $invoice WPInv_Invoice object. |
|
214 | - * @return bool Whether the post can be read. |
|
215 | - */ |
|
216 | - public function check_read_permission( $invoice ) { |
|
217 | - return wpinv_user_can_view_invoice( $invoice->ID ); |
|
206 | + * Checks if an invoice can be read. |
|
207 | + * |
|
208 | + * An invoice can be read by site admins and owners of the invoice |
|
209 | + * |
|
210 | + * |
|
211 | + * @since 1.0.13 |
|
212 | + * |
|
213 | + * @param WPInv_Invoice $invoice WPInv_Invoice object. |
|
214 | + * @return bool Whether the post can be read. |
|
215 | + */ |
|
216 | + public function check_read_permission( $invoice ) { |
|
217 | + return wpinv_user_can_view_invoice( $invoice->ID ); |
|
218 | 218 | } |
219 | 219 | |
220 | 220 | /** |
221 | - * Retrieves a single invoice. |
|
222 | - * |
|
223 | - * @since 1.0.13 |
|
224 | - * |
|
225 | - * @param WP_REST_Request $request Full details about the request. |
|
226 | - * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. |
|
227 | - */ |
|
228 | - public function get_item( $request ) { |
|
221 | + * Retrieves a single invoice. |
|
222 | + * |
|
223 | + * @since 1.0.13 |
|
224 | + * |
|
225 | + * @param WP_REST_Request $request Full details about the request. |
|
226 | + * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. |
|
227 | + */ |
|
228 | + public function get_item( $request ) { |
|
229 | 229 | |
230 | 230 | // Fetch the invoice. |
231 | 231 | $invoice = $this->get_post( $request['id'] ); |
232 | 232 | |
233 | 233 | // Abort early if it does not exist |
234 | - if ( is_wp_error( $invoice ) ) { |
|
235 | - return $invoice; |
|
236 | - } |
|
237 | - |
|
238 | - // Prepare the response |
|
239 | - $response = $this->prepare_item_for_response( $invoice, $request ); |
|
240 | - $response->link_header( 'alternate', esc_url( $invoice->get_view_url() ), array( 'type' => 'text/html' ) ); |
|
241 | - |
|
242 | - /** |
|
243 | - * Filters the responses for single invoice requests. |
|
244 | - * |
|
245 | - * |
|
246 | - * @since 1.0.13 |
|
247 | - * @var WP_HTTP_Response |
|
248 | - * |
|
249 | - * @param WP_HTTP_Response $response Response. |
|
250 | - * @param WP_REST_Request $request The request used. |
|
251 | - */ |
|
234 | + if ( is_wp_error( $invoice ) ) { |
|
235 | + return $invoice; |
|
236 | + } |
|
237 | + |
|
238 | + // Prepare the response |
|
239 | + $response = $this->prepare_item_for_response( $invoice, $request ); |
|
240 | + $response->link_header( 'alternate', esc_url( $invoice->get_view_url() ), array( 'type' => 'text/html' ) ); |
|
241 | + |
|
242 | + /** |
|
243 | + * Filters the responses for single invoice requests. |
|
244 | + * |
|
245 | + * |
|
246 | + * @since 1.0.13 |
|
247 | + * @var WP_HTTP_Response |
|
248 | + * |
|
249 | + * @param WP_HTTP_Response $response Response. |
|
250 | + * @param WP_REST_Request $request The request used. |
|
251 | + */ |
|
252 | 252 | $response = apply_filters( "wpinv_rest_get_invoice_response", $response, $request ); |
253 | 253 | |
254 | 254 | return rest_ensure_response( $response ); |
@@ -256,23 +256,23 @@ discard block |
||
256 | 256 | } |
257 | 257 | |
258 | 258 | /** |
259 | - * Checks if a given request has access to create an invoice. |
|
260 | - * |
|
261 | - * @since 1.0.13 |
|
262 | - * |
|
263 | - * @param WP_REST_Request $request Full details about the request. |
|
264 | - * @return true|WP_Error True if the request has access to create items, WP_Error object otherwise. |
|
265 | - */ |
|
266 | - public function create_item_permissions_check( $request ) { |
|
259 | + * Checks if a given request has access to create an invoice. |
|
260 | + * |
|
261 | + * @since 1.0.13 |
|
262 | + * |
|
263 | + * @param WP_REST_Request $request Full details about the request. |
|
264 | + * @return true|WP_Error True if the request has access to create items, WP_Error object otherwise. |
|
265 | + */ |
|
266 | + public function create_item_permissions_check( $request ) { |
|
267 | 267 | |
268 | - if ( ! empty( $request['id'] ) ) { |
|
269 | - return new WP_Error( 'rest_invoice_exists', __( 'Cannot create existing invoice.', 'invoicing' ), array( 'status' => 400 ) ); |
|
270 | - } |
|
268 | + if ( ! empty( $request['id'] ) ) { |
|
269 | + return new WP_Error( 'rest_invoice_exists', __( 'Cannot create existing invoice.', 'invoicing' ), array( 'status' => 400 ) ); |
|
270 | + } |
|
271 | 271 | |
272 | - $post_type = get_post_type_object( $this->post_type ); |
|
272 | + $post_type = get_post_type_object( $this->post_type ); |
|
273 | 273 | |
274 | - if ( ! current_user_can( $post_type->cap->create_posts ) ) { |
|
275 | - return new WP_Error( |
|
274 | + if ( ! current_user_can( $post_type->cap->create_posts ) ) { |
|
275 | + return new WP_Error( |
|
276 | 276 | 'rest_cannot_create', |
277 | 277 | __( 'Sorry, you are not allowed to create invoices as this user.', 'invoicing' ), |
278 | 278 | array( |
@@ -281,88 +281,88 @@ discard block |
||
281 | 281 | ); |
282 | 282 | } |
283 | 283 | |
284 | - return true; |
|
284 | + return true; |
|
285 | 285 | } |
286 | 286 | |
287 | 287 | /** |
288 | - * Creates a single invoice. |
|
289 | - * |
|
290 | - * @since 1.0.13 |
|
291 | - * |
|
292 | - * @param WP_REST_Request $request Full details about the request. |
|
293 | - * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. |
|
294 | - */ |
|
295 | - public function create_item( $request ) { |
|
296 | - |
|
297 | - if ( ! empty( $request['id'] ) ) { |
|
298 | - return new WP_Error( 'rest_invoice_exists', __( 'Cannot create existing invoice.', 'invoicing' ), array( 'status' => 400 ) ); |
|
299 | - } |
|
288 | + * Creates a single invoice. |
|
289 | + * |
|
290 | + * @since 1.0.13 |
|
291 | + * |
|
292 | + * @param WP_REST_Request $request Full details about the request. |
|
293 | + * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. |
|
294 | + */ |
|
295 | + public function create_item( $request ) { |
|
296 | + |
|
297 | + if ( ! empty( $request['id'] ) ) { |
|
298 | + return new WP_Error( 'rest_invoice_exists', __( 'Cannot create existing invoice.', 'invoicing' ), array( 'status' => 400 ) ); |
|
299 | + } |
|
300 | 300 | |
301 | - $request->set_param( 'context', 'edit' ); |
|
301 | + $request->set_param( 'context', 'edit' ); |
|
302 | 302 | |
303 | - // Prepare the updated data. |
|
304 | - $invoice_data = $this->prepare_item_for_database( $request ); |
|
303 | + // Prepare the updated data. |
|
304 | + $invoice_data = $this->prepare_item_for_database( $request ); |
|
305 | 305 | |
306 | - if ( is_wp_error( $invoice_data ) ) { |
|
307 | - return $invoice_data; |
|
308 | - } |
|
306 | + if ( is_wp_error( $invoice_data ) ) { |
|
307 | + return $invoice_data; |
|
308 | + } |
|
309 | 309 | |
310 | - // Try creating the invoice |
|
310 | + // Try creating the invoice |
|
311 | 311 | $invoice = wpinv_insert_invoice( $invoice_data, true ); |
312 | 312 | |
313 | - if ( is_wp_error( $invoice ) ) { |
|
313 | + if ( is_wp_error( $invoice ) ) { |
|
314 | 314 | return $invoice; |
315 | - } |
|
316 | - |
|
317 | - // Prepare the response |
|
318 | - $response = $this->prepare_item_for_response( $invoice, $request ); |
|
319 | - |
|
320 | - /** |
|
321 | - * Fires after a single invoice is created or updated via the REST API. |
|
322 | - * |
|
323 | - * @since 1.0.13 |
|
324 | - * |
|
325 | - * @param WPinv_Invoice $invoice Inserted or updated invoice object. |
|
326 | - * @param WP_REST_Request $request Request object. |
|
327 | - * @param bool $creating True when creating a post, false when updating. |
|
328 | - */ |
|
329 | - do_action( "wpinv_rest_insert_invoice", $invoice, $request, true ); |
|
330 | - |
|
331 | - /** |
|
332 | - * Filters the responses for creating single invoice requests. |
|
333 | - * |
|
334 | - * |
|
335 | - * @since 1.0.13 |
|
336 | - * |
|
337 | - * |
|
338 | - * @param array $invoice_data Invoice properties. |
|
339 | - * @param WP_REST_Request $request The request used. |
|
340 | - */ |
|
315 | + } |
|
316 | + |
|
317 | + // Prepare the response |
|
318 | + $response = $this->prepare_item_for_response( $invoice, $request ); |
|
319 | + |
|
320 | + /** |
|
321 | + * Fires after a single invoice is created or updated via the REST API. |
|
322 | + * |
|
323 | + * @since 1.0.13 |
|
324 | + * |
|
325 | + * @param WPinv_Invoice $invoice Inserted or updated invoice object. |
|
326 | + * @param WP_REST_Request $request Request object. |
|
327 | + * @param bool $creating True when creating a post, false when updating. |
|
328 | + */ |
|
329 | + do_action( "wpinv_rest_insert_invoice", $invoice, $request, true ); |
|
330 | + |
|
331 | + /** |
|
332 | + * Filters the responses for creating single invoice requests. |
|
333 | + * |
|
334 | + * |
|
335 | + * @since 1.0.13 |
|
336 | + * |
|
337 | + * |
|
338 | + * @param array $invoice_data Invoice properties. |
|
339 | + * @param WP_REST_Request $request The request used. |
|
340 | + */ |
|
341 | 341 | $response = apply_filters( "wpinv_rest_create_invoice_response", $response, $request ); |
342 | 342 | |
343 | 343 | return rest_ensure_response( $response ); |
344 | - } |
|
345 | - |
|
346 | - /** |
|
347 | - * Checks if a given request has access to update an invoice. |
|
348 | - * |
|
349 | - * @since 1.0.13 |
|
350 | - * |
|
351 | - * @param WP_REST_Request $request Full details about the request. |
|
352 | - * @return true|WP_Error True if the request has access to update the item, WP_Error object otherwise. |
|
353 | - */ |
|
354 | - public function update_item_permissions_check( $request ) { |
|
355 | - |
|
356 | - // Retrieve the invoice. |
|
357 | - $invoice = $this->get_post( $request['id'] ); |
|
358 | - if ( is_wp_error( $invoice ) ) { |
|
359 | - return $invoice; |
|
360 | - } |
|
361 | - |
|
362 | - $post_type = get_post_type_object( $this->post_type ); |
|
363 | - |
|
364 | - if ( ! current_user_can( $post_type->cap->edit_post, $invoice->ID ) ) { |
|
365 | - return new WP_Error( |
|
344 | + } |
|
345 | + |
|
346 | + /** |
|
347 | + * Checks if a given request has access to update an invoice. |
|
348 | + * |
|
349 | + * @since 1.0.13 |
|
350 | + * |
|
351 | + * @param WP_REST_Request $request Full details about the request. |
|
352 | + * @return true|WP_Error True if the request has access to update the item, WP_Error object otherwise. |
|
353 | + */ |
|
354 | + public function update_item_permissions_check( $request ) { |
|
355 | + |
|
356 | + // Retrieve the invoice. |
|
357 | + $invoice = $this->get_post( $request['id'] ); |
|
358 | + if ( is_wp_error( $invoice ) ) { |
|
359 | + return $invoice; |
|
360 | + } |
|
361 | + |
|
362 | + $post_type = get_post_type_object( $this->post_type ); |
|
363 | + |
|
364 | + if ( ! current_user_can( $post_type->cap->edit_post, $invoice->ID ) ) { |
|
365 | + return new WP_Error( |
|
366 | 366 | 'rest_cannot_edit', |
367 | 367 | __( 'Sorry, you are not allowed to update this invoice.', 'invoicing' ), |
368 | 368 | array( |
@@ -371,162 +371,162 @@ discard block |
||
371 | 371 | ); |
372 | 372 | } |
373 | 373 | |
374 | - return true; |
|
375 | - } |
|
376 | - |
|
377 | - /** |
|
378 | - * Updates a single invoice. |
|
379 | - * |
|
380 | - * @since 1.0.13 |
|
381 | - * |
|
382 | - * @param WP_REST_Request $request Full details about the request. |
|
383 | - * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. |
|
384 | - */ |
|
385 | - public function update_item( $request ) { |
|
374 | + return true; |
|
375 | + } |
|
376 | + |
|
377 | + /** |
|
378 | + * Updates a single invoice. |
|
379 | + * |
|
380 | + * @since 1.0.13 |
|
381 | + * |
|
382 | + * @param WP_REST_Request $request Full details about the request. |
|
383 | + * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. |
|
384 | + */ |
|
385 | + public function update_item( $request ) { |
|
386 | 386 | |
387 | - // Ensure the invoice exists. |
|
387 | + // Ensure the invoice exists. |
|
388 | 388 | $valid_check = $this->get_post( $request['id'] ); |
389 | 389 | |
390 | 390 | // Abort early if it does not exist |
391 | - if ( is_wp_error( $valid_check ) ) { |
|
392 | - return $valid_check; |
|
393 | - } |
|
391 | + if ( is_wp_error( $valid_check ) ) { |
|
392 | + return $valid_check; |
|
393 | + } |
|
394 | 394 | |
395 | - $request->set_param( 'context', 'edit' ); |
|
395 | + $request->set_param( 'context', 'edit' ); |
|
396 | 396 | |
397 | - // Prepare the updated data. |
|
398 | - $data_to_update = $this->prepare_item_for_database( $request ); |
|
397 | + // Prepare the updated data. |
|
398 | + $data_to_update = $this->prepare_item_for_database( $request ); |
|
399 | 399 | |
400 | - if ( is_wp_error( $data_to_update ) ) { |
|
401 | - return $data_to_update; |
|
402 | - } |
|
400 | + if ( is_wp_error( $data_to_update ) ) { |
|
401 | + return $data_to_update; |
|
402 | + } |
|
403 | 403 | |
404 | - // Abort if no invoice data is provided |
|
404 | + // Abort if no invoice data is provided |
|
405 | 405 | if( empty( $data_to_update ) ) { |
406 | 406 | return new WP_Error( 'missing_data', __( 'An update request cannot be empty.', 'invoicing' ) ); |
407 | 407 | } |
408 | 408 | |
409 | - // Include the invoice ID |
|
410 | - $data_to_update['ID'] = $request['id']; |
|
411 | - |
|
412 | - // Update the invoice |
|
413 | - $updated_invoice = wpinv_update_invoice( $data_to_update, true ); |
|
414 | - |
|
415 | - // Incase the update operation failed... |
|
416 | - if ( is_wp_error( $updated_invoice ) ) { |
|
417 | - return $updated_invoice; |
|
418 | - } |
|
419 | - |
|
420 | - // Prepare the response |
|
421 | - $response = $this->prepare_item_for_response( $updated_invoice, $request ); |
|
422 | - |
|
423 | - /** This action is documented in includes/class-wpinv-rest-invoice-controller.php */ |
|
424 | - do_action( "wpinv_rest_insert_invoice", $updated_invoice, $request, false ); |
|
425 | - |
|
426 | - /** |
|
427 | - * Filters the responses for updating single invoice requests. |
|
428 | - * |
|
429 | - * |
|
430 | - * @since 1.0.13 |
|
431 | - * |
|
432 | - * |
|
433 | - * @param array $invoice_data Invoice properties. |
|
434 | - * @param WP_REST_Request $request The request used. |
|
435 | - */ |
|
409 | + // Include the invoice ID |
|
410 | + $data_to_update['ID'] = $request['id']; |
|
411 | + |
|
412 | + // Update the invoice |
|
413 | + $updated_invoice = wpinv_update_invoice( $data_to_update, true ); |
|
414 | + |
|
415 | + // Incase the update operation failed... |
|
416 | + if ( is_wp_error( $updated_invoice ) ) { |
|
417 | + return $updated_invoice; |
|
418 | + } |
|
419 | + |
|
420 | + // Prepare the response |
|
421 | + $response = $this->prepare_item_for_response( $updated_invoice, $request ); |
|
422 | + |
|
423 | + /** This action is documented in includes/class-wpinv-rest-invoice-controller.php */ |
|
424 | + do_action( "wpinv_rest_insert_invoice", $updated_invoice, $request, false ); |
|
425 | + |
|
426 | + /** |
|
427 | + * Filters the responses for updating single invoice requests. |
|
428 | + * |
|
429 | + * |
|
430 | + * @since 1.0.13 |
|
431 | + * |
|
432 | + * |
|
433 | + * @param array $invoice_data Invoice properties. |
|
434 | + * @param WP_REST_Request $request The request used. |
|
435 | + */ |
|
436 | 436 | $response = apply_filters( "wpinv_rest_update_invoice_response", $response, $request ); |
437 | 437 | |
438 | 438 | return rest_ensure_response( $response ); |
439 | - } |
|
440 | - |
|
441 | - /** |
|
442 | - * Checks if a given request has access to delete an invoice. |
|
443 | - * |
|
444 | - * @since 1.0.13 |
|
445 | - * |
|
446 | - * @param WP_REST_Request $request Full details about the request. |
|
447 | - * @return true|WP_Error True if the request has access to delete the invoice, WP_Error object otherwise. |
|
448 | - */ |
|
449 | - public function delete_item_permissions_check( $request ) { |
|
450 | - |
|
451 | - // Retrieve the invoice. |
|
452 | - $invoice = $this->get_post( $request['id'] ); |
|
453 | - if ( is_wp_error( $invoice ) ) { |
|
454 | - return $invoice; |
|
455 | - } |
|
456 | - |
|
457 | - // Ensure the current user can delete invoices |
|
458 | - if ( wpinv_current_user_can_manage_invoicing() || current_user_can( 'delete_invoices', $request['id'] ) ) { |
|
459 | - return new WP_Error( |
|
439 | + } |
|
440 | + |
|
441 | + /** |
|
442 | + * Checks if a given request has access to delete an invoice. |
|
443 | + * |
|
444 | + * @since 1.0.13 |
|
445 | + * |
|
446 | + * @param WP_REST_Request $request Full details about the request. |
|
447 | + * @return true|WP_Error True if the request has access to delete the invoice, WP_Error object otherwise. |
|
448 | + */ |
|
449 | + public function delete_item_permissions_check( $request ) { |
|
450 | + |
|
451 | + // Retrieve the invoice. |
|
452 | + $invoice = $this->get_post( $request['id'] ); |
|
453 | + if ( is_wp_error( $invoice ) ) { |
|
454 | + return $invoice; |
|
455 | + } |
|
456 | + |
|
457 | + // Ensure the current user can delete invoices |
|
458 | + if ( wpinv_current_user_can_manage_invoicing() || current_user_can( 'delete_invoices', $request['id'] ) ) { |
|
459 | + return new WP_Error( |
|
460 | 460 | 'rest_cannot_delete', |
461 | 461 | __( 'Sorry, you are not allowed to delete this invoice.', 'invoicing' ), |
462 | 462 | array( |
463 | 463 | 'status' => rest_authorization_required_code(), |
464 | 464 | ) |
465 | 465 | ); |
466 | - } |
|
467 | - |
|
468 | - return true; |
|
469 | - } |
|
470 | - |
|
471 | - /** |
|
472 | - * Deletes a single invoice. |
|
473 | - * |
|
474 | - * @since 1.0.13 |
|
475 | - * |
|
476 | - * @param WP_REST_Request $request Full details about the request. |
|
477 | - * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. |
|
478 | - */ |
|
479 | - public function delete_item( $request ) { |
|
466 | + } |
|
467 | + |
|
468 | + return true; |
|
469 | + } |
|
470 | + |
|
471 | + /** |
|
472 | + * Deletes a single invoice. |
|
473 | + * |
|
474 | + * @since 1.0.13 |
|
475 | + * |
|
476 | + * @param WP_REST_Request $request Full details about the request. |
|
477 | + * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. |
|
478 | + */ |
|
479 | + public function delete_item( $request ) { |
|
480 | 480 | |
481 | - // Retrieve the invoice. |
|
482 | - $invoice = $this->get_post( $request['id'] ); |
|
483 | - if ( is_wp_error( $invoice ) ) { |
|
484 | - return $invoice; |
|
485 | - } |
|
481 | + // Retrieve the invoice. |
|
482 | + $invoice = $this->get_post( $request['id'] ); |
|
483 | + if ( is_wp_error( $invoice ) ) { |
|
484 | + return $invoice; |
|
485 | + } |
|
486 | 486 | |
487 | - $request->set_param( 'context', 'edit' ); |
|
487 | + $request->set_param( 'context', 'edit' ); |
|
488 | 488 | |
489 | - // Prepare the invoice id |
|
490 | - $id = $invoice->ID; |
|
489 | + // Prepare the invoice id |
|
490 | + $id = $invoice->ID; |
|
491 | 491 | |
492 | - // Prepare the response |
|
493 | - $response = $this->prepare_item_for_response( $invoice, $request ); |
|
492 | + // Prepare the response |
|
493 | + $response = $this->prepare_item_for_response( $invoice, $request ); |
|
494 | 494 | |
495 | - // Check if the user wants to bypass the trash... |
|
496 | - $force_delete = (bool) $request['force']; |
|
495 | + // Check if the user wants to bypass the trash... |
|
496 | + $force_delete = (bool) $request['force']; |
|
497 | 497 | |
498 | - // Try deleting the invoice. |
|
499 | - $deleted = wp_delete_post( $id, $force_delete ); |
|
498 | + // Try deleting the invoice. |
|
499 | + $deleted = wp_delete_post( $id, $force_delete ); |
|
500 | 500 | |
501 | - // Abort early if we can't delete the invoice. |
|
502 | - if ( ! $deleted ) { |
|
503 | - return new WP_Error( 'rest_cannot_delete', __( 'The invoice cannot be deleted.', 'invoicing' ), array( 'status' => 500 ) ); |
|
504 | - } |
|
501 | + // Abort early if we can't delete the invoice. |
|
502 | + if ( ! $deleted ) { |
|
503 | + return new WP_Error( 'rest_cannot_delete', __( 'The invoice cannot be deleted.', 'invoicing' ), array( 'status' => 500 ) ); |
|
504 | + } |
|
505 | 505 | |
506 | - /** |
|
507 | - * Fires immediately after a single invoice is deleted or trashed via the REST API. |
|
508 | - * |
|
509 | - * |
|
510 | - * @since 1.0.13 |
|
511 | - * |
|
512 | - * @param WPInv_Invoice $invoice The deleted or trashed invoice. |
|
513 | - * @param WP_REST_Request $request The request sent to the API. |
|
514 | - */ |
|
515 | - do_action( "wpinv_rest_delete_invoice", $invoice, $request ); |
|
506 | + /** |
|
507 | + * Fires immediately after a single invoice is deleted or trashed via the REST API. |
|
508 | + * |
|
509 | + * |
|
510 | + * @since 1.0.13 |
|
511 | + * |
|
512 | + * @param WPInv_Invoice $invoice The deleted or trashed invoice. |
|
513 | + * @param WP_REST_Request $request The request sent to the API. |
|
514 | + */ |
|
515 | + do_action( "wpinv_rest_delete_invoice", $invoice, $request ); |
|
516 | 516 | |
517 | - return $response; |
|
517 | + return $response; |
|
518 | 518 | |
519 | - } |
|
519 | + } |
|
520 | 520 | |
521 | 521 | |
522 | 522 | /** |
523 | - * Retrieves the query params for the invoices collection. |
|
524 | - * |
|
525 | - * @since 1.0.13 |
|
526 | - * |
|
527 | - * @return array Collection parameters. |
|
528 | - */ |
|
529 | - public function get_collection_params() { |
|
523 | + * Retrieves the query params for the invoices collection. |
|
524 | + * |
|
525 | + * @since 1.0.13 |
|
526 | + * |
|
527 | + * @return array Collection parameters. |
|
528 | + */ |
|
529 | + public function get_collection_params() { |
|
530 | 530 | |
531 | 531 | $query_params = array( |
532 | 532 | |
@@ -544,22 +544,22 @@ discard block |
||
544 | 544 | |
545 | 545 | // User. |
546 | 546 | 'user' => array( |
547 | - 'description' => __( 'Limit result set to invoices for a specif user.', 'invoicing' ), |
|
548 | - 'type' => 'integer', |
|
547 | + 'description' => __( 'Limit result set to invoices for a specif user.', 'invoicing' ), |
|
548 | + 'type' => 'integer', |
|
549 | 549 | ), |
550 | 550 | |
551 | 551 | // Number of results per page |
552 | 552 | 'limit' => array( |
553 | - 'description' => __( 'Number of invoices to fetch.', 'invoicing' ), |
|
554 | - 'type' => 'integer', |
|
555 | - 'default' => (int) get_option( 'posts_per_page' ), |
|
553 | + 'description' => __( 'Number of invoices to fetch.', 'invoicing' ), |
|
554 | + 'type' => 'integer', |
|
555 | + 'default' => (int) get_option( 'posts_per_page' ), |
|
556 | 556 | ), |
557 | 557 | |
558 | 558 | // Pagination |
559 | 559 | 'page' => array( |
560 | - 'description' => __( 'Current page to fetch.', 'invoicing' ), |
|
561 | - 'type' => 'integer', |
|
562 | - 'default' => 1, |
|
560 | + 'description' => __( 'Current page to fetch.', 'invoicing' ), |
|
561 | + 'type' => 'integer', |
|
562 | + 'default' => 1, |
|
563 | 563 | ), |
564 | 564 | |
565 | 565 | // Exclude certain invoices |
@@ -595,789 +595,789 @@ discard block |
||
595 | 595 | ), |
596 | 596 | ); |
597 | 597 | |
598 | - /** |
|
599 | - * Filter collection parameters for the invoices controller. |
|
600 | - * |
|
601 | - * |
|
602 | - * @since 1.0.13 |
|
603 | - * |
|
604 | - * @param array $query_params JSON Schema-formatted collection parameters. |
|
605 | - */ |
|
606 | - return apply_filters( "wpinv_rest_invoices_collection_params", $query_params ); |
|
598 | + /** |
|
599 | + * Filter collection parameters for the invoices controller. |
|
600 | + * |
|
601 | + * |
|
602 | + * @since 1.0.13 |
|
603 | + * |
|
604 | + * @param array $query_params JSON Schema-formatted collection parameters. |
|
605 | + */ |
|
606 | + return apply_filters( "wpinv_rest_invoices_collection_params", $query_params ); |
|
607 | 607 | } |
608 | 608 | |
609 | 609 | /** |
610 | - * Checks if a given post type can be viewed or managed. |
|
611 | - * |
|
612 | - * @since 1.0.13 |
|
613 | - * |
|
614 | - * @param object|string $post_type Post type name or object. |
|
615 | - * @return bool Whether the post type is allowed in REST. |
|
616 | - */ |
|
617 | - protected function check_is_post_type_allowed( $post_type ) { |
|
618 | - return true; |
|
619 | - } |
|
620 | - |
|
621 | - /** |
|
622 | - * Prepares a single invoice for create or update. |
|
623 | - * |
|
624 | - * @since 1.0.13 |
|
625 | - * |
|
626 | - * @param WP_REST_Request $request Request object. |
|
627 | - * @return array|WP_Error Invoice Properties or WP_Error. |
|
628 | - */ |
|
629 | - protected function prepare_item_for_database( $request ) { |
|
630 | - $prepared_invoice = new stdClass(); |
|
631 | - |
|
632 | - // Post ID. |
|
633 | - if ( isset( $request['id'] ) ) { |
|
634 | - $existing_invoice = $this->get_post( $request['id'] ); |
|
635 | - if ( is_wp_error( $existing_invoice ) ) { |
|
636 | - return $existing_invoice; |
|
637 | - } |
|
638 | - |
|
639 | - $prepared_invoice->ID = $existing_invoice->ID; |
|
640 | - $prepared_invoice->invoice_id = $existing_invoice->ID; |
|
641 | - } |
|
642 | - |
|
643 | - $schema = $this->get_item_schema(); |
|
644 | - |
|
645 | - // Invoice owner. |
|
646 | - if ( ! empty( $schema['properties']['user_id'] ) && isset( $request['user_id'] ) ) { |
|
647 | - $prepared_invoice->user_id = (int) $request['user_id']; |
|
648 | - } |
|
649 | - |
|
650 | - // Cart details. |
|
651 | - if ( ! empty( $schema['properties']['cart_details'] ) && isset( $request['cart_details'] ) ) { |
|
652 | - $prepared_invoice->cart_details = (array) $request['cart_details']; |
|
653 | - } |
|
654 | - |
|
655 | - // Invoice status. |
|
656 | - if ( ! empty( $schema['properties']['status'] ) && isset( $request['status'] ) ) { |
|
657 | - |
|
658 | - if ( in_array( $request['status'], array_keys( wpinv_get_invoice_statuses( true, true ) ), true ) ) { |
|
659 | - $prepared_invoice->status = $request['status']; |
|
660 | - } |
|
661 | - |
|
662 | - } |
|
663 | - |
|
664 | - // User info |
|
665 | - if ( ! empty( $schema['properties']['user_info'] ) && isset( $request['user_info'] ) ) { |
|
666 | - $prepared_invoice->user_info = array(); |
|
667 | - $user_info = (array) $request['user_info']; |
|
668 | - |
|
669 | - foreach( $user_info as $prop => $value ) { |
|
670 | - |
|
671 | - if ( ! empty( $schema['properties']['user_info']['properties'][$prop] ) ) { |
|
672 | - |
|
673 | - $prepared_invoice->user_info[$prop] = $value; |
|
610 | + * Checks if a given post type can be viewed or managed. |
|
611 | + * |
|
612 | + * @since 1.0.13 |
|
613 | + * |
|
614 | + * @param object|string $post_type Post type name or object. |
|
615 | + * @return bool Whether the post type is allowed in REST. |
|
616 | + */ |
|
617 | + protected function check_is_post_type_allowed( $post_type ) { |
|
618 | + return true; |
|
619 | + } |
|
620 | + |
|
621 | + /** |
|
622 | + * Prepares a single invoice for create or update. |
|
623 | + * |
|
624 | + * @since 1.0.13 |
|
625 | + * |
|
626 | + * @param WP_REST_Request $request Request object. |
|
627 | + * @return array|WP_Error Invoice Properties or WP_Error. |
|
628 | + */ |
|
629 | + protected function prepare_item_for_database( $request ) { |
|
630 | + $prepared_invoice = new stdClass(); |
|
631 | + |
|
632 | + // Post ID. |
|
633 | + if ( isset( $request['id'] ) ) { |
|
634 | + $existing_invoice = $this->get_post( $request['id'] ); |
|
635 | + if ( is_wp_error( $existing_invoice ) ) { |
|
636 | + return $existing_invoice; |
|
637 | + } |
|
638 | + |
|
639 | + $prepared_invoice->ID = $existing_invoice->ID; |
|
640 | + $prepared_invoice->invoice_id = $existing_invoice->ID; |
|
641 | + } |
|
642 | + |
|
643 | + $schema = $this->get_item_schema(); |
|
644 | + |
|
645 | + // Invoice owner. |
|
646 | + if ( ! empty( $schema['properties']['user_id'] ) && isset( $request['user_id'] ) ) { |
|
647 | + $prepared_invoice->user_id = (int) $request['user_id']; |
|
648 | + } |
|
649 | + |
|
650 | + // Cart details. |
|
651 | + if ( ! empty( $schema['properties']['cart_details'] ) && isset( $request['cart_details'] ) ) { |
|
652 | + $prepared_invoice->cart_details = (array) $request['cart_details']; |
|
653 | + } |
|
654 | + |
|
655 | + // Invoice status. |
|
656 | + if ( ! empty( $schema['properties']['status'] ) && isset( $request['status'] ) ) { |
|
657 | + |
|
658 | + if ( in_array( $request['status'], array_keys( wpinv_get_invoice_statuses( true, true ) ), true ) ) { |
|
659 | + $prepared_invoice->status = $request['status']; |
|
660 | + } |
|
661 | + |
|
662 | + } |
|
663 | + |
|
664 | + // User info |
|
665 | + if ( ! empty( $schema['properties']['user_info'] ) && isset( $request['user_info'] ) ) { |
|
666 | + $prepared_invoice->user_info = array(); |
|
667 | + $user_info = (array) $request['user_info']; |
|
668 | + |
|
669 | + foreach( $user_info as $prop => $value ) { |
|
670 | + |
|
671 | + if ( ! empty( $schema['properties']['user_info']['properties'][$prop] ) ) { |
|
672 | + |
|
673 | + $prepared_invoice->user_info[$prop] = $value; |
|
674 | 674 | |
675 | - } |
|
675 | + } |
|
676 | 676 | |
677 | - } |
|
677 | + } |
|
678 | 678 | |
679 | - } |
|
679 | + } |
|
680 | 680 | |
681 | - // IP |
|
682 | - if ( ! empty( $schema['properties']['ip'] ) && isset( $request['ip'] ) ) { |
|
683 | - $prepared_invoice->ip = $request['ip']; |
|
684 | - } |
|
681 | + // IP |
|
682 | + if ( ! empty( $schema['properties']['ip'] ) && isset( $request['ip'] ) ) { |
|
683 | + $prepared_invoice->ip = $request['ip']; |
|
684 | + } |
|
685 | 685 | |
686 | - // Payment details |
|
687 | - $prepared_invoice->payment_details = array(); |
|
686 | + // Payment details |
|
687 | + $prepared_invoice->payment_details = array(); |
|
688 | 688 | |
689 | - if ( ! empty( $schema['properties']['gateway'] ) && isset( $request['gateway'] ) ) { |
|
690 | - $prepared_invoice->payment_details['gateway'] = $request['gateway']; |
|
691 | - } |
|
689 | + if ( ! empty( $schema['properties']['gateway'] ) && isset( $request['gateway'] ) ) { |
|
690 | + $prepared_invoice->payment_details['gateway'] = $request['gateway']; |
|
691 | + } |
|
692 | 692 | |
693 | - if ( ! empty( $schema['properties']['gateway_title'] ) && isset( $request['gateway_title'] ) ) { |
|
694 | - $prepared_invoice->payment_details['gateway_title'] = $request['gateway_title']; |
|
695 | - } |
|
693 | + if ( ! empty( $schema['properties']['gateway_title'] ) && isset( $request['gateway_title'] ) ) { |
|
694 | + $prepared_invoice->payment_details['gateway_title'] = $request['gateway_title']; |
|
695 | + } |
|
696 | 696 | |
697 | - if ( ! empty( $schema['properties']['currency'] ) && isset( $request['currency'] ) ) { |
|
698 | - $prepared_invoice->payment_details['currency'] = $request['currency']; |
|
699 | - } |
|
697 | + if ( ! empty( $schema['properties']['currency'] ) && isset( $request['currency'] ) ) { |
|
698 | + $prepared_invoice->payment_details['currency'] = $request['currency']; |
|
699 | + } |
|
700 | 700 | |
701 | - if ( ! empty( $schema['properties']['transaction_id'] ) && isset( $request['transaction_id'] ) ) { |
|
702 | - $prepared_invoice->payment_details['transaction_id'] = $request['transaction_id']; |
|
703 | - } |
|
701 | + if ( ! empty( $schema['properties']['transaction_id'] ) && isset( $request['transaction_id'] ) ) { |
|
702 | + $prepared_invoice->payment_details['transaction_id'] = $request['transaction_id']; |
|
703 | + } |
|
704 | 704 | |
705 | - // Dates |
|
706 | - if ( ! empty( $schema['properties']['date'] ) && isset( $request['date'] ) ) { |
|
707 | - $post_date = rest_get_date_with_gmt( $request['date'] ); |
|
705 | + // Dates |
|
706 | + if ( ! empty( $schema['properties']['date'] ) && isset( $request['date'] ) ) { |
|
707 | + $post_date = rest_get_date_with_gmt( $request['date'] ); |
|
708 | 708 | |
709 | - if ( ! empty( $post_date ) ) { |
|
710 | - $prepared_invoice->post_date = $post_date[0]; |
|
711 | - } |
|
709 | + if ( ! empty( $post_date ) ) { |
|
710 | + $prepared_invoice->post_date = $post_date[0]; |
|
711 | + } |
|
712 | 712 | |
713 | - } |
|
713 | + } |
|
714 | 714 | |
715 | - if ( ! empty( $schema['properties']['due_date'] ) && isset( $request['due_date'] ) ) { |
|
716 | - $due_date = rest_get_date_with_gmt( $request['due_date'] ); |
|
715 | + if ( ! empty( $schema['properties']['due_date'] ) && isset( $request['due_date'] ) ) { |
|
716 | + $due_date = rest_get_date_with_gmt( $request['due_date'] ); |
|
717 | 717 | |
718 | - if ( ! empty( $due_date ) ) { |
|
719 | - $prepared_invoice->due_date = $due_date[0]; |
|
720 | - } |
|
718 | + if ( ! empty( $due_date ) ) { |
|
719 | + $prepared_invoice->due_date = $due_date[0]; |
|
720 | + } |
|
721 | 721 | |
722 | - } |
|
722 | + } |
|
723 | 723 | |
724 | - $invoice_data = (array) wp_unslash( $prepared_invoice ); |
|
724 | + $invoice_data = (array) wp_unslash( $prepared_invoice ); |
|
725 | 725 | |
726 | - /** |
|
727 | - * Filters an invoice before it is inserted via the REST API. |
|
728 | - * |
|
729 | - * @since 1.0.13 |
|
730 | - * |
|
731 | - * @param array $invoice_data An array of invoice data |
|
732 | - * @param WP_REST_Request $request Request object. |
|
733 | - */ |
|
734 | - return apply_filters( "wpinv_rest_pre_insert_invoice", $invoice_data, $request ); |
|
726 | + /** |
|
727 | + * Filters an invoice before it is inserted via the REST API. |
|
728 | + * |
|
729 | + * @since 1.0.13 |
|
730 | + * |
|
731 | + * @param array $invoice_data An array of invoice data |
|
732 | + * @param WP_REST_Request $request Request object. |
|
733 | + */ |
|
734 | + return apply_filters( "wpinv_rest_pre_insert_invoice", $invoice_data, $request ); |
|
735 | 735 | |
736 | - } |
|
736 | + } |
|
737 | + |
|
738 | + /** |
|
739 | + * Prepares a single invoice output for response. |
|
740 | + * |
|
741 | + * @since 1.0.13 |
|
742 | + * |
|
743 | + * @param WPInv_Invoice $invoice Invoice object. |
|
744 | + * @param WP_REST_Request $request Request object. |
|
745 | + * @return WP_REST_Response Response object. |
|
746 | + */ |
|
747 | + public function prepare_item_for_response( $invoice, $request ) { |
|
737 | 748 | |
738 | - /** |
|
739 | - * Prepares a single invoice output for response. |
|
740 | - * |
|
741 | - * @since 1.0.13 |
|
742 | - * |
|
743 | - * @param WPInv_Invoice $invoice Invoice object. |
|
744 | - * @param WP_REST_Request $request Request object. |
|
745 | - * @return WP_REST_Response Response object. |
|
746 | - */ |
|
747 | - public function prepare_item_for_response( $invoice, $request ) { |
|
749 | + $GLOBALS['post'] = get_post( $invoice->ID ); |
|
748 | 750 | |
749 | - $GLOBALS['post'] = get_post( $invoice->ID ); |
|
751 | + setup_postdata( $invoice->ID ); |
|
750 | 752 | |
751 | - setup_postdata( $invoice->ID ); |
|
753 | + // Fetch the fields to include in this response. |
|
754 | + $fields = $this->get_fields_for_response( $request ); |
|
752 | 755 | |
753 | - // Fetch the fields to include in this response. |
|
754 | - $fields = $this->get_fields_for_response( $request ); |
|
756 | + // Base fields for every invoice. |
|
757 | + $data = array(); |
|
758 | + |
|
759 | + // Set up ID |
|
760 | + if ( rest_is_field_included( 'id', $fields ) ) { |
|
761 | + $data['id'] = $invoice->ID; |
|
762 | + } |
|
763 | + |
|
764 | + |
|
765 | + // Basic properties |
|
766 | + $invoice_properties = array( |
|
767 | + 'title', 'email', 'ip', |
|
768 | + 'key', 'number', 'transaction_id', 'mode', |
|
769 | + 'gateway', 'gateway_title', |
|
770 | + 'total', 'discount', 'discount_code', |
|
771 | + 'tax', 'fees_total', 'subtotal', 'currency', |
|
772 | + 'status', 'status_nicename', 'post_type' |
|
773 | + ); |
|
774 | + |
|
775 | + foreach( $invoice_properties as $property ) { |
|
776 | + |
|
777 | + if ( rest_is_field_included( $property, $fields ) ) { |
|
778 | + $data[$property] = $invoice->get( $property ); |
|
779 | + } |
|
780 | + |
|
781 | + } |
|
782 | + |
|
783 | + // Cart details |
|
784 | + if ( rest_is_field_included( 'cart_details', $fields ) ) { |
|
785 | + $data['cart_details'] = $invoice->get( 'cart_details' ); |
|
786 | + } |
|
787 | + |
|
788 | + //Dates |
|
789 | + $invoice_properties = array( 'date', 'due_date', 'completed_date' ); |
|
790 | + |
|
791 | + foreach( $invoice_properties as $property ) { |
|
792 | + |
|
793 | + if ( rest_is_field_included( $property, $fields ) ) { |
|
794 | + $data[$property] = $this->prepare_date_response( '0000-00-00 00:00:00', $invoice->get( $property ) ); |
|
795 | + } |
|
796 | + |
|
797 | + } |
|
798 | + |
|
799 | + // User id |
|
800 | + if ( rest_is_field_included( 'user_id', $fields ) ) { |
|
801 | + $data['user_id'] = (int) $invoice->get( 'user_id' ); |
|
802 | + } |
|
803 | + |
|
804 | + // User info |
|
805 | + $user_info = array( 'first_name', 'last_name', 'company', 'vat_number', 'vat_rate', 'address', 'city', 'country', 'state', 'zip', 'phone' ); |
|
806 | + |
|
807 | + foreach( $user_info as $property ) { |
|
808 | + |
|
809 | + if ( rest_is_field_included( "user_info.$property", $fields ) ) { |
|
810 | + $data['user_info'][$property] = $invoice->get( $property ); |
|
811 | + } |
|
812 | + |
|
813 | + } |
|
814 | + |
|
815 | + // Slug |
|
816 | + if ( rest_is_field_included( 'slug', $fields ) ) { |
|
817 | + $data['slug'] = $invoice->get( 'post_name' ); |
|
818 | + } |
|
819 | + |
|
820 | + // View invoice link |
|
821 | + if ( rest_is_field_included( 'link', $fields ) ) { |
|
822 | + $data['link'] = esc_url( $invoice->get_view_url() ); |
|
823 | + } |
|
755 | 824 | |
756 | - // Base fields for every invoice. |
|
757 | - $data = array(); |
|
758 | 825 | |
759 | - // Set up ID |
|
760 | - if ( rest_is_field_included( 'id', $fields ) ) { |
|
761 | - $data['id'] = $invoice->ID; |
|
762 | - } |
|
826 | + $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
827 | + $data = $this->add_additional_fields_to_object( $data, $request ); |
|
828 | + $data = $this->filter_response_by_context( $data, $context ); |
|
763 | 829 | |
830 | + // Wrap the data in a response object. |
|
831 | + $response = rest_ensure_response( $data ); |
|
764 | 832 | |
765 | - // Basic properties |
|
766 | - $invoice_properties = array( |
|
767 | - 'title', 'email', 'ip', |
|
768 | - 'key', 'number', 'transaction_id', 'mode', |
|
769 | - 'gateway', 'gateway_title', |
|
770 | - 'total', 'discount', 'discount_code', |
|
771 | - 'tax', 'fees_total', 'subtotal', 'currency', |
|
772 | - 'status', 'status_nicename', 'post_type' |
|
773 | - ); |
|
774 | - |
|
775 | - foreach( $invoice_properties as $property ) { |
|
776 | - |
|
777 | - if ( rest_is_field_included( $property, $fields ) ) { |
|
778 | - $data[$property] = $invoice->get( $property ); |
|
779 | - } |
|
780 | - |
|
781 | - } |
|
782 | - |
|
783 | - // Cart details |
|
784 | - if ( rest_is_field_included( 'cart_details', $fields ) ) { |
|
785 | - $data['cart_details'] = $invoice->get( 'cart_details' ); |
|
786 | - } |
|
787 | - |
|
788 | - //Dates |
|
789 | - $invoice_properties = array( 'date', 'due_date', 'completed_date' ); |
|
790 | - |
|
791 | - foreach( $invoice_properties as $property ) { |
|
792 | - |
|
793 | - if ( rest_is_field_included( $property, $fields ) ) { |
|
794 | - $data[$property] = $this->prepare_date_response( '0000-00-00 00:00:00', $invoice->get( $property ) ); |
|
795 | - } |
|
796 | - |
|
797 | - } |
|
798 | - |
|
799 | - // User id |
|
800 | - if ( rest_is_field_included( 'user_id', $fields ) ) { |
|
801 | - $data['user_id'] = (int) $invoice->get( 'user_id' ); |
|
802 | - } |
|
803 | - |
|
804 | - // User info |
|
805 | - $user_info = array( 'first_name', 'last_name', 'company', 'vat_number', 'vat_rate', 'address', 'city', 'country', 'state', 'zip', 'phone' ); |
|
806 | - |
|
807 | - foreach( $user_info as $property ) { |
|
808 | - |
|
809 | - if ( rest_is_field_included( "user_info.$property", $fields ) ) { |
|
810 | - $data['user_info'][$property] = $invoice->get( $property ); |
|
811 | - } |
|
812 | - |
|
813 | - } |
|
814 | - |
|
815 | - // Slug |
|
816 | - if ( rest_is_field_included( 'slug', $fields ) ) { |
|
817 | - $data['slug'] = $invoice->get( 'post_name' ); |
|
818 | - } |
|
819 | - |
|
820 | - // View invoice link |
|
821 | - if ( rest_is_field_included( 'link', $fields ) ) { |
|
822 | - $data['link'] = esc_url( $invoice->get_view_url() ); |
|
823 | - } |
|
824 | - |
|
825 | - |
|
826 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
827 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
828 | - $data = $this->filter_response_by_context( $data, $context ); |
|
829 | - |
|
830 | - // Wrap the data in a response object. |
|
831 | - $response = rest_ensure_response( $data ); |
|
832 | - |
|
833 | - $links = $this->prepare_links( $invoice ); |
|
834 | - $response->add_links( $links ); |
|
835 | - |
|
836 | - if ( ! empty( $links['self']['href'] ) ) { |
|
837 | - $actions = $this->get_available_actions( $invoice, $request ); |
|
838 | - |
|
839 | - $self = $links['self']['href']; |
|
840 | - |
|
841 | - foreach ( $actions as $rel ) { |
|
842 | - $response->add_link( $rel, $self ); |
|
843 | - } |
|
844 | - } |
|
845 | - |
|
846 | - /** |
|
847 | - * Filters the invoice data for a response. |
|
848 | - * |
|
849 | - * @since 1.0.13 |
|
850 | - * |
|
851 | - * @param WP_REST_Response $response The response object. |
|
852 | - * @param WPInv_Invoice $invoice The invoice object. |
|
853 | - * @param WP_REST_Request $request Request object. |
|
854 | - */ |
|
855 | - return apply_filters( "wpinv_rest_prepare_invoice", $response, $invoice, $request ); |
|
856 | - } |
|
857 | - |
|
858 | - /** |
|
859 | - * Gets an array of fields to be included on the response. |
|
860 | - * |
|
861 | - * Included fields are based on item schema and `_fields=` request argument. |
|
862 | - * |
|
863 | - * @since 1.0.13 |
|
864 | - * |
|
865 | - * @param WP_REST_Request $request Full details about the request. |
|
866 | - * @return array Fields to be included in the response. |
|
867 | - */ |
|
868 | - public function get_fields_for_response( $request ) { |
|
869 | - $schema = $this->get_item_schema(); |
|
870 | - $properties = isset( $schema['properties'] ) ? $schema['properties'] : array(); |
|
871 | - |
|
872 | - $additional_fields = $this->get_additional_fields(); |
|
873 | - foreach ( $additional_fields as $field_name => $field_options ) { |
|
874 | - // For back-compat, include any field with an empty schema |
|
875 | - // because it won't be present in $this->get_item_schema(). |
|
876 | - if ( is_null( $field_options['schema'] ) ) { |
|
877 | - $properties[ $field_name ] = $field_options; |
|
878 | - } |
|
879 | - } |
|
880 | - |
|
881 | - // Exclude fields that specify a different context than the request context. |
|
882 | - $context = $request['context']; |
|
883 | - if ( $context ) { |
|
884 | - foreach ( $properties as $name => $options ) { |
|
885 | - if ( ! empty( $options['context'] ) && ! in_array( $context, $options['context'], true ) ) { |
|
886 | - unset( $properties[ $name ] ); |
|
887 | - } |
|
888 | - } |
|
889 | - } |
|
890 | - |
|
891 | - $fields = array_keys( $properties ); |
|
892 | - |
|
893 | - if ( ! isset( $request['_fields'] ) ) { |
|
894 | - return $fields; |
|
895 | - } |
|
896 | - $requested_fields = wpinv_parse_list( $request['_fields'] ); |
|
897 | - if ( 0 === count( $requested_fields ) ) { |
|
898 | - return $fields; |
|
899 | - } |
|
900 | - // Trim off outside whitespace from the comma delimited list. |
|
901 | - $requested_fields = array_map( 'trim', $requested_fields ); |
|
902 | - // Always persist 'id', because it can be needed for add_additional_fields_to_object(). |
|
903 | - if ( in_array( 'id', $fields, true ) ) { |
|
904 | - $requested_fields[] = 'id'; |
|
905 | - } |
|
906 | - // Return the list of all requested fields which appear in the schema. |
|
907 | - return array_reduce( |
|
908 | - $requested_fields, |
|
909 | - function( $response_fields, $field ) use ( $fields ) { |
|
910 | - if ( in_array( $field, $fields, true ) ) { |
|
911 | - $response_fields[] = $field; |
|
912 | - return $response_fields; |
|
913 | - } |
|
914 | - // Check for nested fields if $field is not a direct match. |
|
915 | - $nested_fields = explode( '.', $field ); |
|
916 | - // A nested field is included so long as its top-level property is |
|
917 | - // present in the schema. |
|
918 | - if ( in_array( $nested_fields[0], $fields, true ) ) { |
|
919 | - $response_fields[] = $field; |
|
920 | - } |
|
921 | - return $response_fields; |
|
922 | - }, |
|
923 | - array() |
|
924 | - ); |
|
925 | - } |
|
926 | - |
|
927 | - /** |
|
928 | - * Retrieves the invoice's schema, conforming to JSON Schema. |
|
929 | - * |
|
930 | - * @since 1.0.13 |
|
931 | - * |
|
932 | - * @return array Invoice schema data. |
|
933 | - */ |
|
934 | - public function get_item_schema() { |
|
935 | - |
|
936 | - // Maybe retrieve the schema from cache. |
|
937 | - if ( $this->schema ) { |
|
938 | - return $this->add_additional_fields_schema( $this->schema ); |
|
939 | - } |
|
940 | - |
|
941 | - $schema = array( |
|
942 | - '$schema' => 'http://json-schema.org/draft-04/schema#', |
|
943 | - 'title' => $this->post_type, |
|
944 | - 'type' => 'object', |
|
945 | - |
|
946 | - // Base properties for every Invoice. |
|
947 | - 'properties' => array( |
|
948 | - |
|
949 | - 'title' => array( |
|
950 | - 'description' => __( 'The title for the invoice.', 'invoicing' ), |
|
951 | - 'type' => 'string', |
|
952 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
953 | - 'readonly' => true, |
|
954 | - ), |
|
955 | - |
|
956 | - 'user_id' => array( |
|
957 | - 'description' => __( 'The ID of the owner of the invoice.', 'invoicing' ), |
|
958 | - 'type' => 'integer', |
|
959 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
960 | - ), |
|
961 | - |
|
962 | - 'email' => array( |
|
963 | - 'description' => __( 'The email of the owner of the invoice.', 'invoicing' ), |
|
964 | - 'type' => 'string', |
|
965 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
966 | - 'readonly' => true, |
|
967 | - ), |
|
968 | - |
|
969 | - 'ip' => array( |
|
970 | - 'description' => __( 'The IP of the owner of the invoice.', 'invoicing' ), |
|
971 | - 'type' => 'string', |
|
972 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
973 | - ), |
|
974 | - |
|
975 | - 'user_info' => array( |
|
976 | - 'description' => __( 'Information about the owner of the invoice.', 'invoicing' ), |
|
977 | - 'type' => 'object', |
|
978 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
979 | - 'properties' => array( |
|
980 | - |
|
981 | - 'first_name' => array( |
|
982 | - 'description' => __( 'The first name of the owner of the invoice.', 'invoicing' ), |
|
983 | - 'type' => 'string', |
|
984 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
985 | - ), |
|
986 | - |
|
987 | - 'last_name' => array( |
|
988 | - 'description' => __( 'The last name of the owner of the invoice.', 'invoicing' ), |
|
989 | - 'type' => 'string', |
|
990 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
991 | - ), |
|
992 | - |
|
993 | - 'company' => array( |
|
994 | - 'description' => __( 'The company of the owner of the invoice.', 'invoicing' ), |
|
995 | - 'type' => 'string', |
|
996 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
997 | - ), |
|
998 | - |
|
999 | - 'vat_number' => array( |
|
1000 | - 'description' => __( 'The VAT number of the owner of the invoice.', 'invoicing' ), |
|
1001 | - 'type' => 'string', |
|
1002 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1003 | - ), |
|
1004 | - |
|
1005 | - 'vat_rate' => array( |
|
1006 | - 'description' => __( 'The VAT rate applied on the invoice.', 'invoicing' ), |
|
1007 | - 'type' => 'string', |
|
1008 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1009 | - ), |
|
1010 | - |
|
1011 | - 'address' => array( |
|
1012 | - 'description' => __( 'The address of the invoice owner.', 'invoicing' ), |
|
1013 | - 'type' => 'string', |
|
1014 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1015 | - ), |
|
1016 | - |
|
1017 | - 'city' => array( |
|
1018 | - 'description' => __( 'The city of the invoice owner.', 'invoicing' ), |
|
1019 | - 'type' => 'string', |
|
1020 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1021 | - ), |
|
1022 | - |
|
1023 | - 'country' => array( |
|
1024 | - 'description' => __( 'The country of the invoice owner.', 'invoicing' ), |
|
1025 | - 'type' => 'string', |
|
1026 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1027 | - ), |
|
1028 | - |
|
1029 | - 'state' => array( |
|
1030 | - 'description' => __( 'The state of the invoice owner.', 'invoicing' ), |
|
1031 | - 'type' => 'string', |
|
1032 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1033 | - ), |
|
1034 | - |
|
1035 | - 'zip' => array( |
|
1036 | - 'description' => __( 'The zip code of the invoice owner.', 'invoicing' ), |
|
1037 | - 'type' => 'string', |
|
1038 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1039 | - ), |
|
1040 | - |
|
1041 | - 'phone' => array( |
|
1042 | - 'description' => __( 'The phone number of the invoice owner.', 'invoicing' ), |
|
1043 | - 'type' => 'string', |
|
1044 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1045 | - ), |
|
1046 | - ), |
|
1047 | - ), |
|
1048 | - |
|
1049 | - 'id' => array( |
|
1050 | - 'description' => __( 'Unique identifier for the invoice.', 'invoicing' ), |
|
1051 | - 'type' => 'integer', |
|
1052 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1053 | - 'readonly' => true, |
|
1054 | - ), |
|
1055 | - |
|
1056 | - 'key' => array( |
|
1057 | - 'description' => __( 'A unique key for the invoice.', 'invoicing' ), |
|
1058 | - 'type' => 'string', |
|
1059 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1060 | - 'readonly' => true, |
|
1061 | - ), |
|
1062 | - |
|
1063 | - 'number' => array( |
|
1064 | - 'description' => __( 'The invoice number.', 'invoicing' ), |
|
1065 | - 'type' => 'string', |
|
1066 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1067 | - 'readonly' => true, |
|
1068 | - ), |
|
1069 | - |
|
1070 | - 'transaction_id' => array( |
|
1071 | - 'description' => __( 'The transaction id of the invoice.', 'invoicing' ), |
|
1072 | - 'type' => 'string', |
|
1073 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1074 | - ), |
|
1075 | - |
|
1076 | - 'gateway' => array( |
|
1077 | - 'description' => __( 'The gateway used to process the invoice.', 'invoicing' ), |
|
1078 | - 'type' => 'string', |
|
1079 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1080 | - ), |
|
1081 | - |
|
1082 | - 'gateway_title' => array( |
|
1083 | - 'description' => __( 'The title of the gateway used to process the invoice.', 'invoicing' ), |
|
1084 | - 'type' => 'string', |
|
1085 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1086 | - ), |
|
1087 | - |
|
1088 | - 'total' => array( |
|
1089 | - 'description' => __( 'The total amount of the invoice.', 'invoicing' ), |
|
1090 | - 'type' => 'number', |
|
1091 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1092 | - 'readonly' => true, |
|
1093 | - ), |
|
1094 | - |
|
1095 | - 'discount' => array( |
|
1096 | - 'description' => __( 'The discount applied to the invoice.', 'invoicing' ), |
|
1097 | - 'type' => 'number', |
|
1098 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1099 | - 'readonly' => true, |
|
1100 | - ), |
|
1101 | - |
|
1102 | - 'discount_code' => array( |
|
1103 | - 'description' => __( 'The discount code applied to the invoice.', 'invoicing' ), |
|
1104 | - 'type' => 'string', |
|
1105 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1106 | - 'readonly' => true, |
|
1107 | - ), |
|
1108 | - |
|
1109 | - 'tax' => array( |
|
1110 | - 'description' => __( 'The tax applied to the invoice.', 'invoicing' ), |
|
1111 | - 'type' => 'number', |
|
1112 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1113 | - 'readonly' => true, |
|
1114 | - ), |
|
1115 | - |
|
1116 | - 'fees_total' => array( |
|
1117 | - 'description' => __( 'The total fees applied to the invoice.', 'invoicing' ), |
|
1118 | - 'type' => 'number', |
|
1119 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1120 | - 'readonly' => true, |
|
1121 | - ), |
|
1122 | - |
|
1123 | - 'subtotal' => array( |
|
1124 | - 'description' => __( 'The sub-total for the invoice.', 'invoicing' ), |
|
1125 | - 'type' => 'number', |
|
1126 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1127 | - 'readonly' => true, |
|
1128 | - ), |
|
1129 | - |
|
1130 | - 'currency' => array( |
|
1131 | - 'description' => __( 'The currency used to process the invoice.', 'invoicing' ), |
|
1132 | - 'type' => 'string', |
|
1133 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1134 | - ), |
|
1135 | - |
|
1136 | - 'cart_details' => array( |
|
1137 | - 'description' => __( 'The cart details for invoice.', 'invoicing' ), |
|
1138 | - 'type' => 'array', |
|
1139 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1140 | - 'required' => true, |
|
1141 | - ), |
|
1142 | - |
|
1143 | - 'date' => array( |
|
1144 | - 'description' => __( "The date the invoice was published, in the site's timezone.", 'invoicing' ), |
|
1145 | - 'type' => array( 'string', 'null' ), |
|
1146 | - 'format' => 'date-time', |
|
1147 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1148 | - ), |
|
1149 | - |
|
1150 | - 'due_date' => array( |
|
1151 | - 'description' => __( 'The due date for the invoice.', 'invoicing' ), |
|
1152 | - 'type' => array( 'string', 'null' ), |
|
1153 | - 'format' => 'date-time', |
|
1154 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1155 | - ), |
|
1156 | - |
|
1157 | - 'completed_date' => array( |
|
1158 | - 'description' => __( 'The completed date for the invoice.', 'invoicing' ), |
|
1159 | - 'type' => array( 'string', 'null' ), |
|
1160 | - 'format' => 'date-time', |
|
1161 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1162 | - 'readonly' => true, |
|
1163 | - ), |
|
833 | + $links = $this->prepare_links( $invoice ); |
|
834 | + $response->add_links( $links ); |
|
835 | + |
|
836 | + if ( ! empty( $links['self']['href'] ) ) { |
|
837 | + $actions = $this->get_available_actions( $invoice, $request ); |
|
838 | + |
|
839 | + $self = $links['self']['href']; |
|
840 | + |
|
841 | + foreach ( $actions as $rel ) { |
|
842 | + $response->add_link( $rel, $self ); |
|
843 | + } |
|
844 | + } |
|
845 | + |
|
846 | + /** |
|
847 | + * Filters the invoice data for a response. |
|
848 | + * |
|
849 | + * @since 1.0.13 |
|
850 | + * |
|
851 | + * @param WP_REST_Response $response The response object. |
|
852 | + * @param WPInv_Invoice $invoice The invoice object. |
|
853 | + * @param WP_REST_Request $request Request object. |
|
854 | + */ |
|
855 | + return apply_filters( "wpinv_rest_prepare_invoice", $response, $invoice, $request ); |
|
856 | + } |
|
857 | + |
|
858 | + /** |
|
859 | + * Gets an array of fields to be included on the response. |
|
860 | + * |
|
861 | + * Included fields are based on item schema and `_fields=` request argument. |
|
862 | + * |
|
863 | + * @since 1.0.13 |
|
864 | + * |
|
865 | + * @param WP_REST_Request $request Full details about the request. |
|
866 | + * @return array Fields to be included in the response. |
|
867 | + */ |
|
868 | + public function get_fields_for_response( $request ) { |
|
869 | + $schema = $this->get_item_schema(); |
|
870 | + $properties = isset( $schema['properties'] ) ? $schema['properties'] : array(); |
|
871 | + |
|
872 | + $additional_fields = $this->get_additional_fields(); |
|
873 | + foreach ( $additional_fields as $field_name => $field_options ) { |
|
874 | + // For back-compat, include any field with an empty schema |
|
875 | + // because it won't be present in $this->get_item_schema(). |
|
876 | + if ( is_null( $field_options['schema'] ) ) { |
|
877 | + $properties[ $field_name ] = $field_options; |
|
878 | + } |
|
879 | + } |
|
880 | + |
|
881 | + // Exclude fields that specify a different context than the request context. |
|
882 | + $context = $request['context']; |
|
883 | + if ( $context ) { |
|
884 | + foreach ( $properties as $name => $options ) { |
|
885 | + if ( ! empty( $options['context'] ) && ! in_array( $context, $options['context'], true ) ) { |
|
886 | + unset( $properties[ $name ] ); |
|
887 | + } |
|
888 | + } |
|
889 | + } |
|
890 | + |
|
891 | + $fields = array_keys( $properties ); |
|
892 | + |
|
893 | + if ( ! isset( $request['_fields'] ) ) { |
|
894 | + return $fields; |
|
895 | + } |
|
896 | + $requested_fields = wpinv_parse_list( $request['_fields'] ); |
|
897 | + if ( 0 === count( $requested_fields ) ) { |
|
898 | + return $fields; |
|
899 | + } |
|
900 | + // Trim off outside whitespace from the comma delimited list. |
|
901 | + $requested_fields = array_map( 'trim', $requested_fields ); |
|
902 | + // Always persist 'id', because it can be needed for add_additional_fields_to_object(). |
|
903 | + if ( in_array( 'id', $fields, true ) ) { |
|
904 | + $requested_fields[] = 'id'; |
|
905 | + } |
|
906 | + // Return the list of all requested fields which appear in the schema. |
|
907 | + return array_reduce( |
|
908 | + $requested_fields, |
|
909 | + function( $response_fields, $field ) use ( $fields ) { |
|
910 | + if ( in_array( $field, $fields, true ) ) { |
|
911 | + $response_fields[] = $field; |
|
912 | + return $response_fields; |
|
913 | + } |
|
914 | + // Check for nested fields if $field is not a direct match. |
|
915 | + $nested_fields = explode( '.', $field ); |
|
916 | + // A nested field is included so long as its top-level property is |
|
917 | + // present in the schema. |
|
918 | + if ( in_array( $nested_fields[0], $fields, true ) ) { |
|
919 | + $response_fields[] = $field; |
|
920 | + } |
|
921 | + return $response_fields; |
|
922 | + }, |
|
923 | + array() |
|
924 | + ); |
|
925 | + } |
|
926 | + |
|
927 | + /** |
|
928 | + * Retrieves the invoice's schema, conforming to JSON Schema. |
|
929 | + * |
|
930 | + * @since 1.0.13 |
|
931 | + * |
|
932 | + * @return array Invoice schema data. |
|
933 | + */ |
|
934 | + public function get_item_schema() { |
|
935 | + |
|
936 | + // Maybe retrieve the schema from cache. |
|
937 | + if ( $this->schema ) { |
|
938 | + return $this->add_additional_fields_schema( $this->schema ); |
|
939 | + } |
|
940 | + |
|
941 | + $schema = array( |
|
942 | + '$schema' => 'http://json-schema.org/draft-04/schema#', |
|
943 | + 'title' => $this->post_type, |
|
944 | + 'type' => 'object', |
|
945 | + |
|
946 | + // Base properties for every Invoice. |
|
947 | + 'properties' => array( |
|
948 | + |
|
949 | + 'title' => array( |
|
950 | + 'description' => __( 'The title for the invoice.', 'invoicing' ), |
|
951 | + 'type' => 'string', |
|
952 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
953 | + 'readonly' => true, |
|
954 | + ), |
|
955 | + |
|
956 | + 'user_id' => array( |
|
957 | + 'description' => __( 'The ID of the owner of the invoice.', 'invoicing' ), |
|
958 | + 'type' => 'integer', |
|
959 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
960 | + ), |
|
961 | + |
|
962 | + 'email' => array( |
|
963 | + 'description' => __( 'The email of the owner of the invoice.', 'invoicing' ), |
|
964 | + 'type' => 'string', |
|
965 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
966 | + 'readonly' => true, |
|
967 | + ), |
|
968 | + |
|
969 | + 'ip' => array( |
|
970 | + 'description' => __( 'The IP of the owner of the invoice.', 'invoicing' ), |
|
971 | + 'type' => 'string', |
|
972 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
973 | + ), |
|
974 | + |
|
975 | + 'user_info' => array( |
|
976 | + 'description' => __( 'Information about the owner of the invoice.', 'invoicing' ), |
|
977 | + 'type' => 'object', |
|
978 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
979 | + 'properties' => array( |
|
980 | + |
|
981 | + 'first_name' => array( |
|
982 | + 'description' => __( 'The first name of the owner of the invoice.', 'invoicing' ), |
|
983 | + 'type' => 'string', |
|
984 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
985 | + ), |
|
986 | + |
|
987 | + 'last_name' => array( |
|
988 | + 'description' => __( 'The last name of the owner of the invoice.', 'invoicing' ), |
|
989 | + 'type' => 'string', |
|
990 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
991 | + ), |
|
992 | + |
|
993 | + 'company' => array( |
|
994 | + 'description' => __( 'The company of the owner of the invoice.', 'invoicing' ), |
|
995 | + 'type' => 'string', |
|
996 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
997 | + ), |
|
998 | + |
|
999 | + 'vat_number' => array( |
|
1000 | + 'description' => __( 'The VAT number of the owner of the invoice.', 'invoicing' ), |
|
1001 | + 'type' => 'string', |
|
1002 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
1003 | + ), |
|
1004 | + |
|
1005 | + 'vat_rate' => array( |
|
1006 | + 'description' => __( 'The VAT rate applied on the invoice.', 'invoicing' ), |
|
1007 | + 'type' => 'string', |
|
1008 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
1009 | + ), |
|
1010 | + |
|
1011 | + 'address' => array( |
|
1012 | + 'description' => __( 'The address of the invoice owner.', 'invoicing' ), |
|
1013 | + 'type' => 'string', |
|
1014 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
1015 | + ), |
|
1016 | + |
|
1017 | + 'city' => array( |
|
1018 | + 'description' => __( 'The city of the invoice owner.', 'invoicing' ), |
|
1019 | + 'type' => 'string', |
|
1020 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
1021 | + ), |
|
1022 | + |
|
1023 | + 'country' => array( |
|
1024 | + 'description' => __( 'The country of the invoice owner.', 'invoicing' ), |
|
1025 | + 'type' => 'string', |
|
1026 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
1027 | + ), |
|
1028 | + |
|
1029 | + 'state' => array( |
|
1030 | + 'description' => __( 'The state of the invoice owner.', 'invoicing' ), |
|
1031 | + 'type' => 'string', |
|
1032 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
1033 | + ), |
|
1034 | + |
|
1035 | + 'zip' => array( |
|
1036 | + 'description' => __( 'The zip code of the invoice owner.', 'invoicing' ), |
|
1037 | + 'type' => 'string', |
|
1038 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
1039 | + ), |
|
1040 | + |
|
1041 | + 'phone' => array( |
|
1042 | + 'description' => __( 'The phone number of the invoice owner.', 'invoicing' ), |
|
1043 | + 'type' => 'string', |
|
1044 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
1045 | + ), |
|
1046 | + ), |
|
1047 | + ), |
|
1048 | + |
|
1049 | + 'id' => array( |
|
1050 | + 'description' => __( 'Unique identifier for the invoice.', 'invoicing' ), |
|
1051 | + 'type' => 'integer', |
|
1052 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
1053 | + 'readonly' => true, |
|
1054 | + ), |
|
1055 | + |
|
1056 | + 'key' => array( |
|
1057 | + 'description' => __( 'A unique key for the invoice.', 'invoicing' ), |
|
1058 | + 'type' => 'string', |
|
1059 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
1060 | + 'readonly' => true, |
|
1061 | + ), |
|
1062 | + |
|
1063 | + 'number' => array( |
|
1064 | + 'description' => __( 'The invoice number.', 'invoicing' ), |
|
1065 | + 'type' => 'string', |
|
1066 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
1067 | + 'readonly' => true, |
|
1068 | + ), |
|
1069 | + |
|
1070 | + 'transaction_id' => array( |
|
1071 | + 'description' => __( 'The transaction id of the invoice.', 'invoicing' ), |
|
1072 | + 'type' => 'string', |
|
1073 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
1074 | + ), |
|
1075 | + |
|
1076 | + 'gateway' => array( |
|
1077 | + 'description' => __( 'The gateway used to process the invoice.', 'invoicing' ), |
|
1078 | + 'type' => 'string', |
|
1079 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
1080 | + ), |
|
1081 | + |
|
1082 | + 'gateway_title' => array( |
|
1083 | + 'description' => __( 'The title of the gateway used to process the invoice.', 'invoicing' ), |
|
1084 | + 'type' => 'string', |
|
1085 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
1086 | + ), |
|
1087 | + |
|
1088 | + 'total' => array( |
|
1089 | + 'description' => __( 'The total amount of the invoice.', 'invoicing' ), |
|
1090 | + 'type' => 'number', |
|
1091 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
1092 | + 'readonly' => true, |
|
1093 | + ), |
|
1094 | + |
|
1095 | + 'discount' => array( |
|
1096 | + 'description' => __( 'The discount applied to the invoice.', 'invoicing' ), |
|
1097 | + 'type' => 'number', |
|
1098 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
1099 | + 'readonly' => true, |
|
1100 | + ), |
|
1101 | + |
|
1102 | + 'discount_code' => array( |
|
1103 | + 'description' => __( 'The discount code applied to the invoice.', 'invoicing' ), |
|
1104 | + 'type' => 'string', |
|
1105 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
1106 | + 'readonly' => true, |
|
1107 | + ), |
|
1108 | + |
|
1109 | + 'tax' => array( |
|
1110 | + 'description' => __( 'The tax applied to the invoice.', 'invoicing' ), |
|
1111 | + 'type' => 'number', |
|
1112 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
1113 | + 'readonly' => true, |
|
1114 | + ), |
|
1115 | + |
|
1116 | + 'fees_total' => array( |
|
1117 | + 'description' => __( 'The total fees applied to the invoice.', 'invoicing' ), |
|
1118 | + 'type' => 'number', |
|
1119 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
1120 | + 'readonly' => true, |
|
1121 | + ), |
|
1122 | + |
|
1123 | + 'subtotal' => array( |
|
1124 | + 'description' => __( 'The sub-total for the invoice.', 'invoicing' ), |
|
1125 | + 'type' => 'number', |
|
1126 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
1127 | + 'readonly' => true, |
|
1128 | + ), |
|
1129 | + |
|
1130 | + 'currency' => array( |
|
1131 | + 'description' => __( 'The currency used to process the invoice.', 'invoicing' ), |
|
1132 | + 'type' => 'string', |
|
1133 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
1134 | + ), |
|
1135 | + |
|
1136 | + 'cart_details' => array( |
|
1137 | + 'description' => __( 'The cart details for invoice.', 'invoicing' ), |
|
1138 | + 'type' => 'array', |
|
1139 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
1140 | + 'required' => true, |
|
1141 | + ), |
|
1142 | + |
|
1143 | + 'date' => array( |
|
1144 | + 'description' => __( "The date the invoice was published, in the site's timezone.", 'invoicing' ), |
|
1145 | + 'type' => array( 'string', 'null' ), |
|
1146 | + 'format' => 'date-time', |
|
1147 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
1148 | + ), |
|
1149 | + |
|
1150 | + 'due_date' => array( |
|
1151 | + 'description' => __( 'The due date for the invoice.', 'invoicing' ), |
|
1152 | + 'type' => array( 'string', 'null' ), |
|
1153 | + 'format' => 'date-time', |
|
1154 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
1155 | + ), |
|
1156 | + |
|
1157 | + 'completed_date' => array( |
|
1158 | + 'description' => __( 'The completed date for the invoice.', 'invoicing' ), |
|
1159 | + 'type' => array( 'string', 'null' ), |
|
1160 | + 'format' => 'date-time', |
|
1161 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
1162 | + 'readonly' => true, |
|
1163 | + ), |
|
1164 | 1164 | |
1165 | - 'link' => array( |
|
1166 | - 'description' => __( 'URL to the invoice.', 'invoicing' ), |
|
1167 | - 'type' => 'string', |
|
1168 | - 'format' => 'uri', |
|
1169 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1170 | - 'readonly' => true, |
|
1171 | - ), |
|
1172 | - |
|
1173 | - 'mode' => array( |
|
1174 | - 'description' => __( 'The mode used to process the invoice.', 'invoicing' ), |
|
1175 | - 'type' => 'string', |
|
1176 | - 'enum' => array( 'live', 'test' ), |
|
1177 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1178 | - 'readonly' => true, |
|
1179 | - ), |
|
1180 | - |
|
1181 | - 'slug' => array( |
|
1182 | - 'description' => __( 'An alphanumeric identifier for the invoice.', 'invoicing' ), |
|
1183 | - 'type' => 'string', |
|
1184 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1185 | - 'arg_options' => array( |
|
1186 | - 'sanitize_callback' => array( $this, 'sanitize_slug' ), |
|
1187 | - ), |
|
1188 | - 'readonly' => true, |
|
1189 | - ), |
|
1190 | - |
|
1191 | - 'status' => array( |
|
1192 | - 'description' => __( 'A named status for the invoice.', 'invoicing' ), |
|
1193 | - 'type' => 'string', |
|
1194 | - 'enum' => array_keys( wpinv_get_invoice_statuses( true, true ) ), |
|
1195 | - 'context' => array( 'view', 'edit' ), |
|
1196 | - 'default' => 'wpi-pending', |
|
1197 | - ), |
|
1198 | - |
|
1199 | - 'status_nicename' => array( |
|
1200 | - 'description' => __( 'A human-readable status name for the invoice.', 'invoicing' ), |
|
1201 | - 'type' => 'string', |
|
1202 | - 'context' => array( 'view', 'embed' ), |
|
1203 | - 'readonly' => true, |
|
1204 | - ), |
|
1205 | - |
|
1206 | - 'post_type' => array( |
|
1207 | - 'description' => __( 'The post type for the invoice.', 'invoicing' ), |
|
1208 | - 'type' => 'string', |
|
1209 | - 'context' => array( 'view' ), |
|
1210 | - 'readonly' => true, |
|
1211 | - ), |
|
1212 | - ), |
|
1213 | - ); |
|
1214 | - |
|
1215 | - // Add helpful links to the invoice schem. |
|
1216 | - $schema['links'] = $this->get_schema_links(); |
|
1217 | - |
|
1218 | - /** |
|
1219 | - * Filters the invoice schema for the REST API. |
|
1220 | - * |
|
1221 | - * Enables adding extra properties to invoices. |
|
1222 | - * |
|
1223 | - * @since 1.0.13 |
|
1224 | - * |
|
1225 | - * @param array $schema The invoice schema. |
|
1226 | - */ |
|
1165 | + 'link' => array( |
|
1166 | + 'description' => __( 'URL to the invoice.', 'invoicing' ), |
|
1167 | + 'type' => 'string', |
|
1168 | + 'format' => 'uri', |
|
1169 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
1170 | + 'readonly' => true, |
|
1171 | + ), |
|
1172 | + |
|
1173 | + 'mode' => array( |
|
1174 | + 'description' => __( 'The mode used to process the invoice.', 'invoicing' ), |
|
1175 | + 'type' => 'string', |
|
1176 | + 'enum' => array( 'live', 'test' ), |
|
1177 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
1178 | + 'readonly' => true, |
|
1179 | + ), |
|
1180 | + |
|
1181 | + 'slug' => array( |
|
1182 | + 'description' => __( 'An alphanumeric identifier for the invoice.', 'invoicing' ), |
|
1183 | + 'type' => 'string', |
|
1184 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
1185 | + 'arg_options' => array( |
|
1186 | + 'sanitize_callback' => array( $this, 'sanitize_slug' ), |
|
1187 | + ), |
|
1188 | + 'readonly' => true, |
|
1189 | + ), |
|
1190 | + |
|
1191 | + 'status' => array( |
|
1192 | + 'description' => __( 'A named status for the invoice.', 'invoicing' ), |
|
1193 | + 'type' => 'string', |
|
1194 | + 'enum' => array_keys( wpinv_get_invoice_statuses( true, true ) ), |
|
1195 | + 'context' => array( 'view', 'edit' ), |
|
1196 | + 'default' => 'wpi-pending', |
|
1197 | + ), |
|
1198 | + |
|
1199 | + 'status_nicename' => array( |
|
1200 | + 'description' => __( 'A human-readable status name for the invoice.', 'invoicing' ), |
|
1201 | + 'type' => 'string', |
|
1202 | + 'context' => array( 'view', 'embed' ), |
|
1203 | + 'readonly' => true, |
|
1204 | + ), |
|
1205 | + |
|
1206 | + 'post_type' => array( |
|
1207 | + 'description' => __( 'The post type for the invoice.', 'invoicing' ), |
|
1208 | + 'type' => 'string', |
|
1209 | + 'context' => array( 'view' ), |
|
1210 | + 'readonly' => true, |
|
1211 | + ), |
|
1212 | + ), |
|
1213 | + ); |
|
1214 | + |
|
1215 | + // Add helpful links to the invoice schem. |
|
1216 | + $schema['links'] = $this->get_schema_links(); |
|
1217 | + |
|
1218 | + /** |
|
1219 | + * Filters the invoice schema for the REST API. |
|
1220 | + * |
|
1221 | + * Enables adding extra properties to invoices. |
|
1222 | + * |
|
1223 | + * @since 1.0.13 |
|
1224 | + * |
|
1225 | + * @param array $schema The invoice schema. |
|
1226 | + */ |
|
1227 | 1227 | $schema = apply_filters( "wpinv_rest_invoice_schema", $schema ); |
1228 | 1228 | |
1229 | - // Cache the invoice schema. |
|
1230 | - $this->schema = $schema; |
|
1229 | + // Cache the invoice schema. |
|
1230 | + $this->schema = $schema; |
|
1231 | 1231 | |
1232 | - return $this->add_additional_fields_schema( $this->schema ); |
|
1233 | - } |
|
1234 | - |
|
1235 | - /** |
|
1236 | - * Retrieve Link Description Objects that should be added to the Schema for the invoices collection. |
|
1237 | - * |
|
1238 | - * @since 1.0.13 |
|
1239 | - * |
|
1240 | - * @return array |
|
1241 | - */ |
|
1242 | - protected function get_schema_links() { |
|
1243 | - |
|
1244 | - $href = rest_url( "{$this->namespace}/{$this->rest_base}/{id}" ); |
|
1245 | - |
|
1246 | - $links = array(); |
|
1247 | - |
|
1248 | - $links[] = array( |
|
1249 | - 'rel' => 'https://api.w.org/action-publish', |
|
1250 | - 'title' => __( 'The current user can mark this invoice as completed.', 'invoicing' ), |
|
1251 | - 'href' => $href, |
|
1252 | - 'targetSchema' => array( |
|
1253 | - 'type' => 'object', |
|
1254 | - 'properties' => array( |
|
1255 | - 'status' => array( |
|
1256 | - 'type' => 'string', |
|
1257 | - 'enum' => array( 'publish', 'wpi-renewal' ), |
|
1258 | - ), |
|
1259 | - ), |
|
1260 | - ), |
|
1261 | - ); |
|
1262 | - |
|
1263 | - $links[] = array( |
|
1264 | - 'rel' => 'https://api.w.org/action-assign-author', |
|
1265 | - 'title' => __( 'The current user can change the owner of this invoice.', 'invoicing' ), |
|
1266 | - 'href' => $href, |
|
1267 | - 'targetSchema' => array( |
|
1268 | - 'type' => 'object', |
|
1269 | - 'properties' => array( |
|
1270 | - 'user_id' => array( |
|
1271 | - 'type' => 'integer', |
|
1272 | - ), |
|
1273 | - ), |
|
1274 | - ), |
|
1275 | - ); |
|
1276 | - |
|
1277 | - return $links; |
|
1278 | - } |
|
1279 | - |
|
1280 | - /** |
|
1281 | - * Prepares links for the request. |
|
1282 | - * |
|
1283 | - * @since 1.0.13 |
|
1284 | - * |
|
1285 | - * @param WPInv_Invoice $invoice Invoice Object. |
|
1286 | - * @return array Links for the given invoice. |
|
1287 | - */ |
|
1288 | - protected function prepare_links( $invoice ) { |
|
1289 | - |
|
1290 | - // Prepare the base REST API endpoint for invoices. |
|
1291 | - $base = sprintf( '%s/%s', $this->namespace, $this->rest_base ); |
|
1292 | - |
|
1293 | - // Entity meta. |
|
1294 | - $links = array( |
|
1295 | - 'self' => array( |
|
1296 | - 'href' => rest_url( trailingslashit( $base ) . $invoice->ID ), |
|
1297 | - ), |
|
1298 | - 'collection' => array( |
|
1299 | - 'href' => rest_url( $base ), |
|
1300 | - ), |
|
1301 | - ); |
|
1302 | - |
|
1303 | - if ( ! empty( $invoice->user_id ) ) { |
|
1304 | - $links['user'] = array( |
|
1305 | - 'href' => rest_url( 'wp/v2/users/' . $invoice->user_id ), |
|
1306 | - 'embeddable' => true, |
|
1307 | - ); |
|
1308 | - } |
|
1309 | - |
|
1310 | - /** |
|
1311 | - * Filters the returned invoice links for the REST API. |
|
1312 | - * |
|
1313 | - * Enables adding extra links to invoice API responses. |
|
1314 | - * |
|
1315 | - * @since 1.0.13 |
|
1316 | - * |
|
1317 | - * @param array $links Rest links. |
|
1318 | - */ |
|
1319 | - return apply_filters( "wpinv_rest_invoice_links", $links ); |
|
1320 | - |
|
1321 | - } |
|
1322 | - |
|
1323 | - /** |
|
1324 | - * Get the link relations available for the post and current user. |
|
1325 | - * |
|
1326 | - * @since 1.0.13 |
|
1327 | - * |
|
1328 | - * @param WPInv_Invoice $invoice Invoice object. |
|
1329 | - * @param WP_REST_Request $request Request object. |
|
1330 | - * @return array List of link relations. |
|
1331 | - */ |
|
1332 | - protected function get_available_actions( $invoice, $request ) { |
|
1333 | - |
|
1334 | - if ( 'edit' !== $request['context'] ) { |
|
1335 | - return array(); |
|
1336 | - } |
|
1337 | - |
|
1338 | - $rels = array(); |
|
1339 | - |
|
1340 | - // Retrieve the post type object. |
|
1341 | - $post_type = get_post_type_object( $invoice->post_type ); |
|
1342 | - |
|
1343 | - // Mark invoice as completed. |
|
1344 | - if ( current_user_can( $post_type->cap->publish_posts ) ) { |
|
1345 | - $rels[] = 'https://api.w.org/action-publish'; |
|
1346 | - } |
|
1347 | - |
|
1348 | - // Change the owner of the invoice. |
|
1349 | - if ( current_user_can( $post_type->cap->edit_others_posts ) ) { |
|
1350 | - $rels[] = 'https://api.w.org/action-assign-author'; |
|
1351 | - } |
|
1352 | - |
|
1353 | - /** |
|
1354 | - * Filters the available invoice link relations for the REST API. |
|
1355 | - * |
|
1356 | - * Enables adding extra link relation for the current user and request to invoice responses. |
|
1357 | - * |
|
1358 | - * @since 1.0.13 |
|
1359 | - * |
|
1360 | - * @param array $rels Available link relations. |
|
1361 | - */ |
|
1362 | - return apply_filters( "wpinv_rest_invoice_link_relations", $rels ); |
|
1363 | - } |
|
1364 | - |
|
1365 | - /** |
|
1366 | - * Sanitizes and validates the list of post statuses. |
|
1367 | - * |
|
1368 | - * @since 1.0.13 |
|
1369 | - * |
|
1370 | - * @param string|array $statuses One or more post statuses. |
|
1371 | - * @param WP_REST_Request $request Full details about the request. |
|
1372 | - * @param string $parameter Additional parameter to pass to validation. |
|
1373 | - * @return array|WP_Error A list of valid statuses, otherwise WP_Error object. |
|
1374 | - */ |
|
1375 | - public function sanitize_post_statuses( $statuses, $request, $parameter ) { |
|
1376 | - |
|
1377 | - $statuses = wp_parse_slug_list( $statuses ); |
|
1378 | - $valid_statuses = array_keys( wpinv_get_invoice_statuses( true, true ) ); |
|
1379 | - return array_intersect( $statuses, $valid_statuses ); |
|
1232 | + return $this->add_additional_fields_schema( $this->schema ); |
|
1233 | + } |
|
1234 | + |
|
1235 | + /** |
|
1236 | + * Retrieve Link Description Objects that should be added to the Schema for the invoices collection. |
|
1237 | + * |
|
1238 | + * @since 1.0.13 |
|
1239 | + * |
|
1240 | + * @return array |
|
1241 | + */ |
|
1242 | + protected function get_schema_links() { |
|
1243 | + |
|
1244 | + $href = rest_url( "{$this->namespace}/{$this->rest_base}/{id}" ); |
|
1245 | + |
|
1246 | + $links = array(); |
|
1247 | + |
|
1248 | + $links[] = array( |
|
1249 | + 'rel' => 'https://api.w.org/action-publish', |
|
1250 | + 'title' => __( 'The current user can mark this invoice as completed.', 'invoicing' ), |
|
1251 | + 'href' => $href, |
|
1252 | + 'targetSchema' => array( |
|
1253 | + 'type' => 'object', |
|
1254 | + 'properties' => array( |
|
1255 | + 'status' => array( |
|
1256 | + 'type' => 'string', |
|
1257 | + 'enum' => array( 'publish', 'wpi-renewal' ), |
|
1258 | + ), |
|
1259 | + ), |
|
1260 | + ), |
|
1261 | + ); |
|
1262 | + |
|
1263 | + $links[] = array( |
|
1264 | + 'rel' => 'https://api.w.org/action-assign-author', |
|
1265 | + 'title' => __( 'The current user can change the owner of this invoice.', 'invoicing' ), |
|
1266 | + 'href' => $href, |
|
1267 | + 'targetSchema' => array( |
|
1268 | + 'type' => 'object', |
|
1269 | + 'properties' => array( |
|
1270 | + 'user_id' => array( |
|
1271 | + 'type' => 'integer', |
|
1272 | + ), |
|
1273 | + ), |
|
1274 | + ), |
|
1275 | + ); |
|
1276 | + |
|
1277 | + return $links; |
|
1278 | + } |
|
1279 | + |
|
1280 | + /** |
|
1281 | + * Prepares links for the request. |
|
1282 | + * |
|
1283 | + * @since 1.0.13 |
|
1284 | + * |
|
1285 | + * @param WPInv_Invoice $invoice Invoice Object. |
|
1286 | + * @return array Links for the given invoice. |
|
1287 | + */ |
|
1288 | + protected function prepare_links( $invoice ) { |
|
1289 | + |
|
1290 | + // Prepare the base REST API endpoint for invoices. |
|
1291 | + $base = sprintf( '%s/%s', $this->namespace, $this->rest_base ); |
|
1292 | + |
|
1293 | + // Entity meta. |
|
1294 | + $links = array( |
|
1295 | + 'self' => array( |
|
1296 | + 'href' => rest_url( trailingslashit( $base ) . $invoice->ID ), |
|
1297 | + ), |
|
1298 | + 'collection' => array( |
|
1299 | + 'href' => rest_url( $base ), |
|
1300 | + ), |
|
1301 | + ); |
|
1302 | + |
|
1303 | + if ( ! empty( $invoice->user_id ) ) { |
|
1304 | + $links['user'] = array( |
|
1305 | + 'href' => rest_url( 'wp/v2/users/' . $invoice->user_id ), |
|
1306 | + 'embeddable' => true, |
|
1307 | + ); |
|
1308 | + } |
|
1309 | + |
|
1310 | + /** |
|
1311 | + * Filters the returned invoice links for the REST API. |
|
1312 | + * |
|
1313 | + * Enables adding extra links to invoice API responses. |
|
1314 | + * |
|
1315 | + * @since 1.0.13 |
|
1316 | + * |
|
1317 | + * @param array $links Rest links. |
|
1318 | + */ |
|
1319 | + return apply_filters( "wpinv_rest_invoice_links", $links ); |
|
1320 | + |
|
1321 | + } |
|
1322 | + |
|
1323 | + /** |
|
1324 | + * Get the link relations available for the post and current user. |
|
1325 | + * |
|
1326 | + * @since 1.0.13 |
|
1327 | + * |
|
1328 | + * @param WPInv_Invoice $invoice Invoice object. |
|
1329 | + * @param WP_REST_Request $request Request object. |
|
1330 | + * @return array List of link relations. |
|
1331 | + */ |
|
1332 | + protected function get_available_actions( $invoice, $request ) { |
|
1333 | + |
|
1334 | + if ( 'edit' !== $request['context'] ) { |
|
1335 | + return array(); |
|
1336 | + } |
|
1337 | + |
|
1338 | + $rels = array(); |
|
1339 | + |
|
1340 | + // Retrieve the post type object. |
|
1341 | + $post_type = get_post_type_object( $invoice->post_type ); |
|
1342 | + |
|
1343 | + // Mark invoice as completed. |
|
1344 | + if ( current_user_can( $post_type->cap->publish_posts ) ) { |
|
1345 | + $rels[] = 'https://api.w.org/action-publish'; |
|
1346 | + } |
|
1347 | + |
|
1348 | + // Change the owner of the invoice. |
|
1349 | + if ( current_user_can( $post_type->cap->edit_others_posts ) ) { |
|
1350 | + $rels[] = 'https://api.w.org/action-assign-author'; |
|
1351 | + } |
|
1352 | + |
|
1353 | + /** |
|
1354 | + * Filters the available invoice link relations for the REST API. |
|
1355 | + * |
|
1356 | + * Enables adding extra link relation for the current user and request to invoice responses. |
|
1357 | + * |
|
1358 | + * @since 1.0.13 |
|
1359 | + * |
|
1360 | + * @param array $rels Available link relations. |
|
1361 | + */ |
|
1362 | + return apply_filters( "wpinv_rest_invoice_link_relations", $rels ); |
|
1363 | + } |
|
1364 | + |
|
1365 | + /** |
|
1366 | + * Sanitizes and validates the list of post statuses. |
|
1367 | + * |
|
1368 | + * @since 1.0.13 |
|
1369 | + * |
|
1370 | + * @param string|array $statuses One or more post statuses. |
|
1371 | + * @param WP_REST_Request $request Full details about the request. |
|
1372 | + * @param string $parameter Additional parameter to pass to validation. |
|
1373 | + * @return array|WP_Error A list of valid statuses, otherwise WP_Error object. |
|
1374 | + */ |
|
1375 | + public function sanitize_post_statuses( $statuses, $request, $parameter ) { |
|
1376 | + |
|
1377 | + $statuses = wp_parse_slug_list( $statuses ); |
|
1378 | + $valid_statuses = array_keys( wpinv_get_invoice_statuses( true, true ) ); |
|
1379 | + return array_intersect( $statuses, $valid_statuses ); |
|
1380 | 1380 | |
1381 | - } |
|
1381 | + } |
|
1382 | 1382 | |
1383 | 1383 | } |
1384 | 1384 | \ No newline at end of file |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * @since 1.0.13 |
9 | 9 | */ |
10 | 10 | |
11 | -if ( !defined( 'WPINC' ) ) { |
|
11 | +if (!defined('WPINC')) { |
|
12 | 12 | exit; |
13 | 13 | } |
14 | 14 | |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | * |
42 | 42 | * @param string $namespace Api Namespace |
43 | 43 | */ |
44 | - public function __construct( $namespace ) { |
|
44 | + public function __construct($namespace) { |
|
45 | 45 | |
46 | 46 | // Set api namespace... |
47 | 47 | $this->namespace = $namespace; |
@@ -60,12 +60,12 @@ discard block |
||
60 | 60 | * @param WP_REST_Request $request Full details about the request. |
61 | 61 | * @return true|WP_Error True if the request has read access, WP_Error object otherwise. |
62 | 62 | */ |
63 | - public function get_items_permissions_check( $request ) { |
|
63 | + public function get_items_permissions_check($request) { |
|
64 | 64 | |
65 | - $post_type = get_post_type_object( $this->post_type ); |
|
65 | + $post_type = get_post_type_object($this->post_type); |
|
66 | 66 | |
67 | - if ( 'edit' === $request['context'] && ! current_user_can( $post_type->cap->edit_posts ) ) { |
|
68 | - return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to edit invoices.', 'invoicing' ), array( 'status' => rest_authorization_required_code() ) ); |
|
67 | + if ('edit' === $request['context'] && !current_user_can($post_type->cap->edit_posts)) { |
|
68 | + return new WP_Error('rest_forbidden_context', __('Sorry, you are not allowed to edit invoices.', 'invoicing'), array('status' => rest_authorization_required_code())); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | // Read checks will be evaluated on a per invoice basis |
@@ -82,17 +82,17 @@ discard block |
||
82 | 82 | * @param WP_REST_Request $request Full details about the request. |
83 | 83 | * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. |
84 | 84 | */ |
85 | - public function get_items( $request ) { |
|
85 | + public function get_items($request) { |
|
86 | 86 | |
87 | 87 | // Retrieve the list of registered invoice query parameters. |
88 | 88 | $registered = $this->get_collection_params(); |
89 | 89 | |
90 | 90 | $args = array(); |
91 | 91 | |
92 | - foreach( array_keys( $registered ) as $key ) { |
|
92 | + foreach (array_keys($registered) as $key) { |
|
93 | 93 | |
94 | - if( isset( $request[ $key] ) ) { |
|
95 | - $args[ $key ] = $request[ $key]; |
|
94 | + if (isset($request[$key])) { |
|
95 | + $args[$key] = $request[$key]; |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | } |
@@ -107,32 +107,32 @@ discard block |
||
107 | 107 | * @param array $args Key value array of query var to query value. |
108 | 108 | * @param WP_REST_Request $request The request used. |
109 | 109 | */ |
110 | - $args = apply_filters( "wpinv_rest_get_invoices_arguments", $args, $request, $this ); |
|
110 | + $args = apply_filters("wpinv_rest_get_invoices_arguments", $args, $request, $this); |
|
111 | 111 | |
112 | 112 | // Special args |
113 | - $args[ 'return' ] = 'objects'; |
|
114 | - $args[ 'paginate' ] = true; |
|
113 | + $args['return'] = 'objects'; |
|
114 | + $args['paginate'] = true; |
|
115 | 115 | |
116 | 116 | // Run the query. |
117 | - $query = wpinv_get_invoices( $args ); |
|
117 | + $query = wpinv_get_invoices($args); |
|
118 | 118 | |
119 | 119 | // Prepare the retrieved invoices |
120 | 120 | $invoices = array(); |
121 | - foreach( $query->invoices as $invoice ) { |
|
121 | + foreach ($query->invoices as $invoice) { |
|
122 | 122 | |
123 | - if ( ! $this->check_read_permission( $invoice ) ) { |
|
123 | + if (!$this->check_read_permission($invoice)) { |
|
124 | 124 | continue; |
125 | 125 | } |
126 | 126 | |
127 | - $data = $this->prepare_item_for_response( $invoice, $request ); |
|
128 | - $invoices[] = $this->prepare_response_for_collection( $data ); |
|
127 | + $data = $this->prepare_item_for_response($invoice, $request); |
|
128 | + $invoices[] = $this->prepare_response_for_collection($data); |
|
129 | 129 | |
130 | 130 | } |
131 | 131 | |
132 | 132 | // Prepare the response. |
133 | - $response = rest_ensure_response( $invoices ); |
|
134 | - $response->header( 'X-WP-Total', (int) $query->total ); |
|
135 | - $response->header( 'X-WP-TotalPages', (int) $query->max_num_pages ); |
|
133 | + $response = rest_ensure_response($invoices); |
|
134 | + $response->header('X-WP-Total', (int) $query->total); |
|
135 | + $response->header('X-WP-TotalPages', (int) $query->max_num_pages); |
|
136 | 136 | |
137 | 137 | /** |
138 | 138 | * Filters the responses for invoices requests. |
@@ -145,9 +145,9 @@ discard block |
||
145 | 145 | * @param WP_REST_Request $request The request used. |
146 | 146 | * @param array $args Array of args used to retrieve the invoices |
147 | 147 | */ |
148 | - $response = apply_filters( "wpinv_rest_invoices_response", $response, $request, $args ); |
|
148 | + $response = apply_filters("wpinv_rest_invoices_response", $response, $request, $args); |
|
149 | 149 | |
150 | - return rest_ensure_response( $response ); |
|
150 | + return rest_ensure_response($response); |
|
151 | 151 | |
152 | 152 | } |
153 | 153 | |
@@ -159,17 +159,17 @@ discard block |
||
159 | 159 | * @param int $invoice_id Supplied ID. |
160 | 160 | * @return WPInv_Invoice|WP_Error Invoice object if ID is valid, WP_Error otherwise. |
161 | 161 | */ |
162 | - protected function get_post( $invoice_id ) { |
|
162 | + protected function get_post($invoice_id) { |
|
163 | 163 | |
164 | - $error = new WP_Error( 'rest_invoice_invalid_id', __( 'Invalid invoice ID.', 'invoicing' ), array( 'status' => 404 ) ); |
|
164 | + $error = new WP_Error('rest_invoice_invalid_id', __('Invalid invoice ID.', 'invoicing'), array('status' => 404)); |
|
165 | 165 | |
166 | 166 | // Ids start from 1 |
167 | - if ( (int) $invoice_id <= 0 ) { |
|
167 | + if ((int) $invoice_id <= 0) { |
|
168 | 168 | return $error; |
169 | 169 | } |
170 | 170 | |
171 | - $invoice = wpinv_get_invoice( (int) $invoice_id ); |
|
172 | - if ( empty( $invoice ) ) { |
|
171 | + $invoice = wpinv_get_invoice((int) $invoice_id); |
|
172 | + if (empty($invoice)) { |
|
173 | 173 | return $error; |
174 | 174 | } |
175 | 175 | |
@@ -185,18 +185,18 @@ discard block |
||
185 | 185 | * @param WP_REST_Request $request Full details about the request. |
186 | 186 | * @return bool|WP_Error True if the request has read access for the invoice, WP_Error object otherwise. |
187 | 187 | */ |
188 | - public function get_item_permissions_check( $request ) { |
|
188 | + public function get_item_permissions_check($request) { |
|
189 | 189 | |
190 | 190 | // Retrieve the invoice object. |
191 | - $invoice = $this->get_post( $request['id'] ); |
|
191 | + $invoice = $this->get_post($request['id']); |
|
192 | 192 | |
193 | 193 | // Ensure it is valid. |
194 | - if ( is_wp_error( $invoice ) ) { |
|
194 | + if (is_wp_error($invoice)) { |
|
195 | 195 | return $invoice; |
196 | 196 | } |
197 | 197 | |
198 | - if ( $invoice ) { |
|
199 | - return $this->check_read_permission( $invoice ); |
|
198 | + if ($invoice) { |
|
199 | + return $this->check_read_permission($invoice); |
|
200 | 200 | } |
201 | 201 | |
202 | 202 | return true; |
@@ -213,8 +213,8 @@ discard block |
||
213 | 213 | * @param WPInv_Invoice $invoice WPInv_Invoice object. |
214 | 214 | * @return bool Whether the post can be read. |
215 | 215 | */ |
216 | - public function check_read_permission( $invoice ) { |
|
217 | - return wpinv_user_can_view_invoice( $invoice->ID ); |
|
216 | + public function check_read_permission($invoice) { |
|
217 | + return wpinv_user_can_view_invoice($invoice->ID); |
|
218 | 218 | } |
219 | 219 | |
220 | 220 | /** |
@@ -225,19 +225,19 @@ discard block |
||
225 | 225 | * @param WP_REST_Request $request Full details about the request. |
226 | 226 | * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. |
227 | 227 | */ |
228 | - public function get_item( $request ) { |
|
228 | + public function get_item($request) { |
|
229 | 229 | |
230 | 230 | // Fetch the invoice. |
231 | - $invoice = $this->get_post( $request['id'] ); |
|
231 | + $invoice = $this->get_post($request['id']); |
|
232 | 232 | |
233 | 233 | // Abort early if it does not exist |
234 | - if ( is_wp_error( $invoice ) ) { |
|
234 | + if (is_wp_error($invoice)) { |
|
235 | 235 | return $invoice; |
236 | 236 | } |
237 | 237 | |
238 | 238 | // Prepare the response |
239 | - $response = $this->prepare_item_for_response( $invoice, $request ); |
|
240 | - $response->link_header( 'alternate', esc_url( $invoice->get_view_url() ), array( 'type' => 'text/html' ) ); |
|
239 | + $response = $this->prepare_item_for_response($invoice, $request); |
|
240 | + $response->link_header('alternate', esc_url($invoice->get_view_url()), array('type' => 'text/html')); |
|
241 | 241 | |
242 | 242 | /** |
243 | 243 | * Filters the responses for single invoice requests. |
@@ -249,9 +249,9 @@ discard block |
||
249 | 249 | * @param WP_HTTP_Response $response Response. |
250 | 250 | * @param WP_REST_Request $request The request used. |
251 | 251 | */ |
252 | - $response = apply_filters( "wpinv_rest_get_invoice_response", $response, $request ); |
|
252 | + $response = apply_filters("wpinv_rest_get_invoice_response", $response, $request); |
|
253 | 253 | |
254 | - return rest_ensure_response( $response ); |
|
254 | + return rest_ensure_response($response); |
|
255 | 255 | |
256 | 256 | } |
257 | 257 | |
@@ -263,18 +263,18 @@ discard block |
||
263 | 263 | * @param WP_REST_Request $request Full details about the request. |
264 | 264 | * @return true|WP_Error True if the request has access to create items, WP_Error object otherwise. |
265 | 265 | */ |
266 | - public function create_item_permissions_check( $request ) { |
|
266 | + public function create_item_permissions_check($request) { |
|
267 | 267 | |
268 | - if ( ! empty( $request['id'] ) ) { |
|
269 | - return new WP_Error( 'rest_invoice_exists', __( 'Cannot create existing invoice.', 'invoicing' ), array( 'status' => 400 ) ); |
|
268 | + if (!empty($request['id'])) { |
|
269 | + return new WP_Error('rest_invoice_exists', __('Cannot create existing invoice.', 'invoicing'), array('status' => 400)); |
|
270 | 270 | } |
271 | 271 | |
272 | - $post_type = get_post_type_object( $this->post_type ); |
|
272 | + $post_type = get_post_type_object($this->post_type); |
|
273 | 273 | |
274 | - if ( ! current_user_can( $post_type->cap->create_posts ) ) { |
|
274 | + if (!current_user_can($post_type->cap->create_posts)) { |
|
275 | 275 | return new WP_Error( |
276 | 276 | 'rest_cannot_create', |
277 | - __( 'Sorry, you are not allowed to create invoices as this user.', 'invoicing' ), |
|
277 | + __('Sorry, you are not allowed to create invoices as this user.', 'invoicing'), |
|
278 | 278 | array( |
279 | 279 | 'status' => rest_authorization_required_code(), |
280 | 280 | ) |
@@ -292,30 +292,30 @@ discard block |
||
292 | 292 | * @param WP_REST_Request $request Full details about the request. |
293 | 293 | * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. |
294 | 294 | */ |
295 | - public function create_item( $request ) { |
|
295 | + public function create_item($request) { |
|
296 | 296 | |
297 | - if ( ! empty( $request['id'] ) ) { |
|
298 | - return new WP_Error( 'rest_invoice_exists', __( 'Cannot create existing invoice.', 'invoicing' ), array( 'status' => 400 ) ); |
|
297 | + if (!empty($request['id'])) { |
|
298 | + return new WP_Error('rest_invoice_exists', __('Cannot create existing invoice.', 'invoicing'), array('status' => 400)); |
|
299 | 299 | } |
300 | 300 | |
301 | - $request->set_param( 'context', 'edit' ); |
|
301 | + $request->set_param('context', 'edit'); |
|
302 | 302 | |
303 | 303 | // Prepare the updated data. |
304 | - $invoice_data = $this->prepare_item_for_database( $request ); |
|
304 | + $invoice_data = $this->prepare_item_for_database($request); |
|
305 | 305 | |
306 | - if ( is_wp_error( $invoice_data ) ) { |
|
306 | + if (is_wp_error($invoice_data)) { |
|
307 | 307 | return $invoice_data; |
308 | 308 | } |
309 | 309 | |
310 | 310 | // Try creating the invoice |
311 | - $invoice = wpinv_insert_invoice( $invoice_data, true ); |
|
311 | + $invoice = wpinv_insert_invoice($invoice_data, true); |
|
312 | 312 | |
313 | - if ( is_wp_error( $invoice ) ) { |
|
313 | + if (is_wp_error($invoice)) { |
|
314 | 314 | return $invoice; |
315 | 315 | } |
316 | 316 | |
317 | 317 | // Prepare the response |
318 | - $response = $this->prepare_item_for_response( $invoice, $request ); |
|
318 | + $response = $this->prepare_item_for_response($invoice, $request); |
|
319 | 319 | |
320 | 320 | /** |
321 | 321 | * Fires after a single invoice is created or updated via the REST API. |
@@ -326,7 +326,7 @@ discard block |
||
326 | 326 | * @param WP_REST_Request $request Request object. |
327 | 327 | * @param bool $creating True when creating a post, false when updating. |
328 | 328 | */ |
329 | - do_action( "wpinv_rest_insert_invoice", $invoice, $request, true ); |
|
329 | + do_action("wpinv_rest_insert_invoice", $invoice, $request, true); |
|
330 | 330 | |
331 | 331 | /** |
332 | 332 | * Filters the responses for creating single invoice requests. |
@@ -338,9 +338,9 @@ discard block |
||
338 | 338 | * @param array $invoice_data Invoice properties. |
339 | 339 | * @param WP_REST_Request $request The request used. |
340 | 340 | */ |
341 | - $response = apply_filters( "wpinv_rest_create_invoice_response", $response, $request ); |
|
341 | + $response = apply_filters("wpinv_rest_create_invoice_response", $response, $request); |
|
342 | 342 | |
343 | - return rest_ensure_response( $response ); |
|
343 | + return rest_ensure_response($response); |
|
344 | 344 | } |
345 | 345 | |
346 | 346 | /** |
@@ -351,20 +351,20 @@ discard block |
||
351 | 351 | * @param WP_REST_Request $request Full details about the request. |
352 | 352 | * @return true|WP_Error True if the request has access to update the item, WP_Error object otherwise. |
353 | 353 | */ |
354 | - public function update_item_permissions_check( $request ) { |
|
354 | + public function update_item_permissions_check($request) { |
|
355 | 355 | |
356 | 356 | // Retrieve the invoice. |
357 | - $invoice = $this->get_post( $request['id'] ); |
|
358 | - if ( is_wp_error( $invoice ) ) { |
|
357 | + $invoice = $this->get_post($request['id']); |
|
358 | + if (is_wp_error($invoice)) { |
|
359 | 359 | return $invoice; |
360 | 360 | } |
361 | 361 | |
362 | - $post_type = get_post_type_object( $this->post_type ); |
|
362 | + $post_type = get_post_type_object($this->post_type); |
|
363 | 363 | |
364 | - if ( ! current_user_can( $post_type->cap->edit_post, $invoice->ID ) ) { |
|
364 | + if (!current_user_can($post_type->cap->edit_post, $invoice->ID)) { |
|
365 | 365 | return new WP_Error( |
366 | 366 | 'rest_cannot_edit', |
367 | - __( 'Sorry, you are not allowed to update this invoice.', 'invoicing' ), |
|
367 | + __('Sorry, you are not allowed to update this invoice.', 'invoicing'), |
|
368 | 368 | array( |
369 | 369 | 'status' => rest_authorization_required_code(), |
370 | 370 | ) |
@@ -382,46 +382,46 @@ discard block |
||
382 | 382 | * @param WP_REST_Request $request Full details about the request. |
383 | 383 | * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. |
384 | 384 | */ |
385 | - public function update_item( $request ) { |
|
385 | + public function update_item($request) { |
|
386 | 386 | |
387 | 387 | // Ensure the invoice exists. |
388 | - $valid_check = $this->get_post( $request['id'] ); |
|
388 | + $valid_check = $this->get_post($request['id']); |
|
389 | 389 | |
390 | 390 | // Abort early if it does not exist |
391 | - if ( is_wp_error( $valid_check ) ) { |
|
391 | + if (is_wp_error($valid_check)) { |
|
392 | 392 | return $valid_check; |
393 | 393 | } |
394 | 394 | |
395 | - $request->set_param( 'context', 'edit' ); |
|
395 | + $request->set_param('context', 'edit'); |
|
396 | 396 | |
397 | 397 | // Prepare the updated data. |
398 | - $data_to_update = $this->prepare_item_for_database( $request ); |
|
398 | + $data_to_update = $this->prepare_item_for_database($request); |
|
399 | 399 | |
400 | - if ( is_wp_error( $data_to_update ) ) { |
|
400 | + if (is_wp_error($data_to_update)) { |
|
401 | 401 | return $data_to_update; |
402 | 402 | } |
403 | 403 | |
404 | 404 | // Abort if no invoice data is provided |
405 | - if( empty( $data_to_update ) ) { |
|
406 | - return new WP_Error( 'missing_data', __( 'An update request cannot be empty.', 'invoicing' ) ); |
|
405 | + if (empty($data_to_update)) { |
|
406 | + return new WP_Error('missing_data', __('An update request cannot be empty.', 'invoicing')); |
|
407 | 407 | } |
408 | 408 | |
409 | 409 | // Include the invoice ID |
410 | 410 | $data_to_update['ID'] = $request['id']; |
411 | 411 | |
412 | 412 | // Update the invoice |
413 | - $updated_invoice = wpinv_update_invoice( $data_to_update, true ); |
|
413 | + $updated_invoice = wpinv_update_invoice($data_to_update, true); |
|
414 | 414 | |
415 | 415 | // Incase the update operation failed... |
416 | - if ( is_wp_error( $updated_invoice ) ) { |
|
416 | + if (is_wp_error($updated_invoice)) { |
|
417 | 417 | return $updated_invoice; |
418 | 418 | } |
419 | 419 | |
420 | 420 | // Prepare the response |
421 | - $response = $this->prepare_item_for_response( $updated_invoice, $request ); |
|
421 | + $response = $this->prepare_item_for_response($updated_invoice, $request); |
|
422 | 422 | |
423 | 423 | /** This action is documented in includes/class-wpinv-rest-invoice-controller.php */ |
424 | - do_action( "wpinv_rest_insert_invoice", $updated_invoice, $request, false ); |
|
424 | + do_action("wpinv_rest_insert_invoice", $updated_invoice, $request, false); |
|
425 | 425 | |
426 | 426 | /** |
427 | 427 | * Filters the responses for updating single invoice requests. |
@@ -433,9 +433,9 @@ discard block |
||
433 | 433 | * @param array $invoice_data Invoice properties. |
434 | 434 | * @param WP_REST_Request $request The request used. |
435 | 435 | */ |
436 | - $response = apply_filters( "wpinv_rest_update_invoice_response", $response, $request ); |
|
436 | + $response = apply_filters("wpinv_rest_update_invoice_response", $response, $request); |
|
437 | 437 | |
438 | - return rest_ensure_response( $response ); |
|
438 | + return rest_ensure_response($response); |
|
439 | 439 | } |
440 | 440 | |
441 | 441 | /** |
@@ -446,19 +446,19 @@ discard block |
||
446 | 446 | * @param WP_REST_Request $request Full details about the request. |
447 | 447 | * @return true|WP_Error True if the request has access to delete the invoice, WP_Error object otherwise. |
448 | 448 | */ |
449 | - public function delete_item_permissions_check( $request ) { |
|
449 | + public function delete_item_permissions_check($request) { |
|
450 | 450 | |
451 | 451 | // Retrieve the invoice. |
452 | - $invoice = $this->get_post( $request['id'] ); |
|
453 | - if ( is_wp_error( $invoice ) ) { |
|
452 | + $invoice = $this->get_post($request['id']); |
|
453 | + if (is_wp_error($invoice)) { |
|
454 | 454 | return $invoice; |
455 | 455 | } |
456 | 456 | |
457 | 457 | // Ensure the current user can delete invoices |
458 | - if ( wpinv_current_user_can_manage_invoicing() || current_user_can( 'delete_invoices', $request['id'] ) ) { |
|
458 | + if (wpinv_current_user_can_manage_invoicing() || current_user_can('delete_invoices', $request['id'])) { |
|
459 | 459 | return new WP_Error( |
460 | 460 | 'rest_cannot_delete', |
461 | - __( 'Sorry, you are not allowed to delete this invoice.', 'invoicing' ), |
|
461 | + __('Sorry, you are not allowed to delete this invoice.', 'invoicing'), |
|
462 | 462 | array( |
463 | 463 | 'status' => rest_authorization_required_code(), |
464 | 464 | ) |
@@ -476,31 +476,31 @@ discard block |
||
476 | 476 | * @param WP_REST_Request $request Full details about the request. |
477 | 477 | * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. |
478 | 478 | */ |
479 | - public function delete_item( $request ) { |
|
479 | + public function delete_item($request) { |
|
480 | 480 | |
481 | 481 | // Retrieve the invoice. |
482 | - $invoice = $this->get_post( $request['id'] ); |
|
483 | - if ( is_wp_error( $invoice ) ) { |
|
482 | + $invoice = $this->get_post($request['id']); |
|
483 | + if (is_wp_error($invoice)) { |
|
484 | 484 | return $invoice; |
485 | 485 | } |
486 | 486 | |
487 | - $request->set_param( 'context', 'edit' ); |
|
487 | + $request->set_param('context', 'edit'); |
|
488 | 488 | |
489 | 489 | // Prepare the invoice id |
490 | - $id = $invoice->ID; |
|
490 | + $id = $invoice->ID; |
|
491 | 491 | |
492 | 492 | // Prepare the response |
493 | - $response = $this->prepare_item_for_response( $invoice, $request ); |
|
493 | + $response = $this->prepare_item_for_response($invoice, $request); |
|
494 | 494 | |
495 | 495 | // Check if the user wants to bypass the trash... |
496 | 496 | $force_delete = (bool) $request['force']; |
497 | 497 | |
498 | 498 | // Try deleting the invoice. |
499 | - $deleted = wp_delete_post( $id, $force_delete ); |
|
499 | + $deleted = wp_delete_post($id, $force_delete); |
|
500 | 500 | |
501 | 501 | // Abort early if we can't delete the invoice. |
502 | - if ( ! $deleted ) { |
|
503 | - return new WP_Error( 'rest_cannot_delete', __( 'The invoice cannot be deleted.', 'invoicing' ), array( 'status' => 500 ) ); |
|
502 | + if (!$deleted) { |
|
503 | + return new WP_Error('rest_cannot_delete', __('The invoice cannot be deleted.', 'invoicing'), array('status' => 500)); |
|
504 | 504 | } |
505 | 505 | |
506 | 506 | /** |
@@ -512,7 +512,7 @@ discard block |
||
512 | 512 | * @param WPInv_Invoice $invoice The deleted or trashed invoice. |
513 | 513 | * @param WP_REST_Request $request The request sent to the API. |
514 | 514 | */ |
515 | - do_action( "wpinv_rest_delete_invoice", $invoice, $request ); |
|
515 | + do_action("wpinv_rest_delete_invoice", $invoice, $request); |
|
516 | 516 | |
517 | 517 | return $response; |
518 | 518 | |
@@ -528,43 +528,43 @@ discard block |
||
528 | 528 | */ |
529 | 529 | public function get_collection_params() { |
530 | 530 | |
531 | - $query_params = array( |
|
531 | + $query_params = array( |
|
532 | 532 | |
533 | 533 | // Invoice status. |
534 | 534 | 'status' => array( |
535 | 535 | 'default' => 'publish', |
536 | - 'description' => __( 'Limit result set to invoices assigned one or more statuses.', 'invoicing' ), |
|
536 | + 'description' => __('Limit result set to invoices assigned one or more statuses.', 'invoicing'), |
|
537 | 537 | 'type' => 'array', |
538 | 538 | 'items' => array( |
539 | - 'enum' => array_keys( wpinv_get_invoice_statuses( true, true ) ), |
|
539 | + 'enum' => array_keys(wpinv_get_invoice_statuses(true, true)), |
|
540 | 540 | 'type' => 'string', |
541 | 541 | ), |
542 | - 'sanitize_callback' => array( $this, 'sanitize_post_statuses' ), |
|
542 | + 'sanitize_callback' => array($this, 'sanitize_post_statuses'), |
|
543 | 543 | ), |
544 | 544 | |
545 | 545 | // User. |
546 | 546 | 'user' => array( |
547 | - 'description' => __( 'Limit result set to invoices for a specif user.', 'invoicing' ), |
|
547 | + 'description' => __('Limit result set to invoices for a specif user.', 'invoicing'), |
|
548 | 548 | 'type' => 'integer', |
549 | 549 | ), |
550 | 550 | |
551 | 551 | // Number of results per page |
552 | 552 | 'limit' => array( |
553 | - 'description' => __( 'Number of invoices to fetch.', 'invoicing' ), |
|
553 | + 'description' => __('Number of invoices to fetch.', 'invoicing'), |
|
554 | 554 | 'type' => 'integer', |
555 | - 'default' => (int) get_option( 'posts_per_page' ), |
|
555 | + 'default' => (int) get_option('posts_per_page'), |
|
556 | 556 | ), |
557 | 557 | |
558 | 558 | // Pagination |
559 | 559 | 'page' => array( |
560 | - 'description' => __( 'Current page to fetch.', 'invoicing' ), |
|
560 | + 'description' => __('Current page to fetch.', 'invoicing'), |
|
561 | 561 | 'type' => 'integer', |
562 | 562 | 'default' => 1, |
563 | 563 | ), |
564 | 564 | |
565 | 565 | // Exclude certain invoices |
566 | 566 | 'exclude' => array( |
567 | - 'description' => __( 'Ensure result set excludes specific IDs.', 'invoicing' ), |
|
567 | + 'description' => __('Ensure result set excludes specific IDs.', 'invoicing'), |
|
568 | 568 | 'type' => 'array', |
569 | 569 | 'items' => array( |
570 | 570 | 'type' => 'integer', |
@@ -574,7 +574,7 @@ discard block |
||
574 | 574 | |
575 | 575 | // Order invoices by |
576 | 576 | 'orderby' => array( |
577 | - 'description' => __( 'Sort invoices by object attribute.', 'invoicing' ), |
|
577 | + 'description' => __('Sort invoices by object attribute.', 'invoicing'), |
|
578 | 578 | 'type' => 'string', |
579 | 579 | 'default' => 'date', |
580 | 580 | 'enum' => array( |
@@ -588,10 +588,10 @@ discard block |
||
588 | 588 | |
589 | 589 | // How to order |
590 | 590 | 'order' => array( |
591 | - 'description' => __( 'Order sort attribute ascending or descending.', 'invoicing' ), |
|
591 | + 'description' => __('Order sort attribute ascending or descending.', 'invoicing'), |
|
592 | 592 | 'type' => 'string', |
593 | 593 | 'default' => 'DESC', |
594 | - 'enum' => array( 'ASC', 'DESC' ), |
|
594 | + 'enum' => array('ASC', 'DESC'), |
|
595 | 595 | ), |
596 | 596 | ); |
597 | 597 | |
@@ -603,7 +603,7 @@ discard block |
||
603 | 603 | * |
604 | 604 | * @param array $query_params JSON Schema-formatted collection parameters. |
605 | 605 | */ |
606 | - return apply_filters( "wpinv_rest_invoices_collection_params", $query_params ); |
|
606 | + return apply_filters("wpinv_rest_invoices_collection_params", $query_params); |
|
607 | 607 | } |
608 | 608 | |
609 | 609 | /** |
@@ -614,7 +614,7 @@ discard block |
||
614 | 614 | * @param object|string $post_type Post type name or object. |
615 | 615 | * @return bool Whether the post type is allowed in REST. |
616 | 616 | */ |
617 | - protected function check_is_post_type_allowed( $post_type ) { |
|
617 | + protected function check_is_post_type_allowed($post_type) { |
|
618 | 618 | return true; |
619 | 619 | } |
620 | 620 | |
@@ -626,49 +626,49 @@ discard block |
||
626 | 626 | * @param WP_REST_Request $request Request object. |
627 | 627 | * @return array|WP_Error Invoice Properties or WP_Error. |
628 | 628 | */ |
629 | - protected function prepare_item_for_database( $request ) { |
|
629 | + protected function prepare_item_for_database($request) { |
|
630 | 630 | $prepared_invoice = new stdClass(); |
631 | 631 | |
632 | 632 | // Post ID. |
633 | - if ( isset( $request['id'] ) ) { |
|
634 | - $existing_invoice = $this->get_post( $request['id'] ); |
|
635 | - if ( is_wp_error( $existing_invoice ) ) { |
|
633 | + if (isset($request['id'])) { |
|
634 | + $existing_invoice = $this->get_post($request['id']); |
|
635 | + if (is_wp_error($existing_invoice)) { |
|
636 | 636 | return $existing_invoice; |
637 | 637 | } |
638 | 638 | |
639 | - $prepared_invoice->ID = $existing_invoice->ID; |
|
639 | + $prepared_invoice->ID = $existing_invoice->ID; |
|
640 | 640 | $prepared_invoice->invoice_id = $existing_invoice->ID; |
641 | 641 | } |
642 | 642 | |
643 | 643 | $schema = $this->get_item_schema(); |
644 | 644 | |
645 | 645 | // Invoice owner. |
646 | - if ( ! empty( $schema['properties']['user_id'] ) && isset( $request['user_id'] ) ) { |
|
646 | + if (!empty($schema['properties']['user_id']) && isset($request['user_id'])) { |
|
647 | 647 | $prepared_invoice->user_id = (int) $request['user_id']; |
648 | 648 | } |
649 | 649 | |
650 | 650 | // Cart details. |
651 | - if ( ! empty( $schema['properties']['cart_details'] ) && isset( $request['cart_details'] ) ) { |
|
651 | + if (!empty($schema['properties']['cart_details']) && isset($request['cart_details'])) { |
|
652 | 652 | $prepared_invoice->cart_details = (array) $request['cart_details']; |
653 | 653 | } |
654 | 654 | |
655 | 655 | // Invoice status. |
656 | - if ( ! empty( $schema['properties']['status'] ) && isset( $request['status'] ) ) { |
|
656 | + if (!empty($schema['properties']['status']) && isset($request['status'])) { |
|
657 | 657 | |
658 | - if ( in_array( $request['status'], array_keys( wpinv_get_invoice_statuses( true, true ) ), true ) ) { |
|
658 | + if (in_array($request['status'], array_keys(wpinv_get_invoice_statuses(true, true)), true)) { |
|
659 | 659 | $prepared_invoice->status = $request['status']; |
660 | 660 | } |
661 | 661 | |
662 | 662 | } |
663 | 663 | |
664 | 664 | // User info |
665 | - if ( ! empty( $schema['properties']['user_info'] ) && isset( $request['user_info'] ) ) { |
|
665 | + if (!empty($schema['properties']['user_info']) && isset($request['user_info'])) { |
|
666 | 666 | $prepared_invoice->user_info = array(); |
667 | 667 | $user_info = (array) $request['user_info']; |
668 | 668 | |
669 | - foreach( $user_info as $prop => $value ) { |
|
669 | + foreach ($user_info as $prop => $value) { |
|
670 | 670 | |
671 | - if ( ! empty( $schema['properties']['user_info']['properties'][$prop] ) ) { |
|
671 | + if (!empty($schema['properties']['user_info']['properties'][$prop])) { |
|
672 | 672 | |
673 | 673 | $prepared_invoice->user_info[$prop] = $value; |
674 | 674 | |
@@ -679,49 +679,49 @@ discard block |
||
679 | 679 | } |
680 | 680 | |
681 | 681 | // IP |
682 | - if ( ! empty( $schema['properties']['ip'] ) && isset( $request['ip'] ) ) { |
|
682 | + if (!empty($schema['properties']['ip']) && isset($request['ip'])) { |
|
683 | 683 | $prepared_invoice->ip = $request['ip']; |
684 | 684 | } |
685 | 685 | |
686 | 686 | // Payment details |
687 | 687 | $prepared_invoice->payment_details = array(); |
688 | 688 | |
689 | - if ( ! empty( $schema['properties']['gateway'] ) && isset( $request['gateway'] ) ) { |
|
689 | + if (!empty($schema['properties']['gateway']) && isset($request['gateway'])) { |
|
690 | 690 | $prepared_invoice->payment_details['gateway'] = $request['gateway']; |
691 | 691 | } |
692 | 692 | |
693 | - if ( ! empty( $schema['properties']['gateway_title'] ) && isset( $request['gateway_title'] ) ) { |
|
693 | + if (!empty($schema['properties']['gateway_title']) && isset($request['gateway_title'])) { |
|
694 | 694 | $prepared_invoice->payment_details['gateway_title'] = $request['gateway_title']; |
695 | 695 | } |
696 | 696 | |
697 | - if ( ! empty( $schema['properties']['currency'] ) && isset( $request['currency'] ) ) { |
|
697 | + if (!empty($schema['properties']['currency']) && isset($request['currency'])) { |
|
698 | 698 | $prepared_invoice->payment_details['currency'] = $request['currency']; |
699 | 699 | } |
700 | 700 | |
701 | - if ( ! empty( $schema['properties']['transaction_id'] ) && isset( $request['transaction_id'] ) ) { |
|
701 | + if (!empty($schema['properties']['transaction_id']) && isset($request['transaction_id'])) { |
|
702 | 702 | $prepared_invoice->payment_details['transaction_id'] = $request['transaction_id']; |
703 | 703 | } |
704 | 704 | |
705 | 705 | // Dates |
706 | - if ( ! empty( $schema['properties']['date'] ) && isset( $request['date'] ) ) { |
|
707 | - $post_date = rest_get_date_with_gmt( $request['date'] ); |
|
706 | + if (!empty($schema['properties']['date']) && isset($request['date'])) { |
|
707 | + $post_date = rest_get_date_with_gmt($request['date']); |
|
708 | 708 | |
709 | - if ( ! empty( $post_date ) ) { |
|
709 | + if (!empty($post_date)) { |
|
710 | 710 | $prepared_invoice->post_date = $post_date[0]; |
711 | 711 | } |
712 | 712 | |
713 | 713 | } |
714 | 714 | |
715 | - if ( ! empty( $schema['properties']['due_date'] ) && isset( $request['due_date'] ) ) { |
|
716 | - $due_date = rest_get_date_with_gmt( $request['due_date'] ); |
|
715 | + if (!empty($schema['properties']['due_date']) && isset($request['due_date'])) { |
|
716 | + $due_date = rest_get_date_with_gmt($request['due_date']); |
|
717 | 717 | |
718 | - if ( ! empty( $due_date ) ) { |
|
718 | + if (!empty($due_date)) { |
|
719 | 719 | $prepared_invoice->due_date = $due_date[0]; |
720 | 720 | } |
721 | 721 | |
722 | 722 | } |
723 | 723 | |
724 | - $invoice_data = (array) wp_unslash( $prepared_invoice ); |
|
724 | + $invoice_data = (array) wp_unslash($prepared_invoice); |
|
725 | 725 | |
726 | 726 | /** |
727 | 727 | * Filters an invoice before it is inserted via the REST API. |
@@ -731,7 +731,7 @@ discard block |
||
731 | 731 | * @param array $invoice_data An array of invoice data |
732 | 732 | * @param WP_REST_Request $request Request object. |
733 | 733 | */ |
734 | - return apply_filters( "wpinv_rest_pre_insert_invoice", $invoice_data, $request ); |
|
734 | + return apply_filters("wpinv_rest_pre_insert_invoice", $invoice_data, $request); |
|
735 | 735 | |
736 | 736 | } |
737 | 737 | |
@@ -744,20 +744,20 @@ discard block |
||
744 | 744 | * @param WP_REST_Request $request Request object. |
745 | 745 | * @return WP_REST_Response Response object. |
746 | 746 | */ |
747 | - public function prepare_item_for_response( $invoice, $request ) { |
|
747 | + public function prepare_item_for_response($invoice, $request) { |
|
748 | 748 | |
749 | - $GLOBALS['post'] = get_post( $invoice->ID ); |
|
749 | + $GLOBALS['post'] = get_post($invoice->ID); |
|
750 | 750 | |
751 | - setup_postdata( $invoice->ID ); |
|
751 | + setup_postdata($invoice->ID); |
|
752 | 752 | |
753 | 753 | // Fetch the fields to include in this response. |
754 | - $fields = $this->get_fields_for_response( $request ); |
|
754 | + $fields = $this->get_fields_for_response($request); |
|
755 | 755 | |
756 | 756 | // Base fields for every invoice. |
757 | 757 | $data = array(); |
758 | 758 | |
759 | 759 | // Set up ID |
760 | - if ( rest_is_field_included( 'id', $fields ) ) { |
|
760 | + if (rest_is_field_included('id', $fields)) { |
|
761 | 761 | $data['id'] = $invoice->ID; |
762 | 762 | } |
763 | 763 | |
@@ -772,74 +772,74 @@ discard block |
||
772 | 772 | 'status', 'status_nicename', 'post_type' |
773 | 773 | ); |
774 | 774 | |
775 | - foreach( $invoice_properties as $property ) { |
|
775 | + foreach ($invoice_properties as $property) { |
|
776 | 776 | |
777 | - if ( rest_is_field_included( $property, $fields ) ) { |
|
778 | - $data[$property] = $invoice->get( $property ); |
|
777 | + if (rest_is_field_included($property, $fields)) { |
|
778 | + $data[$property] = $invoice->get($property); |
|
779 | 779 | } |
780 | 780 | |
781 | 781 | } |
782 | 782 | |
783 | 783 | // Cart details |
784 | - if ( rest_is_field_included( 'cart_details', $fields ) ) { |
|
785 | - $data['cart_details'] = $invoice->get( 'cart_details' ); |
|
784 | + if (rest_is_field_included('cart_details', $fields)) { |
|
785 | + $data['cart_details'] = $invoice->get('cart_details'); |
|
786 | 786 | } |
787 | 787 | |
788 | 788 | //Dates |
789 | - $invoice_properties = array( 'date', 'due_date', 'completed_date' ); |
|
789 | + $invoice_properties = array('date', 'due_date', 'completed_date'); |
|
790 | 790 | |
791 | - foreach( $invoice_properties as $property ) { |
|
791 | + foreach ($invoice_properties as $property) { |
|
792 | 792 | |
793 | - if ( rest_is_field_included( $property, $fields ) ) { |
|
794 | - $data[$property] = $this->prepare_date_response( '0000-00-00 00:00:00', $invoice->get( $property ) ); |
|
793 | + if (rest_is_field_included($property, $fields)) { |
|
794 | + $data[$property] = $this->prepare_date_response('0000-00-00 00:00:00', $invoice->get($property)); |
|
795 | 795 | } |
796 | 796 | |
797 | 797 | } |
798 | 798 | |
799 | 799 | // User id |
800 | - if ( rest_is_field_included( 'user_id', $fields ) ) { |
|
801 | - $data['user_id'] = (int) $invoice->get( 'user_id' ); |
|
800 | + if (rest_is_field_included('user_id', $fields)) { |
|
801 | + $data['user_id'] = (int) $invoice->get('user_id'); |
|
802 | 802 | } |
803 | 803 | |
804 | 804 | // User info |
805 | - $user_info = array( 'first_name', 'last_name', 'company', 'vat_number', 'vat_rate', 'address', 'city', 'country', 'state', 'zip', 'phone' ); |
|
805 | + $user_info = array('first_name', 'last_name', 'company', 'vat_number', 'vat_rate', 'address', 'city', 'country', 'state', 'zip', 'phone'); |
|
806 | 806 | |
807 | - foreach( $user_info as $property ) { |
|
807 | + foreach ($user_info as $property) { |
|
808 | 808 | |
809 | - if ( rest_is_field_included( "user_info.$property", $fields ) ) { |
|
810 | - $data['user_info'][$property] = $invoice->get( $property ); |
|
809 | + if (rest_is_field_included("user_info.$property", $fields)) { |
|
810 | + $data['user_info'][$property] = $invoice->get($property); |
|
811 | 811 | } |
812 | 812 | |
813 | 813 | } |
814 | 814 | |
815 | 815 | // Slug |
816 | - if ( rest_is_field_included( 'slug', $fields ) ) { |
|
817 | - $data['slug'] = $invoice->get( 'post_name' ); |
|
816 | + if (rest_is_field_included('slug', $fields)) { |
|
817 | + $data['slug'] = $invoice->get('post_name'); |
|
818 | 818 | } |
819 | 819 | |
820 | 820 | // View invoice link |
821 | - if ( rest_is_field_included( 'link', $fields ) ) { |
|
822 | - $data['link'] = esc_url( $invoice->get_view_url() ); |
|
821 | + if (rest_is_field_included('link', $fields)) { |
|
822 | + $data['link'] = esc_url($invoice->get_view_url()); |
|
823 | 823 | } |
824 | 824 | |
825 | 825 | |
826 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
827 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
828 | - $data = $this->filter_response_by_context( $data, $context ); |
|
826 | + $context = !empty($request['context']) ? $request['context'] : 'view'; |
|
827 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
828 | + $data = $this->filter_response_by_context($data, $context); |
|
829 | 829 | |
830 | 830 | // Wrap the data in a response object. |
831 | - $response = rest_ensure_response( $data ); |
|
831 | + $response = rest_ensure_response($data); |
|
832 | 832 | |
833 | - $links = $this->prepare_links( $invoice ); |
|
834 | - $response->add_links( $links ); |
|
833 | + $links = $this->prepare_links($invoice); |
|
834 | + $response->add_links($links); |
|
835 | 835 | |
836 | - if ( ! empty( $links['self']['href'] ) ) { |
|
837 | - $actions = $this->get_available_actions( $invoice, $request ); |
|
836 | + if (!empty($links['self']['href'])) { |
|
837 | + $actions = $this->get_available_actions($invoice, $request); |
|
838 | 838 | |
839 | 839 | $self = $links['self']['href']; |
840 | 840 | |
841 | - foreach ( $actions as $rel ) { |
|
842 | - $response->add_link( $rel, $self ); |
|
841 | + foreach ($actions as $rel) { |
|
842 | + $response->add_link($rel, $self); |
|
843 | 843 | } |
844 | 844 | } |
845 | 845 | |
@@ -852,7 +852,7 @@ discard block |
||
852 | 852 | * @param WPInv_Invoice $invoice The invoice object. |
853 | 853 | * @param WP_REST_Request $request Request object. |
854 | 854 | */ |
855 | - return apply_filters( "wpinv_rest_prepare_invoice", $response, $invoice, $request ); |
|
855 | + return apply_filters("wpinv_rest_prepare_invoice", $response, $invoice, $request); |
|
856 | 856 | } |
857 | 857 | |
858 | 858 | /** |
@@ -865,57 +865,57 @@ discard block |
||
865 | 865 | * @param WP_REST_Request $request Full details about the request. |
866 | 866 | * @return array Fields to be included in the response. |
867 | 867 | */ |
868 | - public function get_fields_for_response( $request ) { |
|
868 | + public function get_fields_for_response($request) { |
|
869 | 869 | $schema = $this->get_item_schema(); |
870 | - $properties = isset( $schema['properties'] ) ? $schema['properties'] : array(); |
|
870 | + $properties = isset($schema['properties']) ? $schema['properties'] : array(); |
|
871 | 871 | |
872 | 872 | $additional_fields = $this->get_additional_fields(); |
873 | - foreach ( $additional_fields as $field_name => $field_options ) { |
|
873 | + foreach ($additional_fields as $field_name => $field_options) { |
|
874 | 874 | // For back-compat, include any field with an empty schema |
875 | 875 | // because it won't be present in $this->get_item_schema(). |
876 | - if ( is_null( $field_options['schema'] ) ) { |
|
877 | - $properties[ $field_name ] = $field_options; |
|
876 | + if (is_null($field_options['schema'])) { |
|
877 | + $properties[$field_name] = $field_options; |
|
878 | 878 | } |
879 | 879 | } |
880 | 880 | |
881 | 881 | // Exclude fields that specify a different context than the request context. |
882 | 882 | $context = $request['context']; |
883 | - if ( $context ) { |
|
884 | - foreach ( $properties as $name => $options ) { |
|
885 | - if ( ! empty( $options['context'] ) && ! in_array( $context, $options['context'], true ) ) { |
|
886 | - unset( $properties[ $name ] ); |
|
883 | + if ($context) { |
|
884 | + foreach ($properties as $name => $options) { |
|
885 | + if (!empty($options['context']) && !in_array($context, $options['context'], true)) { |
|
886 | + unset($properties[$name]); |
|
887 | 887 | } |
888 | 888 | } |
889 | 889 | } |
890 | 890 | |
891 | - $fields = array_keys( $properties ); |
|
891 | + $fields = array_keys($properties); |
|
892 | 892 | |
893 | - if ( ! isset( $request['_fields'] ) ) { |
|
893 | + if (!isset($request['_fields'])) { |
|
894 | 894 | return $fields; |
895 | 895 | } |
896 | - $requested_fields = wpinv_parse_list( $request['_fields'] ); |
|
897 | - if ( 0 === count( $requested_fields ) ) { |
|
896 | + $requested_fields = wpinv_parse_list($request['_fields']); |
|
897 | + if (0 === count($requested_fields)) { |
|
898 | 898 | return $fields; |
899 | 899 | } |
900 | 900 | // Trim off outside whitespace from the comma delimited list. |
901 | - $requested_fields = array_map( 'trim', $requested_fields ); |
|
901 | + $requested_fields = array_map('trim', $requested_fields); |
|
902 | 902 | // Always persist 'id', because it can be needed for add_additional_fields_to_object(). |
903 | - if ( in_array( 'id', $fields, true ) ) { |
|
903 | + if (in_array('id', $fields, true)) { |
|
904 | 904 | $requested_fields[] = 'id'; |
905 | 905 | } |
906 | 906 | // Return the list of all requested fields which appear in the schema. |
907 | 907 | return array_reduce( |
908 | 908 | $requested_fields, |
909 | - function( $response_fields, $field ) use ( $fields ) { |
|
910 | - if ( in_array( $field, $fields, true ) ) { |
|
909 | + function($response_fields, $field) use ($fields) { |
|
910 | + if (in_array($field, $fields, true)) { |
|
911 | 911 | $response_fields[] = $field; |
912 | 912 | return $response_fields; |
913 | 913 | } |
914 | 914 | // Check for nested fields if $field is not a direct match. |
915 | - $nested_fields = explode( '.', $field ); |
|
915 | + $nested_fields = explode('.', $field); |
|
916 | 916 | // A nested field is included so long as its top-level property is |
917 | 917 | // present in the schema. |
918 | - if ( in_array( $nested_fields[0], $fields, true ) ) { |
|
918 | + if (in_array($nested_fields[0], $fields, true)) { |
|
919 | 919 | $response_fields[] = $field; |
920 | 920 | } |
921 | 921 | return $response_fields; |
@@ -934,8 +934,8 @@ discard block |
||
934 | 934 | public function get_item_schema() { |
935 | 935 | |
936 | 936 | // Maybe retrieve the schema from cache. |
937 | - if ( $this->schema ) { |
|
938 | - return $this->add_additional_fields_schema( $this->schema ); |
|
937 | + if ($this->schema) { |
|
938 | + return $this->add_additional_fields_schema($this->schema); |
|
939 | 939 | } |
940 | 940 | |
941 | 941 | $schema = array( |
@@ -947,266 +947,266 @@ discard block |
||
947 | 947 | 'properties' => array( |
948 | 948 | |
949 | 949 | 'title' => array( |
950 | - 'description' => __( 'The title for the invoice.', 'invoicing' ), |
|
950 | + 'description' => __('The title for the invoice.', 'invoicing'), |
|
951 | 951 | 'type' => 'string', |
952 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
952 | + 'context' => array('view', 'edit', 'embed'), |
|
953 | 953 | 'readonly' => true, |
954 | 954 | ), |
955 | 955 | |
956 | 956 | 'user_id' => array( |
957 | - 'description' => __( 'The ID of the owner of the invoice.', 'invoicing' ), |
|
957 | + 'description' => __('The ID of the owner of the invoice.', 'invoicing'), |
|
958 | 958 | 'type' => 'integer', |
959 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
959 | + 'context' => array('view', 'edit', 'embed'), |
|
960 | 960 | ), |
961 | 961 | |
962 | 962 | 'email' => array( |
963 | - 'description' => __( 'The email of the owner of the invoice.', 'invoicing' ), |
|
963 | + 'description' => __('The email of the owner of the invoice.', 'invoicing'), |
|
964 | 964 | 'type' => 'string', |
965 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
965 | + 'context' => array('view', 'edit', 'embed'), |
|
966 | 966 | 'readonly' => true, |
967 | 967 | ), |
968 | 968 | |
969 | 969 | 'ip' => array( |
970 | - 'description' => __( 'The IP of the owner of the invoice.', 'invoicing' ), |
|
970 | + 'description' => __('The IP of the owner of the invoice.', 'invoicing'), |
|
971 | 971 | 'type' => 'string', |
972 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
972 | + 'context' => array('view', 'edit', 'embed'), |
|
973 | 973 | ), |
974 | 974 | |
975 | 975 | 'user_info' => array( |
976 | - 'description' => __( 'Information about the owner of the invoice.', 'invoicing' ), |
|
976 | + 'description' => __('Information about the owner of the invoice.', 'invoicing'), |
|
977 | 977 | 'type' => 'object', |
978 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
978 | + 'context' => array('view', 'edit', 'embed'), |
|
979 | 979 | 'properties' => array( |
980 | 980 | |
981 | 981 | 'first_name' => array( |
982 | - 'description' => __( 'The first name of the owner of the invoice.', 'invoicing' ), |
|
982 | + 'description' => __('The first name of the owner of the invoice.', 'invoicing'), |
|
983 | 983 | 'type' => 'string', |
984 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
984 | + 'context' => array('view', 'edit', 'embed'), |
|
985 | 985 | ), |
986 | 986 | |
987 | 987 | 'last_name' => array( |
988 | - 'description' => __( 'The last name of the owner of the invoice.', 'invoicing' ), |
|
988 | + 'description' => __('The last name of the owner of the invoice.', 'invoicing'), |
|
989 | 989 | 'type' => 'string', |
990 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
990 | + 'context' => array('view', 'edit', 'embed'), |
|
991 | 991 | ), |
992 | 992 | |
993 | 993 | 'company' => array( |
994 | - 'description' => __( 'The company of the owner of the invoice.', 'invoicing' ), |
|
994 | + 'description' => __('The company of the owner of the invoice.', 'invoicing'), |
|
995 | 995 | 'type' => 'string', |
996 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
996 | + 'context' => array('view', 'edit', 'embed'), |
|
997 | 997 | ), |
998 | 998 | |
999 | 999 | 'vat_number' => array( |
1000 | - 'description' => __( 'The VAT number of the owner of the invoice.', 'invoicing' ), |
|
1000 | + 'description' => __('The VAT number of the owner of the invoice.', 'invoicing'), |
|
1001 | 1001 | 'type' => 'string', |
1002 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1002 | + 'context' => array('view', 'edit', 'embed'), |
|
1003 | 1003 | ), |
1004 | 1004 | |
1005 | 1005 | 'vat_rate' => array( |
1006 | - 'description' => __( 'The VAT rate applied on the invoice.', 'invoicing' ), |
|
1006 | + 'description' => __('The VAT rate applied on the invoice.', 'invoicing'), |
|
1007 | 1007 | 'type' => 'string', |
1008 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1008 | + 'context' => array('view', 'edit', 'embed'), |
|
1009 | 1009 | ), |
1010 | 1010 | |
1011 | 1011 | 'address' => array( |
1012 | - 'description' => __( 'The address of the invoice owner.', 'invoicing' ), |
|
1012 | + 'description' => __('The address of the invoice owner.', 'invoicing'), |
|
1013 | 1013 | 'type' => 'string', |
1014 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1014 | + 'context' => array('view', 'edit', 'embed'), |
|
1015 | 1015 | ), |
1016 | 1016 | |
1017 | 1017 | 'city' => array( |
1018 | - 'description' => __( 'The city of the invoice owner.', 'invoicing' ), |
|
1018 | + 'description' => __('The city of the invoice owner.', 'invoicing'), |
|
1019 | 1019 | 'type' => 'string', |
1020 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1020 | + 'context' => array('view', 'edit', 'embed'), |
|
1021 | 1021 | ), |
1022 | 1022 | |
1023 | 1023 | 'country' => array( |
1024 | - 'description' => __( 'The country of the invoice owner.', 'invoicing' ), |
|
1024 | + 'description' => __('The country of the invoice owner.', 'invoicing'), |
|
1025 | 1025 | 'type' => 'string', |
1026 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1026 | + 'context' => array('view', 'edit', 'embed'), |
|
1027 | 1027 | ), |
1028 | 1028 | |
1029 | 1029 | 'state' => array( |
1030 | - 'description' => __( 'The state of the invoice owner.', 'invoicing' ), |
|
1030 | + 'description' => __('The state of the invoice owner.', 'invoicing'), |
|
1031 | 1031 | 'type' => 'string', |
1032 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1032 | + 'context' => array('view', 'edit', 'embed'), |
|
1033 | 1033 | ), |
1034 | 1034 | |
1035 | 1035 | 'zip' => array( |
1036 | - 'description' => __( 'The zip code of the invoice owner.', 'invoicing' ), |
|
1036 | + 'description' => __('The zip code of the invoice owner.', 'invoicing'), |
|
1037 | 1037 | 'type' => 'string', |
1038 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1038 | + 'context' => array('view', 'edit', 'embed'), |
|
1039 | 1039 | ), |
1040 | 1040 | |
1041 | 1041 | 'phone' => array( |
1042 | - 'description' => __( 'The phone number of the invoice owner.', 'invoicing' ), |
|
1042 | + 'description' => __('The phone number of the invoice owner.', 'invoicing'), |
|
1043 | 1043 | 'type' => 'string', |
1044 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1044 | + 'context' => array('view', 'edit', 'embed'), |
|
1045 | 1045 | ), |
1046 | 1046 | ), |
1047 | 1047 | ), |
1048 | 1048 | |
1049 | 1049 | 'id' => array( |
1050 | - 'description' => __( 'Unique identifier for the invoice.', 'invoicing' ), |
|
1050 | + 'description' => __('Unique identifier for the invoice.', 'invoicing'), |
|
1051 | 1051 | 'type' => 'integer', |
1052 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1052 | + 'context' => array('view', 'edit', 'embed'), |
|
1053 | 1053 | 'readonly' => true, |
1054 | 1054 | ), |
1055 | 1055 | |
1056 | 1056 | 'key' => array( |
1057 | - 'description' => __( 'A unique key for the invoice.', 'invoicing' ), |
|
1057 | + 'description' => __('A unique key for the invoice.', 'invoicing'), |
|
1058 | 1058 | 'type' => 'string', |
1059 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1059 | + 'context' => array('view', 'edit', 'embed'), |
|
1060 | 1060 | 'readonly' => true, |
1061 | 1061 | ), |
1062 | 1062 | |
1063 | 1063 | 'number' => array( |
1064 | - 'description' => __( 'The invoice number.', 'invoicing' ), |
|
1064 | + 'description' => __('The invoice number.', 'invoicing'), |
|
1065 | 1065 | 'type' => 'string', |
1066 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1066 | + 'context' => array('view', 'edit', 'embed'), |
|
1067 | 1067 | 'readonly' => true, |
1068 | 1068 | ), |
1069 | 1069 | |
1070 | 1070 | 'transaction_id' => array( |
1071 | - 'description' => __( 'The transaction id of the invoice.', 'invoicing' ), |
|
1071 | + 'description' => __('The transaction id of the invoice.', 'invoicing'), |
|
1072 | 1072 | 'type' => 'string', |
1073 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1073 | + 'context' => array('view', 'edit', 'embed'), |
|
1074 | 1074 | ), |
1075 | 1075 | |
1076 | 1076 | 'gateway' => array( |
1077 | - 'description' => __( 'The gateway used to process the invoice.', 'invoicing' ), |
|
1077 | + 'description' => __('The gateway used to process the invoice.', 'invoicing'), |
|
1078 | 1078 | 'type' => 'string', |
1079 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1079 | + 'context' => array('view', 'edit', 'embed'), |
|
1080 | 1080 | ), |
1081 | 1081 | |
1082 | 1082 | 'gateway_title' => array( |
1083 | - 'description' => __( 'The title of the gateway used to process the invoice.', 'invoicing' ), |
|
1083 | + 'description' => __('The title of the gateway used to process the invoice.', 'invoicing'), |
|
1084 | 1084 | 'type' => 'string', |
1085 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1085 | + 'context' => array('view', 'edit', 'embed'), |
|
1086 | 1086 | ), |
1087 | 1087 | |
1088 | 1088 | 'total' => array( |
1089 | - 'description' => __( 'The total amount of the invoice.', 'invoicing' ), |
|
1089 | + 'description' => __('The total amount of the invoice.', 'invoicing'), |
|
1090 | 1090 | 'type' => 'number', |
1091 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1091 | + 'context' => array('view', 'edit', 'embed'), |
|
1092 | 1092 | 'readonly' => true, |
1093 | 1093 | ), |
1094 | 1094 | |
1095 | 1095 | 'discount' => array( |
1096 | - 'description' => __( 'The discount applied to the invoice.', 'invoicing' ), |
|
1096 | + 'description' => __('The discount applied to the invoice.', 'invoicing'), |
|
1097 | 1097 | 'type' => 'number', |
1098 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1098 | + 'context' => array('view', 'edit', 'embed'), |
|
1099 | 1099 | 'readonly' => true, |
1100 | 1100 | ), |
1101 | 1101 | |
1102 | 1102 | 'discount_code' => array( |
1103 | - 'description' => __( 'The discount code applied to the invoice.', 'invoicing' ), |
|
1103 | + 'description' => __('The discount code applied to the invoice.', 'invoicing'), |
|
1104 | 1104 | 'type' => 'string', |
1105 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1105 | + 'context' => array('view', 'edit', 'embed'), |
|
1106 | 1106 | 'readonly' => true, |
1107 | 1107 | ), |
1108 | 1108 | |
1109 | 1109 | 'tax' => array( |
1110 | - 'description' => __( 'The tax applied to the invoice.', 'invoicing' ), |
|
1110 | + 'description' => __('The tax applied to the invoice.', 'invoicing'), |
|
1111 | 1111 | 'type' => 'number', |
1112 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1112 | + 'context' => array('view', 'edit', 'embed'), |
|
1113 | 1113 | 'readonly' => true, |
1114 | 1114 | ), |
1115 | 1115 | |
1116 | 1116 | 'fees_total' => array( |
1117 | - 'description' => __( 'The total fees applied to the invoice.', 'invoicing' ), |
|
1117 | + 'description' => __('The total fees applied to the invoice.', 'invoicing'), |
|
1118 | 1118 | 'type' => 'number', |
1119 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1119 | + 'context' => array('view', 'edit', 'embed'), |
|
1120 | 1120 | 'readonly' => true, |
1121 | 1121 | ), |
1122 | 1122 | |
1123 | 1123 | 'subtotal' => array( |
1124 | - 'description' => __( 'The sub-total for the invoice.', 'invoicing' ), |
|
1124 | + 'description' => __('The sub-total for the invoice.', 'invoicing'), |
|
1125 | 1125 | 'type' => 'number', |
1126 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1126 | + 'context' => array('view', 'edit', 'embed'), |
|
1127 | 1127 | 'readonly' => true, |
1128 | 1128 | ), |
1129 | 1129 | |
1130 | 1130 | 'currency' => array( |
1131 | - 'description' => __( 'The currency used to process the invoice.', 'invoicing' ), |
|
1131 | + 'description' => __('The currency used to process the invoice.', 'invoicing'), |
|
1132 | 1132 | 'type' => 'string', |
1133 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1133 | + 'context' => array('view', 'edit', 'embed'), |
|
1134 | 1134 | ), |
1135 | 1135 | |
1136 | 1136 | 'cart_details' => array( |
1137 | - 'description' => __( 'The cart details for invoice.', 'invoicing' ), |
|
1137 | + 'description' => __('The cart details for invoice.', 'invoicing'), |
|
1138 | 1138 | 'type' => 'array', |
1139 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1139 | + 'context' => array('view', 'edit', 'embed'), |
|
1140 | 1140 | 'required' => true, |
1141 | 1141 | ), |
1142 | 1142 | |
1143 | 1143 | 'date' => array( |
1144 | - 'description' => __( "The date the invoice was published, in the site's timezone.", 'invoicing' ), |
|
1145 | - 'type' => array( 'string', 'null' ), |
|
1144 | + 'description' => __("The date the invoice was published, in the site's timezone.", 'invoicing'), |
|
1145 | + 'type' => array('string', 'null'), |
|
1146 | 1146 | 'format' => 'date-time', |
1147 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1147 | + 'context' => array('view', 'edit', 'embed'), |
|
1148 | 1148 | ), |
1149 | 1149 | |
1150 | 1150 | 'due_date' => array( |
1151 | - 'description' => __( 'The due date for the invoice.', 'invoicing' ), |
|
1152 | - 'type' => array( 'string', 'null' ), |
|
1151 | + 'description' => __('The due date for the invoice.', 'invoicing'), |
|
1152 | + 'type' => array('string', 'null'), |
|
1153 | 1153 | 'format' => 'date-time', |
1154 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1154 | + 'context' => array('view', 'edit', 'embed'), |
|
1155 | 1155 | ), |
1156 | 1156 | |
1157 | 1157 | 'completed_date' => array( |
1158 | - 'description' => __( 'The completed date for the invoice.', 'invoicing' ), |
|
1159 | - 'type' => array( 'string', 'null' ), |
|
1158 | + 'description' => __('The completed date for the invoice.', 'invoicing'), |
|
1159 | + 'type' => array('string', 'null'), |
|
1160 | 1160 | 'format' => 'date-time', |
1161 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1161 | + 'context' => array('view', 'edit', 'embed'), |
|
1162 | 1162 | 'readonly' => true, |
1163 | 1163 | ), |
1164 | 1164 | |
1165 | 1165 | 'link' => array( |
1166 | - 'description' => __( 'URL to the invoice.', 'invoicing' ), |
|
1166 | + 'description' => __('URL to the invoice.', 'invoicing'), |
|
1167 | 1167 | 'type' => 'string', |
1168 | 1168 | 'format' => 'uri', |
1169 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1169 | + 'context' => array('view', 'edit', 'embed'), |
|
1170 | 1170 | 'readonly' => true, |
1171 | 1171 | ), |
1172 | 1172 | |
1173 | 1173 | 'mode' => array( |
1174 | - 'description' => __( 'The mode used to process the invoice.', 'invoicing' ), |
|
1174 | + 'description' => __('The mode used to process the invoice.', 'invoicing'), |
|
1175 | 1175 | 'type' => 'string', |
1176 | - 'enum' => array( 'live', 'test' ), |
|
1177 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1176 | + 'enum' => array('live', 'test'), |
|
1177 | + 'context' => array('view', 'edit', 'embed'), |
|
1178 | 1178 | 'readonly' => true, |
1179 | 1179 | ), |
1180 | 1180 | |
1181 | 1181 | 'slug' => array( |
1182 | - 'description' => __( 'An alphanumeric identifier for the invoice.', 'invoicing' ), |
|
1182 | + 'description' => __('An alphanumeric identifier for the invoice.', 'invoicing'), |
|
1183 | 1183 | 'type' => 'string', |
1184 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1184 | + 'context' => array('view', 'edit', 'embed'), |
|
1185 | 1185 | 'arg_options' => array( |
1186 | - 'sanitize_callback' => array( $this, 'sanitize_slug' ), |
|
1186 | + 'sanitize_callback' => array($this, 'sanitize_slug'), |
|
1187 | 1187 | ), |
1188 | 1188 | 'readonly' => true, |
1189 | 1189 | ), |
1190 | 1190 | |
1191 | 1191 | 'status' => array( |
1192 | - 'description' => __( 'A named status for the invoice.', 'invoicing' ), |
|
1192 | + 'description' => __('A named status for the invoice.', 'invoicing'), |
|
1193 | 1193 | 'type' => 'string', |
1194 | - 'enum' => array_keys( wpinv_get_invoice_statuses( true, true ) ), |
|
1195 | - 'context' => array( 'view', 'edit' ), |
|
1194 | + 'enum' => array_keys(wpinv_get_invoice_statuses(true, true)), |
|
1195 | + 'context' => array('view', 'edit'), |
|
1196 | 1196 | 'default' => 'wpi-pending', |
1197 | 1197 | ), |
1198 | 1198 | |
1199 | 1199 | 'status_nicename' => array( |
1200 | - 'description' => __( 'A human-readable status name for the invoice.', 'invoicing' ), |
|
1200 | + 'description' => __('A human-readable status name for the invoice.', 'invoicing'), |
|
1201 | 1201 | 'type' => 'string', |
1202 | - 'context' => array( 'view', 'embed' ), |
|
1202 | + 'context' => array('view', 'embed'), |
|
1203 | 1203 | 'readonly' => true, |
1204 | 1204 | ), |
1205 | 1205 | |
1206 | 1206 | 'post_type' => array( |
1207 | - 'description' => __( 'The post type for the invoice.', 'invoicing' ), |
|
1207 | + 'description' => __('The post type for the invoice.', 'invoicing'), |
|
1208 | 1208 | 'type' => 'string', |
1209 | - 'context' => array( 'view' ), |
|
1209 | + 'context' => array('view'), |
|
1210 | 1210 | 'readonly' => true, |
1211 | 1211 | ), |
1212 | 1212 | ), |
@@ -1224,12 +1224,12 @@ discard block |
||
1224 | 1224 | * |
1225 | 1225 | * @param array $schema The invoice schema. |
1226 | 1226 | */ |
1227 | - $schema = apply_filters( "wpinv_rest_invoice_schema", $schema ); |
|
1227 | + $schema = apply_filters("wpinv_rest_invoice_schema", $schema); |
|
1228 | 1228 | |
1229 | 1229 | // Cache the invoice schema. |
1230 | 1230 | $this->schema = $schema; |
1231 | 1231 | |
1232 | - return $this->add_additional_fields_schema( $this->schema ); |
|
1232 | + return $this->add_additional_fields_schema($this->schema); |
|
1233 | 1233 | } |
1234 | 1234 | |
1235 | 1235 | /** |
@@ -1241,20 +1241,20 @@ discard block |
||
1241 | 1241 | */ |
1242 | 1242 | protected function get_schema_links() { |
1243 | 1243 | |
1244 | - $href = rest_url( "{$this->namespace}/{$this->rest_base}/{id}" ); |
|
1244 | + $href = rest_url("{$this->namespace}/{$this->rest_base}/{id}"); |
|
1245 | 1245 | |
1246 | 1246 | $links = array(); |
1247 | 1247 | |
1248 | 1248 | $links[] = array( |
1249 | 1249 | 'rel' => 'https://api.w.org/action-publish', |
1250 | - 'title' => __( 'The current user can mark this invoice as completed.', 'invoicing' ), |
|
1250 | + 'title' => __('The current user can mark this invoice as completed.', 'invoicing'), |
|
1251 | 1251 | 'href' => $href, |
1252 | 1252 | 'targetSchema' => array( |
1253 | 1253 | 'type' => 'object', |
1254 | 1254 | 'properties' => array( |
1255 | 1255 | 'status' => array( |
1256 | 1256 | 'type' => 'string', |
1257 | - 'enum' => array( 'publish', 'wpi-renewal' ), |
|
1257 | + 'enum' => array('publish', 'wpi-renewal'), |
|
1258 | 1258 | ), |
1259 | 1259 | ), |
1260 | 1260 | ), |
@@ -1262,7 +1262,7 @@ discard block |
||
1262 | 1262 | |
1263 | 1263 | $links[] = array( |
1264 | 1264 | 'rel' => 'https://api.w.org/action-assign-author', |
1265 | - 'title' => __( 'The current user can change the owner of this invoice.', 'invoicing' ), |
|
1265 | + 'title' => __('The current user can change the owner of this invoice.', 'invoicing'), |
|
1266 | 1266 | 'href' => $href, |
1267 | 1267 | 'targetSchema' => array( |
1268 | 1268 | 'type' => 'object', |
@@ -1285,24 +1285,24 @@ discard block |
||
1285 | 1285 | * @param WPInv_Invoice $invoice Invoice Object. |
1286 | 1286 | * @return array Links for the given invoice. |
1287 | 1287 | */ |
1288 | - protected function prepare_links( $invoice ) { |
|
1288 | + protected function prepare_links($invoice) { |
|
1289 | 1289 | |
1290 | 1290 | // Prepare the base REST API endpoint for invoices. |
1291 | - $base = sprintf( '%s/%s', $this->namespace, $this->rest_base ); |
|
1291 | + $base = sprintf('%s/%s', $this->namespace, $this->rest_base); |
|
1292 | 1292 | |
1293 | 1293 | // Entity meta. |
1294 | 1294 | $links = array( |
1295 | 1295 | 'self' => array( |
1296 | - 'href' => rest_url( trailingslashit( $base ) . $invoice->ID ), |
|
1296 | + 'href' => rest_url(trailingslashit($base) . $invoice->ID), |
|
1297 | 1297 | ), |
1298 | 1298 | 'collection' => array( |
1299 | - 'href' => rest_url( $base ), |
|
1299 | + 'href' => rest_url($base), |
|
1300 | 1300 | ), |
1301 | 1301 | ); |
1302 | 1302 | |
1303 | - if ( ! empty( $invoice->user_id ) ) { |
|
1303 | + if (!empty($invoice->user_id)) { |
|
1304 | 1304 | $links['user'] = array( |
1305 | - 'href' => rest_url( 'wp/v2/users/' . $invoice->user_id ), |
|
1305 | + 'href' => rest_url('wp/v2/users/' . $invoice->user_id), |
|
1306 | 1306 | 'embeddable' => true, |
1307 | 1307 | ); |
1308 | 1308 | } |
@@ -1316,7 +1316,7 @@ discard block |
||
1316 | 1316 | * |
1317 | 1317 | * @param array $links Rest links. |
1318 | 1318 | */ |
1319 | - return apply_filters( "wpinv_rest_invoice_links", $links ); |
|
1319 | + return apply_filters("wpinv_rest_invoice_links", $links); |
|
1320 | 1320 | |
1321 | 1321 | } |
1322 | 1322 | |
@@ -1329,24 +1329,24 @@ discard block |
||
1329 | 1329 | * @param WP_REST_Request $request Request object. |
1330 | 1330 | * @return array List of link relations. |
1331 | 1331 | */ |
1332 | - protected function get_available_actions( $invoice, $request ) { |
|
1332 | + protected function get_available_actions($invoice, $request) { |
|
1333 | 1333 | |
1334 | - if ( 'edit' !== $request['context'] ) { |
|
1334 | + if ('edit' !== $request['context']) { |
|
1335 | 1335 | return array(); |
1336 | 1336 | } |
1337 | 1337 | |
1338 | 1338 | $rels = array(); |
1339 | 1339 | |
1340 | 1340 | // Retrieve the post type object. |
1341 | - $post_type = get_post_type_object( $invoice->post_type ); |
|
1341 | + $post_type = get_post_type_object($invoice->post_type); |
|
1342 | 1342 | |
1343 | 1343 | // Mark invoice as completed. |
1344 | - if ( current_user_can( $post_type->cap->publish_posts ) ) { |
|
1344 | + if (current_user_can($post_type->cap->publish_posts)) { |
|
1345 | 1345 | $rels[] = 'https://api.w.org/action-publish'; |
1346 | 1346 | } |
1347 | 1347 | |
1348 | 1348 | // Change the owner of the invoice. |
1349 | - if ( current_user_can( $post_type->cap->edit_others_posts ) ) { |
|
1349 | + if (current_user_can($post_type->cap->edit_others_posts)) { |
|
1350 | 1350 | $rels[] = 'https://api.w.org/action-assign-author'; |
1351 | 1351 | } |
1352 | 1352 | |
@@ -1359,7 +1359,7 @@ discard block |
||
1359 | 1359 | * |
1360 | 1360 | * @param array $rels Available link relations. |
1361 | 1361 | */ |
1362 | - return apply_filters( "wpinv_rest_invoice_link_relations", $rels ); |
|
1362 | + return apply_filters("wpinv_rest_invoice_link_relations", $rels); |
|
1363 | 1363 | } |
1364 | 1364 | |
1365 | 1365 | /** |
@@ -1372,11 +1372,11 @@ discard block |
||
1372 | 1372 | * @param string $parameter Additional parameter to pass to validation. |
1373 | 1373 | * @return array|WP_Error A list of valid statuses, otherwise WP_Error object. |
1374 | 1374 | */ |
1375 | - public function sanitize_post_statuses( $statuses, $request, $parameter ) { |
|
1375 | + public function sanitize_post_statuses($statuses, $request, $parameter) { |
|
1376 | 1376 | |
1377 | - $statuses = wp_parse_slug_list( $statuses ); |
|
1378 | - $valid_statuses = array_keys( wpinv_get_invoice_statuses( true, true ) ); |
|
1379 | - return array_intersect( $statuses, $valid_statuses ); |
|
1377 | + $statuses = wp_parse_slug_list($statuses); |
|
1378 | + $valid_statuses = array_keys(wpinv_get_invoice_statuses(true, true)); |
|
1379 | + return array_intersect($statuses, $valid_statuses); |
|
1380 | 1380 | |
1381 | 1381 | } |
1382 | 1382 |