1
|
|
|
<?php |
|
|
|
|
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Theme Appearance Class |
5
|
|
|
* |
6
|
|
|
* Manages JS & CSS enqueuing of the theme |
7
|
|
|
*/ |
8
|
|
|
class ClassyAppearance { |
|
|
|
|
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( 'flotheme_general_css', THEME_DIR . 'assets/css/general.css', array(), THEME_VERSION, 'all' ); |
28
|
|
|
|
29
|
|
|
wp_enqueue_style( 'flotheme_general_css' ); |
30
|
|
|
|
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Enqueues scripts |
35
|
|
|
*/ |
36
|
|
|
public function enqueue_scripts() { |
37
|
|
|
|
38
|
|
|
wp_deregister_script( 'jquery' ); |
39
|
|
|
|
40
|
|
|
wp_register_script( 'jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js', array(), THEME_VERSION, true ); |
41
|
|
|
|
42
|
|
|
if ( Classy::get_config_var('environment') == 'production' ) { |
43
|
|
|
|
44
|
|
|
wp_register_script( 'theme_plugins', THEME_DIR . 'assets/js/min/production.js', array( 'jquery' ), THEME_VERSION, true ); |
45
|
|
|
|
46
|
|
|
} else { |
47
|
|
|
|
48
|
|
|
wp_register_script( 'theme_plugins', THEME_DIR . 'assets/js/plugins.js', array( 'jquery' ), THEME_VERSION, true ); |
49
|
|
|
|
50
|
|
|
wp_register_script( 'theme_scripts', THEME_DIR . 'assets/js/scripts.js', array( 'jquery' ), THEME_VERSION, true ); |
51
|
|
|
|
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
wp_enqueue_script( 'theme_plugins' ); |
55
|
|
|
|
56
|
|
|
wp_enqueue_script( 'theme_scripts' ); |
57
|
|
|
|
58
|
|
|
wp_enqueue_script( 'theme_production' ); |
59
|
|
|
|
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Load needed options & translations into template. |
64
|
|
|
*/ |
65
|
|
|
public function init_js_vars() { |
66
|
|
|
|
67
|
|
|
$options = array( |
68
|
|
|
'base_url' => home_url(''), |
69
|
|
|
'blog_url' => home_url('archives/'), |
70
|
|
|
'template_dir' => THEME_DIR, |
71
|
|
|
'ajax_load_url' => site_url('/wp-admin/admin-ajax.php'), |
72
|
|
|
'is_mobile' => (int) wp_is_mobile(), |
73
|
|
|
); |
74
|
|
|
|
75
|
|
|
wp_localize_script( |
76
|
|
|
'theme_plugins', |
77
|
|
|
'theme', |
78
|
|
|
$options |
79
|
|
|
); |
80
|
|
|
|
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Sets up theme defaults and registers support for various WordPress features. |
86
|
|
|
* |
87
|
|
|
* Note that this function is hooked into the after_setup_theme hook, which |
88
|
|
|
* runs before the init hook. The init hook is too late for some features, such |
89
|
|
|
* as indicating support for post thumbnails. |
90
|
|
|
*/ |
91
|
|
|
public function setup_theme() { |
92
|
|
|
|
93
|
|
|
/* |
94
|
|
|
* Enable support for Post Thumbnails on posts and pages. |
95
|
|
|
* |
96
|
|
|
* @link http://codex.wordpress.org/Function_Reference/add_theme_support#Post_Thumbnails |
97
|
|
|
*/ |
98
|
|
|
|
99
|
|
|
add_theme_support('post-thumbnails'); |
100
|
|
|
|
101
|
|
|
// This theme uses wp_nav_menu() in one location. |
102
|
|
|
register_nav_menus(array( |
103
|
|
|
'header-menu' => __('Header Menu', Classy::textdomain()), |
104
|
|
|
'footer-menu' => __('Footer Menu', Classy::textdomain()), |
105
|
|
|
)); |
106
|
|
|
|
107
|
|
|
/* |
108
|
|
|
* Switch default core markup for search form, comment form, and comments |
109
|
|
|
* to output valid HTML5. |
110
|
|
|
*/ |
111
|
|
|
|
112
|
|
|
add_theme_support('html5', array( |
113
|
|
|
'search-form', 'comment-form', 'comment-list', 'gallery', 'caption', |
114
|
|
|
)); |
115
|
|
|
|
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
new ClassyAppearance(); |
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.