函数文档

_device_can_upload()

💡 云策文档标注

概述

_device_can_upload() 函数用于检测当前设备是否具备文件上传能力,主要针对移动设备进行判断,返回布尔值。

关键要点

  • 函数返回布尔值,表示设备是否能上传文件
  • 非移动设备(通过 wp_is_mobile() 判断)默认返回 true
  • 对于 iOS 设备(iPhone、iPad、iPod),检查用户代理字符串中的 OS 版本是否大于等于 6
  • 其他移动设备默认返回 true

代码示例

function _device_can_upload() {
    if ( ! wp_is_mobile() ) {
        return true;
    }

    $ua = $_SERVER['HTTP_USER_AGENT'];

    if ( str_contains( $ua, 'iPhone' )
        || str_contains( $ua, 'iPad' )
        || str_contains( $ua, 'iPod' ) ) {
            return preg_match( '#OS ([d_]+) like Mac OS X#', $ua, $version ) && version_compare( $version[1], '6', '>=' );
    }

    return true;
}

注意事项

  • 函数依赖于 wp_is_mobile() 和用户代理字符串检测,可能受设备或浏览器设置影响
  • 自 WordPress 3.4.0 版本引入
  • 相关函数包括 media_upload_form()、wp_plupload_default_settings() 和 wp_print_media_templates()

📄 原文内容

Tests if the current device has the capability to upload files.

Return

bool Whether the device is able to upload files.

Source

function _device_can_upload() {
	if ( ! wp_is_mobile() ) {
		return true;
	}

	$ua = $_SERVER['HTTP_USER_AGENT'];

	if ( str_contains( $ua, 'iPhone' )
		|| str_contains( $ua, 'iPad' )
		|| str_contains( $ua, 'iPod' ) ) {
			return preg_match( '#OS ([d_]+) like Mac OS X#', $ua, $version ) && version_compare( $version[1], '6', '>=' );
	}

	return true;
}

Changelog

Version Description
3.4.0 Introduced.