LLMS_Post_Relationships::maybe_clean_earned_engagments_related_user_post_meta( int $post_id )

Maybe delete LifterLMS user post meta related to earned engagements.


Parameters Parameters

$post_id

(int) (Required) Post ID.


Top ↑

Return Return

(void)


Top ↑

Source Source

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

	public static function maybe_clean_earned_engagments_related_user_post_meta( $post_id ) {

		$post_types = array(
			'llms_my_certificate',
			'llms_my_achievement',
		);
		$post_type  = get_post_type( $post_id );

		if ( ! in_array( $post_type, $post_types, true ) ) {
			return;
		}

		$earned_engagement = 'llms_my_certificate' === $post_type ? new LLMS_User_Certificate( $post_id ) : new LLMS_User_Achievement( $post_id );

		do_action_deprecated(
			'llms_before_delete_' . str_replace( 'llms_my_', '', $post_type ),
			array(
				$earned_engagement,
			),
			'6.0.0',
			'',
			__( 'Use WordPress core  `before_delete_post` action hook', 'lifterlms' )
		);

		global $wpdb;
		$wpdb->delete(
			"{$wpdb->prefix}lifterlms_user_postmeta",
			array(
				'user_id'    => $earned_engagement->get_user_id(),
				'meta_key'   => '_' . str_replace( 'llms_my_', '', $post_type ) . '_earned',
				'meta_value' => $post_id,
			),
			array( '%d', '%s', '%d' )
		); // no-cache ok.

		add_action(
			'after_delete_post',
			function( $post_id ) use ( $earned_engagement, $post_type ) {

				if ( $earned_engagement->get( 'id' ) === $post_id ) {
					do_action_deprecated(
						'llms_delete_' . str_replace( 'llms_my_', '', $post_type ),
						array(
							$earned_engagement,
						),
						'6.0.0',
						'',
						__( 'Use WordPress core `deleted_post` action hook.', 'lifterlms' )
					);
				}

			}
		);
	}


Top ↑

Changelog Changelog

Changelog
Version Description
6.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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