_wp_timezone_choice_usort_callback

函数
_wp_timezone_choice_usort_callback ( $a, $b )
Access
Private
参数
  • (array) $a
    Required:
  • (array) $b
    Required:
返回值
  • (int)
定义位置
相关方法
wp_timezone_choicewp_check_jsonp_callbackwp_timezone_override_offset_wp_object_count_sort_cbwp_timezone_supported
引入
2.9.0
弃用
-

_wp_timezone_choice_usort_callback: 这个函数是一个回调函数,用来对WordPress中的时区选择按UTC偏移进行排序。

时区的排序帮助器。

function _wp_timezone_choice_usort_callback( $a, $b ) {
	// Don't use translated versions of Etc.
	if ( 'Etc' === $a['continent'] && 'Etc' === $b['continent'] ) {
		// Make the order of these more like the old dropdown.
		if ( 'GMT+' === substr( $a['city'], 0, 4 ) && 'GMT+' === substr( $b['city'], 0, 4 ) ) {
			return -1 * ( strnatcasecmp( $a['city'], $b['city'] ) );
		}
		if ( 'UTC' === $a['city'] ) {
			if ( 'GMT+' === substr( $b['city'], 0, 4 ) ) {
				return 1;
			}
			return -1;
		}
		if ( 'UTC' === $b['city'] ) {
			if ( 'GMT+' === substr( $a['city'], 0, 4 ) ) {
				return -1;
			}
			return 1;
		}
		return strnatcasecmp( $a['city'], $b['city'] );
	}
	if ( $a['t_continent'] == $b['t_continent'] ) {
		if ( $a['t_city'] == $b['t_city'] ) {
			return strnatcasecmp( $a['t_subcity'], $b['t_subcity'] );
		}
		return strnatcasecmp( $a['t_city'], $b['t_city'] );
	} else {
		// Force Etc to the bottom of the list.
		if ( 'Etc' === $a['continent'] ) {
			return 1;
		}
		if ( 'Etc' === $b['continent'] ) {
			return -1;
		}
		return strnatcasecmp( $a['t_continent'], $b['t_continent'] );
	}
}

常见问题

FAQs
查看更多 >