'login', 'description' => _a("Login and Lost Password forms")); $control_ops = array('width' => 500); $this->WP_Widget('atom-login', _a("Login"), $widget_ops, $control_ops); add_action('init', array(&$this, 'ajax'), 99); // include in jQuery(document).ready() atom_add('jquery_init', array(&$this, 'js')); } function js(){ // we need to process all instances because this function gets to run only once $widget_settings = atom_get_options($this->option_name); foreach((array)$widget_settings as $instance => $options): // identify instance $id = "{$this->id_base}-{$instance}"; $block_id = "instance-{$id}"; if (is_active_widget(false, $id, $this->id_base)): ?> $('#_login').submit(function(event){ // stop event event.preventDefault(); $status = $("# .status"); $status.removeClass("error").addClass("loading").text(""); // sort out url url = $('#_login').attr('action'); url += (url.match(/\?/) != null) ? '&callback=?' : '?callback=?' ; url += "&log="+encodeURIComponent($("#_user").val()); url += "&pwd="+encodeURIComponent($("#_pass").val()); url += "&rememberme="+encodeURIComponent($("#_login_remember").val()); url += "&login=login"; $.getJSON(url, function(data, status){ if(data.result === true || data.result === false){ if(data.result === true){ $status.removeClass("loading error").addClass("success").html(data.message); window.location.reload(); }else{ $status.removeClass("loading").addClass("error").html(data.error); // assume the link in the status message points to forgot pass form $status.find("a").click(function(event){ event.preventDefault(); if($("#_forgot").is(":visible")){ var origColor = $("#_forgot input.text").css("color"); $("#_forgot input.text").css({backgroundColor: '#ffa799', color: '#333'}).animate({backgroundColor: '#fff', color: origColor}, 1000); }else{ $("# a.forgot_pass").remove(); // remove the bottom forgot pass link $('#_forgot').slideFade('toggle',333,'easeOutQuart'); } }); } }else{ $status.removeClass("loading").html(""); } }); }); $('#_forgot').submit(function(event){ // stop event event.preventDefault(); $status = $("# .status"); $status.removeClass("error").addClass("loading").text(""); // sort out url url = $('#_forgot').attr('action'); url += (url.match(/\?/) != null) ? '&callback=?' : '?callback=?' ; url += "&user_login="+$("#_user_or_email").val(); url += "&login=forgot_pass"; $.getJSON(url, function(data, status){ if(data.result === true || data.result === false){ if(data.result == '1') $status.removeClass("loading error").addClass("success").html(data.message); else $status.removeClass("loading").addClass("error").html(data.error); }else{ $status.removeClass("loading").addClass("error").html(""); } }); }); $("# a.forgot_pass").click(function(event){ event.preventDefault(); $(this).remove(); $('#_forgot').slideFade('toggle',333,'easeOutQuart'); }); get_error_message(); $return['error'] = ($error ? $error : _a("Please type a username and password")); else: //Undefined Error $return['result'] = false; $return['error'] = _a('Unknown error. Sorry...'); endif; $return = json_encode($return); break; case 'forgot_pass': $_POST['user_login'] = $_GET['user_login']; // Reads ajax login creds via POSt, calls the login script and interprets the result $remember = array(); //What we send back $result = retrieve_password(); if($result === true): //Password correctly remembered $remember['result'] = true; $remember['message'] = _a("E-mail has been sent, check your inbox."); elseif(strtolower(get_class($result)) == 'wp_error'): //Something went wrong /* @var $result WP_Error */ $remember['result'] = false; $remember['error'] = $result->get_error_message(); else: //Undefined Error $remember['result'] = false; $remember['error'] = _a('Unknown error. Sorry...'); endif; $return = json_encode($remember); break; default: $return = json_encode(array('result' => 0, 'error' => _a('Requested command is invalid'))); break; endswitch; if(isset($_GET['callback'])) $return = $_GET['callback']."($return)"; echo $return; exit(); endif; } function widget($args, $instance){ extract($args); $instance = wp_parse_args($instance, $this->defaults()); $title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base); // retrieve info about the current user global $current_user, $user_level; get_currentuserinfo(); if(is_user_logged_in()) $title = sprintf(_a('Welcome %s'), $current_user->display_name); echo $before_widget.($title ? $before_title.$title.$after_title : null); echo '
'; // the user is logged in, display the menu links if(is_user_logged_in()): echo '
'.atom_get_avatar($current_user->user_email, 96, '', $current_user->display_name).'
'; echo ''; // the user is not logged in, display the login form else: ?>
" name="log" id="id; ?>_user" class="text clearField" value="" /> " name="pwd" id="id; ?>_pass" class="text clearField" value="" />
'._a('Lost your password?').''; if (atom_get_options('users_can_register')): if(function_exists('bp_get_signup_page')) $register_link = bp_get_signup_page(); // bp elseif(file_exists(ABSPATH."/wp-signup.php")) $register_link = site_url('wp-signup.php', 'login'); //MU + WP3 else $register_link = site_url('wp-login.php?action=register', 'login'); echo ''._a('Register').''; endif; endif; echo '
'; echo $after_widget; } function update($new_instance, $old_instance){ $instance['title'] = esc_attr($new_instance['title']); if (current_user_can('unfiltered_html')) $instance['text'] = $new_instance['text']; else $instance['text'] = stripslashes(wp_filter_post_kses(addslashes($new_instance['text']))); // wp_filter_post_kses() expects slashed $instance['dashboard'] = isset($new_instance['dashboard']); $instance['profile'] = isset($new_instance['profile']); $instance['write'] = isset($new_instance['write']); $instance['comments'] = isset($new_instance['comments']); return wp_parse_args($instance, $this->defaults()); } function defaults(){ // default settings return apply_filters('atom_widget_login_defaults', array( 'title' => _a('Log in'), 'text' => _a("Hello Guest. Login below if you have a account"), 'dashboard' => 1, 'profile' => 1, 'write' => 1, 'comments' => 0, ), $this); } function form($instance){ $instance = wp_parse_args($instance, $this->defaults()); ?>
>