Monday, October 25, 2021

Directorist | Co Authors Plus Integration | Multiple Author

You can use the co-author plus plugin to use/assign multiple authors on your Directorist based website.

Please follow the instructions to achieve this functionality:

1. Install Co Authors Plus Plugin:

Install and activate Co-Authors Plus plugin from WordPress repository -


Directorist | Co Authors Plus Integration | Multiple Author



2. Use Custom Code: 

Please paste the following custom code at the end of "functions.php" of the currently activated themes on the Directorist.


    add_filter( 'coauthors_edit_author_cap', function( $cap ){
        return 'read';
    } );

3. Template Override:

Please read the template override documentation before you start this process. This will help you to understand how to override the templates properly.

Template Override Documentation

Please create a file "directorist/single/section-author_info.php" in your currently activated theme folder with the following code -


Directorist | Co Authors Plus Integration | Multiple Author




  1. <?php
  2. /**
  3.  * @author  wpWax
  4.  * @since   6.7
  5.  * @version 7.0.5.2
  6.  */
  7.  
  8. use \Directorist\Helper;
  9.  
  10. if ( ! defined( 'ABSPATH' ) ) exit;
  11.  
  12. $id = $listing->id;
  13. $author_list= array();
  14. if ( is_plugin_active( 'co-authors-plus/co-authors-plus.php' ) ) {
  15.     $coauthors = get_coauthors($id);
  16.     foreach($coauthors as $authorInfo){
  17.         $author_list[] = $authorInfo->ID;
  18.     }
  19. }else{
  20.     $author_list[] = $listing->author_id;
  21. }
  22.  
  23. ?>
  24.  
  25. <div class="directorist-card directorist-card-author-info <?php echo esc_attr( $class );?>" <?php $listing->section_id( $id ); ?>>
  26.  
  27.     <div class="directorist-card__header">
  28.  
  29.         <h4 class="directorist-card__header--title"><?php directorist_icon( $icon );?><?php echo esc_html( $label );?></h4>
  30.    
  31.     </div>
  32.  
  33.     <div class="directorist-card__body">
  34.  
  35.     <?php
  36.         foreach($author_list as $author_id){
  37.            
  38.             $listing->author_id = $author_id;
  39.             $u_pro_pic  = get_user_meta($author_id, 'pro_pic', true);
  40.             $u_pro_pic  = !empty($u_pro_pic) ? wp_get_attachment_image_src($u_pro_pic, 'thumbnail') : '';
  41.             $author_img = !empty($u_pro_pic) ? $u_pro_pic[0] : '';
  42.             $avatar_img = get_avatar($author_id, 32);
  43.     ?>
  44.  
  45.         <div class="directorist-single-author-info" style="<?php echo count( $author_list )  > 1 ? "margin-bottom:50px" : ""; ?>">
  46.  
  47.             <div class="directorist-single-author-avatar">
  48.  
  49.                 <div class="directorist-single-author-avatar-inner">
  50.                     <?php if ( $author_img ): ?>
  51.                         <img src="<?php echo esc_url( $author_img ); ?>" alt="<?php esc_attr_e( 'Avatar', 'directorist' );?>">
  52.                     <?php else: ?>
  53.                         <?php echo $avatar_img; ?>
  54.                     <?php endif; ?>
  55.                 </div>
  56.  
  57.                 <div class="directorist-single-author-name">
  58.                     <h4><?php echo esc_html( $listing->author_info( 'name' ) ); ?></h4>
  59.                     <span class="directorist-single-author-membership"><?php printf( esc_html__( 'Member since %s ago', 'directorist' ), $listing->author_info( 'member_since' ) ); ?></span>
  60.                 </div>
  61.  
  62.             </div>
  63.  
  64.             <div class="directorist-single-author-contact-info">
  65.  
  66.                 <ul>
  67.                     <?php if ( $address = $listing->author_info( 'address' ) ): ?>
  68.                         <li>
  69.                             <span class="<?php atbdp_icon_type( true );?>-map-marker"></span>
  70.                             <span class="directorist-single-author-contact-info-text"><?php echo esc_html( $address ); ?></span>
  71.                         </li>
  72.                     <?php endif; ?>
  73.  
  74.  
  75.                     <?php if ( $phone = $listing->author_info( 'phone' ) ): ?>
  76.                         <li>
  77.                             <span class="<?php atbdp_icon_type(true);?>-phone"></span>
  78.                             <span class="directorist-single-author-contact-info-text">
  79.                                 <a href="tel:<?php Helper::formatted_tel( $phone ); ?>"><?php echo esc_html( $phone ); ?></a>
  80.                             </span>
  81.                         </li>
  82.                     <?php endif; ?>
  83.  
  84.                     <?php if ( $listing->author_display_email() ): ?>
  85.                         <li>
  86.                             <span class="<?php atbdp_icon_type(true);?>-envelope"></span>
  87.                             <span class="directorist-single-author-contact-info-text"><?php echo esc_html( $listing->author_info( 'email' ) ); ?></span>
  88.                         </li>
  89.                     <?php endif; ?>
  90.  
  91.                     <?php if ( $website = $listing->author_info( 'website' ) ): ?>
  92.                         <li>
  93.                             <span class="<?php atbdp_icon_type(true);?>-globe"></span>
  94.                             <a href="<?php echo esc_url( $website ); ?>" class="directorist-single-author-contact-info-text"><?php echo esc_url( $website ); ?></a>
  95.                         </li>
  96.                     <?php endif; ?>
  97.                 </ul>
  98.  
  99.             </div>
  100.  
  101.             <?php if ( $listing->author_has_socials() ): ?>
  102.                
  103.                 <ul class="directorist-author-social">
  104.                     <?php
  105.                     if ( $facebook = $listing->author_info( 'facebook' ) ) {
  106.                         printf('<li class="directorist-author-social-item"><a target="_blank" href="%s"><span class="'.atbdp_icon_type().'-facebook"></span></a></li>', $facebook);
  107.                     }
  108.                     if ( $twitter = $listing->author_info( 'twitter' ) ) {
  109.                         printf('<li class="directorist-author-social-item"><a target="_blank" href="%s"><span class="'.atbdp_icon_type().'-twitter"></span></a></li>', $twitter);
  110.                     }
  111.                     if ( $linkedin = $listing->author_info( 'linkedin' ) ) {
  112.                         printf('<li class="directorist-author-social-item"><a target="_blank" href="%s"><span class="'.atbdp_icon_type().'-linkedin"></span></a></li>', $linkedin);
  113.                     }
  114.                     if ( $youtube = $listing->author_info( 'youtube' ) ) {
  115.                         printf('<li class="directorist-author-social-item"><a target="_blank" href="%s"><span class="'.atbdp_icon_type().'-youtube"></span></a></li>', $youtube);
  116.                     }
  117.                     ?>
  118.                 </ul>
  119.  
  120.             <?php endif; ?>
  121.  
  122.             <a class="directorist-btn directorist-btn-primary directorist-btn-sm diretorist-view-profile-btn" href="<?php echo ATBDP_Permalink::get_user_profile_page_link( $author_id ); ?>"><?php esc_html_e( 'View Profile', 'directorist' ); ?></a>
  123.            
  124.         </div>
  125.         <?php } ?>
  126.     </div>
  127.  
  128. </div>


4. Outputs:

Backend:


Directorist | Co Authors Plus Integration | Multiple Author


Frontend:


Directorist | Co Authors Plus Integration | Multiple Author



1 comment:

  1. Hello. Thank you for creating this. This is what we have been looking for. However, when I try to activate the plugin you mentioned, it comes back with:

    Fatal error: Cannot redeclare cap_filter_comment_moderation_email_recipients() (previously declared in /home/edsofq1u1msg/public_html/dev/wp-content/plugins/publishpress-authors/src/functions/coauthors-functions.php:152) in /home/edsofq1u1msg/public_html/dev/wp-content/plugins/co-authors-plus/co-authors-plus.php on line 2068

    How do I fix this?

    ReplyDelete