LLMS_Admin_User_Custom_Fields::output_instructors_assistant_fields( WP_User|int $user )

Add instructor parent fields for use when creating instructor’s assistants


Parameters Parameters

$user

(WP_User|int) (Required) Instance of WP_User or WP User ID


Top ↑

Return Return

(void)


Top ↑

Source Source

File: includes/admin/class.llms.admin.user.custom.fields.php

	public function output_instructors_assistant_fields( $user ) {

		if ( is_numeric( $user ) || is_a( $user, 'WP_User' ) ) {
			$instructor = llms_get_instructor( $user );
			$selected   = $instructor->get( 'parent_instructors' );
			if ( empty( $selected ) && ! is_array( $selected ) ) {
				$selected = array();
			}
		} else {
			$selected = array( get_current_user_id() );
		}

		$selected = array_map( 'absint', $selected );

		// Only let admins & lms managers select the parent for an instructor's assistant.
		if ( current_user_can( 'manage_lifterlms' ) ) {

			$users = get_users(
				array(
					'role__in' => array( 'administrator', 'lms_manager', 'instructor' ),
				)
			);
			?>
			<table class="form-table" id="llms-parent-instructors-table" style="display:none;">
				<tr class="form-field">
					<th scope="row"><label for="llms-parent-instructors"><?php _e( 'Parent Instructor(s)', 'lifterlms' ); ?></label></th>
					<td>
						<select class="regular-text" id="llms-parent-instructors" name="llms_parent_instructors[]" multiple="multiple">
							<?php foreach ( $users as $user ) : ?>
								<option value="<?php echo $user->ID; ?>"<?php selected( in_array( $user->ID, $selected, true ) ); ?>>
									<?php echo $user->display_name; ?>
								</option>
							<?php endforeach; ?>
						</select>
					</td>
				</tr>
			</table>
			<?php

			add_action( 'admin_print_footer_scripts', array( $this, 'output_instructors_assistant_scripts' ) );

		} elseif ( 'add-new-user' === $user ) {
			/**
			 * This will be the case for Instructors only:
			 *
			 * Show a hidden field with the current user's info
			 *
			 * When saving it will only save if the created user's role is instructor's assistant.
			 */
			echo '<input type="hidden" name="llms_parent_instructors[]" value="' . get_current_user_id() . '">';
		}

	}


Top ↑

Changelog Changelog

Changelog
Version Description
3.37.15 Use strict comparisons.
3.23.0 Unknown.
3.13.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.