Passed
Push — master ( 169dfd...f76276 )
by Stiofan
04:33
created

WPInv_Plugin::admin_enqueue_scripts()   C

Complexity

Conditions 13
Paths 12

Size

Total Lines 81
Code Lines 62

Duplication

Lines 4
Ratio 4.94 %

Importance

Changes 0
Metric Value
cc 13
eloc 62
nc 12
nop 0
dl 4
loc 81
rs 5.0112
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * Contains functions related to Invoicing plugin.
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_Plugin {
15
    private static $instance;
16
    
17
    public static function run() {
18
        if ( !isset( self::$instance ) && !( self::$instance instanceof WPInv_Plugin ) ) {
19
            self::$instance = new WPInv_Plugin;
20
            self::$instance->includes();
21
            self::$instance->actions();
22
            self::$instance->notes      = new WPInv_Notes();
0 ignored issues
show
Bug introduced by
The property notes does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
23
            self::$instance->reports    = new WPInv_Reports();
0 ignored issues
show
Bug introduced by
The property reports does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
24
        }
25
        
26
        do_action( 'wpinv_loaded' );
27
        
28
        return self::$instance;
29
    }
30
    
31
    public function __construct() {
32
        $this->define_constants();
33
    }
34
    
35
    public function define_constants() {
36
        define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) );
37
        define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) );
38
    }
39
    
40
    private function actions() {
41
        /* Internationalize the text strings used. */
42
        add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) );
43
        
44
        /* Perform actions on admin initialization. */
45
        add_action( 'admin_init', array( &$this, 'admin_init') );
46
        add_action( 'init', array( &$this, 'init' ), 3 );
47
        add_action( 'init', array( 'WPInv_Shortcodes', 'init' ) );
48
        add_action( 'init', array( &$this, 'wpinv_actions' ) );
49
        
50
        if ( class_exists( 'BuddyPress' ) ) {
51
            add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) );
52
        }
53
54
        add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) );
55
        
56
        if ( is_admin() ) {
57
            add_action( 'admin_enqueue_scripts', array( &$this, 'admin_enqueue_scripts' ) );
58
            add_action( 'admin_body_class', array( &$this, 'admin_body_class' ) );
59
        } else {
60
            add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) );
61
        }
62
        
63
        /**
64
         * Fires after the setup of all WPInv_Plugin actions.
65
         *
66
         * @since 1.0.0
67
         *
68
         * @param WPInv_Plugin $this. Current WPInv_Plugin instance. Passed by reference.
69
         */
70
        do_action_ref_array( 'wpinv_actions', array( &$this ) );
71
72
        add_action( 'admin_init', array( &$this, 'activation_redirect') );
73
    }
74
    
75
    public function plugins_loaded() {
76
        /* Internationalize the text strings used. */
77
        $this->load_textdomain();
78
    }
79
    
80
    /**
81
     * Load the translation of the plugin.
82
     *
83
     * @since 1.0
84
     */
85
    public function load_textdomain() {
86
        $locale = apply_filters( 'plugin_locale', get_locale(), 'invoicing' );
87
        
88
        load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' );
89
        load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' );
90
        
91
        /**
92
         * Define language constants.
93
         */
94
        require_once( WPINV_PLUGIN_DIR . 'language.php' );
95
    }
96
        
97
    public function includes() {
98
        global $wpinv_options;
99
        
100
        require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' );
101
        $wpinv_options = wpinv_get_settings();
102
        
103
        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-post-types.php' );
104
        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' );
105
        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' );
106
        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' );
107
        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' );
108
        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' );
109
        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' );
110
        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-invoice-functions.php' );
111
        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' );
112
        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' );
113
        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' );
114
        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' );
115
        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' );
116
        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gd-functions.php' );
117
        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php' );
118
        //require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' );
0 ignored issues
show
Unused Code Comprehensibility introduced by
46% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
119
        //require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' );
0 ignored issues
show
Unused Code Comprehensibility introduced by
46% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
120
        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php' );
121
        //require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscription.php' );
0 ignored issues
show
Unused Code Comprehensibility introduced by
46% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
122
        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php' );
123
        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php' );
124
        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session.php' );
125
        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' );
126
        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' );
127
        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' );
128
        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-shortcodes.php' );
129
        if ( !class_exists( 'Geodir_EUVat' ) ) {
130
            require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' );
131
        }
132
        
133
        $gateways = array_keys( wpinv_get_enabled_payment_gateways() );
134
        if ( !empty( $gateways ) ) {
135
            foreach ( $gateways as $gateway ) {
136
                if ( $gateway == 'manual' ) {
137
                    continue;
138
                }
139
                
140
                $gateway_file = WPINV_PLUGIN_DIR . 'includes/gateways/' . $gateway . '.php';
141
                
142
                if ( file_exists( $gateway_file ) ) {
143
                    require_once( $gateway_file );
144
                }
145
            }
146
        }
147
        require_once( WPINV_PLUGIN_DIR . 'includes/gateways/manual.php' );
148
        
149
        if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
150
            require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' );
151
            require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' );
152
            require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-meta-boxes.php' );
153
            //require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-recurring-admin.php' );
0 ignored issues
show
Unused Code Comprehensibility introduced by
46% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
154
            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-details.php' );
155
            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-items.php' );
156
            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' );
157
            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-address.php' );
158
            require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' );
159
            //require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' );
0 ignored issues
show
Unused Code Comprehensibility introduced by
46% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
160
        }
161
        
162
        // include css inliner
163
        if ( ! class_exists( 'Emogrifier' ) && class_exists( 'DOMDocument' ) ) {
164
            include_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php' );
165
        }
166
        
167
        require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' );
168
    }
169
    
170
    public function init() {
171
    }
172
    
173
    public function admin_init() {
174
        if (!(defined( 'DOING_AJAX' ) && DOING_AJAX)) {
175
        }
176
        
177
        add_action( 'admin_print_scripts-edit.php', array( &$this, 'admin_print_scripts_edit_php' ) );
178
    }
179
180
    public function activation_redirect() {
181
        // Bail if no activation redirect
182
        if ( !get_transient( '_wpinv_activation_redirect' ) ) {
183
            return;
184
        }
185
186
        // Delete the redirect transient
187
        delete_transient( '_wpinv_activation_redirect' );
188
189
        // Bail if activating from network, or bulk
190
        if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
191
            return;
192
        }
193
194
        wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) );
195
        exit;
196
    }
197
    
198
    public function enqueue_scripts() {
199
        $suffix       = '';//defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
0 ignored issues
show
Unused Code Comprehensibility introduced by
48% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
200
        
201
        wp_deregister_style( 'font-awesome' );
202
        wp_register_style( 'font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0' );
203
        wp_enqueue_style( 'font-awesome' );
204
        
205
        wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), WPINV_VERSION );
206
        wp_enqueue_style( 'wpinv_front_style' );
207
               
208
        // Register scripts
209
        wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true );
210
        wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front' . $suffix . '.js', array( 'jquery', 'wpinv-vat-script' ),  WPINV_VERSION );
211
        
212
        $localize                         = array();
213
        $localize['ajax_url']             = admin_url( 'admin-ajax.php' );
214
        $localize['nonce']                = wp_create_nonce( 'wpinv-nonce' );
215
        $localize['currency_symbol']      = wpinv_currency_symbol();
216
        $localize['currency_pos']         = wpinv_currency_position();
217
        $localize['thousand_sep']         = wpinv_thousands_separator();
218
        $localize['decimal_sep']          = wpinv_decimal_separator();
219
        $localize['decimals']             = wpinv_decimals();
220
        
221
        $localize = apply_filters( 'wpinv_front_js_localize', $localize );
222
        
223
        wp_enqueue_script( 'jquery-blockui' );
224
        $autofill_api = wpinv_get_option('address_autofill_api');
225
        $autofill_active = wpinv_get_option('address_autofill_active');
226 View Code Duplication
        if (isset($autofill_active) && 1 == $autofill_active && !empty($autofill_api) && wpinv_is_checkout()) {
227
            wp_enqueue_script('google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array('jquery'), '', false);
228
            wp_enqueue_script('google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array('jquery'), '', true);
229
        }
230
        wp_enqueue_script( 'wpinv-front-script' );
231
        wp_localize_script( 'wpinv-front-script', 'WPInv', $localize );
232
    }
233
    
234
    public function admin_enqueue_scripts() {
235
        global $post, $pagenow;
236
        
237
        $post_type  = wpinv_admin_post_type();
238
        $suffix     = '';//defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
0 ignored issues
show
Unused Code Comprehensibility introduced by
48% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
239
        
240
        wp_deregister_style( 'font-awesome' );
241
        wp_register_style( 'font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0' );
242
        wp_enqueue_style( 'font-awesome' );
243
        
244
        wp_register_style( 'jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16' );
245
        wp_enqueue_style( 'jquery-ui-css' );
246
        
247
        wp_register_style( 'jquery-chosen', WPINV_PLUGIN_URL . 'assets/css/chosen' . $suffix . '.css', array(), '1.6.2' );
248
        wp_enqueue_style( 'jquery-chosen' );
249
250
        wp_register_script( 'jquery-chosen', WPINV_PLUGIN_URL . 'assets/js/chosen.jquery' . $suffix . '.js', array( 'jquery' ), '1.6.2' );
251
        wp_enqueue_script( 'jquery-chosen' );
252
        
253
        wp_register_style( 'wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION );
254
        wp_enqueue_style( 'wpinv_meta_box_style' );
255
        
256
        wp_register_style( 'wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), WPINV_VERSION );
257
        wp_enqueue_style( 'wpinv_admin_style' );
258
        
259
        if ( $post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) ) {
260
            wp_enqueue_script( 'jquery-ui-datepicker' );
261
        }
262
263
        wp_enqueue_style( 'wp-color-picker' );
264
        wp_enqueue_script( 'wp-color-picker' );
265
        
266
        wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true );
267
268
        if ($post_type == 'wpi_invoice' || $post_type == 'wpi_quote' && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) {
269
            $autofill_api = wpinv_get_option('address_autofill_api');
270
            $autofill_active = wpinv_get_option('address_autofill_active');
271 View Code Duplication
            if (isset($autofill_active) && 1 == $autofill_active && !empty($autofill_api)) {
272
                wp_enqueue_script('google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array('jquery'), '', false);
273
                wp_enqueue_script('google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array('jquery'), '', true);
274
            }
275
        }
276
277
        wp_register_script( 'wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin' . $suffix . '.js', array( 'jquery', 'jquery-blockui' ),  WPINV_VERSION );
278
        wp_enqueue_script( 'wpinv-admin-script' );
279
        
280
        $localize                               = array();
281
        $localize['ajax_url']                   = admin_url( 'admin-ajax.php' );
282
        $localize['post_ID']                    = isset( $post->ID ) ? $post->ID : '';
283
        $localize['wpinv_nonce']                = wp_create_nonce( 'wpinv-nonce' );
284
        $localize['add_invoice_note_nonce']     = wp_create_nonce( 'add-invoice-note' );
285
        $localize['delete_invoice_note_nonce']  = wp_create_nonce( 'delete-invoice-note' );
286
        $localize['invoice_item_nonce']         = wp_create_nonce( 'invoice-item' );
287
        $localize['billing_details_nonce']      = wp_create_nonce( 'get-billing-details' );
288
        $localize['tax']                        = wpinv_tax_amount();
289
        $localize['discount']                   = wpinv_discount_amount();
290
        $localize['currency_symbol']            = wpinv_currency_symbol();
291
        $localize['currency_pos']               = wpinv_currency_position();
292
        $localize['thousand_sep']               = wpinv_thousands_separator();
293
        $localize['decimal_sep']                = wpinv_decimal_separator();
294
        $localize['decimals']                   = wpinv_decimals();
295
        $localize['save_invoice']               = __( 'Save Invoice', 'invoicing' );
296
        $localize['status_publish']             = wpinv_status_nicename( 'publish' );
297
        $localize['status_pending']             = wpinv_status_nicename( 'wpi-pending' );
298
        $localize['delete_tax_rate']            = __( 'Are you sure you wish to delete this tax rate?', 'invoicing' );
299
        $localize['OneItemMin']                 = __( 'Invoice must contain at least one item', 'invoicing' );
300
        $localize['DeleteInvoiceItem']          = __( 'Are you sure you wish to delete this item?', 'invoicing' );
301
        $localize['FillBillingDetails']         = __( 'Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing' );
302
        $localize['confirmCalcTotals']          = __( 'Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing' );
303
        $localize['AreYouSure']                 = __( 'Are you sure?', 'invoicing' );
304
        $localize['hasGD']                      = wpinv_gd_active();
305
        $localize['hasPM']                      = wpinv_pm_active();
306
        $localize['emptyInvoice']               = __( 'Add atleast one item to save invoice!', 'invoicing' );
307
        $localize['deletePackage']              = __( 'GD package items should be deleted from GD payment manager only, otherwise it will break invoices that created with this package!', 'invoicing' );
308
        $localize['deletePackages']             = __( 'GD package items should be deleted from GD payment manager only', 'invoicing' );
309
        $localize['deleteInvoiceFirst']         = __( 'This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing' );
310
311
        $localize = apply_filters( 'wpinv_admin_js_localize', $localize );
312
313
        wp_localize_script( 'wpinv-admin-script', 'WPInv_Admin', $localize );
314
    }
315
    
316
    public function admin_body_class( $classes ) {
317
        global $pagenow, $post, $current_screen;
318
        
319
        if ( !empty( $current_screen->post_type ) && ( $current_screen->post_type == 'wpi_invoice' || $current_screen->post_type == 'wpi_quote' ) ) {
320
            $classes .= ' wpinv-cpt';
321
        }
322
        
323
        $page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : false;
324
325
        $add_class = false;
326
        if ( $pagenow == 'admin.php' && $page ) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $page of type string|false is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
327
            $add_class = strpos( $page, 'wpinv-' );
328
        }
329
        
330
        $settings_class = array();
331
        if ( $page == 'wpinv-settings' ) {
332
            if ( !empty( $_REQUEST['tab'] ) ) {
333
                $settings_class[] = sanitize_text_field( $_REQUEST['tab'] );
334
            }
335
            
336
            if ( !empty( $_REQUEST['section'] ) ) {
337
                $settings_class[] = sanitize_text_field( $_REQUEST['section'] );
338
            }
339
            
340
            $settings_class[] = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field( $_REQUEST['wpi_sub'] ) : 'main';
341
        }
342
        
343
        if ( !empty( $settings_class ) ) {
344
            $classes .= ' wpi-' . wpinv_sanitize_key( implode( $settings_class, '-' ) );
345
        }
346
        
347
        $post_type = wpinv_admin_post_type();
348
349
        if ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false ) {
350
            return $classes .= ' wpinv';
351
        }
352
        
353
        if ( $pagenow == 'post.php' && $post_type == 'wpi_item' && !empty( $post ) && !wpinv_item_is_editable( $post ) ) {
354
            $classes .= ' wpi-editable-n';
355
        }
356
357
        return $classes;
358
    }
359
    
360
    public function admin_print_scripts_edit_php() {
361
362
    }
363
    
364
    public function wpinv_actions() {
365
        if ( isset( $_REQUEST['wpi_action'] ) ) {
366
            do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST );
367
        }
368
    }
369
    
370
    public function pre_get_posts( $wp_query ) {
371
        if ( !empty( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) {
372
            $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses() );
373
        }
374
        
375
        return $wp_query;
376
    }
377
    
378
    public function bp_invoicing_init() {
379
        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' );
380
    }
381
}