lsx_setup()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 255
Code Lines 155

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 155
nc 1
nop 0
dl 0
loc 255
rs 8
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 - Config.
4
 *
5
 * @package    lsx
6
 * @subpackage config
7
 */
8
9
if ( ! defined( 'ABSPATH' ) ) {
10
	exit;
11
}
12
13
if ( ! function_exists( 'lsx_setup' ) ) :
14
15
	/**
16
	 * Theme after_setup_theme action.
17
	 *
18
	 * @package    lsx
19
	 * @subpackage config
20
	 */
21
	function lsx_setup() {
22
		global $content_width;
23
		$content_width = 1140;
24
25
		remove_theme_support( 'widgets-block-editor' );
26
27
		load_theme_textdomain( 'lsx', get_template_directory() . '/languages' );
28
29
		add_image_size( 'lsx-thumbnail-carousel', 350, 230, true );
30
		add_image_size( 'lsx-thumbnail-wide', 360, 168, true );
31
		add_image_size( 'lsx-thumbnail-square', 350, 350, true );
32
		add_image_size( 'lsx-thumbnail-single', 750, 350, true );
33
		add_image_size( 'lsx-banner', 1920, 600, true );
34
35
		register_nav_menus(
36
			array(
37
				'primary'       => esc_html__( 'Primary Menu', 'lsx' ),
38
				'top-menu'      => esc_html__( 'Top Menu (right)', 'lsx' ),
39
				'top-menu-left' => esc_html__( 'Top Menu (left)', 'lsx' ),
40
				'social'        => esc_html__( 'Social Menu', 'lsx' ),
41
				'footer'        => esc_html__( 'Footer Menu', 'lsx' ),
42
			)
43
		);
44
45
		add_theme_support( 'automatic-feed-links' );
46
		add_theme_support( 'custom-background' );
47
48
		add_theme_support(
49
			'custom-logo',
50
			array(
51
				'height'      => 50,
52
				'width'       => 160,
53
				'flex-width'  => true,
54
				'flex-height' => true,
55
			)
56
		);
57
58
		add_theme_support( 'html5', array( 'caption' ) );
59
60
		add_theme_support(
61
			'post-formats',
62
			array(
63
				'image',
64
				'video',
65
				'gallery',
66
				'audio',
67
				'quote',
68
			)
69
		);
70
71
		add_theme_support( 'post-thumbnails' );
72
		add_theme_support( 'sensei' );
73
74
		add_theme_support(
75
			'site-logo',
76
			array(
77
				'header-text' => array(
78
					'site-title',
79
					'site-description',
80
				),
81
				'size'        => 'medium',
82
			)
83
		);
84
85
		add_theme_support( 'title-tag' );
86
87
		/*
88
		 * @TODO - Necessary to test it
89
		 */
90
91
		// add_theme_support( 'woocommerce' );.
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% 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...
92
		add_theme_support( 'starter-content', array(
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
Coding Style introduced by
For multi-line function calls, each argument should be on a separate line.

For a function calls that spawns multiple lines, the coding style suggests to split arguments to separate lines like this:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
);
Loading history...
93
			'widgets'     => array(
94
				'sidebar-home'       => array(
95
					'custom_widget_1' => array(
96
						'text',
97
98
						array(
99
							'title' => '',
100
							'text'  => wp_kses_post( '<div class="row"><div class="col-sm-12 text-center"><h3>Build your perfect website <small>with the LSX theme</small></h3></div></div><div class="row"><div class="col-sm-4 text-center"><h4>Fast</h4><p>"Quick" isn\'t a word most people use when describing their website building experience.</p></div><div class="col-sm-4 text-center"><h4>Easy</h4><p>We\'ve built websites for countless clients, and we know what kind of back-end makes sense easily.</p></div><div class="col-sm-4 text-center"><h4>Comprehensive</h4><p>The LSX extensions come with features out the box that are essential.</p></div></div>' ),
101
						),
102
					),
103
104
					'custom_widget_2' => array(
105
						'text',
106
107
						array(
108
							'title' => '',
109
							'text'  => wp_kses_post( '<div class="lsx-full-width-alt"><div class="row"><div class="col-xs-12"><h3>A big CTA title</h3><p class="text-center"><a class="btn cta-btn" href="http://www.lsdeb.biz/" target="_blank" rel="noreferrer noopener">Hire Us</a><p></div></div></div>' ),
110
						),
111
					),
112
113
					'custom_widget_3' => array(
114
						'text',
115
116
						array(
117
							'title' => '',
118
							'text'  => wp_kses_post( '<div class="row"><div class="col-xs-12"><h3>Homepage Widget</h3><p>Lorem ipsum dolor sit amet, <a href="#">consectetuer adipiscing elit</a>. Donec odio. Quisque volutpat mattis eros. Nullam malesuada erat ut turpis. Suspendisse urna nibh, viverra non, semper suscipit, posuere a, pede.</p></div></div>' ),
119
						),
120
					),
121
				),
122
123
				'sidebar-footer'     => array(
124
					'custom_widget_1' => array(
125
						'text',
126
127
						array(
128
							'title' => esc_html__( 'Space for Footer Widgets', 'lsx' ),
129
							'text'  => esc_html__( 'This is here to showcase some footer widgets. You can decide what to add and what to hide. Nam nostrum evertitur ad, ut pri nibh veniam, urbanitas definitionem eum ex.', 'lsx' ),
130
						),
131
					),
132
133
					'custom_widget_2' => array(
134
						'text',
135
136
						array(
137
							'title' => esc_html__( 'Space for Footer Widgets', 'lsx' ),
138
							'text'  => esc_html__( 'This is here to showcase some footer widgets. You can decide what to add and what to hide. Nam nostrum evertitur ad, ut pri nibh veniam, urbanitas definitionem eum ex.', 'lsx' ),
139
						),
140
					),
141
142
					'custom_widget_3' => array(
143
						'text',
144
145
						array(
146
							'title' => esc_html__( 'Contact us:', 'lsx' ),
147
							'text'  => wp_kses_post( '<a href="mailto:[email protected]><i class="fa fa-envelope fa-fw"></i> [email protected]</a><br><a href="tel:+27214489843"><i class="fa fa-phone fa-fw"></i> +27 21 448 9843</a><br><i class="fa fa-skype fa-fw"></i> /lightspeeddevelopment' ),
148
						),
149
					),
150
				),
151
152
				'sidebar-footer-cta' => array(
153
					'custom_widget_1' => array(
154
						'text',
155
156
						array(
157
							'title' => esc_html__( 'A Footer Call to Action', 'lsx' ),
158
							'text'  => esc_html__( 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec odio. Quisque volutpat mattis eros. Nullam malesuada erat ut turpis. Suspendisse urna nibh, viverra non, semper suscipit, posuere a, pede.', 'lsx' ),
159
						),
160
					),
161
				),
162
			),
163
164
			'posts'       => array(
165
				'home'    => array(
166
					'template'     => 'page-templates/template-front-page.php',
167
					'thumbnail'    => '{{image-banner-example-01}}',
168
					'post_title'   => esc_html__( 'LSX is a free WordPress theme', 'lsx' ),
169
					'post_content' => '',
170
				),
171
172
				'about'   => array(
173
					'thumbnail' => '{{image-banner-example-02}}',
174
				),
175
176
				'blog',
177
178
				'contact' => array(
179
					'thumbnail' => '{{image-banner-example-03}}',
180
				),
181
			),
182
183
			'attachments' => array(
184
				'image-banner-example-01' => array(
185
					'post_title' => esc_html_x( 'Banner Example 01', 'Theme starter content', 'lsx' ),
186
					'file'       => 'assets/images/admin/banner-example-01.jpg',
187
				),
188
189
				'image-banner-example-02' => array(
190
					'post_title' => esc_html_x( 'Banner Example 02', 'Theme starter content', 'lsx' ),
191
					'file'       => 'assets/images/admin/banner-example-02.jpg',
192
				),
193
194
				'image-banner-example-03' => array(
195
					'post_title' => esc_html_x( 'Banner Example 03', 'Theme starter content', 'lsx' ),
196
					'file'       => 'assets/images/admin/banner-example-03.jpg',
197
				),
198
			),
199
200
			'options'     => array(
201
				'show_on_front'   => 'page',
202
				'page_on_front'   => '{{home}}',
203
				'page_for_posts'  => '{{blog}}',
204
				'blogdescription' => esc_html__( 'LSX starter content example', 'lsx' ),
205
			),
206
207
			'nav_menus'   => array(
208
				'primary'  => array(
209
					'name'  => esc_html__( 'Primary Menu', 'lsx' ),
210
211
					'items' => array(
212
						'page_home',
213
						'page_about',
214
						'page_blog',
215
						'page_contact',
216
					),
217
				),
218
219
				'top-menu' => array(
220
					'name'  => esc_html__( 'Top Menu', 'lsx' ),
221
222
					'items' => array(
223
						'custom_link_1' => array(
224
							'title'   => 'View Map',
225
							'url'     => 'https://www.google.com/maps/place/LightSpeed+WordPress+Development/@-33.92945,18.45345,17z/data=!3m1!4b1!4m2!3m1!1s0x1dcc5da1b2446d25:0xc8ecdb1cc8afd170',
226
							'classes' => 'map',
227
						),
228
229
						'custom_link_2' => array(
230
							'title'   => '+27 21 448 9843',
231
							'url'     => 'tel:+27214489843',
232
							'classes' => 'tel',
233
						),
234
235
						'custom_link_3' => array(
236
							'title'   => '[email protected]',
237
							'url'     => 'mailto:[email protected]',
238
							'classes' => 'email',
239
						),
240
241
						'page_contact'  => array(
242
							'classes' => 'cta',
243
						),
244
					),
245
				),
246
247
				'social'   => array(
248
					'name'  => esc_html__( 'Social Menu', 'lsx' ),
249
250
					'items' => array(
251
						'link_facebook',
252
						'link_foursquare',
253
						'link_github',
254
						'link_instagram',
255
						'link_linkedin',
256
						'link_pinterest',
257
						'link_twitter',
258
						'link_youtube',
259
					),
260
				),
261
262
				'footer'   => array(
263
					'name'  => esc_html__( 'Footer Menu', 'lsx' ),
264
265
					'items' => array(
266
						'page_about',
267
						'page_contact',
268
					),
269
				),
270
			),
271
272
			'theme_mods'  => array(
273
				'lsx_header_fixed'  => true,
274
				'lsx_header_search' => false,
275
				'lsx_layout'        => '1c',
276
			),
277
		) );
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
278
	}
279
280
endif;
281
282
add_action( 'after_setup_theme', 'lsx_setup' );
283
284
if ( ! function_exists( 'lsx_init' ) ) :
285
286
	/**
287
	 * Theme init action.
288
	 *
289
	 * @package    lsx
290
	 * @subpackage config
291
	 */
292
	function lsx_init() {
293
		add_post_type_support( 'page', 'excerpt' );
294
295
		if ( class_exists( 'WooCommerce' ) ) {
296
			remove_action( 'woocommerce_before_main_content', 'woocommerce_breadcrumb', 20 );
297
		}
298
299
		remove_action( 'comment_form', 'wp_comment_form_unfiltered_html_nonce', 10 );
300
	}
301
302
endif;
303
304
add_action( 'init', 'lsx_init', 100 );
305
306
if ( ! function_exists( 'lsx_process_content_width' ) ) :
307
308
	/**
309
	 * Overwrite the $content_width var, based on the layout of the page.
310
	 *
311
	 * @package    lsx
312
	 * @subpackage config
313
	 */
314
	function lsx_process_content_width() {
315
		global $content_width;
316
317
		if ( is_page_template( 'page-templates/template-front-page.php' ) ) {
318
			$content_width = 1140;
319
		}
320
	}
321
322
endif;
323
324
add_action( 'wp_head', 'lsx_process_content_width' );
325
326
if ( ! function_exists( 'lsx_file_get_contents' ) ) :
327
328
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$file" missing
Loading history...
329
	 * Get file contents.
330
	 *
331
	 * @package    lsx
332
	 * @subpackage config
333
	 */
334
	function lsx_file_get_contents( $file ) {
335
		if ( file_exists( $file ) ) {
336
			global $wp_filesystem;
337
338
			if ( empty( $wp_filesystem ) ) {
339
				require_once ABSPATH . 'wp-admin/includes/file.php';
340
				WP_Filesystem();
341
			}
342
343
			if ( $wp_filesystem ) {
344
				$contents = $wp_filesystem->get_contents( $file );
345
346
				if ( ! empty( $contents ) ) {
347
					return $contents;
348
				}
349
			}
350
		}
351
352
		return '';
353
	}
354
355
endif;
356