|
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( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
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
|
|
|
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
|
|
|
$invoices = new WP_Query( $wp_query_args ); |
|
78
|
|
|
$count = absint( $invoices->found_posts ); |
|
79
|
|
|
|
|
80
|
|
|
if(empty($count)){ |
|
81
|
|
|
$output .= __('No Invoice(s)','invoicing'); |
|
82
|
|
|
}else{ |
|
83
|
|
|
$link_url = admin_url( "edit.php?post_type=wpi_invoice&author=".absint($user_id) ); |
|
84
|
|
|
$link_text = sprintf( __('Invoices ( %d )', 'invoicing'), $count ); |
|
85
|
|
|
$output .= "<a href='$link_url' >$link_text</a>"; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
return apply_filters('wpinv_user_invoice_content', $output, $user_id); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
} |
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.