Skip to content
This repository was archived by the owner on Jan 22, 2026. It is now read-only.

Commit 625b818

Browse files
author
Mitesh
committed
add rtm_add_watermark_bp_group.php
1 parent b23ba70 commit 625b818

1 file changed

Lines changed: 65 additions & 0 deletions

File tree

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
/**
3+
* This snippets is allows you to add watermark on buddypress group avatar and cover-image.
4+
*
5+
* Add this code snippet to end of theme's functions.php file
6+
*/
7+
8+
if ( ! function_exists( 'is_plugin_active' ) ) {
9+
include_once ABSPATH . 'wp-admin/includes/plugin.php';
10+
}
11+
12+
if ( ( is_plugin_active( 'buddypress-media/index.php' ) || is_plugin_active( 'rtMedia/index.php' ) ) && is_plugin_active( 'rtmedia-photo-watermak/index.php' ) ) {
13+
if ( ! function_exists( 'rtm_groups_cover_image_uploaded' ) ) {
14+
15+
/**
16+
* Add watermark to BuddyPress group cover-image after successful completion of upload.
17+
*
18+
* @param Integer $item_id BuddyPress Component ID.
19+
*/
20+
function rtm_groups_cover_image_uploaded( $item_id ) {
21+
$abspath = bp_attachments_get_attachment(
22+
'path', array(
23+
'object_dir' => 'groups',
24+
'item_id' => $item_id,
25+
'type' => 'cover-image',
26+
'file' => '',
27+
)
28+
);
29+
$callwatermark = new RTMediaWatermarkProcessor();
30+
$callwatermark->add_watermark( $abspath, 'rt_media_featured_image' );
31+
}
32+
add_action( 'groups_cover_image_uploaded', 'rtm_groups_cover_image_uploaded', 999, 1 );
33+
}
34+
35+
if ( ! function_exists( 'rtm_groups_avatar_uploaded' ) ) {
36+
37+
/**
38+
* Add watermark to BuddyPress group avatar after successful completion of upload.
39+
*
40+
* @param Integer $item_id BuddyPress Component ID.
41+
*/
42+
function rtm_groups_avatar_uploaded( $item_id ) {
43+
$upload_dir = wp_upload_dir();
44+
$basedir = $upload_dir['basedir'];
45+
$abspath = $basedir . '/group-avatars/' . $item_id . '/';
46+
$callwatermark = new RTMediaWatermarkProcessor();
47+
48+
if ( is_dir( $abspath ) ) {
49+
$dh = opendir( $abspath );
50+
if ( $dh ) {
51+
$file = readdir( $dh );
52+
while ( false !== $file ) {
53+
$file_path = $abspath . $file;
54+
if ( is_file( $file_path ) ) {
55+
$callwatermark->add_watermark( $file_path, 'rt_media_thumbnail' );
56+
}
57+
$file = readdir( $dh );
58+
}
59+
closedir( $dh );
60+
}
61+
}
62+
}
63+
add_action( 'groups_avatar_uploaded', 'rtm_groups_avatar_uploaded', 999, 1 );
64+
}
65+
}

0 commit comments

Comments
 (0)