Last active
February 11, 2026 19:50
-
-
Save yuriinalivaiko/dbbad498fe2a2479b74d632463144efb to your computer and use it in GitHub Desktop.
Code snippets for the "Groups" extension
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // Delete group discussion posts after 6 months. | |
| add_action( 'um_daily_scheduled_events', 'um_groups_autodelete' ); | |
| function um_groups_autodelete() { | |
| $args = array( | |
| 'post_type' => 'um_groups_discussion', | |
| 'fields' => 'ids', | |
| 'numberposts' => -1, | |
| 'date_query' => array( | |
| array( | |
| 'before' => '6 months ago', | |
| ), | |
| ), | |
| ); | |
| $posts = get_posts( $args ); | |
| foreach ( $posts as $post_id ) { | |
| wp_delete_post( $post_id, true ); | |
| } | |
| return $posts; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // Enable Invites search for new groups by default. | |
| add_action( 'um_groups_after_front_insert', 'um_groups_invites_search_on', 10, 2 ); | |
| function um_groups_invites_search_on( $formdata, $group_id ) { | |
| if ( ! empty( $formdata['invites_settings'] ) ) { | |
| add_post_meta( $group_id, '_um_groups_invites_search', 1 ); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Dispatch the "Groups - New post" email notification. | |
| * Instead of sending multiple emails, include all recipients in the "Bcc" header. | |
| * | |
| * This function replaces the default `um_groups_send_notification_to_group_members` function. | |
| * | |
| * @global wpdb $wpdb | |
| * @param int $post_id The group discussion post ID. | |
| * @param int $author_id The group discussion post author ID. | |
| */ | |
| function my_um_groups_send_notification_to_group_members( $post_id, $author_id ) { | |
| global $wpdb; | |
| $option = UM()->options()->get( 'groups_new_post_on' ); | |
| if ( ! $option ) { | |
| return; | |
| } | |
| $table_name = UM()->Groups()->setup()->db_groups_table; | |
| $group_id = get_post_meta( $post_id, '_group_id', true ); | |
| $members = $wpdb->get_col( "SELECT user_id1 FROM $table_name WHERE group_id = $group_id AND `status` = 'approved'" ); | |
| foreach ( $members as $i => $member_id ) { | |
| if ( absint( $author_id ) === absint( $member_id ) ) { | |
| unset( $members[ $i ] ); | |
| continue; | |
| } | |
| if ( ! UM()->Groups()->api()->enabled_email( $member_id, 'um_group_post_notification' ) ) { | |
| unset( $members[ $i ] ); | |
| continue; | |
| } | |
| } | |
| if ( empty( $members ) ) { | |
| return; | |
| } | |
| um_fetch_user( $author_id ); | |
| $author_name = um_user( 'display_name' ); | |
| $author_photo = um_get_avatar_url( get_avatar( $author_id, 40 ) ); | |
| $group_name = ucwords( get_the_title( $group_id ) ); | |
| $group_url = get_the_permalink( $group_id ); | |
| $group_url_postid = "$group_url#postid-$post_id"; | |
| $post_url = UM()->Groups()->discussion()->get_permalink( $post_id ); | |
| $content = get_post_meta( $post_id, '_original_content', true ); | |
| $member_id = array_pop( $members ); | |
| $member_data = get_userdata( $member_id ); | |
| $member_address = $member_data->user_email; | |
| // email notification | |
| $mail_args = array( | |
| $member_address, | |
| 'groups_new_post', | |
| array( | |
| 'members' => $members, | |
| 'path' => um_groups_path . 'templates/email/', | |
| 'tags' => array( | |
| '{group_name}', | |
| '{group_url}', | |
| '{group_url_postid}', | |
| '{post_url}', | |
| '{author_name}', | |
| '{author_photo}', | |
| '{content}', | |
| ), | |
| 'tags_replace' => array( | |
| $group_name, | |
| $group_url, | |
| $group_url_postid, | |
| $post_url, | |
| $author_name, | |
| $author_photo, | |
| $content, | |
| ), | |
| ), | |
| ); | |
| UM()->maybe_action_scheduler()->enqueue_async_action( 'um_dispatch_email', $mail_args ); | |
| } | |
| add_action( 'um_groups_after_wall_post_published', 'my_um_groups_send_notification_to_group_members', 50, 2 ); | |
| remove_action( 'um_groups_after_wall_post_published', 'um_groups_send_notification_to_group_members', 50 ); | |
| /** | |
| * Add the "Bcc" header to the "Groups - New post" email template. | |
| * | |
| * @param string $message Email content. | |
| * @param string $template Email template. | |
| * @param arrat $args Arguments for sending email. | |
| */ | |
| function my_um_email_groups_new_post( $message, $template, $args ) { | |
| if ( 'groups_new_post' === $template && ! empty( $args['members'] ) ) { | |
| $bcc = array(); | |
| foreach( $args['members'] as $member_id ) { | |
| $member_data = get_userdata( $member_id ); | |
| if ( $member_data ) { | |
| $bcc[] = $member_data->user_email; | |
| } | |
| } | |
| UM()->mail()->headers .= 'Bcc: ' . implode( ',', $bcc ) . "\r\n"; | |
| } | |
| return $message; | |
| } | |
| add_filter( 'um_email_send_message_content', 'my_um_email_groups_new_post', 10, 3 ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // Display groups directory tabs with the "Create a Group" link in the "Groups" profile tab. | |
| add_action( 'um_profile_content_groups_list', 'um_profile_content_groups_directory_tabs', 8 ); | |
| function um_profile_content_groups_directory_tabs () { | |
| $filter = get_query_var( 'filter' ); | |
| $t_args = compact( 'filter' ); | |
| UM()->get_template( 'directory/directory-tabs.php', um_groups_plugin, $t_args, true ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment