Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

LLMS_Roles::get_post_type_caps( string $role )

Retrieve the post type specific capabilities for a give role.


Parameters Parameters

$role

(string) (Required) Name of the role


Top ↑

Return Return

(array)


Top ↑

Source Source

File: includes/class.llms.roles.php

	private static function get_post_type_caps( $role ) {

		$caps = array();

		// Students get nothing.
		if ( 'student' !== $role ) {

			$post_types = array(
				'course'          => 'course',
				'lesson'          => 'lesson',
				'llms_quiz'       => array( 'quiz', 'quizzes' ),
				'llms_question'   => 'question',
				'llms_membership' => 'membership',
			);
			foreach ( $post_types as $post_type => $names ) {

				$post_caps = LLMS_Post_Types::get_post_type_caps( $names );

				// Filter the caps down for these roles.
				if ( in_array( $role, array( 'instructor', 'instructors_assistant' ), true ) ) {

					$allowed = array(
						'instructor'            => array(
							'delete_posts',
							'delete_published_posts',
							'edit_post',
							'edit_posts',
							'edit_published_posts',
							'publish_posts',
							'create_posts',
						),
						'instructors_assistant' => array(
							'edit_post',
							'edit_posts',
							'edit_published_posts',
						),
					);

					foreach ( $post_caps as $post_cap => $cpt_cap ) {

						if ( ! in_array( $post_cap, $allowed[ $role ], true ) ) {
							unset( $post_caps[ $post_cap ] );
						}
					}
				}

				$caps[ $post_type ] = array_fill_keys( array_values( $post_caps ), true );

			}

			$taxes = array(
				'course_cat'        => 'course_cat',
				'course_difficulty' => array( 'course_difficulty', 'course_difficulties' ),
				'course_tag'        => 'course_tag',
				'course_track'      => 'course_track',
				'membership_cat'    => 'membership_cat',
				'membership_tag'    => 'membership_tag',
			);
			foreach ( $taxes as $tax => $names ) {

				$tax_caps = LLMS_Post_Types::get_tax_caps( $names );

				// Filter the caps down for these roles.
				if ( in_array( $role, array( 'instructor', 'instructors_assistant' ), true ) ) {

					$allowed = array(
						'assign_terms',
					);

					foreach ( $tax_caps as $tax_cap => $ct_cap ) {

						if ( ! in_array( $tax_cap, $allowed, true ) ) {
							unset( $tax_caps[ $tax_cap ] );
						}
					}
				}

				$caps[ $tax ] = array_fill_keys( array_values( $tax_caps ), true );

			}
		}

		return apply_filters( 'llms_get_' . $role . '_post_type_caps', $caps );

	}


Top ↑

Changelog Changelog

Changelog
Version Description
4.21.2 Use strict comparisons for in_array().
3.13.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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