|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Contains functions related to Invoicing users. |
|
4
|
|
|
* |
|
5
|
|
|
* @since 1.0.0 |
|
6
|
|
|
* @package Invoicing |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
// MUST have WordPress. |
|
10
|
|
|
if ( ! defined( 'WPINC' ) ) { |
|
11
|
|
|
exit; |
|
12
|
|
|
} |
|
13
|
|
|
|
|
14
|
|
|
class WPInv_Admin_Users { |
|
15
|
|
|
private static $instance; |
|
16
|
|
|
|
|
17
|
|
|
public static function run() { |
|
18
|
|
|
if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WPInv_Admin_Users ) ) { |
|
19
|
|
|
self::$instance = new WPInv_Admin_Users(); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
return self::$instance; |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
public function __construct() { |
|
26
|
|
|
add_filter( 'manage_users_columns', array( $this, 'wpinv_add_user_column' ) ); |
|
27
|
|
|
add_filter( 'manage_users_custom_column', array( $this, 'wpinv_user_column_content' ), 10, 3 ); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Adds a new backend user column. |
|
32
|
|
|
* |
|
33
|
|
|
* @param $column |
|
34
|
|
|
* |
|
35
|
|
|
* @return mixed |
|
36
|
|
|
*/ |
|
37
|
|
|
public function wpinv_add_user_column( $column ) { |
|
38
|
|
|
$column['wpinvoicing'] = __( 'Invoicing', 'invoicing' ); |
|
39
|
|
|
return $column; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Add the backend user column content. |
|
44
|
|
|
* |
|
45
|
|
|
* @param $val |
|
46
|
|
|
* @param $column_name |
|
47
|
|
|
* @param $user_id |
|
48
|
|
|
* |
|
49
|
|
|
* @return string |
|
50
|
|
|
*/ |
|
51
|
|
|
public function wpinv_user_column_content( $val, $column_name, $user_id ) { |
|
52
|
|
|
switch ( $column_name ) { |
|
53
|
|
|
case 'wpinvoicing': |
|
54
|
|
|
return $this->get_user_invoices( $user_id ); |
|
55
|
|
|
break; |
|
|
|
|
|
|
56
|
|
|
default: |
|
57
|
|
|
} |
|
58
|
|
|
return $val; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Get the backend user invoices. |
|
63
|
|
|
* |
|
64
|
|
|
* @param $user_id |
|
65
|
|
|
* |
|
66
|
|
|
* @return string |
|
67
|
|
|
*/ |
|
68
|
|
|
public function get_user_invoices( $user_id ) { |
|
69
|
|
|
$output = ''; |
|
70
|
|
|
$wp_query_args = array( |
|
71
|
|
|
'post_type' => 'wpi_invoice', |
|
72
|
|
|
'post_status' => array( 'wpi-pending', 'publish', 'wpi-processing', 'wpi-onhold', 'wpi-refunded', 'wpi-cancelled', 'wpi-failed', 'wpi-renewal' ), |
|
73
|
|
|
'posts_per_page' => -1, |
|
74
|
|
|
'fields' => 'ids', |
|
75
|
|
|
'author' => $user_id, |
|
76
|
|
|
); |
|
77
|
|
|
|
|
78
|
|
|
$wp_query_args = apply_filters( 'wpinv_get_user_invoices_args', $wp_query_args, $user_id ); |
|
79
|
|
|
|
|
80
|
|
|
$invoices = new WP_Query( $wp_query_args ); |
|
81
|
|
|
$count = absint( $invoices->found_posts ); |
|
82
|
|
|
|
|
83
|
|
|
if ( empty( $count ) ) { |
|
84
|
|
|
$output .= __( 'No Invoice(s)', 'invoicing' ); |
|
85
|
|
|
} else { |
|
86
|
|
|
$link_url = admin_url( 'edit.php?post_type=wpi_invoice&author=' . absint( $user_id ) ); |
|
87
|
|
|
$link_text = sprintf( __( 'Invoices ( %d )', 'invoicing' ), $count ); |
|
88
|
|
|
$output .= "<a href='$link_url' >$link_text</a>"; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
return apply_filters( 'wpinv_user_invoice_content', $output, $user_id ); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
} |
|
95
|
|
|
|
The
breakstatement is not necessary if it is preceded for example by areturnstatement:If you would like to keep this construct to be consistent with other
casestatements, you can safely mark this issue as a false-positive.