Project

General

Profile

11.2.2015UPDATE_cac-acert-custom.php

David dos Santos, 2015-11-02 02:57 PM

 
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
    }
94
add_action('init','cac_acert_my_em_own_taxonomy_register',100);
95

    
96

    
97

    
98
function cac_acert_blog_feature_init() {
99
  // create a new taxonomy for blog_feature
100
  register_taxonomy(
101
    'blog_feature',
102
    'post',
103
    array(
104
    // Hierarchical taxonomy (like categories)
105
    'hierarchical' => true,
106
      'label' => __( 'Blog Feature' ),
107
      'rewrite' => array( 'slug' => 'Blog Feature'),
108
    )
109
  );
110
}
111
add_action( 'init', 'cac_acert_blog_feature_init' );
112

    
113
//Add content category to woo projects
114
function cac_acert_projects_own_taxonomy_register(){
115
    register_taxonomy_for_object_type('content_category',project);
116
    }
117
add_action('init','cac_acert_projects_own_taxonomy_register',100);
118

    
119

    
120

    
121
function cac_acert_project_category_init() {
122
  // create a new taxonomy for Events Manager Content Category
123
  register_taxonomy(
124
    'project_content_category',
125
    project,
126
    array(
127
    // Hierarchical taxonomy (like categories)
128
    'hierarchical' => true,
129
      'label' => __( 'Project Content Category' ),
130
      'rewrite' => array( 'slug' => 'Project Content Category'),
131
    )
132
  );
133
}
134
add_action( 'init', 'cac_acert_project_category_init' );
135

    
136
function cac_acert_project_department_init() {
137
  // create a new taxonomy for Project departments
138
  register_taxonomy(
139
    'project_department_category',
140
    project,
141
    array(
142
    // Hierarchical taxonomy (like categories)
143
    'hierarchical' => false,
144
      'label' => __( 'Department' ),
145
      'rewrite' => array( 'slug' => 'Department'),
146
    )
147
  );
148
}
149
add_action( 'init', 'cac_acert_project_department_init' );
150

    
151

    
152
// Custom shortcode function for coauthors post links
153

    
154
function cac_acert_coauthor_links_shortcode( ) {
155

    
156
    if ( function_exists( 'coauthors_posts_links' ) ) {
157
        $author = coauthors_posts_links( null, null, null, null, false );
158
    } else {
159
       $author = '[post_author_posts_link]';
160
    }
161
    return  $author;
162
}
163

    
164
add_shortcode('author_links','cac_acert_coauthor_links_shortcode');
165

    
166
// Define woo_post_meta if not set in filter yet
167

    
168
if ( ! function_exists( 'woo_post_meta' ) ) :
169
        function woo_post_meta() {
170

    
171
          if ( is_page() && !( is_page_template( 'template-blog.php' ) || is_page_template( 'template-magazine.php' ) ) ) {
172
            return;
173
          }
174

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

    
178
        } // End woo_post_meta()
179
endif;
180

    
181
// Replace Single Post Author (in theme-actions.php)
182
if ( ! function_exists( 'woo_author_box' ) ) :
183
        function woo_author_box () {
184
          global $post;
185
          $author_id=$post->post_author;
186

    
187
          // Adjust the arrow, if is_rtl().
188
          $arrow = '';
189
          if ( is_rtl() ) $arrow = '';
190

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

    
212
// Replace Archive Titles conditions
213

    
214
if ( ! function_exists( 'woo_archive_title' ) ) :
215
        function woo_archive_title ( $before = '', $after = '', $echo = true ) {
216

    
217
          global $wp_query;
218

    
219
          if ( is_category() || is_tag() || is_tax() ) {
220

    
221
            $taxonomy_obj = $wp_query->get_queried_object();
222
            $term_id = $taxonomy_obj->term_id;
223
            $taxonomy_short_name = $taxonomy_obj->taxonomy;
224

    
225
            $taxonomy_raw_obj = get_taxonomy( $taxonomy_short_name );
226

    
227
          } // End IF Statement
228

    
229
          $title = '';
230
          $delimiter = ' | ';
231
          $date_format = get_option( 'date_format' );
232

    
233
          // Category Archive
234
          if ( is_category() ) {
235

    
236
            $title = '<span class="fl cat">' . __( 'Archive', 'woothemes' ) . $delimiter . single_cat_title( '', false ) . '</span> <span class="fr catrss">';
237
            $cat_obj = $wp_query->get_queried_object();
238
            $cat_id = $cat_obj->cat_ID;
239
            $title .= '<a href="' . get_term_feed_link( $term_id, $taxonomy_short_name, '' ) . '" class="icon-rss icon-large" ></a></span>';
240

    
241
            $has_title = true;
242
          }
243

    
244
          // Day Archive
245
          if ( is_day() ) {
246

    
247
            $title = __( 'Archive', 'woothemes' ) . $delimiter . get_the_time( $date_format );
248
          }
249

    
250
          // Month Archive
251
          if ( is_month() ) {
252

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

    
257
          // Year Archive
258
          if ( is_year() ) {
259

    
260
            $date_format = apply_filters( 'woo_archive_title_date_format', 'Y' );
261
            $title = __( 'Archive', 'woothemes' ) . $delimiter . get_the_time( $date_format );
262
          }
263

    
264
          // Author Archive
265
          if ( is_author() ) {
266

    
267
            $title = __( 'Author Archive', 'woothemes' ) . $delimiter . coauthors( null, null, null, null, true );
268
          }
269

    
270
          // Tag Archive
271
          if ( is_tag() ) {
272

    
273
            $title = __( 'Tag Archives', 'woothemes' ) . $delimiter . single_tag_title( '', false );
274
          }
275

    
276
          // Post Type Archive
277
          if ( function_exists( 'is_post_type_archive' ) && is_post_type_archive() ) {
278

    
279
            /* Get the post type object. */
280
            $post_type_object = get_post_type_object( get_query_var( 'post_type' ) );
281

    
282
            $title = $post_type_object->labels->name . ' ' . __( 'Archive', 'woothemes' );
283
          }
284

    
285
          // Post Format Archive
286
          if ( get_query_var( 'taxonomy' ) == 'post_format' ) {
287

    
288
            $post_format = str_replace( 'post-format-', '', get_query_var( 'post_format' ) );
289

    
290
            $title = get_post_format_string( $post_format ) . ' ' . __( ' Archives', 'woothemes' );
291
          }
292

    
293
          // General Taxonomy Archive
294
          if ( is_tax() ) {
295

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

    
298
          }
299

    
300
          if ( strlen($title) == 0 )
301
          return;
302

    
303
          $title = $before . $title . $after;
304

    
305
          // Allow for external filters to manipulate the title value.
306
          $title = apply_filters( 'woo_archive_title', $title, $before, $after );
307

    
308
          if ( $echo )
309
            echo $title;
310
          else
311
            return $title;
312

    
313
        } // End woo_archive_title()
314
endif;
315

    
316
// Add Custom Post Type Support args
317

    
318
add_action('init', 'cac_acert_custom_post_type_support');
319
function cac_acert_custom_post_type_support() {
320
  add_post_type_support( 'portfolio', array('publicize','author') );
321
  /* add_post_type_support( 'product', array('publicize','author') ); -- if adding coauthor box to woocommerce */
322

    
323
}
324

    
325
//Add blog header to posts with blog feature and date
326
function cac_acert_insert_blog_header(){
327
if(get_post_type() == 'post'){  
328
echo '<p class="blog_header">';
329
echo do_shortcode('[blog_feature]');
330
echo " | ";
331
echo get_the_date(); 
332
echo '</p>';
333
  }}
334
   add_action('woo_post_inside_before','cac_acert_insert_blog_header',1)
335