Skip to content

Commit

Permalink
added lost password shortcode / email notification
Browse files Browse the repository at this point in the history
I think the current process for a customer to reset their password is
jarring, especially if the shop hasn't styled the wordpress login form
to match their branding. The form process is mainly copied from the
same process in wp-login.php and fires the same actions to maintain
compatibility.
  • Loading branch information
maxrice committed Oct 4, 2012
1 parent d9e3e5a commit 2faa4d6
Show file tree
Hide file tree
Showing 9 changed files with 447 additions and 1 deletion.
11 changes: 11 additions & 0 deletions admin/settings/settings-init.php
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,17 @@
'desc_tip' => true,
),

array(
'name' => __( 'Lost Password Page', 'woocommerce' ),
'desc' => __( 'Page contents: [woocommerce_lost_password]', 'woocommerce' ),
'id' => 'woocommerce_lost_password_page_id',
'type' => 'single_select_page',
'std' => '',
'class' => 'chosen_select_nostd',
'css' => 'min-width:300px;',
'desc_tip' => true,
),

array( 'type' => 'sectionend', 'id' => 'page_options'),

)); // End pages settings
Expand Down
2 changes: 2 additions & 0 deletions admin/woocommerce-admin-install.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ function woocommerce_create_pages() {
// Thanks page
woocommerce_create_page( esc_sql( _x( 'order-received', 'page_slug', 'woocommerce' ) ), 'woocommerce_thanks_page_id', __( 'Order Received', 'woocommerce' ), '[woocommerce_thankyou]', woocommerce_get_page_id( 'checkout' ) );

// Lost password page
woocommerce_create_page( esc_sql( _x( 'lost-password', 'page_slug', 'woocommerce' ) ), 'woocommerce_lost_password_page_id', __( 'Lost Password', 'woocommerce' ), '[woocommerce_lost_password]' );
}


Expand Down
106 changes: 106 additions & 0 deletions classes/emails/class-wc-email-customer-reset-password.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?php
/**
* Customer Reset Password
*
* An email sent to the customer when they reset their password.
*
* @class WC_Email_Customer_Reset_Password
* @version 1.7.0
* @package WooCommerce/Classes/Emails
* @author WooThemes
* @extends WC_Email
*/
class WC_Email_Customer_Reset_Password extends WC_Email {

/** @var string */
var $user_login;

/** @var string */
var $user_email;

/** @var string */
var $reset_key;

/**
* Constructor
*
* @access public
* @return void
*/
function __construct() {

$this->id = 'customer_reset_password';
$this->title = __( 'Reset password', 'woocommerce' );
$this->description = __( 'Customer reset password emails are sent when a customer resets their password.', 'woocommerce' );

$this->template_html = 'emails/customer-reset-password.php';
$this->template_plain = 'emails/plain/customer-reset-password.php';

$this->subject = __( 'Password Reset for {blogname}', 'woocommerce');
$this->heading = __( 'Password Reset Instructions for {blogname}', 'woocommerce');

// Trigger
add_action( 'woocommerce_reset_password_notification', array( $this, 'trigger' ), 10, 2 );

// Call parent constuctor
parent::__construct();
}

/**
* trigger function.
*
* @access public
* @return void
*/
function trigger( $user_login = '', $reset_key = '' ) {
global $woocommerce;
if ( $user_login && $reset_key ) {
$this->object = get_user_by( 'login', $user_login );

$this->user_login = $user_login;
$this->reset_key = $reset_key;
$this->user_email = stripslashes( $this->object->user_email );
$this->recipient = $this->user_email;
}

if ( ! $this->is_enabled() || ! $this->get_recipient() )
return;

$this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );

}

/**
* get_content_html function.
*
* @access public
* @return string
*/
function get_content_html() {
ob_start();
woocommerce_get_template( $this->template_html, array(
'email_heading' => $this->get_heading(),
'user_login' => $this->user_login,
'reset_key' => $this->reset_key,
'blogname' => $this->get_blogname()
) );
return ob_get_clean();
}

/**
* get_content_plain function.
*
* @access public
* @return string
*/
function get_content_plain() {
ob_start();
woocommerce_get_template( $this->template_plain, array(
'email_heading' => $this->get_heading(),
'user_login' => $this->user_login,
'reset_key' => $this->reset_key,
'blogname' => $this->get_blogname()
) );
return ob_get_clean();
}
}
2 changes: 2 additions & 0 deletions classes/emails/class-wc-emails.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ function __construct() {
include_once( 'class-wc-email-customer-invoice.php' );
include_once( 'class-wc-email-customer-new-account.php' );
include_once( 'class-wc-email-customer-note.php' );
include_once( 'class-wc-email-customer-reset-password.php' );
include_once( 'class-wc-email-customer-processing-order.php' );
include_once( 'class-wc-email-new-order.php' );

Expand All @@ -57,6 +58,7 @@ function __construct() {
$this->emails['WC_Email_Customer_Completed_Order'] = new WC_Email_Customer_Completed_Order();
$this->emails['WC_Email_Customer_Invoice'] = new WC_Email_Customer_Invoice();
$this->emails['WC_Email_Customer_Note'] = new WC_Email_Customer_Note();
$this->emails['WC_Email_Customer_Reset_Password'] = new WC_Email_Customer_Reset_Password();
$this->emails['WC_Email_Customer_New_Account'] = new WC_Email_Customer_New_Account();

$this->emails = apply_filters( 'woocommerce_email_classes', $this->emails );
Expand Down
6 changes: 5 additions & 1 deletion shortcodes/shortcode-init.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @author WooThemes
* @category Shortcodes
* @package WooCommerce/Shortcodes
* @version 1.6.4
* @version 1.7.0
*/

/** Cart shortcode */
Expand All @@ -22,6 +22,9 @@
/** Order tracking shortcode */
include_once('shortcode-order_tracking.php');

/** Lost password shortcode */
include_once( 'shortcode-lost_password.php' );

/** Pay shortcode */
include_once('shortcode-pay.php');

Expand Down Expand Up @@ -857,6 +860,7 @@ function woocommerce_order_by_rating_post_clauses( $args ) {
add_shortcode('woocommerce_my_account', 'get_woocommerce_my_account');
add_shortcode('woocommerce_edit_address', 'get_woocommerce_edit_address');
add_shortcode('woocommerce_change_password', 'get_woocommerce_change_password');
add_shortcode('woocommerce_lost_password', 'get_woocommerce_lost_password');
add_shortcode('woocommerce_view_order', 'get_woocommerce_view_order');
add_shortcode('woocommerce_pay', 'get_woocommerce_pay');
add_shortcode('woocommerce_thankyou', 'get_woocommerce_thankyou');
Expand Down
Loading

0 comments on commit 2faa4d6

Please sign in to comment.