Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save strangerstudios/bf897bf6ef2d14cc43e1 to your computer and use it in GitHub Desktop.
Save strangerstudios/bf897bf6ef2d14cc43e1 to your computer and use it in GitHub Desktop.
Code gists to help when running Theme My Login on Multisite with PMPro
/*
This is a collection of code gists that can optionally be used when running Themed My Login on a multisite network
to help things flow better.
Be sure to NETWORK ACTIVATE Theme My Login.
To be specific, this setup is meant for cases where users registering at the main site are gaining access to a "membersonly" subsite and users should effectively have a WP user account on all subsites within the network. i.e. all of the subsites are parts of the main site instead of completely different sites.
*/
/*
Keep non-admins out of the dashboard.
TML will send network admins to the profile page on subsites if they aren't also admins of the subsite. So we don't use this instead of Themed Profiles options to keep non-admins out of the dashboard.)
*/
function my_admin_init_hide_dashboard()
{
if(!current_user_can('edit_posts'))
{
wp_redirect(home_url());
exit;
}
}
add_action('admin_init', 'my_admin_init_hide_dashboard');
/*
Redirect /membersonly/ (subsite home) to login if not logged in
*/
function my_template_redirect_membersonly()
{
if(is_front_page() && !is_user_logged_in())
{
wp_redirect(wp_login_url());
exit;
}
}
add_action('template_redirect', 'my_template_redirect_membersonly');
/*
Tweak lost password email to point to /membersonly/ page.
*/
function my_retrieve_password_message($message)
{
if(strpos($message, "membersonly") === false)
$message = str_replace("/resetpass", "/membersonly/resetpass", $message);
return $message;
}
add_action('retrieve_password_message', 'my_retrieve_password_message');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment