LLMS_Post_Relationships::maybe_prevent_product_deletion( bool|null $delete, WP_Post $post )

Determine whether a product deletion should take place.


Parameters Parameters

$delete

(bool|null) (Required) Whether to go forward with deletion.

$post

(WP_Post) (Required) Post object.


Top ↑

Return Return

(bool|null)


Top ↑

Source Source

File: includes/class.llms.post.relationships.php

	public static function maybe_prevent_product_deletion( $delete, $post ) {

		if ( ! in_array( get_post_type( $post ), array( 'course', 'llms_membership' ), true ) ) {
			return $delete;
		}

		$product = llms_get_product( $post );

		if ( empty( $product ) || ! $product->has_active_subscriptions() ) {
			return $delete;
		}

		// If performing the deletion via REST API change the error message to reflect the reason for the prevention.
		if ( llms_is_rest() ) {
			// Filter the error message.
			add_filter( 'rest_request_after_callbacks', array( __CLASS__, 'rest_filter_products_with_active_subscriptions_error_message' ), 10, 3 );
		} else { // Deleting via wp-admin.
			wp_die(
				self::delete_product_with_active_subscriptions_error_message( $product->get( 'id' ) )
			);
		}

		return false;

	}


Top ↑

Changelog Changelog

Changelog
Version Description
5.4.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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