Created
August 28, 2020 01:16
-
-
Save marktenney/df7dab06ca74c7f0c61473a8e385a800 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// List all user admin sites | |
// This is correctly listing the primary blog url | |
function get_primary_blog_url($id=null) { | |
// is there a user to check? | |
global $current_user; | |
$user_id = (null != $id ) ? $id : $current_user->ID; | |
if ( isset( $user_id ) ) { | |
// Get the blogs of this user | |
$user_blogs = get_blogs_of_user( $user_id ); | |
// Get the URL of the blog | |
foreach ( $user_blogs AS $user_blog ) { | |
if ( $user_blog->userblog_id != BLOG_ID_CURRENT_SITE ) { | |
return $user_blog->siteurl; | |
} | |
} | |
// If user has no blog, return to the homepage. | |
} else { | |
return home_url(); | |
} | |
} | |
add_shortcode( 'dgtl-sites-listing', 'get_primary_blog_url' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment