bp_member_type_permissions_metabox( WP_Post $post )

Generate Profile Type Permissions Meta box.

Description

Parameters

$post

(Required)

Source

File: bp-core/admin/bp-core-admin-functions.php

function bp_member_type_permissions_metabox( $post ) {

	$meta = get_post_custom( $post->ID );
	?><?php
	$enable_filter = isset( $meta['_bp_member_type_enable_filter'] ) ? $meta['_bp_member_type_enable_filter'][0] : 0; //disabled by default
	?>

	<table class="widefat bp-postbox-table">
		<thead>
		<tr>
			<th scope="col" colspan="2">
				<?php _e( 'Members Directory', 'buddyboss' ); ?>
			</th>
		</tr>
		</thead>
		<tbody>
		<tr>
			<td colspan="2">
				<input type='checkbox' name='bp-member-type[enable_filter]' value='1' <?php checked( $enable_filter,
					1 ); ?> />
				<?php _e( 'Display this profile type in "Types" filter in Members Directory', 'buddyboss' ); ?>
			</td>
		</tr>
		<tr>
			<td colspan="2">
				<?php
				$enable_remove = isset( $meta['_bp_member_type_enable_remove'] ) ? $meta['_bp_member_type_enable_remove'][0] : 0; //enabled by default
				?>
				<input type='checkbox' name='bp-member-type[enable_remove]' value='1' <?php checked( $enable_remove,
					1 ); ?> />
				<?php _e( 'Hide all members of this type from Members Directory', 'buddyboss' ); ?>
			</td>
		</tr>
		</tbody>
	</table>

	<?php
	if ( bp_is_active( 'groups' ) && false === bp_restrict_group_creation() ) {
		$get_all_registered_group_types = bp_get_active_group_types();
		// Add meta box if group types is entered.
		if ( true === bp_disable_group_type_creation() && isset( $get_all_registered_group_types ) && ! empty( $get_all_registered_group_types ) ) {
			// When profile types and group types are enabled, admins may restrict individual profile types from creating specified group types.
			?>
			<table class="widefat bp-postbox-table">
				<thead>
				<tr>
					<th colspan="2">
						<?php _e( 'Group Type Creation', 'buddyboss' ); ?>
					</th>
				</tr>
				</thead>
				<tbody>
				<tr>
					<td colspan="2">
						<?php _e( 'Select which group types this profile type is allowed to create. (Leave all unchecked to allow creation of any group type.)',
							'buddyboss' ); ?>
					</td>
				</tr>

				<?php

				$get_all_registered_group_types = bp_get_active_group_types();

				$get_selected_group_types = get_post_meta( $post->ID,
					'_bp_member_type_enabled_group_type_create',
					true ) ?: [];

				?>

				<tr>
					<td colspan="2">
						<input class="group-type-checkboxes" type='checkbox' name='bp-group-type[]' value='<?php echo esc_attr( 'none' ); ?>' <?php checked( in_array( 'none',
							$get_selected_group_types ) ); ?> /> <?php _e( '(None)', 'buddyboss' ); ?>
					</td>
				</tr>

				<?php

				foreach ( $get_all_registered_group_types as $group_type_id ) {

					$group_type_key = get_post_meta( $group_type_id, '_bp_group_type_key', true );
					$group_type_label = bp_groups_get_group_type_object( $group_type_key )->labels['name'];
					?>

					<tr>
						<td colspan="2">
							<input class="group-type-checkboxes" type='checkbox' name='bp-group-type[]' value='<?php echo esc_attr( $group_type_key ); ?>' <?php checked( in_array( $group_type_key,
								$get_selected_group_types ) ); ?> /> <?php echo $group_type_label; ?>
						</td>
					</tr>

				<?php } ?>

				</tbody>
			</table>
			<script>
				jQuery(document).ready(function () {
					jQuery('#bp-member-type-permissions .inside .group-type-checkboxes').click(function () {
						var checkValues = jQuery(this).val();
						if ('none' === checkValues && jQuery(this).is(':checked')) {
							jQuery('#bp-member-type-permissions .inside .group-type-checkboxes').attr('checked', false);
							jQuery('#bp-member-type-permissions .inside .group-type-checkboxes').attr('disabled', true);
							jQuery(this).attr('checked', true);
							jQuery(this).attr('disabled', false);
						} else {
							jQuery('#bp-member-type-permissions .inside .group-type-checkboxes').attr('disabled', false);
						}
					});

					jQuery("#bp-member-type-permissions .inside .group-type-checkboxes").each(function () {
						var checkValues = jQuery(this).val();
						if ('none' === checkValues && jQuery(this).is(':checked')) {
							jQuery('#bp-member-type-permissions .inside .group-type-checkboxes').attr('checked', false);
							jQuery('#bp-member-type-permissions .inside .group-type-checkboxes').attr('disabled', true);
							jQuery(this).attr('checked', true);
							jQuery(this).attr('disabled', false);
							return false;
						} else {
							jQuery('#bp-member-type-permissions .inside .group-type-checkboxes').attr('disabled', false);
						}
					});
				});
			</script>
			<?php
		}
	}

	if ( bp_is_active( 'groups' ) && true === bp_disable_group_type_creation() && true === bp_enable_group_auto_join() && bp_is_active( 'invites' ) ) {

		$get_all_registered_group_types = bp_get_active_group_types();

		// Add meta box if group types is entered.
		if ( true === bp_disable_group_type_creation() && isset( $get_all_registered_group_types ) && ! empty( $get_all_registered_group_types ) ) {
			?>
			<table class="widefat bp-postbox-table">
				<thead>
				<tr>
					<th colspan="2">
						<?php _e( 'Group Type Membership Approval', 'buddyboss' ); ?>
					</th>
				</tr>
				</thead>
				<tbody>
				<tr>
					<td colspan="2">
						<?php _e( 'Selected group types will automatically approve all membership requests from users of this profile type:', 'buddyboss' ); ?>
					</td>
				</tr>

				<?php
				$get_all_registered_group_types = bp_get_active_group_types();

				$get_selected_group_types = get_post_meta( $post->ID, '_bp_member_type_enabled_group_type_auto_join', true )?: [];

				foreach ( $get_all_registered_group_types as $group_type_id ) {

					$group_type_key = get_post_meta( $group_type_id, '_bp_group_type_key', true );
					$group_type_label = bp_groups_get_group_type_object( $group_type_key )->labels['name'];
					?>

					<tr>
						<td colspan="2">
							<input type='checkbox' name='bp-group-type-auto-join[]' value='<?php echo esc_attr( $group_type_key ); ?>' <?php checked( in_array( $group_type_key, $get_selected_group_types ) ); ?> /> <?php echo $group_type_label; ?>
						</td>
					</tr>

				<?php } ?>

				</tbody>
			</table>
			<?php
		}
	}

	// Metabox for the profile type invite.
	if ( true === bp_disable_invite_member_type() && bp_is_active( 'invites' ) ) {

		//Allow a specific profile type to send invitations to new members and specify their profile type upon registration.
		$enable_invite = isset( $meta[ '_bp_member_type_enable_invite' ] ) ? $meta[ '_bp_member_type_enable_invite' ][ 0 ] : 1; //enabled by default
		?>

		<table class="widefat bp-postbox-table">
			<thead>
			<tr>
				<th colspan="2">
					<?php _e( 'Email Invites', 'buddyboss' ); ?>
				</th>
			</tr>
			</thead>
			<tbody>
			<tr>
				<td colspan="2">
					<input type='checkbox' name='bp-member-type-enabled-invite' value='1' <?php checked( $enable_invite, 1 ); ?> /> <?php _e( 'Allow members to select the profile type that the invited recipient will be automatically assigned to on registration. If checked, select which of the below profile types can be assigned to the recipient:', 'buddyboss' ); ?>
				</td>
			</tr>

			<?php

			$get_all_registered_profile_types = bp_get_active_member_types();

			$get_selected_profile_types = get_post_meta( $post->ID, '_bp_member_type_allowed_member_type_invite', true )?: [];

			foreach ( $get_all_registered_profile_types as $member_type_id ) {

				$member_type_name = get_post_meta( $member_type_id, '_bp_member_type_label_name', true );
				?>

				<tr>
					<td colspan="2">
						<input type='checkbox' name='bp-member-type-invite[]' value='<?php echo esc_attr( $member_type_id ); ?>' <?php checked( in_array( $member_type_id, $get_selected_profile_types ) ); ?> /> <?php echo $member_type_name; ?>
					</td>
				</tr>

			<?php } ?>

			</tbody>
		</table>

		<?php

	}
}

Changelog

Changelog
Version Description
BuddyBoss 1.0.0 Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.