Skip to:
Content

BuddyPress.org

Changeset 13631


Ignore:
Timestamp:
11/03/2023 04:37:33 AM (7 months ago)
Author:
imath
Message:

Add a function to output the bp-activity-comment-id data attribute

In BP Nouveau, instead of using the same function to output the bp-activity-comment-id or bp-activity-id data attribute according to the activity type, introduce the bp_nouveau_activity_comment_data_attribute_id() function and use it inside the activity/comment.php template.
This prevents a notice warning notice and avoid to query for the parent activity to get the right activity type.

Props vapvarun

Fixes #9014
Closes https://github.com/buddypress/buddypress/pull/182

Location:
trunk/src/bp-templates/bp-nouveau
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-templates/bp-nouveau/buddypress/activity/comment.php

    r13114 r13631  
    77 *
    88 * @since 3.0.0
    9  * @version 10.0.0
     9 * @version 12.0.0
    1010 */
    1111
    1212bp_nouveau_activity_hook( 'before', 'comment' ); ?>
    1313
    14 <li id="acomment-<?php bp_activity_comment_id(); ?>" class="comment-item" <?php bp_nouveau_activity_data_attribute_id(); ?>>
     14<li id="acomment-<?php bp_activity_comment_id(); ?>" class="comment-item" <?php bp_nouveau_activity_comment_data_attribute_id(); ?>>
    1515    <div class="acomment-avatar item-avatar">
    1616        <a href="<?php bp_activity_comment_user_link(); ?>">
  • trunk/src/bp-templates/bp-nouveau/includes/activity/template-tags.php

    r13517 r13631  
    160160
    161161/**
    162  * Output the `data-bp-activity-id` or `data-bp-activity-comment-id` attribute
    163  * according to the activity type.
     162 * Output the `data-bp-activity-id` attribute.
    164163 *
    165164 * @since 10.0.0
    166165 */
    167166function bp_nouveau_activity_data_attribute_id() {
    168     $attribute  = 'data-bp-%1$s-id="%2$s"';
    169     $type       = 'activity';
    170     $id         = (int) bp_get_activity_id();
    171     $comment_id = (int) bp_get_activity_comment_id();
    172 
    173     if ( 'activity_comment' === bp_get_activity_type() || $comment_id ) {
    174         $type = 'activity-comment';
    175 
    176 
    177         if ( $comment_id ) {
    178             $id = $comment_id;
    179         }
    180     }
    181 
    182     printf( $attribute, $type, $id );
     167    printf( 'data-bp-activity-id="%d"', (int) bp_get_activity_id() );
     168}
     169
     170/**
     171 * Output the `data-bp-activity-comment-id` attribute.
     172 *
     173 * @since 12.0.0
     174 */
     175function bp_nouveau_activity_comment_data_attribute_id() {
     176    printf( 'data-bp-activity-comment-id="%d"', (int) bp_get_activity_comment_id() );
    183177}
    184178
     
    277271     * @todo This function is too large and needs refactoring and reviewing.
    278272     * @since 3.0.0
    279      * 
     273     *
    280274     * @global BP_Activity_Template $activities_template The Activity template loop.
    281275     *
     
    778772     *
    779773     * @since 3.0.0
    780      * 
     774     *
    781775     * @global BP_Activity_Template $activities_template The Activity template loop.
    782776     *
Note: See TracChangeset for help on using the changeset viewer.