-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
306 lines (253 loc) · 8.93 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
<?php
/** Tell WordPress to run theme_setup() when the 'after_setup_theme' hook is run. */
if ( ! function_exists( 'theme_setup' ) ):
function theme_setup() {
/* This theme uses post thumbnails (aka "featured images")
* all images will be cropped to thumbnail size (below), as well as
* a square size (also below). You can add more of your own crop
* sizes with add_image_size. */
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size(120, 90, true);
add_image_size('square', 150, 150, true);
// Add default posts and comments RSS feed links to head
add_theme_support( 'automatic-feed-links' );
/* This theme uses wp_nav_menu() in one location.
* You can allow clients to create multiple menus by
* adding additional menus to the array. */
register_nav_menus( array(
'primary' => 'Primary Navigation',
'internal' => 'Internal Navigation'
) );
/*
* 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'
) );
}
endif;
add_action( 'after_setup_theme', 'theme_setup' );
if( function_exists('acf_add_options_page') ) {
acf_add_options_page(array(
'page_title' => 'KPMG General Settings',
'menu_title' => 'KPMG Theme Settings',
'menu_slug' => 'theme-general-settings',
'capability' => 'edit_posts',
'redirect' => false
));
acf_add_options_sub_page(array(
'page_title' => 'KPMG Header Settings',
'menu_title' => 'Header',
'parent_slug' => 'theme-general-settings',
));
acf_add_options_sub_page(array(
'page_title' => 'KPMG Footer Settings',
'menu_title' => 'Footer',
'parent_slug' => 'theme-general-settings',
));
}
/* Add all our JavaScript files here.
We'll let WordPress add them to our templates automatically instead
of writing our own script tags in the header and footer. */
function starter_kpmg_scripts() {
//Don't use WordPress' local copy of jquery, load our own version from a CDN instead
wp_deregister_script('jquery');
wp_enqueue_script(
'jquery',
"http" . ($_SERVER['SERVER_PORT'] == 443 ? "s" : "") . "://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js",
false, //dependencies
null, //version number
true //load in footer
);
wp_enqueue_script(
'plugins', //handle
get_template_directory_uri() . '/js/plugins.js', //source
false, //dependencies
null, // version number
true //load in footer
);
wp_enqueue_script(
'scripts', //handle
get_template_directory_uri() . '/js/main.min.js', //source
array( 'jquery', 'plugins' ), //dependencies
null, // version number
true //load in footer
);
}
add_action( 'wp_enqueue_scripts', 'starter_kpmg_scripts' );
/* Custom Title Tags */
function starter_kpmg_wp_title( $title, $sep ) {
global $paged, $page;
if ( is_feed() ) {
return $title;
}
// Add the site name.
$title .= get_bloginfo( 'name', 'display' );
// Add the site description for the home/front page.
$site_description = get_bloginfo( 'description', 'display' );
if ( $site_description && ( is_home() || is_front_page() ) ) {
$title = "$title $sep $site_description";
}
// Add a page number if necessary.
if ( ( $paged >= 2 || $page >= 2 ) && ! is_404() ) {
$title = "$title $sep " . sprintf( __( 'Page %s', 'starter_kpmg' ), max( $paged, $page ) );
}
return $title;
}
add_filter( 'wp_title', 'starter_kpmg_wp_title', 10, 2 );
/*
Get our wp_nav_menu() fallback, wp_page_menu(), to show a home link.
*/
function starter_kpmg_page_menu_args( $args ) {
$args['show_home'] = true;
return $args;
}
add_filter( 'wp_page_menu_args', 'starter_kpmg_page_menu_args' );
/*
* Sets the post excerpt length to 40 characters.
*/
function starter_kpmg_excerpt_length( $length ) {
return 40;
}
add_filter( 'excerpt_length', 'starter_kpmg_excerpt_length' );
/*
* Returns a "Continue Reading" link for excerpts
*/
function starter_kpmg_continue_reading_link() {
return ' <a href="'. get_permalink() . '">Continue reading <span class="meta-nav">→</span></a>';
}
/**
* Replaces "[...]" (appended to automatically generated excerpts) with an ellipsis and starter_kpmg_continue_reading_link().
*/
function starter_kpmg_auto_excerpt_more( $more ) {
return ' …' . starter_kpmg_continue_reading_link();
}
add_filter( 'excerpt_more', 'starter_kpmg_auto_excerpt_more' );
/**
* Adds a pretty "Continue Reading" link to custom post excerpts.
*/
function starter_kpmg_custom_excerpt_more( $output ) {
if ( has_excerpt() && ! is_attachment() ) {
$output .= starter_kpmg_continue_reading_link();
}
return $output;
}
add_filter( 'get_the_excerpt', 'starter_kpmg_custom_excerpt_more' );
/*
* Register a single widget area.
* You can register additional widget areas by using register_sidebar again
* within starter_kpmg_widgets_init.
* Display in your template with dynamic_sidebar()
*/
function starter_kpmg_widgets_init() {
// Area 1, located at the top of the sidebar.
register_sidebar( array(
'name' => 'Primary Widget Area',
'id' => 'primary-widget-area',
'description' => 'The primary widget area',
'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
'after_widget' => '</li>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );
}
add_action( 'widgets_init', 'starter_kpmg_widgets_init' );
/**
* Removes the default styles that are packaged with the Recent Comments widget.
*/
function starter_kpmg_remove_recent_comments_style() {
global $wp_widget_factory;
remove_action( 'wp_head', array( $wp_widget_factory->widgets['WP_Widget_Recent_Comments'], 'recent_comments_style' ) );
}
add_action( 'widgets_init', 'starter_kpmg_remove_recent_comments_style' );
if ( ! function_exists( 'starter_kpmg_posted_on' ) ) :
/**
* Prints HTML with meta information for the current post—date/time and author.
*/
function starter_kpmg_posted_on() {
printf('<span class="%1$s">Posted on</span> %2$s <span class="meta-sep">by</span> %3$s',
'meta-prep meta-prep-author',
sprintf( '<a href="%1$s" title="%2$s" rel="bookmark"><span class="entry-date">%3$s</span></a>',
get_permalink(),
esc_attr( get_the_time() ),
get_the_date()
),
sprintf( '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s">%3$s</a></span>',
get_author_posts_url( get_the_author_meta( 'ID' ) ),
sprintf( esc_attr( 'View all posts by %s'), get_the_author() ),
get_the_author()
)
);
}
endif;
if ( ! function_exists( 'starter_kpmg_posted_in' ) ) :
/**
* Prints HTML with meta information for the current post (category, tags and permalink).
*/
function starter_kpmg_posted_in() {
// Retrieves tag list of current post, separated by commas.
$tag_list = get_the_tag_list( '', ', ' );
if ( $tag_list ) {
$posted_in = 'This entry was posted in %1$s and tagged %2$s. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.';
} elseif ( is_object_in_taxonomy( get_post_type(), 'category' ) ) {
$posted_in = 'This entry was posted in %1$s. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.';
} else {
$posted_in = 'Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.';
}
// Prints the string, replacing the placeholders.
printf(
$posted_in,
get_the_category_list( ', ' ),
$tag_list,
get_permalink(),
the_title_attribute( 'echo=0' )
);
}
endif;
/* Get rid of junk! - Gets rid of all the crap in the header that you dont need */
function clean_stuff_up() {
// windows live
remove_action('wp_head', 'rsd_link');
remove_action('wp_head', 'wlwmanifest_link');
// wordpress gen tag
remove_action('wp_head', 'wp_generator');
// comments RSS
remove_action( 'wp_head', 'feed_links_extra', 3 );
remove_action( 'wp_head', 'feed_links', 3 );
}
add_action('init', 'clean_stuff_up');
/* Here are some utility helper functions for use in your templates! */
/* pre_r() - makes for easy debugging. <?php pre_r($post); ?> */
function pre_r($obj) {
echo "<pre>";
print_r($obj);
echo "</pre>";
}
/* is_blog() - checks various conditionals to figure out if you are currently within a blog page */
function is_blog () {
global $post;
$posttype = get_post_type($post );
return ( ((is_archive()) || (is_author()) || (is_category()) || (is_home()) || (is_single()) || (is_tag())) && ( $posttype == 'post') ) ? true : false ;
}
/* get_post_parent() - Returns the current posts parent, if current post if top level, returns itself */
function get_post_parent($post) {
if ($post->post_parent) {
return $post->post_parent;
}
else {
return $post->ID;
}
}
add_filter('wp_nav_menu_items', 'add_login_logout_link', 10, 2);
function add_login_logout_link($items, $args) {
$user = wp_get_current_user();
if (in_array('winterfest_employee', (array) $user->roles ) || in_array('winterfest_admin', (array) $user->roles)) {
ob_start();
wp_loginout('index.php');
$loginoutlink = ob_get_contents();
ob_end_clean();
$items .= '<li>'. $loginoutlink .'</li>';
}
return $items;
}