| @@ -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,74 +17,127 @@ | ||
| 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' ) ); |
| 34 | + add_action( 'uwp_dashboard_links', array( $this, 'dashboard_output' ), 10, 2 ); | |
| 35 | + | |
| 37 | 36 | } |
| 37 | + | |
| 38 | + // Dynamic tax label integration. | |
| 39 | + add_filter( 'uwp_get_form_label', array( $this, 'dynamic_tax_label' ), 10, 2 ); | |
| 38 | 40 | |
| 39 | 41 | do_action( 'uwp_wpi_setup_actions', $this ); |
| 40 | 42 | } |
| 41 | 43 | |
| 42 | - private function includes() { | |
| 43 | - do_action( 'uwp_gd_include_files' ); | |
| 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){ | |
| 44 | 56 | |
| 45 | - if ( is_admin() ) { | |
| 46 | - do_action( 'uwp_gd_include_admin_files' ); | |
| 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 | + | |
| 47 | 79 | } |
| 80 | + | |
| 81 | + return $links; | |
| 48 | 82 | } |
| 49 | 83 | |
| 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' ); | |
| 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 | + } | |
| 62 | 98 | |
| 63 | - return $tabs_arr; | |
| 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; | |
| 64 | 133 | } |
| 65 | 134 | |
| 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) { | |
| 135 | + public function exclude_privacy_settings($tabs) { | |
| 79 | 136 | |
| 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 | - } | |
| 137 | + $tabs[] = 'invoices'; | |
| 138 | + $tabs[] = 'invoice_subscriptions'; | |
| 139 | + $tabs[] = 'quotes'; | |
| 89 | 140 | |
| 90 | 141 | return $tabs; |
| 91 | 142 | } |
| 92 | 143 | |
| @@ -100,91 +151,23 @@ | ||
| 100 | 151 | * |
| 101 | 152 | * @return void |
| 102 | 153 | */ |
| 103 | 154 | 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; | |
| 155 | + if(is_user_logged_in() && isset($user->ID) && get_current_user_id() == $user->ID){ | |
| 156 | + echo do_shortcode('[wpinv_history]'); | |
| 110 | 157 | } |
| 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 | - </div> | |
| 167 | - </li> | |
| 168 | - <?php | |
| 169 | - do_action('uwp_after_profile_invoice_item', $wpi_invoice, $user); | |
| 170 | - } | |
| 171 | - echo '</ul>'; | |
| 172 | - /* Restore original Post Data */ | |
| 173 | - wp_reset_postdata(); | |
| 174 | - } else { | |
| 175 | - // no posts found | |
| 176 | - echo "<p>".__('No Invoices Found.', 'userswp')."</p>"; | |
| 177 | - } | |
| 178 | - | |
| 179 | - do_action('uwp_after_profile_invoice_items', $user); | |
| 180 | - | |
| 181 | - do_action('uwp_profile_pagination', $the_query->max_num_pages); | |
| 182 | - ?> | |
| 183 | - </div> | |
| 184 | - <?php | |
| 185 | 158 | } |
| 186 | 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 | + */ | |
| 187 | 170 | public function invoice_count($user_id) { |
| 188 | 171 | global $wpdb; |
| 189 | 172 | |
| 190 | 173 | $post_status_array = array_keys(wpinv_get_invoice_statuses()); |
| @@ -198,6 +181,38 @@ | ||
| 198 | 181 | AND post_type = "wpi_invoice"' |
| 199 | 182 | ); |
| 200 | 183 | return $count; |
| 201 | 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 | + } | |
| 202 | 217 | } |
| 203 | -$userswp_geodirectory = UsersWP_Invoicing_Plugin::get_instance(); | |
| 218 | +$userswp_wpinv = UsersWP_Invoicing_Plugin::get_instance(); | |