Skip to:
Content

BuddyPress.org

Changeset 8718


Ignore:
Timestamp:
07/29/2014 06:52:10 PM (12 years ago)
Author:
johnjamesjacoby
Message:

Correct phpdoc for bp_activity_recurse_comment_count() and bp_activity_get_comment_count(). Also formally deprecate $args in bp_activity_get_comment_count() and add filter at the end of bp_activity_recurse_comment_count() so it can be manipulated by third party plugins.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-activity/bp-activity-template.php

    r8717 r8718  
    21472147
    21482148    /**
    2149      * Return the content of the activity comment currently being displayed.
    2150      *
    2151      * The content is run through two filters. 'bp_get_activity_content'
    2152      * will apply all filters applied to activity items in general. Use
    2153      * 'bp_activity_comment_content' to modify the content of activity
    2154      * comments only.
     2149     * Return the comment count of an activity item.
    21552150     *
    21562151     * @since BuddyPress (1.2)
     
    21592154     * @uses bp_activity_recurse_comment_count()
    21602155     * @uses apply_filters() To call the 'bp_activity_get_comment_count' hook.
    2161      * @todo deprecate $args
    2162      *
    2163      * @param array $args Deprecated.
     2156     *
     2157     * @param array $deprecated Deprecated.
     2158     *
    21642159     * @return int $count The activity comment count.
    21652160     */
    2166     function bp_activity_get_comment_count( $args = '' ) {
    2167         global $activities_template;
    2168 
    2169         if ( !isset( $activities_template->activity->children ) || !$activities_template->activity->children )
    2170             return 0;
    2171 
    2172         $count = bp_activity_recurse_comment_count( $activities_template->activity );
     2161    function bp_activity_get_comment_count( $deprecated = null ) {
     2162        global $activities_template;
     2163
     2164        // Deprecated notice about $args
     2165        if ( ! empty( $deprecated ) ) {
     2166            _deprecated_argument( __FUNCTION__, '1.2', sprintf( __( '%1$s no longer accepts arguments. See the inline documentation at %2$s for more details.', 'buddypress' ), __FUNCTION__, __FILE__ ) );
     2167        }
     2168
     2169        // Get the count using the purpose-built recursive function
     2170        $count = ! empty( $activities_template->activity->children )
     2171            ? bp_activity_recurse_comment_count( $activities_template->activity )
     2172            : 0;
    21732173
    21742174        return apply_filters( 'bp_activity_get_comment_count', (int) $count );
     
    21762176
    21772177        /**
    2178          * Return the content of the activity comment currently being displayed.
     2178         * Return the total number of comments to the current comment.
    21792179         *
    2180          * The content is run through two filters. 'bp_get_activity_content'
    2181          * will apply all filters applied to activity items in general.
    2182          * Use bp_activity_comment_content to modify the content of
    2183          * activity comments only.
     2180         * This function recursively adds the total number of comments each
     2181         * activity child has, and returns them.
    21842182         *
    21852183         * @since BuddyPress (1.2)
    21862184         *
    21872185         * @uses bp_activity_recurse_comment_count()
    2188          * @uses apply_filters() To call the 'bp_activity_get_comment_count' hook
    2189          * @todo investigate why bp_activity_recurse_comment_count() is used while being declared
     2186         * @uses apply_filters() To call the 'bp_activity_recurse_comment_count' hook
    21902187         *
    21912188         * @param object $comment Activity comment object.
    21922189         * @param int $count The current iteration count.
     2190         *
    21932191         * @return int $count The activity comment count.
    21942192         */
    21952193        function bp_activity_recurse_comment_count( $comment, $count = 0 ) {
    21962194
    2197             if ( empty( $comment->children ) )
    2198                 return $count;
    2199 
    2200             foreach ( (array) $comment->children as $comment ) {
    2201                 $count++;
    2202                 $count = bp_activity_recurse_comment_count( $comment, $count );
     2195            // Copy the count
     2196            $new_count = $count;
     2197
     2198            // Loop through children and recursively count comments
     2199            if ( ! empty( $comment->children ) ) {
     2200                foreach ( (array) $comment->children as $comment ) {
     2201                    $new_count++;
     2202                    $new_count = bp_activity_recurse_comment_count( $comment, $new_count );
     2203                }
    22032204            }
    22042205
    2205             return $count;
     2206            // Filter and return
     2207            return apply_filters( 'bp_activity_recurse_comment_count', $new_count, $comment, $count );
    22062208        }
    22072209
Note: See TracChangeset for help on using the changeset viewer.