-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
98 lines (69 loc) · 2.41 KB
/
functions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
class Hand_Built {
private static $instance;
public function __construct() {}
public static function get_instance() {
if ( ! isset( self::$instance ) ) {
self::$instance = new Hand_Built;
self::$instance->require_files();
self::$instance->setup_actions();
self::$instance->setup_filters();
}
return self::$instance;
}
private function require_files() {
require_once dirname( __FILE__ ) . '/lib/cache-busting-magic.php';
require_once dirname( __FILE__ ) . '/lib/timber/timber.php';
}
private function setup_actions() {
add_action( 'init', function() {
if ( ! is_admin() ) {
show_admin_bar( false );
}
});
add_action( 'template_redirect', function() {
if ( ! is_home() ) {
wp_safe_redirect( home_url() );
exit;
}
});
add_action( 'wp_enqueue_scripts', array( $this, 'action_wp_enqueue_scripts' ) );
add_action( 'wp_footer', array( $this, 'action_wp_footer' ) );
}
private function setup_filters() {
add_filter( 'pre_option_blogname', function() {
return 'Hand Built';
});
add_filter( 'pre_option_blogdescription', function(){
return 'Custom WordPress development, code review, data migrations, and consulting services from Daniel Bachhuber.';
});
}
public function action_wp_enqueue_scripts() {
wp_enqueue_script( 'foundation', get_stylesheet_directory_uri() . '/lib/foundation/foundation.min.js', array( 'jquery' ) );
wp_enqueue_style( 'foundation', get_stylesheet_directory_uri() . '/lib/foundation/foundation.min.css' );
wp_enqueue_style( 'google-fonts', '//fonts.googleapis.com/css?family=Roboto+Slab:400,300,700|Open+Sans:400italic,600italic,300,400,600' );
wp_enqueue_style( 'hand-built', get_stylesheet_uri() );
}
public function action_wp_footer() {
if ( is_user_logged_in() || ( defined( 'ENVIRONMENT' ) && 'local' === ENVIRONMENT ) ) {
return;
}
?>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-49623239-1', 'handbuilt.co');
ga('send', 'pageview');
</script>
<?php
}
}
/**
* Load the theme
*/
add_action( 'after_setup_theme', 'Hand_Built' );
function Hand_Built() {
return Hand_Built::get_instance();
}