/** * Load the view for login form. Can be loaded to a modal. * * @param string $redirect_to URL, after login the user will be redirected to this URL. * @return string HTML form view. */ function get_moove_login_form($redirect_to) { return Moove_View::load('moove.login', array('redirect_to' => $redirect_to)); }
/** * Login form with redirect url * * @return string Login form */ public static function moove_login() { Moove_Controller::moove_check_redirect(); $get_login = sanitize_text_field(wp_unslash($_GET['login'])); $login = isset($get_login) ? esc_attr($get_login) : 0; $login_message = array('type' => false); if ($login === 'failed') { $login_message['type'] = 'error'; $login_message['msg'] = __('Invalid username and/or password.', 'moove'); } elseif ($login === 'empty') { $login_message['type'] = 'error'; $login_message['msg'] = __('Username and/or Password is empty.', 'moove'); } elseif ($login === 'false') { $login_message['type'] = 'info'; $login_message['msg'] = __('You are logged out.', 'moove'); } $redirect_to = esc_url_raw(wp_unslash($_GET['redirect'])); $redirect = isset($redirect_to) ? trim(esc_url($redirect_to)) : ''; $view_bag = array('system_message' => $login_message); if (trim($redirect) !== '') { $view_bag['redirect_to'] = $redirect; } return Moove_View::load('moove.login', $view_bag); }
/** * Setting page for post type protection settings * * @param array $args Data array to view. */ public function moove_setting_callback($args) { echo Moove_View::load('moove.admin.settings.post_type', array('post_type' => $args['post_type'], 'protection_type' => sanitize_text_field(wp_unslash($args['protection_type'])), 'options' => $this->options)); }
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>[[mail_title]]</title> </head> <body> <?php echo Moove_View::load('moove.mail.remind-content'); ?> </body> </html>
<button type="submit" class="btn btn-default request_new_password"><?php _e('request new password', 'moove'); ?> </button> <a class="back-to-login" href="#" title="<?php _e('Back to login', 'moove'); ?> "><?php _e('Back to login', 'moove'); ?> </a> </form> <!-- #moove-password-reset --> <div class="reset-confirm-part"> <?php echo Moove_View::load('moove.reset-complete'); ?> <a class="back-to-login" href="#" title="<?php _e('Back to login', 'moove'); ?> "><?php _e('Back to login', 'moove'); ?> </a> </div> <!-- reset-confirm --> </div> <!-- reset-password-part --> </div> <!-- moove-protection-login-container --> </div>
/** * New user registration * * @param array $userData Form data. * @param array $customFields Extra fields from register form. * @return array Created and updated user data */ public function moove_register($userData, $customFields) { $user_id = wp_create_user($userData['username'], $userData['password'], $userData['email']); if (is_wp_error($user_id)) { return $user_id; } $userdata = array('ID' => $user_id, 'first_name' => esc_attr($userData['name']), 'last_name' => esc_attr($userData['surname']), 'display_name' => esc_attr($userData['name'] . ' ' . esc_attr($userData['surname'])), 'user_nicename' => esc_attr($userData['name'] . ' ' . esc_attr($userData['surname'])), 'role' => 'free_registration'); $x = wp_update_user($userdata); if (!is_wp_error($x)) { $maildata = array('username' => esc_attr($userData['name'] . ' ' . esc_attr($userData['surname'])), 'user_email' => esc_attr($userData['email'])); $_mailcontent = Moove_View::load('moove.mail.confirm'); $mailcontent = Moove_User::moove_register_mail_content(array('mail' => $_mailcontent, 'view_data' => $maildata)); wp_mail($userData['email'], 'Welcome to ' . get_option('blogname'), $mailcontent, 'Content-type: text/html' . "\r\n" . ''); do_action('moove_user_normal_registration_complete', $user_id); } return $x; }
/** * Sending the password reset e-mail with token * * @return void */ function moove_password_reset_request() { $email_address = sanitize_email($_POST['email']); if (is_email($email_address)) { $user = get_user_by('email', $email_address); } else { $user = false; } if ($user === false) { echo json_encode(array('success' => false)); } else { $token = sha1($email_address . substr(str_shuffle(str_repeat('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', mt_rand(1, 20))), 1, 20)); $model = new Moove_User(); $model->moove_set_activation_key($token, $user->user_login); $subject = get_option('blogname') . ' - Reset your password'; $view_data = array('name' => $user->display_name, 'email' => $email_address, 'link' => site_url('/reset-password/?token=' . $token)); $_mailcontent = Moove_View::load('moove.mail.remind'); $mailcontent = Moove_User_Custom_Settings::moove_password_reset_content(array('mail' => $_mailcontent, 'view_data' => $view_data)); wp_mail($email_address, $subject, $mailcontent, 'Content-type: text/html' . "\r\n"); echo json_encode(array('success' => true)); } die; }
/** * Functions on plugin activation, create relevant pages and defaults for settings page. */ function moove_activate() { // Activation code here... $pages = array('moove_login_page' => array('title' => 'Login', 'content' => '[LoginForm]'), 'moove_myaccount_page' => array('title' => 'My Account', 'content' => '[MyAccount]'), 'moove_register_page' => array('title' => 'Register', 'content' => '[RegisterForm]'), 'moove_resetpassword_page' => array('title' => 'Reset password', 'content' => '[moove_reset_password]')); foreach ($pages as $option_name => $page) { moove_create_page_with_shortcode($option_name, $page); } if (empty(get_option('moove_protection-email')['Remindcontent'])) { $email['Remindcontent'] = Moove_View::load('moove.mail.remind-content'); if (empty(get_option('moove_protection-email')['Remindemail_title'])) { $email['Remindemail_title'] = __('Reset your password', 'moove'); update_option('moove_protection-email', $email); } update_option('moove_protection-email', $email); } if (empty(get_option('moove_protection-email')['Confirmcontent'])) { $email['Confirmcontent'] = Moove_View::load('moove.mail.confirm-content'); if (empty(get_option('moove_protection-email')['Confirmemail_title'])) { $email['Confirmemail_title'] = __('User signup confirmation mail', 'moove'); update_option('moove_protection-email', $email); } update_option('moove_protection-email', $email); } $protection = get_option('moove_protection-settings'); if (empty($protection['Free-membershipmodal-content'])) { $protection['Free-membershipmodal-content'] = Moove_View::load('moove.protected.free_membership'); if (empty($protection['Free-membershiptruncate-button-text'])) { $protection['Free-membershiptruncate-button-text'] = __('Click here to register.', 'moove'); update_option('moove_protection-settings', $protection); } if (empty($protection['Free-membershiptruncate-button-link'])) { $protection['Free-membershiptruncate-button-link'] = '/register'; update_option('moove_protection-settings', $protection); } if (empty($protection['Free-membershipprotection-message'])) { $protection['Free-membershipprotection-message'] = __('This content is protected, available for registered users.', 'moove'); update_option('moove_protection-settings', $protection); } update_option('moove_protection-settings', $protection); } if (empty($protection['Premium-membershipmodal-content'])) { $protection['Premium-membershipmodal-content'] = Moove_View::load('moove.protected.premium_membership'); if (empty($protection['Premium-membershiptruncate-button-text'])) { $protection['Premium-membershiptruncate-button-text'] = __('Click here to register.', 'moove'); update_option('moove_protection-settings', $protection); } if (empty($protection['Premium-membershiptruncate-button-link'])) { $protection['Premium-membershiptruncate-button-link'] = '/register'; update_option('moove_protection-settings', $protection); } if (empty($protection['Premium-membershipprotection-message'])) { $protection['Premium-membershipprotection-message'] = __('This content is protected, available for users with premium membership.', 'moove'); update_option('moove_protection-settings', $protection); } update_option('moove_protection-settings', $protection); } moove_set_validation_messages(); moove_set_protection_type(); moove_settings_activate(); }
<?php settings_fields('moove_protection_validation'); do_settings_sections('moove-protection-validation'); submit_button(); ?> </form> <?php } elseif ($active_tab == 'protection_settings') { ?> <form action="options.php" method="post" class="moove-protection-form"> <?php settings_fields('moove_protection_settings'); do_settings_sections('moove-protection-settings'); submit_button(); ?> </form> <?php } elseif ($active_tab == 'plugin_documentation') { ?> <?php echo Moove_View::load('moove.admin.settings.documentation'); ?> <?php } ?> </div> <!-- moove-form-container --> </div> <!-- wrap -->
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>[[mail_title]]</title> </head> <body> <?php echo Moove_View::load('moove.mail.confirm-content'); ?> </body> </html>
/** * Password reset * * @param array $atts User attributes. * @return string Error message */ function moove_reset_password($atts) { $validation_messages = get_option('moove_protection-validation'); if (is_user_logged_in()) { return '<p>' . __('Cannot reset password for a logged in user.', 'moove') . '</p>'; } $errors = array(); $token = sanitize_key(wp_unslash($_GET['token'])); $reset_token = sanitize_key(wp_unslash($_POST['reset_token'])); if (trim($token) === '' && !isset($reset_token)) { return '<p>' . __('No token has been specified.', 'moove') . '</p>'; } if (isset($reset_token)) { if (!wp_verify_nonce(sanitize_key(wp_unslash($_POST['moove_reset'])), 'moove_reset_action')) { $errors['error'] = true; $errors['nonce'] = 'Remote check failed'; } $token = $reset_token; $password = sanitize_text_field(wp_unslash($_POST['password'])); $password2 = sanitize_text_field(wp_unslash($_POST['password2'])); if (trim($password) === '') { $errors['error'] = true; $errors['password'] = $validation_messages['Reset_password_required']; } if (mb_strlen($password) < 8) { $errors['error'] = true; $errors['password'] = $validation_messages['Reset_password_min-length']; } if ($password !== $password2) { $errors['error'] = true; $errors['password2'] = $validation_messages['Reset_password_equal-to']; } } if (!isset($errors['error']) && isset($reset_token)) { $user = new Moove_User(); $result = $user->moove_update_password($token, sanitize_text_field(wp_unslash($_POST['password']))); if ($result === false) { $errors['error'] = true; $errors['fail'] = __('An error occurred. Please try again', 'moove'); } } if (!isset($errors['error']) && isset($reset_token)) { echo Moove_View::load('moove.reset-completed', false); } else { echo Moove_View::load('moove.reset', array('token' => esc_attr($token), 'errors' => $errors)); } }
<div class="moove-protection-modal-content"> <a href="" title="Close" class="close">x</a> <?php if (empty(get_option('moove_protection-settings')['Free-membershipmodal-content'])) { echo Moove_View::load('moove.protected.free_membership'); } else { echo get_option('moove_protection-settings')['Free-membershipmodal-content']; } ?> </div> <!-- moove-protection-modal-content --> </div> <!-- moove-modal-dialog-free --> <div id="moove-protection-modal-premium" class="moove-modal-dialog <?php echo $data['modal-premium']; ?> "> <div class="moove-protection-modal-content"> <a href="" title="Close" class="close">x</a> <?php if (empty(get_option('moove_protection-settings')['Premium-membershipmodal-content'])) { echo Moove_View::load('moove.protected.premium_membership'); } else { echo get_option('moove_protection-settings')['Premium-membershipmodal-content']; } ?> </div> <!-- moove-protection-modal-content --> </div> <!-- moove-modal-dialog-premium -->
/** * Content protection, returns the trimmed content if is protected. * * @param string $content Content string. */ function moove_protect_content($content) { $moove_user = new Moove_User(); $u = $moove_user->moove_check(); $post = $GLOBALS['post']; $protection_selected = get_post_meta($post->ID, 'moove_post_protect_data', true); if (empty($protection_selected)) { $post_type = $post->post_type; $options = get_option('moove_post_protect'); if (isset($options[$post_type])) { $protection_selected = $options[$post_type]; } } if (!$u['wp_admin'] || !$u['editor']) { if (!is_admin() && !current_user_can('edit_posts')) { $post_level = moove_post_protection_level($post); if (!is_user_logged_in() && !moove_is_public($post) && !moove_is_premium($post)) { $trimmed = wp_trim_words($post->post_content, $num_words = 55, $more = null); $content = $trimmed; $content .= Moove_View::load('moove.protected.truncated.free_membership_restriction'); } if (moove_is_premium($post)) { $trimmed = wp_trim_words($post->post_content, $num_words = 55, $more = null); $content = $trimmed; $content .= Moove_View::load('moove.protected.truncated.premium_membership_restriction'); } } } return $content; }