Theme My Login - Version 1.0.1

Version Description

Download this release

Release Info

Developer jfarthing84
Plugin Icon 128x128 Theme My Login
Version 1.0.1
Comparing to
See all releases

Version 1.0.1

Files changed (2) hide show
  1. readme.txt +48 -0
  2. theme-my-login.php +632 -0
readme.txt ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Theme My Login ===
2
+ Contributors: jfarthing84
3
+ Donate link: http://webdesign.jaedub.com
4
+ Tags: wordpress, login, register, theme, form
5
+ Requires at least: 2.5
6
+ Tested up to: 2.5
7
+ Stable tag: 1.1
8
+
9
+ This plugin makes your registration and login pages look just like the rest of your website.
10
+
11
+
12
+ == Description ==
13
+
14
+ This plugin makes your registration and login pages look just like the rest of your website by replacing the wp-login.php page with a function that includes the header files, footer files, and all of the HTML in between that you specify in the 'Theme My Login' settings.
15
+
16
+
17
+ == Installation ==
18
+
19
+ Upload the Theme My Login plugin to your 'wp-content/plugins' directory and activate it. The 'Theme My Login' settings will apear under the 'Settings' menu in the WordPress admin. You will need to go in to these settings and set them according to your theme layout. Here is a desciption of what needs to go into each setting.
20
+
21
+ 1. Redirect on Login - You can change this to any location you would like the user to be redirected to upon login. This defaults to 'wp-admin/'.
22
+
23
+ 2. Redirect on Logout - You can change this to any location you would like the user to be redirected to upon logout. This defaults to 'wp-login.php?loggedout=true'.
24
+
25
+ 3. Register Text - You can change this to whatever text you want to appear above your registration form. This defaults to 'Register'.
26
+
27
+ 4. Login Text - You can change this to whatever text you want to appear above your login form. This defaults to 'Log In'.
28
+
29
+ 5. Forgot Password Text - You can change this to whatever text you want to appear above your forgot password form. This defaults to 'Forgot Password'.
30
+
31
+ 6. Template Header Files - Enter each header file used in your template, one per line. Typically, this is only header.php, but you can figure this out by clicking Appearance->Editor->Main Index Template. If the only function call you see is get_header() before the HTML then it's likely this is the only file you need to enter.
32
+
33
+ 7. Template HTML After Header - Enter the HTML that appears between the get_header() function and the page code. You can probably figure this out by clicking Appearance->Editor->Main Index Template. The HTML you need to copy is everything between the last ?> in the top of the file and the line that looks something like this: <?php endif; ?> and the line that may look like this: <?php get_sidebar(); ?>. Keep in mind that if you are using a template that doesn't fit the typical scheme, you will need to experiment a bit to get this right.
34
+
35
+ 8. Template HTML Before Footer - Enter the HTML that appears between the page code and the get_sidebar()/get_footer() functions. You can probably figure this out by clicking Appearance->Editor->Main Index Template. The HTML you need to copy is everything between the last ?> in the top of the file and the line that looks something like this: <?php if (have_posts()) : ?>. Keep in mind that if you are using a template that doesn't fit the typical scheme, you will need to experiment a bit to get this right.
36
+
37
+ 9. Template Footer Files - Enter each footer file used in your template, one per line. Typically this is sidebar.php and footer.php. You can figure this out by clicking Appearance->Editor->Main Index Template. If you see the function calls get_sidebar() and get_footer() then you should be able to leave the defaults alone.
38
+
39
+ Now you can save your changes and go test out your new themed login and registration pages. That's all!
40
+
41
+
42
+ == Version History ==
43
+
44
+ * 1.0.0 - 2009-03-13 - Initial release version
45
+ * 1.0.1 - 2009-03-14 - Made backwards compatible to WordPress 2.5+
46
+
47
+
48
+ http://webdesign.jaedub.com
theme-my-login.php ADDED
@@ -0,0 +1,632 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: Theme My Login
4
+ Plugin URI: http://webdesign.jaedub.com/wordpress-plugins/theme-my-login-plugin
5
+ Description: This plugin creates custom login and register pages to replace the wp-login and wp-register pages.
6
+ Version: 1.0.1
7
+ Author: Jae Dub
8
+ Author URI: http://webdesign.jaedub.com
9
+
10
+ Version History
11
+
12
+ 1.0.0 - 2009-03-13
13
+ Initial release version
14
+ 1.0.1 - 2009-03-14
15
+ Made backwards compatible to WordPress 2.5+
16
+
17
+ */
18
+
19
+ if (!class_exists('ThemeMyLogin')) {
20
+ class ThemeMyLogin {
21
+
22
+ var $options = array();
23
+
24
+ function ThemedRegLog() {
25
+ $this->__construct();
26
+ }
27
+
28
+ function __construct() {
29
+ register_activation_hook ( __FILE__, array( &$this, 'Activate' ) );
30
+ register_deactivation_hook ( __FILE__, array( &$this, 'Deactivate' ) );
31
+
32
+ add_action('init', array(&$this, 'Init'));
33
+ add_action('admin_menu', array(&$this, 'AddAdminPage'));
34
+
35
+ $this->LoadOptions();
36
+ }
37
+
38
+ function Activate() {
39
+
40
+ }
41
+
42
+ function Deactivate() {
43
+ delete_option('tml_options');
44
+ }
45
+
46
+ # Sets up default options
47
+ function InitOptions() {
48
+ $this->options['tml_version'] ='1.0';
49
+ $this->options['tml_uninstall'] = 0;
50
+ $this->options['tml_login_redirect'] = 'wp-admin/';
51
+ $this->options['tml_logout_redirect'] = 'wp-login.php?loggedout=true';
52
+ $this->options['tml_header_files'] = array('header.php');
53
+ $this->options['tml_header_html'] = ' <div id="content" class="narrowcolumn">' . "\n";
54
+ $this->options['tml_footer_files'] = array('sidebar.php', 'footer.php');
55
+ $this->options['tml_footer_html'] = ' </div>' . "\n";
56
+ $this->options['tml_login_text'] = 'Log In';
57
+ $this->options['tml_register_text'] = 'Register';
58
+ $this->options['tml_password_text'] = 'Reset Password';
59
+ }
60
+
61
+ # Loads options from database
62
+ function LoadOptions() {
63
+
64
+ $this->InitOptions();
65
+
66
+ $storedoptions = get_option( 'tml_options' );
67
+ if ( $storedoptions && is_array( $storedoptions ) ) {
68
+ foreach ( $storedoptions as $key => $value ) {
69
+ $this->options[$key] = $value;
70
+ }
71
+ } else update_option( 'tml_options', $this->options );
72
+ }
73
+
74
+ # Returns option value for given key
75
+ function GetOption( $key ) {
76
+ $key = "tml_" . $key;
77
+ if ( array_key_exists( $key, $this->options ) ) {
78
+ return $this->options[$key];
79
+ } else return null;
80
+ }
81
+
82
+ # Sets the speficied option key to a new value
83
+ function SetOption( $key, $value ) {
84
+ if ( strstr( $key, 'tml_' )!== 0 ) $key = 'tml_' . $key;
85
+
86
+ $this->options[$key] = $value;
87
+ }
88
+
89
+ # Saves the options to the database
90
+ function SaveOptions() {
91
+ $oldvalue = get_option( 'tml_options' );
92
+ if( $oldvalue == $this->options ) {
93
+ return true;
94
+ } else return update_option( 'tml_options', $this->options );
95
+ }
96
+
97
+ function AddAdminPage(){
98
+ add_submenu_page('options-general.php', "Theme My Login", "Theme My Login", 10, "Theme My Login", array(&$this, 'AdminPage'));
99
+ }
100
+
101
+ function AdminPage(){
102
+ if ( $_POST ) {
103
+ if ( !current_user_can('manage_options') )
104
+ die( __( 'Cheatin&#8217; huh?' ) );
105
+
106
+ check_admin_referer('tml-settings');
107
+
108
+ $error = "";
109
+ $header_files = trim(str_replace("\r\n", "\n", stripslashes($_POST['header_files'])));
110
+ $header_files = explode("\n", $header_files);
111
+ foreach((array)$header_files as $header_file) {
112
+ if ( !file_exists(TEMPLATEPATH . '/' . $header_file) ) {
113
+ $error .= "<li>The header file {$header_file} doesn't exist in your theme (template) directory, please verify the name and try again.</li>";
114
+ }
115
+ }
116
+ if ( empty($error) )
117
+ $this->SetOption('header_files', $header_files);
118
+
119
+ $footer_files = trim(str_replace("\r\n", "\n", stripslashes($_POST['footer_files'])));
120
+ $footer_files = explode("\n", $footer_files);
121
+ foreach((array)$footer_files as $footer_file) {
122
+ if ( !file_exists(TEMPLATEPATH . '/' . $footer_file) ) {
123
+ $error .= "<li>The footer file {$footer_file} doesn't exist in your theme (template) directory, please verify the name and try again.</li>";
124
+ }
125
+ }
126
+ if ( empty($error) ) {
127
+ $this->SetOption('footer_files', $footer_files);
128
+ $success = "<li>Custom login and registration form options updated successfully!</li>";
129
+ }
130
+
131
+ $this->SetOption('login_text', stripslashes($_POST['login_text']));
132
+ $this->SetOption('register_text', stripslashes($_POST['register_text']));
133
+ $this->SetOption('password_text', stripslashes($_POST['password_text']));
134
+ $this->SetOption('login_redirect', stripslashes($_POST['login_redirect']));
135
+ $this->SetOption('logout_redirect', stripslashes($_POST['logout_redirect']));
136
+ $this->SetOption('header_html', stripslashes($_POST['header_html']));
137
+ $this->SetOption('footer_html', stripslashes($_POST['footer_html']));
138
+ $this->SaveOptions();
139
+
140
+ $success = "<li>Settings updated successfully!</li>";
141
+
142
+ } //end if
143
+
144
+ ?>
145
+ <div class="wrap">
146
+ <?php if ( strlen($success) > 0 ) { ?>
147
+ <div id="message" class="updated fade">
148
+ <p><strong><?php _e("<ul>{$success}</ul>"); ?></strong></p>
149
+ </div>
150
+ <?php } ?>
151
+ <div id="icon-options-general" class="icon32"><br /></div>
152
+ <h2><?php _e('Theme My Login Settings'); ?></h2>
153
+
154
+ <form action="" method="post" id="tml-settings">
155
+ <?php if ( function_exists('wp_nonce_field') ) wp_nonce_field('tml-settings'); ?>
156
+ <h3>Redirection Settings</h3>
157
+ <table class="form-table">
158
+ <tr valign="top">
159
+ <th scope="row"><label for="login_redirect">Redirect on Login</label></th>
160
+ <td>
161
+ <input name="login_redirect" type="text" id="login_redirect" value="<?php echo( htmlspecialchars ( $this->GetOption('login_redirect') ) ); ?>" class="regular-text" />
162
+ <span class="setting-description">Defaults to 'wp-admin/'.</span>
163
+ </td>
164
+ </tr>
165
+ <tr valign="top">
166
+ <th scope="row"><label for="logout_redirect">Redirect on Logout</label></th>
167
+ <td>
168
+ <input name="logout_redirect" type="text" id="logout_redirect" value="<?php echo( htmlspecialchars ( $this->GetOption('logout_redirect') ) ); ?>" class="regular-text" />
169
+ <span class="setting-description">Defaults to 'wp-login.php?loggedout=true'.</span>
170
+ </td>
171
+ </tr>
172
+ </table>
173
+
174
+ <h3>Template Settings</h3>
175
+ <table class="form-table">
176
+ <tr valign="top">
177
+ <th scope="row"><label for="register_text">Register Text</label></th>
178
+ <td>
179
+ <input name="register_text" type="text" id="register_text" value="<?php echo( htmlspecialchars ( $this->GetOption('register_text') ) ); ?>" class="regular-text" />
180
+ <span class="setting-description">This will appear above the registration form.</span>
181
+ </td>
182
+ </tr>
183
+ <tr valign="top">
184
+ <th scope="row"><label for="login_text">Login Text</label></th>
185
+ <td>
186
+ <input name="login_text" type="text" id="login_text" value="<?php echo( htmlspecialchars ( $this->GetOption('login_text') ) ); ?>" class="regular-text" />
187
+ <span class="setting-description">This will appear above the login form.</span>
188
+ </td>
189
+ </tr>
190
+ <tr valign="top">
191
+ <th scope="row"><label for="password_text">Forgot Password Text</label></th>
192
+ <td>
193
+ <input name="password_text" type="text" id="password_text" value="<?php echo( htmlspecialchars ( $this->GetOption('password_text') ) ); ?>" class="regular-text" />
194
+ <span class="setting-description">This will appear above the forgot password form.</span>
195
+ </td>
196
+ </tr>
197
+ <tr valign="top">
198
+ <th scope="row"><label for="login_redirect">Template Header Files</label></th>
199
+ <td>
200
+ <textarea name="header_files" id="header_files" rows="5" cols="50" class="large-text"><?php echo $this->GetOption('header_files') ? htmlspecialchars(implode("\n", $this->GetOption('header_files'))) : ''; ?></textarea>
201
+ <span class="setting-description">Enter each header file used in your template, one per line. Typically, this is 'header.php'.</span>
202
+ </td>
203
+ </tr>
204
+ <tr valign="top">
205
+ <th scope="row"><label for="header_html">Template HTML After Header</label></th>
206
+ <td>
207
+ <textarea name="header_html" id="header_html" rows="5" cols="50" class="large-text"><?php echo $this->GetOption('header_html') ? htmlspecialchars($this->GetOption('header_html')) : ''; ?></textarea>
208
+ <span class="setting-description">Enter the HTML that appears after the get_header() function and before the page code.</span>
209
+ </td>
210
+ </tr>
211
+ <tr valign="top">
212
+ <th scope="row"><label for="footer_html">Template HTML Before Footer</label></th>
213
+ <td>
214
+ <textarea name="footer_html" id="footer_html" rows="5" cols="50" class="large-text"><?php echo $this->GetOption('footer_html') ? htmlspecialchars($this->GetOption('footer_html')) : ''; ?></textarea>
215
+ <span class="setting-description">Enter footer HTML that appears between the page code and the get_sidebar()/get_footer() functions.</span>
216
+ </td>
217
+ </tr>
218
+ <tr valign="top">
219
+ <th scope="row"><label for="footer_files">Template Footer Files</label></th>
220
+ <td>
221
+ <textarea name="footer_files" id="footer_files" rows="5" cols="50" class="large-text"><?php echo $this->GetOption('footer_files') ? htmlspecialchars(implode("\n", $this->GetOption('footer_files'))) : ''; ?></textarea>
222
+ <span class="setting-description">Enter each footer file used in your template, one per line. Typically, this is 'sidebar.php' and 'footer.php'.</span>
223
+ </td>
224
+ </tr>
225
+ </table>
226
+ <p class="submit"><input type="submit" name="Submit" class="button-primary" value="Save Changes" />
227
+ </form>
228
+ </div>
229
+ <?php
230
+ }
231
+
232
+ function Init() {
233
+ global $pagenow;
234
+
235
+ switch ($pagenow) {
236
+ case "wp-login.php":
237
+ case "wp-register.php":
238
+ $this->DoLogin();
239
+ break;
240
+ }
241
+ }
242
+
243
+ function DoHeader($title = 'Log In', $message = '', $wp_error = '') {
244
+ global $error;
245
+
246
+ if ( empty($wp_error) )
247
+ $wp_error = new WP_Error();
248
+
249
+ $header_files = $this->GetOption('header_files');
250
+ foreach((array)$header_files as $header_file)
251
+ include(TEMPLATEPATH . '/' . $header_file);
252
+
253
+ echo $this->GetOption('header_html');
254
+ ?>
255
+
256
+ <div id="login">
257
+ <h2><?php _e($title); ?></h2>
258
+
259
+ <?php
260
+
261
+ if ( !empty( $message ) ) echo apply_filters('login_message', $message) . "\n";
262
+
263
+ // Incase a plugin uses $error rather than the $errors object
264
+ if ( !empty( $error ) ) {
265
+ $wp_error->add('error', $error);
266
+ unset($error);
267
+ }
268
+
269
+ if ( $wp_error->get_error_code() ) {
270
+ $errors = '';
271
+ $messages = '';
272
+ foreach ( $wp_error->get_error_codes() as $code ) {
273
+ $severity = $wp_error->get_error_data($code);
274
+ foreach ( $wp_error->get_error_messages($code) as $error ) {
275
+ if ( 'message' == $severity )
276
+ $messages .= ' ' . $error . "<br />\n";
277
+ else
278
+ $errors .= ' ' . $error . "<br />\n";
279
+ }
280
+ }
281
+ if ( !empty($errors) )
282
+ echo '<div id="login_error">' . apply_filters('login_errors', $errors) . "</div>\n";
283
+ if ( !empty($messages) )
284
+ echo '<p class="message">' . apply_filters('login_messages', $messages) . "</p>\n";
285
+
286
+ }
287
+ }
288
+
289
+ function DoLogin() {
290
+ $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
291
+ $errors = new WP_Error();
292
+
293
+ if ( isset($_GET['key']) )
294
+ $action = 'resetpass';
295
+
296
+ nocache_headers();
297
+
298
+ if ( defined('RELOCATE') ) { // Move flag is set
299
+ if ( isset( $_SERVER['PATH_INFO'] ) && ($_SERVER['PATH_INFO'] != $_SERVER['PHP_SELF']) )
300
+ $_SERVER['PHP_SELF'] = str_replace( $_SERVER['PATH_INFO'], '', $_SERVER['PHP_SELF'] );
301
+
302
+ $schema = ( isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ) ? 'https://' : 'http://';
303
+ if ( dirname($schema . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']) != get_option('siteurl') )
304
+ update_option('siteurl', dirname($schema . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']) );
305
+ }
306
+
307
+ //Set a cookie now to see if they are supported by the browser.
308
+ setcookie(TEST_COOKIE, 'WP Cookie check', 0, COOKIEPATH, COOKIE_DOMAIN);
309
+ if ( SITECOOKIEPATH != COOKIEPATH )
310
+ setcookie(TEST_COOKIE, 'WP Cookie check', 0, SITECOOKIEPATH, COOKIE_DOMAIN);
311
+
312
+ $http_post = ('POST' == $_SERVER['REQUEST_METHOD']);
313
+ switch ($action) :
314
+
315
+ case 'logout' :
316
+ if ($wp_version > '2.6')
317
+ check_admin_referer('log-out');
318
+ wp_logout();
319
+
320
+ if ($this->GetOption('logout_redirect')) {
321
+ $redirect_to = $this->GetOption('logout_redirect');
322
+ } else {
323
+ if ( isset( $_REQUEST['redirect_to'] ) )
324
+ $redirect_to = $_REQUEST['redirect_to'];
325
+ else
326
+ $redirect_to = 'wp-login.php';
327
+ }
328
+
329
+ wp_safe_redirect($redirect_to);
330
+ exit();
331
+ break;
332
+
333
+ case 'lostpassword' :
334
+ case 'retrievepassword' :
335
+ if ( $http_post ) {
336
+ $errors = retrieve_password();
337
+ if ( !is_wp_error($errors) ) {
338
+ wp_redirect('wp-login.php?checkemail=confirm');
339
+ exit();
340
+ }
341
+ }
342
+
343
+ if ( isset($_GET['error']) && 'invalidkey' == $_GET['error'] ) $errors->add('invalidkey', __('Sorry, that key does not appear to be valid.'));
344
+
345
+ do_action('lost_password');
346
+ $this->DoHeader(__($this->GetOption('password_text')), '<p class="message">' . __('Please enter your username or e-mail address. You will receive a new password via e-mail.') . '</p>', $errors);
347
+
348
+ $user_login = isset($_POST['user_login']) ? stripslashes($_POST['user_login']) : '';
349
+
350
+ ?>
351
+
352
+ <form name="lostpasswordform" id="lostpasswordform" action="<?php echo site_url('wp-login.php?action=lostpassword', 'login_post') ?>" method="post">
353
+ <p>
354
+ <label><?php _e('Username or E-mail:') ?><br />
355
+ <input type="text" name="user_login" id="user_login" class="input" value="<?php echo attribute_escape($user_login); ?>" size="20" tabindex="10" /></label>
356
+ </p>
357
+ <?php do_action('lostpassword_form'); ?>
358
+ <p class="submit"><input type="submit" name="wp-submit" id="wp-submit" value="<?php _e('Get New Password'); ?>" tabindex="100" /></p>
359
+ </form>
360
+
361
+ <ul class="nav">
362
+ <li><a href="<?php echo site_url('wp-login.php', 'login') ?>"><?php _e('Log in') ?></a></li>
363
+ <?php if (get_option('users_can_register')) : ?>
364
+ <li><a href="<?php echo site_url('wp-login.php?action=register', 'login') ?>"><?php _e('Register') ?></li>
365
+ <?php endif; ?>
366
+ </ul>
367
+
368
+ </div>
369
+
370
+ <?php
371
+ echo $this->GetOption('footer_html');
372
+ $footer_files = $this->GetOption('footer_files');
373
+ foreach((array)$footer_files as $footer_file)
374
+ include(TEMPLATEPATH . '/' . $footer_file);
375
+
376
+ die();
377
+ break;
378
+
379
+ case 'resetpass' :
380
+ case 'rp' :
381
+ $errors = reset_password($_GET['key']);
382
+
383
+ if ( ! is_wp_error($errors) ) {
384
+ wp_redirect('wp-login.php?checkemail=newpass');
385
+ exit();
386
+ }
387
+
388
+ wp_redirect('wp-login.php?action=lostpassword&error=invalidkey');
389
+ exit();
390
+
391
+ break;
392
+
393
+ case 'register' :
394
+ if ( !get_option('users_can_register') ) {
395
+ wp_redirect('wp-login.php?registration=disabled');
396
+ exit();
397
+ }
398
+
399
+ $user_login = '';
400
+ $user_email = '';
401
+ if ( $http_post ) {
402
+ require_once( ABSPATH . WPINC . '/registration.php');
403
+
404
+ $user_login = $_POST['user_login'];
405
+ $user_email = $_POST['user_email'];
406
+ $errors = register_new_user($user_login, $user_email);
407
+ if ( !is_wp_error($errors) ) {
408
+ wp_redirect('wp-login.php?checkemail=registered');
409
+ exit();
410
+ }
411
+ }
412
+
413
+ $this->DoHeader(__($this->GetOption('register_text')), '', $errors);
414
+ ?>
415
+
416
+ <form name="registerform" id="registerform" action="<?php echo site_url('wp-login.php?action=register', 'login_post') ?>" method="post">
417
+ <p>
418
+ <label><?php _e('Username') ?><br />
419
+ <input type="text" name="user_login" id="user_login" class="input" value="<?php echo attribute_escape(stripslashes($user_login)); ?>" size="20" tabindex="10" /></label>
420
+ </p>
421
+ <p>
422
+ <label><?php _e('E-mail') ?><br />
423
+ <input type="text" name="user_email" id="user_email" class="input" value="<?php echo attribute_escape(stripslashes($user_email)); ?>" size="25" tabindex="20" /></label>
424
+ </p>
425
+ <?php do_action('register_form'); ?>
426
+ <p id="reg_passmail"><?php _e('A password will be e-mailed to you.') ?></p>
427
+ <p class="submit"><input type="submit" name="wp-submit" id="wp-submit" value="<?php _e('Register'); ?>" tabindex="100" /></p>
428
+ </form>
429
+
430
+ <ul class="nav">
431
+ <li><a href="<?php echo site_url('wp-login.php', 'login') ?>"><?php _e('Log in') ?></a></li>
432
+ <li><a href="<?php echo site_url('wp-login.php?action=lostpassword', 'login') ?>" title="<?php _e('Password Lost and Found') ?>"><?php _e('Lost your password?') ?></a></li>
433
+ </ul>
434
+
435
+ </div>
436
+
437
+ <?php
438
+ echo $this->GetOption('footer_html');
439
+ $footer_files = $this->GetOption('footer_files');
440
+ foreach((array)$footer_files as $footer_file)
441
+ include(TEMPLATEPATH . '/' . $footer_file);
442
+
443
+ die();
444
+ break;
445
+
446
+ case 'login' :
447
+ default:
448
+ $secure_cookie = '';
449
+
450
+ // If the user wants ssl but the session is not ssl, force a secure cookie.
451
+ if ( !empty($_POST['log']) && !force_ssl_admin() ) {
452
+ $user_name = sanitize_user($_POST['log']);
453
+ if ( $user = get_userdatabylogin($user_name) ) {
454
+ if ( get_user_option('use_ssl', $user->ID) ) {
455
+ $secure_cookie = true;
456
+ force_ssl_admin(true);
457
+ }
458
+ }
459
+ }
460
+
461
+ if ( isset( $_REQUEST['redirect_to'] ) ) {
462
+ $redirect_to = $_REQUEST['redirect_to'];
463
+ // Redirect to https if user wants ssl
464
+ if ( $secure_cookie && false !== strpos($redirect_to, 'wp-admin') )
465
+ $redirect_to = preg_replace('|^http://|', 'https://', $redirect_to);
466
+ } else {
467
+ $redirect_to = $this->GetOption('login_redirect');
468
+ }
469
+
470
+ if ( !$secure_cookie && is_ssl() && force_ssl_login() && !force_ssl_admin() && ( 0 !== strpos($redirect_to, 'https') ) && ( 0 === strpos($redirect_to, 'http') ) )
471
+ $secure_cookie = false;
472
+
473
+ $user = wp_signon('', $secure_cookie);
474
+
475
+ $redirect_to = apply_filters('login_redirect', $redirect_to, isset( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : '', $user);
476
+
477
+ if ( !is_wp_error($user) ) {
478
+ // If the user can't edit posts, send them to their profile.
479
+ if ( !$user->has_cap('edit_posts') && ( empty( $redirect_to ) || $redirect_to == 'wp-admin/' ) )
480
+ $redirect_to = admin_url('profile.php');
481
+ wp_safe_redirect($redirect_to);
482
+ exit();
483
+ }
484
+
485
+ $errors = $user;
486
+ // Clear errors if loggedout is set.
487
+ if ( !empty($_GET['loggedout']) )
488
+ $errors = new WP_Error();
489
+
490
+ // If cookies are disabled we can't log in even with a valid user+pass
491
+ if ( isset($_POST['testcookie']) && empty($_COOKIE[TEST_COOKIE]) )
492
+ $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."));
493
+
494
+ // Some parts of this script use the main login form to display a message
495
+ if ( isset($_GET['loggedout']) && TRUE == $_GET['loggedout'] ) $errors->add('loggedout', __('You are now logged out.'), 'message');
496
+ elseif ( isset($_GET['registration']) && 'disabled' == $_GET['registration'] ) $errors->add('registerdisabled', __('User registration is currently not allowed.'));
497
+ elseif ( isset($_GET['checkemail']) && 'confirm' == $_GET['checkemail'] ) $errors->add('confirm', __('Check your e-mail for the confirmation link.'), 'message');
498
+ elseif ( isset($_GET['checkemail']) && 'newpass' == $_GET['checkemail'] ) $errors->add('newpass', __('Check your e-mail for your new password.'), 'message');
499
+ elseif ( isset($_GET['checkemail']) && 'registered' == $_GET['checkemail'] ) $errors->add('registered', __('Registration complete. Please check your e-mail.'), 'message');
500
+
501
+ $this->DoHeader(__($this->GetOption('login_text')), '', $errors);
502
+
503
+ if ( isset($_POST['log']) )
504
+ $user_login = ( 'incorrect_password' == $errors->get_error_code() || 'empty_password' == $errors->get_error_code() ) ? attribute_escape(stripslashes($_POST['log'])) : '';
505
+ ?>
506
+
507
+ <?php if ( !isset($_GET['checkemail']) || !in_array( $_GET['checkemail'], array('confirm', 'newpass') ) ) : ?>
508
+ <form name="loginform" id="loginform" action="<?php echo site_url('wp-login.php', 'login_post') ?>" method="post">
509
+ <p>
510
+ <label><?php _e('Username') ?><br />
511
+ <input type="text" name="log" id="user_login" class="input" value="<?php echo $user_login; ?>" size="20" tabindex="10" /></label>
512
+ </p>
513
+ <p>
514
+ <label><?php _e('Password') ?><br />
515
+ <input type="password" name="pwd" id="user_pass" class="input" value="" size="20" tabindex="20" /></label>
516
+ </p>
517
+ <?php do_action('login_form'); ?>
518
+ <p class="forgetmenot"><label><input name="rememberme" type="checkbox" id="rememberme" value="forever" tabindex="90" /> <?php _e('Remember Me'); ?></label></p>
519
+ <p class="submit">
520
+ <input type="submit" name="wp-submit" id="wp-submit" value="<?php _e('Log In'); ?>" tabindex="100" />
521
+ <input type="hidden" name="redirect_to" value="<?php echo attribute_escape($redirect_to); ?>" />
522
+ <input type="hidden" name="testcookie" value="1" />
523
+ </p>
524
+ </form>
525
+ <?php endif; ?>
526
+
527
+ <ul class="nav">
528
+ <?php if ( isset($_GET['checkemail']) && in_array( $_GET['checkemail'], array('confirm', 'newpass') ) ) : ?>
529
+ <?php elseif (get_option('users_can_register')) : ?>
530
+ <li><a href="<?php echo site_url('wp-login.php?action=register', 'login') ?>"><?php _e('Register') ?></a></li>
531
+ <?php endif; ?>
532
+ <li><a href="<?php echo site_url('wp-login.php?action=lostpassword', 'login') ?>" title="<?php _e('Password Lost and Found') ?>"><?php _e('Lost your password?') ?></a></li>
533
+ </ul>
534
+
535
+ </div>
536
+
537
+ <?php
538
+ echo $this->GetOption('footer_html');
539
+ $footer_files = $this->GetOption('footer_files');
540
+ foreach((array)$footer_files as $footer_file)
541
+ include(TEMPLATEPATH . '/' . $footer_file);
542
+
543
+ die();
544
+ break;
545
+ endswitch;
546
+ }
547
+ }
548
+ }
549
+
550
+ //instantiate the class
551
+ if (class_exists('ThemeMyLogin')) {
552
+ $ThemeMyLogin = new ThemeMyLogin();
553
+ }
554
+
555
+ if ( !function_exists('is_ssl') ) :
556
+ function is_ssl() {
557
+ if ( isset($_SERVER['HTTPS']) ) {
558
+ if ( 'on' == strtolower($_SERVER['HTTPS']) )
559
+ return true;
560
+ if ( '1' == $_SERVER['HTTPS'] )
561
+ return true;
562
+ } elseif ( isset($_SERVER['SERVER_PORT']) && ( '443' == $_SERVER['SERVER_PORT'] ) ) {
563
+ return true;
564
+ }
565
+ return false;
566
+ }
567
+ endif;
568
+
569
+ if ( !function_exists('site_url') ) :
570
+ function site_url($path = '', $scheme = null) {
571
+ // should the list of allowed schemes be maintained elsewhere?
572
+ $orig_scheme = $scheme;
573
+ if ( !in_array($scheme, array('http', 'https')) ) {
574
+ if ( ('login_post' == $scheme) && ( force_ssl_login() || force_ssl_admin() ) )
575
+ $scheme = 'https';
576
+ elseif ( ('login' == $scheme) && ( force_ssl_admin() ) )
577
+ $scheme = 'https';
578
+ elseif ( ('admin' == $scheme) && force_ssl_admin() )
579
+ $scheme = 'https';
580
+ else
581
+ $scheme = ( is_ssl() ? 'https' : 'http' );
582
+ }
583
+
584
+ $url = str_replace( 'http://', "{$scheme}://", get_option('siteurl') );
585
+
586
+ if ( !empty($path) && is_string($path) && strpos($path, '..') === false )
587
+ $url .= '/' . ltrim($path, '/');
588
+
589
+ return apply_filters('site_url', $url, $path, $orig_scheme);
590
+ }
591
+ endif;
592
+
593
+ if ( !function_exists('admin_url') ) :
594
+ function admin_url($path = '') {
595
+ $url = site_url('wp-admin/', 'admin');
596
+
597
+ if ( !empty($path) && is_string($path) && strpos($path, '..') === false )
598
+ $url .= ltrim($path, '/');
599
+
600
+ return $url;
601
+ }
602
+ endif;
603
+
604
+ if ( !function_exists('force_ssl_login') ) :
605
+ function force_ssl_login($force = '') {
606
+ static $forced;
607
+
608
+ if ( '' != $force ) {
609
+ $old_forced = $forced;
610
+ $forced = $force;
611
+ return $old_forced;
612
+ }
613
+
614
+ return $forced;
615
+ }
616
+ endif;
617
+
618
+ if ( !function_exists('force_ssl_admin') ) :
619
+ function force_ssl_admin($force = '') {
620
+ static $forced;
621
+
622
+ if ( '' != $force ) {
623
+ $old_forced = $forced;
624
+ $forced = $force;
625
+ return $old_forced;
626
+ }
627
+
628
+ return $forced;
629
+ }
630
+ endif;
631
+
632
+ ?>