-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
572 lines (464 loc) · 16.9 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
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
<?php
/**
* Load styles and javascript on front-end
*
* Styles:
* - Bootstrap
* - Theme
* - Font-Awesome
* - Flexslider
*
* Scripts:
* - Jquery
* - Bootstrap
* - FitVids
* - Flexslider
*
*/
if ( ! is_admin() ) {
function hc_load_styles() { // Load CSS
// Bootstrap
wp_register_style( 'bootstrap-styles', 'https://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css', array(), '3.1.1', 'all' );
wp_enqueue_style( 'bootstrap-styles' );
// Theme Styles
wp_register_style( 'theme-styles', get_template_directory_uri() . '/css/main.css', array(), '3.06.01', 'all' );
wp_enqueue_style( 'theme-styles' );
// Font Awesome
wp_register_style( 'font-awesome', 'https://maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css', array(), '4.1.0', 'all' );
wp_enqueue_style( 'font-awesome' );
//owl
wp_register_style( 'owl-style', get_template_directory_uri() . '/owl/owl-carousel/owl.carousel.css', array(), '3.06.01', 'all' );
wp_enqueue_style( 'owl-style' );
wp_register_style( 'owl-style-default', get_template_directory_uri() . '/owl/owl-carousel/owl.theme.css', array(), '3.1.1', 'all' );
wp_enqueue_style( 'owl-style-default' );
}
add_action( 'wp_enqueue_scripts', 'hc_load_styles', 11 );
function hc_load_scripts() { // Load Javascript
// Bootstrap
wp_register_script( 'bootstrap-scripts', 'https://netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js', array( 'jquery'), '3.1.1', true);
wp_enqueue_script( 'bootstrap-scripts' );
// Hellaclips JS
wp_register_script( 'hc-scripts', get_template_directory_uri() . '/js/hc-main.js', array( 'jquery'), '1.1', true);
wp_enqueue_script( 'hc-scripts' );
//owl JS
wp_register_script( 'owl-scripts', get_template_directory_uri() . '/owl/owl-carousel/owl.carousel.js', array( 'jquery'), '1.1', true);
wp_enqueue_script( 'owl-scripts' );
}
add_action( 'wp_enqueue_scripts', 'hc_load_scripts', 12 );
function hc_conditionaly_load_scripts() {
global $post;
if ( is_single($post->ID) ) {
if( in_category( 'video', $post->ID ) ) {
// Fitvids
wp_register_script( 'fitvids-script', get_template_directory_uri() . '/js/vendor/jquery.fitvids.js', array( 'jquery'), '1.1', true);
wp_enqueue_script( 'fitvids-script' );
}
if( in_category( 'Hella Hype', $post->ID ) ) {
// Flexslider
wp_register_script( 'flexslider-script', get_template_directory_uri() . '/js/vendor/jquery.flexslider-min.js', array( 'jquery'), '2.2.2', true);
wp_enqueue_script( 'flexslider-script' );
}
}
}
add_action( 'wp_enqueue_scripts', 'hc_conditionaly_load_scripts' );
}
/**
* Register bootstrap menu for theme
*
* Include walker nav for Bootstrap dropdown support
* https://github.com/twittem/wp-bootstrap-navwalker
*/
require_once('vendor/wp_bootstrap_navwalker.php');
if ( ! function_exists( 'hc_register_menu' ) ):
function hc_register_menu() {
register_nav_menu( 'primary', __( 'Primary navigation', 'Hellaclips' ) );
}
endif;
add_action( 'after_setup_theme', 'hc_register_menu' );
/**
* Add theme support:
* - Post Thumbnails
*/
if ( function_exists( 'add_theme_support' ) ) {
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 358, 215, array( 'center', 'center') );
// additional image sizes
// delete the next line if you do not need additional image sizes
// add_image_size( 'category-thumb', 300, 9999 ); //300 pixels wide (and unlimited height)
add_theme_support( 'post-formats', array( 'video', 'gallery', 'image' ) );
add_theme_support( 'html5', array( 'search-form' ) );
}
/**
* Register sidebars
*/
function hc_register_sidebars() {
if ( function_exists('register_sidebar') )
register_sidebar( // Primary
array(
'id' => 'primary',
'name' => __( 'Primary' ),
'description' => __( 'Home sidebar' ),
'before_widget' => '<div id="%1$s" class="hc-widget hc-trending clearfix">',
'after_widget' => '</div>',
'before_title' => '<h1 class="font-weight-light"><div class="sub-link">View <a href="' . get_category_link( 4 ) . '">All Videos</a></div>',
'after_title' => '</h1>'
)
);
if ( function_exists('register_sidebar') )
register_sidebar( // Video Single
array(
'id' => 'single',
'name' => __( 'Single' ),
'description' => __( 'Single sidebar' ),
'before_widget' => '<div id="%1$s" class="hc-widget hc-widget-light clearfix">',
'after_widget' => '</div>',
'before_title' => '<h1 class="hc-lead font-size-big font-weight-bold">',
'after_title' => '</h1>'
)
);
if ( function_exists('register_sidebar') )
register_sidebar( // Hella Hype Single
array(
'id' => 'hellahype',
'name' => __( 'Hellahype' ),
'description' => __( 'Hella Hype sidebar' ),
'before_widget' => '<div id="%1$s" class="hc-widget hc-widget-light clearfix">',
'after_widget' => '</div>',
'before_title' => '<h1 class="hc-lead font-size-big font-weight-bold">',
'after_title' => '</h1>'
)
);
if ( function_exists('register_sidebar') )
register_sidebar( // Gallery Single
array(
'id' => 'gallery',
'name' => __( 'gallery' ),
'description' => __( 'Gallery sidebar' ),
'before_widget' => '<div id="%1$s" class="hc-widget hc-widget-light clearfix">',
'after_widget' => '</div>',
'before_title' => '<h1 class="hc-lead font-size-big font-weight-bold">',
'after_title' => '</h1>'
)
);
if ( function_exists('register_sidebar') )
register_sidebar( // Sidekick - Next to single video
array(
'id' => 'sidekick',
'name' => __( 'Sidekick' ),
'description' => __( 'sidekick sidebar' ),
'before_widget' => '<div id="%1$s" class="hc-widget hc-widget-sidekick clearfix">',
'after_widget' => '</div>',
'before_title' => '<h1 class="hc-lead font-size-big font-weight-bold">',
'after_title' => '</h1>'
)
);
}
add_action( 'widgets_init', 'hc_register_sidebars' );
/**
* Custom login
*
* Loads custom login css for user auth pages
*/
function custom_login_css() {
wp_enqueue_style( '', get_template_directory_uri() . '/login-style.css' );
}
if ( ! has_action( 'login_enqueue_scripts', 'custom_login_css' ) ) {
add_action( 'login_enqueue_scripts', 'custom_login_css', 11 );
}
function hc_login_logo_url() {
return get_bloginfo( 'url' );
}
add_filter( 'login_headerurl', 'hc_login_logo_url' );
function hc_login_logo_url_title() {
return 'Your Site Name and Info';
}
add_filter( 'login_headertitle', 'hc_login_logo_url_title' );
function hc_login_head() {
remove_action('login_head', 'wp_shake_js', 12);
}
add_action('login_head', 'hc_login_head' );
/*
* DETECT USER-AGENTS
*/
function check_user_agent ( $type = NULL ) {
$user_agent = strtolower ( $_SERVER['HTTP_USER_AGENT'] );
if ( $type == 'bot' ) {
// matches popular bots
if ( preg_match ( "/googlebot|adsbot|yahooseeker|yahoobot|msnbot|watchmouse|pingdom\.com|feedfetcher-google/", $user_agent ) ) {
return true;
// watchmouse|pingdom\.com are "uptime services"
}
} else if ( $type == 'browser' ) {
// matches core browser types
if ( preg_match ( "/mozilla\/|opera\//", $user_agent ) ) {
return true;
}
} else if ( $type == 'mobile' ) {
// matches popular mobile devices that have small screens and/or touch inputs
// mobile devices have regional trends; some of these will have varying popularity in Europe, Asia, and America
// detailed demographics are unknown, and South America, the Pacific Islands, and Africa trends might not be represented, here
if ( preg_match ( "/phone|iphone|itouch|ipod|symbian|android|htc_|htc-|palmos|blackberry|opera mini|iemobile|windows ce|nokia|fennec|hiptop|kindle|mot |mot-|webos\/|samsung|sonyericsson|^sie-|nintendo/", $user_agent ) ) {
// these are the most common
return true;
} else if ( preg_match ( "/mobile|pda;|avantgo|eudoraweb|minimo|netfront|brew|teleca|lg;|lge |wap;| wap /", $user_agent ) ) {
// these are less common, and might not be worth checking
return true;
}
}
return false;
}
/**
* Word limitter
**/
function string_limit_words($string, $word_limit)
{
$words = explode(' ', $string, ($word_limit + 1));
if(count($words) > $word_limit)
array_pop($words);
return implode(' ', $words);
}
/**
* Custom recent posts
*
* Number of posts
* Category ID
*/
function get_recent_posts( $num_posts, $cat_id ) {
$args = array(
'posts_per_page' => $num_posts,
'no_found_rows' => true,
'post_status' => 'publish',
'ignore_sticky_posts' => true,
'cat' => $cat_id
);
// The Query
$the_query = new WP_Query( $args );
// The Loop
if ( $the_query->have_posts() ) {
echo '<ul>';
while ( $the_query->have_posts() ) {
$the_query->the_post();
echo '<li><a href="' . get_the_permalink() . '" target="_top" title="' . get_the_title() . '">' . get_the_title() . '</a></li>';
}
echo '</ul>';
} else {
// no posts found
}
/* Restore original Post Data */
wp_reset_postdata();
}
/**
* Custom gallery
*
* Flexslider friendly
*/
function parse_gallery_shortcode($atts) {
global $post;
if ( ! empty( $atts['ids'] ) ) {
// 'ids' is explicitly ordered, unless you specify otherwise.
if ( empty( $atts['orderby'] ) ) {
$atts['orderby'] = 'post__in';
$atts['include'] = $atts['ids'];
}
}
extract(shortcode_atts(array(
'orderby' => 'menu_order ASC, ID ASC',
'include' => '',
'id' => $post->ID,
'itemtag' => 'dl',
'icontag' => 'dt',
'captiontag' => 'dd',
'columns' => 3,
'size' => 'large',
'link' => 'file'
), $atts));
$args = array(
'post_type' => 'attachment',
'post_status' => 'inherit',
'post_mime_type' => 'image',
'exclude' => get_post_thumbnail_id(),
'orderby' => $orderby
);
if ( !empty($include) ) {
$args['include'] = $include;
} else {
$args['post_parent'] = $id;
$args['numberposts'] = -1;
}
$images = get_posts($args);
$gallery = '<ul class="slides">';
foreach ( $images as $image ) {
$caption = $image->post_excerpt;
$description = $image->post_content;
if($description == '') $description = $image->post_title;
$image_alt = get_post_meta($image->ID,'_wp_attachment_image_alt', true);
// render your gallery here
$gallery .= '<li>' . wp_get_attachment_image($image->ID, $size) . '</li>';
}
$gallery .= '</ul>';
echo $gallery;
}
remove_shortcode('gallery');
add_shortcode('gallery', 'parse_gallery_shortcode');
/**
* Remove gallery & images
*
* Removes gallery from the_content()
*/
function strip_shortcode_gallery( $content ) {
preg_match_all( '/'. get_shortcode_regex() .'/s', $content, $matches, PREG_SET_ORDER );
if ( ! empty( $matches ) ) {
foreach ( $matches as $shortcode ) {
if ( 'gallery' === $shortcode[2] ) {
$pos = strpos( $content, $shortcode[0] );
if ($pos !== false)
return substr_replace( $content, '', $pos, strlen($shortcode[0]) );
}
}
}
// $content = preg_replace('/<img[^>]+\>/i', '', $content);
return $content;
}
/**
* Calculate post views
*
* Displays view count based on wpp and custom post_views
*/
function get_post_views() {
$tptnviews = get_tptn_post_count_only( get_the_ID(), 'total' );
$hcviews = get_post_meta( get_the_ID(), 'post_views', true);
$newpost = 100;
if( $hcviews > $tptnviews) {
return $hcviews + $tptnviews + rand(320, 500);
}elseif ($tptnviews >= $hcviews) {
return $tptnviews;
}elseif ($tptnviews < $newpost) {
return $tptnviews + 97;
}else{ return 801; }
}
add_filter( 'check_password', 'check_sha1_password', 10, 4 );
/**
* Check if a user has a SHA1 password hash,
* allows login if password hashes match, then
* updates password hash to wp format.
*
* Hooks into check_password filter, mostly
* copied from md5 upgrade function with
* pluggable.php/wp_check_password
*
* @param string $check
* @param string $password
* @param string $hash
* @param string $user_id
* @return results of sha1 hash comparison, or $check if $password is not a SHA1 hash
*/
function check_sha1_password( $check, $password, $hash, $user_id ) {
if( is_sha1( $hash ) ) {
$check = ( $hash == sha1( $password ) );
if ( $check && $user_id ) {
// Rehash using new proper WP hash
wp_set_password( $password, $user_id );
$hash = wp_hash_password( $password );
// Allow login
return true;
} else {
// SHA1 hash in db, but SHA1 has of provided $password did not match. Do not allow login.
// echo $password . ' did not match ' . $check;
return false;
}
}
// Not SHA1 password, so return what was passed
return $check;
}
/**
* Check if provided string is a SHA1 hash
*/
function is_sha1( $str ) {
return ( bool ) preg_match( '/^[0-9a-f]{40}$/i', $str );
}
/**
*change http tp https in all iframes
*
*/
function add_secure_video_options($html) {
if (strpos($html, "<iframe" ) !== false) {
$search = array('src="http://www.','src="http://');
$replace = array('src="https://www.','src="https://');
$html = str_replace($search, $replace, $html);
return $html;
} else {
return $html;
}
}
add_filter('the_content', 'add_secure_video_options', 10);
/**
* get more in custom fields drop down
*/
function increase_postmeta_form_limit() {
return 120;
}
add_filter('postmeta_form_limit', 'increase_postmeta_form_limit');
/**
*Allow contributers to upload media
*/
if ( current_user_can('contributor') && !current_user_can('upload_files') )
add_action('admin_init', 'allow_contributor_uploads');
function allow_contributor_uploads() {
$contributor = get_role('contributor');
$contributor->add_cap('upload_files');
}
add_action('set_current_user', 'cc_hide_admin_bar');
function cc_hide_admin_bar() {
if (!current_user_can('edit_posts')) {
show_admin_bar(false);
}
}
/**
* Load More
*/
function pbd_alp_init() {
global $wp_query;
// Add code to index pages.
if( !is_singular() ) {
// Queue JS
wp_register_script( 'pbd-alp-load-posts', get_template_directory_uri() . '/js/load-posts.js', array('jquery'),'1.0', true);
wp_enqueue_script( 'pbd-alp-load-posts' );
// What page are we on? And what is the pages limit?
$max = $wp_query->max_num_pages;
$paged = ( get_query_var('paged') > 1 ) ? get_query_var('paged') : 1;
// Add some parameters for the JS.
wp_localize_script(
'pbd-alp-load-posts',
'pbd_alp',
array(
'startPage' => $paged,
'maxPages' => $max,
'nextLink' => next_posts($max, false)
)
);
}
}
add_action('template_redirect', 'pbd_alp_init');
/**
* app functions
*/
// include Write to functionality
include('php/xml_write_test_function.php');
include('php/app_options.php');
// Register Custom Status
function app_post_status() {
$argsies = array(
'label' => 'On App',
'label_count' => 'On App (%s)',
'public' => true,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'exclude_from_search' => false,
);
register_post_status( 'AppPublished', $argsies );
}
add_action( 'init', 'app_post_status', 0 );
add_theme_support( 'featured-content', array(
'featured_content_filter' => 'hellaclips_get_featured_content',
));
?>