-
Notifications
You must be signed in to change notification settings - Fork 3
/
functions.php
201 lines (167 loc) · 5.46 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
<?php
/**
* Adds composer autoload file and starts Timber
============================================== */
require_once __DIR__ . '/vendor/autoload.php';
$timber = new \Timber\Timber();
Timber::$dirname = array( 'templates', 'views' );
class Seedling extends \Timber\Site {
function __construct() {
add_action( 'init', array($this, 'extend') );
$this->filters();
$this->actions();
parent::__construct();
}
function extend() {
$this->themeSupport();
$this->registerPostTypes();
$this->registerTaxonomies();
$this->registerMenus();
$this->addUserRoles();
$this->addImagesSizes();
$this->addToACF();
}
/**
* Add all filters here
*/
function filters() {
add_filter( 'timber_context', array($this, 'addToContext') );
add_filter( 'login_headerurl', array($this, 'updateLoginLogoURL') );
add_filter( 'login_message', array($this, 'addLoginMessage') );
add_filter( 'acf/settings/show_admin', array($this, 'hideACFAdmin') );
}
/**
* Add all actions here
*/
function actions() {
add_action( 'login_enqueue_scripts', array($this, 'updateLoginLogo') );
add_action( 'wp_enqueue_scripts', array($this, 'enqueueScripts') );
add_action( 'wp_head', array($this, 'addGTMHead'), 10 );
add_action( 'body_top', array($this, 'addGTMBody') );
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
remove_action( 'wp_print_styles', 'print_emoji_styles' );
remove_action( 'admin_print_styles', 'print_emoji_styles' );
}
/**
* Use this method to add theme support
*/
function themeSupport() {
add_theme_support( 'post-formats' );
add_theme_support( 'post-thumbnails' );
}
function registerPostTypes() {
require __DIR__ . '/app/post-types.php';
}
function registerTaxonomies() {
require __DIR__ . '/app/taxonomies.php';
}
function registerMenus() {
require __DIR__ . '/app/menus.php';
}
function addUserRoles() {
require __DIR__ . '/app/user-roles.php';
}
/**
* Use this method to add variables to the context
*/
function addToContext($context) {
$context['site'] = $this;
$context['menu'] = new Timber\Menu('main-menu');
$context['footer-menu'] = new Timber\Menu('footer-menu');
// Site-wide Settings
if( function_exists('get_field') ) {
$context['site_settings'] = get_fields('option');
}
return $context;
}
/**
* Use this method to register custom image sizes
*/
function addImagesSizes() {
// add_image_size( 'hero', 3000, 9999 );
}
/**
* Use this method to add to Advanced Custom Fields
*/
function addToACF() {
if( function_exists('acf_add_options_page') ) {
acf_add_options_page(array(
'page_title' => 'General Settings',
'menu_title' => 'Site Settings',
'menu_slug' => 'site-general-settings',
'capability' => 'edit_posts',
'redirect' => false
));
}
}
function enqueueScripts() {
wp_deregister_script('jquery');
wp_enqueue_script('jquery', get_template_directory_uri() . '/assets/build/js/jquery.min.js', array(), '3.4.0');
wp_enqueue_script('seedling-scripts', get_template_directory_uri() . '/assets/build/js/all.min.js', array(), '');
}
function updateLoginLogo() { ?>
<style type="text/css">
#login h1 a, .login h1 a {
background-image: url(<?php echo get_stylesheet_directory_uri(); ?>/logo.png);
background-size: 90%;
width: XXXpx;
height: XXXpx;
margin: 0 auto;
}
</style>
<?php }
function updateLoginLogoURL() {
return get_site_url();
}
function addLoginMessage() {
return "";
}
function hideACFAdmin() {
// get the current site url
$site_url = get_bloginfo( 'url' );
// an array of protected site urls
$protected_urls = array(
'https://example.com',
'https://staging.example.com'
);
// check if the current site url is in the protected urls array
if ( in_array( $site_url, $protected_urls ) ) {
// hide the acf menu item
return false;
} else {
// show the acf menu item
return true;
}
}
function addGTMHead() { ?>
<?php if ( WP_ENV === 'production' && get_field('google_tag_manager_id', 'option') ): ?>
<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-<?php the_field("google_tag_manager_id", "option") ?>');</script>
<!-- End Google Tag Manager -->
<?php endif; ?>
<?php }
function addGTMBody() { ?>
<?php if ( WP_ENV === 'production' && get_field('google_tag_manager_id', 'option') ): ?>
<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-<?php the_field('google_tag_manager_id', 'option') ?>"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->
<?php endif; ?>
<?php }
}
new Seedling();
/*
_____ _ _ _
/ ___| | | (_)
\ `--. ___ ___ __| | |_ _ __ __ _
`--. \/ _ \/ _ \/ _` | | | '_ \ / _` |
/\__/ / __/ __/ (_| | | | | | | (_| |
\____/ \___|\___|\__,_|_|_|_| |_|\__, |
__/ |
|___/
*/