-
Notifications
You must be signed in to change notification settings - Fork 2
/
templates.php
executable file
·230 lines (187 loc) · 6.48 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
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
<?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', 20 );
add_filter( 'archive_template' , 'wpcc_archive_template' );
add_filter( 'taxonomy_template' , 'wpcc_taxonomy_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 taxonomy-archive-template
function wpcc_taxonomy_archive_template( $template ){
if( is_tax('card_group') ){
$theme_files = array('archive-card.php','taxonomy-card_group.php') ;
$exists_in_theme = locate_template($theme_files, false);
if( $exists_in_theme == '' ){
return wpcc_PLUGIN_PATH . '/templates/archive-card.php';
}
}
return $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' ) && !is_admin() ){
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',
'wpcc-tithely-giving',
'wpcc-pco-giving',
);
// 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() {
global $post;
if( is_singular( 'card' ) || is_post_type_archive('card') || get_page_template_slug( get_the_ID() ) =='center_home.php' || is_tax('card_group') || has_shortcode( $post->post_content, 'wpcc') ){
wp_enqueue_style( 'wpcc-style', plugins_url( '/templates/wpcc_style.1.3.css', __FILE__ ) );
//if( get_option('wpcc_scroll_direction') =='horizontal' ) {
wp_enqueue_script( 'wpcc-scripts', plugins_url( '/templates/wpcc_script.1.3-min.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($status){
if( !is_user_logged_in() ){
return false;
}
return $status;
}
//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', 'wpcc_sort_cards' );
function wpcc_sort_cards( $query ) {
if ( $query->is_main_query() && !is_admin() ) {
if ( $query->is_post_type_archive('card') ) {
$query->set('orderby', 'menu_order');
$query->set('order', 'ASC');
}
}
}
// Don't show unlisted cards in Archive/Category queries
add_action( 'pre_get_posts', 'wpcc_exclude_unlisted_cards' );
function wpcc_exclude_unlisted_cards( $query ) {
if ( $query->is_main_query() && !is_admin() ) {
if ( $query->is_post_type_archive('card') ) {
// in case for some reason there's already a meta query set from other plugin
$meta_query = $query->get('meta_query')? : [];
// append yours
$meta_query[] = [
'relation' => 'OR',
array(
'key' => 'wpcc_unlisted',
'compare' => 'NOT EXISTS'
),
array(
'key' => 'wpcc_unlisted',
'value' => '0',
'compare' => '==',
),
];
$query->set('meta_query', $meta_query);
//echo '<pre>'; print_r( $query ); echo '</pre>';
}
}
}
//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');