Completed
Push — master ( bf1080...d99bb1 )
by Md. Mozahidur
04:04
created

functions.php (6 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 18 and the first side effect is on line 110.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * Lighthouse functions and definitions.
4
 *
5
 * @link https://developer.wordpress.org/themes/basics/theme-functions/
6
 *
7
 * @package Lighthouse
8
 */
9
10
if ( ! function_exists( 'lighthouse_setup' ) ) :
11
/**
12
 * Sets up theme defaults and registers support for various WordPress features.
13
 *
14
 * Note that this function is hooked into the after_setup_theme hook, which
15
 * runs before the init hook. The init hook is too late for some features, such
16
 * as indicating support for post thumbnails.
17
 */
18
function lighthouse_setup() {
19
	/*
20
	 * Make theme available for translation.
21
	 * Translations can be filed in the /languages/ directory.
22
	 * If you're building a theme based on Lighthouse, use a find and replace
23
	 * to change 'lighthouse' to the name of your theme in all the template files.
24
	 */
25
	load_theme_textdomain( 'lighthouse', get_template_directory() . '/languages' );
26
27
	// Add default posts and comments RSS feed links to head.
28
	add_theme_support( 'automatic-feed-links' );
29
30
	/*
31
	 * Let WordPress manage the document title.
32
	 * By adding theme support, we declare that this theme does not use a
33
	 * hard-coded <title> tag in the document head, and expect WordPress to
34
	 * provide it for us.
35
	 */
36
	add_theme_support( 'title-tag' );
37
38
	/*
39
	 * Enable support for Post Thumbnails on posts and pages.
40
	 *
41
	 * @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
42
	 */
43
	add_theme_support( 'post-thumbnails' );
44
45
	add_image_size( 'lighthouse_feature_img', 1000, 310, array( 'center', 'center' ) );
46
47
	add_image_size( 'lighthouse_blog_listing', 714, 274, array( 'center', 'center' ) );
48
49
	add_image_size( 'lighthouse_related_post', 475, 280, array( 'center', 'center' ) );
50
51
	/*
52
	 * Default HTML5 Form
53
	 *
54
	 * @link https://codex.wordpress.org/Function_Reference/get_search_form
55
	 */
56
	add_theme_support( 'html5', array( 'search-form' ) ); 
57
58
	// This theme uses wp_nav_menu() in one location.
59
	register_nav_menus( array(
60
		'primary' => esc_html__( 'Primary', 'lighthouse' ),
61
	) );
62
63
64
	/*
65
	 * Lighthouse custom header menus
66
	 *
67
	 */
68
	function lighthouse_menus() {
69
		register_nav_menus(
70
			array(
71
				'header-menu-left' => __( 'Header menu left', 'nav menu location', 'lighthouse' ),
72
				'header-menu-right' => __( 'Header menu right' , 'nav menu location', 'lighthouse'),
73
				'footer-menu' => __( 'Footer menu' , 'nav menu location', 'lighthouse'),
74
				'footer-menu-bottom' => __( 'Footer menu bottom' , 'nav menu location', 'lighthouse')
75
				)
76
			);
77
	}
78
	add_action( 'init', 'lighthouse_menus' );
79
80
	/*
81
	 * Switch default core markup for search form, comment form, and comments
82
	 * to output valid HTML5.
83
	 */
84
	add_theme_support( 'html5', array(
85
		'search-form',
86
		'comment-form',
87
		'comment-list',
88
		'gallery',
89
		'caption',
90
	) );
91
92
	/*
93
	 * Enable support for Post Formats.
94
	 * See https://developer.wordpress.org/themes/functionality/post-formats/
95
	 */
96
	add_theme_support( 'post-formats', array(
97
		'aside',
98
		'image',
99
		'video',
100
		'quote',
101
		'link',
102
	) );
103
104
	// Set up the WordPress core custom background feature.
105
	add_theme_support( 'custom-background', apply_filters( 'lighthouse_custom_background_args', array(
106
		'default-color' => 'ffffff',
107
		'default-image' => '',
108
	) ) );
109
}
110
endif;
111
add_action( 'after_setup_theme', 'lighthouse_setup' );
112
113
/**
114
 * Set the content width in pixels, based on the theme's design and stylesheet.
115
 *
116
 * Priority 0 to make it available to lower priority callbacks.
117
 *
118
 * @global int $content_width
119
 */
120
function lighthouse_content_width() {
121
	$GLOBALS['content_width'] = apply_filters( 'lighthouse_content_width', 640 );
122
}
123
add_action( 'after_setup_theme', 'lighthouse_content_width', 0 );
124
125
/**
126
 * Register widget area.
127
 *
128
 * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
129
 */
130 View Code Duplication
function lighthouse_widgets_init() {
0 ignored issues
show
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
131
	register_sidebar( array(
132
		'name'          => esc_html__( 'Sidebar', 'lighthouse' ),
133
		'id'            => 'sidebar-1',
134
		'description'   => '',
135
		'before_widget' => '<section id="%1$s" class="widget %2$s">',
136
		'after_widget'  => '</section>',
137
		'before_title'  => '<h2 class="widget-title">',
138
		'after_title'   => '</h2>',
139
	) );
140
}
141
add_action( 'widgets_init', 'lighthouse_widgets_init' );
142
143
/**
144
 * Enqueue scripts and styles.
145
 */
146
function lighthouse_scripts() {
147
148
	wp_enqueue_style( 'lighthouse-font-awesome-css', get_template_directory_uri() . '/css/font-awesome.min.css');
149
150
	wp_enqueue_style( 'lighthouse-style', get_stylesheet_uri() );
151
152
	wp_enqueue_style('lighthouse-google-fonts', 'https://fonts.googleapis.com/css?family=Questrial');
153
154
	//wp_enqueue_style('lighthouse-owl-carousel-css', get_template_directory_uri() . '/css/owl.carousel.css');
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% 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...
155
156
	wp_enqueue_script( 'lighthouse-classList-js', 'https://cdnjs.cloudflare.com/ajax/libs/classlist/2014.01.31/classList.min.js', array('jquery'), '');
157
158
	wp_enqueue_script( 'lighthouse-bootstrap-js', get_template_directory_uri() . '/js/bootstrap.min.js', array('jquery'), '', true );
159
160
	wp_enqueue_script( 'lighthouse-material-menu-js', get_template_directory_uri() . '/js/materialMenu.js', array('jquery'), '', true );
161
162
	wp_enqueue_script( 'lighthouse-owl-carousel-js', get_template_directory_uri() . '/js/owl-carousel.js', array('jquery'), '', true );
163
164
	wp_enqueue_script( 'lighthouse-match-height-js', get_template_directory_uri() . '/js/jquery.matchHeight-min.js', array('jquery'), '', true );
165
166
	wp_enqueue_script( 'lighthouse-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '20120206', true );
167
168
	wp_enqueue_script( 'lighthouse-settings-js', get_template_directory_uri() . '/js/lighthouse-settings.js', array('jquery'), '', true );
169
170
	wp_enqueue_script( 'lighthouse-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20130115', true );
171
172
	if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
173
		wp_enqueue_script( 'comment-reply' );
174
	}
175
}
176
add_action( 'wp_enqueue_scripts', 'lighthouse_scripts' );
177
178
179
/**
180
 * Read More button in excerpt
181
 */
182
function new_excerpt_more( $more ) {
183
    return '... <a class="readmore" href="' . get_permalink() . ' ">Read more <i class="fa fa-external-link"></i></a>';
184
}
185
add_filter( 'excerpt_more', 'new_excerpt_more' );
186
187
/**
188
 * Custome Lenght of excerpt
189
 */
190
// function custom_excerpt_length( $length ) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
49% 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...
191
//     return 50;
192
// }
193
// add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );
194
195
196
//callback function for the 'clear_content' shortcode
197
function recent_post_slider($atts){
198
199
	echo'<div class="post-slider row"><div id="recent-posts" class="owl-carousel">';
200
201
	global $post;
202
203
	$post_query = new WP_Query( array(
204
		'post_type' => 'post',
205
		'posts_per_page' => 12,
206
		'order'=>'DESC',
207
		'orderby' => 'date',
208
		)
209
	);
210
211
	if( $post_query->have_posts() ) : while( $post_query->have_posts() ) : $post_query->the_post();
212
213
		$thumb_post = wp_get_attachment_image_src( get_post_thumbnail_id(), 'lighthouse_related_post');
214
		$url_post = $thumb_post[0];
215
		$content = get_the_content();
216
217
		echo '<div class="col-xs-12"><div class="thumbnail thumbnail-hover">';
218
219
		echo'<img class="img-responsive" src=" ' . $url_post . '">';
220
221
		echo '<a href=" ' . get_permalink() .' " " title=" ' .  get_the_title() .' " class="overlay"></a>';
222
223
		echo'</div>';
224
		
225
		echo'<div class="entry">';
226
227
		echo '<h3><a href=" ' . get_permalink() . ' "> ' . get_the_title() . '</a></h3>';
228
229
		echo '<span class="date"> <i class="fa fa-clock-o"></i> ' . get_the_time(get_option('date_format')) .'</span>';
230
		
231
		echo '<div class="entry-content">' . wp_trim_words( $content , '27' ) . '</div>';
232
233
		echo '<div class="read-more">';
234
235
		echo '<a href="' . get_permalink() . ' " class="btn read-more-btn">View Article</a>';
236
237
		echo '</div>';
238
239
		echo '</div></div>';
240
241
		endwhile;
242
	    wp_reset_postdata();
243
	endif;
244
		
245
		echo '</div></div>';
246
247
}
248
//add the new 'recent_posts' shortcode
249
add_shortcode('recent_posts','recent_post_slider');
250
251
// Numbered Pagination
252
function pagination($pages = '', $range = 4)
253
{  
254
     $showitems = ($range * 2)+1;  
255
 
256
     global $paged;
257
     if(empty($paged)) $paged = 1;
258
 
259
     if($pages == '')
260
     {
261
         global $wp_query;
262
         $pages = $wp_query->max_num_pages;
263
         if(!$pages)
264
         {
265
             $pages = 1;
266
         }
267
     }   
268
 
269
     if(1 != $pages)
270
     {
271
         echo "<div class=\"pagination\"><span>Page ".$paged." of ".$pages."</span>";
272
         if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href='".get_pagenum_link(1)."'>&laquo; First</a>";
273 View Code Duplication
         if($paged > 1 && $showitems < $pages) echo "<a href='".get_pagenum_link($paged - 1)."'>&lsaquo; Previous</a>";
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
274
 
275
         for ($i=1; $i <= $pages; $i++)
276
         {
277
             if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
278
             {
279
                 echo ($paged == $i)? "<span class=\"current\">".$i."</span>":"<a href='".get_pagenum_link($i)."' class=\"inactive\">".$i."</a>";
280
             }
281
         }
282
 
283 View Code Duplication
         if ($paged < $pages && $showitems < $pages) echo "<a href=\"".get_pagenum_link($paged + 1)."\">Next &rsaquo;</a>";  
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
284
         if ($paged < $pages-1 &&  $paged+$range-1 < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($pages)."'>Last &raquo;</a>";
285
         echo "</div>\n";
286
     }
287
}
288
289
/**
290
 * Implement the Custom Header feature.
291
 */
292
require get_template_directory() . '/inc/custom-header.php';
293
294
/**
295
 * Custom template tags for this theme.
296
 */
297
require get_template_directory() . '/inc/template-tags.php';
298
299
/**
300
 * Custom functions that act independently of the theme templates.
301
 */
302
require get_template_directory() . '/inc/extras.php';
303
304
/**
305
 * Customizer additions.
306
 */
307
require get_template_directory() . '/inc/customizer.php';
308
309
/**
310
 * Load Jetpack compatibility file.
311
 */
312
require get_template_directory() . '/inc/jetpack.php';
313