Created
January 15, 2016 12:10
-
-
Save ahmadawais/cde547a8fde705299ff5 to your computer and use it in GitHub Desktop.
WP: Generate Unique Title
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Generate Unique Title. | |
* | |
* @since 1.0.0 | |
*/ | |
public function booking_title() { | |
// Generate a random number with 8 length. | |
$id_length = 8; | |
$uniqueid = crypt( uniqid( rand(), 1 ) ); | |
$uniqueid = strip_tags( stripslashes( $uniqueid ) ); | |
$uniqueid = str_replace( ".","",$uniqueid ); | |
$uniqueid = strrev( str_replace( "/","",$uniqueid ) ); | |
$uniqueid = substr( $uniqueid, 0, $id_length ); | |
$uniqueid = strtoupper( $uniqueid ); | |
// Format the title. | |
$title = 'Booking: #' . $uniqueid . ' - ' . date( 'd-m-Y' ); | |
// Return the title. | |
return $title; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment