Much as I looove WP, one thing just bugs me silly: a user goes to a blog, registers, logs in, and then, in order to submit a post, they have to click a link labeled "Login". My brain screams, "I am logged in!!"
So I cobbled together this function, and replace everything in the "Other:" box, whose name I've already changed to "Do Stuff", with a call to my function. I also usually move it to the top, and ditch the trailing colons on all those section headers.
Now, when someone who is not logged in visits the page, links for "Register" and "Login" show up. After they log in, links for "Create a Post", "Edit a Post", and "Change Settings" appear instead. I inserted links to the specific pages because I thought it was unfriendly to just dump someone in the Dashboard and make them figure it out alone.
Below is my function, let me know if I've done something inadvertently terrible, I'm still pretty new at this. Also, I always try to mark my hacks so I can find them when things blow up, which is why I named the function with a "jw_" prefix, and use my name in comments. That's my hint not to blame WP if it doesn't work.
Also, I realize WP has a function "wp_loginout()" which is very similar--in fact, I stole the code from it. But from a user standpoint, it makes more sense to me to replace the "Login" link with links that provide functions available once you have logged in rather than a "Logout" link.
In "wp-includes/template-functions-general.php":
/* the following function does not come with WP. added by Jeff. */
function jw_loginorpost() {
global $user_ID;
get_currentuserinfo();
if ('' == $user_ID) :
$link = 'If you want to post, first <a href="' . get_settings('siteurl') .
'/wp-register.php">' . __('Register') . '</a> if you haven\'t yet, then <a href="' .
get_settings('siteurl') . '/wp-login.php">' . __('Login') . '</a>.';
else :
$link = '<a href="' . get_settings('siteurl') . '/wp-admin/post.php">' .
__('Create a Post') . '</a>' . '<br /><br />' . '<a href="' . get_settings('siteurl') .
'/wp-admin/edit.php">' . __('Edit a Post') . '</a>' . '<br /><br />' . '<a href="' .
get_settings('siteurl') . '/wp-login.php">' . __('Change Settings') . '</a>';
endif;
echo apply_filters('loginorpost', $link);
}
Jeff, I made some minor changes to your function. It provided the funtionality that I wanted (minus the tweaks I made). Thanks!
In "wp-includes/template-functions-general.php":
/* the following function does not come with WP. added by Jeff. */
function jw_loginorpost() {
global $user_ID ,$user_identity;
get_currentuserinfo();
if ('' == $user_ID) :
$link = 'To post you must <a href="' . get_settings('siteurl') .
'/wp-register.php">' . __('Register') . '</a></br> if you have an account <a href="' .
get_settings('siteurl') . '/wp-login.php">' . __('Login') . '</a>.';
else :
$link = '<b>' . $user_identity .'</b><br/>' . '<a href="' .
get_settings('siteurl') .'/wp-admin/post.php">' .
__('Create a Post') . '</a>' . '<br />' . '<a href="' .
get_settings('siteurl') . '/wp-admin/edit.php">' . __('Edit a Post') . '</a>' . '<br />' . '<a href="' .
get_settings('siteurl') . '/wp-login.php">' . __('Change Settings') . '</a>' . '<br/>' . '
<a href="' . get_option('siteurl') . '/wp-login.php?action=logout">' . __('Logout') . '</a>';
endif;
echo apply_filters('loginorpost', $link);
Usage in sidebar.php
<!-- /* Add new list header To Id user and provide logged in user options */ -->
<ul><li class="listHeader"><h2><?php _e('Welcome'); ?></h2></li>
<li><?php jw_loginorpost(); ?></li>
</ul>
MPorras 03:55, 17 Mar 2007 (UTC)