Completed
Push — master ( 0fb8d7...6333ec )
by Fernando
03:59
created
inc/extras.php 1 patch
Spacing   +97 added lines, -97 removed lines patch added patch discarded remove patch
@@ -1,16 +1,16 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) return; // Exit if accessed directly
2
+if ( ! defined('ABSPATH')) return; // Exit if accessed directly
3 3
 
4 4
 /**
5 5
  * Enable extra attributes (srcset, sizes) in img tag
6 6
  */
7
-function lsx_kses_allowed_html( $allowedtags, $context ) {
7
+function lsx_kses_allowed_html($allowedtags, $context) {
8 8
 	$allowedtags['img']['srcset'] = true;
9 9
 	$allowedtags['img']['sizes'] = true;
10 10
 
11 11
 	return $allowedtags;
12 12
 }
13
-add_filter( 'wp_kses_allowed_html', 'lsx_kses_allowed_html', 10, 2 );
13
+add_filter('wp_kses_allowed_html', 'lsx_kses_allowed_html', 10, 2);
14 14
 
15 15
 /**
16 16
  * Add and remove body_class() classes
@@ -19,21 +19,21 @@  discard block
 block discarded – undo
19 19
 	/*
20 20
 	 * Add the header layout class
21 21
 	 */
22
-	$header_layout = get_theme_mod('lsx_header_layout','inline');
23
-	$classes[] = 'header-'.$header_layout;
22
+	$header_layout = get_theme_mod('lsx_header_layout', 'inline');
23
+	$classes[] = 'header-' . $header_layout;
24 24
 		
25 25
 	
26 26
   // Add post/page slug
27
-  if (is_single() || is_page() && !is_front_page()) {
27
+  if (is_single() || is_page() && ! is_front_page()) {
28 28
     $classes[] = basename(get_permalink());
29 29
   }
30 30
   
31
-  if(!class_exists('Lsx_Banners')){
32
-		$post_types = array('page','post');
33
-		$post_types = apply_filters('lsx_allowed_post_type_banners',$post_types);  
31
+  if ( ! class_exists('Lsx_Banners')) {
32
+		$post_types = array('page', 'post');
33
+		$post_types = apply_filters('lsx_allowed_post_type_banners', $post_types);  
34 34
 
35
-		if((is_singular($post_types) && has_post_thumbnail()) 
36
-		|| (is_singular('jetpack-portfolio'))){
35
+		if ((is_singular($post_types) && has_post_thumbnail()) 
36
+		|| (is_singular('jetpack-portfolio'))) {
37 37
 			$classes[] = 'page-has-banner';
38 38
 		}
39 39
 	}
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
   	$classes[] = 'has-top-menu';
43 43
   }
44 44
 
45
-	if ( get_theme_mod( 'lsx_preloader_content_status', '1' ) === '1' ) {
45
+	if (get_theme_mod('lsx_preloader_content_status', '1') === '1') {
46 46
 		$classes[] = 'preloader-content-enable';
47 47
 	}
48 48
 
@@ -66,30 +66,30 @@  discard block
 block discarded – undo
66 66
  * @param string $sep Optional separator.
67 67
  * @return string The filtered title.
68 68
  */
69
-function lsx_wp_title( $title, $sep ) {
69
+function lsx_wp_title($title, $sep) {
70 70
 	global $page, $paged;
71 71
 
72
-	if ( is_feed() ) {
72
+	if (is_feed()) {
73 73
 		return $title;
74 74
 	}
75 75
 
76 76
 	// Add the blog name
77
-	$title .= get_bloginfo( 'name' );
77
+	$title .= get_bloginfo('name');
78 78
 
79 79
 	// Add the blog description for the home/front page.
80
-	$site_description = get_bloginfo( 'description', 'display' );
81
-	if ( $site_description && ( is_home() || is_front_page() ) ) {
80
+	$site_description = get_bloginfo('description', 'display');
81
+	if ($site_description && (is_home() || is_front_page())) {
82 82
 		$title .= " $sep $site_description";
83 83
 	}
84 84
 
85 85
 	// Add a page number if necessary:
86
-	if ( $paged >= 2 || $page >= 2 ) {
87
-		$title .= " $sep " . sprintf( __( 'Page %s', 'lsx' ), max( $paged, $page ) );
86
+	if ($paged >= 2 || $page >= 2) {
87
+		$title .= " $sep " . sprintf(__('Page %s', 'lsx'), max($paged, $page));
88 88
 	}
89 89
 
90 90
 	return $title;
91 91
 }
92
-add_filter( 'wp_title', 'lsx_wp_title', 10, 2 );
92
+add_filter('wp_title', 'lsx_wp_title', 10, 2);
93 93
 
94 94
 
95 95
 /**
@@ -110,12 +110,12 @@  discard block
 block discarded – undo
110 110
 function lsx_remove_self_closing_tags($input) {
111 111
   return str_replace(' />', '>', $input);
112 112
 }
113
-add_filter('get_avatar',          'lsx_remove_self_closing_tags'); // <img />
114
-add_filter('comment_id_fields',   'lsx_remove_self_closing_tags'); // <input />
113
+add_filter('get_avatar', 'lsx_remove_self_closing_tags'); // <img />
114
+add_filter('comment_id_fields', 'lsx_remove_self_closing_tags'); // <input />
115 115
 add_filter('post_thumbnail_html', 'lsx_remove_self_closing_tags'); // <img />
116 116
 
117 117
 
118
-if (!function_exists('lsx_get_attachment_id')) {
118
+if ( ! function_exists('lsx_get_attachment_id')) {
119 119
 	/**
120 120
 	 * Get the Attachment ID for a given image URL.
121 121
 	 *
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
 	function lsx_get_attachment_id($url) {
127 127
 		$dir = wp_upload_dir();
128 128
 		// baseurl never has a trailing slash
129
-		if (false === strpos($url, $dir['baseurl'].'/')) {
129
+		if (false === strpos($url, $dir['baseurl'] . '/')) {
130 130
 			// URL points to a place outside of upload directory
131 131
 			return false;
132 132
 		}
@@ -144,11 +144,11 @@  discard block
 block discarded – undo
144 144
 		$query['meta_query'][0]['key'] = '_wp_attached_file';
145 145
 		// query attachments
146 146
 		$ids = get_posts($query);
147
-		if (!empty($ids)) {
147
+		if ( ! empty($ids)) {
148 148
 			foreach ($ids as $id) {
149 149
 				// first entry of returned array is the URL
150
-				$temp_url = wp_get_attachment_image_src( $id, 'full' );
151
-				if ( array_shift( $temp_url ) === $url ) {
150
+				$temp_url = wp_get_attachment_image_src($id, 'full');
151
+				if (array_shift($temp_url) === $url) {
152 152
 					return $id;
153 153
 				}
154 154
 			}
@@ -161,8 +161,8 @@  discard block
 block discarded – undo
161 161
 		}
162 162
 		foreach ($ids as $id) {
163 163
 			$meta = wp_get_attachment_metadata($id);
164
-			foreach ( $meta['sizes'] as $size => $values ) {
165
-				if ( $values['file'] === $file && array_shift( wp_get_attachment_image_src( $id, $size ) ) === $url ) {
164
+			foreach ($meta['sizes'] as $size => $values) {
165
+				if ($values['file'] === $file && array_shift(wp_get_attachment_image_src($id, $size)) === $url) {
166 166
 					return $id;
167 167
 				}
168 168
 			}
@@ -187,7 +187,7 @@  discard block
 block discarded – undo
187 187
  */
188 188
 function lsx_is_element_empty($element) {
189 189
 	$element = trim($element);
190
-	return empty($element)?false:true;
190
+	return empty($element) ? false : true;
191 191
 }
192 192
 
193 193
 
@@ -198,39 +198,39 @@  discard block
 block discarded – undo
198 198
  * @subpackage extras
199 199
  * @category thumbnails
200 200
  */
201
-function lsx_get_thumbnail($size,$image_src = false){
201
+function lsx_get_thumbnail($size, $image_src = false) {
202 202
 	
203
-	if(false === $image_src){
203
+	if (false === $image_src) {
204 204
 		$post_id = get_the_ID(); 
205
-		$post_thumbnail_id = get_post_thumbnail_id( $post_id );
206
-	}elseif(false != $image_src	){
207
-		if(is_numeric($image_src)){
205
+		$post_thumbnail_id = get_post_thumbnail_id($post_id);
206
+	}elseif (false != $image_src) {
207
+		if (is_numeric($image_src)) {
208 208
 			$post_thumbnail_id = $image_src;
209
-		}else{
209
+		} else {
210 210
 			$post_thumbnail_id = lsx_get_attachment_id_from_src($image_src);
211 211
 		}
212 212
 	}
213
-	$size = apply_filters('lsx_thumbnail_size',$size);
213
+	$size = apply_filters('lsx_thumbnail_size', $size);
214 214
 	$img = false;
215
-	if ( 'lsx-thumbnail-wide' === $size || 'thumbnail' === $size ) {
215
+	if ('lsx-thumbnail-wide' === $size || 'thumbnail' === $size) {
216 216
 		$srcset = false;
217
-		$img = wp_get_attachment_image_src($post_thumbnail_id,$size);
217
+		$img = wp_get_attachment_image_src($post_thumbnail_id, $size);
218 218
 		$img = $img[0];
219 219
 	} else {
220 220
 		$srcset = true;
221
-		$img = wp_get_attachment_image_srcset($post_thumbnail_id,$size);
222
-		if ( false == $img ) {
221
+		$img = wp_get_attachment_image_srcset($post_thumbnail_id, $size);
222
+		if (false == $img) {
223 223
 			$srcset = false;
224
-			$img = wp_get_attachment_image_src($post_thumbnail_id,$size);
224
+			$img = wp_get_attachment_image_src($post_thumbnail_id, $size);
225 225
 			$img = $img[0];
226 226
 		}
227 227
 	}
228
-	if ( $srcset ) {
229
-		$img = '<img alt="'.get_the_title(get_the_ID()).'" class="attachment-responsive wp-post-image lsx-responsive" srcset="'.$img.'" />';
228
+	if ($srcset) {
229
+		$img = '<img alt="' . get_the_title(get_the_ID()) . '" class="attachment-responsive wp-post-image lsx-responsive" srcset="' . $img . '" />';
230 230
 	} else {
231
-		$img = '<img alt="'.get_the_title(get_the_ID()).'" class="attachment-responsive wp-post-image lsx-responsive" src="'.$img.'" />';
231
+		$img = '<img alt="' . get_the_title(get_the_ID()) . '" class="attachment-responsive wp-post-image lsx-responsive" src="' . $img . '" />';
232 232
 	}
233
-	$img = apply_filters('lsx_lazyload_filter_images',$img);
233
+	$img = apply_filters('lsx_lazyload_filter_images', $img);
234 234
 	return $img;
235 235
 }
236 236
 
@@ -241,8 +241,8 @@  discard block
 block discarded – undo
241 241
  * @subpackage extras
242 242
  * @category thumbnails
243 243
  */
244
-function lsx_thumbnail( $size = 'thumbnail', $image_src = false ) {
245
-	echo wp_kses_post( lsx_get_thumbnail( $size, $image_src ) );
244
+function lsx_thumbnail($size = 'thumbnail', $image_src = false) {
245
+	echo wp_kses_post(lsx_get_thumbnail($size, $image_src));
246 246
 }
247 247
 
248 248
 
@@ -252,13 +252,13 @@  discard block
 block discarded – undo
252 252
  * @subpackage extras
253 253
  * @category thumbnails
254 254
  */
255
-function lsx_get_attachment_id_from_src( $image_src ) {
256
-	$post_id = wp_cache_get( $image_src, 'lsx_get_attachment_id_from_src' );
255
+function lsx_get_attachment_id_from_src($image_src) {
256
+	$post_id = wp_cache_get($image_src, 'lsx_get_attachment_id_from_src');
257 257
 	
258
-	if ( false === $post_id ) {
258
+	if (false === $post_id) {
259 259
 		global $wpdb;
260
-		$post_id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE guid='%s' LIMIT 1", $image_src ) );
261
-		wp_cache_set( $image_src, $post_id, 'lsx_get_attachment_id_from_src', 3600 );
260
+		$post_id = $wpdb->get_var($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE guid='%s' LIMIT 1", $image_src));
261
+		wp_cache_set($image_src, $post_id, 'lsx_get_attachment_id_from_src', 3600);
262 262
 	}
263 263
 
264 264
 	return $post_id;
@@ -272,28 +272,28 @@  discard block
 block discarded – undo
272 272
  * @subpackage extras
273 273
  * @category banner
274 274
  */
275
-if (!function_exists('lsx_page_banner')) {
275
+if ( ! function_exists('lsx_page_banner')) {
276 276
 	function lsx_page_banner() {
277 277
 
278
-		$post_types = array('page','post');
279
-		$post_types = apply_filters('lsx_allowed_post_type_banners',$post_types);	
278
+		$post_types = array('page', 'post');
279
+		$post_types = apply_filters('lsx_allowed_post_type_banners', $post_types);	
280 280
 		
281
-		if ( (is_singular($post_types) && has_post_thumbnail())
282
-		 || (is_singular('jetpack-portfolio')) ) { ?>
281
+		if ((is_singular($post_types) && has_post_thumbnail())
282
+		 || (is_singular('jetpack-portfolio'))) { ?>
283 283
 	        
284 284
 	        <?php 
285 285
 	        	$bg_image = '';
286
-	        	if(has_post_thumbnail()){
287
-	        		$bg_image = wp_get_attachment_image_src(get_post_thumbnail_id(get_the_ID()),'full');
286
+	        	if (has_post_thumbnail()) {
287
+	        		$bg_image = wp_get_attachment_image_src(get_post_thumbnail_id(get_the_ID()), 'full');
288 288
 	        		$bg_image = $bg_image[0];
289 289
 	        	}
290 290
 	        ?>
291 291
 
292
-	   		<?php if ( ! empty( $bg_image ) ) : ?>
292
+	   		<?php if ( ! empty($bg_image)) : ?>
293 293
 	        
294 294
 	        <div class="page-banner-wrap">
295 295
 		        <div class="page-banner">
296
-		        	<div class="page-banner-image" style="background-image:url(<?php echo esc_attr( $bg_image ); ?>);"></div>
296
+		        	<div class="page-banner-image" style="background-image:url(<?php echo esc_attr($bg_image); ?>);"></div>
297 297
 
298 298
 		        	<div class="container">
299 299
 			            <header class="page-header">
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
 	    <?php } 
310 310
 	}
311 311
 }
312
-add_action( 'lsx_header_after', 'lsx_page_banner' );
312
+add_action('lsx_header_after', 'lsx_page_banner');
313 313
 
314 314
 
315 315
 /**
@@ -319,43 +319,43 @@  discard block
 block discarded – undo
319 319
  * @subpackage extras
320 320
  * @category mobile
321 321
  */
322
-function lsx_allow_sms_protocol( $protocols ) {
322
+function lsx_allow_sms_protocol($protocols) {
323 323
     $protocols[] = 'sms';
324 324
     return $protocols;
325 325
 }
326
-add_filter( 'kses_allowed_protocols', 'lsx_allow_sms_protocol' );
326
+add_filter('kses_allowed_protocols', 'lsx_allow_sms_protocol');
327 327
 
328 328
 
329 329
 /**
330 330
  * Adding browser and user-agent classes to body
331 331
  */
332 332
 function mv_browser_body_class($classes) {
333
-		$http_user_agent = sanitize_text_field( wp_unslash( $_SERVER['HTTP_USER_AGENT'] ) );
334
-		$http_user_agent = ! empty( $http_user_agent ) ? $http_user_agent : '';
333
+		$http_user_agent = sanitize_text_field(wp_unslash($_SERVER['HTTP_USER_AGENT']));
334
+		$http_user_agent = ! empty($http_user_agent) ? $http_user_agent : '';
335 335
 
336 336
         global $is_lynx, $is_gecko, $is_ie, $is_opera, $is_ns4, $is_safari, $is_chrome, $is_iphone;
337
-        if($is_lynx) $classes[] = 'lynx';
338
-        elseif($is_gecko) $classes[] = 'gecko';
339
-        elseif($is_opera) $classes[] = 'opera';
340
-        elseif($is_ns4) $classes[] = 'ns4';
341
-        elseif($is_safari) $classes[] = 'safari';
342
-        elseif($is_chrome) $classes[] = 'chrome';
343
-        elseif($is_ie) {
337
+        if ($is_lynx) $classes[] = 'lynx';
338
+        elseif ($is_gecko) $classes[] = 'gecko';
339
+        elseif ($is_opera) $classes[] = 'opera';
340
+        elseif ($is_ns4) $classes[] = 'ns4';
341
+        elseif ($is_safari) $classes[] = 'safari';
342
+        elseif ($is_chrome) $classes[] = 'chrome';
343
+        elseif ($is_ie) {
344 344
                 $classes[] = 'ie';
345
-                if(preg_match('/MSIE ([0-9]+)([a-zA-Z0-9.]+)/', $http_user_agent, $browser_version))
346
-                $classes[] = 'ie'.$browser_version[1];
345
+                if (preg_match('/MSIE ([0-9]+)([a-zA-Z0-9.]+)/', $http_user_agent, $browser_version))
346
+                $classes[] = 'ie' . $browser_version[1];
347 347
         } else $classes[] = 'unknown';
348
-        if($is_iphone) $classes[] = 'iphone';
349
-        if ( stristr( $http_user_agent, "mac") ) {
348
+        if ($is_iphone) $classes[] = 'iphone';
349
+        if (stristr($http_user_agent, "mac")) {
350 350
                  $classes[] = 'osx';
351
-           } elseif ( stristr( $http_user_agent, "linux") ) {
351
+           } elseif (stristr($http_user_agent, "linux")) {
352 352
                  $classes[] = 'linux';
353
-           } elseif ( stristr( $http_user_agent, "windows") ) {
353
+           } elseif (stristr($http_user_agent, "windows")) {
354 354
                  $classes[] = 'windows';
355 355
            }
356 356
         return $classes;
357 357
 }
358
-add_filter('body_class','mv_browser_body_class');
358
+add_filter('body_class', 'mv_browser_body_class');
359 359
 
360 360
 
361 361
 /**
@@ -368,7 +368,7 @@  discard block
 block discarded – undo
368 368
  * @param		$form		Object
369 369
  * @return		String
370 370
  */
371
-function lsx_form_submit_button($button, $form){
371
+function lsx_form_submit_button($button, $form) {
372 372
 	return "<button class='btn btn-primary' id='gform_submit_button_{$form["id"]}'><span>Submit</span></button>";
373 373
 }
374 374
 add_filter("gform_submit_button", "lsx_form_submit_button", 10, 2);
@@ -382,7 +382,7 @@  discard block
 block discarded – undo
382 382
 	//return ' ... <a class="moretag" href="'. get_permalink($post->ID) . '">'.__('Continue reading','lsx').'</a>';
383 383
 	return '...';
384 384
 }
385
-add_filter( 'excerpt_more', 'lsx_excerpt_more' );
385
+add_filter('excerpt_more', 'lsx_excerpt_more');
386 386
 
387 387
 
388 388
 /**
@@ -391,44 +391,44 @@  discard block
 block discarded – undo
391 391
 function lsx_the_excerpt_filter($excerpt) {
392 392
 	$show_full_content = has_post_format(apply_filters('lsx_the_excerpt_filter_post_types', array('aside', 'gallery', 'link', 'image', 'quote', 'status', 'video', 'audio')));
393 393
 	
394
-	if (!$show_full_content) {
395
-		if ('' !== $excerpt  && !stristr($excerpt, 'moretag')) {
396
-			$pagination = wp_link_pages( array(
394
+	if ( ! $show_full_content) {
395
+		if ('' !== $excerpt && ! stristr($excerpt, 'moretag')) {
396
+			$pagination = wp_link_pages(array(
397 397
 							'before' => '<div class="lsx-postnav-wrapper"><div class="lsx-postnav">',
398 398
 							'after' => '</div></div>',
399 399
 							'link_before' => '<span>',
400 400
 							'link_after' => '</span>',
401 401
 							'echo' => 0
402
-						) );
402
+						));
403 403
 
404
-			if ( ! empty( $pagination ) ) {
404
+			if ( ! empty($pagination)) {
405 405
 				$excerpt .= $pagination;
406 406
 			}
407 407
 			else {
408
-				$excerpt .= '<p><a class="moretag" href="'.get_permalink().'">'.__('Continue reading','lsx').'</a></p>';
408
+				$excerpt .= '<p><a class="moretag" href="' . get_permalink() . '">' . __('Continue reading', 'lsx') . '</a></p>';
409 409
 			}
410 410
 		}
411 411
 	}
412 412
 
413 413
 	return $excerpt;
414 414
 }
415
-add_filter( 'the_excerpt', 'lsx_the_excerpt_filter' , 1 , 20 );
415
+add_filter('the_excerpt', 'lsx_the_excerpt_filter', 1, 20);
416 416
 
417 417
 
418 418
 /**
419 419
  * Allow HTML tags in excerpt
420 420
  */
421
-if ( ! function_exists( 'wpse_custom_wp_trim_excerpt' ) ) {
421
+if ( ! function_exists('wpse_custom_wp_trim_excerpt')) {
422 422
 	function wpse_custom_wp_trim_excerpt($wpse_excerpt) {
423 423
 		global $post;
424 424
 		$raw_excerpt = $wpse_excerpt;
425 425
 
426
-		if ( '' == $wpse_excerpt ) {
426
+		if ('' == $wpse_excerpt) {
427 427
 			$wpse_excerpt = get_the_content('');
428 428
 			$show_full_content = has_post_format(array('aside', 'gallery', 'link', 'image', 'quote', 'status', 'video', 'audio'));
429 429
 
430
-			if (!$show_full_content) {
431
-				$wpse_excerpt = strip_shortcodes( $wpse_excerpt );
430
+			if ( ! $show_full_content) {
431
+				$wpse_excerpt = strip_shortcodes($wpse_excerpt);
432 432
 				$wpse_excerpt = apply_filters('the_content', $wpse_excerpt);
433 433
 				$wpse_excerpt = str_replace(']]>', ']]>', $wpse_excerpt);
434 434
 				$wpse_excerpt = strip_tags($wpse_excerpt, '<blockquote>,<p>,<br>,<b>,<strong>,<i>,<u>,<ul>,<li>,<span>,<div>');
@@ -456,12 +456,12 @@  discard block
 block discarded – undo
456 456
 				$wpse_excerpt = trim(force_balance_tags($excerpt_output));
457 457
 
458 458
 				if ($has_more) {
459
-					$excerpt_end = '<a class="moretag" href="'.get_permalink().'">'.__('More','lsx').'</a>';
459
+					$excerpt_end = '<a class="moretag" href="' . get_permalink() . '">' . __('More', 'lsx') . '</a>';
460 460
 					$excerpt_end = apply_filters('excerpt_more', ' ' . $excerpt_end); 
461 461
 
462 462
 					$pos = strrpos($wpse_excerpt, '</');
463 463
 
464
-					if ( false !== $pos ) {
464
+					if (false !== $pos) {
465 465
 						// Inside last HTML tag
466 466
 						$wpse_excerpt = substr_replace($wpse_excerpt, $excerpt_end, $pos, 0); /* Add read more next to last word */
467 467
 					} else {
@@ -484,4 +484,4 @@  discard block
 block discarded – undo
484 484
 }
485 485
 remove_filter('get_the_excerpt', 'wp_trim_excerpt');
486 486
 add_filter('get_the_excerpt', 'wpse_custom_wp_trim_excerpt');
487
-remove_filter( 'the_excerpt', 'wpautop' );
487
+remove_filter('the_excerpt', 'wpautop');
Please login to merge, or discard this patch.