llms_get_certificate_sequential_id( integer $template_id, boolean $increment = false )
Retrieve the next sequential ID for a given certificate template and optionally increment it.
Description Description
If there’s no existing ID, a default ID of 1 will be used. This can be customized using the filter llms_certificate_sequential_id_starting_number.
When an increment is requested, the new incremented ID will be automatically persisted to the database.
Parameters Parameters
- $template_id
-
(integer) (Required) WP_Post ID of the certificate template (
llms_certificate) post. - $increment
-
(boolean) (Optional) Whether or not to increment the current ID.
Default value: false
Return Return
(int)
Source Source
File: includes/functions/llms.functions.certificate.php
function llms_get_certificate_sequential_id( $template_id, $increment = false ) {
$key = '_llms_sequential_id';
$update = $increment;
$id = absint( get_post_meta( $template_id, $key, true ) );
// No id, get the initial ID.
if ( ! $id ) {
/**
* Determines the default starting number for the a certificate's sequential ID.
*
* The returned number *must* be an absolute integer (zero included). The returned value will be
* passed through `absint()` to sanitize the filtered value.
*
* @since 6.0.0
*
* @param int $starting_id The starting number.
* @param int $template_id WP_Post ID of the certificate template.
*/
$starting_id = apply_filters( 'llms_certificate_sequential_id_starting_number', 1, $template_id );
$id = absint( $starting_id );
$update = true;
}
if ( $update ) {
update_post_meta( $template_id, $key, $increment ? $id + 1 : $id );
}
/**
* Filters the sequential ID number for a given certificate template.
*
* The returned number *must* be an absolute integer. The returned value will be
* passed through `absint()` to sanitize the filtered value.
*
* @since 6.0.0
*
* @param int $id The sequential ID.
* @param int $template_id WP_Post ID of the certificate template.
*/
return absint( apply_filters( 'llms_certificate_sequential_id', $id, $template_id ) );
}
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
| Version | Description |
|---|---|
| 6.0.0 | Introduced. |