<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[BuddyPress][13215] trunk/src: Make it possible to disable Avatar history & richer logging activities</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="http://buddypress.trac.wordpress.org/changeset/13215">13215</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"http://buddypress.trac.wordpress.org/changeset/13215","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>imath</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2022-01-19 21:21:45 +0000 (Wed, 19 Jan 2022)</dd>
</dl>

<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Make it possible to disable Avatar history & richer logging activities

Advanced users wishing to:
1. disable the Avatar history feature, can do so returning `true` when filtering `'bp_disable_avatar_history'`,
2. prevent one or more logging activity types to have a richer output, can return an array of the allowed activity types (or an empty array to completely disable the feature) when filtering `'bp_activity_get_types_supporting_generated_content'`. 

Props sbrajesh, oztaser

Fixes <a href="http://buddypress.trac.wordpress.org/ticket/8617">#8617</a></pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcbpactivitybpactivityfunctionsphp">trunk/src/bp-activity/bp-activity-functions.php</a></li>
<li><a href="#trunksrcbpactivitybpactivitytemplatephp">trunk/src/bp-activity/bp-activity-template.php</a></li>
<li><a href="#trunksrcbpcorebpcoreattachmentsphp">trunk/src/bp-core/bp-core-attachments.php</a></li>
<li><a href="#trunksrcbpcorebpcoreavatarsphp">trunk/src/bp-core/bp-core-avatars.php</a></li>
<li><a href="#trunksrcbpcoreclassesclassbpadminphp">trunk/src/bp-core/classes/class-bp-admin.php</a></li>
<li><a href="#trunksrcbpcoreclassesclassbpattachmentavatarphp">trunk/src/bp-core/classes/class-bp-attachment-avatar.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcbpactivitybpactivityfunctionsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-activity/bp-activity-functions.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-activity/bp-activity-functions.php   2022-01-16 14:40:49 UTC (rev 13214)
+++ trunk/src/bp-activity/bp-activity-functions.php     2022-01-19 21:21:45 UTC (rev 13215)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -632,6 +632,57 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Gets the list of activity types name supporting the requested feature.
+ *
+ * This function is still a WIP, please don't use it into your plugins or themes.
+ *
+ * @since 10.0.0
+ *
+ * @access private
+ * @todo `bp_activity_set_action()` should be improved to include a supports
+ * argument or best we should create a `bp_register_activity_type()` function
+ * to mimic the way WordPress registers post types. For now we'll use a non
+ * extendable workaround.
+ *
+ * @param string $feature The feature activity types should support.
+ * @return array          The list of activity types name supporting the requested feature.
+ */
+function _bp_activity_get_types_by_support( $feature = 'generated-content' ) {
+       $activity_types = array();
+
+       if ( 'generated-content' === $feature ) {
+               $activity_types = array( 'new_member', 'new_avatar' );
+
+               if ( bp_is_active( 'friends' ) ) {
+                       array_push( $activity_types, 'friendship_created' );
+               }
+
+               if ( bp_is_active( 'groups' ) ) {
+                       array_push( $activity_types, 'created_group', 'joined_group' );
+               }
+
+               if ( bp_is_active( 'xprofile' ) ) {
+                       array_push( $activity_types, 'updated_profile' );
+               }
+       }
+
+       $filter_key = str_replace( '-', '_', $feature );
+
+       /**
+        * Use this filter to add/remove activity types supporting the requested feature.
+        *
+        * The dynamic portion of the filter is the name of the requested feature where hyphens are
+        * replaced by underscores. Eg. use `bp_activity_get_types_supporting_generated_content` to
+        * edit the list of activities supporting the `generated-content` feature.
+        *
+        * @since 10.0.0
+        *
+        * @param array $activity_types The list of activity types name supporting the requested feature.
+        */
+       return apply_filters( "bp_activity_get_types_supporting_{$filter_key}", $activity_types );
+}
+
+/**
</ins><span class="cx" style="display: block; padding: 0 10px">  * Check if the *Post Type* activity supports a specific feature.
</span><span class="cx" style="display: block; padding: 0 10px">  *
</span><span class="cx" style="display: block; padding: 0 10px">  * @since 2.5.0
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -714,26 +765,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">                 * Does this activity type support `generated-content`?
</span><span class="cx" style="display: block; padding: 0 10px">                 */
</span><span class="cx" style="display: block; padding: 0 10px">                case 'generated-content' :
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        /*
-                        * @todo `bp_activity_set_action()` should be improved to include a supports
-                        * argument or best we should create a `bp_register_activity_type()` function
-                        * to mimic the way WordPress registers post types. For now we'll use a non
-                        * extendable workaround.
-                        */
-                       $activity_types = array( 'new_member', 'new_avatar' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 $activity_types = _bp_activity_get_types_by_support( 'generated-content' );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        if ( bp_is_active( 'friends' ) ) {
-                               array_push( $activity_types, 'friendship_created' );
-                       }
-
-                       if ( bp_is_active( 'groups' ) ) {
-                               array_push( $activity_types, 'created_group', 'joined_group' );
-                       }
-
-                       if ( bp_is_active( 'xprofile' ) ) {
-                               array_push( $activity_types, 'updated_profile' );
-                       }
-
</del><span class="cx" style="display: block; padding: 0 10px">                         $retval = in_array( $activity_type, $activity_types, true );
</span><span class="cx" style="display: block; padding: 0 10px">                        break;
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span></span></pre></div>
<a id="trunksrcbpactivitybpactivitytemplatephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-activity/bp-activity-template.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-activity/bp-activity-template.php    2022-01-16 14:40:49 UTC (rev 13214)
+++ trunk/src/bp-activity/bp-activity-template.php      2022-01-19 21:21:45 UTC (rev 13215)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1462,21 +1462,38 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                        // Set generated content properties.
</span><span class="cx" style="display: block; padding: 0 10px">                        if ( 'new_avatar' === $activity_type ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                $avatars = bp_avatar_get_version( $user_id, 'user', bp_get_activity_date_recorded() );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         $avatars = array();
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                if ( $avatars && 1 === count( $avatars ) ) {
-                                       $avatar            = reset( $avatars );
-                                       $historical_avatar = trailingslashit( $avatar->parent_dir_url ) . $avatar->name;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         // Use the avatar history to display the avatar that was in use at the time the activity was posted.
+                               if ( ! bp_avatar_history_is_disabled() ) {
+                                       $avatars = bp_avatar_get_version( $user_id, 'user', bp_get_activity_date_recorded() );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                        // Add historical avatar to the current activity.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                 if ( $avatars && 1 === count( $avatars ) ) {
+                                               $avatar            = reset( $avatars );
+                                               $historical_avatar = trailingslashit( $avatar->parent_dir_url ) . $avatar->name;
+
+                                               // Add historical avatar to the current activity.
+                                               $generated_content->user_profile_photo = array(
+                                                       'value'             => $historical_avatar,
+                                                       'sanitize_callback' => 'esc_url',
+                                               );
+                                       }
+
+                                       // Otherwise use the current/latest avatar.
+                               } else {
</ins><span class="cx" style="display: block; padding: 0 10px">                                         $generated_content->user_profile_photo = array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                                'value'             => $historical_avatar,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                         'value'             => bp_core_fetch_avatar(
+                                                       array(
+                                                               'item_id' => $user_id,
+                                                               'object'  => 'user',
+                                                               'type'    => 'full',
+                                                               'width'   => bp_core_avatar_full_width(),
+                                                               'height'  => bp_core_avatar_full_height(),
+                                                               'html'    => false,
+                                                       )
+                                               ),
</ins><span class="cx" style="display: block; padding: 0 10px">                                                 'sanitize_callback' => 'esc_url',
</span><span class="cx" style="display: block; padding: 0 10px">                                        );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
-                                       // Do not use a generated content.
-                               } else {
-                                       return false;
</del><span class="cx" style="display: block; padding: 0 10px">                                 }
</span><span class="cx" style="display: block; padding: 0 10px">                        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span></span></pre></div>
<a id="trunksrcbpcorebpcoreattachmentsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-core/bp-core-attachments.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-core/bp-core-attachments.php 2022-01-16 14:40:49 UTC (rev 13214)
+++ trunk/src/bp-core/bp-core-attachments.php   2022-01-19 21:21:45 UTC (rev 13215)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -815,7 +815,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        ),
</span><span class="cx" style="display: block; padding: 0 10px">                );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( 'user' === $object ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         // Add the recycle view if avatar history is enabled.
+               if ( 'user' === $object && ! bp_avatar_history_is_disabled() ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         // Look inside history to see if the user previously uploaded avatars.
</span><span class="cx" style="display: block; padding: 0 10px">                        $avatars_history = bp_avatar_get_avatars_history( $item_id, $object );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span></span></pre></div>
<a id="trunksrcbpcorebpcoreavatarsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-core/bp-core-avatars.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-core/bp-core-avatars.php     2022-01-16 14:40:49 UTC (rev 13214)
+++ trunk/src/bp-core/bp-core-avatars.php       2022-01-19 21:21:45 UTC (rev 13215)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2150,6 +2150,26 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Informs about whether avatar history is disabled or not.
+ *
+ * @since 10.0.0
+ *
+ * @return bool True if avatar history is disabled. False otherwise.
+ *              Default: `false`.
+ */
+function bp_avatar_history_is_disabled() {
+       /**
+        * Filter here returning `true` to disable avatar history.
+        *
+        * @since 10.0.0
+        *
+        * @param bool $value True to disable avatar history. False otherwise.
+        *                    Default: `false`.
+        */
+       return apply_filters( 'bp_disable_avatar_history', false );
+}
+
+/**
</ins><span class="cx" style="display: block; padding: 0 10px">  * Get a specific version of an avatar from its history.
</span><span class="cx" style="display: block; padding: 0 10px">  *
</span><span class="cx" style="display: block; padding: 0 10px">  * @since 10.0.0
</span></span></pre></div>
<a id="trunksrcbpcoreclassesclassbpadminphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-core/classes/class-bp-admin.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-core/classes/class-bp-admin.php      2022-01-16 14:40:49 UTC (rev 13214)
+++ trunk/src/bp-core/classes/class-bp-admin.php        2022-01-19 21:21:45 UTC (rev 13215)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -906,10 +906,10 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                                <?php
</span><span class="cx" style="display: block; padding: 0 10px">                                                printf(
</span><span class="cx" style="display: block; padding: 0 10px">                                                        /* translators: 1: heart dashicons. 2: BP Credits screen url. 3: number of BuddyPress contributors to this version. */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                                        _n( 'Built with %1$s by <a href="%2$s">%3$d volunteer</a>.', 'Built with %1$s by <a href="%2$s">%3$d volunteers</a>.', 38, 'buddypress' ),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                                 _n( 'Built with %1$s by <a href="%2$s">%3$d volunteer</a>.', 'Built with %1$s by <a href="%2$s">%3$d volunteers</a>.', 39, 'buddypress' ),
</ins><span class="cx" style="display: block; padding: 0 10px">                                                         '<span class="dashicons dashicons-heart"></span>',
</span><span class="cx" style="display: block; padding: 0 10px">                                                        esc_url( bp_get_admin_url( 'admin.php?page=bp-credits' ) ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                                        number_format_i18n( 38 )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                                 number_format_i18n( 39 )
</ins><span class="cx" style="display: block; padding: 0 10px">                                                 );
</span><span class="cx" style="display: block; padding: 0 10px">                                                ?>
</span><span class="cx" style="display: block; padding: 0 10px">                                        </p>
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1088,6 +1088,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                <a href="https://github.com/Achilles4400">Achilles4400</a>,
</span><span class="cx" style="display: block; padding: 0 10px">                                <a href="https://profiles.wordpress.org/oztaser/">Adil Öztaşer (oztaser)</a>,
</span><span class="cx" style="display: block; padding: 0 10px">                                <a href="https://profiles.wordpress.org/boonebgorges/">Boone B Gorges (boonebgorges)</a>,
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                <a href="https://profiles.wordpress.org/sbrajesh/">Brajesh Singh (sbrajesh)</a>,
</ins><span class="cx" style="display: block; padding: 0 10px">                                 <a href="https://profiles.wordpress.org/needle/">Christian Wach (needle)</a>,
</span><span class="cx" style="display: block; padding: 0 10px">                                <a href="https://profiles.wordpress.org/comminski/">comminski</a>,
</span><span class="cx" style="display: block; padding: 0 10px">                                <a href="https://profiles.wordpress.org/dancaragea/">Dan Caragea (dancaragea)</a>,
</span></span></pre></div>
<a id="trunksrcbpcoreclassesclassbpattachmentavatarphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-core/classes/class-bp-attachment-avatar.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-core/classes/class-bp-attachment-avatar.php  2022-01-16 14:40:49 UTC (rev 13214)
+++ trunk/src/bp-core/classes/class-bp-attachment-avatar.php    2022-01-19 21:21:45 UTC (rev 13215)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -246,12 +246,14 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        return false;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                // Delete the existing avatar files for the object.
-               $existing_avatar = bp_core_fetch_avatar( array(
-                       'object'  => $args['object'],
-                       'item_id' => $args['item_id'],
-                       'html' => false,
-               ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         // Get the existing avatar files for the object.
+               $existing_avatar = bp_core_fetch_avatar(
+                       array(
+                               'object'  => $args['object'],
+                               'item_id' => $args['item_id'],
+                               'html'    => false,
+                       )
+               );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                /**
</span><span class="cx" style="display: block; padding: 0 10px">                 * Check that the new avatar doesn't have the same name as the
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -258,29 +260,40 @@
</span><span class="cx" style="display: block; padding: 0 10px">                 * old one before moving the previous one into history.
</span><span class="cx" style="display: block; padding: 0 10px">                 */
</span><span class="cx" style="display: block; padding: 0 10px">                if ( ! empty( $existing_avatar ) && $existing_avatar !== $this->url . $relative_path ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        // Add a new revision for the existing avatar.
-                       $avatars = bp_attachments_list_directory_files( $avatar_folder_dir );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 // Avatar history is disabled, simply delete the existing avatar files.
+                       if ( bp_avatar_history_is_disabled() ) {
+                               bp_core_delete_existing_avatar(
+                                       array(
+                                               'object'      => $args['object'],
+                                               'item_id'     => $args['item_id'],
+                                               'avatar_path' => $avatar_folder_dir,
+                                       )
+                               );
+                       } else {
+                               // Add a new revision for the existing avatar.
+                               $avatars = bp_attachments_list_directory_files( $avatar_folder_dir );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        if ( $avatars ) {
-                               foreach ( $avatars as $avatar_file ) {
-                                       if ( ! isset( $avatar_file->name, $avatar_file->id, $avatar_file->path ) ) {
-                                               continue;
-                                       }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         if ( $avatars ) {
+                                       foreach ( $avatars as $avatar_file ) {
+                                               if ( ! isset( $avatar_file->name, $avatar_file->id, $avatar_file->path ) ) {
+                                                       continue;
+                                               }
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                        $is_full  = preg_match( "/-bpfull/", $avatar_file->name );
-                                       $is_thumb = preg_match( "/-bpthumb/", $avatar_file->name );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                         $is_full  = preg_match( "/-bpfull/", $avatar_file->name );
+                                               $is_thumb = preg_match( "/-bpthumb/", $avatar_file->name );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                        if ( $is_full || $is_thumb ) {
-                                               $revision = $this->add_revision(
-                                                       'avatar',
-                                                       array(
-                                                               'file_abspath' => $avatar_file->path,
-                                                               'file_id'      => $avatar_file->id,
-                                                       )
-                                               );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                         if ( $is_full || $is_thumb ) {
+                                                       $revision = $this->add_revision(
+                                                               'avatar',
+                                                               array(
+                                                                       'file_abspath' => $avatar_file->path,
+                                                                       'file_id'      => $avatar_file->id,
+                                                               )
+                                                       );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                                if ( is_wp_error( $revision ) ) {
-                                                       error_log( $revision->get_error_message() );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                                 if ( is_wp_error( $revision ) ) {
+                                                               error_log( $revision->get_error_message() );
+                                                       }
</ins><span class="cx" style="display: block; padding: 0 10px">                                                 }
</span><span class="cx" style="display: block; padding: 0 10px">                                        }
</span><span class="cx" style="display: block; padding: 0 10px">                                }
</span></span></pre>
</div>
</div>

</body>
</html>