Login

/*
Plugin Name: Login-Logout
Version: 2.6.1
Author: Roger Howorth
Author URI: http://www.thehypervisor.com
Plugin URI: http://www.thehypervisor.com/login-logout-changelog
Description: Adds a user friendly widget to make login/logout easy. Compatible WP 2.7+. Available in English, German, French, Italian, Spanish, Catalan, Dutch, Norwegian, Polish and Persian.
License: http://www.gnu.org/licenses/gpl.html
Text Domain: hypervisor-login-logout
*/
/*
Installation
1. Copy the file login-and-out.php to your WordPress plugins directory.
2. Login to WordPress as Administrator, go to Plugins and Activate it.
3. Add the Login-Logout widget to your Widget-enabled Sidebar
instead of the default “Meta” Widget

Credit: Thanks to Patrick Khoo http://www.deepwave.net/ for model code. I worked with his Hide dashboard code, removed unwanted sections and updated for WordPress 2.7+.

Copyright (c) 2009 Roger Howorth

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the “Software”), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

*/

function rh_hype_lilo_widget($args) {
extract($args);
$code = array();
global $user_identity , $user_email;
$options = get_option(‘rh_hidedash_options’);
$before_html = stripslashes($options[‘before_html’]);
$after_html = stripslashes($options[‘after_html’]);
echo $before_html;
echo __(stripslashes($options[‘title’]),’hypervisor-login-logout’);
echo ‘‘;
if ( !wp_specialchars($options[‘sidebar_width’]) ) $options[‘sidebar_width’] = “200”;
if ( $options[‘center_widget’] ) echo ‘

‘;
$all_links = get_option ( ‘rh_hidedash_links_options’ );
if ( !empty($all_links)) {
foreach ( $all_links as $link ) {
$extra_links = $extra_links . ‘‘. key($link).’ ‘;
}
}
if (is_user_logged_in()) {
// User Already Logged In
get_currentuserinfo(); // Usually someone already did this, right?
if ( $options[‘display_email’] == ‘1’ && !$options[‘hide_option_label’] ) $code[] = sprintf(__(‘Welcome, %s (%s)
Options:  ‘,’hypervisor-login-logout’),$user_identity,$user_email);
else
if ( $options[‘display_email’] == ‘1’ && $options[‘hide_option_label’] ) $code[] = sprintf(__(‘Welcome, %s (%s)
‘,’hypervisor-login-logout’),$user_identity,$user_email);
else
if ( $options[‘hide_option_label’] ) $code[] = sprintf(__(‘Welcome, %s
‘,’hypervisor-login-logout’),$user_identity);
else $code[] = sprintf(__(‘Welcome, %s
Options:  ‘,’hypervisor-login-logout’),$user_identity);
// Default Strings
$link_string_site = ““.__(‘Site Admin’,’hypervisor-login-logout’).”  |  “;
$link_string_logout = ‘‘.__(‘Log out’,’hypervisor-login-logout’).’‘;
$link_string_edit = ““.__(‘Edit Posts’,’hypervisor-login-logout’).”  |  “;
$link_string_profile = ““.__(‘My Profile’,’hypervisor-login-logout’).”  |  “;

// Administrator?
if (current_user_can(‘level_10’)) {
$code[] = $link_string_site;
$code[] = $link_string_logout;
if ( $extra_links ) $code[] = ‘
Links: ‘.$extra_links;
if ( $options[‘center_widget’] ) $code[] = ‘

‘;
$code[] = $after_html;
} else
// level_2?
if (current_user_can(‘level_2’)) {
if ($options[‘allow_authed’]) {
// Allow level_2 user to see Dashboard – treat like Administrator
$code[] = $link_string_site;
$code[] = $link_string_logout;
if ( $extra_links ) $code[] = ‘
Links: ‘.$extra_links;
if ( $options[‘center_widget’] ) $code[] = ‘

‘;
$code[] = $after_html;
}
// Hide Dashboard for level_2 user
$code[] = $link_string_edit;
$code[] = $link_string_logout;
if ( $extra_links ) $code[] = ‘
Links: ‘.$extra_links;
if ( $options[‘center_widget’] ) $code[] = ‘

‘;
$code[] = $after_html;
} else
// Less than level_2 user – Hide Dashboard from this User
{
$code[] = $link_string_profile;
$code[] = $link_string_logout;
if ( $extra_links ) $code[] = ‘
Links: ‘.$extra_links;
if ( $options[‘center_widget’] ) $code[] = ‘

‘;
$code[] = $after_html;
}
}
else {
// User _NOT_ Logged In
if ( $options[‘hide_register’] != 1 ) $code[] = ““.__(‘Register’,’hypervisor-login-logout’).”  |  “;
$code[] = ““.__(‘Login’,’hypervisor-login-logout’).”“;
$code[] = $after_html;
}
foreach ( $code as $snip ) {
_e($snip);
}
echo ““;
return $code;
}

function rh_hype_lilo() {
echo $before_widget;
global $user_identity , $user_email;
// $insert_php = get_option ( ‘rh_insert_php’ );
$options = get_option(‘rh_hidedash_options’);
$before_html = stripslashes($options[‘before_html’]);
$after_html = stripslashes($options[‘after_html’]);
echo ““;
echo ‘‘;
echo $before_html;
$all_links = get_option ( ‘rh_hidedash_links_options’ );
if ( !empty($all_links)) {
foreach ( $all_links as $link ) {
$extra_links = $extra_links . ‘‘. __(key($link),’hypervisor-login-logout’).’ ‘;
}
}
if (is_user_logged_in()) {
// User Already Logged In
get_currentuserinfo(); // Usually someone already did this, right?
if ( $options[‘display_email’] == ‘1’ && !$options[‘hide_option_label’] ) printf(__(‘Welcome, %s (%s)  Options:  ‘,’hypervisor-login-logout’),$user_identity,$user_email);
else
if ( $options[‘display_email’] == ‘1’ && $options[‘hide_option_label’] ) printf(__(‘Welcome, %s (%s)  ‘,’hypervisor-login-logout’),$user_identity,$user_email);
else
if ( $options[‘hide_option_label’] ) printf(__(‘Welcome, %s  ‘,’hypervisor-login-logout’),$user_identity);
else printf(__(‘Welcome, %s  Options:  ‘,’hypervisor-login-logout’),$user_identity);
// Default Strings
$link_string_site = ““.__(‘Site Admin’,’hypervisor-login-logout’).”  |  “;
$link_string_logout = ‘‘.__(‘Log out’,’hypervisor-login-logout’).’‘;
$link_string_edit = ““.__(‘Edit Posts’,’hypervisor-login-logout’).”  |  “;
$link_string_profile = ““.__(‘My Profile’,’hypervisor-login-logout’).”  |  “;

// Administrator?
if (current_user_can(‘level_10’)) {
echo $link_string_site;
echo $link_string_logout;
if ( $extra_links ) echo ‘  Links: ‘.$extra_links;
echo $after_html;
echo $after_widget;
echo ““;
return;
}
// level_2?
if (current_user_can(‘level_2’)) {
if ($options[‘allow_authed’]) {
// Allow level_2 user to see Dashboard – treat like Administrator
echo $link_string_site;
echo $link_string_logout;
if ( $extra_links ) echo ‘  Links: ‘.$extra_links;
echo $after_html;
echo $after_widget;
echo ““;
return;
}
// Hide Dashboard for level_2 user
echo $link_string_edit;
echo $link_string_logout;
if ( $extra_links ) echo ‘  Links: ‘.$extra_links;
echo $after_html;
echo $after_widget;
echo ““;
return;
}
// Less than level_2 user – Hide Dashboard from this User
echo $link_string_profile;
echo $link_string_logout;
if ( $extra_links ) echo ‘  Links: ‘.$extra_links;
echo $after_html;
echo $after_widget;
echo ““;
return;
}
// User _NOT_ Logged In
if ( $options[‘hide_register’] != 1 ) echo ““.__(‘Register’,’hypervisor-login-logout’).”  |  “;
echo ““.__(‘Login’,’hypervisor-login-logout’).”“;
echo $after_html;
echo $after_widget;
echo ““;
return;
}

function rh_hype_lilo_control () {
$options = get_option(‘rh_hidedash_options’);
if ( $_POST[‘rhhd_submit’] ) {
$options[‘sidebar_width’] = $_POST[‘rhhd_sb_width’];
$options[‘center_widget’] = $_POST[‘ecenter_widget’];
$options[‘title’] = $_POST[‘rhhd_title’];
update_option(‘rh_hidedash_options’, $options);
$cur_links = array();
$new_links = array();
$cur_links = get_option ( ‘rh_hidedash_links_options’ );
if ( !empty ($cur_links) ) {
$count=0;
foreach ( $cur_links as $link ) {
/* remove unwanted links… if a link is not ticked do not add to new_links array */
if ( $_POST[$count] <> ‘1’ ) { $count++; continue;}
$new_links[] = $link;
$count++;
}
}
// if we posted a new link add it to new_link array
if ( $_POST[‘nlink-text’] <> ” ) $new_links[] = array($_POST[‘nlink-text’] => $_POST[‘nlink-target’]);
if ( !empty ( $new_links) ) {
array_unique ( $new_links) ;
sort ( $new_links);
}
update_option ( ‘rh_hidedash_links_options’, $new_links );
}
$title = wp_specialchars(stripslashes($options[‘title’]));
if ( !wp_specialchars($options[‘sidebar_width’]) ) $options[‘sidebar_width’] = “160”;
?>


echo ”

“. __(‘Add a link to the widget’,’hypervisor-login-logout’). “

“;
echo __(‘Text for a new link’,’hypervisor-login-logout’) . ‘ :

‘;
echo __(‘Target for a new link’,’hypervisor-login-logout’) . ‘ :

‘;
echo ”

” . __(‘Remove Links’,’hypervisor-login-logout’) . “

“;
echo __(‘Un-tick to delete’,’hypervisor-login-logout’);
$all_links = get_option ( ‘rh_hidedash_links_options’ );
if ( !empty ($all_links) ) {
echo ‘

‘; $count = 0; $link = array(); echo ”;
foreach ( $all_links as $link ) {
echo ‘
‘;
$count++;
}
echo ‘

‘ . __(‘Text’,’hypervisor-login-logout’) . ‘ ‘ . __(‘Target’,’hypervisor-login-logout’) . ‘
‘. __(key($link),’hypervisor-login-logout’).’ ‘. current($link).’

‘;
}
else _e(‘

No links in database.

‘,’hypervisor-login-logout’);
?>

echo ‘‘;
_e(‘Login & Out widget settings’,’hypervisor-login-logout’);
echo ‘
‘;
_e(‘to adjust other settings.

‘,’hypervisor-login-logout’);
_e(‘Note: You must logout and in again to see changes in widget.’,’hypervisor-login-logout’);
return;
}

function rh_plugin_init() {
$plugin_dir = dirname(plugin_basename(__FILE__));
load_plugin_textdomain( ‘hypervisor-login-logout’, PLUGINDIR . ‘/’ . $plugin_dir , $plugin_dir );
register_sidebar_widget(‘Hypervisor ‘. __(‘Login/Logout’,’hypervisor-login-logout’), ‘rh_hype_lilo_widget’);
register_widget_control(‘Hypervisor ‘. __(‘Login/Logout’,’hypervisor-login-logout’), ‘rh_hype_lilo_control’);
return;
}

add_action(“plugins_loaded”, “rh_plugin_init”);
add_action(“admin_menu”, “rh_plugin_init”);

// Hook for adding admin menus
add_action(‘admin_menu’, ‘login_and_out_menu’);

// action function for above hook
function login_and_out_menu() {
add_management_page(‘Login & Out’, ‘Login & Out’, 8, ‘login_out_menu’, ‘login_out_menu’);
}

// login_out_menu() displays the page content for the Login & Out admin submenu
function login_out_menu() {
if ( isset ($_POST[‘update_loginout’]) ) {
if ( !wp_verify_nonce ( $_POST[‘loginout-verify-key’], ‘loginout’) ) die(__(‘Failed security check. Reload page and retry’,’hypervisor-login-logout’));
if ( $_POST[‘insert_php’] == ‘php’ ) update_option ( ‘rh_insert_php’, ‘1’ ); else update_option ( ‘rh_insert_php’, ‘0’ );
$options[“display_email”] = $_POST[‘edisplay_email’];
$options[“hide_register”] = $_POST[‘ehide_register’];
$options[“hide_option_label”] = $_POST[‘ehide_option_label’];
$options[“before_html”] = $_POST[‘ebefore_html’];
$options[“after_html”] = $_POST[‘eafter_html’];
update_option ( ‘rh_hidedash_options’, $options );

?>

} // end if isset
?>

echo ”

” . __(‘Login and Out Configuration’,’hypervisor-login-logout’) . “

“;
echo ‘‘;
$options = get_option(‘rh_hidedash_options’);
$insert_php = get_option ( ‘rh_insert_php’ );
$before_html = stripslashes($options[‘before_html’]);
$after_html = stripslashes($options[‘after_html’]);
echo ”

“. __(‘How to display Login Logout’,’hypervisor-login-logout’). “

“;
echo ”

“. __(‘Display the plugin by placing the widget in a sidebar or by inserting “&lt&#63php rh_hype_lilo();&#63&gt” into your template file(s).’,’hypervisor-login-logout’). ”

“;
?>

name=”edisplay_email” id=”edisplay_email” value=”1″ />
name=”ehide_option_label” id=”ehide_option_label” value=”1″ />
name=”ehide_register” id=”ehide_register” value=”1″ />

 

The Hypervisor

.




}

?>

Share this: