LLMS_Post_Types::register_taxonomies()

Register Taxonomies


Return Return

(void)


Top ↑

Source Source

File: includes/class.llms.post-types.php

	}

	/**
	 * Register a custom post type taxonomy
	 * Automatically checks for duplicates and filters data
	 *
	 * @since 3.13.0
	 *
	 * @param string       $name   Taxonomy name.
	 * @param string|array $object Post type object(s) to associate the taxonomy with.
	 * @param array        $data   Taxonomy data.
	 * @return void
	 */
	public static function register_taxonomy( $name, $object, $data ) {

		if ( ! taxonomy_exists( $name ) ) {
			$filter_name = str_replace( 'llms_', '', $name );
			register_taxonomy(
				$name,
				apply_filters( 'lifterlms_register_taxonomy_objects_' . $filter_name, $object ),
				apply_filters( 'lifterlms_register_taxonomy_args_' . $filter_name, $data )
			);
		}
	}

	/**
	 * Register Taxonomies
	 *
	 * @since 1.0.0
	 * @since 3.30.3 Removed duplicate array keys when registering course_tag taxonomy.
	 * @since 3.34.1 Add custom property `show_in_llms_rest` set to true by default to those taxonomies we want to show in LLMS REST api.
	 *
	 * @return void
	 */
	public static function register_taxonomies() {

		$permalinks = llms_get_permalink_structure();

		// Course cat.
		self::register_taxonomy(
			'course_cat',
			array( 'course' ),
			array(
				'label'             => __( 'Course Categories', 'lifterlms' ),
				'labels'            => array(
					'name'              => __( 'Course Categories', 'lifterlms' ),
					'singular_name'     => __( 'Course Category', 'lifterlms' ),
					'menu_name'         => _x( 'Categories', 'Admin menu name', 'lifterlms' ),
					'search_items'      => __( 'Search Course Categories', 'lifterlms' ),
					'all_items'         => __( 'All Course Categories', 'lifterlms' ),
					'parent_item'       => __( 'Parent Course Category', 'lifterlms' ),
					'parent_item_colon' => __( 'Parent Course Category:', 'lifterlms' ),
					'edit_item'         => __( 'Edit Course Category', 'lifterlms' ),
					'update_item'       => __( 'Update Course Category', 'lifterlms' ),
					'add_new_item'      => __( 'Add New Course Category', 'lifterlms' ),
					'new_item_name'     => __( 'New Course Category Name', 'lifterlms' ),
				),
				'capabilities'      => self::get_tax_caps( 'course_cat' ),
				'hierarchical'      => true,
				'query_var'         => true,
				'show_admin_column' => true,
				'show_ui'           => true,
				'rewrite'           => array(
					'slug'         => $permalinks['course_category_base'],
					'with_front'   => false,
					'hierarchical' => true,
				),
				'show_in_llms_rest' => true,
			)
		);

		// Course difficulty.
		self::register_taxonomy(
			'course_difficulty',
			array( 'course' ),
			array(
				'label'             => __( 'Course Difficulties', 'lifterlms' ),
				'labels'            => array(
					'name'              => __( 'Course Difficulties', 'lifterlms' ),
					'singular_name'     => __( 'Course Difficulty', 'lifterlms' ),
					'menu_name'         => _x( 'Difficulties', 'Admin menu name', 'lifterlms' ),
					'search_items'      => __( 'Search Course Difficulties', 'lifterlms' ),
					'all_items'         => __( 'All Course Difficulties', 'lifterlms' ),
					'parent_item'       => __( 'Parent Course Difficulty', 'lifterlms' ),
					'parent_item_colon' => __( 'Parent Course Difficulty:', 'lifterlms' ),
					'edit_item'         => __( 'Edit Course Difficulty', 'lifterlms' ),
					'update_item'       => __( 'Update Course Difficulty', 'lifterlms' ),
					'add_new_item'      => __( 'Add New Course Difficulty', 'lifterlms' ),
					'new_item_name'     => __( 'New Course Difficulty Name', 'lifterlms' ),
				),
				'capabilities'      => self::get_tax_caps( array( 'course_difficulty', 'course_difficulties' ) ),
				'hierarchical'      => false,
				'query_var'         => true,
				'show_admin_column' => true,
				'show_ui'           => true,
				'rewrite'           => array(
					'slug'       => $permalinks['course_difficulty_base'],
					'with_front' => false,
				),
				'show_in_llms_rest' => true,
			)
		);

		// Course tag.
		self::register_taxonomy(
			'course_tag',
			array( 'course' ),
			array(
				'label'             => __( 'Course Tags', 'lifterlms' ),
				'labels'            => array(
					'name'              => __( 'Course Tags', 'lifterlms' ),
					'singular_name'     => __( 'Course Tag', 'lifterlms' ),
					'menu_name'         => _x( 'Tags', 'Admin menu name', 'lifterlms' ),
					'search_items'      => __( 'Search Course Tags', 'lifterlms' ),
					'all_items'         => __( 'All Course Tags', 'lifterlms' ),
					'parent_item'       => __( 'Parent Course Tag', 'lifterlms' ),
					'parent_item_colon' => __( 'Parent Course Tag:', 'lifterlms' ),
					'edit_item'         => __( 'Edit Course Tag', 'lifterlms' ),
					'update_item'       => __( 'Update Course Tag', 'lifterlms' ),
					'add_new_item'      => __( 'Add New Course Tag', 'lifterlms' ),
					'new_item_name'     => __( 'New Course Tag Name', 'lifterlms' ),
				),
				'capabilities'      => self::get_tax_caps( 'course_tag' ),
				'hierarchical'      => false,
				'query_var'         => true,
				'show_admin_column' => true,
				'show_ui'           => true,
				'rewrite'           => array(
					'slug'       => $permalinks['course_tag_base'],
					'with_front' => false,
				),
				'show_in_llms_rest' => true,
			)
		);

		// Course track.
		self::register_taxonomy(
			'course_track',
			array( 'course' ),
			array(
				'label'             => __( 'Course Track', 'lifterlms' ),
				'labels'            => array(
					'name'              => __( 'Course Tracks', 'lifterlms' ),
					'singular_name'     => __( 'Course Track', 'lifterlms' ),
					'menu_name'         => _x( 'Tracks', 'Admin menu name', 'lifterlms' ),
					'search_items'      => __( 'Search Course Tracks', 'lifterlms' ),
					'all_items'         => __( 'All Course Tracks', 'lifterlms' ),
					'parent_item'       => __( 'Parent Course Track', 'lifterlms' ),
					'parent_item_colon' => __( 'Parent Course Track:', 'lifterlms' ),
					'edit_item'         => __( 'Edit Course Track', 'lifterlms' ),
					'update_item'       => __( 'Update Course Track', 'lifterlms' ),
					'add_new_item'      => __( 'Add New Course Track', 'lifterlms' ),
					'new_item_name'     => __( 'New Course Track Name', 'lifterlms' ),
				),
				'capabilities'      => self::get_tax_caps( 'course_track' ),
				'hierarchical'      => true,
				'query_var'         => true,
				'show_admin_column' => true,
				'show_ui'           => true,
				'rewrite'           => array(
					'slug'         => $permalinks['course_track_base'],
					'with_front'   => false,
					'hierarchical' => true,
				),
				'show_in_llms_rest' => true,
			)
		);

		// Membership cat.
		self::register_taxonomy(
			'membership_cat',
			array( 'llms_membership' ),
			array(
				'hierarchical'      => true,
				'label'             => __( 'Membership Categories', 'lifterlms' ),
				'labels'            => array(
					'name'              => __( 'Membership Categories', 'lifterlms' ),
					'singular_name'     => __( 'Membership Category', 'lifterlms' ),
					'menu_name'         => _x( 'Categories', 'Admin menu name', 'lifterlms' ),
					'search_items'      => __( 'Search Membership Categories', 'lifterlms' ),
					'all_items'         => __( 'All Membership Categories', 'lifterlms' ),
					'parent_item'       => __( 'Parent Membership Category', 'lifterlms' ),
					'parent_item_colon' => __( 'Parent Membership Category:', 'lifterlms' ),
					'edit_item'         => __( 'Edit Membership Category', 'lifterlms' ),
					'update_item'       => __( 'Update Membership Category', 'lifterlms' ),
					'add_new_item'      => __( 'Add New Membership Category', 'lifterlms' ),
					'new_item_name'     => __( 'New Membership Category Name', 'lifterlms' ),
				),
				'capabilities'      => self::get_tax_caps( 'membership_cat' ),
				'show_ui'           => true,
				'show_in_menu'      => true,
				'query_var'         => true,
				'show_admin_column' => true,
				'rewrite'           => array(
					'slug'         => $permalinks['membership_category_base'],
					'with_front'   => false,
					'hierarchical' => true,
				),
				'show_in_llms_rest' => true,
			)
		);

		// Membership tag.
		self::register_taxonomy(
			'membership_tag',
			array( 'llms_membership' ),
			array(
				'hierarchical'      => false,
				'label'             => __( 'Membership Tags', 'lifterlms' ),
				'labels'            => array(
					'name'              => __( 'Membership Tags', 'lifterlms' ),
					'singular_name'     => __( 'Membership Tag', 'lifterlms' ),
					'menu_name'         => _x( 'Tags', 'Admin menu name', 'lifterlms' ),
					'search_items'      => __( 'Search Membership Tags', 'lifterlms' ),
					'all_items'         => __( 'All Membership Tags', 'lifterlms' ),
					'parent_item'       => __( 'Parent Membership Tag', 'lifterlms' ),
					'parent_item_colon' => __( 'Parent Membership Tag:', 'lifterlms' ),
					'edit_item'         => __( 'Edit Membership Tag', 'lifterlms' ),
					'update_item'       => __( 'Update Membership Tag', 'lifterlms' ),
					'add_new_item'      => __( 'Add New Membership Tag', 'lifterlms' ),
					'new_item_name'     => __( 'New Membership Tag Name', 'lifterlms' ),
				),
				'capabilities'      => self::get_tax_caps( 'membership_tag' ),
				'show_ui'           => true,
				'show_in_menu'      => 'lifterlms',
				'query_var'         => true,
				'show_admin_column' => true,
				'rewrite'           => array(

Top ↑

Changelog Changelog

Changelog
Version Description
3.34.1 Add custom property show_in_llms_rest set to true by default to those taxonomies we want to show in LLMS REST api.
3.30.3 Removed duplicate array keys when registering course_tag taxonomy.
1.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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