PluginProbe
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP / trunk
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP vtrunk
1.2.72 1.2.71 1.2.70 1.2.69 1.2.68 1.2.67 1.2.66 1.2.65 1.2.64 1.2.63 trunk 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.20 1.0.21 1.0.22 1.0.23 All 172 releases
userswp / includes / libraries / class-invoicing-plugin.php

class-invoicing-plugin.php in UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP trunk, at includes/libraries/class-invoicing-plugin.php

218 lines 6.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Invoicing plugin related functions
4 *
5 * This class defines all code necessary for Invoicing plugin.
6 *
7 * @author GeoDirectory Team <info@wpgeodirectory.com>
8 */
9 class UsersWP_Invoicing_Plugin {
10 private static $instance;
11
12 public static function get_instance() {
13 if ( ! isset( self::$instance ) && ! ( self::$instance instanceof UsersWP_Invoicing_Plugin ) ) {
14 self::$instance = new UsersWP_Invoicing_Plugin;
15 self::$instance->setup_actions();
16 }
17
18 return self::$instance;
19 }
20
21 public function __construct() {
22 self::$instance = $this;
23 }
24
25 /**
26 * Setup action hooks
27 */
28 private function setup_actions() {
29 if ( is_admin() ) {
30 add_filter( 'uwp_profile_tabs_predefined_fields', array( $this, 'add_profile_tabs_predefined_fields' ), 10, 2 );
31 add_filter( 'uwp_exclude_privacy_settings_tabs', array( $this, 'exclude_privacy_settings' ) );
32 } else {
33 add_action( 'uwp_profile_invoices_tab_content', array( $this, 'add_profile_invoices_tab_content' ) );
34 add_action( 'uwp_dashboard_links', array( $this, 'dashboard_output' ), 10, 2 );
35
36 }
37
38 // Dynamic tax label integration.
39 add_filter( 'uwp_get_form_label', array( $this, 'dynamic_tax_label' ), 10, 2 );
40
41 do_action( 'uwp_wpi_setup_actions', $this );
42 }
43
44 /**
45 * Add quick links to the logged in Dashboard.
46 *
47 * @since 1.0.0
48 * @package userswp
49 *
50 * @param array $links Links to output
51 * @param string $args Arguments
52 *
53 * @return array
54 */
55 public function dashboard_output($links, $args){
56
57 // check its not disabled
58 if(empty($args['disable_wpi'])){
59
60 // My invoices
61 //if (in_array('invoices', $allowed_tabs) && (get_current_user_id() == $user->ID)) {
62 $user_id = get_current_user_id();
63 $i_counts = $this->invoice_count($user_id);
64 if($i_counts > 0) {
65 $links['wpi_invoicing'][] = array(
66 'optgroup' => 'open',
67 'text' => esc_attr( __( 'My Invoices', 'userswp' ) )
68 );
69 $links['wpi_invoicing'][] = array(
70 'url' => uwp_build_profile_tab_url( $user_id, 'invoices', '' ),
71 'text' => esc_attr( __( 'View Invoices', 'userswp' ) )
72 );
73 $links['wpi_invoicing'][] = array(
74 'optgroup' => 'close',
75 );
76 }
77 //}
78
79 }
80
81 return $links;
82 }
83
84 /**
85 * Adds predefined field in for profile tabs.
86 *
87 * @package userswp
88 *
89 * @param array $fields Predefined field array.
90 * @param string $form_type Form type.
91 *
92 * @return array $fields Predefined field array.
93 */
94 public function add_profile_tabs_predefined_fields($fields, $form_type){
95 if('profile-tabs' != $form_type){
96 return $fields;
97 }
98
99 $fields[] = array(
100 'tab_type' => 'standard',
101 'tab_name' => __('Invoices','userswp'),
102 'tab_icon' => 'fas fa-file-invoice',
103 'tab_key' => 'invoices',
104 'tab_content'=> '[wpinv_history]',
105 'tab_privacy' => '2',
106 'user_decided' => '0',
107 );
108
109 $fields[] = array(
110 'tab_type' => 'standard',
111 'tab_name' => __('Subscriptions','userswp'),
112 'tab_icon' => 'fas fa-dollar-sign',
113 'tab_key' => 'invoice_subscriptions',
114 'tab_content'=> '[wpinv_subscriptions]',
115 'tab_privacy' => '2',
116 'user_decided' => '0',
117 );
118
119 if(defined('WPINV_QUOTES_VERSION')){
120 $fields[] = array(
121 'tab_type' => 'standard',
122 'tab_name' => __('Quotes','userswp'),
123 'tab_icon' => 'fas fa-file-invoice',
124 'tab_key' => 'quotes',
125 'tab_content'=> '[wpinv_quote_history]',
126 'tab_privacy' => '2',
127 'user_decided' => '0',
128 );
129 }
130
131
132 return $fields;
133 }
134
135 public function exclude_privacy_settings($tabs) {
136
137 $tabs[] = 'invoices';
138 $tabs[] = 'invoice_subscriptions';
139 $tabs[] = 'quotes';
140
141 return $tabs;
142 }
143
144 /**
145 * Adds Invoices tab content.
146 *
147 * @since 1.0.0
148 * @package userswp
149 *
150 * @param object $user User object.
151 *
152 * @return void
153 */
154 public function add_profile_invoices_tab_content($user) {
155 if(is_user_logged_in() && isset($user->ID) && get_current_user_id() == $user->ID){
156 echo do_shortcode('[wpinv_history]');
157 }
158 }
159
160 /**
161 * Returns invoices count
162 *
163 * @since 1.0.0
164 * @package userswp
165 *
166 * @param int $user_id User ID
167 *
168 * @return int
169 */
170 public function invoice_count($user_id) {
171 global $wpdb;
172
173 $post_status_array = array_keys(wpinv_get_invoice_statuses());
174 $post_status = "'" . implode("','", $post_status_array) . "'";
175
176 $count = $wpdb->get_var('
177 SELECT COUNT(ID)
178 FROM ' . $wpdb->posts. '
179 WHERE post_author = "' . $user_id . '"
180 AND post_status IN ('.$post_status.')
181 AND post_type = "wpi_invoice"'
182 );
183 return $count;
184 }
185
186 /**
187 * Filter form labels for GetPaid VAT number field to use dynamic tax names.
188 *
189 * @since 1.2.8
190 * @param string $label Current field label.
191 * @param object $field Field configuration object.
192 * @return string Modified label for tax fields.
193 */
194 public function dynamic_tax_label( $label, $field ) {
195
196 // Only modify GetPaid VAT number field.
197 if ( ! isset( $field->htmlvar_name ) || '_wpinv_vat_number' !== $field->htmlvar_name ) {
198 return $label;
199 }
200
201 // Check if GetPaid's dynamic tax label function exists.
202 if ( ! function_exists( 'getpaid_get_tax_name_for_country' ) ) {
203 return $label;
204 }
205
206 // Get the tax name based on store's default country.
207 $country = function_exists( 'wpinv_get_default_country' ) ? wpinv_get_default_country() : '';
208
209 if ( empty( $country ) ) {
210 return $label;
211 }
212
213 $tax_name = getpaid_get_tax_name_for_country( $country );
214
215 return sprintf( __( '%s Number', 'userswp' ), $tax_name );
216 }
217 }
218 $userswp_wpinv = UsersWP_Invoicing_Plugin::get_instance();