Ticket #8617: 8617.patch
File 8617.patch, 9.4 KB (added by , 3 years ago) |
---|
-
src/bp-activity/bp-activity-functions.php
diff --git src/bp-activity/bp-activity-functions.php src/bp-activity/bp-activity-functions.php index 91c1fa519..137e4ccfd 100644
function bp_activity_get_post_types_tracking_args() { 631 631 return apply_filters( 'bp_activity_get_post_types_tracking_args', $post_types_tracking_args ); 632 632 } 633 633 634 /** 635 * Gets the list of activity types name supporting the requested feature. 636 * 637 * This function is still a WIP, please don't use it into your plugins or themes. 638 * 639 * @since 10.0.0 640 * 641 * @access private 642 * @todo `bp_activity_set_action()` should be improved to include a supports 643 * argument or best we should create a `bp_register_activity_type()` function 644 * to mimic the way WordPress registers post types. For now we'll use a non 645 * extendable workaround. 646 * 647 * @param string $feature The feature activity types should support. 648 * @return array The list of activity types name supporting the requested feature. 649 */ 650 function _bp_activity_get_types_by_support( $feature = 'generated-content' ) { 651 $activity_types = array(); 652 653 if ( 'generated-content' === $feature ) { 654 $activity_types = array( 'new_member', 'new_avatar' ); 655 656 if ( bp_is_active( 'friends' ) ) { 657 array_push( $activity_types, 'friendship_created' ); 658 } 659 660 if ( bp_is_active( 'groups' ) ) { 661 array_push( $activity_types, 'created_group', 'joined_group' ); 662 } 663 664 if ( bp_is_active( 'xprofile' ) ) { 665 array_push( $activity_types, 'updated_profile' ); 666 } 667 } 668 669 $filter_key = str_replace( '-', '_', $feature ); 670 671 /** 672 * Use this filter to add/remove activity types supporting the requested feature. 673 * 674 * The dynamic portion of the filter is the name of the requested feature where hyphens are 675 * replaced by underscores. Eg. use `bp_activity_get_types_supporting_generated_content` to 676 * edit the list of activities supporting the `generated-content` feature. 677 * 678 * @since 10.0.0 679 * 680 * @param array $activity_types The list of activity types name supporting the requested feature. 681 */ 682 return apply_filters( "bp_activity_get_types_supporting_{$filter_key}", $activity_types ); 683 } 684 634 685 /** 635 686 * Check if the *Post Type* activity supports a specific feature. 636 687 * … … function bp_activity_type_supports( $activity_type = '', $feature = '' ) { 714 765 * Does this activity type support `generated-content`? 715 766 */ 716 767 case 'generated-content' : 717 /* 718 * @todo `bp_activity_set_action()` should be improved to include a supports 719 * argument or best we should create a `bp_register_activity_type()` function 720 * to mimic the way WordPress registers post types. For now we'll use a non 721 * extendable workaround. 722 */ 723 $activity_types = array( 'new_member', 'new_avatar' ); 724 725 if ( bp_is_active( 'friends' ) ) { 726 array_push( $activity_types, 'friendship_created' ); 727 } 728 729 if ( bp_is_active( 'groups' ) ) { 730 array_push( $activity_types, 'created_group', 'joined_group' ); 731 } 732 733 if ( bp_is_active( 'xprofile' ) ) { 734 array_push( $activity_types, 'updated_profile' ); 735 } 768 $activity_types = _bp_activity_get_types_by_support( 'generated-content' ); 736 769 737 770 $retval = in_array( $activity_type, $activity_types, true ); 738 771 break; -
src/bp-activity/bp-activity-template.php
diff --git src/bp-activity/bp-activity-template.php src/bp-activity/bp-activity-template.php index 52f074202..8165d22ca 100644
function bp_activity_has_content() { 1462 1462 1463 1463 // Set generated content properties. 1464 1464 if ( 'new_avatar' === $activity_type ) { 1465 $avatars = bp_avatar_get_version( $user_id, 'user', bp_get_activity_date_recorded());1465 $avatars = array(); 1466 1466 1467 if ( $avatars && 1 === count( $avatars ) ) {1468 $avatar = reset( $avatars );1469 $ historical_avatar = trailingslashit( $avatar->parent_dir_url ) . $avatar->name;1467 // Use the avatar history to display the avatar that was in use at the time the activity was posted. 1468 if ( ! bp_avatar_history_is_disabled() ) { 1469 $avatars = bp_avatar_get_version( $user_id, 'user', bp_get_activity_date_recorded() ); 1470 1470 1471 // Add historical avatar to the current activity. 1471 if ( $avatars && 1 === count( $avatars ) ) { 1472 $avatar = reset( $avatars ); 1473 $historical_avatar = trailingslashit( $avatar->parent_dir_url ) . $avatar->name; 1474 1475 // Add historical avatar to the current activity. 1476 $generated_content->user_profile_photo = array( 1477 'value' => $historical_avatar, 1478 'sanitize_callback' => 'esc_url', 1479 ); 1480 } 1481 1482 // Otherwise use the current/latest avatar. 1483 } else { 1472 1484 $generated_content->user_profile_photo = array( 1473 'value' => $historical_avatar, 1485 'value' => bp_core_fetch_avatar( 1486 array( 1487 'item_id' => $user_id, 1488 'object' => 'user', 1489 'type' => 'full', 1490 'width' => bp_core_avatar_full_width(), 1491 'height' => bp_core_avatar_full_height(), 1492 'html' => false, 1493 ) 1494 ), 1474 1495 'sanitize_callback' => 'esc_url', 1475 1496 ); 1476 1477 // Do not use a generated content.1478 } else {1479 return false;1480 1497 } 1481 1498 } 1482 1499 -
src/bp-core/bp-core-attachments.php
diff --git src/bp-core/bp-core-attachments.php src/bp-core/bp-core-attachments.php index 66e8dd2bb..8a4c1dab2 100644
function bp_attachments_enqueue_scripts( $class = '' ) { 815 815 ), 816 816 ); 817 817 818 if ( 'user' === $object ) { 818 // Add the recycle view if avatar history is enabled. 819 if ( 'user' === $object && ! bp_avatar_history_is_disabled() ) { 819 820 // Look inside history to see if the user previously uploaded avatars. 820 821 $avatars_history = bp_avatar_get_avatars_history( $item_id, $object ); 821 822 -
src/bp-core/bp-core-avatars.php
diff --git src/bp-core/bp-core-avatars.php src/bp-core/bp-core-avatars.php index f0abaec6a..8f264f607 100644
function bp_avatar_template_check() { 2149 2149 } 2150 2150 } 2151 2151 2152 /** 2153 * Informs about whether avatar history is disabled or not. 2154 * 2155 * @since 10.0.0 2156 * 2157 * @return bool True if avatar history is disabled. False otherwise. 2158 * Default: `false`. 2159 */ 2160 function bp_avatar_history_is_disabled() { 2161 /** 2162 * Filter here returning `true` to disable avatar history. 2163 * 2164 * @since 10.0.0 2165 * 2166 * @param bool $value True to disable avatar history. False otherwise. 2167 * Default: `false`. 2168 */ 2169 return apply_filters( 'bp_disable_avatar_history', false ); 2170 } 2171 2152 2172 /** 2153 2173 * Get a specific version of an avatar from its history. 2154 2174 * -
src/bp-core/classes/class-bp-attachment-avatar.php
diff --git src/bp-core/classes/class-bp-attachment-avatar.php src/bp-core/classes/class-bp-attachment-avatar.php index 2887f33e2..21bfedd94 100644
class BP_Attachment_Avatar extends BP_Attachment { 246 246 return false; 247 247 } 248 248 249 // Delete the existing avatar files for the object. 250 $existing_avatar = bp_core_fetch_avatar( array( 251 'object' => $args['object'], 252 'item_id' => $args['item_id'], 253 'html' => false, 254 ) ); 249 // Get the existing avatar files for the object. 250 $existing_avatar = bp_core_fetch_avatar( 251 array( 252 'object' => $args['object'], 253 'item_id' => $args['item_id'], 254 'html' => false, 255 ) 256 ); 255 257 256 258 /** 257 259 * Check that the new avatar doesn't have the same name as the 258 260 * old one before moving the previous one into history. 259 261 */ 260 262 if ( ! empty( $existing_avatar ) && $existing_avatar !== $this->url . $relative_path ) { 261 // Add a new revision for the existing avatar. 262 $avatars = bp_attachments_list_directory_files( $avatar_folder_dir ); 263 264 if ( $avatars ) { 265 foreach ( $avatars as $avatar_file ) { 266 if ( ! isset( $avatar_file->name, $avatar_file->id, $avatar_file->path ) ) { 267 continue; 268 } 269 270 $is_full = preg_match( "/-bpfull/", $avatar_file->name ); 271 $is_thumb = preg_match( "/-bpthumb/", $avatar_file->name ); 263 // Avatar history is disabled, simply delete the existing avatar files. 264 if ( bp_avatar_history_is_disabled() ) { 265 bp_core_delete_existing_avatar( 266 array( 267 'object' => $args['object'], 268 'item_id' => $args['item_id'], 269 'avatar_path' => $avatar_folder_dir, 270 ) 271 ); 272 } else { 273 // Add a new revision for the existing avatar. 274 $avatars = bp_attachments_list_directory_files( $avatar_folder_dir ); 272 275 273 if ( $is_full || $is_thumb ) { 274 $revision = $this->add_revision( 275 'avatar', 276 array( 277 'file_abspath' => $avatar_file->path, 278 'file_id' => $avatar_file->id, 279 ) 280 ); 276 if ( $avatars ) { 277 foreach ( $avatars as $avatar_file ) { 278 if ( ! isset( $avatar_file->name, $avatar_file->id, $avatar_file->path ) ) { 279 continue; 280 } 281 281 282 if ( is_wp_error( $revision ) ) { 283 error_log( $revision->get_error_message() ); 282 $is_full = preg_match( "/-bpfull/", $avatar_file->name ); 283 $is_thumb = preg_match( "/-bpthumb/", $avatar_file->name ); 284 285 if ( $is_full || $is_thumb ) { 286 $revision = $this->add_revision( 287 'avatar', 288 array( 289 'file_abspath' => $avatar_file->path, 290 'file_id' => $avatar_file->id, 291 ) 292 ); 293 294 if ( is_wp_error( $revision ) ) { 295 error_log( $revision->get_error_message() ); 296 } 284 297 } 285 298 } 286 299 }