forked from jordesign/wp-church-center
-
Notifications
You must be signed in to change notification settings - Fork 0
/
templates.php
executable file
·179 lines (147 loc) · 5.05 KB
/
templates.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
<?php
define( 'wpcc_PLUGIN_PATH', dirname(__FILE__) );
//Use Filters to direct the 'card' CPT to use the templates in our plugin
add_filter( 'single_template' , 'wpcc_single_template' );
add_filter( 'archive_template' , 'wpcc_archive_template' );
//route single-template
function wpcc_single_template( $single_template ){
global $post;
$found = locate_template('single-card.php', false) ;
if( $post->post_type == 'card' && $found == '' ){
$single_template = wpcc_PLUGIN_PATH .'/templates/single-card.php';
}
return $single_template;
}
//route archive-template
function wpcc_archive_template( $template ){
if( is_post_type_archive('card') ){
$theme_files = array('archive-card.php') ;
$exists_in_theme = locate_template($theme_files, false);
if( $exists_in_theme == '' ){
return wpcc_PLUGIN_PATH . '/templates/archive-card.php';
}
}
return $template;
}
// De-Queue all Stylesheets
function wpcc_remove_default_styles (){
if ( get_post_type() == 'card' || is_post_type_archive('card') || is_page_template('center_home.php') ){
// get all styles data
global $wp_styles;
$keep_styles = array(
'admin-bar', //Always show the admin bar
'nf-display', //Ninja Forms
'wp-mediaelement' //MediaElement
);
// loop over all of the registered scripts
foreach ( $wp_styles->registered as $handle => $data )
{
if( !in_array ($handle, $keep_styles ) ){
// remove it
wp_deregister_style($handle);
wp_dequeue_style($handle);
}
}
}
}
if( 1 == get_option( 'wpcc_disable_styles' ) ){
add_action('wp_print_scripts', 'wpcc_remove_default_styles', 100);
}
// De-Queue all Scripts
function wpcc_remove_default_scripts (){
if ( get_post_type() == 'card' || is_post_type_archive('card') || is_page_template('center_home.php' ) ){
// get all styles data
global $wp_scripts;
$keep_scripts = array(
'wpcc-scripts',
'jquery' ,
'nf-front-end-deps' ,
'nf-front-end' ,
'admin-bar' ,
'masonry',
'wp-mediaelement'
);
// loop over all of the registered scripts
foreach ( $wp_scripts->registered as $handle => $data )
{
if( !in_array ($handle, $keep_scripts ) ){
// remove it
//wp_deregister_script($handle);
wp_dequeue_script($handle);
}
}
}
}
if( 1 == get_option( 'wpcc_disable_scripts' ) && !is_admin() ){
add_action('wp_print_scripts', 'wpcc_remove_default_scripts', 100);
}
//Now enqueue styles we want
function wpcc_add_styles() {
if( is_singular( 'card' ) || is_post_type_archive('card') || get_page_template_slug( get_the_ID() ) =='center_home.php' ){
wp_enqueue_style( 'wpcc-style', plugins_url( '/templates/wpcc_style.1.2.1.css', __FILE__ ) );
//if( get_option('wpcc_scroll_direction') =='horizontal' ) {
wp_enqueue_script( 'wpcc-scripts', plugins_url( '/templates/wpcc_script-min.1.2.1.js', __FILE__ ), array( 'jquery' ) );
//}
if( get_option('wpcc_layout') =='small-card' ) {
// Pull Masonry from the core of WordPress
wp_enqueue_script( 'masonry' );
}
}
}
add_action('wp_enqueue_scripts', 'wpcc_add_styles', 1000);
//Image Sizes
add_image_size( 'card_image', 600, 1200, false );
add_image_size( 'card_hero_image', 1200, 1200, false );
//remove automated WP title
add_action('template_redirect', 'wpcc_remove_title');
function wpcc_remove_title()
{
if ( get_post_type() == 'card' || is_post_type_archive('card') || is_page_template('center_home.php' ) ){
remove_action( 'wp_head', '_wp_render_title_tag', 1 );
}
}
//Definitely Hide admin bar when not logged in
add_filter( 'show_admin_bar', 'wpct_hide_adminbar' );
function wpct_hide_adminbar(){
if( !is_user_logged_in() ){
return false;
}
return true;
}
//Function to check if certain plugins are active
function active( $plugin ) {
$network_active = false;
if ( is_multisite() ) {
$plugins = get_site_option( 'active_sitewide_plugins' );
if ( isset( $plugins[$plugin] ) ) {
$network_active = true;
}
}
return in_array( $plugin, get_option( 'active_plugins' ) ) || $network_active;
}
//Change sort order of post type archive
add_action( 'pre_get_posts', 'cd_sort_staff' );
function cd_sort_staff( $query ) {
if ( $query->is_main_query() && !is_admin() ) {
if ( $query->is_tax() || $query->is_post_type_archive('card') ) {
$query->set('orderby', 'menu_order');
$query->set('order', 'ASC');
}
}
}
//Add an extra class for theming
/**
* Adds classes to the array of body classes.
*
* @uses body_class() filter
*/
function wpcc_body_classes( $classes ) {
$classes[] = 'wpcc_' . get_option('wpcc_theme');
return $classes;
}
add_filter( 'body_class', 'wpcc_body_classes' );
//Include editor.min.css even if there is no text editor
function wpcc_add_admin_editor_styles() {
wp_register_style($handle = 'wpcc-theme-admin-styles', $src = site_url() . '/wp-includes/css/editor.min.css', $deps = array(), $ver = '1.0.0', $media = 'all');
wp_enqueue_style('wpcc-theme-admin-styles');}
add_action('admin_print_styles', 'wpcc_add_admin_editor_styles');