Replies
Hi Brajesh
The code worked, it has been further improved to limit based of membership count and work only on bp_is_register_page() can you please review it
<?php /* * Plugin Name: BuddyPress Registration Control * Description: Allows administrators to enable or disable user registration and select a URL to redirect to when registration is disabled. * Version: 1.0 */ // Register the new setting in the BuddyPress options group function custom_bp_register_settings() { register_setting( 'buddypress', 'bp-disable-site-registration', 'sanitize_text_field' ); register_setting( 'buddypress', 'bp-disable-site-registration-redirection-url', 'sanitize_text_field' ); register_setting( 'buddypress', 'bp-close-registration-at-users', 'intval' ); // added this line } add_action( 'bp_register_admin_settings', 'custom_bp_register_settings' ); // Add the new setting to the BuddyPress options page function custom_bp_add_settings_field() { add_settings_field( 'bp-disable-site-registration', __( 'Registration', 'buddypress' ), 'custom_bp_settings_field_html', 'buddypress', 'bp_main', array( 'label_for' => 'bp-disable-site-registration', ) ); add_settings_field( 'bp-disable-site-registration-redirection-url', __( 'Redirection URL', 'buddypress' ), 'custom_bp_settings_redirection_url_html', 'buddypress', 'bp_main', array( 'label_for' => 'bp-disable-site-registration-redirection-url', ) ); add_settings_field( // added this block 'bp-close-registration-at-users', __( 'Limit User Registration Count', 'buddypress' ), 'custom_bp_close_registration_at_users_html', 'buddypress', 'bp_main', array( 'label_for' => 'bp-close-registration-at-users', ) ); } add_action( 'bp_register_admin_settings', 'custom_bp_add_settings_field', 10, 1 ); // Output the HTML for the setting field function custom_bp_settings_field_html() { $value = get_option( 'bp-disable-site-registration', 'open' ); ?> <select name="bp-disable-site-registration" id="bp-disable-site-registration"> <option value="open" <?php selected( $value, 'open' ); ?>><?php _e( 'Open', 'buddypress' ); ?></option> <option value="closed" <?php selected( $value, 'closed' ); ?>><?php _e( 'Closed', 'buddypress' ); ?></option> </select> <?php } // Output the HTML for the redirection URL field function custom_bp_settings_redirection_url_html() { $value = get_option( 'bp-disable-site-registration-redirection-url' ); ?> <input type="text" name="bp-disable-site-registration-redirection-url" id="bp-disable-site-registration-redirection-url" value="<?php echo esc_attr( $value ); ?>" /> <?php } // Output the HTML for the close registration at users field // added this function function custom_bp_close_registration_at_users_html() { $value = get_option( 'bp-close-registration-at-users' ); ?> <input type="number" name="bp-close-registration-at-users" id="bp-close-registration-at-users" value="<?php echo esc_attr( $value ); ?>" /> <p class="description"><?php _e( 'Close registration when the total number of users reaches this number.', 'buddypress' ); ?></p> <?php } // Redirect users if registration is closed function custom_bp_redirect_registration() { $total_users = count_users(); // added this line $total_users = $total_users['total_users']; // added this line if ( bp_is_register_page() && ( get_option( 'bp-disable-site-registration' ) === 'closed' || $total_users >= get_option( 'bp-close-registration-at-users' ) ) ) { // modified this line wp_redirect( get_option( 'bp-disable-site-registration-redirection-url' ) ); exit; } } add_action( 'bp_screens', 'custom_bp_redirect_registration' );
What im trying to achieve is instead of using the default wordpress settings option to disable registrations (Anyone can register). I want to leave this default option enabled but disable buddypress registration using page redirection
when user tries to access (sign-up) page redirect the user to (coming-soon) page
Thanks this is now resolved
Thanks Brajesh
This worked
add_action( 'bp_activity_entry_meta', function () { global $activities_template; // Check if the current activity's user is the logged in user if ( bp_get_activity_user_id() === get_current_user_id() ) { // Check if the activity type is 'new_classified' if ( 'new_classified' === $activities_template->activity->type ) { echo '<a href="https://www.nigerpress.com/manage-listings/" class="advert-edit-link">Manage / Edit Ad</a>'; } } } );
- Tosin on December 21, 2022 at 2:12 pm in reply to: [Resolved] Open all external activity links in a new browser tab #47741This reply has been marked as private.
- Tosin on December 21, 2022 at 2:03 pm in reply to: [Resolved] Open all external activity links in a new browser tab #47740This reply has been marked as private.
- Tosin on December 21, 2022 at 9:07 am in reply to: [Resolved] Open all external activity links in a new browser tab #47735This reply has been marked as private.
- Tosin on December 21, 2022 at 9:05 am in reply to: [Resolved] Open all external activity links in a new browser tab #47734
What about this
function open_external_links_in_new_tab_bp_activity( $query_string, $object ) { if ( $object != 'activity' ) { return $query_string; } ?> <script type="text/javascript"> var links = document.getElementsByTagName("a"); for (var i = 0; i < links.length; i++) { var link = links[i]; if (link.hostname != window.location.hostname) { link.target = "_blank"; } } </script> <?php return $query_string; } add_filter( 'bp_ajax_querystring', 'open_external_links_in_new_tab_bp_activity', 10, 2 );
- Tosin on December 20, 2022 at 4:43 pm in reply to: [Resolved] Open all external activity links in a new browser tab #47715
I found this code
function open_external_links_in_new_tab() { echo '<script type="text/javascript">'; echo 'var links = document.getElementsByTagName("a");'; echo 'for (var i = 0; i < links.length; i++) {'; echo 'var link = links[i];'; echo 'if (link.hostname != window.location.hostname) {'; echo 'link.target = "_blank";'; echo '}'; echo '}'; echo '</script>'; } add_action( 'wp_footer', 'open_external_links_in_new_tab' );
Kindly review
- Tosin on December 20, 2022 at 4:37 pm in reply to: How to add condition to custom profile button #47714
or maybe using a profile group id 4323 to identify CONTACT DETAILS profile group
function bp_add_contact_button() { // Check if the current user is logged in if ( !is_user_logged_in() ) { return; } // Get the current user's ID $user_id = bp_displayed_user_id(); // Get the field data for the "Contact Information" profile group $field_data = bp_get_profile_group_field_data( array( 'user_id' => $user_id, 'group_id' => 4323 ) ); // Check if the "Contact Information" profile group has at least one field updated if ( !empty( $field_data ) ) { $contact_user_button_args = array( 'id' => 'contact_user', 'component' => 'members', 'must_be_logged_in' => true, 'block_self' => true, 'link_class' => 'contact-user', 'link_href' => esc_url( bp_displayed_user_domain() . bp_get_profile_slug() . '/#item-body' ), 'link_text' => __( 'Contact Me' ), ); echo bp_get_button( $contact_user_button_args ); } } add_action( 'bp_member_header_actions', 'bp_add_contact_button' );