PluginProbe
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP / 1.0.21
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP v1.0.21
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 1.0.19 1.0.20 1.0.21 1.0.22 All 173 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 1.0.21, at includes/libraries/class-invoicing-plugin.php

239 lines 9.5 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_globals();
16 self::$instance->includes();
17 self::$instance->setup_actions();
18 }
19
20 return self::$instance;
21 }
22
23 private function __construct() {
24 self::$instance = $this;
25 }
26
27 private function setup_globals() {
28
29 }
30
31 private function setup_actions() {
32 if ( is_admin() ) {
33 add_filter( 'uwp_available_tab_items', array( $this, 'available_tab_items' ) );
34 } else {
35 add_filter( 'uwp_profile_tabs', array( $this, 'add_profile_tabs' ), 10, 3 );
36 add_action( 'uwp_profile_invoices_tab_content', array( $this, 'add_profile_invoices_tab_content' ) );
37 }
38
39 do_action( 'uwp_wpi_setup_actions', $this );
40 }
41
42 private function includes() {
43 do_action( 'uwp_gd_include_files' );
44
45 if ( is_admin() ) {
46 do_action( 'uwp_gd_include_admin_files' );
47 }
48 }
49
50 /**
51 * Registers the current addon tab items in "Choose the tabs to display in UsersWP Profile" setting.
52 *
53 * @since 1.0.0
54 * @package userswp
55 *
56 * @param array $tabs_arr Existing tabs array.
57 *
58 * @return array Tabs array.
59 */
60 public function available_tab_items( $tabs_arr ) {
61 $tabs_arr['invoices'] = __( 'Invoices', 'userswp' );
62
63 return $tabs_arr;
64 }
65
66 /**
67 * Adds tab in user profile page.
68 *
69 * @since 1.0.0
70 * @package userswp
71 *
72 * @param array $tabs Existing tabs array.
73 * @param object $user User object.
74 * @param array $allowed_tabs Allowed tabs array.
75 *
76 * @return array Tabs array.
77 */
78 function add_profile_tabs($tabs, $user,$allowed_tabs) {
79
80 if (in_array('invoices', $allowed_tabs) && (get_current_user_id() == $user->ID)) {
81 $i_counts = $this->invoice_count($user->ID);
82 if($i_counts > 0) {
83 $tabs['invoices'] = array(
84 'title' => __('Invoices', 'userswp'),
85 'count' => $i_counts
86 );
87 }
88 }
89
90 return $tabs;
91 }
92
93 /**
94 * Adds Invoices tab content.
95 *
96 * @since 1.0.0
97 * @package userswp
98 *
99 * @param object $user User object.
100 *
101 * @return void
102 */
103 public function add_profile_invoices_tab_content($user) {
104 $this->profile_gd_invoices_content($user);
105 }
106
107 public function profile_gd_invoices_content($user) {
108 if (!is_user_logged_in()) {
109 return;
110 }
111
112 if (get_current_user_id() != $user->ID) {
113 return;
114 }
115 ?>
116 <h3><?php echo __('Invoices', 'userswp'); ?></h3>
117
118 <div class="uwp-profile-item-block">
119 <?php
120 $paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
121
122 $args = array(
123 'post_type' => 'wpi_invoice',
124 'post_status' => array_keys(wpinv_get_invoice_statuses()),
125 'posts_per_page' => uwp_get_option('profile_no_of_items', 10),
126 'author' => $user->ID,
127 'paged' => $paged,
128 );
129 // The Query
130 $the_query = new WP_Query($args);
131
132 do_action('uwp_before_profile_invoice_items', $user);
133
134 // The Loop
135 if ($the_query->have_posts()) {
136 echo '<ul class="uwp-profile-item-ul">';
137 while ($the_query->have_posts()) {
138 $the_query->the_post();
139 $wpi_invoice = new WPInv_Invoice( get_the_ID() );
140 do_action('uwp_before_profile_invoice_item', $wpi_invoice, $user);
141 ?>
142 <li class="uwp-profile-item-li uwp-profile-item-clearfix">
143 <?php do_action('uwp_before_profile_invoice_title', $wpi_invoice, $user); ?>
144 <h3 class="uwp-profile-item-title">
145 <a href="<?php echo get_the_permalink(); ?>"><?php _e('Invoice','userswp');?> <?php echo get_the_title(); ?></a>
146 </h3>
147 <?php do_action('uwp_after_profile_invoice_title', $wpi_invoice, $user); ?>
148 <?php do_action('uwp_before_profile_invoice_date', $wpi_invoice, $user); ?>
149 <time class="uwp-profile-item-time published" datetime="<?php echo get_the_time('c'); ?>">
150 <?php echo get_the_date(); ?>
151 </time>
152 <?php do_action('uwp_after_profile_invoice_date', $wpi_invoice, $user); ?>
153 <div class="uwp-profile-item-summary">
154 <?php do_action('uwp_before_profile_invoice_summary', $wpi_invoice, $user); ?>
155 <div class="uwp-order-status">
156 <?php
157 echo __('Invoice Status: ', 'userswp').$wpi_invoice->get_status( true ) . ( $wpi_invoice->is_recurring() && $wpi_invoice->is_parent() ? ' <span class="wpi-suffix">' . __( '(r)', 'invoicing' ) . '</span>' : '' );
158 ?>
159 </div>
160 <div class="uwp-order-total">
161 <?php
162 echo __('Invoice Total: ', 'userswp'). $wpi_invoice->get_total( true );
163 ?>
164 </div>
165 <?php do_action('uwp_after_profile_invoice_summary', $wpi_invoice, $user); ?>
166 <?php
167 $actions = array();
168
169 if ( 'wpi-pending' == $wpi_invoice->post_status && $wpi_invoice->needs_payment() ) {
170 $actions['pay'] = array(
171 'url' => $wpi_invoice->get_checkout_payment_url(),
172 'name' => __( 'Pay Now', 'invoicing' ),
173 'class' => 'btn-uwp-pay-now'
174 );
175 }
176
177 $cart_items = $wpi_invoice->get_cart_details();
178 if ( !empty( $cart_items )) {
179 foreach ($cart_items as $key => $cart_item) {
180 $item_id = $cart_item['id'];
181 $wpi_item = $item_id > 0 ? new WPInv_Item( $item_id ) : NULL;
182 if ( !empty( $cart_item ) && !empty( $cart_item['meta']['post_id'] ) && $wpi_item->get_type() == 'package' ) {
183 $post_id = $cart_item['meta']['post_id'];
184 $post_ink = get_permalink( $post_id );
185 $actions['listing'] = array(
186 'url' => $post_ink,
187 'name' => __( 'Listing', 'invoicing' ),
188 'class' => 'btn-uwp-listing'
189 );
190 }
191 }
192 }
193
194 $actions = apply_filters( 'wpinv_user_profile_invoice_actions', $actions, $wpi_invoice );
195 if ( $actions ) {
196 foreach ( $actions as $key => $action ) {
197 $class = !empty($action['class']) ? sanitize_html_class($action['class']) : '';
198 echo '<a href="' . esc_url( $action['url'] ) . '" class="btn btn-sm ' . $class . ' ' . sanitize_html_class( $key ) . '" ' . ( !empty($action['attrs']) ? $action['attrs'] : '' ) . '>' . $action['name'] . '</a>';
199 }
200 }
201 ?>
202 </div>
203 </li>
204 <?php
205 do_action('uwp_after_profile_invoice_item', $wpi_invoice, $user);
206 }
207 echo '</ul>';
208 /* Restore original Post Data */
209 wp_reset_postdata();
210 } else {
211 // no posts found
212 echo "<p>".__('No Invoices Found.', 'userswp')."</p>";
213 }
214
215 do_action('uwp_after_profile_invoice_items', $user);
216
217 do_action('uwp_profile_pagination', $the_query->max_num_pages);
218 ?>
219 </div>
220 <?php
221 }
222
223 public function invoice_count($user_id) {
224 global $wpdb;
225
226 $post_status_array = array_keys(wpinv_get_invoice_statuses());
227 $post_status = "'" . implode("','", $post_status_array) . "'";
228
229 $count = $wpdb->get_var('
230 SELECT COUNT(ID)
231 FROM ' . $wpdb->posts. '
232 WHERE post_author = "' . $user_id . '"
233 AND post_status IN ('.$post_status.')
234 AND post_type = "wpi_invoice"'
235 );
236 return $count;
237 }
238 }
239 $userswp_geodirectory = UsersWP_Invoicing_Plugin::get_instance();