Passed
Push — master ( cf7cb5...555ee7 )
by Brian
09:37 queued 04:37
created

WPInv_Plugin::wp_footer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 2
rs 10
c 0
b 0
f 0
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 Best Practice introduced by
The property notes does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
23
            self::$instance->reports              = new WPInv_Reports();
0 ignored issues
show
Bug Best Practice introduced by
The property reports does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
24
            self::$instance->api                  = new WPInv_API();
0 ignored issues
show
Bug Best Practice introduced by
The property api does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
25
            self::$instance->form_elements        = new WPInv_Payment_Form_Elements();
0 ignored issues
show
Bug Best Practice introduced by
The property form_elements does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
26
        }
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( &$this, 'wpinv_actions' ) );
48
        
49
        if ( class_exists( 'BuddyPress' ) ) {
50
            add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) );
51
        }
52
53
        add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) );
54
        add_action( 'wp_footer', array( &$this, 'wp_footer' ) );
55
        add_action( 'widgets_init', array( &$this, 'register_widgets' ) );
56
        add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) );
57
58
        if ( is_admin() ) {
59
            add_action( 'admin_enqueue_scripts', array( &$this, 'admin_enqueue_scripts' ) );
60
            add_filter( 'admin_body_class', array( &$this, 'admin_body_class' ) );
61
            add_action( 'admin_init', array( &$this, 'init_ayecode_connect_helper' ) );
62
63
        } else {
64
            add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) );
65
        }
66
        
67
        /**
68
         * Fires after the setup of all WPInv_Plugin actions.
69
         *
70
         * @since 1.0.0
71
         *
72
         * @param WPInv_Plugin $this. Current WPInv_Plugin instance. Passed by reference.
73
         */
74
        do_action_ref_array( 'wpinv_actions', array( &$this ) );
75
76
        add_action( 'admin_init', array( &$this, 'activation_redirect') );
77
    }
78
79
    /**
80
     * Maybe show the AyeCode Connect Notice.
81
     */
82
    public function init_ayecode_connect_helper(){
83
        // AyeCode Connect notice
84
        if ( is_admin() ){
85
            // set the strings so they can be translated
86
            $strings = array(
87
                'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"),
88
                'connect_external'  => __( "Please confirm you wish to connect your site?","invoicing" ),
89
                'connect'           => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ),
90
                'connect_button'    => __("Connect Site","invoicing"),
91
                'connecting_button'    => __("Connecting...","invoicing"),
92
                'error_localhost'   => __( "This service will only work with a live domain, not a localhost.","invoicing" ),
93
                'error'             => __( "Something went wrong, please refresh and try again.","invoicing" ),
94
            );
95
            new AyeCode_Connect_Helper($strings,array('wpi-addons'));
96
        }
97
    }
98
    
99
    public function plugins_loaded() {
100
        /* Internationalize the text strings used. */
101
        $this->load_textdomain();
102
103
        do_action( 'wpinv_loaded' );
104
105
        // Fix oxygen page builder conflict
106
        if ( function_exists( 'ct_css_output' ) ) {
107
            wpinv_oxygen_fix_conflict();
108
        }
109
    }
110
    
111
    /**
112
     * Load the translation of the plugin.
113
     *
114
     * @since 1.0
115
     */
116
    public function load_textdomain( $locale = NULL ) {
117
        if ( empty( $locale ) ) {
118
            $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale();
119
        }
120
121
        $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' );
0 ignored issues
show
Unused Code introduced by
The call to get_locale() has too many arguments starting with $locale. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

121
        $locale = /** @scrutinizer ignore-call */ apply_filters( 'plugin_locale', $locale, 'invoicing' );

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
122
        
123
        unload_textdomain( 'invoicing' );
124
        load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' );
125
        load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' );
126
        
127
        /**
128
         * Define language constants.
129
         */
130
        require_once( WPINV_PLUGIN_DIR . 'language.php' );
131
    }
132
133
    public function includes() {
134
        global $wpinv_options;
135
136
        require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' );
137
        $wpinv_options = wpinv_get_settings();
138
        
139
        require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' );
140
        require_once( WPINV_PLUGIN_DIR . 'includes/libraries/action-scheduler/action-scheduler.php' );
141
        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' );
142
        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' );
143
        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' );
144
        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' );
145
        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' );
146
        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' );
147
        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-invoice-functions.php' );
148
        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' );
149
        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' );
150
        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' );
151
        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' );
152
        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' );
153
        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php' );
154
        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-post-types.php' );
155
        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php' );
156
        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-discount.php' );
157
        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php' );
158
        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php' );
159
        require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' );
160
        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' );
161
        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' );
162
        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' );
163
        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' );
164
        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' );
165
        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' );
166
        require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' );
167
        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' );
168
        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions.php' );
169
        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' );
170
        require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-subscriptions-list-table.php' );
171
        require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' );
172
        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' );
173
        require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' );
174
        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' );
175
	    require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' );
176
	    require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' );
177
	    require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' );
178
	    require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' );
179
	    require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' );
180
        require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' );
181
        require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' );
182
        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-payment-form-elements.php' );
183
184
        if ( !class_exists( 'WPInv_EUVat' ) ) {
185
            require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' );
186
        }
187
        
188
        $gateways = array_keys( wpinv_get_enabled_payment_gateways() );
189
        if ( !empty( $gateways ) ) {
190
            foreach ( $gateways as $gateway ) {
191
                if ( $gateway == 'manual' ) {
192
                    continue;
193
                }
194
                
195
                $gateway_file = WPINV_PLUGIN_DIR . 'includes/gateways/' . $gateway . '.php';
196
                
197
                if ( file_exists( $gateway_file ) ) {
198
                    require_once( $gateway_file );
199
                }
200
            }
201
        }
202
        require_once( WPINV_PLUGIN_DIR . 'includes/gateways/manual.php' );
203
        
204
        if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
0 ignored issues
show
Bug introduced by
The constant WP_CLI was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
205
            require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' );
206
            require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' );
207
            require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-meta-boxes.php' );
208
            //require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-recurring-admin.php' );
209
            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-details.php' );
210
            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-items.php' );
211
            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' );
212
            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' );
213
            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-address.php' );
214
            require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' );
215
            require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' );
216
            require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' );
217
            //require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' );
218
            // load the user class only on the users.php page
219
            global $pagenow;
220
            if($pagenow=='users.php'){
221
                new WPInv_Admin_Users();
222
            }
223
        }
224
225
        // Register cli commands
226
        if ( defined( 'WP_CLI' ) && WP_CLI ) {
227
            require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' );
228
            WP_CLI::add_command( 'invoicing', 'WPInv_CLI' );
0 ignored issues
show
Bug introduced by
The type WP_CLI was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
229
        }
230
        
231
        // include css inliner
232
        if ( ! class_exists( 'Emogrifier' ) && class_exists( 'DOMDocument' ) ) {
233
            include_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php' );
234
        }
235
        
236
        require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' );
237
    }
238
    
239
    public function init() {
240
    }
241
    
242
    public function admin_init() {
243
        self::$instance->default_payment_form = wpinv_get_default_payment_form();
244
        add_action( 'admin_print_scripts-edit.php', array( &$this, 'admin_print_scripts_edit_php' ) );
245
    }
246
247
    public function activation_redirect() {
248
        // Bail if no activation redirect
249
        if ( !get_transient( '_wpinv_activation_redirect' ) ) {
250
            return;
251
        }
252
253
        // Delete the redirect transient
254
        delete_transient( '_wpinv_activation_redirect' );
255
256
        // Bail if activating from network, or bulk
257
        if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
258
            return;
259
        }
260
261
        wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) );
262
        exit;
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
263
    }
264
    
265
    public function enqueue_scripts() {
266
        $suffix       = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
267
        
268
        wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), WPINV_VERSION );
269
        wp_enqueue_style( 'wpinv_front_style' );
270
               
271
        // Register scripts
272
        wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true );
273
        wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array( 'jquery' ),  filemtime( WPINV_PLUGIN_DIR . 'assets/js/invoice-front.js' ) );
274
275
        $localize                         = array();
276
        $localize['ajax_url']             = admin_url( 'admin-ajax.php' );
277
        $localize['nonce']                = wp_create_nonce( 'wpinv-nonce' );
278
        $localize['currency_symbol']      = wpinv_currency_symbol();
279
        $localize['currency_pos']         = wpinv_currency_position();
280
        $localize['thousand_sep']         = wpinv_thousands_separator();
281
        $localize['decimal_sep']          = wpinv_decimal_separator();
282
        $localize['decimals']             = wpinv_decimals();
283
        $localize['txtComplete']          = __( 'Continue', 'invoicing' );
284
        $localize['UseTaxes']             = wpinv_use_taxes();
285
        $localize['checkoutNonce']        = wp_create_nonce( 'wpinv_checkout_nonce' );
286
287
        $localize = apply_filters( 'wpinv_front_js_localize', $localize );
288
        
289
        wp_enqueue_script( 'jquery-blockui' );
290
        $autofill_api = wpinv_get_option('address_autofill_api');
291
        $autofill_active = wpinv_get_option('address_autofill_active');
292
        if ( isset( $autofill_active ) && 1 == $autofill_active && !empty( $autofill_api ) && wpinv_is_checkout() ) {
293
            if ( wp_script_is( 'google-maps-api', 'enqueued' ) ) {
294
                wp_dequeue_script( 'google-maps-api' );
295
            }
296
            wp_enqueue_script( 'google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array( 'jquery' ), '', false );
297
            wp_enqueue_script( 'google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array( 'jquery', 'google-maps-api' ), '', true );
298
        }
299
300
        wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all' );
301
        wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION );
302
303
        wp_enqueue_script( 'wpinv-front-script' );
304
        wp_localize_script( 'wpinv-front-script', 'WPInv', $localize );
305
306
        $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' );
307
        wp_enqueue_script( 'wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'wpinv-front-script', 'wp-hooks' ),  $version, true );
308
    }
309
310
    public function admin_enqueue_scripts( $hook ) {
311
        global $post, $pagenow;
312
        
313
        $post_type  = wpinv_admin_post_type();
314
        $suffix     = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
315
        $page       = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : '';
316
317
        $jquery_ui_css = false;
318
        if ( ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $post_type == 'wpi_discount' ) && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) ) {
319
            $jquery_ui_css = true;
320
        } else if ( $page == 'wpinv-settings' || $page == 'wpinv-reports' ) {
321
            $jquery_ui_css = true;
322
        }
323
        if ( $jquery_ui_css ) {
324
            wp_register_style( 'jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16' );
325
            wp_enqueue_style( 'jquery-ui-css' );
326
            wp_deregister_style( 'yoast-seo-select2' );
327
	        wp_deregister_style( 'yoast-seo-monorepo' );
328
        }
329
330
        wp_register_style( 'wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION );
331
        wp_enqueue_style( 'wpinv_meta_box_style' );
332
        
333
        $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/admin.css' );
334
        wp_register_style( 'wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), $version );
335
        wp_enqueue_style( 'wpinv_admin_style' );
336
337
        $enqueue = ( $post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) );
338
        if ( $page == 'wpinv-subscriptions' ) {
339
            wp_enqueue_script( 'jquery-ui-datepicker' );
340
            wp_deregister_style( 'yoast-seo-select2' );
341
	        wp_deregister_style( 'yoast-seo-monorepo' );
342
        }
343
        
344
        if ( $enqueue_datepicker = apply_filters( 'wpinv_admin_enqueue_jquery_ui_datepicker', $enqueue ) ) {
0 ignored issues
show
Unused Code introduced by
The assignment to $enqueue_datepicker is dead and can be removed.
Loading history...
345
            wp_enqueue_script( 'jquery-ui-datepicker' );
346
        }
347
348
        wp_enqueue_style( 'wp-color-picker' );
349
        wp_enqueue_script( 'wp-color-picker' );
350
        
351
        wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true );
352
353
        if (($post_type == 'wpi_invoice' || $post_type == 'wpi_quote') && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) {
354
            $autofill_api = wpinv_get_option('address_autofill_api');
355
            $autofill_active = wpinv_get_option('address_autofill_active');
356
            if (isset($autofill_active) && 1 == $autofill_active && !empty($autofill_api)) {
357
                wp_enqueue_script('google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array('jquery'), '', false);
358
                wp_enqueue_script('google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array('jquery'), '', true);
359
            }
360
        }
361
362
        wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all' );
363
        wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION );
364
365
        $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin.js' );
366
        wp_register_script( 'wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array( 'jquery', 'jquery-blockui','jquery-ui-tooltip' ),  $version );
367
        wp_enqueue_script( 'wpinv-admin-script' );
368
        
369
        $localize                               = array();
370
        $localize['ajax_url']                   = admin_url( 'admin-ajax.php' );
371
        $localize['post_ID']                    = isset( $post->ID ) ? $post->ID : '';
372
        $localize['wpinv_nonce']                = wp_create_nonce( 'wpinv-nonce' );
373
        $localize['add_invoice_note_nonce']     = wp_create_nonce( 'add-invoice-note' );
374
        $localize['delete_invoice_note_nonce']  = wp_create_nonce( 'delete-invoice-note' );
375
        $localize['invoice_item_nonce']         = wp_create_nonce( 'invoice-item' );
376
        $localize['billing_details_nonce']      = wp_create_nonce( 'get-billing-details' );
377
        $localize['tax']                        = wpinv_tax_amount();
378
        $localize['discount']                   = wpinv_discount_amount();
379
        $localize['currency_symbol']            = wpinv_currency_symbol();
380
        $localize['currency_pos']               = wpinv_currency_position();
381
        $localize['thousand_sep']               = wpinv_thousands_separator();
382
        $localize['decimal_sep']                = wpinv_decimal_separator();
383
        $localize['decimals']                   = wpinv_decimals();
384
        $localize['save_invoice']               = __( 'Save Invoice', 'invoicing' );
385
        $localize['status_publish']             = wpinv_status_nicename( 'publish' );
386
        $localize['status_pending']             = wpinv_status_nicename( 'wpi-pending' );
387
        $localize['delete_tax_rate']            = __( 'Are you sure you wish to delete this tax rate?', 'invoicing' );
388
        $localize['OneItemMin']                 = __( 'Invoice must contain at least one item', 'invoicing' );
389
        $localize['DeleteInvoiceItem']          = __( 'Are you sure you wish to delete this item?', 'invoicing' );
390
        $localize['FillBillingDetails']         = __( 'Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing' );
391
        $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' );
392
        $localize['AreYouSure']                 = __( 'Are you sure?', 'invoicing' );
393
        $localize['emptyInvoice']               = __( 'Add at least one item to save invoice!', 'invoicing' );
394
        $localize['errDeleteItem']              = __( 'This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing' );
395
        $localize['delete_subscription']        = __( 'Are you sure you want to delete this subscription?', 'invoicing' );
396
        $localize['action_edit']                = __( 'Edit', 'invoicing' );
397
        $localize['action_cancel']              = __( 'Cancel', 'invoicing' );
398
399
        $localize = apply_filters( 'wpinv_admin_js_localize', $localize );
400
401
        wp_localize_script( 'wpinv-admin-script', 'WPInv_Admin', $localize );
402
403
        // Load payment form scripts on our admin pages only.
404
        if ( ( $hook == 'post-new.php' || $hook == 'post.php' ) && 'wpi_payment_form' === $post->post_type ) {
405
406
            wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION );
407
            wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION );
408
            wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION );
409
410
            $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' );
411
            wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ),  $version );
412
        
413
            wp_localize_script( 'wpinv-admin-payment-form-script', 'wpinvPaymentFormAdmin', array(
414
                'elements'      => $this->form_elements->get_elements(),
415
                'form_elements' => $this->form_elements->get_form_elements( $post->ID ),
416
                'all_items'     => $this->form_elements->get_published_items(),
417
                'currency'      => wpinv_currency_symbol(),
418
                'position'      => wpinv_currency_position(),
419
                'decimals'      => (int) wpinv_decimals(),
420
                'thousands_sep' => wpinv_thousands_separator(),
421
                'decimals_sep'  => wpinv_decimal_separator(),
422
                'form_items'    => $this->form_elements->get_form_items( $post->ID ),
423
                'is_default'    => $post->ID == $this->default_payment_form,
424
            ) );
425
426
            wp_enqueue_script( 'wpinv-admin-payment-form-script' );
427
        }
428
429
        if ( $page == 'wpinv-subscriptions' ) {
430
            wp_register_script( 'wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array( 'wpinv-admin-script' ),  WPINV_VERSION );
431
            wp_enqueue_script( 'wpinv-sub-admin-script' );
432
        }
433
434
        if ( $page == 'wpinv-reports' ) {
435
            wp_enqueue_script( 'jquery-flot', WPINV_PLUGIN_URL . 'assets/js/jquery.flot.min.js', array( 'jquery' ), '0.7' );
436
        }
437
438
    }
439
440
    public function admin_body_class( $classes ) {
441
        global $pagenow, $post, $current_screen;
442
        
443
        if ( !empty( $current_screen->post_type ) && ( $current_screen->post_type == 'wpi_invoice' || $current_screen->post_type == 'wpi_payment_form' || $current_screen->post_type == 'wpi_quote' ) ) {
444
            $classes .= ' wpinv-cpt';
445
        }
446
        
447
        $page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : false;
448
449
        $add_class = $page && $pagenow == 'admin.php' && strpos( $page, 'wpinv-' ) === 0 ? true : false;
450
        if ( $add_class ) {
451
            $classes .= ' wpi-' . wpinv_sanitize_key( $page );
452
        }
453
        
454
        $settings_class = array();
455
        if ( $page == 'wpinv-settings' ) {
456
            if ( !empty( $_REQUEST['tab'] ) ) {
457
                $settings_class[] = sanitize_text_field( $_REQUEST['tab'] );
458
            }
459
            
460
            if ( !empty( $_REQUEST['section'] ) ) {
461
                $settings_class[] = sanitize_text_field( $_REQUEST['section'] );
462
            }
463
            
464
            $settings_class[] = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field( $_REQUEST['wpi_sub'] ) : 'main';
465
        }
466
        
467
        if ( !empty( $settings_class ) ) {
468
            $classes .= ' wpi-' . wpinv_sanitize_key( implode( $settings_class, '-' ) );
0 ignored issues
show
Unused Code introduced by
The call to implode() has too many arguments starting with '-'. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

468
            $classes .= ' wpi-' . wpinv_sanitize_key( /** @scrutinizer ignore-call */ implode( $settings_class, '-' ) );

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
469
        }
470
        
471
        $post_type = wpinv_admin_post_type();
472
473
        if ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false ) {
474
            return $classes .= ' wpinv';
475
        }
476
        
477
        if ( $pagenow == 'post.php' && $post_type == 'wpi_item' && !empty( $post ) && !wpinv_item_is_editable( $post ) ) {
478
            $classes .= ' wpi-editable-n';
479
        }
480
481
        return $classes;
482
    }
483
    
484
    public function admin_print_scripts_edit_php() {
485
486
    }
487
    
488
    public function wpinv_actions() {
489
        if ( isset( $_REQUEST['wpi_action'] ) ) {
490
            do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST );
491
        }
492
    }
493
    
494
    public function pre_get_posts( $wp_query ) {
495
        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() ) {
496
            $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses() );
497
        }
498
        
499
        return $wp_query;
500
    }
501
    
502
    public function bp_invoicing_init() {
503
        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' );
504
    }
505
506
	/**
507
	 * Register widgets
508
	 *
509
	 */
510
	public function register_widgets() {
511
		register_widget( "WPInv_Checkout_Widget" );
512
		register_widget( "WPInv_History_Widget" );
513
		register_widget( "WPInv_Receipt_Widget" );
514
		register_widget( "WPInv_Subscriptions_Widget" );
515
		register_widget( "WPInv_Buy_Item_Widget" );
516
        register_widget( "WPInv_Messages_Widget" );
517
        register_widget( 'WPInv_GetPaid_Widget' );
518
	}
519
    
520
    /**
521
     * Remove our pages from yoast sitemaps.
522
     *
523
     * @since 1.0.19
524
     * @param int[] $excluded_posts_ids
525
     */
526
    public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){
527
528
        // Ensure that we have an array.
529
        if ( ! is_array( $excluded_posts_ids ) ) {
0 ignored issues
show
introduced by
The condition is_array($excluded_posts_ids) is always true.
Loading history...
530
            $excluded_posts_ids = array();
531
        }
532
533
        // Prepare our pages.
534
        $our_pages = array();
535
    
536
        // Checkout page.
537
        $our_pages[] = wpinv_get_option( 'checkout_page', false );
538
539
        // Success page.
540
        $our_pages[] = wpinv_get_option( 'success_page', false );
541
542
        // Failure page.
543
        $our_pages[] = wpinv_get_option( 'failure_page', false );
544
545
        // History page.
546
        $our_pages[] = wpinv_get_option( 'invoice_history_page', false );
547
548
        // Subscriptions page.
549
        $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false );
550
551
        $our_pages   = array_map( 'intval', array_filter( $our_pages ) );
552
553
        $excluded_posts_ids = $excluded_posts_ids + $our_pages;
554
        return array_unique( $excluded_posts_ids );
555
556
    }
557
558
    public function wp_footer() {
559
        echo '
560
            <div class="bsui">
561
                <div  id="getpaid-payment-modal" class="modal" tabindex="-1" role="dialog">
562
                    <div class="modal-dialog modal-dialog-centered modal-lg" role="document">
563
                        <div class="modal-content">
564
                            <div class="modal-body"></div>
565
                        </div>
566
                    </div>
567
                </div>
568
            </div>
569
        ';
570
    }
571
572
}
573