LLMS_Controller_Awards::on_rest_insert( stdClass $post, WP_Rest_Request $request, boolean $creating )

Awarded certificate REST API insertion callback.

Description Description

Automatically syncs an awarded certificate with its parent when inserted via the REST API and sets a unique post name (slug).

This method relies on the fact that there is (currently) no native way to insert an awarded certificate into the database via the REST API with a linked parent template without using the AwardCertificateButton Javascript component. The component sets the parent and student and allows this callback function to perform the remaining (necessary) sync operations.

Top ↑

Parameters Parameters


(stdClass) (Required) The post object.


(WP_Rest_Request) (Required) Rest request object.


(boolean) (Required) Whether or not the post is being created.

Top ↑

Return Return

(integer) Returns an integer, primarily for unit tests: 0 if the insertion is an update, 1 if the post has not parent, and 2 when the certificate is synced and updated.

Top ↑

Source Source

File: includes/controllers/class-llms-controller-awards.php

	public static function on_rest_insert( $post, $request, $creating ) {

		if ( ! $creating ) {
			return 0;

		$cert = self::get_object( $post->ID );
		if ( ! $cert->get( 'parent' ) ) {
			return 1;

		add_filter( 'llms_certificate_merge_data', array( __CLASS__, 'on_rest_insert_merge_data' ) );

		$cert->sync( 'create' );
		$cert->set( 'name', llms()->certificates()->get_unique_slug( $cert->get( 'title' ) ) );

		remove_filter( 'llms_certificate_merge_data', array( __CLASS__, 'on_rest_insert_merge_data' ) );

		return 2;


Top ↑

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.