Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
7288ab1
WIP: Add embeddable to the post and student. Will likely want to spec…
brianhogg Jun 17, 2025
f7a4c05
Changelog.
brianhogg Jun 18, 2025
7d9f3fb
Adding more data to show in webhooks and when _embed query param adde…
brianhogg Jun 18, 2025
b49702e
Removing embed from collections
brianhogg Jun 18, 2025
c1b26e2
Avoid error if core LifterLMS is deactivated.
brianhogg Jun 20, 2025
9cee054
Allow retrieving all progress for a student rather than just a specif…
brianhogg Jun 24, 2025
9469f55
Fixing warning for no pagination args.
brianhogg Jun 24, 2025
562a93b
Fixing individual link.
brianhogg Jun 24, 2025
cb4c5f1
Adding note about maybe changing to getting more items to check progr…
brianhogg Jun 24, 2025
a65132d
WIP: Initial quizzes controller.
brianhogg Jun 24, 2025
49974e2
Quiz attempts controller.
brianhogg Jun 26, 2025
745a7ea
Refactor to use LLMS_Query_Quiz_Attempt.
brianhogg Jun 26, 2025
db78f15
WIP: Adding quiz attempts endpoint.
brianhogg Jun 26, 2025
7524e4e
Quiz attempt completed webhook.
brianhogg Jun 26, 2025
8200ff7
Changelogs.
brianhogg Jun 26, 2025
7c1ef12
WIP: Initial orders endpoint.
brianhogg Jun 26, 2025
4325188
Filter "llms-" out of status. Read-only for order items and collection.
brianhogg Jun 26, 2025
f5a10fc
Fixing comment.
brianhogg Jun 26, 2025
133bd2a
Adding billing email.
brianhogg Jun 26, 2025
deba91a
WIP: Adding additional fields
brianhogg Jun 26, 2025
d336c97
Fixing comments.
brianhogg Jun 27, 2025
aa4c21f
Fixing comments.
brianhogg Jun 27, 2025
d0ec7ed
FIx schema base.
brianhogg Jun 27, 2025
20f861f
More comment fixes.
brianhogg Jun 27, 2025
0819f3b
Removing add-on topic from core. Allow generic webhook rest api build…
brianhogg Jun 27, 2025
d7c814f
Adding assignment webhook topic and hooks within the add-on.
brianhogg Jun 27, 2025
76f3b86
Base certificate endpoint.
brianhogg Jun 27, 2025
16f4142
awarded-certificates endpoint.
brianhogg Jun 27, 2025
46ff338
Awarded-certificates webhook and API mods.
brianhogg Jul 3, 2025
6762e68
Changelog.
brianhogg Jul 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
awarded-certificates endpoint.
  • Loading branch information
brianhogg committed Jun 27, 2025
commit 16f41428eef8d61ead64f402dd12b48c929e5b77
2 changes: 2 additions & 0 deletions class-lifterlms-rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ public function rest_api_includes() {
'server/class-llms-rest-quizzes-controller',
'server/class-llms-rest-quiz-attempts-controller',
'server/class-llms-rest-certificates-controller',
'server/class-llms-rest-awarded-certificates-controller',
'server/class-llms-rest-orders-controller',
'server/class-llms-rest-sections-controller',
'server/class-llms-rest-lessons-controller',
Expand Down Expand Up @@ -181,6 +182,7 @@ public function rest_api_controllers_init() {
'LLMS_REST_Quizzes_Controller',
'LLMS_REST_Quiz_Attempts_Controller',
'LLMS_REST_Certificates_Controller',
'LLMS_REST_Awarded_Certificates_Controller',
'LLMS_REST_Orders_Controller',
'LLMS_REST_Memberships_Controller',
'LLMS_REST_Instructors_Controller',
Expand Down
178 changes: 178 additions & 0 deletions includes/server/class-llms-rest-awarded-certificates-controller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
<?php
/**
* REST Awarded Certificates Controller
*
* @package LifterLMS/Classes/REST
*
* @since [version]
*/

defined( 'ABSPATH' ) || exit;

/**
* LLMS_REST_Awarded_Certificates_Controller class.
*
* @since [version]
*/
class LLMS_REST_Awarded_Certificates_Controller extends LLMS_REST_Posts_Controller {

/**
* Route base.
*
* @var string
*/
protected $rest_base = 'awarded-certificates';

/**
* Post type.
*
* @var string
*/
protected $post_type = 'llms_my_certificate';

protected $llms_post_class = 'LLMS_User_Certificate';

/**
* Schema properties available for ordering the collection.
*
* @var string[]
*/
protected $orderby_properties = array(
'id',
'title',
'date_created',
'date_updated',
'order',
'relevance',
);

/**
* Get the Section's schema, conforming to JSON Schema.
*
* @since [version]
*
* @return array
*/
public function get_item_schema() {

$schema = parent::get_item_schema();

// Update language.
$schema['properties']['title']['description'] = __( 'Awarded Certificate Title', 'lifterlms' );

$schema['properties']['certificate_id'] = array(
'description' => __( 'The ID of the certificate template.', 'lifterlms' ),
'type' => 'integer',
'context' => array( 'view', 'edit', 'embed' ),
'readonly' => true,
);

// Update defaults.
$schema['properties']['content']['required'] = false;

// Remove unnecessary props.
$remove = array(
'status',
'comment_status',
'password',
'ping_status',
'post_type',
'featured_media',
);
foreach ( $remove as $prop ) {
unset( $schema['properties'][ $prop ] );
}

return $schema;
}

public function register_routes() {

// Only registering read-only routes for this controller.
register_rest_route(
$this->namespace,
'/' . $this->rest_base,
array(
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_items' ),
'permission_callback' => array( $this, 'get_items_permissions_check' ),
'args' => $this->get_collection_params(),
),
'schema' => array( $this, 'get_public_item_schema' ),
)
);

register_rest_route(
$this->namespace,
'/' . $this->rest_base . '/(?P<id>[\d]+)',
array(
'args' => array(
'id' => array(
'description' => __( 'Unique identifier for the resource.', 'lifterlms' ),
'type' => 'integer',
),
),
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_item' ),
'permission_callback' => array( $this, 'get_item_permissions_check' ),
'args' => $this->get_get_item_params(),
),
'schema' => array( $this, 'get_public_item_schema' ),
)
);
}


protected function get_object( $id_or_object ) {
return new LLMS_User_Certificate( $id_or_object );
}

/**
* Prepare a single object output for response.
*
* @since [version]
*
* @param LLMS_User_Certificate $certificate Certificate object.
* @param WP_REST_Request $request Full details about the request.
*
* @return array
*/
protected function prepare_object_for_response( $certificate, $request ) {

$data = parent::prepare_object_for_response( $certificate, $request );

$data['post'] = $certificate->get( 'post_id' );
$data['certificate'] = $certificate->get( 'parent' );

/**
* Filters the assignment data for a response.
*
* @param array $data Array of assignment properties prepared for response.
* @param LLMS_Assignment $certificate Assignment object.
* @param WP_REST_Request $request Full details about the request.
*
*@since [version]
*/
return apply_filters( 'llms_rest_prepare_assignment_object_response', $data, $certificate, $request );
}

/**
* Prepare links for the request.
*
* @since [version]
*
* @param LLMS_User_Certificate $certificate Certificate oblect.
* @param WP_REST_Request $request Request object.
* @return array Links for the given object.
*/
protected function prepare_links( $certificate, $request ) {

$links = parent::prepare_links( $certificate, $request );

unset( $links['content'] );

return $links;
}
}
Loading