LLMS_Abstract_User_Engagement::sync( string $context = 'update' )
Update the awarded engagement by regenerating it from its template.
Parameters Parameters
- $context
-
(string) (Optional) Sync context. Either "update" for an update to an existing awarded engagement or "create" when the awarded engagement is being created.
Default value: 'update'
Return Return
(boolean) Returns false if the parent doesn't exist, otherwise returns true.
Source Source
File: includes/abstracts/llms-abstract-user-engagement.php
public function sync( $context = 'update' ) {
$template_id = $this->get( 'parent' );
$template = $this->get_user_engagement( $template_id, false );
if ( ! $template ) {
return false;
}
$this->set( 'title', get_post_meta( $template_id, "_llms_{$this->model_post_type}_title", true ) );
if ( get_post_thumbnail_id( $template_id ) !== get_post_thumbnail_id( $this->get( 'post' ) ) &&
! set_post_thumbnail( $this->get( 'post' ), get_post_thumbnail_id( $template_id ) )
) {
delete_post_thumbnail( $this->get( 'post' ) );
}
// Copy the content with optional merge codes, shortcodes, and optional block editor layout meta properties
// from the template to this awarded engagement.
$content = $template->get( 'content', true );
$this->set( 'content', $this->merge_content( $content, true ) );
$this->sync_meta( $template );
/**
* Action run after an awarded engagement is synchronized with its template.
*
* The dynamic portion of the hook name, `$this->model_post_type`,
* refers to the engagement type, either "achievement" or "certificate".
*
* @since 6.0.0
*
* @param LLMS_Abstract_User_Engagement $engagement Awarded engagement object.
* @param LLMS_Abstract_User_Engagement $template Engagement template object.
* @param string $context The context within which the synchronization is run.
* Either "create" or "update".
*/
do_action( "llms_{$this->model_post_type}_synchronized", $this, $template, $context );
return true;
}
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
| Version | Description |
|---|---|
| 6.4.0 | Added replacement of references to reusable blocks with their actual blocks. |
| 6.0.0 | Introduced. |