Support » Plugins » Author Template link: edit author_base and view by nickname instead of nicename

  • My question is two part: (all in WP 2.0.1)

    1) How can I modify author_base to switch from the default ‘author’ to ‘profile’?
    * I don’t want to edit the core WP
    * Even when I do change the core… line 865 in classes.php — var $author_base = ‘author’; — to ‘profile’ — i still can’t get an author to display at /profile/%author%/

    2) How can I view by nickname instead of nicename?
    * I’m looking to display author profiles at: /profile/nickname/
    * I’ve confirmed that no duplicate nicknames exist, and built actions to prevent duplicates in the future

    What works:
    I can view profiles right now just fine at:
    /index.php?author=1 (or the author user id)
    I can also view profiles at:
    /author/jane-doe/ (or the author nice name)

    I want:

    Your help is appreciated.

Viewing 6 replies - 1 through 6 (of 6 total)
  • I tried to get a similar effect:

    I successfully have the author profile pages coming up with
    but unfortunately I’ve not got an answer to how to get your desired effect.

    Let me know how or if you figured this out– I’d like to know what uses there are for nicknames in WP 2.x as I’m redoing the DB for user profiles. From what I can tell, they aren’t useful.

    edit: I can think of one use, which is to give another option for the user to pick as the display name. I suppose that’s it. And I’ve now found this interesting info:

    I’ll add a “me too” request to this.

    I’ve been studying other plugins to figure it out and I think the key is that $author_base is readable, not writeable.

    For example if you look at the $category_base it’s for reading the property only and then there is set_category_base($category_base)

    There is no set_author_base so we have to make one. If I can find the code for set_category_base we can hack it for that.

    Here we go, it’s in wordpress/trunk/wp-includes/rewrite.php

    function set_category_base($category_base) {
    if ($category_base != $this->category_base) {
    update_option('category_base', $category_base);

    so just change the word “category” to “author” everywhere in the function and we are set.

    Now I just need to learn how to make that function hook into the wp startup code. Seems like it would slow things down as it has to be called everytime. Would have been nice just to have it in wp-config.php or something similar.

    Ah and here is a plugin that lets you modify ALL the rewrite rules, though I am not sure if WP will then know if things like $author_base have changed?

    Okay after a bunch of poking around I got this working nicely from the permalinks option in the dashboard/control panel.

    Unfortunately due to my limited knowledge of WordPress and if the init() function is replaceable by a plugin, I chose to do this directly as a hack for now. Those that know better can see what I did and perhaps make it a complete standalone plugin with no hacks needed?

    Okay, start here:
    function init() at or around line 1425 in wp2.0.3
    it’s missing all the options to set ANY base except for category – someone was either in a hurry or lazy

    add below the $this->category_base…

    $this->author_base = get_settings('author_base');
    $this->feed_base = get_settings('feed_base');
    $this->search_base = get_settings('search_base');
    $this->comments_base = get_settings('comments_base');

    that will allow WP to rebuild all the rules for those extra bases

    now find this part of code in classes.php

    function set_category_base($category_base) {
    if ($category_base != $this->category_base) {
    update_option('category_base', $category_base);

    and again mimic it for the other bases, adding

    function set_author_base($author_base) {
    if ($author_base != $this->author_base) {
    update_option('author_base', $author_base);

    function set_feed_base($feed_base) {
    if ($feed_base != $this->feed_base) {
    update_option('feed_base', $feed_base);

    function set_search_base($search_base) {
    if ($search_base != $this->search_base) {
    update_option('search_base', $search_base);

    function set_comments_base($comments_base) {
    if ($comments_base != $this->comments_base) {
    update_option('comments_base', $comments_base);

    it’s a shame all this isn’t done in a nice “eval” loop with an array of all the bases but that’s too much work for me right now and I don’t want to break anything

    now we need to move to
    it’s going to need bunch of additions, all mimicking the functions for base_category

    first find
    <?php _e('Category base'); ?>: <input name="category_base" type="text" class="code" value="<?php echo $category_base; ?>" size="30" />

    and again, add and mimic:

    <?php _e('Author base'); ?>: <input name="author_base" type="text" class="code" value="<?php echo $author_base; ?>" size="30" />

    <?php _e('Feed base'); ?>: <input name="feed_base" type="text" class="code" value="<?php echo $feed_base; ?>" size="30" />

    <?php _e('Search base'); ?>: <input name="search_base" type="text" class="code" value="<?php echo $search_base; ?>" size="30" />

    <?php _e('Comments base'); ?>: <input name="comments_base" type="text" class="code" value="<?php echo $comments_base; ?>" size="30" />

    (saving and coming back to edit)

    Last step is a big addition of code, find this line near the top
    if ( isset($_POST['permalink_structure']) || isset($_POST['category_base'])
    and all the way to
    $category_base = get_settings('category_base');

    replace it with this chunk:

    if ( isset($_POST['permalink_structure']) || isset($_POST['category_base']) || isset($_POST['author_base']) || isset($_POST['feed_base']) || isset($_POST['search_base']) || isset($_POST['comments_base'])) {

    if ( isset($_POST['permalink_structure']) ) {
    $permalink_structure = $_POST['permalink_structure'];
    if (! empty($permalink_structure) )
    $permalink_structure = preg_replace('#/+#', '/', '/' . $_POST['permalink_structure']);

    if ( isset($_POST['category_base']) ) {
    $category_base = $_POST['category_base'];
    if (! empty($category_base) )
    $category_base = preg_replace('#/+#', '/', '/' . $_POST['category_base']);

    if ( isset($_POST['author_base']) ) {
    $author_base = $_POST['author_base'];
    if (! empty($author_base) )
    $author_base = preg_replace('#/+#', '/', '/' . $_POST['author_base']);

    if ( isset($_POST['feed_base']) ) {
    $feed_base = $_POST['feed_base'];
    if (! empty($feed_base) )
    $feed_base = preg_replace('#/+#', '/', '/' . $_POST['feed_base']);

    if ( isset($_POST['search_base']) ) {
    $search_base = $_POST['search_base'];
    if (! empty($search_base) )
    $search_base = preg_replace('#/+#', '/', '/' . $_POST['search_base']);

    if ( isset($_POST['comments_base']) ) {
    $comments_base = $_POST['comments_base'];
    if (! empty($comments_base) )
    $comments_base = preg_replace('#/+#', '/', '/' . $_POST['comments_base']);


    $permalink_structure = get_settings('permalink_structure');
    $category_base = get_settings('category_base');
    $author_base = get_settings('author_base');
    $feed_base = get_settings('feed_base');
    $search_base = get_settings('search_base');
    $comments_base = get_settings('comments_base');

    Once you upload and go to the permalinks section you will see you can change all the bases – tested working.

    You can use the “WordPress Internal Rewrite Viewer” to see the changes happen after you save.

    There is only one bug right now that I can see.
    Unlike the category field, if you clear out the others, they do not revert to their default.

    I think this has to do with the way wp_rewrite inits and has default settings, category_base is done differently and I am not sure how.

    Unsetting the variables may fix it, I am too much a novice at PHP to figure it out right now, perhaps a greater mind can tell me easily how to fix that.

    This is too late for 2.0.4 I guess but I’d like to see this fix permanently done for 2.1.0 – I have no idea how to use the bugtrack system so feel free to submit all this for me if you are a bugtrack pro.

    Oh heck, I just discover this ticket which is slated for 2.1

    same thing I did with better code

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Author Template link: edit author_base and view by nickname instead of nicename’ is closed to new replies.