Plugin Directory

Changeset 1223847


Ignore:
Timestamp:
08/18/2015 04:03:25 PM (11 years ago)
Author:
tinkerpriest
Message:

bbPress New Topics: Bug fixes

  • Small update to code
  • Added participants to user array
  • Added new tag to before forum title
  • Fixed issue with removing new tag from read topics
  • Updated version and stable tag
Location:
bbpress-new-topics/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • bbpress-new-topics/trunk/bbpress-new-topics.php

    r860389 r1223847  
    33Plugin Name: bbPress New Topics
    44Plugin URI: http://bavotasan.com/2014/bbpress-new-topics-plugin/
    5 Description: Displays a "new" label on topics that are unread or have unread replies for all keymasters and moderators.
     5Description: Displays a "new" label on topics that are unread or have unread replies for all keymasters, moderators and participants.
    66Author: c.bavota
    7 Version: 1.0.0
     7Version: 1.0.1
    88Author URI: http://bavotasan.com
    99Text Domain: new-topics
     
    1212*/
    1313
    14 /*  Copyright 2014  c.bavota  (email : [email protected])
     14/*  Copyright 2015  c.bavota  (email : [email protected])
    1515
    1616    This program is free software; you can redistribute it and/or modify
     
    3030// Plugin version
    3131if ( ! defined( 'NEW_TOPICS_VERSION' ) ) {
    32     define( 'NEW_TOPICS_VERSION', '1.0.0' );
     32    define( 'NEW_TOPICS_VERSION', '1.0.1' );
    3333}
    3434
     
    5050
    5151            add_action( 'bbp_theme_before_topic_title', array( $this, 'bbp_theme_before_topic_title' ) );
     52            add_action( 'bbp_template_before_single_topic', array( $this, 'bbp_template_before_single_topic' ) );
     53            add_action( 'bbp_theme_before_forum_title', array( $this, 'bbp_theme_before_forum_title' ) );
    5254        }
    5355
     
    8082                    $new_topics_array = (array) get_user_meta( $admin->ID, 'bbp_new_topics', true );
    8183
    82                     if ( ! in_array( $topic_id, $new_topics_array ) ) {
     84                    if ( ! in_array( $topic_id, array_filter( $new_topics_array ) ) ) {
    8385                        $new_topics_array[] = (int) $topic_id;
    8486
     
    106108            $new_topics_array = (array) get_user_meta( $user_id, 'bbp_new_topics', true );
    107109
    108             if ( in_array( $topic_id, $new_topics_array ) )
     110            if ( in_array( $topic_id, array_filter( $new_topics_array ) ) )
    109111                $classes[] = 'new-topic';
    110112
     
    122124            $new_topics_array = (array) get_user_meta( $user_id, 'bbp_new_topics', true );
    123125
    124             if ( in_array( $topic_id, $new_topics_array ) ) {
    125                 if ( bbp_is_single_topic () ) {
    126                     unset( $new_topics_array[array_search( (int) $topic_id, $new_topics_array )] );
     126            if ( in_array( $topic_id, array_filter( $new_topics_array ) ) ) {
     127                echo '<span class="new-topic-notifier">' . __( 'New', 'new-topics' ) . '</span> ';
     128            }
     129        }
    127130
    128                     update_user_meta( $user_id, 'bbp_new_topics', (array) $new_topics_array );
    129                 } else {
     131        /**
     132         * Remove topic from unread topics array upon viewing.
     133         *
     134         * @since 1.0.1
     135         */
     136        public function bbp_template_before_single_topic() {
     137            $user_id = get_current_user_id();
     138            $topic_id = bbp_get_topic_id();
     139            $new_topics_array = (array) get_user_meta( $user_id, 'bbp_new_topics', true );
     140
     141            if ( in_array( (int) $topic_id, $new_topics_array ) ) {
     142                unset( $new_topics_array[array_search( (int) $topic_id, $new_topics_array )] );
     143
     144                update_user_meta( $user_id, 'bbp_new_topics', (array) $new_topics_array );
     145            }
     146        }
     147
     148
     149        /**
     150         * Adds 'New' label to all forums that contain topics which appear in the unread topics array.
     151         *
     152         * @since 1.0.1
     153         */
     154        public function bbp_theme_before_forum_title(){
     155            $user_id = get_current_user_id();
     156            $forum_id = bbp_get_forum_id();
     157            $new_topics_array = (array) get_user_meta( $user_id, 'bbp_new_topics', true );
     158
     159            global $wpdb;
     160            $new_query = 'SELECT post_id FROM ' . $wpdb->prefix . 'postmeta WHERE meta_key = "_bbp_forum_id" AND meta_value = "' . $forum_id. '"';
     161
     162            $result = $wpdb->get_results( $new_query );
     163
     164            foreach( $result as $row ) {
     165                if ( in_array( (int) $row->post_id, array_filter( $new_topics_array ) ) ) {
    130166                    echo '<span class="new-topic-notifier">' . __( 'New', 'new-topics' ) . '</span> ';
    131167                }
     
    134170
    135171        /**
    136          * Gathers all keymasters and moderators.
     172         * Gathers all keymasters, moderators and participants.
    137173         *
    138174         * @since 1.0.0
    139175         */
    140176        public function bbp_get_admins() {
    141             $keymaster = get_users( array(
    142                 'role' => 'bbp_keymaster',
    143             ) );
     177            $keymaster = get_users( array(
     178                'role' => 'bbp_keymaster',
     179            ) );
    144180
    145             $moderators = get_users( array(
    146                 'role' => 'bbp_moderator',
    147             ) );
     181            $moderators = get_users( array(
     182                'role' => 'bbp_moderator',
     183            ) );
    148184
    149             return array_merge( $keymaster, $moderators );
     185            $participant = get_users( array(
     186                'role' => 'bbp_participant',
     187            ) );
     188
     189            return array_merge( $keymaster, $moderators, $participant );
    150190        }
    151191    }
  • bbpress-new-topics/trunk/readme.txt

    r860389 r1223847  
    66Domain Path: /languages
    77Requires at least: 3.5
    8 Tested up to: 3.8
    9 Stable tag: 1.0.0
     8Tested up to: 4.3
     9Stable tag: 1.0.1
    1010License: GPLv2 or later
    1111License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    3535== Change Log ==
    3636
     37= 2015-08-18 v1.0.1 =
     38* Small update to code
     39* Added participants to user array
     40* Added new tag to before forum title
     41* Fixed issue with removing new tag from read topics
     42* Updated version and stable tag
     43
    3744= 2014-02-18 v1.0.0 =
    3845Initial Public Release
Note: See TracChangeset for help on using the changeset viewer.