LLMS_Admin_User_Custom_Fields::output_instructors_assistant_fields( mixed $user )

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


Description Description


Parameters Parameters

$user

(mixed) (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() );
		}

		// 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 ) ); ?>>
									<?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' ) );

			// 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
		} elseif ( 'add-new-user' === $user ) {
			echo '<input type="hidden" name="llms_parent_instructors[]" value="' . get_current_user_id() . '">';
		}

	}

Top ↑

Changelog Changelog

Changelog
Version Description
3.13.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

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