*/ class Ace_User_Management_Activator { /** * Short Description. (use period) * * Long Description. * * @since 1.0.0 */ public static function activate() { global $wpdb; // Prepare table names with proper table prefix $reset_table_name = $wpdb->prefix . "ace_reset_password"; $fields_table_name = $wpdb->prefix . "ace_register_fields"; // Check if the 'ace_reset_password' table exists using a more WordPress-friendly approach $table_exists = $wpdb->get_var( $wpdb->prepare("SHOW TABLES LIKE %s", $reset_table_name) ); // If table doesn't exist, create it if (empty($table_exists)) { $sqlCreateTable = " CREATE TABLE {$reset_table_name} ( `id` int(20) NOT NULL AUTO_INCREMENT, `user_id` int(20) NOT NULL, `email` varchar(100) NOT NULL, `randomCode` varchar(100) NOT NULL, `currentTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; "; // Use dbDelta for creating/updating tables require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); dbDelta($sqlCreateTable); } // Check if the 'ace_register_fields' table exists using a more WordPress-friendly approach $table_exists2 = $wpdb->get_var( $wpdb->prepare("SHOW TABLES LIKE %s", $fields_table_name) ); // If table doesn't exist, create it if (empty($table_exists2)) { $sqlCreateTable2 = " CREATE TABLE {$fields_table_name} ( `id` INT NOT NULL AUTO_INCREMENT, `input_label` VARCHAR(255) NOT NULL, `input_placeholder` VARCHAR(255) NOT NULL, `input_name` VARCHAR(255) NOT NULL, `input_type` VARCHAR(255) NOT NULL, `dropdown_options` TEXT NOT NULL, -- Changed to TEXT for flexibility `sortby` INT NOT NULL, PRIMARY KEY (`id`), INDEX `idx_input_name` (`input_name`), INDEX `idx_input_type` (`input_type`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4; "; // Use dbDelta for creating/updating tables require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); dbDelta($sqlCreateTable2); } // Define pages to be created $pages = [ 'ace-register' => ['Registration', '[ace-registration-public-form]'], 'ace-login' => ['Login', '[ace-login-public-form]'], 'ace-forgetpass' => ['Forget password', '[ace-forget-password]'], 'ace-confirm-password' => ['Confirm Password', '[ace-random-code-page]'], 'ace-profile' => ['Profile', '[ace-profile-page]'] ]; $page_ids = []; foreach ($pages as $slug => $data) { $existing_page = get_page_by_path($slug); if (!$existing_page) { $page = [ 'post_title' => sanitize_text_field($data[0]), 'post_name' => sanitize_title($slug), 'post_content' => wp_kses_post($data[1]), 'post_status' => 'publish', 'post_type' => 'page' ]; // Insert the page and store its ID $page_id = wp_insert_post($page); $page_ids["{$slug}_page_id"] = $page_id; } } // Store page IDs in the database if pages were created if (!empty($page_ids)) { add_option('ace_auto_page_create', $page_ids); } // Add custom rewrite rules self::custom_rewrite_rule(); // Flush rewrite rules after activation flush_rewrite_rules(); } /** * Custom rewrite rule for reset password page. */ public static function custom_rewrite_rule() { add_rewrite_rule( '^ace-confirm-password/([a-f0-9]{32,64})/?$', // Capture the reset code (hash) 'index.php?pagename=ace-confirm-password&randNum=$matches[1]', // Map the reset code to a query var 'top' ); } }