Ads Set 1

/* ========================================================= * DAAUD.COM * WHOLESALE + DISTRIBUTOR APPLICATION SYSTEM * Shop Photo + CNIC Front + CNIC Back * Admin Approval System * * Code Snippets: * DO NOT ADD prefix . 'daaud_applications'; if ( get_option( 'daaud_application_table_created' ) ) { return; } $charset_collate = $wpdb->get_charset_collate(); $sql = "CREATE TABLE $table_name ( id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, account_type VARCHAR(30) NOT NULL, shop_name VARCHAR(255) NOT NULL, owner_name VARCHAR(255) NOT NULL, phone VARCHAR(50) NOT NULL, email VARCHAR(255) NOT NULL, address TEXT NOT NULL, city VARCHAR(100) NOT NULL, market VARCHAR(255) DEFAULT '', monthly_purchase VARCHAR(100) DEFAULT '', products TEXT DEFAULT '', message TEXT DEFAULT '', shop_photo BIGINT UNSIGNED DEFAULT 0, cnic_front BIGINT UNSIGNED DEFAULT 0, cnic_back BIGINT UNSIGNED DEFAULT 0, status VARCHAR(30) DEFAULT 'pending', user_id BIGINT UNSIGNED DEFAULT 0, submitted_at DATETIME NOT NULL, PRIMARY KEY (id) ) $charset_collate;"; require_once ABSPATH . 'wp-admin/includes/upgrade.php'; dbDelta( $sql ); update_option( 'daaud_application_table_created', 1 ); } /* ========================================================= * 2. APPLICATION FORM SHORTCODE * * Use: * [daaud_business_application] * ========================================================= */ add_shortcode( 'daaud_business_application', 'daaud_business_application_form' ); function daaud_business_application_form() { if ( is_user_logged_in() ) { $user = wp_get_current_user(); if ( in_array( 'wholesale_customer', (array) $user->roles, true ) || in_array( 'distributor_customer', (array) $user->roles, true ) ) { return '
Your Wholesale/Distributor account is already approved.
'; } } ob_start(); ?>

Wholesale & Distributor Application

Apply for a Daaud Wholesale or Distributor account. Your application will be reviewed before approval.

Account Type

Business Information

Business Details

Business Verification

Please upload clear images. These documents are used only for account verification.

JPG, PNG or WebP. Maximum 5MB.
JPG, PNG or WebP. Maximum 5MB.
JPG, PNG or WebP. Maximum 5MB.
prefix . 'daaud_applications'; $wpdb->insert( $table_name, array( 'account_type' => $account_type, 'shop_name' => $shop_name, 'owner_name' => $owner_name, 'phone' => $phone, 'email' => $email, 'address' => $address, 'city' => $city, 'market' => $market, 'monthly_purchase' => $monthly_purchase, 'products' => $products, 'message' => $message, 'shop_photo' => $shop_photo, 'cnic_front' => $cnic_front, 'cnic_back' => $cnic_back, 'status' => 'pending', 'submitted_at' => current_time( 'mysql' ), ), array( '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%d', '%d', '%d', '%s', '%s', ) ); /* * Send admin email */ $admin_email = get_option( 'admin_email' ); $subject = 'New Daaud ' . ucfirst( $account_type ) . ' Application'; $email_message = "New Daaud Business Application\n\n" . "Account Type: " . ucfirst( $account_type ) . "\n" . "Shop: " . $shop_name . "\n" . "Owner: " . $owner_name . "\n" . "Phone: " . $phone . "\n" . "Email: " . $email . "\n" . "City: " . $city . "\n" . "Market: " . $market . "\n\n" . "Login to WordPress Admin to review and approve the application."; wp_mail( $admin_email, $subject, $email_message ); /* * Redirect after successful submission */ $redirect_url = add_query_arg( 'daaud_application', 'submitted', wp_get_referer() ); wp_safe_redirect( $redirect_url ); exit; } /* ========================================================= * 4. ADMIN MENU * ========================================================= */ add_action( 'admin_menu', 'daaud_application_admin_menu' ); function daaud_application_admin_menu() { add_menu_page( 'Daaud Applications', 'Daaud Applications', 'manage_options', 'daaud-applications', 'daaud_application_admin_page', 'dashicons-id', 26 ); } /* ========================================================= * 5. ADMIN APPLICATION PAGE * ========================================================= */ function daaud_application_admin_page() { if ( ! current_user_can( 'manage_options' ) ) { return; } global $wpdb; $table_name = $wpdb->prefix . 'daaud_applications'; /* * Approve / Reject */ if ( isset( $_GET['action'] ) && isset( $_GET['application_id'] ) ) { $action = sanitize_text_field( wp_unslash( $_GET['action'] ) ); $application_id = absint( $_GET['application_id'] ); if ( isset( $_GET['_wpnonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['_wpnonce'] ) ), 'daaud_application_action_' . $application_id ) ) { if ( $action === 'reject' ) { $wpdb->update( $table_name, array( 'status' => 'rejected', ), array( 'id' => $application_id, ), array( '%s', ), array( '%d', ) ); } if ( $action === 'approve_wholesale' || $action === 'approve_distributor' ) { $application = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $table_name WHERE id = %d", $application_id ) ); if ( $application ) { /* * Create WordPress username */ $base_username = sanitize_user( strtolower( preg_replace( '/\s+/', '', $application->shop_name ) ) ); if ( empty( $base_username ) ) { $base_username = 'customer'; } $username = $base_username . wp_rand( 100, 999 ); /* * Make sure email is unique */ $email = $application->email; $existing_user = get_user_by( 'email', $email ); if ( $existing_user ) { $user_id = $existing_user->ID; } else { /* * Generate password */ $password = wp_generate_password( 12, true, true ); $user_id = wp_create_user( $username, $password, $email ); if ( is_wp_error( $user_id ) ) { echo '

'; echo esc_html( $user_id->get_error_message() ); echo '

'; return; } wp_update_user( array( 'ID' => $user_id, 'first_name' => $application->owner_name, ) ); } /* * Assign role */ $user = new WP_User( $user_id ); if ( $action === 'approve_distributor' ) { $user->set_role( 'distributor_customer' ); $approved_role = 'distributor_customer'; } else { $user->set_role( 'wholesale_customer' ); $approved_role = 'wholesale_customer'; } /* * Save business information */ update_user_meta( $user_id, 'daaud_shop_name', $application->shop_name ); update_user_meta( $user_id, 'daaud_owner_name', $application->owner_name ); update_user_meta( $user_id, 'daaud_phone', $application->phone ); update_user_meta( $user_id, 'daaud_business_address', $application->address ); update_user_meta( $user_id, 'daaud_city', $application->city ); update_user_meta( $user_id, 'daaud_market', $application->market ); /* * Update application */ $wpdb->update( $table_name, array( 'status' => 'approved', 'user_id' => $user_id, ), array( 'id' => $application_id, ), array( '%s', '%d', ), array( '%d', ) ); /* * Send account email */ wp_mail( $email, 'Your Daaud Business Account Has Been Approved', "Hello {$application->owner_name},\n\n" . "Your Daaud " . ucfirst( str_replace( '_customer', '', $approved_role ) ) . " account has been approved.\n\n" . "You can now login to your Daaud account and access your approved pricing.\n\n" . "Username: {$username}\n\n" . "For security, please use the password reset option if required.\n\n" . "Thank you,\nDaaud" ); } } echo '

'; echo 'Application updated successfully.'; echo '

'; } } /* * Get applications */ $applications = $wpdb->get_results( "SELECT * FROM $table_name ORDER BY submitted_at DESC" ); ?>

Daaud Business Applications

Review Wholesale and Distributor applications before approving customer access.

ID Type Shop Owner Phone City Status Date Action
id ); ?> account_type ) ); ?> shop_name ); ?> owner_name ); ?> phone ); ?> city ); ?> status === 'approved' ) { echo 'Approved'; } elseif ( $application->status === 'rejected' ) { echo 'Rejected'; } else { echo 'Pending'; } ?> submitted_at ); ?> id ); ?> View status === 'pending' ) { $wholesale_url = wp_nonce_url( admin_url( 'admin.php?page=daaud-applications&action=approve_wholesale&application_id=' . $application->id ), 'daaud_application_action_' . $application->id ); $distributor_url = wp_nonce_url( admin_url( 'admin.php?page=daaud-applications&action=approve_distributor&application_id=' . $application->id ), 'daaud_application_action_' . $application->id ); $reject_url = wp_nonce_url( admin_url( 'admin.php?page=daaud-applications&action=reject&application_id=' . $application->id ), 'daaud_application_action_' . $application->id ); ?> Approve Wholesale Approve Distributor Reject
No applications found.
get_row( $wpdb->prepare( "SELECT * FROM $table_name WHERE id = %d", $application_id ) ); if ( $application ) : ?>

Application #id ); ?>

Account Type account_type ) ); ?>
Shop Name shop_name ); ?>
Owner Name owner_name ); ?>
Phone phone ); ?>
Email email ); ?>
Address address ) ); ?>
City city ); ?>
Market / Area market ); ?>
Monthly Purchase monthly_purchase ); ?>
Products products ); ?>
Message message ) ); ?>

Verification Documents

$application->shop_photo, 'CNIC Front' => $application->cnic_front, 'CNIC Back' => $application->cnic_back, ); foreach ( $images as $label => $attachment_id ) { if ( ! $attachment_id ) { continue; } $image_url = wp_get_attachment_image_url( $attachment_id, 'large' ); ?>

Step 2 — Application page banayein

WordPress mein:

Pages → Add New

Title:

Wholesale & Distributor Application

Page ke andar sirf ye shortcode paste karein:

[daaud_business_application]

Publish kar dein.

Ab page par complete form aa jayega.


Step 3 — Admin mein applications

Form submit hone ke baad WordPress dashboard mein left side par:

Daaud Applications

ka menu aa jayega.

Wahan example:

TypeShopOwnerCityStatus
WholesaleABC TradersAliSahiwalPending
DistributorXYZ EnterprisesAhmedLahorePending

View par click karke Shop Photo + CNIC Front + CNIC Back bhi dekh sakenge.

Phir:

Approve Wholesale

ya

Approve Distributor

button.


Sabse important

Approval ke baad existing system ke saath connection hoga:

Wholesale Customer → Wholesale Pack Price

Distributor Customer → Distributor Pack Price

Isliye customer ko manually pricing dene ki zarurat nahi hogi.

CNIC ke bare mein ek important security point

Is code mein CNIC images WordPress Media Library mein upload hoti hain. CNIC sensitive document hai, isliye production site par main recommend karunga ke next step mein hum in images ko public Media URL ke bajaye admin-only/private storage mein rakhein. Isse koi direct image URL milne par bhi CNIC openly accessible nahi hogi.

Aur ek aur useful improvement: approval ke baad customer ko username/password email karne ke bajaye secure password-set/reset link bhejna zyada safe hoga.
















Post a Comment

0 Comments