LLMS_Certificates::get_unique_slug( string $title )
Create a unique slug for earned certificates.
Description Description
When relying only on wp_unique_post_slug()
, predictable URLs are created for earned certificates, such as "certificate-of-completion-1", "certificate-of-completion-2", etc… this method creates an obtuse and randomized suffix and appends it to the post slug.
The unique suffix will be a randomized string at least 3 characters long and made up of lowercase letters and numbers.
When ensuring uniqueness of the generated suffix, the length of the string will be increased by one for every 5 encountered collisions.
Parameters Parameters
- $title
-
(string) (Required) The title of the certificate being created.
Return Return
(string)
Source Source
File: includes/class.llms.certificates.php
public function get_unique_slug( $title ) { $title = sanitize_title( $title ) . '-'; /** * Filters the minimum length of the suffix used to create a unique earned certificate slug. * * @since 6.0.0 * * @param int $min_strlen The minimum desired suffix string length. */ $min_strlen = apply_filters( 'llms_certificate_unique_slug_suffix_min_length', 3 ); $i = 0; do { $length = $min_strlen + floor( $i / 5 ); $slug = $title . strtolower( wp_generate_password( absint( $length ), false ) ); $i++; } while ( wp_unique_post_slug( $slug, 0, 'publish', 'llms_my_certificate', 0 ) !== $slug ); return $slug; }
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
6.0.0 | Introduced. |