llms_update_4150_remove_orphan_access_plans()

Remove orphan access plans


Return Return

(bool) True if it needs to run again, false otherwise.


Top ↑

Source Source

File: includes/functions/updates/llms-functions-updates-4150.php

function llms_update_4150_remove_orphan_access_plans() {

	$limit = 50;

	global $wpdb;

	$orphan_access_plans = $wpdb->get_col(
		$wpdb->prepare(
			"SELECT pm.post_id AS apid
			FROM {$wpdb->postmeta} AS pm
			LEFT JOIN {$wpdb->posts} AS p
			ON pm.meta_value = p.ID
			WHERE pm.meta_key = '_llms_product_id'
			AND p.ID IS NULL
			ORDER BY apid ASC
			LIMIT %d
		",
			$limit
		)
	); // db call ok; no-cache ok.

	// Finished.
	if ( empty( $orphan_access_plans ) ) {
		set_transient( 'llms_update_4150_remove_orphan_access_plans', 'complete', DAY_IN_SECONDS );
		return false;
	}

	foreach ( $orphan_access_plans as $orphan_access_plan_id ) {
		wp_delete_post( $orphan_access_plan_id );
	}

	// Needs to run again.
	return true;
}

Top ↑

Changelog Changelog

Changelog
Version Description
4.15.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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