Well, I've never used any CMS and I was simply under the impression that it adds complexity that is overkill for my needs. Saying that, I am kinda surprised that it is taking so much effort to set things up the way I want it. I've got two questions:
1. By default, it seems that WordPress redirect a logged-in user to the dashboard. It might make sense when it's me, the admin, but how can I redirect a user exactly back to the page s/he logged from?
2. This one is for anyone familiar with WordPress / PHP with a bit of spare time. I've installed a plug-in called "Members" for the sole purpose of being able to hide contents from posts according to users. The plug-in comes with a shortcode called [access] which does almost what I need. It takes a parameter called "role", and if the logged-in user matches the role, then content within a post can be displayed. So I can transparently hide contents within a post (as opposed to having entire posts private). The problem is, the shortcode can only take one role at the moment. This leads to the odd scenario where if I set a content to be only viewable by "friends" (custom role), I, as the "administrator" can not view the content (without logging into a dummy "friend" account). I had a peek at the code, it the author has stated that multi-roles will be implemented in the future. But that was a year and a half ago, and it looks like his latest version of the plug-in is only available through his own site, for members who are paying for support. Since I do not know if he intends to publicly release the new plugin, I've decided to do a lame edit to his code:
Code:
/**
* Provide/restrict access to specific roles or capabilities. This content should
* not be shown in feeds.
*
* @todo Allow multiple roles and capabilities to be input (comma-separated).
*
* Content should be wrapped like [access role="editor"]This is content.[/access].
*
* @since 0.1
* @uses current_user_can() Checks if the current user has the role or capability.
* @uses is_feed() Checks if we're currently viewing a feed.
* @param $attr array The shortcode attributes.
* @param $content string The content that should be shown/restricted.
* @return $content string The content if it should be shown. Else, return nothing.
*/
function members_access_check_shortcode( $attr, $content = null ) {
/* Set up the default attributes. */
$defaults = array(
'capability' => '',
'role' => '',
'feed' => false,
);
/* Merge the input attributes and the defaults. */
extract( shortcode_atts( $defaults, $attr ) );
/* If the current user has the input capability, show the content. */
if ( $capability && current_user_can( $capability ) )
return $content;
/* If the current user is admin */
elseif ( current_user_can( 'administrator') )
return $content;
/* If the current user has the input role, show the content. */
elseif ( $role && current_user_can( $role ) )
return $content;
/* If $feed was set to true and we're currently displaying a feed, show the content. */
elseif ( $feed && 'false' !== $feed && is_feed() )
return $content;
/* If there is no content, return nothing. */
elseif ( !is_null( $content ) )
return '';
/* Return nothing if none of the conditions have been met. */
return '';
}
Bits in bold is what I've added. Dirty fix for what I'd like now, but inadequate if I ever find myself in a situation where I'd like to have contents for "friends" and "family". For that, I'd have to implement what the author said he would do, notably comma separated input for multiple roles / capabilities.
I have a vague idea of how I might try to solve this, but I'll need to figure out how strings work in PHP and I am not confident that I won't break something. Is this something anyone here might be able to do quite easily?