Sidebar Login - Version 2.0

Version Description

Download this release

Release Info

Developer jolley_small
Plugin Icon 128x128 Sidebar Login
Version 2.0
Comparing to
See all releases

Version 2.0

Files changed (4) hide show
  1. readme.txt +31 -0
  2. screenshot-1.jpg +0 -0
  3. screenshot-2.jpg +0 -0
  4. sidebar-login.php +176 -0
readme.txt ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Plugin Name ===
2
+ Contributors: jolley_small
3
+ Author URI: http://blue-anvil.com/archives/wordpress-sidebar-login-2-optimised-for-wordpress-26
4
+ Plugin URI: http://blue-anvil.com/archives/wordpress-sidebar-login-2-optimised-for-wordpress-26
5
+ Donate link: http://blue-anvil.com/archives/wordpress-sidebar-login-2-optimised-for-wordpress-26
6
+ Tags: login, sidebar, widget, sidebar login, meta, form, register
7
+ Requires at least: 2.0
8
+ Tested up to: 2.6
9
+ Stable tag: 2.0
10
+
11
+ Plugin with interface for uploading and managing download files, inserting download links in posts, and monitoring download hits.
12
+
13
+ == Description ==
14
+
15
+ Sidebar-Login has both a widget and a template tag to allow you to have a login form in the sidebar of your wordpress powered blog.
16
+
17
+ It lets users login, and then redirects them back to the page they logged in from rather than the backend, it also shows error messages.
18
+
19
+ == Installation ==
20
+
21
+ = First time installation instructions =
22
+
23
+ 1. Unzip and upload the php file to your wordpress plugin directory
24
+ 2. Activate the plugin
25
+ 3. For a sidebar widget: Goto the design > widgets tab - Drag the widget into a sidebar and save!
26
+ 4. To use the template tag: Add <?php sidebarlogin(); ?> to your template.
27
+
28
+ == Screenshots ==
29
+
30
+ 1. Login Form
31
+ 2. After Login
screenshot-1.jpg ADDED
Binary file
screenshot-2.jpg ADDED
Binary file
sidebar-login.php ADDED
@@ -0,0 +1,176 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: Sidebar Login
4
+ Description: Adds a sidebar widget to let users login
5
+ Author: Mike Jolley
6
+ Plugin URI: http://blue-anvil.com
7
+ Version: 2.0
8
+ Author URI: http://blue-anvil.com
9
+ */
10
+ function sidebarlogin() {
11
+ $args["before_widget"]="";
12
+ $args["after_widget"]="";
13
+ $args["before_title"]="<h2>";
14
+ $args["after_title"]="</h2>";
15
+ widget_sidebarlogin($args);
16
+ }
17
+ function widget_sidebarlogin($args) {
18
+
19
+ extract($args);
20
+
21
+ global $user_ID;
22
+
23
+ if (isset($user_ID)) {
24
+ // User is logged in
25
+ $user_info = get_userdata($user_ID);
26
+ echo $before_widget . $before_title . __("Welcome "). $user_info->user_name . $after_title;
27
+ echo '<ul class="pagenav">
28
+ <li class="page_item"><a href="'.get_bloginfo('wpurl').'/wp-admin">'.__('Dashboard').'</a></li>
29
+ <li class="page_item"><a href="'.get_bloginfo('wpurl').'/wp-admin/profile.php">'.__('Profile').'</a></li>
30
+ <li class="page_item"><a href="'.current_url('logout').'">'.__('Logout').'</a></li>
31
+ </ul>';
32
+ } else {
33
+ // User is NOT logged in!!!
34
+ echo $before_widget . $before_title . __("Login") . $after_title;
35
+ // Show any errors
36
+ global $myerrors;
37
+ $wp_error = new WP_Error();
38
+ if ( !empty($myerrors) ) {
39
+ $wp_error = $myerrors;
40
+ }
41
+ if ( $wp_error->get_error_code() ) {
42
+ $errors = '';
43
+ $messages = '';
44
+ foreach ( $wp_error->get_error_codes() as $code ) {
45
+ $severity = $wp_error->get_error_data($code);
46
+ foreach ( $wp_error->get_error_messages($code) as $error ) {
47
+ if ( 'message' == $severity )
48
+ $messages .= ' ' . $error . "<br />\n";
49
+ else
50
+ $errors .= ' ' . $error . "<br />\n";
51
+ }
52
+ }
53
+ if ( !empty($errors) )
54
+ echo '<div id="login_error">' . apply_filters('login_errors', $errors) . "</div>\n";
55
+ if ( !empty($messages) )
56
+ echo '<p class="message">' . apply_filters('login_messages', $messages) . "</p>\n";
57
+ }
58
+ // login form
59
+ echo '<form action="'.current_url().'" method="post" >';
60
+ ?>
61
+ <p><label for="user_login"><?php _e('Username:') ?><br/><input name="log" value="<?php echo attribute_escape(stripslashes($_POST['log'])); ?>" class="mid" id="user_login" type="text" /></label></p>
62
+ <p><label for="user_pass"><?php _e('Password:') ?><br/><input name="pwd" class="mid" id="user_pass" type="password" /></label></p>
63
+ <p><label for="rememberme"><input name="rememberme" class="checkbox" id="rememberme" value="forever" type="checkbox" /> <?php _e('Remember me'); ?></label></p>
64
+ <p class="submit"><input type="submit" name="wp-submit" id="wp-submit" value="<?php _e('Login'); ?> &raquo;" />
65
+ <input type="hidden" name="sidebarlogin_posted" value="1" />
66
+ <input type="hidden" name="testcookie" value="1" /></p>
67
+ </form>
68
+ <?php
69
+ // Output other links
70
+ echo '<ul class="sidebarlogin_otherlinks">';
71
+ if (get_option('users_can_register')) {
72
+ // MU FIX
73
+ global $wpmu_version;
74
+ if (empty($wpmu_version)) {
75
+ ?>
76
+ <li><a href="<?php bloginfo('wpurl'); ?>/wp-login.php?action=register"><?php _e('Register') ?></a></li>
77
+ <?php
78
+ } else {
79
+ ?>
80
+ <li><a href="<?php bloginfo('wpurl'); ?>/wp-signup.php"><?php _e('Register') ?></a></li>
81
+ <?php
82
+ }
83
+ }
84
+ ?>
85
+ <li><a href="<?php bloginfo('wpurl'); ?>/wp-login.php?action=lostpassword" title="<?php _e('Password Lost and Found') ?>"><?php _e('Lost your password?') ?></a></li>
86
+ </ul>
87
+ <?php
88
+ }
89
+ // echo widget closing tag
90
+ echo $after_widget;
91
+ }
92
+ function widget_sidebarlogin_init() {
93
+ if ( !function_exists('register_sidebar_widget') ) return;
94
+ // Register widget for use
95
+ register_sidebar_widget(array('Sidebar Login', 'widgets'), 'widget_sidebarlogin');
96
+ }
97
+ function widget_sidebarlogin_check() {
98
+ if ($_POST['sidebarlogin_posted'] || $_GET['logout']) {
99
+ // Includes
100
+ //include_once('wp-settings.php');
101
+ global $myerrors;
102
+ $myerrors = new WP_Error();
103
+ //Set a cookie now to see if they are supported by the browser.
104
+ setcookie(TEST_COOKIE, 'WP Cookie check', 0, COOKIEPATH, COOKIE_DOMAIN);
105
+ if ( SITECOOKIEPATH != COOKIEPATH )
106
+ setcookie(TEST_COOKIE, 'WP Cookie check', 0, SITECOOKIEPATH, COOKIE_DOMAIN);
107
+ // Logout
108
+ if ($_GET['logout']==true) {
109
+ wp_logout();
110
+ wp_redirect(current_url('nologout'));
111
+ exit();
112
+ }
113
+ // Are we doing a sidebar login action?
114
+ if ($_POST['sidebarlogin_posted']) {
115
+
116
+ if ( is_ssl() && force_ssl_login() && !force_ssl_admin() && ( 0 !== strpos($redirect_to, 'https') ) && ( 0 === strpos($redirect_to, 'http') ) )
117
+ $secure_cookie = false;
118
+ else
119
+ $secure_cookie = '';
120
+
121
+ $user = wp_signon('', $secure_cookie);
122
+
123
+ // Error Handling
124
+ if ( is_wp_error($user) ) {
125
+
126
+ $errors = $user;
127
+
128
+ // If cookies are disabled we can't log in even with a valid user+pass
129
+ if ( isset($_POST['testcookie']) && empty($_COOKIE[TEST_COOKIE]) )
130
+ $errors->add('test_cookie', __("<strong>ERROR</strong>: Cookies are blocked or not supported by your browser. You must <a href='http://www.google.com/cookies.html'>enable cookies</a> to use WordPress."));
131
+
132
+ if ( empty($_POST['log']) && empty($_POST['pwd']) ) {
133
+ $errors->add('empty_username', __('<strong>ERROR</strong>: Please enter a username.'));
134
+ $errors->add('empty_password', __('<strong>ERROR</strong>: Please enter your password.'));
135
+ }
136
+
137
+ $myerrors = $errors;
138
+
139
+ } else {
140
+ wp_redirect(current_url('nologout'));
141
+ exit;
142
+ }
143
+ }
144
+ }
145
+ }
146
+ if ( !function_exists('current_url') ) :
147
+ function current_url($url = '') {
148
+ $pageURL = 'http';
149
+ if ($_SERVER["HTTPS"] == "on") $pageURL .= "s";
150
+ $pageURL .= "://";
151
+ if ($_SERVER["SERVER_PORT"] != "80") {
152
+ $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
153
+ } else {
154
+ $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
155
+ }
156
+ if ($url == "logout" && strstr($pageURL,'logout')==false) {
157
+ if (strstr($pageURL,'?')) {
158
+ $pageURL .='&logout=true';
159
+ } else {
160
+ $pageURL .='?logout=true';
161
+ }
162
+ }
163
+ if ($url == "nologout" && strstr($pageURL,'logout')==true) {
164
+ $pageURL = str_replace('?logout=true','',$pageURL);
165
+ $pageURL = str_replace('&logout=true','',$pageURL);
166
+ }
167
+ //�����added by mick
168
+ if (!strstr(get_bloginfo('wpurl'),'www.')) $pageURL = str_replace('www.','', $pageURL );
169
+ //�������
170
+ return $pageURL;
171
+ }
172
+ endif;
173
+ // Run code and init
174
+ add_action('init', 'widget_sidebarlogin_check',1);
175
+ add_action('widgets_init', 'widget_sidebarlogin_init');
176
+ ?>