Completed
Push — master ( 50ebea...f30043 )
by Andrew
02:27
created

ClassyAppearance::enqueue_scripts()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
c 2
b 0
f 0
nc 2
nop 0
dl 0
loc 15
rs 9.4285
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 8 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
/**
4
 * Theme Appearance Class
5
 *
6
 * Manages JS & CSS enqueuing of the theme
7
 */
8
class ClassyAppearance {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
9
10
	public function __construct() {
11
12
		add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles' ) );
13
14
		add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
15
16
		add_action( 'wp_print_scripts', array($this, 'init_js_vars') );
17
18
		add_action( 'after_setup_theme', array($this, 'setup_theme') );
19
20
	}
21
22
	/**
23
	 * Enqueues styles
24
	 */
25
	public function enqueue_styles() {
26
27
		wp_register_style( 'general_css', THEME_DIR . 'assets/css/general.css', array(), THEME_VERSION, 'all' );
28
		
29
		// wp_enqueue_style( 'general_css' );
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...
30
31
	}
32
33
	/**
34
	 * Enqueues scripts
35
	 */
36
	public function enqueue_scripts() {
37
38
		if ( Classy::get_config_var('environment') == 'production' ) {
39
		
40
			wp_register_script( 'theme_scripts', THEME_DIR . 'assets/js/min/production.js', array( 'jquery' ), THEME_VERSION, true );
41
		
42
		} else {
43
44
			wp_register_script( 'theme_scripts', THEME_DIR . 'assets/js/scripts.js', array( 'jquery' ), THEME_VERSION, true );
45
		
46
		}
47
		
48
		// wp_enqueue_script( 'theme_scripts' );
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...
49
50
	}
51
52
	/**
53
	 * Load needed options & translations into template.
54
	 */
55
	public function init_js_vars() {
56
	
57
		$options = array(
58
			'base_url'          => home_url(''),
59
			'blog_url'          => home_url('archives/'),
60
			'template_dir'      => THEME_DIR,
61
			'ajax_load_url'     => site_url('/wp-admin/admin-ajax.php'),
62
			'is_mobile'         => (int) wp_is_mobile(),
63
		);
64
65
		wp_localize_script(
66
			'theme_plugins',
67
			'theme',
68
			$options
69
		);
70
71
	}
72
73
74
	/**
75
	 * Sets up theme defaults and registers support for various WordPress features.
76
	 *
77
	 * Note that this function is hooked into the after_setup_theme hook, which
78
	 * runs before the init hook. The init hook is too late for some features, such
79
	 * as indicating support for post thumbnails.
80
	 */
81
	public function setup_theme() {
82
83
		/*
84
		 * Enable support for Post Thumbnails on posts and pages.
85
		 *
86
		 * @link http://codex.wordpress.org/Function_Reference/add_theme_support#Post_Thumbnails
87
		 */
88
		
89
		add_theme_support('post-thumbnails');
90
91
		// This theme uses wp_nav_menu() in one location.
92
		register_nav_menus(array(
93
			'header-menu' => __('Header Menu', Classy::textdomain()),
94
			'footer-menu' => __('Footer Menu', Classy::textdomain()),
95
		));
96
97
		/*
98
		 * Switch default core markup for search form, comment form, and comments
99
		 * to output valid HTML5.
100
		 */
101
		
102
		add_theme_support('html5', array(
103
			'search-form', 'comment-form', 'comment-list', 'gallery', 'caption',
104
		));
105
106
	}
107
108
}
109
110
new ClassyAppearance();