1
|
|
|
<?php |
2
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
3
|
|
|
exit; // Exit if accessed directly |
4
|
|
|
} |
5
|
|
|
|
6
|
|
|
class WPInv_Shortcodes { |
7
|
|
|
/** |
8
|
|
|
* Init shortcodes. |
9
|
|
|
*/ |
10
|
|
|
public static function init() { |
11
|
|
|
$shortcodes = array( |
12
|
|
|
'wpinv_checkout' => __CLASS__ . '::checkout', |
13
|
|
|
'wpinv_history' => __CLASS__ . '::history', |
14
|
|
|
'wpinv_receipt' => __CLASS__ . '::receipt', |
15
|
|
|
); |
16
|
|
|
|
17
|
|
|
foreach ( $shortcodes as $shortcode => $function ) { |
18
|
|
|
add_shortcode( apply_filters( "{$shortcode}_shortcode_tag", $shortcode ), $function ); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
add_shortcode( 'wpinv_messages', __CLASS__ . '::messages' ); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public static function shortcode_wrapper( |
25
|
|
|
$function, |
26
|
|
|
$atts = array(), |
27
|
|
|
$wrapper = array( |
28
|
|
|
'class' => 'wpinv-invoices', |
29
|
|
|
'before' => null, |
30
|
|
|
'after' => null |
31
|
|
|
) |
32
|
|
|
) { |
33
|
|
|
ob_start(); |
34
|
|
|
|
35
|
|
|
echo empty( $wrapper['before'] ) ? '<div class="' . esc_attr( $wrapper['class'] ) . '">' : $wrapper['before']; |
36
|
|
|
call_user_func( $function, $atts ); |
37
|
|
|
echo empty( $wrapper['after'] ) ? '</div>' : $wrapper['after']; |
38
|
|
|
|
39
|
|
|
return ob_get_clean(); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public static function checkout( $atts = array(), $content = null ) { |
43
|
|
|
return wpinv_checkout_form( $atts, $content ); |
|
|
|
|
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public static function messages( $atts, $content = null ) { |
|
|
|
|
47
|
|
|
ob_start(); |
48
|
|
|
wpinv_print_errors(); |
49
|
|
|
return '<div class="wpinv">' . ob_get_clean() . '</div>'; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public static function history( $atts, $content = null ) { |
|
|
|
|
53
|
|
|
return self::shortcode_wrapper( array( __CLASS__, 'history_output' ), $atts ); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Output the shortcode. |
58
|
|
|
* |
59
|
|
|
* @param array $atts |
60
|
|
|
*/ |
61
|
|
|
public static function history_output( $atts ) { |
62
|
|
|
do_action( 'wpinv_before_user_invoice_history' ); |
63
|
|
|
wpinv_get_template_part( 'wpinv-invoice-history', $atts ); |
64
|
|
|
do_action( 'wpinv_after_user_invoice_history' ); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public static function receipt( $atts, $content = null ) { |
68
|
|
|
return wpinv_payment_receipt( $atts, $content ); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.