woo_widget_cssclass = 'woocommerce widget_login';
$this->woo_widget_description = __( 'Display a login area and "My Account" links in the sidebar.', 'woocommerce' );
$this->woo_widget_idbase = 'woocommerce_login';
$this->woo_widget_name = __( 'WooCommerce Login', 'woocommerce' );
/* Widget settings. */
$widget_ops = array( 'classname' => $this->woo_widget_cssclass, 'description' => $this->woo_widget_description );
/* Create the widget. */
$this->WP_Widget('woocommerce_login', $this->woo_widget_name, $widget_ops);
}
/**
* widget function.
*
* @see WP_Widget
* @access public
* @param array $args
* @param array $instance
* @return void
*/
function widget( $args, $instance ) {
global $woocommerce;
extract($args);
// Don't show if on the account page since that has a login
if (is_account_page() && !is_user_logged_in()) return;
$logged_out_title = apply_filters('widget_title', empty( $instance['logged_out_title'] ) ? __('Customer Login', 'woocommerce' ) : $instance['logged_out_title'], $instance, $this->id_base );
$logged_in_title = apply_filters('widget_title', empty( $instance['logged_in_title'] ) ? __( 'Welcome %s', 'woocommerce' ) : $instance['logged_in_title'], $instance, $this->id_base );
echo $before_widget;
if (is_user_logged_in()) {
$user = get_user_by('id', get_current_user_id());
$logged_in_title = apply_filters( 'woocommerce_login_widget_logged_in_title', sprintf( $logged_in_title, ucwords( $user->display_name ) ) );
if ( $logged_in_title )
echo $before_title . $logged_in_title . $after_title;
do_action('woocommerce_login_widget_logged_in_before_links');
$links = apply_filters( 'woocommerce_login_widget_logged_in_links', array(
__( 'My account', 'woocommerce' ) => get_permalink(woocommerce_get_page_id('myaccount')),
__( 'Change my password', 'woocommerce' ) => get_permalink(woocommerce_get_page_id('change_password')),
__( 'Logout', 'woocommerce' ) => wp_logout_url(home_url())
));
if (sizeof($links>0)) :
echo '
';
foreach ($links as $name => $link) :
echo '- '.$name.'
';
endforeach;
echo '
';
endif;
do_action('woocommerce_login_widget_logged_in_after_links');
} else {
$logged_out_title = apply_filters( 'woocommerce_login_widget_logged_out_title', $logged_out_title );
if ( $logged_out_title )
echo $before_title . $logged_out_title . $after_title;
do_action('woocommerce_login_widget_logged_out_before_form');
global $login_errors;
if ( is_wp_error($login_errors) && $login_errors->get_error_code() ) foreach ($login_errors->get_error_messages() as $error) :
echo '' . esc_html( $error ) . "
\n";
break;
endforeach;
// Get redirect URL
$redirect_to = esc_url( apply_filters( 'woocommerce_login_widget_redirect', get_permalink( woocommerce_get_page_id( 'myaccount' ) ) ) );
?>
add_inline_js("
// Ajax Login
jQuery('.widget_login form').submit(function(){
var thisform = this;
jQuery(thisform).block({ message: null, overlayCSS: {
backgroundColor: '#fff',
opacity: 0.6
} });
var data = {
action: 'woocommerce_sidebar_login_process',
security: '".wp_create_nonce("woocommerce-sidebar-login-action")."',
user_login: jQuery('input[name=\"log\"]', thisform).val(),
user_password: jQuery('input[name=\"pwd\"]', thisform).val(),
redirect_to: jQuery('.redirect_to:eq(0)', thisform).val()
};
// Ajax action
jQuery.ajax({
url: '" . ( ( is_ssl() || force_ssl_admin() || force_ssl_login() ) ? str_replace( 'http:', 'https:', admin_url( 'admin-ajax.php' ) ) : str_replace( 'https:', 'http:', admin_url( 'admin-ajax.php' ) ) ) . "',
data: data,
type: 'GET',
dataType: 'jsonp',
success: function( result ) {
jQuery('.woocommerce_error').remove();
if (result.success==1) {
window.location = result.redirect;
} else {
jQuery(thisform).prepend('' + result.error + '
');
jQuery(thisform).unblock();
}
}
});
return false;
});
");
$links = apply_filters( 'woocommerce_login_widget_logged_out_links', array());
if (sizeof($links>0)) :
echo '';
foreach ( $links as $name => $link ) {
echo '- ' . wp_kses_post( $name ) . '
';
}
echo '
';
endif;
}
echo $after_widget;
}
/**
* update function.
*
* @see WP_Widget->update
* @access public
* @param array $new_instance
* @param array $old_instance
* @return array
*/
function update( $new_instance, $old_instance ) {
$instance['logged_out_title'] = strip_tags(stripslashes($new_instance['logged_out_title']));
$instance['logged_in_title'] = strip_tags(stripslashes($new_instance['logged_in_title']));
return $instance;
}
/**
* form function.
*
* @see WP_Widget->form
* @access public
* @param array $instance
* @return void
*/
function form( $instance ) {
?>