1
|
<?php
|
2
|
/*
|
3
|
Plugin name: ACERT Custom
|
4
|
Description: Custom functionality for ACERT.
|
5
|
*/
|
6
|
|
7
|
#Function to create shortcode for Blog Feature
|
8
|
if ( ! function_exists( 'woo_shortcode_post_blog_feature' ) ) :
|
9
|
function woo_shortcode_post_blog_feature ( $atts ) {
|
10
|
$defaults = array(
|
11
|
'sep' => ', ',
|
12
|
'before' => '',
|
13
|
'after' => '',
|
14
|
'taxonomy' => 'blog_feature'
|
15
|
);
|
16
|
$atts = shortcode_atts( $defaults, $atts );
|
17
|
|
18
|
$atts = array_map( 'wp_kses_post', $atts );
|
19
|
|
20
|
$terms = get_the_terms( get_the_ID(), esc_html( $atts['taxonomy'] ) );
|
21
|
$cats = '';
|
22
|
|
23
|
if ( is_array( $terms ) && 0 < count( $terms ) ) {
|
24
|
$links_array = array();
|
25
|
foreach ( $terms as $k => $v ) {
|
26
|
$term_name = get_term_field( 'name', $v->term_id, $atts['taxonomy'] );
|
27
|
$links_array[] = '<a href="' . esc_url( get_term_link( $v, $atts['taxonomy'] ) ) . '" title="' . esc_attr( sprintf( __( 'View all items in %s', 'woothemes' ), $term_name ) ) . '">' . esc_html( $term_name ) . '</a>';
|
28
|
}
|
29
|
|
30
|
$cats = join( $atts['sep'], $links_array );
|
31
|
}
|
32
|
|
33
|
$output = sprintf('<span class="categories">%2$s%1$s%3$s</span> ', $cats, $atts['before'], $atts['after']);
|
34
|
return apply_filters( 'woo_shortcode_post_categories', $output, $atts );
|
35
|
} // End woo_shortcode_post_categories()
|
36
|
endif;
|
37
|
|
38
|
add_shortcode( 'blog_feature', 'woo_shortcode_post_blog_feature' );
|
39
|
|
40
|
|
41
|
function cac_acert_new_projects_fields( $fields ) {
|
42
|
$fields['faculty'] = array(
|
43
|
'name' => __( 'Faculty', 'projects' ),
|
44
|
'description' => __( 'Enter faculty for this project.', 'projects' ),
|
45
|
'type' => 'text',
|
46
|
'default' => '',
|
47
|
'section' => 'info'
|
48
|
);
|
49
|
return $fields;
|
50
|
}
|
51
|
add_filter( 'projects_custom_fields', 'cac_acert_new_projects_fields' );
|
52
|
|
53
|
|
54
|
|
55
|
function cac_acert_display_new_projects_fields() {
|
56
|
global $post;
|
57
|
$faculty = esc_attr( get_post_meta( $post->ID, '_faculty', true ) );
|
58
|
|
59
|
echo '<p>' . __( 'Faculty: ', 'projects' ) . $faculty . '</p>';
|
60
|
|
61
|
}
|
62
|
add_action( 'projects_after_loop_item', 'cac_acert_display_new_projects_fields', 10 );
|
63
|
|
64
|
|
65
|
// add tag support to project pages
|
66
|
function cac_acert_tags_support_all() {
|
67
|
register_taxonomy_for_object_type('post_tag', 'project');
|
68
|
}
|
69
|
|
70
|
// add category support to project pages
|
71
|
function cac_acert_category_support_all() {
|
72
|
register_taxonomy_for_object_type('category', 'project');
|
73
|
}
|
74
|
|
75
|
// ensure all tags are included in queries
|
76
|
function cac_acert_tags_support_query($wp_query) {
|
77
|
if ($wp_query->get('tag')) $wp_query->set('post_type', 'any');
|
78
|
}
|
79
|
|
80
|
// tag hooks
|
81
|
add_action('init', 'cac_acert_tags_support_all');
|
82
|
add_action('init', 'cac_acert_category_support_all');
|
83
|
add_action('pre_get_posts', 'cac_acert_tags_support_query');
|
84
|
|
85
|
|
86
|
|
87
|
//Add post categories and post tags to Events Manager
|
88
|
function cac_acert_my_em_own_taxonomy_register(){
|
89
|
register_taxonomy_for_object_type('category',EM_POST_TYPE_EVENT);
|
90
|
register_taxonomy_for_object_type('category',EM_POST_TYPE_LOCATION);
|
91
|
register_taxonomy_for_object_type('post_tag',EM_POST_TYPE_EVENT);
|
92
|
register_taxonomy_for_object_type('post_tag',EM_POST_TYPE_LOCATION);
|
93
|
//Add Discipline taxonomy to Events Manager
|
94
|
register_taxonomy_for_object_type('discipline',EM_POST_TYPE_EVENT);
|
95
|
}
|
96
|
add_action('init','cac_acert_my_em_own_taxonomy_register',100);
|
97
|
|
98
|
|
99
|
|
100
|
function cac_acert_blog_feature_init() {
|
101
|
// create a new taxonomy for blog_feature
|
102
|
register_taxonomy(
|
103
|
'blog_feature',
|
104
|
'post',
|
105
|
array(
|
106
|
// Hierarchical taxonomy (like categories)
|
107
|
'hierarchical' => true,
|
108
|
'label' => __( 'Blog Feature' ),
|
109
|
'rewrite' => array( 'slug' => 'BlogFeature'),
|
110
|
)
|
111
|
);
|
112
|
}
|
113
|
add_action( 'init', 'cac_acert_blog_feature_init' );
|
114
|
|
115
|
|
116
|
|
117
|
|
118
|
|
119
|
// function cac_acert_project_category_init() {
|
120
|
// // create a new taxonomy for Events Manager Content Category
|
121
|
// register_taxonomy(
|
122
|
// 'project_content_category',
|
123
|
// project,
|
124
|
// array(
|
125
|
// // Hierarchical taxonomy (like categories)
|
126
|
// 'hierarchical' => true,
|
127
|
// 'label' => __( 'Project Content Category' ),
|
128
|
// 'rewrite' => array( 'slug' => 'Project Content Category'),
|
129
|
// )
|
130
|
// );
|
131
|
// }
|
132
|
// add_action( 'init', 'cac_acert_project_category_init' );
|
133
|
|
134
|
// function cac_acert_project_department_init() {
|
135
|
// // create a new taxonomy for Project departments
|
136
|
// register_taxonomy(
|
137
|
// 'project_department_category',
|
138
|
// project,
|
139
|
// array(
|
140
|
// // Hierarchical taxonomy (like categories)
|
141
|
// 'hierarchical' => false,
|
142
|
// 'label' => __( 'Department' ),
|
143
|
// 'rewrite' => array( 'slug' => 'Department'),
|
144
|
// )
|
145
|
// );
|
146
|
// }
|
147
|
// add_action( 'init', 'cac_acert_project_department_init' );
|
148
|
|
149
|
|
150
|
// Custom shortcode function for coauthors post links
|
151
|
|
152
|
function cac_acert_coauthor_links_shortcode( ) {
|
153
|
|
154
|
if ( function_exists( 'coauthors_posts_links' ) ) {
|
155
|
$author = coauthors_posts_links( null, null, null, null, false );
|
156
|
} else {
|
157
|
$author = '[post_author_posts_link]';
|
158
|
}
|
159
|
return $author;
|
160
|
}
|
161
|
|
162
|
add_shortcode('author_links','cac_acert_coauthor_links_shortcode');
|
163
|
|
164
|
// Define woo_post_meta if not set in filter yet
|
165
|
|
166
|
if ( ! function_exists( 'woo_post_meta' ) ) :
|
167
|
function woo_post_meta() {
|
168
|
|
169
|
if ( is_page() && !( is_page_template( 'template-blog.php' ) || is_page_template( 'template-magazine.php' ) ) ) {
|
170
|
return;
|
171
|
}
|
172
|
|
173
|
$post_info = '<span class="small">' . __( 'By', 'woothemes' ) . '</span> [author_links] <span class="small">' . _x( 'on', 'post datetime', 'woothemes' ) . '</span> [post_date] <span class="small">' . __( 'in', 'woothemes' ) . '</span> [post_categories before=""] ';
|
174
|
printf( '<div class="post-meta">%s</div>' . "\n", apply_filters( 'woo_filter_post_meta', $post_info ) );
|
175
|
|
176
|
} // End woo_post_meta()
|
177
|
endif;
|
178
|
|
179
|
// Replace Single Post Author (in theme-actions.php)
|
180
|
if ( ! function_exists( 'woo_author_box' ) ) :
|
181
|
function woo_author_box () {
|
182
|
global $post;
|
183
|
$author_id=$post->post_author;
|
184
|
|
185
|
// Adjust the arrow, if is_rtl().
|
186
|
$arrow = '→';
|
187
|
if ( is_rtl() ) $arrow = '←';
|
188
|
|
189
|
?>
|
190
|
<?php foreach( get_coauthors() as $coauthor ): ?>
|
191
|
<aside id="post-author">
|
192
|
<div class="profile-image"> <?php echo coauthors_get_avatar( $coauthor, '80', '', false ); ?></div>
|
193
|
<div class="profile-content">
|
194
|
<h4><?php echo 'About '.$coauthor->display_name ?></h4>
|
195
|
<?php echo $coauthor->description; ?>
|
196
|
<?php if ( is_singular() ) : ?>
|
197
|
<div class="profile-link">
|
198
|
<a href="<?php echo get_author_posts_url( $coauthor->ID, $coauthor->user_nicename ); ?>">
|
199
|
<?php echo ('View all posts by: ' . $coauthor->display_name . '<span class="meta-nav">' . $arrow . '</span>' ); ?>
|
200
|
</a>
|
201
|
</div><!--#profile-link-->
|
202
|
<?php endif; ?>
|
203
|
</div>
|
204
|
<div class="fix"></div>
|
205
|
</aside>
|
206
|
<?php endforeach;
|
207
|
} // End woo_author_box()
|
208
|
endif;
|
209
|
|
210
|
// Replace Archive Titles conditions
|
211
|
|
212
|
if ( ! function_exists( 'woo_archive_title' ) ) :
|
213
|
function woo_archive_title ( $before = '', $after = '', $echo = true ) {
|
214
|
|
215
|
global $wp_query;
|
216
|
|
217
|
if ( is_category() || is_tag() || is_tax() ) {
|
218
|
|
219
|
$taxonomy_obj = $wp_query->get_queried_object();
|
220
|
$term_id = $taxonomy_obj->term_id;
|
221
|
$taxonomy_short_name = $taxonomy_obj->taxonomy;
|
222
|
|
223
|
$taxonomy_raw_obj = get_taxonomy( $taxonomy_short_name );
|
224
|
|
225
|
} // End IF Statement
|
226
|
|
227
|
$title = '';
|
228
|
$delimiter = ' | ';
|
229
|
$date_format = get_option( 'date_format' );
|
230
|
|
231
|
// Category Archive
|
232
|
if ( is_category() ) {
|
233
|
|
234
|
$title = '<span class="fl cat">' . __( 'Archive', 'woothemes' ) . $delimiter . single_cat_title( '', false ) . '</span> <span class="fr catrss">';
|
235
|
$cat_obj = $wp_query->get_queried_object();
|
236
|
$cat_id = $cat_obj->cat_ID;
|
237
|
$title .= '<a href="' . get_term_feed_link( $term_id, $taxonomy_short_name, '' ) . '" class="icon-rss icon-large" ></a></span>';
|
238
|
|
239
|
$has_title = true;
|
240
|
}
|
241
|
|
242
|
// Day Archive
|
243
|
if ( is_day() ) {
|
244
|
|
245
|
$title = __( 'Archive', 'woothemes' ) . $delimiter . get_the_time( $date_format );
|
246
|
}
|
247
|
|
248
|
// Month Archive
|
249
|
if ( is_month() ) {
|
250
|
|
251
|
$date_format = apply_filters( 'woo_archive_title_date_format', 'F, Y' );
|
252
|
$title = __( 'Archive', 'woothemes' ) . $delimiter . get_the_time( $date_format );
|
253
|
}
|
254
|
|
255
|
// Year Archive
|
256
|
if ( is_year() ) {
|
257
|
|
258
|
$date_format = apply_filters( 'woo_archive_title_date_format', 'Y' );
|
259
|
$title = __( 'Archive', 'woothemes' ) . $delimiter . get_the_time( $date_format );
|
260
|
}
|
261
|
|
262
|
// Author Archive
|
263
|
if ( is_author() ) {
|
264
|
|
265
|
$title = __( 'Author Archive', 'woothemes' ) . $delimiter . coauthors( null, null, null, null, true );
|
266
|
}
|
267
|
|
268
|
// Tag Archive
|
269
|
if ( is_tag() ) {
|
270
|
|
271
|
$title = __( 'Tag Archives', 'woothemes' ) . $delimiter . single_tag_title( '', false );
|
272
|
}
|
273
|
|
274
|
// Post Type Archive
|
275
|
if ( function_exists( 'is_post_type_archive' ) && is_post_type_archive() ) {
|
276
|
|
277
|
/* Get the post type object. */
|
278
|
$post_type_object = get_post_type_object( get_query_var( 'post_type' ) );
|
279
|
|
280
|
$title = $post_type_object->labels->name . ' ' . __( 'Archive', 'woothemes' );
|
281
|
}
|
282
|
|
283
|
// Post Format Archive
|
284
|
if ( get_query_var( 'taxonomy' ) == 'post_format' ) {
|
285
|
|
286
|
$post_format = str_replace( 'post-format-', '', get_query_var( 'post_format' ) );
|
287
|
|
288
|
$title = get_post_format_string( $post_format ) . ' ' . __( ' Archives', 'woothemes' );
|
289
|
}
|
290
|
|
291
|
// General Taxonomy Archive
|
292
|
if ( is_tax() ) {
|
293
|
|
294
|
$title = sprintf( __( '%1$s Archives: %2$s', 'woothemes' ), $taxonomy_raw_obj->labels->name, $taxonomy_obj->name );
|
295
|
|
296
|
}
|
297
|
|
298
|
if ( strlen($title) == 0 )
|
299
|
return;
|
300
|
|
301
|
$title = $before . $title . $after;
|
302
|
|
303
|
// Allow for external filters to manipulate the title value.
|
304
|
$title = apply_filters( 'woo_archive_title', $title, $before, $after );
|
305
|
|
306
|
if ( $echo )
|
307
|
echo $title;
|
308
|
else
|
309
|
return $title;
|
310
|
|
311
|
} // End woo_archive_title()
|
312
|
endif;
|
313
|
|
314
|
// Add Custom Post Type Support args
|
315
|
|
316
|
add_action('init', 'cac_acert_custom_post_type_support');
|
317
|
function cac_acert_custom_post_type_support() {
|
318
|
add_post_type_support( 'portfolio', array('publicize','author') );
|
319
|
/* add_post_type_support( 'product', array('publicize','author') ); -- if adding coauthor box to woocommerce */
|
320
|
|
321
|
}
|
322
|
|
323
|
//Add blog header to posts with blog feature and date
|
324
|
function cac_acert_insert_blog_header(){
|
325
|
if(get_post_type() == 'post'){
|
326
|
echo '<p class="blog_header">';
|
327
|
echo do_shortcode('[blog_feature]');
|
328
|
echo " | ";
|
329
|
echo get_the_date();
|
330
|
echo '</p>';
|
331
|
}}
|
332
|
add_action('woo_post_inside_before','cac_acert_insert_blog_header',1);
|
333
|
|
334
|
|
335
|
function cac_acert_discipline_init() {
|
336
|
// create a new taxonomy for Discipline
|
337
|
register_taxonomy(
|
338
|
'discipline',
|
339
|
'post',
|
340
|
array(
|
341
|
// Hierarchical taxonomy (like categories)
|
342
|
'hierarchical' => true,
|
343
|
'label' => __( 'Discipline' ),
|
344
|
'rewrite' => array( 'slug' => 'Discipline'),
|
345
|
)
|
346
|
);
|
347
|
}
|
348
|
add_action( 'init', 'cac_acert_discipline_init' );
|
349
|
|
350
|
#Function to create shortcode for Discipline
|
351
|
if ( ! function_exists( 'woo_shortcode_post_discipline' ) ) :
|
352
|
function woo_shortcode_post_discipline ( $atts ) {
|
353
|
$defaults = array(
|
354
|
'sep' => ', ',
|
355
|
'before' => '',
|
356
|
'after' => '',
|
357
|
'taxonomy' => 'discipline'
|
358
|
);
|
359
|
$atts = shortcode_atts( $defaults, $atts );
|
360
|
|
361
|
$atts = array_map( 'wp_kses_post', $atts );
|
362
|
|
363
|
$terms = get_the_terms( get_the_ID(), esc_html( $atts['taxonomy'] ) );
|
364
|
$cats = '';
|
365
|
|
366
|
if ( is_array( $terms ) && 0 < count( $terms ) ) {
|
367
|
$links_array = array();
|
368
|
foreach ( $terms as $k => $v ) {
|
369
|
$term_name = get_term_field( 'name', $v->term_id, $atts['taxonomy'] );
|
370
|
$links_array[] = '<a href="' . esc_url( get_term_link( $v, $atts['taxonomy'] ) ) . '" title="' . esc_attr( sprintf( __( 'View all items in %s', 'woothemes' ), $term_name ) ) . '">' . esc_html( $term_name ) . '</a>';
|
371
|
}
|
372
|
|
373
|
$cats = join( $atts['sep'], $links_array );
|
374
|
}
|
375
|
|
376
|
$output = sprintf('<span class="categories">%2$s%1$s%3$s</span> ', $cats, $atts['before'], $atts['after']);
|
377
|
return apply_filters( 'woo_shortcode_post_categories', $output, $atts );
|
378
|
} // End woo_shortcode_post_categories()
|
379
|
endif;
|
380
|
|
381
|
add_shortcode( 'discipline', 'woo_shortcode_post_discipline' );
|
382
|
|
383
|
//Add discipline to woo projects
|
384
|
function cac_acert_projects_own_taxonomy_register(){
|
385
|
register_taxonomy_for_object_type('discipline',project);
|
386
|
}
|
387
|
add_action('init','cac_acert_projects_own_taxonomy_register',100);
|
388
|
|
389
|
//https://wordpress.org/support/topic/custom-post-type-tagscategories-archive-page
|
390
|
//Include events and projects on category pages
|
391
|
add_filter('pre_get_posts', 'query_post_type');
|
392
|
function query_post_type($query) {
|
393
|
if(is_category() || is_tag()) {
|
394
|
$post_type = get_query_var('post_type');
|
395
|
if($post_type)
|
396
|
$post_type = $post_type;
|
397
|
else
|
398
|
$post_type = array('post','event','project'); // replace cpt to your custom post type
|
399
|
|
400
|
$query->set('post_type',$post_type);
|
401
|
return $query;
|
402
|
}
|
403
|
}
|
404
|
|
405
|
|
406
|
|