LLMS_Post_Types::register_post_type( string $name, array $data )

Register a custom post type.


Description Description

Automatically checks for duplicates and filters data.


Top ↑

Parameters Parameters

$name

(string) (Required) Post type name.

$data

(array) (Required) Post type data.


Top ↑

Return Return

(WP_Post_Type|WP_Error)


Top ↑

Source Source

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

	public static function register_post_type( $name, $data ) {

		if ( ! post_type_exists( $name ) ) {

			$unprefixed_name = str_replace( 'llms_', '', $name );

			if ( $unprefixed_name !== $name ) {
				$data = apply_filters_deprecated(
					"lifterlms_register_post_type_{$name}",
					array( $data ),
					'5.5.0',
					"lifterlms_register_post_type_{$unprefixed_name}"
				);
			}

			if ( empty( $data['template'] ) ) {
				$data['template'] = self::get_template( $name );
			}

			/**
			 * Modify post type registration arguments of a LifterLMS custom post type.
			 *
			 * The dynamic portion of this hook refers to the post type's name with the `llms_` prefix
			 * removed (if it exist). For example, to modify the arguments for the membership post type
			 * (`llms_membership`) the full hook would be "lifterlms_register_post_type_membership".
			 *
			 * @since 3.13.0
			 *
			 * @param array $data Post type registration arguments passed to `register_post_type()`.
			 */
			$data = apply_filters( "lifterlms_register_post_type_{$unprefixed_name}", $data );
			return register_post_type( $name, $data );

		}

		return get_post_type_object( $name );

	}


Top ↑

Changelog Changelog

Changelog
Version Description
6.0.0 Automatically load templates from the llms-block-templates schema. Added return value.
5.5.0 Added lifterlms_register_post_type_${name} filters deprecation where $name is the the post type name, if the unprefixed name (removing 'llms_') is different from $name. E.g. it'll be triggered when registering when using lifterlms_register_post_type_llms_engagement but not when using lifterlms_register_post_type_course, for the latter, both the name and the unprefixed name are the same.
3.13.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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