Passed
Push — master ( 2e0b8e...1bd345 )
by Warwick
03:19
created

scripts.php ➔ lsx_scripts_add_fonts()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 72

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 0
dl 0
loc 72
rs 8.6109
c 0
b 0
f 0

How to fix   Long Method   

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
 * LSX functions and definitions - Scripts.
4
 *
5
 * @package    lsx
6
 * @subpackage scripts
7
 */
8
9
if ( ! defined( 'ABSPATH' ) ) {
10
	exit;
11
}
12
13
if ( ! function_exists( 'lsx_scripts' ) ) :
14
15
	/**
16
	 * Enqueue scripts, fonts and styles.
17
	 *
18
	 * @package    lsx
19
	 * @subpackage scripts
20
	 */
21
	function lsx_scripts() {
22
		lsx_scripts_add_styles();
23
		lsx_scripts_add_fonts();
24
		lsx_scripts_add_scripts();
25
	}
26
27
endif;
28
29
add_action( 'wp_enqueue_scripts', 'lsx_scripts', 5 );
30
31
if ( ! function_exists( 'lsx_admin_scripts' ) ) :
32
33
	/**
34
	 * Enqueue scripts (admin).
35
	 *
36
	 * @package    lsx
37
	 * @subpackage scripts
38
	 */
39
	function lsx_admin_scripts() {
40
		wp_enqueue_script( 'lsx-admin', get_template_directory_uri() . '/assets/js/admin/lsx-admin.js', array( 'jquery' ), LSX_VERSION, true );
41
	}
42
43
endif;
44
45
add_action( 'admin_enqueue_scripts', 'lsx_admin_scripts' );
46
47
if ( ! function_exists( 'lsx_scripts_add_styles' ) ) :
48
49
	/**
50
	 * Enqueue styles.
51
	 *
52
	 * @package    lsx
53
	 * @subpackage scripts
54
	 */
55
	function lsx_scripts_add_styles() {
56
		wp_register_style( 'fontawesome', get_template_directory_uri() . '/assets/css/vendor/font-awesome.css', array(), LSX_VERSION );
57
		wp_style_add_data( 'fontawesome', 'rtl', 'replace' );
58
59
		wp_register_style( 'bootstrap', get_template_directory_uri() . '/assets/css/vendor/bootstrap.css', array(), LSX_VERSION );
60
		wp_style_add_data( 'bootstrap', 'rtl', 'replace' );
61
62
		wp_enqueue_style( 'slick', get_template_directory_uri() . '/assets/css/vendor/slick.css', array(), LSX_VERSION, null );
63
		wp_enqueue_style( 'slick-lightbox', get_template_directory_uri() . '/assets/css/vendor/slick-lightbox.css', array( 'slick' ), LSX_VERSION, null );
64
65
		wp_enqueue_style( 'lsx_main_style', get_template_directory_uri() . '/style.css', array(), LSX_VERSION );
66
		wp_enqueue_style( 'lsx_main', get_template_directory_uri() . '/assets/css/lsx.css', array( 'lsx_main_style', 'fontawesome', 'bootstrap', 'slick', 'slick-lightbox' ), LSX_VERSION );
67
		wp_style_add_data( 'lsx_main', 'rtl', 'replace' );
68
	}
69
70
endif;
71
72
if ( ! function_exists( 'lsx_scripts_add_fonts' ) ) :
73
74
	/**
75
	 * Enqueue fonts.
76
	 *
77
	 * @package    lsx
78
	 * @subpackage scripts
79
	 */
80
	function lsx_scripts_add_fonts() {
81
82
		$disable_fonts = get_theme_mod( 'lsx_disable_fonts', false );
83
		if ( false !== $disable_fonts ) {
84
			return;
85
		}
86
87
		// Font styles.
88
		$font_styles = '
89
			@font-face {
90
				font-family: \'Lora\';
91
				font-style: normal;
92
				font-weight: 400;
93
				src: url( "' . get_stylesheet_directory_uri() . '/assets/fonts/lora/Lora-Regular.ttf" ) format("truetype");
94
			}
95
			@font-face {
96
				font-family: \'Lora\';
97
				font-style: italic;
98
				font-weight: 400i;
99
				src: url( "' . get_stylesheet_directory_uri() . '/assets/fonts/lora/Lora-Italic.ttf" ) format("truetype");
100
			}
101
			@font-face {
102
				font-family: \'Lora\';
103
				font-style: normal;
104
				font-weight: 700;
105
				src: url( "' . get_stylesheet_directory_uri() . '/assets/fonts/lora/Lora-Bold.ttf" ) format("truetype");
106
			}
107
			@font-face {
108
				font-family: \'Lora\';
109
				font-style: italic;
110
				font-weight: 700i;
111
				src: url( "' . get_stylesheet_directory_uri() . '/assets/fonts/lora/Lora-BoldItalic.ttf" ) format("truetype");
112
			}
113
			@font-face {
114
				font-family: \'Noto Sans\';
115
				font-style: normal;
116
				font-weight: 400;
117
				src: url( "' . get_stylesheet_directory_uri() . '/assets/fonts/noto_sans/NotoSans-Regular.ttf" ) format("truetype");
118
			}
119
			@font-face {
120
				font-family: \'Noto Sans\';
121
				font-style: italic;
122
				font-weight: 400i;
123
				src: url( "' . get_stylesheet_directory_uri() . '/assets/fonts/noto_sans/NotoSans-Italic.ttf" ) format("truetype");
124
			}
125
			@font-face {
126
				font-family: \'Noto Sans\';
127
				font-style: normal;
128
				font-weight: 700;
129
				src: url( "' . get_stylesheet_directory_uri() . '/assets/fonts/noto_sans/NotoSans-Bold.ttf" ) format("truetype");
130
			}
131
			@font-face {
132
				font-family: \'Noto Sans\';
133
				font-style: italic;
134
				font-weight: 700i;
135
				src: url( "' . get_stylesheet_directory_uri() . '/assets/fonts/noto_sans/NotoSans-BoldItalic.ttf" ) format("truetype");
136
			}
137
138
			body{font-family:\'Noto Sans\',sans-serif}
139
			h1,h2,h3,h4,h5,h6,.h1,.h2,.h3,.h4,.h5,.h6{font-family:\'Lora\',serif}
140
			.content-area blockquote:before,.widget-area blockquote:before{font-family:\'Lora\',serif}
141
			.wc-social-login:before{font-family:\'Lora\',serif}
142
			.blog article.post .entry-title .label-sticky,.blog article.page .entry-title .label-sticky,.blog article.lsx-slot .entry-title .label-sticky,.archive article.post .entry-title .label-sticky,.archive article.page .entry-title .label-sticky,.archive article.lsx-slot .entry-title .label-sticky,.search-results article.post .entry-title .label-sticky,.search-results article.page .entry-title .label-sticky,.search-results article.lsx-slot .entry-title .label-sticky{font-family:\'Noto Sans\',sans-serif}
143
			#respond .comment-reply-title>small{font-family:\'Noto Sans\',sans-serif}
144
			#comments .media-list .media .media-heading{font-family:\'Noto Sans\',sans-serif}
145
			.single-testimonial .entry-content:before{font-family:\'Lora\',serif}			
146
		';
147
148
		if ( ! empty( $font_styles ) ) {
149
			wp_add_inline_style( 'lsx_main', $font_styles );
150
		}
151
	}
152
153
endif;
154
155
if ( ! function_exists( 'lsx_scripts_add_scripts' ) ) :
156
157
	/**
158
	 * Enqueue scripts.
159
	 *
160
	 * @package    lsx
161
	 * @subpackage scripts
162
	 */
163
	function lsx_scripts_add_scripts() {
164
		if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
165
			wp_enqueue_script( 'comment-reply' );
166
		}
167
168
		wp_enqueue_script( 'platform', get_template_directory_uri() . '/assets/js/vendor/platform.min.js', array(), LSX_VERSION, true );
169
		wp_enqueue_script( 'bootstrap', get_template_directory_uri() . '/assets/js/vendor/bootstrap.min.js', array( 'jquery' ), LSX_VERSION, true );
170
171
		wp_enqueue_script( 'imagesLoaded', get_template_directory_uri() . '/assets/js/vendor/imagesloaded.pkgd.min.js', array( 'masonry' ), LSX_VERSION, true );
172
		wp_enqueue_script( 'scrolltofixed', get_template_directory_uri() . '/assets/js/vendor/jquery-scrolltofixed-min.js', array( 'jquery' ), LSX_VERSION, true );
173
		wp_enqueue_script( 'slick', get_template_directory_uri() . '/assets/js/vendor/slick.min.js', array( 'jquery' ), LSX_VERSION, true );
174
		wp_enqueue_script( 'slick-lightbox', get_template_directory_uri() . '/assets/js/vendor/slick-lightbox.min.js', array( 'jquery', 'slick' ), LSX_VERSION, true );
175
		wp_enqueue_script( 'picturefill', get_template_directory_uri() . '/assets/js/vendor/picturefill.min.js', array(), LSX_VERSION, true );
176
177
		wp_enqueue_script( 'lsx_script', get_template_directory_uri() . '/assets/js/lsx.min.js', array( 'jquery', 'platform', 'bootstrap', 'masonry', 'imagesLoaded', 'scrolltofixed', 'slick', 'slick-lightbox', 'picturefill' ), LSX_VERSION, true );
178
179
		$param_array = array(
180
			'columns' => apply_filters( 'lsx_archive_column_number', 3 ),
181
		);
182
183
		wp_localize_script( 'lsx_script', 'lsx_params', $param_array );
184
	}
185
186
endif;
187
188
if ( ! function_exists( 'lsx_scripts_child_theme' ) ) :
189
190
	/**
191
	 * Enqueue scripts and styles (for child theme).
192
	 *
193
	 * @package    lsx
194
	 * @subpackage scripts
195
	 */
196
	function lsx_scripts_child_theme() {
197
		if ( is_child_theme() && file_exists( get_stylesheet_directory() . '/assets/css/custom.css' ) ) {
198
			wp_enqueue_style( 'child-css', get_stylesheet_directory_uri() . '/assets/css/custom.css', array( 'lsx_main' ), LSX_VERSION );
199
			wp_style_add_data( 'child-css', 'rtl', 'replace' );
200
		}
201
	}
202
203
endif;
204
205
add_action( 'wp_enqueue_scripts', 'lsx_scripts_child_theme', 1999 );
206