Project

General

Profile

Feature #4751 » functions.php

Boone Gorges, 2015-10-08 02:36 PM

 
1
<?php
2
#Function to create shortcode for Blog Feature
3
if ( ! function_exists( 'woo_shortcode_post_blog_feature' ) ) {
4
function woo_shortcode_post_blog_feature ( $atts ) {
5
  $defaults = array(
6
    'sep' => ', ',
7
    'before' => '',
8
    'after' => '',
9
    'taxonomy' => 'blog_feature'
10
  );
11
  $atts = shortcode_atts( $defaults, $atts );
12

    
13
  $atts = array_map( 'wp_kses_post', $atts );
14

    
15
  $terms = get_the_terms( get_the_ID(), esc_html( $atts['taxonomy'] ) );
16
  $cats = '';
17

    
18
  if ( is_array( $terms ) && 0 < count( $terms ) ) {
19
    $links_array = array();
20
    foreach ( $terms as $k => $v ) {
21
      $term_name = get_term_field( 'name', $v->term_id, $atts['taxonomy'] );
22
      $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>';
23
    }
24

    
25
    $cats = join( $atts['sep'], $links_array );
26
  }
27

    
28
  $output = sprintf('<span class="categories">%2$s%1$s%3$s</span> ', $cats, $atts['before'], $atts['after']);
29
  return apply_filters( 'woo_shortcode_post_categories', $output, $atts );
30
} // End woo_shortcode_post_categories()
31
}
32

    
33
add_shortcode( 'blog_feature', 'woo_shortcode_post_blog_feature' );
34

    
35

    
36
function new_projects_fields( $fields ) {
37
$fields['faculty'] = array(
38
'name' => __( 'Faculty', 'projects' ),
39
'description' => __( 'Enter faculty for this project.', 'projects' ),
40
'type' => 'text',
41
'default' => '',
42
'section' => 'info'
43
);
44
return $fields;
45
}
46
add_filter( 'projects_custom_fields', 'new_projects_fields' );
47

    
48

    
49

    
50
function display_new_projects_fields() {
51
global $post;
52
$faculty = esc_attr( get_post_meta( $post->ID, '_faculty', true ) );
53

    
54
echo '<p>' . __( 'Faculty: ', 'projects' ) . $faculty . '</p>';
55

    
56
}
57
add_action( 'projects_after_loop_item', 'display_new_projects_fields', 10 );
58

    
59

    
60
// add tag support to project pages
61
function tags_support_all() {
62
  register_taxonomy_for_object_type('post_tag', 'project');
63
}
64

    
65
// add category support to project pages
66
function category_support_all() {
67
  register_taxonomy_for_object_type('category', 'project');
68
}
69

    
70
// ensure all tags are included in queries
71
function tags_support_query($wp_query) {
72
  if ($wp_query->get('tag')) $wp_query->set('post_type', 'any');
73
}
74

    
75
// tag hooks
76
add_action('init', 'tags_support_all');
77
add_action('init', 'category_support_all');
78
add_action('pre_get_posts', 'tags_support_query');
79

    
80

    
81

    
82
//Add post categories and post tags to Events Manager
83
function my_em_own_taxonomy_register(){
84
    register_taxonomy_for_object_type('category',EM_POST_TYPE_EVENT);
85
    register_taxonomy_for_object_type('category',EM_POST_TYPE_LOCATION);
86
    register_taxonomy_for_object_type('post_tag',EM_POST_TYPE_EVENT);
87
    register_taxonomy_for_object_type('post_tag',EM_POST_TYPE_LOCATION);
88
    }
89
add_action('init','my_em_own_taxonomy_register',100);
90

    
91

    
92

    
93
function blog_feature_init() {
94
  // create a new taxonomy for blog_feature
95
  register_taxonomy(
96
    'blog_feature',
97
    'post',
98
    array(
99
    // Hierarchical taxonomy (like categories)
100
    'hierarchical' => true,
101
      'label' => __( 'Blog Feature' ),
102
      'rewrite' => array( 'slug' => 'Blog Feature'),
103
    )
104
  );
105
}
106
add_action( 'init', 'blog_feature_init' );
107

    
108
//Add content category to woo projects
109
function projects_own_taxonomy_register(){
110
    register_taxonomy_for_object_type('content_category',project);
111
    }
112
add_action('init','projects_own_taxonomy_register',100);
113

    
114

    
115

    
116
function project_category_init() {
117
  // create a new taxonomy for Events Manager Content Category
118
  register_taxonomy(
119
    'project_content_category',
120
    project,
121
    array(
122
    // Hierarchical taxonomy (like categories)
123
    'hierarchical' => true,
124
      'label' => __( 'Project Content Category' ),
125
      'rewrite' => array( 'slug' => 'Project Content Category'),
126
    )
127
  );
128
}
129
add_action( 'init', 'project_category_init' );
130

    
131
function project_department_init() {
132
  // create a new taxonomy for Project departments
133
  register_taxonomy(
134
    'project_department_category',
135
    project,
136
    array(
137
    // Hierarchical taxonomy (like categories)
138
    'hierarchical' => false,
139
      'label' => __( 'Department' ),
140
      'rewrite' => array( 'slug' => 'Department'),
141
    )
142
  );
143
}
144
add_action( 'init', 'project_department_init' );
145

    
146

    
147
// Custom shortcode function for coauthors post links
148

    
149
function coauthor_links_shortcode( ) {
150

    
151
    if ( function_exists( 'coauthors_posts_links' ) ) {
152
        $author = coauthors_posts_links( null, null, null, null, false );
153
    } else {
154
       $author = '[post_author_posts_link]';
155
    }
156
    return  $author;
157
}
158

    
159
add_shortcode('author_links','coauthor_links_shortcode');
160

    
161
// Define woo_post_meta if not set in filter yet
162

    
163
function woo_post_meta() {
164

    
165
  if ( is_page() && !( is_page_template( 'template-blog.php' ) || is_page_template( 'template-magazine.php' ) ) ) {
166
    return;
167
  }
168

    
169
  $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=""] ';
170
printf( '<div class="post-meta">%s</div>' . "\n", apply_filters( 'woo_filter_post_meta', $post_info ) );
171

    
172
} // End woo_post_meta()
173

    
174
// Replace Single Post Author (in theme-actions.php)
175

    
176
function woo_author_box () {
177
  global $post;
178
  $author_id=$post->post_author;
179

    
180
  // Adjust the arrow, if is_rtl().
181
  $arrow = '→';
182
  if ( is_rtl() ) $arrow = '←';
183

    
184
?>
185
<?php foreach( get_coauthors() as $coauthor ): ?>
186
<aside id="post-author">
187
  <div class="profile-image"> <?php echo coauthors_get_avatar( $coauthor, '80', '', false ); ?></div>
188
  <div class="profile-content">
189
    <h4><?php echo 'About '.$coauthor->display_name ?></h4>
190
    <?php echo $coauthor->description; ?>
191
    <?php if ( is_singular() ) : ?>
192
    <div class="profile-link">
193
      <a href="<?php echo get_author_posts_url( $coauthor->ID, $coauthor->user_nicename ); ?>">
194
        <?php echo ('View all posts by: ' . $coauthor->display_name . '<span class="meta-nav">' . $arrow . '</span>' ); ?>
195
      </a>
196
    </div><!--#profile-link-->
197
    <?php endif; ?>
198
  </div>
199
  <div class="fix"></div>
200
</aside>
201
<?php endforeach;
202
} // End woo_author_box()
203

    
204
// Replace Archive Titles conditions
205

    
206
function woo_archive_title ( $before = '', $after = '', $echo = true ) {
207

    
208
  global $wp_query;
209

    
210
  if ( is_category() || is_tag() || is_tax() ) {
211

    
212
    $taxonomy_obj = $wp_query->get_queried_object();
213
    $term_id = $taxonomy_obj->term_id;
214
    $taxonomy_short_name = $taxonomy_obj->taxonomy;
215

    
216
    $taxonomy_raw_obj = get_taxonomy( $taxonomy_short_name );
217

    
218
  } // End IF Statement
219

    
220
  $title = '';
221
  $delimiter = ' | ';
222
  $date_format = get_option( 'date_format' );
223

    
224
  // Category Archive
225
  if ( is_category() ) {
226

    
227
    $title = '<span class="fl cat">' . __( 'Archive', 'woothemes' ) . $delimiter . single_cat_title( '', false ) . '</span> <span class="fr catrss">';
228
    $cat_obj = $wp_query->get_queried_object();
229
    $cat_id = $cat_obj->cat_ID;
230
    $title .= '<a href="' . get_term_feed_link( $term_id, $taxonomy_short_name, '' ) . '" class="icon-rss icon-large" ></a></span>';
231

    
232
    $has_title = true;
233
  }
234

    
235
  // Day Archive
236
  if ( is_day() ) {
237

    
238
    $title = __( 'Archive', 'woothemes' ) . $delimiter . get_the_time( $date_format );
239
  }
240

    
241
  // Month Archive
242
  if ( is_month() ) {
243

    
244
    $date_format = apply_filters( 'woo_archive_title_date_format', 'F, Y' );
245
    $title = __( 'Archive', 'woothemes' ) . $delimiter . get_the_time( $date_format );
246
  }
247

    
248
  // Year Archive
249
  if ( is_year() ) {
250

    
251
    $date_format = apply_filters( 'woo_archive_title_date_format', 'Y' );
252
    $title = __( 'Archive', 'woothemes' ) . $delimiter . get_the_time( $date_format );
253
  }
254

    
255
  // Author Archive
256
  if ( is_author() ) {
257

    
258
    $title = __( 'Author Archive', 'woothemes' ) . $delimiter . coauthors( null, null, null, null, true );
259
  }
260

    
261
  // Tag Archive
262
  if ( is_tag() ) {
263

    
264
    $title = __( 'Tag Archives', 'woothemes' ) . $delimiter . single_tag_title( '', false );
265
  }
266

    
267
  // Post Type Archive
268
  if ( function_exists( 'is_post_type_archive' ) && is_post_type_archive() ) {
269

    
270
    /* Get the post type object. */
271
    $post_type_object = get_post_type_object( get_query_var( 'post_type' ) );
272

    
273
    $title = $post_type_object->labels->name . ' ' . __( 'Archive', 'woothemes' );
274
  }
275

    
276
  // Post Format Archive
277
  if ( get_query_var( 'taxonomy' ) == 'post_format' ) {
278

    
279
    $post_format = str_replace( 'post-format-', '', get_query_var( 'post_format' ) );
280

    
281
    $title = get_post_format_string( $post_format ) . ' ' . __( ' Archives', 'woothemes' );
282
  }
283

    
284
  // General Taxonomy Archive
285
  if ( is_tax() ) {
286

    
287
    $title = sprintf( __( '%1$s Archives: %2$s', 'woothemes' ), $taxonomy_raw_obj->labels->name, $taxonomy_obj->name );
288

    
289
  }
290

    
291
  if ( strlen($title) == 0 )
292
  return;
293

    
294
  $title = $before . $title . $after;
295

    
296
  // Allow for external filters to manipulate the title value.
297
  $title = apply_filters( 'woo_archive_title', $title, $before, $after );
298

    
299
  if ( $echo )
300
    echo $title;
301
  else
302
    return $title;
303

    
304
} // End woo_archive_title()
305

    
306
// Add Custom Post Type Support args
307

    
308
add_action('init', 'custom_post_type_support');
309
function custom_post_type_support() {
310
  add_post_type_support( 'portfolio', array('publicize','author') );
311
  /* add_post_type_support( 'product', array('publicize','author') ); -- if adding coauthor box to woocommerce */
312

    
313
}
314

    
315
?>
(1-1/2)