-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
284 lines (223 loc) · 8.79 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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
<?php
require get_theme_file_path('/inc/like-route.php');
require get_theme_file_path('/inc/search-route.php');
function university_custom_rest() {
register_rest_field('post', 'authorName', array(
'get_callback' => function() {return get_the_author();}
));
register_rest_field('note', 'userNoteCount', array(
'get_callback' => function() {return count_user_posts(get_current_user_id(), 'note');}
));
}
add_action('rest_api_init', 'university_custom_rest');
function pageBanner($args = NULL) {
if (!isset($args['title'])) {
$args['title'] = get_the_title();
}
if (!isset($args['subtitle'])) {
$args['subtitle'] = get_field('page_banner_subtitle');
}
if (!isset($args['photo'])) {
if (get_field('page_banner_background_image') AND !is_archive() AND !is_home() ) {
$args['photo'] = get_field('page_banner_background_image')['sizes']['pageBanner'];
} else {
$args['photo'] = get_theme_file_uri('/images/building.jpg');
}
}
?>
<div class="page-banner">
<div class="page-banner__bg-image" style="background-image: url(<?php echo $args['photo']; ?>);"></div>
<div class="page-banner__content container container--narrow">
<h1 class="page-banner__title"><?php echo $args['title'] ?></h1>
<div class="page-banner__intro">
<p><?php echo $args['subtitle']; ?></p>
</div>
</div>
</div>
<?php }
function university_files() {
wp_enqueue_script('googleMap', '//maps.googleapis.com/maps/api/js?key=AIzaSyDin3iGCdZ7RPomFLyb2yqFERhs55dmfTI', NULL, '1.0', true);
wp_enqueue_script('main-university-js', get_theme_file_uri('/build/index.js'), array('jquery'), '1.0', true);
wp_enqueue_style('custom-google-fonts', '//fonts.googleapis.com/css?family=Roboto+Condensed:300,300i,400,400i,700,700i|Roboto:100,300,400,400i,700,700i');
wp_enqueue_style('font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css');
wp_enqueue_style('university_main_styles', get_theme_file_uri('/build/style-index.css'));
wp_enqueue_style('university_extra_styles', get_theme_file_uri('/build/index.css'));
wp_localize_script('main-university-js', 'universityData', array(
'root_url' => get_site_url(),
'nonce' => wp_create_nonce('wp_rest')
));
}
add_action('wp_enqueue_scripts', 'university_files');
function university_features() {
add_theme_support('title-tag');
add_theme_support('post-thumbnails');
add_image_size('professorLandscape', 400, 260, true);
add_image_size('professorPortrait', 480, 650, true);
add_image_size('pageBanner', 1500, 350, true);
add_theme_support('editor-styles');
add_editor_style(array('https://fonts.googleapis.com/css?family=Roboto+Condensed:300,300i,400,400i,700,700i|Roboto:100,300,400,400i,700,700i', 'build/style-index.css', 'build/index.css'));
}
add_action('after_setup_theme', 'university_features');
function university_adjust_queries($query) {
if (!is_admin() AND is_post_type_archive('campus') AND $query->is_main_query()) {
$query->set('posts_per_page', -1);
}
if (!is_admin() AND is_post_type_archive('program') AND $query->is_main_query()) {
$query->set('orderby', 'title');
$query->set('order', 'ASC');
$query->set('posts_per_page', -1);
}
if (!is_admin() AND is_post_type_archive('event') AND $query->is_main_query()) {
$today = date('Ymd');
$query->set('meta_key', 'event_date');
$query->set('orderby', 'meta_value_num');
$query->set('order', 'ASC');
$query->set('meta_query', array(
array(
'key' => 'event_date',
'compare' => '>=',
'value' => $today,
'type' => 'numeric'
)
));
}
}
add_action('pre_get_posts', 'university_adjust_queries');
function universityMapKey($api) {
$api['key'] = 'yourKeyGoesHere';
return $api;
}
add_filter('acf/fields/google_map/api', 'universityMapKey');
// Redirect subscriber accounts out of admin and onto homepage
add_action('admin_init', 'redirectSubsToFrontend');
function redirectSubsToFrontend() {
$ourCurrentUser = wp_get_current_user();
if (count($ourCurrentUser->roles) == 1 AND $ourCurrentUser->roles[0] == 'subscriber') {
wp_redirect(site_url('/'));
exit;
}
}
add_action('wp_loaded', 'noSubsAdminBar');
function noSubsAdminBar() {
$ourCurrentUser = wp_get_current_user();
if (count($ourCurrentUser->roles) == 1 AND $ourCurrentUser->roles[0] == 'subscriber') {
show_admin_bar(false);
}
}
// Customize Login Screen
add_filter('login_headerurl', 'ourHeaderUrl');
function ourHeaderUrl() {
return esc_url(site_url('/'));
}
add_action('login_enqueue_scripts', 'ourLoginCSS');
function ourLoginCSS() {
wp_enqueue_style('custom-google-fonts', '//fonts.googleapis.com/css?family=Roboto+Condensed:300,300i,400,400i,700,700i|Roboto:100,300,400,400i,700,700i');
wp_enqueue_style('font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css');
wp_enqueue_style('university_main_styles', get_theme_file_uri('/build/style-index.css'));
wp_enqueue_style('university_extra_styles', get_theme_file_uri('/build/index.css'));
}
add_filter('login_headertitle', 'ourLoginTitle');
function ourLoginTitle() {
return get_bloginfo('name');
}
// Force note posts to be private
add_filter('wp_insert_post_data', 'makeNotePrivate', 10, 2);
function makeNotePrivate($data, $postarr) {
if ($data['post_type'] == 'note') {
if(count_user_posts(get_current_user_id(), 'note') > 4 AND !$postarr['ID']) {
die("You have reached your note limit.");
}
$data['post_content'] = sanitize_textarea_field($data['post_content']);
$data['post_title'] = sanitize_text_field($data['post_title']);
}
if($data['post_type'] == 'note' AND $data['post_status'] != 'trash') {
$data['post_status'] = "private";
}
return $data;
}
//Blog And Events
class PlaceholderBlock {
function __construct($name) {
$this->name = $name;
add_action('init', [$this, 'onInit']);
}
function ourRenderCallback($attributes, $content) {
ob_start();
require get_theme_file_path("/our-blocks/{$this->name}.php");
return ob_get_clean();
}
function onInit() {
wp_register_script($this->name, get_stylesheet_directory_uri() . "/our-blocks/{$this->name}.js", array('wp-blocks', 'wp-editor'));
register_block_type("ourblocktheme/{$this->name}", array(
'editor_script' => $this->name,
'render_callback' => [$this, 'ourRenderCallback']
));
}
}
new PlaceholderBlock("eventsandblogs");
//HEADER
new PlaceholderBlock("header");
//FOOTER
new PlaceholderBlock("footer");
//SINGLE POST
new PlaceholderBlock("singlepost");
//PAGE
new PlaceholderBlock("page");
//BLOG INDEX
new PlaceholderBlock("blogindex");
new PlaceholderBlock("programarchive");
new PlaceholderBlock("singleprogram");
new PlaceholderBlock("singleprofessor");
new PlaceholderBlock("mynotes");
new PlaceholderBlock("archivecampus");
new PlaceholderBlock("archiveevent");
new PlaceholderBlock("archive");
new PlaceholderBlock("pastevents");
new PlaceholderBlock("search");
new PlaceholderBlock("searchresults");
new PlaceholderBlock("singlecampus");
new PlaceholderBlock("singleevent");
// BANNER
class JSXBlock {
function __construct($name, $renderCallback = null, $data = null) {
$this->name = $name;
$this->data = $data;
$this->renderCallback = $renderCallback;
add_action('init', [$this, 'onInit']);
}
function ourRenderCallback($attributes, $content) {
ob_start();
require get_theme_file_path("/our-blocks/{$this->name}.php");
return ob_get_clean();
}
function onInit() {
wp_register_script($this->name, get_stylesheet_directory_uri() . "/build/{$this->name}.js", array('wp-blocks', 'wp-editor'));
if ($this->data) {
wp_localize_script($this->name, $this->name, $this->data);
}
$ourArgs = array(
'editor_script' => $this->name
);
if ($this->renderCallback) {
$ourArgs['render_callback'] = [$this, 'ourRenderCallback'];
}
register_block_type("ourblocktheme/{$this->name}", $ourArgs);
}
}
new JSXBlock('banner', true, ['fallbackimage' => get_theme_file_uri('/images/library-hero.jpg')]);
//up line Reason wht Bg image wasn't showing initially, look out for $data
new JSXBlock('genericheading');
new JSXBlock('genericbutton');
//SLIDESHOW
new JSXBlock('slideshow', true);
new JSXBlock('slide', true, ['themeimagepath' => get_theme_file_uri('/images/')]);
function myallowedblocks($allowed_block_types, $editor_context) {
// If you are on a page/post editor screen
if (!empty($editor_context->post)) {
return $allowed_block_types;
}
// if you are on the FSE screen
return array('ourblocktheme/header', 'ourblocktheme/footer');
}
// Uncomment the line below if you actually want to restrict which block types are allowed
//add_filter('allowed_block_types_all', 'myallowedblocks', 10, 2);