-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
66 lines (55 loc) · 1.58 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
<?php
/**
* Custom excerpt
*
* @param $post_excerpt
*
* @return mixed|string
*/
function easy_event_the_excerpt( $post_excerpt ) {
$post_id = get_the_ID();
$post = get_post( $post_id );
$excerpt_temp = $post->post_excerpt;
if ( $excerpt_temp == '' ) {
$excerpt_temp = get_post_meta( $post_id, 'easy_event_description', true );
}
if ( $excerpt_temp == '' ) {
$excerpt_temp = strip_tags( $post->post_content );
}
$excerpt_temp = strip_shortcodes( $excerpt_temp );
/**
* Excerpt length
*/
$excerpt_length = get_option( 'easy_event_excerpt_length' );
if ( $excerpt_length == false ) {
$excerpt_length = 250;
}
$excerpt_length += 5;
if ( mb_strlen( $excerpt_temp ) > $excerpt_length ) {
$subex = mb_substr( $excerpt_temp, 0, $excerpt_length - 5 );
$exwords = explode( ' ', $subex );
$excut = - ( mb_strlen( $exwords[ count( $exwords ) - 1 ] ) );
if ( $excut < 0 ) {
return mb_substr( $subex, 0, $excut ) . '[...]';;
} else {
return $subex . '[...]';
}
} else {
return $excerpt_temp;
}
}
add_filter( 'the_excerpt', 'easy_event_the_excerpt' );
function easy_event_get_my_time() {
$gmt_offset = intval( get_option( 'gmt_offset' ) );
$time_zones = $timezone_identifiers = DateTimeZone::listIdentifiers();
foreach ( $time_zones as $time_zone ) {
$date = new DateTime( 'now', new DateTimeZone( $time_zone ) );
$offset_in_hours = $date->getOffset() / 60 / 60;
if ( ! is_null( $gmt_offset ) && $gmt_offset == $offset_in_hours ) {
date_default_timezone_set( $time_zone );
break;
}
}
$my_time = date_create();
return $my_time;
}