Passed
Push — master ( dd948d...2b23ec )
by Kiran
14:42 queued 08:32
created

WPInv_Receipt_Widget::output()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
nc 2
nop 3
dl 0
loc 6
rs 10
c 1
b 0
f 0
1
<?php
2
if ( ! defined( 'ABSPATH' ) ) {
3
    exit;
4
}
5
6
/**
7
 * Invoice receipt widget.
8
 */
9
class WPInv_Receipt_Widget extends WP_Super_Duper {
10
11
	/**
12
	 * Register the widget with WordPress.
13
	 *
14
	 */
15
	public function __construct() {
16
17
		$options = array(
18
			'textdomain'     => 'invoicing',
19
			'block-icon'     => 'admin-site',
20
			'block-category' => 'widgets',
21
			'block-keywords' => "['invoicing','receipt']",
22
			'class_name'     => __CLASS__,
23
			'base_id'        => 'wpinv_receipt',
24
			'name'           => __( 'GetPaid > Invoice Receipt', 'invoicing' ),
25
			'widget_ops'     => array(
26
				'classname'   => 'wpinv-receipt-class bsui',
27
				'description' => esc_html__( 'Displays invoice receipt after checkout.', 'invoicing' ),
28
			),
29
			'arguments'      => array(
30
				'title' => array(
31
					'title'    => __( 'Widget title', 'invoicing' ),
32
					'desc'     => __( 'Enter widget title.', 'invoicing' ),
33
					'type'     => 'text',
34
					'desc_tip' => true,
35
					'default'  => '',
36
					'advanced' => false,
37
				),
38
			),
39
40
		);
41
42
		parent::__construct( $options );
43
	}
44
45
	/**
46
	 * The Super block output function.
47
	 *
48
	 * @param array $args
49
	 * @param array $widget_args
50
	 * @param string $content
51
	 *
52
	 * @return mixed|string|bool
53
	 */
54
	public function output( $args = array(), $widget_args = array(), $content = '' ) {
55
		if ( $this->is_preview() ) {
56
			return $this->get_dummy_preview( $args );
57
		}
58
59
		return wpinv_payment_receipt();
60
	}
61
62
	public function get_dummy_preview( $args ) {
0 ignored issues
show
Unused Code introduced by
The parameter $args is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

62
	public function get_dummy_preview( /** @scrutinizer ignore-unused */ $args ) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
63
		global $wpdb;
64
65
		$output = aui()->alert( array(
66
				'type'=> 'info',
67
				'content' => __( 'This is a simple preview for a invoice receipt.', 'invoicing' )
68
			)
69
		);
70
71
		if ( ! current_user_can( 'manage_options' ) ) {
72
			return $output;
73
		}
74
75
		$invoice_id = $wpdb->get_var( $wpdb->prepare( "SELECT `ID` FROM `{$wpdb->posts}` WHERE `post_type` = %s AND `post_status` IN( 'wpi-pending', 'publish', 'wpi-processing', 'wpi-onhold' ) ORDER BY `post_status` ASC, `ID` ASC LIMIT 1;", 'wpi_invoice' ) );
76
77
		if ( ! $invoice_id ) {
78
			return $output;
79
		}
80
81
		$invoice = new WPInv_Invoice( $invoice_id );
82
83
		if ( empty( $invoice ) ) {
84
			return $output;
85
		}
86
87
		$output .= wpinv_get_template_html( 'invoice-receipt.php', array( 'invoice' => $invoice ) );
88
89
		$output = preg_replace( '/<a([^>]*)href=(["\'])(.*?)\2([^>]*)>/is', '<a\\1href="javascript:void(0)"\\4>', $output );
90
91
		return $output;
92
	}
93
}
94