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( array $data )

Delete/trash elements from heartbeat data


Description Description


Parameters Parameters

$data

(array) (Required) array of ids to trash/delete


Top ↑

Return Return

(array)


Top ↑

Source Source

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

	private static function process_trash( $data ) {

		$ret = array();

		foreach ( $data['trash'] as $id ) {

			$res = array(
				'error' => sprintf( esc_html__( 'Unable to delete "%s". Invalid ID.', 'lifterlms' ), $id ),
				'id' => $id,
			);

			$custom = apply_filters( 'llms_builder_trash_custom_item', null, $res, $id );
			if ( $custom ) {
				array_push( $ret, $custom );
				continue;
			}

			if ( is_numeric( $id ) ) {

				$type = get_post_type( $id );

			} else {

				$type = 'question_choice';

			}

			$post_types = apply_filters( 'llms_builder_trashable_post_types', array( 'lesson', 'llms_quiz', 'llms_question', 'question_choice', 'section' ) );
			if ( ! in_array( $type, $post_types ) ) {
				array_push( $ret, $res );
				continue;
			}

			// lessons, sections, & questions passed as numeric WP Post IDs
			if ( is_numeric( $id ) ) {

				// delete sections
				if ( in_array( $type, array( 'section', 'llms_question', 'llms_quiz' ) ) ) {
					$stat = wp_delete_post( $id, true );
				} // End if().
				else {
					$stat = wp_trash_post( $id );
				}
			} else {

				$split = explode( ':', $id );
				$question = llms_get_post( $split[0] );
				if ( $question && is_a( $question, 'LLMS_Question' ) ) {
					$stat = $question->delete_choice( $split[1] );
				} else {
					$stat = false;
				}
			}

			// both functions return false on failure
			if ( ! $stat ) {
				$res['error'] = sprintf( esc_html__( 'Error deleting %1$s "%s".', 'lifterlms' ), $type, $id );
			} else {
				unset( $res['error'] );
			}

			array_push( $ret, $res );

		}// End foreach().

		return $ret;

	}

Top ↑

Changelog Changelog

Changelog
Version Description
3.16.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

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





Permalink: