/** * Handle an Ajax request for a password, print response. * * Uses wp_generate_password(), a pluggable function within the WordPress core. * * @since 1.0 */ function wp_password_generator_generate() { $opts = get_option('wp-password-generator-opts', false); if (!$opts || $opts['version'] < WP_PASSWORD_GENERATOR_VERSION) { // No options or an older version wp_password_generator_install(); $opts = get_option('wp-password-generator-opts', false); } $len = mt_rand($opts['min-length'], $opts['max-length']); // Min/max password lengths // Allow to modify the args supplied to wp_generate_password $args = array('length' => $len, 'special_chars' => true, 'extra_special_chars' => false); /** * Filter arguments being passed to wp_generate_password(). * * @param array $args The $length, $special_chars, and $extra_special_chars arguments for * the wp_generate_password() function. * @param array $opts Plugin options stored in the options table. */ echo call_user_func_array('wp_generate_password', apply_filters('wp_password_generator_args', $args, $opts)); exit; }
/** * Handle an Ajax request for a password, print response. * Uses wp_generate_password(), a pluggable function within the WordPress core * * @return void (echoes password) * @uses get_option() * @uses wp_generate_password() * @uses wp_password_generator_install() * @since 1.0 */ function wp_password_generator_generate() { $opts = get_option('wp-password-generator-opts', false); if (!$opts || $opts['version'] < WP_PASSWORD_GENERATOR_VERSION) { // No options or an older version wp_password_generator_install(); $opts = get_option('wp-password-generator-opts', false); } $len = mt_rand($opts['min-length'], $opts['max-length']); // Min/max password lengths // Allow to modify the args supplied to wp_generate_password $args = array('length' => $len, 'special_chars' => true, 'extra_special_chars' => false); print call_user_func_array('wp_generate_password', apply_filters('wp_password_generator_args', $args, $opts)); exit; }