EduardET

Extra functions.php - co author plus plugin

Nov 23rd, 2017
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.05 KB | None | 0 0
  1. function wpc_extra_display_single_post_meta() {
  2.     $post_meta_options = et_get_option( 'extra_postinfo2', array(
  3.         'author',
  4.         'date',
  5.         'categories',
  6.         'comments',
  7.         'rating_stars',
  8.     ) );
  9.  
  10.     $meta_args = array(
  11.         'author_link'    => in_array( 'author', $post_meta_options ),
  12.         'author_link_by' => et_get_safe_localization( __( 'Posted by %s', 'extra' ) ),
  13.         'post_date'      => in_array( 'date', $post_meta_options ),
  14.         'categories'     => in_array( 'categories', $post_meta_options ),
  15.         'comment_count'  => in_array( 'comments', $post_meta_options ),
  16.         'rating_stars'   => in_array( 'rating_stars', $post_meta_options ),
  17.     );
  18.  
  19.     return wpc_et_extra_display_post_meta( $meta_args );
  20. }
  21.  
  22. function wpc_et_extra_display_post_meta( $args = array() ) {
  23.     $default_args = array(
  24.         'post_id'        => get_the_ID(),
  25.         'author_link'    => true,
  26.         'author_link_by' => et_get_safe_localization( __( 'by %s', 'extra' ) ),
  27.         'post_date'      => true,
  28.         'date_format'    => et_get_option( 'extra_date_format', '' ),
  29.         'categories'     => true,
  30.         'comment_count'  => true,
  31.         'rating_stars'   => true,
  32.     );
  33.  
  34.     $args = wp_parse_args( $args, $default_args );
  35.  
  36.     $meta_pieces = array();
  37.  
  38.     if ( $args['author_link'] ) {
  39.         $meta_pieces[] = sprintf( $args['author_link_by'], wpc_extra_get_post_author_link( $args['post_id'] ) );
  40.     }
  41.  
  42.     if ( $args['post_date'] ) {
  43.         $meta_pieces[] = extra_get_the_post_date( $args['post_id'], $args['date_format'] );
  44.     }
  45.  
  46.     if ( $args['categories'] ) {
  47.         $meta_piece_categories = extra_get_the_post_categories( $args['post_id'] );
  48.         if ( !empty( $meta_piece_categories ) ) {
  49.             $meta_pieces[] = $meta_piece_categories;
  50.         }
  51.     }
  52.  
  53.     if ( $args['comment_count'] ) {
  54.         $meta_piece_comments = extra_get_the_post_comments_link( $args['post_id'] );
  55.         if ( !empty( $meta_piece_comments ) ) {
  56.             $meta_pieces[] = $meta_piece_comments;
  57.         }
  58.     }
  59.  
  60.     if ( $args['rating_stars'] && extra_is_post_rating_enabled( $args['post_id'] ) ) {
  61.         $meta_piece_rating_stars = extra_get_post_rating_stars( $args['post_id'] );
  62.         if ( !empty( $meta_piece_rating_stars ) ) {
  63.             $meta_pieces[] = $meta_piece_rating_stars;
  64.         }
  65.     }
  66.  
  67.     $output = implode( ' | ', $meta_pieces );
  68.  
  69.     return $output;
  70. }
  71.  
  72. function wpc_extra_get_post_author_link( $post_id = 0 ) {
  73.     $post_id = empty( $post_id ) ? get_the_ID() : $post_id;
  74.     $post_author_id = get_post( $post_id )->post_author;
  75.     $author = get_user_by( 'id', $post_author_id );
  76.  
  77.     if ( function_exists( 'coauthors_posts_links' ) ) {
  78.         $link = sprintf(
  79.             '<a href="%1$s" class="url fn" title="%2$s" rel="author">%3$s</a>',
  80.             esc_url( get_author_posts_url( $author->ID, $author->user_nicename ) ),
  81.             esc_attr( sprintf( __( 'Posts by %s' ), $author->display_name ) ),
  82.             coauthors_posts_links( null, null, null, null, false )
  83.         );
  84.     } else {
  85.         $link = sprintf(
  86.             '<a href="%1$s" class="url fn" title="%2$s" rel="author">%3$s</a>',
  87.             esc_url( get_author_posts_url( $author->ID, $author->user_nicename ) ),
  88.             esc_attr( sprintf( __( 'Posts by %s' ), $author->display_name ) ),
  89.             esc_html( $author->display_name )
  90.         );
  91.     }
  92.     return $link;
  93. }
Advertisement
Add Comment
Please, Sign In to add comment