Wordpress Validate New Nicename/Slug -


i have written custom "edit account" script allows wordpress user update wordpress account. working great, except can't seem find way update user's nicename, doubles user's url slug (via get_author_posts_url function). causing issues because when user changes name, slug still contains original name - not new one.

i know sanitize_title function generate new nicename, don't know how verify unique , modify if not before entering db. wondering built-in functions wordpress has handle this. know can write own script this, rather use wordpress functions. couldn't find anywhere in wp documentation. thanks!

here function have written in lue of built in function:

function new_user_slug($string){    //generate new slug    $slug=sanitize_title($string);     //make sure slug unique    $result=mysql_query("select * wp_users user_nicename='$slug'");    if(mysql_num_rows($result)==0){     return $slug;    }else{     $counter=2;     $kill=0;     while($kill==0){         $mod_slug=$slug."-".$counter;            $result=mysql_query("select * wp_users user_nicename='$mod_slug'");            if(mysql_num_rows($result)==0){             $kill=1;            }else{             $counter++;            }        }        return $mod_slug;     } } 

this takes string (the user's updated name) , converts default slug. checks slug against database see if unique. if is, slug returned. if not, enters iteration loop incrementally changes slug until unique.


Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -