Skip to content

Instantly share code, notes, and snippets.

@davpsh davpsh/gist:11314964
Last active Aug 29, 2015

Embed
What would you like to do?
WP Добавление произвольного блока к slug-у поста
/* WP Добавление произвольного блока к slug-у поста */
function GenerateRandomInt($length){
$Characters = '0123456789';
$RandomInt = '';
for ($i = 0; $i < $length; $i++) {
$RandomInt .= $Characters[rand(0, strlen($Characters) - 1)];
}
return $RandomInt;
}
function filter_post_data( $data , $postarr ) {
$PostID = $postarr["ID"];
if($postarr["publish"]){
$NewInt = GenerateRandomInt(6);
$ChangedName = urlencode(strip_tags($NewInt."-".$data["post_name"]));
$data["post_name"] = $ChangedName;
}
return $data;
}
add_filter( 'wp_insert_post_data' , 'filter_post_data' , '99', 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.