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_Admin_Builder::process_trash_item_post_type( int $id, string $post_type )

Delete / Trash a post type

Parameters Parameters


(int) (Required) WP_Post ID.


(string) (Required) Post type name.

Top ↑

Return Return

(boolean|WP_Error) true when successfully deleted or trashed. WP_Error for unsupported post types or when a deletion error is encountered.

Top ↑

Source Source

File: includes/admin/class.llms.admin.builder.php

	private static function process_trash_item_post_type( $id, $post_type ) {

		// Used for errors.
		$obj = get_post_type_object( $post_type );

		 * Filter course elements that can be deleted or trashed via the course builder.
		 * Note that the use of "trash" in the filter name is not semantically correct as this filter does not guarantee
		 * that the element will be sent to the trash. Use the filter `llms_builder_trash_{$post_type}_force_delete` to
		 * determine if the element is sent to the trash or deleted immediately.
		 * @since Unknown
		 * @since 3.37.12 The "question_choice" item was removed from the default list and is being handled as a "custom item".
		 * @param string[] $post_types Array of post type names.
		$post_types = apply_filters( 'llms_builder_trashable_post_types', array( 'lesson', 'llms_quiz', 'llms_question', 'section' ) );
		if ( ! in_array( $post_type, $post_types, true ) ) {
			// Translators: %s = Post type name.
			return new WP_Error( 'llms_builder_trash_unsupported_post_type', sprintf( esc_html__( '%s cannot be deleted via the Course Builder.', 'lifterlms' ), $obj->labels->name ) );

		// Default force value: these post types are force deleted and others are moved to the trash.
		$force = in_array( $post_type, array( 'section', 'llms_question', 'llms_quiz' ), true );

		 * Determine whether or not a post type should be moved to the trash or deleted when trashed via the Course Builder.
		 * The dynamic portion of this hook, `$post_type`, refers to the post type name of the post that's being trashed.
		 * By default all post types are moved to trash except for `section`, `llms_question`, and `llms_quiz` post types.
		 * @since 3.37.12
		 * @param boolean $force If `true` the post is deleted, if `false` it will be moved to the trash.
		 * @param int     $id    WP_Post ID of the post being trashed.
		$force = apply_filters( "llms_builder_{$post_type}_force_delete", $force, $id );

		// Delete or trash the post.
		$res = $force ? wp_delete_post( $id, true ) : wp_trash_post( $id );
		if ( ! $res ) {
			// Translators: %1$s = Post type singular name; %2$d = Post id.
			return new WP_Error( 'llms_builder_trash_post_type', sprintf( esc_html__( 'Error deleting the %1$s "%2$d".', 'lifterlms' ), $obj->labels->singular_name, $id ) );

		return true;


Top ↑

Changelog Changelog

Version Description
3.37.12 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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