Completed
Push — master ( bc6754...ed64c2 )
by
unknown
07:19
created

Appearance   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 100
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 100
rs 10
wmc 6
lcom 0
cbo 1

5 Methods

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