-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
160 lines (135 loc) · 5.51 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
<?php
/* #1: Include core theme files and directories
---------------------------------------------------------------------------*/
define( 'CENT_SLUG', 'centauri' );
define( 'CENT_PATH', get_template_directory() );
define( 'CENT_URL', get_template_directory_uri() );
define( 'CENT_MODULE_PATH', CENT_PATH . '/modules' );
define( 'CENT_MODULE_URL', CENT_URL . '/modules' );
define( 'CENT_TEMPLATE_PATH', CENT_PATH . '/templates' );
define( 'CENT_TEMPLATE_URL', CENT_URL . '/templates' );
define( 'CENT_QUERY_PATH', CENT_TEMPLATE_PATH . '/queries' );
define( 'CENT_QUERY_URL', CENT_TEMPLATE_URL . '/queries' );
foreach ( glob( CENT_MODULE_PATH . '/*.php' ) as $filename ) {
require_once( $filename );
}
/* #2: Initialize the theme options
---------------------------------------------------------------------------*/
add_action( 'after_setup_theme', 'centalpha_setup' );
function centalpha_setup(){
centalpha_theme_support();
centalpha_nav_menus();
}
function centalpha_theme_support(){
add_theme_support( 'title-tag' );
add_theme_support( 'html5' );
add_theme_support( 'automatic-feed-links' );
add_theme_support( 'post-thumbnails' );
}
function centalpha_nav_menus(){
register_nav_menus(
array( 'main-menu' => __( 'Main Menu', 'laniakea' ) )
);
}
/* #3: Include core script files
---------------------------------------------------------------------------*/
add_action( 'wp_enqueue_scripts', 'centalpha_load_scripts' );
function centalpha_load_scripts(){
wp_deregister_script('jquery');
wp_enqueue_script( 'jquery' , '/wp-content/themes/centauri-alpha/scripts/jquery-3.2.1.min.js' );
wp_enqueue_script( 'tiny_mce' );
wp_enqueue_script( 'pym' , '/wp-content/themes/centauri-alpha/scripts/pym.v1.min.js' );
wp_enqueue_script( 'ca-typekit' , 'https://use.typekit.net/cta0jll.js' );
wp_add_inline_script( 'ca-typekit' , 'try{Typekit.load({ async: true });}catch(e){}' );
wp_enqueue_script( 'fontawesome' , 'https://use.fontawesome.com/4ac2a9e804.js' );
}
/* #4: Comment-related functions
---------------------------------------------------------------------------*/
add_action( 'comment_form_before', 'centalpha_enqueue_comment_reply_script' );
function centalpha_enqueue_comment_reply_script(){
if ( get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
}
function centalpha_custom_pings( $comment ){
$GLOBALS['comment'] = $comment;
?>
<li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>"><?php echo comment_author_link(); ?></li>
<?php
}
add_filter( 'get_comments_number', 'centalpha_comments_number' );
function centalpha_comments_number( $count ){
if ( !is_admin() ) {
global $id;
$comments_by_type = &separate_comments( get_comments( 'status=approve&post_id=' . $id ) );
return count( $comments_by_type['comment'] );
} else {
return $count;
}
}
/* #5: Dynamic loading of index page posts
---------------------------------------------------------------------------*/
add_action( 'wp_ajax_nopriv_ajax_pagination', 'centalpha_load_more_index_posts' );
add_action( 'wp_ajax_ajax_pagination', 'centalpha_load_more_index_posts' );
function centalpha_load_more_index_posts() {
//query posts
$query_vars = json_decode( stripslashes( $_POST['query_vars'] ), true );
$query_vars['paged'] = $_POST['page'];
$posts = new WP_Query( $query_vars );
$GLOBALS['wp_query'] = $posts;
if( $posts->have_posts() ) {
while ( $posts->have_posts() ) {
$posts->the_post();
get_template_part( 'templates/entry/entry' , 'index' );
}
}
die();
}
function centalpha_localize_ajax_script($args){
wp_enqueue_script( 'ajax-pagination', get_stylesheet_directory_uri() . '/scripts/ajax-index.js', array( 'jquery' ) , false, true );
wp_localize_script( 'ajax-pagination', 'ajaxpagination', array(
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'query_vars' => json_encode( $args )
));
}
add_action('wp_print_footer_scripts', 'centalpha_localize_ajax_script');
/* #6: Simple Random Functions
---------------------------------------------------------------------------*/
function centalpha_random_number( $floor, $ceil ){
$rand = rand( $floor, $ceil);
return $rand;
}
/* #7: Determine time between two dates
===============================================================*/
function centalpha_determine_time_difference($target){
$current = time();
$target = date_create_from_format( 'U', $target );
$current = date_create_from_format( 'U', $current );
$current->setTimeZone( new DateTimeZone( 'America/Los_Angeles' ) );
$difference = date_diff( $current, $target );
return $difference;
}
function centalpha_populate_time_difference($d){
$ret = [];
// find the first time value and return that
if ( $d->y !== 0 ) {
$ret[] = $d->y;
$ret[0] < 2 ? $ret[] = ' year' : $ret[] = ' years';
} elseif ( $d->m !== 0 ) {
$ret[0][] = $d->m;
$ret[0] < 2 ? $ret[] = ' month' : $ret[] = ' months';
} elseif ( $d->d !== 0 ) {
$ret[] = $d->d;
$ret[0] < 2 ? $ret[] = ' day' : $ret[] = ' days';
} elseif ( $d->h !== 0 ) {
$ret[] = $d->h;
$ret[0] < 2 ? $ret[] = ' hour' : $ret[] = ' hours';
} elseif ( $d->i !== 0 ) {
$ret[] = $d->i;
$ret[0] < 2 ? $ret[] = ' minute' : $ret[] = ' minutes';
} elseif ( $d->s !== 0 ) {
$ret[] = $d->s;
$ret[0] < 2 ? $ret[] = ' second' : $ret[] = ' seconds';
}
return $ret;
}