Title: Unread docs count
Last modified: August 21, 2016

---

# Unread docs count

 *  Resolved [laurahreniucu](https://wordpress.org/support/users/laurahreniucu/)
 * (@laurahreniucu)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/unread-docs-count/)
 * Hello.
 * Is it possible to get a list of unread docs, so the user can see better which
   docs he/she has accessed and which not?
 * [http://wordpress.org/plugins/buddypress-docs/](http://wordpress.org/plugins/buddypress-docs/)

Viewing 10 replies - 1 through 10 (of 10 total)

 *  Plugin Author [Boone Gorges](https://wordpress.org/support/users/boonebgorges/)
 * (@boonebgorges)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/unread-docs-count/#post-4094301)
 * This is a cool idea, but the concept of “unread” needs a bit of fleshing out.
   It could mean:
    – Docs that the user has never looked at – Docs that have been
   edited since the last time the user looked at them – Docs that have been edited
   or commented on since the last time the user looked at them
 * I’m not sure what makes the most sense from a user’s point of view. Do you have
   thoughts about it?
 *  Thread Starter [laurahreniucu](https://wordpress.org/support/users/laurahreniucu/)
 * (@laurahreniucu)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/unread-docs-count/#post-4094363)
 * By “unread” i mean docs that the user has never looked at.
 *  Plugin Author [Boone Gorges](https://wordpress.org/support/users/boonebgorges/)
 * (@boonebgorges)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/unread-docs-count/#post-4094372)
 * Do you have a sense of where/how this would appear in the UI? Or are you just
   looking for a function that’ll do it?
 * FWIW, at the moment, BP Docs does not currently keep track at all of read/unread
   status. This’d require storing lots of data: potentially, one piece of data for
   every Doc-user pair. So I’m wary of including it in Docs itself. But I do think
   you could build a plugin for this purpose, and I’d be happy to point you in the
   right direction, if that’s what you’re looking for.
 *  Thread Starter [laurahreniucu](https://wordpress.org/support/users/laurahreniucu/)
 * (@laurahreniucu)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/unread-docs-count/#post-4094373)
 * Ok, i will explain in detail what i want.
 * I have a website based on Buddypress and Buddypress Docs. It’s a file sharing
   system.
 * Members can create docs that admins / mods will then read/edit. I need to build
   some kind of counter to show me how many docs per member has the admin not read
   yet. And this needs to be showed near the group title and the member name (so,
   one counter for unread docs for members and anotehr for groups).
 * I hope you understand what i’m saying 🙂
 * Thank you.
 *  Plugin Author [Boone Gorges](https://wordpress.org/support/users/boonebgorges/)
 * (@boonebgorges)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/unread-docs-count/#post-4094379)
 * Yup, that use case definitely makes sense. I’d say that this needs to be built
   as a separate plugin, because it’s very use-case-specific. Here’s the strategy
   I’d take:
 * – Decide on a good storage mechanism for “read/unread” data. I guess postmeta
   probably makes the most sense, eg `update_post_meta( $doc_id, 'read_by_user_'.
   $user_id, 1 )`
    – When loading a Doc, update that ‘read_by_user_’ key – To get
   your unread counts, do a WP_Query, and use the ‘meta_query’ param to limit to
   those items that have/don’t have the `'read_by_user_' . $user_id` postmeta. –
   Either use hooks or custom templates to display the data
 * Good luck! Sounds like a cool project.
 *  Thread Starter [laurahreniucu](https://wordpress.org/support/users/laurahreniucu/)
 * (@laurahreniucu)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/unread-docs-count/#post-4094397)
 * So, when i create the doc, i use _update\_post\_meta_ to make the key = 1, and
   then, when i open the doc, use _update\_post\_meta_ again to make it = 0?
 * Or i use it only when loading the Doc.
    I know it may be a dumb question, but,
   as i said, i’m kind of a noob 😀
 *  Thread Starter [laurahreniucu](https://wordpress.org/support/users/laurahreniucu/)
 * (@laurahreniucu)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/unread-docs-count/#post-4094399)
 * Also, unfortunatelly, i don’t have time to build a new plugin. I want to edit
   this plugin’s files. It’s ok, since i won’t be upgrading.
 * Could you please tell me where should i edit?
 * Thank you 🙂
 *  Plugin Author [Boone Gorges](https://wordpress.org/support/users/boonebgorges/)
 * (@boonebgorges)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/unread-docs-count/#post-4094406)
 * It really doesn’t take any additional time to build a plugin as opposed to editing
   the Docs core files. But, it’s your call.
 * I’m afraid I can’t give more specific pointers than what I’ve already given above.
   You’ll have to track how Docs are saved; look into buddypress-docs/includes/query-
   builder.php to get a preliminary sense.
 *  Thread Starter [laurahreniucu](https://wordpress.org/support/users/laurahreniucu/)
 * (@laurahreniucu)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/unread-docs-count/#post-4094418)
 *  Thread Starter [laurahreniucu](https://wordpress.org/support/users/laurahreniucu/)
 * (@laurahreniucu)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/unread-docs-count/#post-4094419)
 * Ok, so i managed to get this done. I will post the changes i made, in case anyone
   needs this.
 * 1. buddypress-docs\includes\query-builder.php – function “save” – line 556
    ADD
 *     ```
       $current_user = wp_get_current_user();
       $user_id = $current_user->ID;
       $user_query = new WP_User_Query( array( 'exclude' => array( $user_id) ) );
   
       if ( ! empty( $user_query->results ) ) {
       	foreach ( $user_query->results as $user ) {
       		update_post_meta( $this->doc_id, 'read_by_user_' . $user->ID, 1 );
       	}
       }
       ```
   
 * 2. buddypress-docs\includes\templates\docs\docs-header.php – line 9
    ADD
 *     ```
       <?php $current_user = wp_get_current_user();
       	  $user_id = $current_user->ID;
       	  ?>
       <?php update_post_meta( get_the_ID(), 'read_by_user_' . $user_id, 0 ) ?>
       ```
   
 * 3. buddypress-docs\includes\functions.php – end of file
    ADD
 *     ```
       function bp_docs_get_unread_count($user_id = false, $author_id) {
       	if ( false === $user_id ) {
       		$user_id = bp_loggedin_user_id();
       	}
   
       	$unread_post_count = 0;
       	$unread_key = 'read_by_user_' . $user_id;
   
       	$args = array(
       		'author' => $author_id,
       		'post_type' => 'bp_doc',
       		'meta_query' => array(
       			array(
       				'key' => $unread_key,
       				'value' => '1'
       			)
       		)
       	);
   
       	$query = new WP_Query( $args );
   
       	$unread_post_count = $query->found_posts;
       	wp_reset_postdata(); 
   
       	if( $unread_post_count == 0) {
       		$unread_post_count = '';
       	}
   
       	return $unread_post_count;
       }
       ```
   
 * AND ADD
 *     ```
       function get_user_id_by_display_name( $display_name ) {
           global $wpdb;
   
           if ( ! $user = $wpdb->get_row( $wpdb->prepare(
               "SELECT <code>ID</code> FROM $wpdb->users WHERE <code>display_name</code> = %s", $display_name
           ) ) )
               return false;
   
           return $user->ID;
       }
       ```
   
 * 4. buddypress\bp-themes\bp-default\members\members-loop.php – line 47
    ADD
 *     ```
       <?php
       	$current_user = wp_get_current_user();
       	$user_id = $current_user->ID;
       	$name_id = get_user_id_by_display_name(bp_get_member_name());
       	?>
       ```
   
 * AND REPLACE
    `<a href="<?php bp_member_permalink(); ?>"><?php bp_member_name();?
   ></a>` WITH `<a href="<?php bp_member_permalink(); ?>"><?php bp_member_name();?
   ><?php echo bp_docs_get_unread_count($user_id, $name)?></a>`
 * This will result in the total number of unread docs for each user to be listed
   next to the user name on the “Members” page.
 * Thank you Boone for all your answers and especially for your patience with me
   🙂

Viewing 10 replies - 1 through 10 (of 10 total)

The topic ‘Unread docs count’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/buddypress-docs.svg)
 * [BuddyPress Docs](https://wordpress.org/plugins/buddypress-docs/)
 * [Support Threads](https://wordpress.org/support/plugin/buddypress-docs/)
 * [Active Topics](https://wordpress.org/support/plugin/buddypress-docs/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/buddypress-docs/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/buddypress-docs/reviews/)

 * 10 replies
 * 2 participants
 * Last reply from: [laurahreniucu](https://wordpress.org/support/users/laurahreniucu/)
 * Last activity: [12 years, 9 months ago](https://wordpress.org/support/topic/unread-docs-count/#post-4094419)
 * Status: resolved