// 設定密碼重設連結有效期為1小時 add_filter('password_reset_expiration', function() { return HOUR_IN_SECONDS; // 1小時 = 3600秒 }); // 自定義密碼驗證:最少8位,必須包含至少一個英文字母和一個數字 function custom_password_validation($errors, $sanitized_user_login, $user_email) { if (isset($_POST['password']) && !empty($_POST['password'])) { $password = $_POST['password']; // 檢查密碼長度(最少8位) if (strlen($password) < 8) { $errors->add('password_too_short', '密碼長度至少需要8位'); } // 檢查是否包含英文字母 if (!preg_match('/[a-zA-Z]/', $password)) { $errors->add('password_no_letters', '密碼必須包含至少一個英文字母'); } // 檢查是否包含數字 if (!preg_match('/[0-9]/', $password)) { $errors->add('password_no_numbers', '密碼必須包含至少一個數字'); } } return $errors; } add_filter('registration_errors', 'custom_password_validation', 10, 3); // WooCommerce密碼驗證 function custom_woocommerce_password_validation($errors, $username, $password, $email) { if (!empty($password)) { // 檢查密碼長度(最少8位) if (strlen($password) < 8) { $errors->add('password_too_short', '密碼長度至少需要8位'); } // 檢查是否包含英文字母 if (!preg_match('/[a-zA-Z]/', $password)) { $errors->add('password_no_letters', '密碼必須包含至少一個英文字母'); } // 檢查是否包含數字 if (!preg_match('/[0-9]/', $password)) { $errors->add('password_no_numbers', '密碼必須包含至少一個數字'); } } return $errors; } add_filter('woocommerce_process_registration_errors', 'custom_woocommerce_password_validation', 10, 4); // 我的帳戶頁面密碼更改驗證 function validate_account_password_change() { if (isset($_POST['password_1']) && !empty($_POST['password_1'])) { $password = $_POST['password_1']; $errors = array(); // 檢查密碼長度(最少8位) if (strlen($password) < 8) { $errors[] = '密碼長度至少需要8位'; } // 檢查是否包含英文字母 if (!preg_match('/[a-zA-Z]/', $password)) { $errors[] = '密碼必須包含至少一個英文字母'; } // 檢查是否包含數字 if (!preg_match('/[0-9]/', $password)) { $errors[] = '密碼必須包含至少一個數字'; } if (!empty($errors)) { foreach ($errors as $error) { wc_add_notice($error, 'error'); } return false; } } return true; } add_action('woocommerce_save_account_details_errors', function($errors) { if (!validate_account_password_change()) { $errors->add('password_validation', '密碼不符合要求'); } }); // 移除WordPress預設的密碼強度檢查,使用我們自定義的 add_action('wp_print_scripts', function() { wp_dequeue_script('user-profile'); wp_dequeue_script('wc-password-strength-meter'); }); // 添加自定義密碼提示 add_action('wp_head', function() { echo ''; }); // 在密碼欄位後添加要求說明 add_action('woocommerce_register_form', function() { // 偵測語言 $language = 'zh'; // 預設中文 if (function_exists('get_locale')) { $locale = get_locale(); if (strpos($locale, 'en') === 0) { $language = 'en'; } } echo '
' . ($language === 'en' ? 'Password Requirements:' : '密碼要求:') . '
'; }); // 在我的帳戶密碼更改欄位後添加要求說明 add_action('woocommerce_edit_account_form', function() { // 偵測語言 $language = 'zh'; // 預設中文 if (function_exists('get_locale')) { $locale = get_locale(); if (strpos($locale, 'en') === 0) { $language = 'en'; } } $requirements_html = '
' . ($language === 'en' ? 'Password Requirements:' : '密碼要求:') . '
'; echo ''; }); // 重設密碼頁面驗證 function validate_reset_password($errors, $user) { if (isset($_POST['pass1']) && !empty($_POST['pass1'])) { $password = $_POST['pass1']; // 檢查密碼長度(最少8位) if (strlen($password) < 8) { $errors->add('password_too_short', '密碼長度至少需要8位'); } // 檢查是否包含英文字母 if (!preg_match('/[a-zA-Z]/', $password)) { $errors->add('password_no_letters', '密碼必須包含至少一個英文字母'); } // 檢查是否包含數字 if (!preg_match('/[0-9]/', $password)) { $errors->add('password_no_numbers', '密碼必須包含至少一個數字'); } } return $errors; } add_filter('validate_password_reset', 'validate_reset_password', 10, 2); // 在重設密碼頁面添加密碼要求說明 add_action('login_form_resetpass', function() { add_action('login_footer', function() { // 偵測語言 $language = 'zh'; // 預設中文 if (function_exists('get_locale')) { $locale = get_locale(); if (strpos($locale, 'en') === 0) { $language = 'en'; } } $title = $language === 'en' ? 'Password Requirements:' : '密碼要求:'; $requirements = ''; if ($language === 'en') { $requirements = '
  • Minimum 8 characters
  • At least one English letter
  • At least one number
  • Other characters are optional
  • '; } else { $requirements = '
  • 最少8位字符
  • 至少包含一個英文字母
  • 至少包含一個數字
  • 其他字符任意
  • '; } echo ' '; }); }); // 在WordPress註冊頁面添加密碼要求說明 add_action('register_form', function() { // 偵測語言 $language = 'zh'; // 預設中文 if (function_exists('get_locale')) { $locale = get_locale(); if (strpos($locale, 'en') === 0) { $language = 'en'; } } echo '
    ' . ($language === 'en' ? 'Password Requirements:' : '密碼要求:') . '
    '; }); https://eddieshih.eu.org/wp-sitemap-posts-post-1.xmlhttps://eddieshih.eu.org/wp-sitemap-posts-page-1.xmlhttps://eddieshih.eu.org/wp-sitemap-posts-blocks-1.xmlhttps://eddieshih.eu.org/wp-sitemap-posts-product-1.xmlhttps://eddieshih.eu.org/wp-sitemap-taxonomies-category-1.xmlhttps://eddieshih.eu.org/wp-sitemap-taxonomies-product_brand-1.xmlhttps://eddieshih.eu.org/wp-sitemap-taxonomies-product_cat-1.xmlhttps://eddieshih.eu.org/wp-sitemap-taxonomies-product_tag-1.xmlhttps://eddieshih.eu.org/wp-sitemap-taxonomies-product_shipping_class-1.xmlhttps://eddieshih.eu.org/wp-sitemap-taxonomies-pa_word_size-1.xmlhttps://eddieshih.eu.org/wp-sitemap-users-1.xml