This repository has been archived by the owner on Apr 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathfunctions.php
executable file
·351 lines (289 loc) · 9.82 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
<?php
/*
* Plugin dependencies
*/
require_once(STYLESHEETPATH . '/inc/class-tgm-plugin-activation.php');
function newsroom_register_required_plugins() {
$plugins = array(
array(
'name' => 'Page Builder by SiteOrigin',
'slug' => 'siteorigin-panels',
'required' => true,
'force_activation' => true
)
);
$options = array(
'default_path' => '',
'menu' => 'newsroom-install-plugins',
'has_notices' => true,
'dismissable' => true,
'dismiss_msg' => '',
'is_automatic' => false,
'message' => ''
);
tgmpa($plugins, $options);
}
add_action('tgmpa_register', 'newsroom_register_required_plugins');
/*
* Theme options
*/
require_once(STYLESHEETPATH . '/inc/theme-options.php');
function newsroom_logo($mobile = false) {
$logo = newsroom_get_logo();
if($logo) {
?>
<?php echo $mobile ? '<span class="logo with-image">' : '<h1 class="has-logo">'; ?>
<a href="<?php echo home_url('/'); ?>" title="<?php bloginfo('name'); ?>">
<?php bloginfo('name'); ?>
<?php echo $logo; ?>
</a>
<?php echo $mobile ? '</span>' : '</h1>'; ?>
<?php
} else {
?>
<?php echo $mobile ? '<span class="logo">' : '<h1>'; ?>
<a href="<?php echo home_url('/'); ?>" title="<?php bloginfo('name'); ?>">
<?php bloginfo('name'); ?>
</a>
<?php echo $mobile ? '</span>' : '</h1>'; ?>
<?php
}
}
/*
* Theme setup
*/
function newsroom_setup() {
add_image_size('highlight-carousel', 672, 380, true);
add_image_size('kicker', 1020, 800);
add_image_size('small-thumb', 87, 87, true);
add_image_size('list-thumb', 237, 112, true);
add_theme_support('automatic-feed-links');
add_theme_support('post-thumbnails');
// text domain
load_child_theme_textdomain('newsroom', get_stylesheet_directory() . '/languages');
// nav
register_nav_menus(array(
'header_menu' => __('Header menu', 'newsroom'),
'footer_menu' => __('Footer menu', 'newsroom')
));
unregister_sidebar('front_page');
unregister_sidebar('general');
//sidebars
register_sidebar(array(
'name' => __('Post sidebar', 'newsroom'),
'id' => 'post',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>'
));
register_sidebar(array(
'name' => __('Footer content', 'newsroom'),
'id' => 'footer',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>'
));
register_sidebar(array(
'name' => __('Archive sidebar', 'newsroom'),
'id' => 'archive',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>'
));
register_sidebar(array(
'name' => __('Search results sidebar', 'newsroom'),
'id' => 'search',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>'
));
}
add_action('after_setup_theme', 'newsroom_setup', 100);
/*
* Newsroom widgets
*/
include_once(STYLESHEETPATH . '/inc/widgets/single-map.php');
if(class_exists('SiteOrigin_Widget')) {
include_once(STYLESHEETPATH . '/inc/siteorigin-widgets/highlight-carousel/highlight-carousel.php');
include_once(STYLESHEETPATH . '/inc/siteorigin-widgets/square-posts/square-posts.php');
include_once(STYLESHEETPATH . '/inc/siteorigin-widgets/list-posts/list-posts.php');
include_once(STYLESHEETPATH . '/inc/siteorigin-widgets/list-images/list-images.php');
}
/*
* Clears JEO default front-end styles and scripts
*/
function newsroom_scripts() {
// deregister jeo styles
wp_deregister_style('jeo-main');
// deregister jeo site frontend scripts
wp_deregister_script('jeo-site');
}
add_action('wp_enqueue_scripts', 'newsroom_scripts', 10);
/*
* JEO Hooks examples
* Most common hooks
*/
// Action right after JEO functionality inits
function newsroom_init() {
// Action goes here
}
add_action('jeo_init', 'newsroom_init');
// Hook scripts after JEO scripts has been initialized
function newsroom_main_scripts() {
// JS libraries
wp_register_script('fitvids', get_stylesheet_directory_uri() . '/lib/jquery.fitvids.js', array('jquery'), '1.1');
wp_register_script('hammer.js', get_stylesheet_directory_uri() . '/lib/hammerjs/hammer.min.js');
wp_register_script('chosen', get_stylesheet_directory_uri() . '/lib/chosen/chosen.jquery.min.js', array('jquery'));
wp_register_style('chosen', get_stylesheet_directory_uri() . '/lib/chosen/chosen.min.css');
wp_register_script('moment', get_stylesheet_directory_uri() . '/lib/moment/moment.min.js');
// CSS Dependencies
wp_register_style('newsroom-normalize', get_stylesheet_directory_uri() . '/css/normalize.css');
wp_register_style('newsroom-entypo', get_stylesheet_directory_uri() . '/css/entypo.css');
wp_register_style('newsroom-fonts', 'https://fonts.googleapis.com/css?family=Source+Sans+Pro:400,300,400italic,600,600italic,700,700italic,300italic,200|Crimson+Text:400,600,700');
// Enqueue child theme JEO related scripts
// wp_enqueue_script('newsroom-jeo-scripts', get_stylesheet_directory_uri() . '/js/jeo-scripts.js', array('jquery') , '0.0.1');
// Main
wp_enqueue_script('newsroom-main', get_stylesheet_directory_uri() . '/js/main.js', array('jquery', 'fitvids'), '0.0.1');
// Enqueue child theme main CSS
wp_enqueue_style('newsroom-styles', get_stylesheet_directory_uri() . '/css/main.css', array('newsroom-normalize', 'newsroom-entypo', 'newsroom-fonts'));
}
add_action('wp_enqueue_scripts', 'newsroom_main_scripts');
function newsroom_pb_parse_query($pb_query) {
$query = wp_parse_args($pb_query);
if($query['tax_query']) {
$tax_args = explode(',', $query['tax_query']);
$query['tax_query'] = array();
foreach($tax_args as $tax_arg) {
$tax_arg = explode(':', $tax_arg);
$query['tax_query'][] = array(
'taxonomy' => $tax_arg[0],
'field' => 'slug',
'terms' => $tax_arg[1]
);
}
}
return $query;
}
// Single templates
include_once(STYLESHEETPATH . '/inc/single-templates/single-templates.php');
function newsroom_tax_terms($post_id = false) {
global $post;
$post_id = $post_id ? $post_id : $post->ID;
$taxonomies = get_taxonomies(array(
'public' => true,
'show_ui' => true
), 'objects');
$post_tax_terms = array();
foreach($taxonomies as $tax) {
$terms = wp_get_post_terms($post_id, $tax->name);
if($terms) {
$post_tax_terms[$tax->name] = array();
$post_tax_terms[$tax->name]['taxonomy'] = $tax;
$post_tax_terms[$tax->name]['terms'] = $terms;
}
}
if(!empty($post_tax_terms)) :
?>
<div class="newsroom-tax-terms">
<?php foreach($post_tax_terms as $tax) : ?>
<div class="tax-<?php echo $tax['taxonomy']->name; ?> tax-item">
<p><?php echo $tax['taxonomy']->labels->name; ?>:</p>
<ul>
<?php foreach($tax['terms'] as $term) : ?>
<li><a href="<?php echo get_term_link($term); ?>"><?php echo apply_filters('the_title', $term->name); ?></a></li>
<?php endforeach; ?>
</ul>
</div>
<?php endforeach; ?>
</div>
<?php
endif;
}
// Photoswipe
include_once(STYLESHEETPATH . '/inc/photoswipe/photoswipe.php');
// Featured media
include_once(STYLESHEETPATH . '/inc/featured-media/featured-media.php');
// Advanced nav
include_once(STYLESHEETPATH . '/inc/advanced-nav.php');
/*
* Social APIs
*/
function newsroom_social_apis() {
// Facebook
$fb_api = newsroom_get_fb_client_id();
if($fb_api) :
?>
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=<?php echo $fb_api; ?>";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<?php
endif;
// Twitter
?>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="https://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
<?php
// Google Plus
?>
<script type="text/javascript">
(function() {
var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
po.src = 'https://apis.google.com/js/plusone.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
})();
</script>
<?php
}
add_action('wp_footer', 'newsroom_social_apis');
function newsroom_the_author($display_name) {
global $post;
if(function_exists('get_field') && get_field('author')) {
return get_field('author');
}
return $display_name;
}
add_filter('the_author', 'newsroom_the_author');
/******************************************
CUSTOM AUTHORS SHORTCODE
******************************************/
function author_list_func( ){
$result = '';
$result .= '<div class="author-alphabet">';
$letter = '';
$newletter = '1';
$blogusers = get_users( 'orderby=nicename' );
usort($blogusers, create_function('$a, $b', 'return strnatcasecmp($a->last_name, $b->last_name);'));
foreach ( $blogusers as $user ) {
if(!$user->last_name == "") {
$letter = substr($user->last_name,0,1);
$letter = strtoupper($letter);
if($letter !== $newletter) {
$newletter = $letter;
$result .= '<a href="#al-' . $letter . '">' . $letter . '</a>';
}
}
}
$result .='</div>';
$result .='<div class="authorsList">';
$letter = '';
$newletter = '1';
$blogusers = get_users( 'orderby=nicename' );
usort($blogusers, create_function('$a, $b', 'return strnatcasecmp($a->last_name, $b->last_name);'));
foreach ( $blogusers as $user ) {
if(!$user->last_name == "") {
$letter = substr($user->last_name,0,1);
$letter = strtoupper($letter);
if($letter !== $newletter) {
$newletter = $letter;
$result .='<div class="alphabetListing" id="al-' . $letter . '">' . $letter . '</div>';
}
$result .= $user->user_url;
$result .='<div class="authorListing"><a href="' . get_bloginfo('url') . '/author/' . $user->user_nicename . '">';
$result .= '' . esc_html( $user->last_name ) . ', ' . esc_html( $user->first_name ) . '';
$result .='</a></div>';
}
}
$result .='</div>';
return $result;
}
add_shortcode( 'author_list', 'author_list_func' );