WordPress.org

Ready to get started?Download WordPress

Forums

WordPress MU Sitewide Tags Pages
Author Posts Archive URL Redirect to Author's Blog (6 posts)

  1. nm
    Member
    Posted 2 years ago #

    On the tags blog, how do work the url of the posts archives for Authors (/author/username) so it redirects to the author's blog instead?

    http://wordpress.org/extend/plugins/wordpress-mu-sitewide-tags/

  2. Ron Rennick
    MultiSite Guru
    Plugin Author

    Posted 2 years ago #

    You'll have to write a plugin for that. See http://wordpress.org/extend/plugins/bp-blog-author-link/ for an example of how to filter the author URL.

  3. nm
    Member
    Posted 2 years ago #

    Thanks Ron, I think i'm on to something here, http://wordpress.stackexchange.com/questions/14047/how-to-hide-redirect-the-author-page

    Any clues to how to tie the author id to their blog? Any references/links would be just fine. I'm willing to dig around and learn.

  4. nm
    Member
    Posted 2 years ago #

    add_action( 'template_redirect', 'authorblog_template_redirect' );
    function authorblog_template_redirect()
    {
      $id = get_query_var( 'author' );
    global $bp;
    
    //two lines from bp_adminbar_blogs_menu() in bp-core-adminbar.php
    	if ( !$blogs = wp_cache_get( 'bp_blogs_of_user_' . $id . '_inc_hidden', 'bp' ) ) {
    		$blogs = bp_blogs_get_blogs_for_user( $id, true );
    		wp_cache_set( 'bp_blogs_of_user_' . $id . '_inc_hidden', $blogs, 'bp' );
    	}
    
    	if ( is_array( $blogs['blogs'] ) && (int)$blogs['count'] ) {
    		$blog=array_pop($blogs['blogs']);//the first blog
    
    		}
    
        if ( is_author() ) {
    
            // get_usernumposts() is deprecated since 3.0
            $post_count = count_user_posts( $id );
            if ( $post_count >= 0 ) {
                //This line could also be wp_redirect
                wp_redirect( $blog->siteurl );
                exit;
            }
     }
    
    }

    This works at about 50%

    For some reason if a user belongs to many other sites in the network as subscriber, this code doesn't find the one that the author is Administrator on.

    Any hints.

  5. nm
    Member
    Posted 2 years ago #

    This seems to be working better...

    add_action( 'template_redirect', 'authorblog_template_redirect' );
    function authorblog_template_redirect()
    {
    global $wpdb;
    $id = get_query_var( 'author' );
    
    //two lines from bp_adminbar_blogs_menu() in bp-core-adminbar.php
    
    		$blogs = get_active_blog_for_user(  $id );
    
        if ( is_author() ) {
    
            // get_usernumposts() is deprecated since 3.0
            $post_count = count_user_posts( $id );
            if ( $post_count >= 0 ) {
                //This line could also be wp_redirect
                wp_redirect( $blogs->siteurl );
                exit;
            }
     }
    
    }

    The user's blog must be set as their primary site under My Sites settings on there dashboard.

    Is there anyway to ensure that that their primary blog is always their site?

  6. Ron Rennick
    MultiSite Guru
    Plugin Author

    Posted 2 years ago #

    Is there anyway to ensure that that their primary blog is always their site?

    If they have more than one site they can change which one is the primary one.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic