*/ class Ace_User_Management_Public { /** * The ID of this plugin. * * @since 1.0.0 * @access private * @var string $pluginName The ID of this plugin. */ private $pluginName; /** * The version of this plugin. * * @since 1.0.0 * @access private * @var string $version The current version of this plugin. */ private $version; /** * Initialize the class and set its properties. * * @since 1.0.0 * @param string $pluginName The name of the plugin. * @param string $version The version of this plugin. */ public function __construct( $pluginName, $version ) { $this->pluginName = $pluginName; $this->version = $version; } /** * Register the stylesheets for the public-facing side of the site. * * @since 1.0.0 */ public function aceEnqueueStyles() { /** * This function is provided for demonstration purposes only. * * An instance of this class should be passed to the run() function * defined in Ace_User_Management_Loader as all of the hooks are defined * in that particular class. * * The Ace_User_Management_Loader will then create the relationship * between the defined hooks and the functions defined in this * class. */ wp_enqueue_style( 'bootstrap-css', 'https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css' ); wp_enqueue_style( $this->pluginName, plugin_dir_url( __FILE__ ) . 'css/ace-user-management-public.css', array(), $this->version, 'all' ); wp_enqueue_style( 'font-awesome', 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css', array(), null ); } /** * Register the JavaScript for the public-facing side of the site. * * @since 1.0.0 */ public function aceEnqueueScripts() { /** * This function is provided for demonstration purposes only. * * An instance of this class should be passed to the run() function * defined in Ace_User_Management_Loader as all of the hooks are defined * in that particular class. * * The Ace_User_Management_Loader will then create the relationship * between the defined hooks and the functions defined in this * class. */ wp_enqueue_script( $this->pluginName, plugin_dir_url( __FILE__ ) .'js/ace-user-management-public.js', array( 'jquery' ), $this->version, false ); wp_localize_script( 'ajax-script', 'my_ajax_object',array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) ); wp_enqueue_script( $this->pluginName.'api', plugin_dir_url( __FILE__ ) . 'js/ace-api.js', array(), $this->version, 'all' ); // wp_enqueue_script('google-recaptcha', 'https://www.google.com/recaptcha/api.js', array(), null, true); wp_enqueue_script( 'jquery' ); wp_enqueue_script( 'bootstrap-js', 'https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.bundle.min.js', array('jquery'), '', true ); } public function acePagesPermalink() { global $pagePermalink; $pagePermalink = array( 'login_permalink' => get_page_by_title('login'), 'reg_permalink' => get_page_by_title('registration'), 'profile_permalink' => get_page_by_title('profile'), 'confirm_pass' => get_page_by_title('Confirm Password'), 'forget_pass' => get_page_by_title('Forget password') ); } public function aceShowAdminBarStatus(){ if ( ! current_user_can( 'manage_options' ) ) { show_admin_bar( false ); } } // user logout public function aceCustomLogoutPage(){ global $pagePermalink; wp_redirect( site_url('/').$pagePermalink['login_permalink']->post_name ); exit; } function aceRegisterUrl($link){ global $pagePermalink; return str_replace(site_url('wp-login.php?action=register', 'login'),site_url().$pagePermalink['reg_permalink']->ID,$link); } // login error public function aceMyLoginRedirect($redirect_to, $requested_redirect_to, $user) { global $pagePermalink; $loginPermalink = get_page_by_title( 'login' ); if (is_wp_error($user)) { if (isset($_POST['wp-submit'])) { // Your code here wp_redirect( get_permalink($loginPermalink->ID)."?&login=failed" ); }else{ wp_redirect( get_permalink($loginPermalink->ID) ); } exit; }else{ if( $user->roles[0] == 'administrator' ) { wp_redirect( site_url('/wp-admin')); }else { wp_redirect( site_url($pagePermalink['profile_permalink']->ID) ); } } } public function aceCatchEmptyUser( $username, $pwd ) { $loginPermalink = get_page_by_title( 'login' ); $recaptchaKeys = get_option('custom_reCapatcha_value'); if( $recaptchaKeys['c_reCaptcha_value'] == 1 ){ $recEmpty = empty($_POST['g-recaptcha-response']); } } // user custom profile page public function aceSubscriberLogin(){ global $current_user, $pagePermalink; get_currentuserinfo(); if ( ! user_can( $current_user, "administrator" ) ) { //wp_redirect( site_url(). $pagePermalink['profile_permalink']->ID ); } } public function aceLoginoutMenuLink( $items, $args ) { global $pagePermalink; if ($args->theme_location) { if (is_user_logged_in()) { $items .= '
  • '. __("Profile") .'
  • '; $items .= '
  • '. __("Log Out") .'
  • '; } else { $items .= '
  • '. __("Log In") .'
  • '; $items .= '
  • '. __("Sign Up") .'
  • '; } } return $items; } // login and profile access public function aceRedirectToSpecificPage() { global $current_user, $pagePermalink; get_currentuserinfo(); if ( ! user_can( $current_user, "administrator" ) ) { if ( is_user_logged_in() ) { if ( is_page($pagePermalink['login_permalink']->ID)) { wp_redirect( get_permalink( $pagePermalink['profile_permalink']->ID ) ); exit; } if ( is_page($pagePermalink['reg_permalink']->ID)) { wp_redirect( site_url() ); exit; } }else{ if( is_page($pagePermalink['profile_permalink']->ID)) { wp_redirect( get_permalink($pagePermalink['login_permalink']->ID ) ) ; exit; } } } } public function ace_user_profile_template(){ require_once ( __DIR__ ). '/partials/ace-profile.php'; } function ace_subscriber_profile(){ global $pagePermalink; if(current_user_can( 'manage_options' )) return ''; if( strpos( site_url(), 'wp_admin/?action=reg.php' ) ){ wp_redirect( get_permalink($pagePermalink['login_permalink']->ID ) ); exit; } } public function ace_login_form(){ ob_start(); global $pagePermalink; $css_by_option = get_option('ace_custom_css_plugin'); $forget_url = get_permalink($pagePermalink['forget_pass']->ID ); $recaptchaKeys = get_option('custom_reCapatcha_value'); if ( isset( $_POST['g-recaptcha-response']) && $_POST['g-recaptcha-response']) { $captcha = $_POST['g-recaptcha-response'] ; $secretKey = ''; $remoteip = $_SERVER['REMOTE_ADDR']; $response = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=" . $secretKey . "&response=" . $captcha . "&remoteip=" . $remoteip); $responseKeys = json_decode($response, true); if (intval($responseKeys["success"]) !== 1) { return "failed"; } else { return "success"; } } if (is_user_logged_in()) { echo ""; } $recaptchaKeys = get_option('custom_reCapatcha_value'); if (isset($_GET['login']) && $_GET['login'] === 'failed') { echo '
    ⚠ Username and password incorrect
    '; } if (isset($_GET['login']) && $_GET['login'] === 'empty') { echo '
    ⚠ Please fill all fields
    '; } $url = ( __DIR__ ); require_once ( __DIR__ ). '/partials/ace-login.php'; return ob_get_clean(); } public function ace_forget_password(){ $loginPermalink = get_page_by_title( 'login' ); ob_start(); global $wpdb, $pagePermalink ; if(isset($_POST['reset-submit'])){ $resetPassword = isset($_POST['reset_password']) ? sanitize_text_field($_POST['reset_password']) : ''; $resetEmail = sanitize_text_field($resetPassword); $error = array(); if(!empty($resetEmail)){ if(is_email($resetEmail)){ if(email_exists($resetEmail)){ $user = get_user_by('email',$resetEmail); $userId = $user->ID; $user_email = sanitize_text_field( $user->user_email); $randomCode = bin2hex(random_bytes(16)); $table_name = $wpdb->prefix."ace_reset_password" ; $exsist_user = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $table_name WHERE user_id = %d", $userId )); if(!empty($exsist_user)){ $update_data = array( 'randomCode' => $randomCode, 'currentTime' => current_time('mysql') ); $where = array( 'user_id' => $userId ); $updated = $wpdb->update( $table_name, $update_data,$where); }else{ $wpdb->insert($table_name, array( "user_id" => $userId, "email" => $resetEmail, "randomCode" => $randomCode ) ); } $to = $resetEmail; $subject = __('Lost Password','ace-user-management'); $message = get_permalink( $pagePermalink['confirm_pass']->ID).$randomCode; $headers = get_option('admin_email'); if( wp_mail( $to, $subject, $message, $headers )){ ?>


    ' . esc_html($emailError) . '
    '; } } require_once ( __DIR__ ). '/partials/ace-forget-password.php'; $wp_content = ob_get_clean(); return $wp_content; } function custom_rewrite_rule() { add_rewrite_rule( '^confirm-password/([a-f0-9]{32,64})/?$', 'index.php?pagename=confirm-password&randNum=$matches[1]', 'top' ); } function add_randNum_to_query_vars($vars) { $vars[] = 'randNum'; return $vars; } function redirect_old_randNum_url() { if (isset($_GET['randNum']) && !empty($_GET['randNum'])) { $randNum = sanitize_text_field($_GET['randNum']); wp_redirect(home_url("/confirm-password/{$randNum}")); exit(); } } public function ace_confirm_code_page() { ob_start(); // Start output buffering global $wpdb; $loginPermalink = get_page_by_title('login'); $getRandcode = get_query_var('randNum'); $tablename = $wpdb->prefix . "ace_reset_password"; $sql = $wpdb->get_row("SELECT * FROM $tablename WHERE randomCode = '$getRandcode'"); if (!empty($sql->randomCode)) { $createdAt = strtotime($sql->currentTime); $current_time = date('Y-m-d H:i:s'); $current_time_unix = strtotime($current_time); $diffInMinutes = ($current_time_unix - $createdAt) / 60; if ($diffInMinutes > 10) { echo '
    Token expired. Please request a new reset link. Click here
    '; } else { $userId = $sql->user_id; $error = array(); if (isset($_POST['submit_password'])) { $password = isset($_POST['password']) ? sanitize_text_field($_POST['password']) : ''; $conPassword = isset($_POST['confirm_password']) ? sanitize_text_field($_POST['confirm_password']) : ''; if (!empty($password)) { if (strlen($password) > 6) { if (preg_match('/[!@#$%^&*(),.?":{}|<>]/', $password)) { if (!empty($conPassword)) { if (strcmp($password, $conPassword) == 0) { $user = intval($_POST['user_id']); $password = wp_hash_password($password); $userTable = $wpdb->prefix . 'users'; $update_pass = $wpdb->query("UPDATE $userTable SET user_pass = '$password' WHERE ID = $user"); echo '
    ' . esc_html('Password successfully updated', 'ace-user-management') . '
    '; echo ''; } else { $error['confirm_password'] = __('! Confirm password does not match', 'ace-user-management'); } } else { $error['empty_password'] = __('! Please enter confirm password', 'ace-user-management'); } } else { $error['password_symbol'] = __('! Password must contain at least one special symbol', 'ace-user-management'); } } else { $error['password_length'] = __('! Password must be at least 6 characters long', 'ace-user-management'); } } else { $error['empty_password'] = __('! Please enter a password', 'ace-user-management'); } if (!empty($error)) { foreach ($error as $error_key => $errorValue) { echo '
    ' . esc_html($errorValue) . '
    '; } } } require_once plugin_dir_path( __FILE__ ). 'partials/ace-confirm-randnum.php'; } } else { echo ''; } $wp_content = ob_get_clean(); return $wp_content; } public function ace_reg_form(){ ob_start(); global $wpdb, $userID; $loginPermalink = get_page_by_title( 'login' ); $results = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}ace_register_fields ORDER BY sortby ASC ", OBJECT ); $firstname=''; $lastname=''; $username=''; $email=''; if(isset( $_POST['submit'] ) && sanitize_text_field( $_POST['submit']) != ''){ $error = array(); $username = sanitize_text_field( $_REQUEST['username'] ); if ( empty($username) ) { $error['username_empty'] = __('Enter Username','ace-user-management'); } else { if ( strlen($username) < 7 ) { $error['username_length'] = __('Username must be more than 6 characters.','ace-user-management'); } if ( !preg_match('/\d/', $username) ) { $error['username_number'] = __('Username must contain at least one number.','ace-user-management'); } if ( username_exists($username) ) { $error['username_exists'] = __('Username already exists','ace-user-management'); } } $email = sanitize_text_field( $_REQUEST['email'] ); $blocked_domains = [ 'tempmail.com', 'mailinator.com', '10minutemail.com', 'yopmail.com', 'guerrillamail.com', 'example.com' ]; // Extract the domain from email $email_domain = strtolower(substr(strrchr($email, "@"), 1)); if (in_array($email_domain, $blocked_domains)) { $error['disposable_email_error'] = __('Temporary or disposable email addresses are not allowed. Please use a valid email.', 'ace-user-management'); } $password = $wpdb->escape( sanitize_text_field( $_REQUEST['password'])); $c_password = sanitize_text_field($_POST['c_password']); $reCaptcha = ( isset ($_POST['g-recaptcha-response'])) ? sanitize_text_field($_POST['g-recaptcha-response'] ) : '' ; $success =''; if(!empty($username)){ if(username_exists($username)){ $error['username_exists'] = __('Username exists','ace-user-management'); } }else{ $error['username_empty'] = __('Enter Username','ace-user-management'); } if(!empty($email)){ if(is_email($email)){ if(email_exists($email)) { $error['email_exists'] = __('This email already exists','ace-user-management'); } } else { $error['email_valid'] = __('Enter valid email','ace-user-management'); } } else { $error['email_empty'] = __('Enter email','ace-user-management'); } if(!empty($password)){ if(!empty($c_password)){ if(strcmp($password, $c_password) != 0){ $error['con_password'] =__('password not same','ace-user-management'); } }else{ $error['confirm_empty'] = __('Enter Confirm Password','ace-user-management'); } }else{ $error['password_empty'] = __('Enter Password','ace-user-management'); } $recaptcha_v = get_option('custom_reCapatcha_value'); if (is_array($recaptcha_v) && isset($recaptcha_v['c_reCaptcha_value']) && $recaptcha_v['c_reCaptcha_value'] == 1){ if( empty( $recaptcha_v ) ){ $error['reCap'] = __('reCaptcha is not set','ace-user-management'); } } if(empty($error)){ $userId = wp_create_user( $username, $password, $email ); unset($_POST['username']); unset($_POST['email']); unset($_POST['password']); unset($_POST['c_password']); unset($_POST['submit']); $userExtrafields = Ace_User_Management_Function::sanitize($_POST ); update_user_meta( $userId, 'user_extrafields', $userExtrafields ); $user_data = get_user_meta( $userId, 'user_extrafields', true ); foreach ( $user_data as $userkey => $userValue ) { update_user_meta( $userId, $userkey , $userValue ); } ?>