|
11 | 11 | add_action( |
12 | 12 | 'bp_init', |
13 | 13 | function () { |
14 | | - /* |
15 | | - * Tweaks for fetching avatars and cover images -- bp_core_fetch_avatar() and bp_attachments_get_attachment(). |
16 | | - */ |
| 14 | + // Tweaks for fetching avatars and cover images -- bp_core_fetch_avatar() and bp_attachments_get_attachment(). |
17 | 15 | add_filter( 'bp_core_avatar_folder_dir', '__return_empty_string' ); |
18 | 16 | add_filter( 'bp_core_fetch_avatar_no_grav', '__return_true' ); |
19 | 17 | add_filter( 'bp_core_default_avatar_user', 'vipbp_filter_user_avatar_urls', 10, 2 ); |
20 | 18 | add_filter( 'bp_core_default_avatar_group', 'vipbp_filter_group_avatar_urls', 10, 2 ); |
21 | 19 | add_filter( 'bp_attachments_pre_get_attachment', 'vipbp_filter_get_cover_image', 10, 2 ); |
22 | 20 |
|
23 | | - /* |
24 | | - * Tweaks for uploading user and group avatars -- bp_core_avatar_handle_upload(). |
25 | | - */ |
| 21 | + // Tweaks for uploading user and group avatars -- bp_core_avatar_handle_upload(). |
26 | 22 | add_filter( 'bp_core_pre_avatar_handle_upload', 'vipbp_handle_avatar_upload', 10, 3 ); |
27 | 23 | add_filter( 'bp_avatar_pre_handle_capture', 'vipbp_handle_avatar_capture', 10, 3 ); |
28 | 24 |
|
29 | | - /* |
30 | | - * Tweaks for uploading cover images -- bp_attachments_cover_image_ajax_upload(). |
31 | | - */ |
| 25 | + // Tweaks for uploading cover images -- bp_attachments_cover_image_ajax_upload(). |
32 | 26 | add_filter( 'bp_attachments_pre_cover_image_ajax_upload', 'vip_handle_cover_image_upload', 10, 4 ); |
33 | 27 |
|
34 | | - /* |
35 | | - * Tweaks for cropping user and group avatars -- bp_core_avatar_handle_crop(). |
36 | | - */ |
| 28 | + // Tweaks for cropping user and group avatars -- bp_core_avatar_handle_crop(). |
37 | 29 | add_filter( 'bp_core_pre_avatar_handle_crop', 'vipbp_handle_avatar_crop', 10, 2 ); |
38 | 30 |
|
39 | | - /* |
40 | | - * Tweaks for deleting avatars and cover images -- bp_core_delete_existing_avatar() and bp_attachments_delete_file(). |
41 | | - */ |
| 31 | + // Tweaks for deleting avatars and cover images -- bp_core_delete_existing_avatar() and bp_attachments_delete_file(). |
42 | 32 | add_filter( 'bp_core_pre_delete_existing_avatar', 'vipbp_delete_existing_avatar', 10, 2 ); |
43 | 33 | add_filter( 'bp_attachments_pre_delete_file', 'vipbp_delete_cover_image', 10, 2 ); |
| 34 | + |
| 35 | + // Tweaks for uploading videos into groups. |
| 36 | + add_filter( 'bp_core_pre_remove_temp_directory', 'vipbp_override_remove_temp_directory', 10, 3 ); |
| 37 | + |
| 38 | + // Tweaks for flushing the cache after moving a video. |
| 39 | + add_action( 'bp_video_after_save', 'vipbp_flush_cache_after_video_move', 99 ); |
44 | 40 | } |
45 | 41 | ); |
46 | 42 |
|
@@ -789,3 +785,35 @@ function vipbp_delete_cover_image( $_, $args ) { |
789 | 785 |
|
790 | 786 | return false; |
791 | 787 | } |
| 788 | + |
| 789 | +/** |
| 790 | + * Override bp_core_remove_temp_directory on VIP to use WP_Filesystem. |
| 791 | + * |
| 792 | + * @param bool $override Whether to override the default behavior. |
| 793 | + * @param string $directory The directory to remove. |
| 794 | + * @param string $image_name The name of the image file to delete. |
| 795 | + * |
| 796 | + * @return bool True if overridden on VIP, otherwise false. |
| 797 | + */ |
| 798 | +function vipbp_override_remove_temp_directory( $override, $directory, $image_name ) { |
| 799 | + $file_path = trailingslashit( $directory ) . $image_name . '.jpg'; |
| 800 | + |
| 801 | + if ( file_exists( $file_path ) ) { |
| 802 | + // Skip default directory deletion logic. |
| 803 | + wp_delete_file( $file_path ); |
| 804 | + return true; |
| 805 | + } |
| 806 | + |
| 807 | + // Continue with default behavior. |
| 808 | + return false; |
| 809 | +} |
| 810 | + |
| 811 | +/** |
| 812 | + * Flush the media cache after a video has been moved to an album. |
| 813 | + * |
| 814 | + * This function resets the BuddyPress media incrementor to ensure that |
| 815 | + * any cached media data is invalidated after a video is moved. |
| 816 | + */ |
| 817 | +function vipbp_flush_cache_after_video_move() { |
| 818 | + bp_core_reset_incrementor( 'bp_media' ); |
| 819 | +} |
0 commit comments