WordPress.org

Ready to get started?Download WordPress

Forums

Author Template link: edit author_base and view by nickname instead of nicename (7 posts)

  1. maccarrp
    Member
    Posted 8 years ago #

    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:
    /profile/nickname/

    Your help is appreciated.

  2. geoffe
    Member
    Posted 8 years ago #

    I tried to get a similar effect:
    http://wordpress.org/support/topic/61083

    I successfully have the author profile pages coming up with
    /author/user_login
    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:
    http://wordpress.org/support/topic/57653

  3. _ck_
    Member
    Posted 7 years ago #

    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);
    $this->init();
    }
    }

    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?

    http://www.dynamiccorestudios.com/archive/wordpress-plugin-custom-rewrite-rules/

  4. _ck_
    Member
    Posted 7 years ago #

    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:
    wp-includes\classes.php
    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);
    $this->init();
    }
    }

    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);
    $this->init();
    }
    }

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

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

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

    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
    wp-admin/options-permalink.php
    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)

  5. _ck_
    Member
    Posted 7 years ago #

    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'])) {
    check_admin_referer('update-permalink');

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

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

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

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

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

    if ( isset($_POST['comments_base']) ) {
    $comments_base = $_POST['comments_base'];
    if (! empty($comments_base) )
    $comments_base = preg_replace('#/+#', '/', '/' . $_POST['comments_base']);
    $wp_rewrite->set_comments_base($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');

  6. _ck_
    Member
    Posted 7 years ago #

    TADA!
    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.
    http://www.dagondesign.com/articles/wordpress-internal-rewrite-viewer-plugin/

    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.

  7. _ck_
    Member
    Posted 7 years ago #

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

    http://trac.wordpress.org/ticket/1762

    same thing I did with better code

Topic Closed

This topic has been closed to new replies.

About this Topic