_migrate_award( int $post_id, string $type )

Migrate meta values for a single award.


Description Description

Performs the following updates:

  • Copies lifterlms_user_postmeta user data to the post_author property.
  • Moves the title from postmeta to the post_title property.
  • Moves the template relationship from meta to the post_parent property.
  • Moves the award image from custom meta to the post’s featured image.

And then deletes the previous metadata after performing the necessary updates.


Top ↑

Parameters Parameters

$post_id

(int) (Required) WP_Post ID.

$type

(string) (Required) Award type, either "achievement" or "certificate".


Top ↑

Return Return

(bool) true if there was an image to migrate, else false.


Top ↑

Source Source

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

function _migrate_award( $post_id, $type ) {

	$obj = 'achievement' === $type ? new \LLMS_User_Achievement( $post_id ) : new \LLMS_User_Certificate( $post_id );

	$updates = array(
		'awarded' => $obj->get_earned_date( 'Y-m-d H:i:s' ),
		'author'  => $obj->get_user_id(),
	);

	$title = get_post_meta( $post_id, "_llms_{$type}_title", true );
	if ( $title ) {
		$updates['title'] = $title;
	}

	$template = get_post_meta( $post_id, "_llms_{$type}_template", true );
	if ( $template ) {
		$updates['parent'] = $template;
	}
	$obj->set_bulk( $updates );

	$image_migrated = _migrate_image( $post_id, $type );

	if ( 'achievement' === $type ) {
		_migrate_achievement_content( $post_id );
	}

	delete_post_meta( $post_id, "_llms_{$type}_title" );
	delete_post_meta( $post_id, "_llms_{$type}_template" );

	return $image_migrated;
}

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.