-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfunctions.php
353 lines (284 loc) · 10.3 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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
<?php
// Include files.
require_once( STYLESHEETPATH . '/includes/filters.php' );
require_once( STYLESHEETPATH . '/includes/shortcodes.php' );
/**
* Sets up theme defaults and registers
* support for various WordPress features.
*
* @since 1.0.0
*/
function wpcampus_2016_theme_setup() {
// Make theme available for translation.
load_theme_textdomain( 'wpcampus', get_stylesheet_directory() . '/languages' );
// Enable network components.
if ( function_exists( 'wpcampus_network_enable' ) ) {
wpcampus_network_enable( array( 'coc', 'footer' ) );
}
// Add default posts and comments RSS feed links to head.
add_theme_support( 'automatic-feed-links' );
// Let WordPress manage the document title.
add_theme_support( 'title-tag' );
// Enable support for Post Thumbnails on posts and pages.
add_theme_support( 'post-thumbnails' );
// Switch default core markup for search form, comment form, and comments to output valid HTML5.
add_theme_support( 'html5', array(
'search-form',
'comment-form',
'comment-list',
'gallery',
'caption',
));
}
add_action( 'after_setup_theme', 'wpcampus_2016_theme_setup' );
/**
* Register sidebars.
*/
function wpcampus_2016_register_sidebars() {
// Register home sidebar.
register_sidebar( array(
'name' => 'Home Sidebar',
'id' => 'home-sidebar',
'description' => '',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h2 class="sidebar-title">',
'after_title' => '</h2>',
));
// Register main sidebar.
register_sidebar( array(
'name' => 'Main Sidebar',
'id' => 'main-sidebar',
'description' => '',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h2 class="sidebar-title">',
'after_title' => '</h2>',
));
// Register sponsors sidebar.
register_sidebar( array(
'name' => 'Sponsors Sidebar',
'id' => 'sponsors-sidebar',
'description' => '',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h2 class="sidebar-title">',
'after_title' => '</h2>',
));
}
add_action( 'widgets_init', 'wpcampus_2016_register_sidebars' );
/**
* Make sure the Open Sans
* font weights we need are added.
*/
function wpcampus_2016_load_open_sans_weights( $weights ) {
return array_merge( $weights, array( 300, 400, 600 ) );
}
add_filter( 'wpcampus_open_sans_font_weights', 'wpcampus_2016_load_open_sans_weights' );
/**
* Enqueues scripts and styles.
*/
function wpcampus_2016_enqueue_scripts() {
$theme_dir = get_template_directory();
$theme_dir_uri = get_stylesheet_directory_uri();
// Add our theme stylesheet.
// wpc-fonts-open-sans is registered in the network plugin.
wp_enqueue_style( 'wpcampus-2016', $theme_dir_uri . '/assets/css/styles.css', array( 'wpc-fonts-open-sans' ), filemtime( $theme_dir . '/assets/css/styles.css' ) );
// Add our theme script.
wp_enqueue_script( 'wpcampus-2016', $theme_dir_uri . '/assets/js/wpcampus-2016.min.js', array( 'jquery' ), filemtime( $theme_dir . '/assets/js/wpcampus-2016.min.js' ) );
// Add our home styles.
if ( is_front_page() ) {
wp_enqueue_style( 'wpcampus-2016-home', $theme_dir_uri . '/assets/css/home.css', array( 'wpcampus-2016' ), filemtime( $theme_dir . '/assets/css/home.css' ) );
}
// Add our iframe script.
if ( is_page_template( 'template-map.php' ) ) {
wp_enqueue_script( 'wpcampus-2016-iframe', $theme_dir_uri . '/assets/js/wpcampus-2016-iframe.min.js', array( 'jquery' ), filemtime( $theme_dir . '/assets/js/wpcampus-2016-iframe.min.js' ) );
}
// Register handlebars.
wp_register_script( 'handlebars', '//cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.0.5/handlebars.min.js' );
// Get the API route.
$wp_rest_api_route = function_exists( 'rest_get_url_prefix' ) ? rest_get_url_prefix() : '';
if ( ! empty( $wp_rest_api_route ) ) {
$wp_rest_api_route = "/{$wp_rest_api_route}/wp/v2/";
}
// For the livestream page.
if ( is_page_template( 'template-livestream.php' ) ) {
// Enqueue the schedule script.
wp_enqueue_script( 'wpcampus-2016-livestream', $theme_dir_uri . '/assets/js/wpcampus-2016-livestream.min.js', array(
'jquery',
'handlebars',
), false, true );
// Pass some data.
wp_localize_script( 'wpcampus-2016-livestream', 'wpc_ls', array(
'wp_api_route' => $wp_rest_api_route,
));
}
}
add_action( 'wp_enqueue_scripts', 'wpcampus_2016_enqueue_scripts', 20 );
/**
* Get the post type archive title.
*/
function wpcampus_get_post_type_archive_title( $post_type = '' ) {
// Make sure we have a post type.
if ( ! $post_type ) {
$post_type = get_query_var( 'post_type' );
}
// Get post type archive title.
if ( $post_type ) {
// Make sure its not an array.
if ( is_array( $post_type ) ) {
$post_type = reset( $post_type );
}
// Get the post type data.
if ( $post_type_obj = get_post_type_object( $post_type ) ) {
// Get the title.
$title = apply_filters( 'post_type_archive_title', $post_type_obj->labels->name, $post_type );
// Return the title.
return apply_filters( 'wpcampus_post_type_archive_title', $title, $post_type );
}
}
return null;
}
/**
* Get breadcrumbs.
*/
function wpcampus_get_breadcrumbs_html() {
// Build array of breadcrumbs.
$breadcrumbs = array();
// Not for front page.
if ( is_front_page() ) {
return false;
}
// Get post type.
$post_type = get_query_var( 'post_type' );
// Make sure its not an array.
if ( is_array( $post_type ) ) {
$post_type = reset( $post_type );
}
// Add home.
$breadcrumbs[] = array(
'url' => '/',
'label' => __( 'Home', 'wpcampus' ),
);
// Add archive(s).
if ( is_archive() ) {
// Add the archive breadcrumb.
if ( is_post_type_archive() ) {
// Add crumb to schedule page.
if ( is_post_type_archive( 'speakers' ) ) {
$breadcrumbs[] = array(
'url' => '/schedule/',
'label' => __( 'Schedule', 'wpcampus' ),
);
}
// Get the info.
$post_type_archive_link = get_post_type_archive_link( $post_type );
$post_type_archive_title = wpcampus_get_post_type_archive_title( $post_type );
// Add the breadcrumb.
if ( $post_type_archive_link && $post_type_archive_title ) {
$breadcrumbs[] = array(
'url' => $post_type_archive_link,
'label' => $post_type_archive_title,
);
}
}
} else {
// Add links to archive.
if ( is_singular() ) {
// Get the information.
$post_type_archive_link = get_post_type_archive_link( $post_type );
$post_type_archive_title = wpcampus_get_post_type_archive_title( $post_type );
if ( $post_type_archive_link ) {
$breadcrumbs[] = array(
'url' => $post_type_archive_link,
'label' => $post_type_archive_title,
);
}
}
// Print info for the current post.
$post = get_queried_object();
if ( $post && is_a( $post, 'WP_Post' ) ) {
// Get ancestors.
$post_ancestors = isset( $post ) ? get_post_ancestors( $post->ID ) : array();
// Add the ancestors.
foreach ( $post_ancestors as $post_ancestor_id ) {
// Add ancestor.
$breadcrumbs[] = array(
'ID' => $post_ancestor_id,
'url' => get_permalink( $post_ancestor_id ),
'label' => get_the_title( $post_ancestor_id ),
);
}
// Add current page - if not home page.
if ( isset( $post ) ) {
$breadcrumbs['current'] = array(
'ID' => $post->ID,
'url' => get_permalink( $post ),
'label' => get_the_title( $post->ID ),
);
}
}
}
// Filter the breadcrumbs.
$breadcrumbs = apply_filters( 'wpcampus_2016_breadcrumbs', $breadcrumbs );
// Build breadcrumbs HTML.
$breadcrumbs_html = null;
foreach ( $breadcrumbs as $crumb_key => $crumb ) {
// Make sure we have what we need.
if ( empty( $crumb['label'] ) ) {
continue;
}
// If no string crumb key, set as ancestor.
if ( ! $crumb_key || is_numeric( $crumb_key ) ) {
$crumb_key = 'ancestor';
}
// Setup classes.
$crumb_classes = array( $crumb_key );
// Add if current.
if ( isset( $crumb['current'] ) && $crumb['current'] ) {
$crumb_classes[] = 'current';
}
$breadcrumbs_html .= '<li' . ( ! empty( $crumb_classes ) ? ' class="' . implode( ' ', $crumb_classes ) . '"' : null ) . '>';
// Add URL and label.
if ( ! empty( $crumb['url'] ) ) {
$breadcrumbs_html .= '<a href="' . $crumb['url'] . '"' . ( ! empty( $crumb['title'] ) ? ' title="' . $crumb['title'] . '"' : null ) . '>' . $crumb['label'] . '</a>';
} else {
$breadcrumbs_html .= $crumb['label'];
}
$breadcrumbs_html .= '</li>';
}
// Wrap them in nav.
$breadcrumbs_html = '<div class="breadcrumbs-wrapper"><nav class="breadcrumbs" aria-label="breadcrumbs"><ul>' . $breadcrumbs_html . '</ul></nav></div>';
// We change up the variable so it doesn't interfere with global variable.
return $breadcrumbs_html;
}
/**
* Decide which main callout to print.
*/
function wpcampus_2016_print_main_callout() {
//wpcampus_2016_print_2017_callout();
}
/**
* Print the 2017 callout.
*/
function wpcampus_2016_print_2017_callout() {
?>
<div class="callout secondary" style="text-align:center;">
<h2>WPCampus 2017 Conference on July 14-15</h2>
<p><a href="https://2017.wpcampus.org/" style="color:inherit;">WPCampus 2017</a> will take place July 14-15 on the campus of Canisius College in Buffalo, New York. <strong>Ticket sales have closed</strong> but, if you can't join us in person, all sessions will be live-streamed and made available online after the event. Gather with other WordPress users on your campus and create your own WPCampus experience!</p>
<a class="button expand" style="display:block;" href="https://2017.wpcampus.org/">Visit the WPCampus 2017 website</a>
</div>
<?php
}
/**
* Print the ed survey callout.
*/
function wpcampus_2016_print_ed_survey_callout() {
?>
<div class="callout secondary" style="text-align:center;">
<h2>The "WordPress in Education" Survey</h2>
<p>After an overwhelming response to our 2016 survey, WPCampus is back this year to dig a little deeper on key topics that schools and campuses care about most when it comes to WordPress and website development. We’d love to include your feedback in our results this year. The larger the data set, the more we all benefit. <strong>The survey will close on June 23rd, 2017.</strong></p>
<a class="button expand" style="display:block;" href="https://2017.wpcampus.org/announcements/wordpress-in-education-survey/">Take the "WordPress in Education" survey</a>
</div>
<?php
}