Search Results for 'group_id'
-
Search Results
-
I have created a new group with the below code.
// Define the group details. $group_args = array( 'creator_id' => get_current_user_id(), // The ID of the user who creates the group. 'name' => 'My New Group', // Replace this with the desired group name. 'description' => 'This is a sample group created by code.', // Replace this with the group description. 'status' => 'public', // You can set the status to 'public', 'private', or 'hidden'. ); // Create the group. $group_id = groups_create_group( $group_args ); if ( ! is_wp_error( $group_id ) ) { echo 'Group created successfully. Group ID: ' . $group_id; } else { echo 'Failed to create group: ' . $group_id->get_error_message(); }I want to update the created group status from “public” to “hidden” but I cannot find the proper hook/function.
WordPress v 6.1.1
BuddyPress v 11.0.0
Theme Onecommunity (latest version 3.7.8) (https://themeforest.net/item/onecommunity-buddypress-theme/3713046?gclid=CjwKCAiAqt-dBhBcEiwATw-ggL19B1O2bH4PjCwmpFyse_KZ7o4KEGnurStZcFrqDBd1d-3rDApwZxoC22cQAvD_BwE)
My frontend test Site: https://staging-rezodenthodenthcom-staging.kinsta.cloud/Hi there!
1/ After updating my hosted site from php 7.4 to 8.0 (Kinsta hosting), buddypress causes the following critical syntax error !
2023/01/06 13:48:41 [error] 43493#43493: *668 FastCGI sent in stderr: “PHP message: PHP Parse error: syntax error, unexpected token “;”, expecting “)” in /www/rezodenthodenthcom_528 /public/wp-content/themes/onecommunity/buddypress/groups/single/group-header.php on line 29
The site (front and backend) is still visible but the groups are not displayed anymore in groups single page
Could you please be kind enough to help solving this first problem?2/ I usually use a child theme with two small custom codes that worked fine in php 7.4 but with php 8.0, I have a new FTAL error. So it appears that this function somehow is not working correctly with the child theme enabled: call_user_func_array()
From that stack trace in the Fatal error, it is referencing BuddyPress with it:
#2 /www/rezodenthodenthcom_528/public/wp-content/plugins/buddypress/bp-core/bp-core-dependency.php(407): do_action(‘bp_widgets_init’)As far as I know, our custom codes were very limited in 2 templates :
Template 1: group-sidebar.php :
WE CHANGED THIS CODE:
$group_id = bp_get_current_group_id();
echo do_shortcode( ‘[rtmedia_gallery context=”group” per_page=”6″ context_id=”5″ context_id=”‘ . $group_id . ‘”]’ );
BY THAT ONE:
if ( bp_group_is_visible() ) :
$group_id = bp_get_current_group_id();
echo do_shortcode( ‘[rtmedia_gallery context=”group” per_page=”6″ context_id=”5″ context_id=”‘ . $group_id . ‘”]’ );
endif;Template 2: group-sidebar.php (for customiszation image ads in widget column) with this code:
<div class=”bp-sidebar-details”>
<div class=”bp-sidebar-details-category first”><?php _e(‘Advertisement’, ‘onecommunity’); ?></div>
<div class=”col-1-ads”>
[widget id=”media_gallery-3″]
</div>I don’t understand what could interfere in php 8.0 environment!
What do you think about it? and could you help me to solve this second issue?Thank you for your appreciated help ; )
C. GARCIA
I want to set the group ID to “group name slug” by default.
Is there a good way to override the function “groups_create_group()” in “bp-groups/bp-groups-functions.php”?
I would like to specify an id for the slug as shown below, but do not want to modify the core file. It would be helpful if I could override it in “bp-custom.php”.
$args = bp_parse_args( $args, array( 'group_id' => 0, 'creator_id' => 0, 'name' => '', 'description' => '', 'slug' => bp_get_current_group_id(), 'status' => null, 'parent_id' => null, 'enable_forum' => null, 'date_created' => null, ), 'groups_create_group' );Topic: Join group ajax not working
I’m getting an admin-ajax 403 error when clicking the Join Group button. It seems to be the switch case in the functions. It seems to be completely ignored somehow. Logging within any of the cases returns nothing at all. Also a quick note… it’s not every group. It’s only on random ones
function bp_legacy_theme_ajax_joinleave_group() { if ( ! bp_is_post_request() ) { return; } // Cast gid as integer. $group_id = (int) $_POST['gid']; if ( groups_is_user_banned( bp_loggedin_user_id(), $group_id ) ) return; if ( ! $group = groups_get_group( $group_id ) ) return; // Client doesn't distinguish between different request types, so we infer from user status. if ( groups_is_user_member( bp_loggedin_user_id(), $group->id ) ) { $request_type = 'leave_group'; } elseif ( groups_check_user_has_invite( bp_loggedin_user_id(), $group->id ) ) { $request_type = 'accept_invite'; } elseif ( 'private' === $group->status ) { $request_type = 'request_membership'; } else { $request_type = 'join_group'; } // NOTE: WHY IS THIS BROKEN?!!? switch ( $request_type ) { case 'join_group' : if ( ! bp_current_user_can( 'groups_join_group', array( 'group_id' => $group->id ) ) ) { esc_html_e( 'Error joining group', 'buddypress' ); } check_ajax_referer( 'groups_join_group' ); if ( ! groups_join_group( $group->id ) ) { _e( 'Error joining group', 'buddypress' ); } else { echo '<a id="group-' . esc_attr( $group->id ) . '" class="group-button leave-group" rel="leave" href="' . wp_nonce_url( bp_get_group_permalink( $group ) . 'leave-group', 'groups_leave_group' ) . '">' . __( 'Leave Group', 'buddypress' ) . '</a>'; } break; case 'accept_invite' : if ( ! bp_current_user_can( 'groups_request_membership', array( 'group_id' => $group->id ) ) ) { esc_html_e( 'Error accepting invitation', 'buddypress' ); } check_ajax_referer( 'groups_accept_invite' ); if ( ! groups_accept_invite( bp_loggedin_user_id(), $group->id ) ) { _e( 'Error requesting membership', 'buddypress' ); } else { echo '<a id="group-' . esc_attr( $group->id ) . '" class="group-button leave-group" rel="leave" href="' . wp_nonce_url( bp_get_group_permalink( $group ) . 'leave-group', 'groups_leave_group' ) . '">' . __( 'Leave Group', 'buddypress' ) . '</a>'; } break; case 'request_membership' : check_ajax_referer( 'groups_request_membership' ); if ( ! groups_send_membership_request( [ 'user_id' => bp_loggedin_user_id(), 'group_id' => $group->id ] ) ) { _e( 'Error requesting membership', 'buddypress' ); } else { echo '<a id="group-' . esc_attr( $group->id ) . '" class="group-button disabled pending membership-requested" rel="membership-requested" href="' . bp_get_group_permalink( $group ) . '">' . __( 'Request Sent', 'buddypress' ) . '</a>'; } break; case 'leave_group' : check_ajax_referer( 'groups_leave_group' ); if ( ! groups_leave_group( $group->id ) ) { _e( 'Error leaving group', 'buddypress' ); } elseif ( 'public' === $group->status ) { echo '<a id="group-' . esc_attr( $group->id ) . '" class="group-button join-group btn" rel="join" href="' . wp_nonce_url( bp_get_group_permalink( $group ) . 'join', 'groups_join_group' ) . '">' . __( 'Join Group', 'buddypress' ) . '</a>'; } else { echo '<a id="group-' . esc_attr( $group->id ) . '" class="group-button request-membership" rel="join" href="' . wp_nonce_url( bp_get_group_permalink( $group ) . 'request-membership', 'groups_request_membership' ) . '">' . __( 'Request Membership', 'buddypress' ) . '</a>'; } break; } exit; }Hi
How can I find the meta names of the extra fields on the extended profile? I create extra fields but I don’t know their names, just id and group_id.
I need meta names so I can use other plugins for registration, for example, or for PODS.
By the way, PODS doesn’t seem to see the extended profile fields anywhere…I use gravity forms to create a new user from a groups tab and assign them to a group, based on the group that the group admin is adding them from. This was working just fine in BuddyPress version 8.0 but since upgrading to 10 it is no longer working. What am I missing?
/** * Add member form handler. This form is currently located under the Group Information tab */ add_action( 'gform_after_submission', 'add_member_gform_handle', 10, 2 ); function add_member_gform_handle( $entry, $form ) { if ( $form['title'] === 'Add Member' ) { $fields = $form['fields']; $first_name = rgar( $entry, '1' ); $last_name = rgar( $entry, '2' ); $login = rgar( $entry, '3' ); $password = rgar( $entry, '4' ); $email = rgar( $entry, '5' ); $group_id = rgar( $entry, '6' ); $role = rgar( $entry, '11' ); $notification = rgar( $entry, '9.1' ); $birthdate = rgar( $entry, '10' ); $userdata = array( 'user_login' => $login, 'user_pass' => $password, ); if ( ! empty( $first_name ) ) { $userdata['first_name'] = $first_name; } if ( ! empty( $last_name ) ) { $userdata['last_name'] = $last_name; } if ( ! empty( $email ) ) { $userdata['user_email'] = $email; } if ( ! empty( $role ) ) { $userdata['role'] = $role; } // Create a new user $new_user_id = wp_insert_user( $userdata ); // GFCommon::log_debug( __METHOD__ . '(): form => ' . print_r( $birthdate, true ) ); if ( ! is_wp_error( $new_user_id ) ) { groups_join_group( $group_id, $new_user_id ); // Make the user displayed as a staff on a clubhouse page if ( $role === 'staff' ) { $group_ids = groups_get_user_groups( $new_user_id ); $group = groups_get_group( array( 'group_id' => $group_ids['groups'][0]) ); $group_id = $group->id; groups_promote_member( $new_user_id, $group_id, 'admin' ); } else { groups_demote_member( $new_user_id, $group_id ); } if ( ! empty( $notification ) ) { tml_send_new_user_notifications( $new_user_id, 'both' ); } if ( ! empty( $birthdate ) ) { $date = DateTime::createFromFormat('Y-m-d', $birthdate); $date = $date->format('Ymd'); update_field('user_birthdate', $date, 'user_' . $new_user_id); } } // Delete form entry // GFAPI::delete_entry( $entry['id'] ); } } /** * Add Member form validation */ add_filter( "gform_validation_$clubnet_add_member_form_id", 'add_member_form_validation' ); function add_member_form_validation( $validation_result ) { $form = $validation_result['form']; $login = rgpost( 'input_3' ); $email = rgpost( 'input_5' ); $send_notificaton = rgpost( 'input_9_1' ); if ( ! empty( $login ) && get_user_by( 'login', $login ) ) { $validation_result['is_valid'] = false; //finding Field with ID and marking it as failed validation foreach( $form['fields'] as &$field ) { if ( $field->id == '3' ) { $field->failed_validation = true; $field->validation_message = 'The user with this login already exists.'; break; } } // foreach } if ( ! empty( $email ) && get_user_by( 'email', $email ) ) { $validation_result['is_valid'] = false; //finding Field with ID and marking it as failed validation foreach( $form['fields'] as &$field ) { if ( $field->id == '5' ) { $field->failed_validation = true; $field->validation_message = 'The user with this email already exists.'; break; } } // foreach } // GFCommon::log_debug( 'VALIDATION' . __METHOD__ . '(): form => ' . print_r( 'Empty', true ) ); // Email is required if we requested to send a email about user's account if ( ! empty( $send_notificaton ) && empty( $email ) ) { $validation_result['is_valid'] = false; //finding Field with ID and marking it as failed validation foreach( $form['fields'] as &$field ) { if ( $field->id == '5' ) { $field->failed_validation = true; $field->validation_message = 'Email is required since you requested to send an email.'; break; } } // foreach } //Assign modified $form object back to the validation result $validation_result['form'] = $form; return $validation_result; } /** * Role field */ add_action( 'init', 'clubnet_add_role_field' ); function clubnet_add_role_field( $form ) { global $wp_roles; global $clubnet_add_member_form_id; $all_roles = $wp_roles->roles; // $editable_roles = apply_filters('editable_roles', $all_roles); // $roles_to_skip = array( 'administrator' ); $editable_roles = $all_roles; $roles_to_display = array( 'mentor', 'member', 'youth_leader', 'alumni', 'staff' ); $choices = array(); foreach ( $editable_roles as $role => $role_data ) { if ( ! in_array( $role, $roles_to_display ) ) { continue; } $choice = array( 'text' => $role_data['name'], 'value' => $role ); array_push( $choices, $choice ); } // Reorder to make member role first usort( $choices, function( $choice ) { if ( $choice['text'] === 'Member' ) { return -1; } return 1; } ); $form = GFAPI::get_form( $clubnet_add_member_form_id ); if ( ! $form ) { return; } $label = 'User Role'; $field_idx = -1; $field_id = -1; foreach ($form['fields'] as $idx => $field) { if ( $field->label === $label ) { $field_idx = $idx; $field_id = $field->id; } } if ( $field_idx === -1 ) { $field_id = GFFormsModel::get_next_field_id( $form['fields'] ); } $props = array( 'id' => $field_id, 'label' => $label, 'type' => 'select', 'choices' => $choices, ); if ( $field_idx === -1 ) { $field = GF_Fields::create( $props ); $form['fields'][] = $field; GFAPI::update_form( $form ); } else if ( $form['fields'][$field_idx]->choices !== $choices ) { $field = GF_Fields::create( $props ); $form['fields'][$field_idx] = $field; GFAPI::update_form( $form ); } }Topic: Get group ID from slug
I am trying to add a user to a group when they register to an event with event espresso. My code fires when a user successfully registers to the event. I can get the slug (which I assume is the post_name), but I just can’t seem to get the group id from that slug.
I have tried multiple different ways, but I’m not overly experienced, so would really appreciate some help.
$slug is successfully set to a string ‘capital-football-c-license-2022’
Have tried:
$group_id = BP_Groups_Group::get_id_from_slug($slug); //$group_id is empty
$group = groups_get_group(array(‘slug’ => $slug)); //$group is emptyI know the slug is correct as it matches the ‘slug’ field in BP_GROUPS in my database.
Any help appreciated!