PluginProbe
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP / 1.2.73
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP v1.2.73
1.2.77 1.2.76 1.2.75 1.2.74 1.2.73 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 All 177 releases
← All changes | includes/libraries/class-invoicing-plugin.php +115 -174 1.0.22 → 1.2.73 View file →
@@ -11,10 +11,8 @@
11 11
12 12 public static function get_instance() {
13 13 if ( ! isset( self::$instance ) && ! ( self::$instance instanceof UsersWP_Invoicing_Plugin ) ) {
14 14 self::$instance = new UsersWP_Invoicing_Plugin;
15 - self::$instance->setup_globals();
16 - self::$instance->includes();
17 15 self::$instance->setup_actions();
18 16 }
19 17
20 18 return self::$instance;
@@ -19,34 +17,42 @@
19 17
20 18 return self::$instance;
21 19 }
22 20
23 - private function __construct() {
21 + public function __construct() {
24 22 self::$instance = $this;
25 23 }
26 24
27 - private function setup_globals() {
28 -
29 - }
30 -
25 + /**
26 + * Setup action hooks
27 + */
31 28 private function setup_actions() {
32 29 if ( is_admin() ) {
33 - add_filter( 'uwp_available_tab_items', array( $this, 'available_tab_items' ) );
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' ) );
34 32 } else {
35 - add_filter( 'uwp_profile_tabs', array( $this, 'add_profile_tabs' ), 10, 3 );
36 33 add_action( 'uwp_profile_invoices_tab_content', array( $this, 'add_profile_invoices_tab_content' ) );
37 - add_action( 'uwp_dashboard_links', array( $this, 'dashboard_output' ),10,2 );
34 + add_action( 'uwp_dashboard_links', array( $this, 'dashboard_output' ), 10, 2 );
38 35
39 36 }
37 +
38 + // Dynamic tax label integration.
39 + add_filter( 'uwp_get_form_label', array( $this, 'dynamic_tax_label' ), 10, 2 );
40 40
41 41 do_action( 'uwp_wpi_setup_actions', $this );
42 42 }
43 43
44 - /**
45 - * Add GD quick links to the logged in Dashboard.
46 - *
47 - * @param $args
48 - */
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 + */
49 55 public function dashboard_output($links, $args){
50 56
51 57 // check its not disabled
52 58 if(empty($args['disable_wpi'])){
@@ -74,55 +80,64 @@
74 80
75 81 return $links;
76 82 }
77 83
78 - private function includes() {
79 - do_action( 'uwp_gd_include_files' );
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 + }
80 98
81 - if ( is_admin() ) {
82 - do_action( 'uwp_gd_include_admin_files' );
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 + );
83 129 }
84 - }
85 130
86 - /**
87 - * Registers the current addon tab items in "Choose the tabs to display in UsersWP Profile" setting.
88 - *
89 - * @since 1.0.0
90 - * @package userswp
91 - *
92 - * @param array $tabs_arr Existing tabs array.
93 - *
94 - * @return array Tabs array.
95 - */
96 - public function available_tab_items( $tabs_arr ) {
97 - $tabs_arr['invoices'] = __( 'Invoices', 'userswp' );
98 131
99 - return $tabs_arr;
132 + return $fields;
100 133 }
101 134
102 - /**
103 - * Adds tab in user profile page.
104 - *
105 - * @since 1.0.0
106 - * @package userswp
107 - *
108 - * @param array $tabs Existing tabs array.
109 - * @param object $user User object.
110 - * @param array $allowed_tabs Allowed tabs array.
111 - *
112 - * @return array Tabs array.
113 - */
114 - function add_profile_tabs($tabs, $user,$allowed_tabs) {
135 + public function exclude_privacy_settings($tabs) {
115 136
116 - if (in_array('invoices', $allowed_tabs) && (get_current_user_id() == $user->ID)) {
117 - $i_counts = $this->invoice_count($user->ID);
118 - if($i_counts > 0) {
119 - $tabs['invoices'] = array(
120 - 'title' => __('Invoices', 'userswp'),
121 - 'count' => $i_counts
122 - );
123 - }
124 - }
137 + $tabs[] = 'invoices';
138 + $tabs[] = 'invoice_subscriptions';
139 + $tabs[] = 'quotes';
125 140
126 141 return $tabs;
127 142 }
128 143
@@ -136,129 +151,23 @@
136 151 *
137 152 * @return void
138 153 */
139 154 public function add_profile_invoices_tab_content($user) {
140 - $this->profile_gd_invoices_content($user);
141 - }
142 -
143 - public function profile_gd_invoices_content($user) {
144 - if (!is_user_logged_in()) {
145 - return;
155 + if(is_user_logged_in() && isset($user->ID) && get_current_user_id() == $user->ID){
156 + echo do_shortcode('[wpinv_history]');
146 157 }
147 -
148 - if (get_current_user_id() != $user->ID) {
149 - return;
150 - }
151 - ?>
152 - <h3><?php echo __('Invoices', 'userswp'); ?></h3>
153 -
154 - <div class="uwp-profile-item-block">
155 - <?php
156 - $paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
157 -
158 - $args = array(
159 - 'post_type' => 'wpi_invoice',
160 - 'post_status' => array_keys(wpinv_get_invoice_statuses()),
161 - 'posts_per_page' => uwp_get_option('profile_no_of_items', 10),
162 - 'author' => $user->ID,
163 - 'paged' => $paged,
164 - );
165 - // The Query
166 - $the_query = new WP_Query($args);
167 -
168 - do_action('uwp_before_profile_invoice_items', $user);
169 -
170 - // The Loop
171 - if ($the_query->have_posts()) {
172 - echo '<ul class="uwp-profile-item-ul">';
173 - while ($the_query->have_posts()) {
174 - $the_query->the_post();
175 - $wpi_invoice = new WPInv_Invoice( get_the_ID() );
176 - do_action('uwp_before_profile_invoice_item', $wpi_invoice, $user);
177 - ?>
178 - <li class="uwp-profile-item-li uwp-profile-item-clearfix">
179 - <?php do_action('uwp_before_profile_invoice_title', $wpi_invoice, $user); ?>
180 - <h3 class="uwp-profile-item-title">
181 - <a href="<?php echo get_the_permalink(); ?>"><?php _e('Invoice','userswp');?> <?php echo get_the_title(); ?></a>
182 - </h3>
183 - <?php do_action('uwp_after_profile_invoice_title', $wpi_invoice, $user); ?>
184 - <?php do_action('uwp_before_profile_invoice_date', $wpi_invoice, $user); ?>
185 - <time class="uwp-profile-item-time published" datetime="<?php echo get_the_time('c'); ?>">
186 - <?php echo get_the_date(); ?>
187 - </time>
188 - <?php do_action('uwp_after_profile_invoice_date', $wpi_invoice, $user); ?>
189 - <div class="uwp-profile-item-summary">
190 - <?php do_action('uwp_before_profile_invoice_summary', $wpi_invoice, $user); ?>
191 - <div class="uwp-order-status">
192 - <?php
193 - echo __('Invoice Status: ', 'userswp').$wpi_invoice->get_status( true ) . ( $wpi_invoice->is_recurring() && $wpi_invoice->is_parent() ? ' <span class="wpi-suffix">' . __( '(r)', 'invoicing' ) . '</span>' : '' );
194 - ?>
195 - </div>
196 - <div class="uwp-order-total">
197 - <?php
198 - echo __('Invoice Total: ', 'userswp'). $wpi_invoice->get_total( true );
199 - ?>
200 - </div>
201 - <?php do_action('uwp_after_profile_invoice_summary', $wpi_invoice, $user); ?>
202 - <?php
203 - $actions = array();
204 -
205 - if ( 'wpi-pending' == $wpi_invoice->post_status && $wpi_invoice->needs_payment() ) {
206 - $actions['pay'] = array(
207 - 'url' => $wpi_invoice->get_checkout_payment_url(),
208 - 'name' => __( 'Pay Now', 'invoicing' ),
209 - 'class' => 'btn-uwp-pay-now'
210 - );
211 - }
212 -
213 - $cart_items = $wpi_invoice->get_cart_details();
214 - if ( !empty( $cart_items )) {
215 - foreach ($cart_items as $key => $cart_item) {
216 - $item_id = $cart_item['id'];
217 - $wpi_item = $item_id > 0 ? new WPInv_Item( $item_id ) : NULL;
218 - if ( !empty( $cart_item ) && !empty( $cart_item['meta']['post_id'] ) && $wpi_item->get_type() == 'package' ) {
219 - $post_id = $cart_item['meta']['post_id'];
220 - $post_ink = get_permalink( $post_id );
221 - if($post_ink ){
222 - $actions['listing'] = array(
223 - 'url' => $post_ink,
224 - 'name' => __( 'Listing', 'invoicing' ),
225 - 'class' => 'btn-uwp-listing'
226 - );
227 - }
228 - }
229 - }
230 - }
231 -
232 - $actions = apply_filters( 'wpinv_user_profile_invoice_actions', $actions, $wpi_invoice );
233 - if ( $actions ) {
234 - foreach ( $actions as $key => $action ) {
235 - $class = !empty($action['class']) ? sanitize_html_class($action['class']) : '';
236 - echo '<a href="' . esc_url( $action['url'] ) . '" class="btn btn-sm ' . $class . ' ' . sanitize_html_class( $key ) . '" ' . ( !empty($action['attrs']) ? $action['attrs'] : '' ) . '>' . $action['name'] . '</a>';
237 - }
238 - }
239 - ?>
240 - </div>
241 - </li>
242 - <?php
243 - do_action('uwp_after_profile_invoice_item', $wpi_invoice, $user);
244 - }
245 - echo '</ul>';
246 - /* Restore original Post Data */
247 - wp_reset_postdata();
248 - } else {
249 - // no posts found
250 - echo "<p>".__('No Invoices Found.', 'userswp')."</p>";
251 - }
252 -
253 - do_action('uwp_after_profile_invoice_items', $user);
254 -
255 - do_action('uwp_profile_pagination', $the_query->max_num_pages);
256 - ?>
257 - </div>
258 - <?php
259 158 }
260 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 + */
261 170 public function invoice_count($user_id) {
262 171 global $wpdb;
263 172
264 173 $post_status_array = array_keys(wpinv_get_invoice_statuses());
@@ -272,6 +181,38 @@
272 181 AND post_type = "wpi_invoice"'
273 182 );
274 183 return $count;
275 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 + }
276 217 }
277 -$userswp_geodirectory = UsersWP_Invoicing_Plugin::get_instance();
218 +$userswp_wpinv = UsersWP_Invoicing_Plugin::get_instance();