Completed
Push — master ( 4045d8...acfc89 )
by Md. Mozahidur
02:07
created

functions.php (5 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 106.

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_blog_listing', 714, 274, array( 'center', 'center' ) );
46
47
	/*
48
	 * Default HTML5 Form
49
	 *
50
	 * @link https://codex.wordpress.org/Function_Reference/get_search_form
51
	 */
52
	add_theme_support( 'html5', array( 'search-form' ) ); 
53
54
	// This theme uses wp_nav_menu() in one location.
55
	register_nav_menus( array(
56
		'primary' => esc_html__( 'Primary', 'lighthouse' ),
57
	) );
58
59
60
	/*
61
	 * Lighthouse custom header menus
62
	 *
63
	 */
64
	function lighthouse_menus() {
65
		register_nav_menus(
66
			array(
67
				'header-menu-left' => __( 'Header menu left', 'nav menu location', 'lighthouse' ),
68
				'header-menu-right' => __( 'Header menu right' , 'nav menu location', 'lighthouse'),
69
				'footer-menu' => __( 'Footer menu' , 'nav menu location', 'lighthouse'),
70
				'footer-menu-bottom' => __( 'Footer menu bottom' , 'nav menu location', 'lighthouse')
71
				)
72
			);
73
	}
74
	add_action( 'init', 'lighthouse_menus' );
75
76
	/*
77
	 * Switch default core markup for search form, comment form, and comments
78
	 * to output valid HTML5.
79
	 */
80
	add_theme_support( 'html5', array(
81
		'search-form',
82
		'comment-form',
83
		'comment-list',
84
		'gallery',
85
		'caption',
86
	) );
87
88
	/*
89
	 * Enable support for Post Formats.
90
	 * See https://developer.wordpress.org/themes/functionality/post-formats/
91
	 */
92
	add_theme_support( 'post-formats', array(
93
		'aside',
94
		'image',
95
		'video',
96
		'quote',
97
		'link',
98
	) );
99
100
	// Set up the WordPress core custom background feature.
101
	add_theme_support( 'custom-background', apply_filters( 'lighthouse_custom_background_args', array(
102
		'default-color' => 'ffffff',
103
		'default-image' => '',
104
	) ) );
105
}
106
endif;
107
add_action( 'after_setup_theme', 'lighthouse_setup' );
108
109
/**
110
 * Set the content width in pixels, based on the theme's design and stylesheet.
111
 *
112
 * Priority 0 to make it available to lower priority callbacks.
113
 *
114
 * @global int $content_width
115
 */
116
function lighthouse_content_width() {
0 ignored issues
show
lighthouse_content_width uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
117
	$GLOBALS['content_width'] = apply_filters( 'lighthouse_content_width', 640 );
118
}
119
add_action( 'after_setup_theme', 'lighthouse_content_width', 0 );
120
121
/**
122
 * Register widget area.
123
 *
124
 * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
125
 */
126 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...
127
	register_sidebar( array(
128
		'name'          => esc_html__( 'Sidebar', 'lighthouse' ),
129
		'id'            => 'sidebar-1',
130
		'description'   => '',
131
		'before_widget' => '<section id="%1$s" class="widget %2$s">',
132
		'after_widget'  => '</section>',
133
		'before_title'  => '<h2 class="widget-title">',
134
		'after_title'   => '</h2>',
135
	) );
136
}
137
add_action( 'widgets_init', 'lighthouse_widgets_init' );
138
139
/**
140
 * Enqueue scripts and styles.
141
 */
142
function lighthouse_scripts() {
143
144
	wp_enqueue_style( 'lighthouse-font-awesome-css', get_template_directory_uri() . '/css/font-awesome.min.css');
145
146
	wp_enqueue_style( 'lighthouse-style', get_stylesheet_uri() );
147
148
	wp_enqueue_style('lighthouse-google-fonts', 'https://fonts.googleapis.com/css?family=Questrial');
149
150
	wp_enqueue_script( 'lighthouse-classList-js', 'https://cdnjs.cloudflare.com/ajax/libs/classlist/2014.01.31/classList.min.js', array('jquery'), '');
151
152
	wp_enqueue_script( 'lighthouse-bootstrap-js', get_template_directory_uri() . '/js/bootstrap.min.js', array('jquery'), '', true );
153
154
	wp_enqueue_script( 'lighthouse-material-menu-js', get_template_directory_uri() . '/js/materialMenu.js', array('jquery'), '', true );
155
156
	wp_enqueue_script( 'lighthouse-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '20120206', true );
157
158
	wp_enqueue_script( 'lighthouse-settings-js', get_template_directory_uri() . '/js/lighthouse-settings.js', array('jquery'), '', true );
159
160
	wp_enqueue_script( 'lighthouse-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20130115', true );
161
162
	if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
163
		wp_enqueue_script( 'comment-reply' );
164
	}
165
}
166
add_action( 'wp_enqueue_scripts', 'lighthouse_scripts' );
167
168
169
/**
170
 * Read More button in excerpt
171
 */
172
function new_excerpt_more( $more ) {
0 ignored issues
show
The parameter $more is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
173
    return ' ';
174
}
175
add_filter( 'excerpt_more', 'new_excerpt_more' );
176
177
/**
178
 * Custome Lenght of excerpt
179
 */
180
function custom_excerpt_length( $length ) {
0 ignored issues
show
The parameter $length is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
181
    return 30;
182
}
183
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );
184
185
/**
186
 * Implement the Custom Header feature.
187
 */
188
require get_template_directory() . '/inc/custom-header.php';
189
190
/**
191
 * Custom template tags for this theme.
192
 */
193
require get_template_directory() . '/inc/template-tags.php';
194
195
/**
196
 * Custom functions that act independently of the theme templates.
197
 */
198
require get_template_directory() . '/inc/extras.php';
199
200
/**
201
 * Customizer additions.
202
 */
203
require get_template_directory() . '/inc/customizer.php';
204
205
/**
206
 * Load Jetpack compatibility file.
207
 */
208
require get_template_directory() . '/inc/jetpack.php';
209