GetPaid_Meta_Box_Item_Info   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 117
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 67
dl 0
loc 117
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A get_tooltip() 0 12 1
B output() 0 90 3
1
<?php
2
3
/**
4
 * Item Info
5
 *
6
 * Display the item data meta box.
7
 *
8
 */
9
10
if ( ! defined( 'ABSPATH' ) ) {
11
	exit; // Exit if accessed directly
12
}
13
14
/**
15
 * GetPaid_Meta_Box_Item_Info Class.
16
 */
17
class GetPaid_Meta_Box_Item_Info {
18
19
    /**
20
	 * Output the metabox.
21
	 *
22
	 * @param WP_Post $post
23
	 */
24
    public static function output( $post ) {
25
26
        // Prepare the item.
27
        $item = new WPInv_Item( $post );
28
29
        ?>
30
31
        <div class='bsui' style='padding-top: 10px;'>
32
            <?php do_action( 'wpinv_item_before_info_metabox', $item ); ?>
33
34
            <div class="wpinv_item_type form-group mb-3 row">
35
                <label for="wpinv_item_type" class="col-sm-12 col-form-label">
36
                    <?php esc_html_e( 'Item Type', 'invoicing' ); ?>
37
                    <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php echo esc_attr( self::get_tooltip( $post ) ); ?>"></span>
38
                </label>
39
40
                <div class="col-sm-12">
41
42
                    <?php
43
                        aui()->select(
44
                            array(
45
                                'id'               => 'wpinv_item_type',
46
                                'name'             => 'wpinv_item_type',
47
                                'placeholder'      => __( 'Select item type', 'invoicing' ),
48
                                'value'            => $item->get_type( 'edit' ),
49
                                'select2'          => true,
50
                                'data-allow-clear' => 'false',
51
                                'no_wrap'          => true,
52
                                'options'          => wpinv_get_item_types(),
53
                            ),
54
                            true
55
                        );
56
                    ?>
57
58
                </div>
59
            </div>
60
61
            <?php if ( getpaid_item_type_supports( $item->get_type( 'edit' ), 'buy_now' ) ) : ?>
62
                <div class="wpinv_item_shortcode form-group mb-3 row">
63
                    <label for="wpinv_item_shortcode" class="col-sm-12 col-form-label">
64
                        <?php esc_html_e( 'Payment Form Shortcode', 'invoicing' ); ?>
65
                        <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Displays a payment form', 'invoicing' ); ?>"></span>
66
                    </label>
67
68
                    <div class="col-sm-12">
69
                        <input  onClick="this.select()" type="text" id="wpinv_item_shortcode" value="[getpaid item=<?php echo esc_attr( $item->get_id() ); ?>]" style="width: 100%;" readonly/>
70
                    </div>
71
                </div>
72
73
                <div class="wpinv_item_buy_shortcode form-group mb-3 row">
74
                    <label for="wpinv_item_button_shortcode" class="col-sm-12 col-form-label">
75
                        <?php esc_html_e( 'Payment Button Shortcode', 'invoicing' ); ?>
76
                        <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Displays a buy now button', 'invoicing' ); ?>"></span>
77
                    </label>
78
79
                    <div class="col-sm-12">
80
                        <input onClick="this.select()" type="text" id="wpinv_item_button_shortcode" value="[getpaid item=<?php echo esc_attr( $item->get_id() ); ?> button='Buy Now']" style="width: 100%;" readonly/>
81
                        <small class="form-text text-muted">
82
                            <?php esc_html_e( 'Or use the following URL in a link:', 'invoicing' ); ?>
83
                            <code>#getpaid-item-<?php echo intval( $item->get_id() ); ?>|0</code>
84
                        </small>
85
                    </div>
86
                </div>
87
88
                <div class="wpinv_item_buy_url form-group mb-3 row">
89
                    <label for="wpinv_item_buy_url" class="col-sm-12 col-form-label">
90
                        <?php esc_html_e( 'Direct Payment URL', 'invoicing' ); ?>
91
                        <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'You can use this in an iFrame to embed the payment form on another website', 'invoicing' ); ?>"></span>
92
                    </label>
93
94
                    <div class="col-sm-12">
95
                        <input onClick="this.select()" type="text" id="wpinv_item_buy_url" value="<?php echo esc_url( getpaid_embed_url( false, $item->get_id() . '|0' ) ); ?>" style="width: 100%;" readonly/>
0 ignored issues
show
Bug introduced by
false of type false is incompatible with the type integer expected by parameter $payment_form of getpaid_embed_url(). ( Ignorable by Annotation )

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

95
                        <input onClick="this.select()" type="text" id="wpinv_item_buy_url" value="<?php echo esc_url( getpaid_embed_url( /** @scrutinizer ignore-type */ false, $item->get_id() . '|0' ) ); ?>" style="width: 100%;" readonly/>
Loading history...
96
                    </div>
97
                </div>
98
99
            <?php endif; ?>
100
101
            <div class="wpinv_item_custom_id form-group mb-3">
102
                <?php esc_html_e( 'Custom ID', 'invoicing' ); ?> &mdash; <?php echo esc_html( $item->get_custom_id() ); ?>
103
            </div>
104
105
            <?php do_action( 'wpinv_meta_values_metabox_before', $post ); ?>
106
            <?php foreach ( apply_filters( 'wpinv_show_meta_values_for_keys', array() ) as $meta_key ) : ?>
107
                <div class="wpinv_item_custom_id form-group mb-3">
108
                    <?php echo esc_html( $meta_key ); ?> &mdash; <?php echo esc_html( get_post_meta( $item->get_id(), '_wpinv_' . $meta_key, true ) ); ?>
0 ignored issues
show
Bug introduced by
It seems like get_post_meta($item->get...nv_' . $meta_key, true) can also be of type false; however, parameter $text of esc_html() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

108
                    <?php echo esc_html( $meta_key ); ?> &mdash; <?php echo esc_html( /** @scrutinizer ignore-type */ get_post_meta( $item->get_id(), '_wpinv_' . $meta_key, true ) ); ?>
Loading history...
109
                </div>
110
            <?php endforeach; ?>
111
            <?php do_action( 'wpinv_meta_values_metabox_after', $post ); ?>
112
            <?php do_action( 'wpinv_item_info_metabox', $item ); ?>
113
        </div>
114
        <?php
115
116
    }
117
118
    /**
119
	 * Returns item type tolltip.
120
	 *
121
	 */
122
    public static function get_tooltip( $post ) {
123
124
        ob_start();
125
        ?>
126
127
        <?php esc_html_e( 'Standard: Standard item type', 'invoicing' ); ?>
128
        <?php esc_html_e( 'Fee: Like Registration Fee, Sign up Fee etc', 'invoicing' ); ?>
129
130
        <?php
131
        do_action( 'wpinv_item_info_metabox_after', $post );
132
133
        return ob_get_clean();
134
135
    }
136
137
}
138