';
- if ( $this->set_mode == 'account' && um_is_account_page() ) {
+ if ( $this->set_mode == 'account' && um_is_core_page('account') || $this->set_mode == 'password' && um_is_core_page('password-reset') ) {
+
$output .= $this->field_label( 'New Password', $key, $data);
+
} else if ( isset( $data['label'] ) ) {
+
$output .= $this->field_label($label, $key, $data);
+
}
$output .= '
';
diff --git a/core/um-filters-profile.php b/core/um-filters-profile.php
index d26a0281..44f2237c 100644
--- a/core/um-filters-profile.php
+++ b/core/um-filters-profile.php
@@ -9,7 +9,7 @@
$profile_title = um_get_option('profile_title');
- if ( um_is_user_page_uri() && um_get_requested_user() ) {
+ if ( um_is_core_page('user') && um_get_requested_user() ) {
um_fetch_user( um_get_requested_user() );
@@ -35,9 +35,9 @@
return $title;
if ( $id == $ultimatemember->permalinks->core['user'] ) {
- if ( um_is_user_page_uri() && um_get_requested_user() ) {
+ if ( um_is_core_page('user') && um_get_requested_user() ) {
$title = um_get_display_name( um_get_requested_user() );
- } else if ( um_is_user_page_uri() && is_user_logged_in() ) {
+ } else if ( um_is_core_page('user') && is_user_logged_in() ) {
$title = um_get_display_name( get_current_user_id() );
}
}
diff --git a/core/um-form.php b/core/um-form.php
index 131a00d1..c2a49308 100644
--- a/core/um-form.php
+++ b/core/um-form.php
@@ -67,8 +67,7 @@ class UM_Form {
$this->post_form['submitted'] = $this->post_form;
$this->post_form = array_merge( $this->form_data, $this->post_form );
-
- /*
+
if ( $_POST[ $ultimatemember->honeypot ] != '' )
wp_die('Hello, spam bot!');
@@ -81,10 +80,9 @@ class UM_Form {
wp_die( __('Hello, spam bot!') );
if ( $live_timestamp - $form_timestamp < 5 )
- wp_die( __('Whoa, slow down! You’re seeing this message because you tried to submit a form too fast and we think you might be a spam bot. If you are a real human being please wait a few seconds before submitting the form. Thanks!') );
+ wp_die( __('Whoa, slow down! You\'re seeing this message because you tried to submit a form too fast and we think you might be a spam bot. If you are a real human being please wait a few seconds before submitting the form. Thanks!') );
}
- */
/* Continue based on form mode - pre-validation */
diff --git a/core/um-logout.php b/core/um-logout.php
index 0f7cb18c..5720d5cc 100644
--- a/core/um-logout.php
+++ b/core/um-logout.php
@@ -12,7 +12,8 @@ class UM_Logout {
*** @Logout via logout page
***/
function logout_page() {
- if ( um_is_logout_page() ) {
+
+ if ( um_is_core_page('logout') ) {
if ( is_user_logged_in() ) {
@@ -32,6 +33,7 @@ class UM_Logout {
}
}
+
}
}
\ No newline at end of file
diff --git a/core/um-mail.php b/core/um-mail.php
index 1bf3b342..43d3db8d 100644
--- a/core/um-mail.php
+++ b/core/um-mail.php
@@ -38,6 +38,7 @@ class UM_Mail {
'{display_name}',
'{site_name}',
'{account_activation_link}',
+ '{password_reset_link}',
'{admin_email}',
'{user_profile_link}',
);
@@ -48,6 +49,7 @@ class UM_Mail {
um_user('display_name'),
um_get_option('site_name'),
um_user('account_activation_link'),
+ um_user('password_reset_link'),
um_admin_email(),
um_user_profile_url(),
);
diff --git a/core/um-password.php b/core/um-password.php
new file mode 100644
index 00000000..9b18c20c
--- /dev/null
+++ b/core/um-password.php
@@ -0,0 +1,225 @@
+user->profile['reset_pass_hash_token'] = time();
+ $ultimatemember->user->update_usermeta_info('reset_pass_hash_token');
+
+ $this->change_password = true;
+
+ um_reset_user();
+
+ }
+
+ }
+
+ /***
+ *** @reset url
+ ***/
+ function reset_url(){
+ global $ultimatemember;
+
+ if ( !um_user('reset_pass_hash') ) return false;
+
+ $url = add_query_arg( 'act', 'reset_password', um_get_core_page('password-reset') );
+ $url = add_query_arg( 'hash', um_user('reset_pass_hash'), $url );
+ $url = add_query_arg( 'user_id', um_user('ID'), $url );
+
+ return $url;
+
+ }
+
+ /***
+ *** @we are on password reset page
+ ***/
+ function password_reset(){
+ global $ultimatemember;
+
+ if ( um_is_core_page('password-reset') ) {
+
+ $ultimatemember->fields->set_mode = 'password';
+
+ }
+
+ }
+
+ /***
+ *** @password page form
+ ***/
+ function form_init() {
+ global $ultimatemember;
+
+ if ( um_requesting_password_reset() ) {
+
+ $ultimatemember->form->post_form = $_POST;
+
+ do_action('um_reset_password_errors_hook', $ultimatemember->form->post_form );
+
+ if ( !isset($ultimatemember->form->errors) ) {
+
+ do_action('um_reset_password_process_hook', $ultimatemember->form->post_form );
+
+ }
+
+ }
+
+ if ( um_requesting_password_change() ) {
+
+ $ultimatemember->form->post_form = $_POST;
+
+ do_action('um_change_password_errors_hook', $ultimatemember->form->post_form );
+
+ if ( !isset($ultimatemember->form->errors) ) {
+
+ do_action('um_change_password_process_hook', $ultimatemember->form->post_form );
+
+ }
+
+ }
+
+ }
+
+ /***
+ *** @Add class based on shortcode
+ ***/
+ function get_class( $mode ){
+
+ global $ultimatemember;
+
+ $classes = 'um-'.$mode;
+
+ if ( is_admin() ) {
+ $classes .= ' um-in-admin';
+ }
+
+ if ( $ultimatemember->fields->editing == true ) {
+ $classes .= ' um-editing';
+ }
+
+ if ( $ultimatemember->fields->viewing == true ) {
+ $classes .= ' um-viewing';
+ }
+
+ $classes = apply_filters('um_form_official_classes__hook', $classes);
+ return $classes;
+ }
+
+ /***
+ *** @Shortcode
+ ***/
+ function ultimatemember_password( $args = array() ) {
+ return $this->load( $args );
+ }
+
+ /***
+ *** @Load a module with global function
+ ***/
+ function load( $args ) {
+
+ global $ultimatemember;
+
+ ob_start();
+
+ $defaults = array(
+ 'template' => 'password-reset',
+ 'mode' => 'password',
+ 'form_id' => 'um_password_id',
+ 'max_width' => '450px',
+ 'align' => 'center',
+ );
+ $args = wp_parse_args( $args, $defaults );
+
+ if ( isset( $args['use_globals'] ) && $args['use_globals'] == 1 ) {
+ $args = array_merge( $args, $this->get_css_args( $args ) );
+ } else {
+ $args = array_merge( $this->get_css_args( $args ), $args );
+ }
+
+ $args = apply_filters('um_reset_password_shortcode_args_filter', $args);
+
+ if ( isset( $this->change_password ) ) {
+
+ $args['user_id'] = $_REQUEST['user_id'];
+ $args['template'] = 'password-change';
+
+ }
+
+ extract( $args, EXTR_SKIP );
+
+ do_action("um_pre_{$mode}_shortcode", $args);
+
+ do_action("um_before_form_is_loaded", $args);
+
+ do_action("um_before_{$mode}_form_is_loaded", $args);
+
+ do_action("um_before_{$template}_form_is_loaded", $args);
+
+ $this->template_load( $template, $args );
+
+ if ( !is_admin() && !defined( 'DOING_AJAX' ) ) {
+ $this->dynamic_css( $args );
+ }
+
+ $output = ob_get_contents();
+ ob_end_clean();
+ return $output;
+
+ }
+
+ /***
+ *** @Get dynamic css args
+ ***/
+ function get_css_args( $args ) {
+ $arr = um_styling_defaults( $args['mode'] );
+ $arr = array_merge( $arr, array( 'form_id' => $args['form_id'], 'mode' => $args['mode'] ) );
+ return $arr;
+ }
+
+ /***
+ *** @Load dynamic css
+ ***/
+ function dynamic_css( $args=array() ) {
+ extract($args);
+ $global = um_path . 'assets/dynamic_css/dynamic_global.php';
+ $file = um_path . 'assets/dynamic_css/dynamic_'.$mode.'.php';
+ include $global;
+ if ( file_exists( $file ) )
+ include $file;
+ }
+
+ /***
+ *** @Loads a template file
+ ***/
+ function template_load( $template, $args=array() ) {
+ global $ultimatemember;
+ extract($args);
+ $file = um_path . 'templates/'. $template . '.php';
+ if ( file_exists( $file ) ) include $file;
+ }
+}
\ No newline at end of file
diff --git a/core/um-permalinks.php b/core/um-permalinks.php
index 79eca569..742cc8bb 100644
--- a/core/um-permalinks.php
+++ b/core/um-permalinks.php
@@ -70,6 +70,7 @@ class UM_Permalinks {
$ultimatemember->user->approve();
um_reset_user();
+
}
}
@@ -123,6 +124,7 @@ class UM_Permalinks {
***/
function profile_url() {
global $ultimatemember;
+
$profile_url = $this->core['user'];
$profile_url = get_permalink($profile_url);
diff --git a/core/um-rewrite.php b/core/um-rewrite.php
index 28cd2a4f..12a87f97 100644
--- a/core/um-rewrite.php
+++ b/core/um-rewrite.php
@@ -59,14 +59,14 @@ class UM_Rewrite {
function locate_user_profile() {
global $post, $ultimatemember;
- if ( um_queried_user() && um_is_user_page_uri() ) {
+ if ( um_queried_user() && um_is_core_page('user') ) {
if ( um_get_option('permalink_base') == 'user_login' ) {
$user_id = username_exists( um_queried_user() );
if ( $user_id ) {
um_set_requested_user( $user_id );
} else {
- exit( wp_redirect( um_user_page_uri() ) );
+ exit( wp_redirect( um_get_core_page('user') ) );
}
}
@@ -75,7 +75,7 @@ class UM_Rewrite {
if ( $user_id ) {
um_set_requested_user( $user_id );
} else {
- exit( wp_redirect( um_user_page_uri() ) );
+ exit( wp_redirect( um_get_core_page('user') ) );
}
}
@@ -84,7 +84,7 @@ class UM_Rewrite {
if ( $user_id ) {
um_set_requested_user( $user_id );
} else {
- exit( wp_redirect( um_user_page_uri() ) );
+ exit( wp_redirect( um_get_core_page('user') ) );
}
}
diff --git a/core/um-short-functions.php b/core/um-short-functions.php
index ebfda21a..d2e57c9d 100644
--- a/core/um-short-functions.php
+++ b/core/um-short-functions.php
@@ -3,13 +3,27 @@
/***
*** @Get core page url
***/
- function um_get_core_page( $slug ) {
+ function um_get_core_page( $slug, $updated = false) {
global $ultimatemember;
if ( $ultimatemember->permalinks->core[ $slug ] )
- return get_permalink( $ultimatemember->permalinks->core[ $slug ] );
+ $url = get_permalink( $ultimatemember->permalinks->core[ $slug ] );
+ if ( $updated ) {
+ $url = add_query_arg( 'updated', $updated, $url );
+ }
+ return $url;
return '';
}
+ /***
+ *** @boolean check if we are on a core page or not
+ ***/
+ function um_is_core_page( $page ) {
+ global $post, $ultimatemember;
+ if ( isset($post->ID) && $post->ID == $ultimatemember->permalinks->core[ $page ] )
+ return true;
+ return false;
+ }
+
/***
*** @Check value of queried search in text input
***/
@@ -67,57 +81,35 @@
return '';
}
+ /***
+ *** @check if a legitimate password reset request is in action
+ ***/
+ function um_requesting_password_reset() {
+ global $post, $ultimatemember;
+ if ( um_is_core_page('password-reset') && isset( $_POST['_um_password_reset'] ) == 1 )
+ return true;
+ return false;
+ }
+
+ /***
+ *** @check if a legitimate password change request is in action
+ ***/
+ function um_requesting_password_change() {
+ global $post, $ultimatemember;
+ if ( um_is_core_page('password-reset') && isset( $_POST['_um_password_change'] ) == 1 )
+ return true;
+ return false;
+ }
+
/***
*** @boolean for account page editing
***/
function um_submitting_account_page() {
- if ( um_is_account_page() && isset($_POST['_um_account']) == 1 && is_user_logged_in() )
+ if ( um_is_core_page('account') && isset($_POST['_um_account']) == 1 && is_user_logged_in() )
return true;
return false;
}
- /***
- *** @if we're on account page
- ***/
- function um_is_account_page() {
- global $post, $ultimatemember;
- if ( isset($post->ID) && $post->ID == $ultimatemember->permalinks->core['account'] )
- return true;
- return false;
- }
-
- /***
- *** @account page URI
- ***/
- function um_account_page_url(){
- global $ultimatemember;
- return get_permalink( $ultimatemember->permalinks->core['account'] );
- }
-
- /***
- *** @if we're on logout page
- ***/
- function um_is_logout_page() {
- global $post, $ultimatemember;
- if ( isset($post->ID) && $post->ID == $ultimatemember->permalinks->core['logout'] )
- return true;
- return false;
- }
-
- /***
- *** @show logout page url
- ***/
- function um_logout_page( $redirect_to = false ) {
- global $ultimatemember;
- if ( isset( $ultimatemember->permalinks->core['logout'] ) && is_user_logged_in() )
- $link = get_permalink( $ultimatemember->permalinks->core['logout'] );
- if ( $redirect_to ) {
- $link = add_query_arg( 'redirect_to', $redirect_to, $link );
- }
- return $link;
- return false;
- }
-
/***
*** @get a user's display name
***/
@@ -161,39 +153,10 @@
***/
function um_is_my_profile() {
if ( !is_user_logged_in() ) return false;
- if ( um_is_user_page_uri() && get_current_user_id() == um_get_requested_user() ) return true;
+ if ( um_is_core_page('user') && get_current_user_id() == um_get_requested_user() ) return true;
return false;
}
- /***
- *** @The UM's profile page URI
- ***/
- function um_user_page_uri(){
- global $ultimatemember;
- return get_permalink( $ultimatemember->permalinks->core['user'] );
- }
-
- /***
- *** @checks whether we're on UM profile page
- ***/
- function um_is_user_page_uri() {
- global $post, $ultimatemember;
- if ( isset($post->ID) && $post->ID == $ultimatemember->permalinks->core['user'] )
- return true;
- return false;
- }
-
- /***
- *** @user's profile ID
- ***/
- function um_user_page_id() {
- global $post, $ultimatemember;
- if ( isset( $ultimatemember->permalinks->core['user'] ) ) {
- return $ultimatemember->permalinks->core['user'];
- }
- return '';
- }
-
/***
*** @gets the queried user
***/
@@ -543,6 +506,10 @@
return $array;
break;
+ case 'password_reset_link':
+ return $ultimatemember->password->reset_url();
+ break;
+
case 'account_activation_link':
return $ultimatemember->permalinks->activate_url();
break;
diff --git a/core/um-user.php b/core/um-user.php
index db5f1304..caaaa6bb 100644
--- a/core/um-user.php
+++ b/core/um-user.php
@@ -207,6 +207,17 @@ class UM_User {
}
+ /***
+ *** @Set user's hash for password reset
+ ***/
+ function password_reset_hash(){
+ global $ultimatemember;
+
+ $this->profile['reset_pass_hash'] = $ultimatemember->validation->generate(30);
+ $this->update_usermeta_info('reset_pass_hash');
+
+ }
+
/***
*** @Set user's hash
***/
@@ -222,6 +233,15 @@ class UM_User {
}
+ /***
+ *** @password reset email
+ ***/
+ function password_reset(){
+ global $ultimatemember;
+ $this->password_reset_hash();
+ $ultimatemember->mail->send( um_user('user_email'), 'resetpw_email' );
+ }
+
/***
*** @approves a user
***/
diff --git a/templates/password-change.php b/templates/password-change.php
new file mode 100644
index 00000000..0340dd79
--- /dev/null
+++ b/templates/password-change.php
@@ -0,0 +1,25 @@
+
\ No newline at end of file
diff --git a/templates/password-reset.php b/templates/password-reset.php
new file mode 100644
index 00000000..a4f4b24e
--- /dev/null
+++ b/templates/password-reset.php
@@ -0,0 +1,35 @@
+
\ No newline at end of file
diff --git a/um-config.php b/um-config.php
index fe237b5e..dddc11c3 100644
--- a/um-config.php
+++ b/um-config.php
@@ -54,7 +54,7 @@ $this->sections[] = array(
'title' => __( 'Profile Permalink Base' ),
'desc' => __( 'Here you can control the permalink structure of the user profile URL globally' ),
'default' => 'user_login',
- 'desc' => 'e.g. ' . trailingslashit( um_user_page_uri() ) .'
username/',
+ 'desc' => 'e.g. ' . trailingslashit( um_get_core_page('user') ) .'
username/',
'options' => array(
'user_login' => 'Username',
'name' => 'First and Last Name',
@@ -582,6 +582,38 @@ $this->sections[] = array(
'Thanks,' . "\r\n" .
'{site_name}',
),
+
+ array(
+ 'id' => 'resetpw_email_on',
+ 'type' => 'switch',
+ 'title' => __( 'Password Reset Email' ),
+ 'default' => 1,
+ 'desc' => 'Whether to send the user an email when he request to reset password (Recommended, please keep on)',
+ ),
+
+ array(
+ 'id' => 'resetpw_email_sub',
+ 'type' => 'text',
+ 'title' => __( 'Password Reset Email' ),
+ 'subtitle' => __( 'Subject Line' ),
+ 'default' => 'Reset your password',
+ 'required' => array( 'resetpw_email_on', '=', 1 ),
+ 'desc' => 'This is the subject line of the e-mail',
+ ),
+
+ array(
+ 'id' => 'resetpw_email',
+ 'type' => 'textarea',
+ 'title' => __( 'Password Reset Email' ),
+ 'subtitle' => __( 'Message Body' ),
+ 'required' => array( 'resetpw_email_on', '=', 1 ),
+ 'default' => 'Hi {display_name},' . "\r\n\r\n" .
+ 'We received a request to reset the password for your account. If you made this request, click the link below to change your password:' . "\r\n\r\n" .
+ '{password_reset_link}' . "\r\n\r\n" .
+ 'If you didn\'t make this request, you can ignore this email' . "\r\n\r\n" .
+ 'Thanks,' . "\r\n" .
+ '{site_name}',
+ ),
)
diff --git a/um-init.php b/um-init.php
index 28e3c7c2..ad25f053 100644
--- a/um-init.php
+++ b/um-init.php
@@ -32,6 +32,7 @@ class UM_API {
require_once um_path . 'core/um-enqueue.php';
require_once um_path . 'core/um-shortcodes.php';
require_once um_path . 'core/um-account.php';
+ require_once um_path . 'core/um-password.php';
require_once um_path . 'core/um-fields.php';
require_once um_path . 'core/um-form.php';
require_once um_path . 'core/um-user.php';
@@ -58,12 +59,14 @@ class UM_API {
require_once um_path . 'core/um-actions-register.php';
require_once um_path . 'core/um-actions-profile.php';
require_once um_path . 'core/um-actions-account.php';
+ require_once um_path . 'core/um-actions-password.php';
require_once um_path . 'core/um-actions-members.php';
require_once um_path . 'core/um-actions-global.php';
require_once um_path . 'core/um-actions-tracking.php';
require_once um_path . 'core/um-actions-user.php';
require_once um_path . 'core/um-actions-save-profile.php';
require_once um_path . 'core/um-actions-modal.php';
+ require_once um_path . 'core/um-actions-notices.php';
require_once um_path . 'core/um-filters-login.php';
require_once um_path . 'core/um-filters-register.php';
@@ -85,6 +88,7 @@ class UM_API {
$this->styles = new UM_Enqueue();
$this->shortcodes = new UM_Shortcodes();
$this->account = new UM_Account();
+ $this->password = new UM_Password();
$this->login = new UM_Login();
$this->register = new UM_Register();
$this->fields = new UM_Fields();