Completed
Push — master ( 42ba23...5fbbab )
by Julien
03:55
created

scripts.php ➔ wpbo_enqueue_scripts()   C

Complexity

Conditions 10
Paths 66

Size

Total Lines 50
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 6
Bugs 1 Features 1
Metric Value
cc 10
eloc 22
c 6
b 1
f 1
nc 66
nop 0
dl 0
loc 50
rs 5.7647

How to fix   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
 * BetterOptin Installer
4
 *
5
 * @package   BetterOptin/Install
6
 * @author    ThemeAvenue <[email protected]>
7
 * @license   GPL-2.0+
8
 * @link      http://themeavenue.net
9
 * @copyright 2015 ThemeAvenue
10
 */
11
12
// If this file is called directly, abort.
13
if ( ! defined( 'WPINC' ) ) {
14
	die;
15
}
16
17
add_action( 'wp_enqueue_scripts', 'wpbo_enqueue_styles' );
18
/**
19
 * Register and enqueue public-facing style sheet.
20
 *
21
 * @since    1.0.0
22
 */
23
function wpbo_enqueue_styles() {
24
25
	if ( is_admin() ) {
26
		return;
27
	}
28
29
	if ( ! wpbo_page_has_popup() ) {
30
		return;
31
	}
32
33
	wp_enqueue_style( 'wpbo-main', WPBO_URL . 'public/assets/css/betteroptin.css', array(), WPBO_VERSION );
34
}
35
36
37
add_action( 'wp_enqueue_scripts', 'wpbo_enqueue_scripts' );
38
/**
39
 * Register and enqueues public-facing JavaScript files.
40
 *
41
 * @since    1.0.0
42
 */
43
function wpbo_enqueue_scripts() {
44
45
	if ( is_admin() ) {
46
		return;
47
	}
48
49
	if ( ! wpbo_page_has_popup() ) {
50
		return;
51
	}
52
53
	$settings = get_post_meta( wpbo_page_has_popup(), '_wpbo_settings', true );
54
55
	/**
56
	 * Check if we can display the credit.
57
	 */
58
	$settings['credit'] = apply_filters( 'wpbo_show_credit', true );
59
60
	/**
61
	 * Use booleans
62
	 */
63
	$settings['close_overlay']     = isset( $settings['close_overlay'] ) ? true : false;
64
	$settings['close_esc']         = isset( $settings['close_esc'] ) ? true : false;
65
	$settings['hide_close_button'] = isset( $settings['hide_close_button'] ) ? true : false;
66
	$settings['wiggle']            = isset( $settings['wiggle'] ) ? true : false;
67
	$settings['cookie_lifetime']   = isset( $settings['cookie_lifetime'] ) ? intval( $settings['cookie_lifetime'] ) : 30;
68
69
	/**
70
	 * Add popup ID
71
	 */
72
	$settings['popup_id'] = wpbo_page_has_popup();
73
74
	/**
75
	 * Define Ajax URL
76
	 */
77
	$settings['ajaxurl'] = admin_url( 'admin-ajax.php' );
78
79
	/**
80
	 * Load un-minified scripts if debug mode is enabled 
81
	 */
82
	if (defined('WP_DEBUG') && true === WP_DEBUG) {
83
		wp_enqueue_script( 'wpbo-easyModal', WPBO_URL . 'bower_components/easyModal.js/jquery.easyModal.js', array( 'jquery' ), '1.3.2' );
84
		wp_enqueue_script( 'wpbo-cookie', WPBO_URL . 'bower_components/jquery.cookie/jquery.cookie.js', array( 'jquery' ), '1.4.1' );
85
		wp_enqueue_script( 'wpbo-matchHeight', WPBO_URL . 'bower_components/matchHeight/jquery.matchHeight.js', array( 'jquery' ), '0.5.2' );
86
		wp_enqueue_script( 'wpbo-script', WPBO_URL . 'public/assets/js/betterOptin.js', array( 'jquery' ), WPBO_VERSION );
87
	} else {
88
		wp_enqueue_script( 'wpbo-script', WPBO_URL . 'public/assets/js/betterOptin.min.js', array( 'jquery' ), WPBO_VERSION );
89
	}
90
	wp_localize_script( 'wpbo-script', 'wpbo', json_encode( $settings ) );
91
92
}
93
94
add_action( 'admin_enqueue_scripts', 'wpbo_enqueue_admin_styles' );
95
/**
96
 * Register and enqueue admin-specific style sheet
97
 *
98
 * @since     1.0.0
99
 * @return    null    Return early if no settings page is registered.
100
 */
101
function wpbo_enqueue_admin_styles() {
102
103
	global $post, $current_screen;
104
105
	if ( wpbo_is_plugin_page() ) {
106
107
		wp_enqueue_style( 'wpbo-admin', WPBO_URL . 'admin/assets/css/admin.css', array(), WPBO_VERSION );
108
		wp_enqueue_style( 'wpbo-admin-chosen', WPBO_URL . 'bower_components/chosen_v1.1.0/chosen.min.css', array(), WPBO_VERSION );
109
110
		/* Customizer page */
111
		if ( isset( $_GET['wpbo_popup'] ) ) {
112
113
			wp_enqueue_style( 'wpbo-editor', WPBO_URL . 'admin/assets/css/ta-editor.css', array(), WPBO_VERSION );
114
			wp_enqueue_style( 'wpbo-main', WPBO_URL . 'public/assets/css/betteroptin.css', array(), WPBO_VERSION );
115
116
		}
117
118
		/* Load colorpicker style */
119
		if ( isset( $_GET['action'] ) && 'edit' == $_GET['action'] ||
120
		     isset( $current_screen->action ) && isset( $current_screen->post_type ) && 'add' == $current_screen->action && 'wpbo-popup' == $current_screen->post_type ||
121
		     isset( $current_screen->base ) && 'wpbo-popup_page_wpbo-customizer' == $current_screen->base
122
		) {
123
			wp_enqueue_style( 'wp-color-picker' );
124
		}
125
126
		/* Analytics page */
127
		if ( isset( $_GET['page'] ) && 'wpbo-analytics' == $_GET['page'] ) {
128
129
			wp_enqueue_style( 'wpbo-dataTables', '//cdnjs.cloudflare.com/ajax/libs/datatables/1.10.1/css/jquery.dataTables.min.css', array(), WPBO_VERSION );
130
			wp_enqueue_style( 'wpbo-circliful', WPBO_URL . 'bower_components/circliful/css/jquery.circliful.css', array(), WPBO_VERSION );
131
132
		}
133
134
	}
135
136
}
137
138
139
add_action( 'admin_enqueue_scripts', 'wpbo_enqueue_admin_scripts' );
140
/**
141
 * Register and enqueue admin-specific JavaScript.
142
 *
143
 * @since     1.0.0
144
 * @return    null    Return early if no settings page is registered.
145
 */
146
function wpbo_enqueue_admin_scripts() {
147
148
	global $post, $current_screen;
149
150
	if ( wpbo_is_plugin_page() ) {
151
152
		/* Required on all plugin pages */
153
		wp_enqueue_script( 'wpbo--admin', WPBO_URL . 'admin/assets/js/admin.js', array( 'jquery' ), WPBO_VERSION );
154
155
		if ( isset( $_GET['action'] ) && 'edit' == $_GET['action'] || isset( $_GET['post_type'] ) && 'wpbo-popup' == $_GET['post_type'] ) {
156
157
			wp_enqueue_script( 'wpbo-admin-chosen', WPBO_URL . 'bower_components/chosen_v1.1.0/chosen.jquery.min.js', array( 'jquery' ), WPBO_VERSION );
158
159
		}
160
161
		/* Required only on the post edit screen */
162
		if ( isset( $_GET['action'] ) && 'edit' == $_GET['action'] || isset( $current_screen->action ) && isset( $current_screen->post_type ) && 'add' == $current_screen->action && 'wpbo-popup' == $current_screen->post_type ) {
163
			wp_enqueue_script( 'wp-color-picker' );
164
		}
165
166
		/* Required on the customizer page only */
167
		if ( isset( $_GET['wpbo_popup'] ) ) {
168
169
			wp_enqueue_media();
170
			wp_enqueue_script( 'wpbo-admin-script', WPBO_URL . 'admin/assets/js/ta-live-editor.js', array( 'jquery', 'wp-color-picker' ), WPBO_VERSION );
171
			wp_enqueue_script( 'wpbo-admin-autosize', WPBO_URL . 'bower_components/jquery-autosize/jquery.autosize.min.js', array( 'jquery' ), WPBO_VERSION );
172
			wp_enqueue_script( 'wpbo-admin-matchHeight', WPBO_URL . 'bower_components/matchHeight/jquery.matchHeight-min.js', array( 'jquery' ), WPBO_VERSION );
173
174
		}
175
176
		if ( isset( $_GET['page'] ) ) {
177
178
			/* Analytics page */
179
			if ( 'wpbo-analytics' == $_GET['page'] ) {
180
181
				wp_enqueue_script( 'wpbo-admin-dataTables', '//cdnjs.cloudflare.com/ajax/libs/datatables/1.10.1/js/jquery.dataTables.min.js', array( 'jquery' ), WPBO_VERSION );
182
				wp_enqueue_script( 'wpbo-admin-flot', WPBO_URL . 'bower_components/flot/jquery.flot.js', array( 'jquery' ), WPBO_VERSION );
183
				wp_enqueue_script( 'wpbo-admin-flot-time', WPBO_URL . 'bower_components/flot/jquery.flot.time.js', array( 'jquery' ), WPBO_VERSION );
184
				wp_enqueue_script( 'wpbo-admin-flot-tooltip', WPBO_URL . 'bower_components/flot.tooltip/js/jquery.flot.tooltip.min.js', array( 'jquery' ), WPBO_VERSION );
185
				wp_enqueue_script( 'wpbo-admin-circliful', WPBO_URL . 'bower_components/circliful/js/jquery.circliful.min.js', array( 'jquery' ), WPBO_VERSION );
186
				wp_enqueue_script( 'wpbo-admin-analytics', WPBO_URL . 'admin/assets/js/part-analytics.js', array( 'jquery' ), WPBO_VERSION );
187
188
			}
189
190
		}
191
192
	}
193
194
}