Skip to content

Instantly share code, notes, and snippets.

@ahmadawais
Created January 15, 2016 12:10
Show Gist options
  • Save ahmadawais/cde547a8fde705299ff5 to your computer and use it in GitHub Desktop.
Save ahmadawais/cde547a8fde705299ff5 to your computer and use it in GitHub Desktop.
WP: Generate Unique Title
/**
* 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