wp_set_all_user_settings

函数
wp_set_all_user_settings ( $user_settings )
Access
Private
参数
  • (array) $user_settings User settings.
    Required:
返回值
  • (bool|null) True if set successfully, false if the current user could not be found. Null if the current user is not a member of the site.
定义位置
相关方法
get_all_user_settingsdelete_all_user_settingsset_user_settingwp_user_settingsget_user_setting
引入
2.8.0
弃用
-

wp_set_all_user_settings: 这是一个WordPress的函数,用于设置一个用户的所有用户设置。它允许你设置各种用户选项,如用户的时区、日期格式等。

隐私。设置所有的用户界面设置。

function wp_set_all_user_settings( $user_settings ) {
	global $_updated_user_settings;

	$user_id = get_current_user_id();
	if ( ! $user_id ) {
		return false;
	}

	if ( ! is_user_member_of_blog() ) {
		return;
	}

	$settings = '';
	foreach ( $user_settings as $name => $value ) {
		$_name  = preg_replace( '/[^A-Za-z0-9_-]+/', '', $name );
		$_value = preg_replace( '/[^A-Za-z0-9_-]+/', '', $value );

		if ( ! empty( $_name ) ) {
			$settings .= $_name . '=' . $_value . '&';
		}
	}

	$settings = rtrim( $settings, '&' );
	parse_str( $settings, $_updated_user_settings );

	update_user_option( $user_id, 'user-settings', $settings, false );
	update_user_option( $user_id, 'user-settings-time', time(), false );

	return true;
}

常见问题

FAQs
查看更多 >