Advertisement
fauzanjeg

Add Share Button to Meta Block

Nov 8th, 2021
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.45 KB | None | 0 0
  1. /* Add Share Button to Meta Block */
  2. function add_share_button_to_meta_block( $output, $post, $instance ) {
  3.     $output = '';
  4.  
  5.     if ( get_theme_mod( 'jnews_show_block_meta', true ) ) {
  6.         $comment    = jnews_get_comments_number( $post->ID );
  7.         $view_count = jnews_meta_views( $post->ID );
  8.  
  9.         // author detail
  10.         $author        = isset( $post->post_author ) ? $post->post_author : 'rss_post';
  11.         $is_rss        = jnews_get_rss_post_id( $author );
  12.         $author_url    = $is_rss ? ( isset( $post->post_author_url ) ? $post->post_author_url : '' ) : get_author_posts_url( $author );
  13.         $author_name   = $is_rss ? $post->post_author_name : get_the_author_meta( 'display_name', $author );
  14.         $author_avatar = ( $is_rss ? false : $avatar ) ?
  15.             '<div class="jeg_author_avatar">
  16.                 ' . get_avatar( get_the_author_meta( 'ID', $post->post_author ), 80, null, get_the_author_meta( 'display_name', $post->post_author ) ) . '
  17.             </div>' : '';
  18.  
  19.         $trending = ( vp_metabox( 'jnews_single_post.trending_post', null, $post->ID ) ) ? '<div class="jeg_meta_trending"><a href="' . get_the_permalink( $post ) . '"><i class="fa fa-bolt"></i></a></div>' : '';
  20.  
  21.         if ( jnews_is_review( $post->ID ) ) {
  22.             $rating = jnews_generate_rating( $post->ID, 'jeg_landing_review' );
  23.  
  24.             $output .= '<div class="jeg_post_meta">';
  25.             $output .= $trending;
  26.             $output .= get_theme_mod( 'jnews_show_block_meta_rating', true ) ? $rating : '';
  27.             $output .= get_theme_mod( 'jnews_show_block_meta_author', true ) ? ( jnews_check_coauthor_plus() ? '<div class="jeg_meta_author coauthor">' . jnews_get_author_coauthor( $post->ID, false, 'by', 1 ) . '</div>' : '<div class="jeg_meta_author"><span class="by">' . jnews_return_translation( 'by', 'jnews', 'by' ) . "</span> <a href=\"{$author_url}\">{$author_name}</a></div>" ) : '';
  28.             /* Start Custom */
  29.             $share_class = JNews_Share_Bar::getInstance();
  30.             remove_all_filters( 'jnews_top_share_output' );
  31.             $output .= $share_class->top_share_output();
  32.             /* End Custom */
  33.             $output .= '</div>';
  34.         } else {
  35.             $output .= '<div class="jeg_post_meta">';
  36.             $output .= $trending;
  37.             $output .= get_theme_mod( 'jnews_show_block_meta_author', true ) ? ( jnews_check_coauthor_plus() ? '<div class="jeg_meta_author coauthor">' . jnews_get_author_coauthor( $post->ID, $avatar, 'by', 1 ) . '</div>' : '<div class="jeg_meta_author">' . $author_avatar . '<span class="by">' . jnews_return_translation( 'by', 'jnews', 'by' ) . "</span> <a href=\"{$author_url}\">{$author_name}</a></div>" ) : '';
  38.             $output .= get_theme_mod( 'jnews_show_block_meta_date', true ) ? '<div class="jeg_meta_date"><a href="' . get_the_permalink( $post ) . '"><i class="fa fa-clock-o"></i> ' . $instance->format_date( $post ) . '</a></div>' : '';
  39.             $output .= get_theme_mod( 'jnews_show_block_meta_comment', true ) && ! $feed ? '<div class="jeg_meta_comment"><a href="' . jnews_get_respond_link( $post->ID ) . "\" ><i class=\"fa fa-comment-o\"></i> {$comment} </a></div>" : '';
  40.             $output .= get_theme_mod( 'jnews_show_block_meta_views', false ) && ! $feed ? '<div class="jeg_meta_views"><a href="' . get_the_permalink( $post->ID ) . "\" ><i class=\"fa fa-eye\"></i> {$view_count} </a></div>" : '';
  41.             /* Start Custom */
  42.             $share_class = JNews_Share_Bar::getInstance();
  43.             remove_all_filters( 'jnews_top_share_output' );
  44.             $output .= $share_class->top_share_output();
  45.             /* End Custom */
  46.             $output .= '</div>';
  47.         }
  48.     }
  49.     return $output;
  50. }
  51. add_filter( 'jnews_module_post_meta_1', 'add_share_button_to_meta_block', null, 3 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement