php - How to redirect new WordPress multisite user inside their admin panel after they log in? -
here code in functions.php redirects users (to new "sample page") when log in:
function admin_default_page() { homecoming '/wp-admin/post.php?post=2&action=edit'; } add_filter('login_redirect', 'admin_default_page'); the problem url redirect missing users site url. example, if user creates site "bobs trucks", redirects them
example.com/wp-admin/post.php?post=2&action=edit (does not work)
instead of
example.com/bobstrucks/wp-admin/post.php?post=2&action=edit
i've tried wordpress functions total url needed (example.com/bobstrucs/url-to-redirect-to) have not succeeded.
i'm trying rather hackish solution user id form logged in user, , blogs user has (= one, "bobs trucks"):
function admin_default_page() { global $current_user; get_currentuserinfo(); $blogs = get_blogs_of_user( $current_user->id); foreach($blogs $blog) { $userblog = $blog->siteurl; } homecoming $userblog .'/wp-admin/post.php?post=2&action=edit'; } add_filter('login_redirect', 'admin_default_page'); but 1 has problem of not working first time user logs in.
thank much!
try this:
function admin_default_page() { if ( is_user_logged_in() && is_admin() ) { $blog_id = get_current_blog_id(); $blog = get_blog_details( array( 'blog_id' => $blog_id ) ); $location = '/' . $blog->blogname . '/wp-admin/post.php?post=2&action=edit'; wp_redirect( $location ); exit; } } add_filter( 'login_redirect', 'admin_default_page' ); refs:
http://codex.wordpress.org/function_reference/get_blog_details http://codex.wordpress.org/function_reference/wp_redirect php wordpress function url-redirection
No comments:
Post a Comment