我无法将一个职位的年份设置为1899年以下。如果我将年份设置为1899以下,它将自动设置为当前年份。
我已经购买了Timeline主题,并在他们的支持论坛中询问。他们回答说:
这听起来像是您的托管提供商造成的限制。主题中没有任何内容阻止您指定日期–正如您所看到的,演示中的帖子使用了14世纪的日期。试着联系你的托管提供商,看看他们是否对如何解决这个问题有什么见解。
我无法将一个职位的年份设置为1899年以下。如果我将年份设置为1899以下,它将自动设置为当前年份。
我已经购买了Timeline主题,并在他们的支持论坛中询问。他们回答说:
这听起来像是您的托管提供商造成的限制。主题中没有任何内容阻止您指定日期–正如您所看到的,演示中的帖子使用了14世纪的日期。试着联系你的托管提供商,看看他们是否对如何解决这个问题有什么见解。
这并不是一个真正的答案,只是试图找到这个问题的具体背景。请在您的网站上安装以下插件,尝试设置三个日期并将结果添加到第二个日期<pre>
在下表中。
/* Plugin Name: WPSE Sysinfo */
add_action( \'admin_footer\', \'wpse_sysinfo\' );
function wpse_sysinfo() {
$bit = 4 === PHP_INT_SIZE ? 32 : 64; // PHP version, not OS!
$php_version = PHP_VERSION;
$db_version = $GLOBALS[\'wpdb\']->db_version();
print "<pre>$bit | $php_version | $db_version</pre>";
}
Gist of the Plugin can be checked out here.OS | OS bit | PHP | PHP Bit | MySQL | 999 | 1899 | 2020 | 2039 | user
WIN7 | 64 | 5.4.4 | ?? | 5.5.25 | ✘ | ✘ | ✔ | ✘ | toscho Linux | ?? | 5.3.18-nmm1 | ?? | 5.1.70 | ✔ | ✔ | ✔ | ✔ | toscho CentOS 6 | 64 | 5.5.4 | ?? | 5.0.95 | ✔ | ✔ | ✔ | ✔ | toscho WIN7 | 64 | 5.4.15 | 32 | 5.5.31 | ✘ | ✘ | ✔ | ✘ | rarst Ubuntu 12.04 | 64 | 5.3.10-1 | 64 | 5.5.32 | ✔ | ✔ | ✔ | ✔ | Pille CloudLinux | 64 | 5.2.17 | 64 | 5.0.96 | ✔ | ✔ | ✔ | ✔ | Pille Ubuntu 12.10 | 64 | 5.4.6 | 64 | 5.5.32 | ✔ | ✔ | ✔ | ✔ | Michael Ecklund CENTOS 5.9 | 32 | 5.3.27 | 32 | 5.5.32 | ✘ | ✘ | ✔ | ✘ | Michael Ecklund WIN7 | 64 | 5.4.7 | 64 | 5.5.27 | ✘ | ✘ | ✔ | ✘ | kaiser OSX 10.7.5 | 64 | 5.3.6 | 64 | 5.5.9 | ✔ | ✔ | ✔ | ✔ | GhostToast Centos 6.4 | 64 | 5.4.17 | 32 | 5.1.59 | ✘ | ✘ | ✔ | ✘ | birgire Debian 6 | 64 | 5.4.19 | 64 | 5.1.66 | ✘ | ✘ | ✔ | ✘ | birgire WIN7 | 64 | 5.5.0 | 64 | 5.5.22 | ✘ | ✘ | ✔ | ✘ | G.M. OSX 10.7.4 | 64 | 5.3.6 | 64 | 5.5.9 | ✔ | ✔ | ✔ | ✔ | brasofilo CentOS 5 | 64 | 5.3.22 | 64 | 5.1.68 | ✔ | ✔ | ✔ | ✔ | brasofilo Mac 10.8.5 | 64 | 5.3.26 | 64 | 5.5.25 | ✔ | ✔ | ✔ | ✔ | flentini WIN7 | 64 | 5.3.27 | 64 | 5.5.31 | ✔ | ✔ | ✔ | ✔ | Sascha Krause Win7SP1 | 64 | 5.3.8 | 64 | 5.5.28 | ✔ | ✔ | ✔ | ✔ | Manuel Sychold<创建新帖子。保存它0999, 单击更新。是否保存或更改为当前日期1899,
2020
和2039
.自WordPress最初作为博客引擎出现以来,从上下文的角度来看,它逐渐发展为处理以下时间跨度:
WP存在的日期(显然能够使用它)
为了研究的目的,我提出了以下问题:
最早和最晚的两个完整日历年是哪两个,可以与WordPress发布日期本地可靠地结合使用
post_date
第列,共列DATETIME
键入MySQL。根据documentation 此类型支持年1000 to 9999:
这个DATETIME
类型用于同时包含日期和时间部分的值。MySQL检索并显示DATETIME
中的值\'YYYY-MM-DD HH:MM:SS\'
总体安排支持的范围为\'1000-01-01 00:00:00\'
到\'9999-12-31 23:59:59\'
.
然而,它也表示早期的值可能会起作用,没有提及后来的值:
对于DATE and DATETIME
范围描述,“支持”意味着,尽管早期的值可能有效,但无法保证。
虽然根据经验,我观察到数值超出了工作范围,但这只是一个轶事,不符合我们的可靠性条件。
时间戳的有效范围通常为Fri, 13 Dec 1901 20:45:54 UTC
到Tue, 19 Jan 2038 03:14:07 UTC
. (这些日期对应于32位有符号整数的最小值和最大值。)此外,并非所有平台都支持负时间戳,因此您的日期范围可能被限制为不早于Unix纪元。这意味着,例如,日期早于Jan 1, 1970
无法在Windows、某些Linux发行版和其他一些操作系统上运行。PHP 5.1.0和更新版本克服了这一限制。
除了那个更新的Date/Time
基于的处理为64位,具有范围roughly -292 billion to 292 billion years, 这可能超过了人类目前的需求。
编辑后表格中输入的日期必须正确处理并保存在数据库中。保存在数据库中的日期必须正确读取并显示在界面中。请注意,这些在技术上是完全不同和独立的过程。正如进一步解释的,它们的范围不重叠,保存正确的日期并不等于在WordPress环境中正确读取日期。
_wp_translate_postdata()
处理年份(以与表格不同的数字提交),并将其净化为非负数>0wp_checkdate()
, 它调用PHP本机checkdate()
, 限制1 to 32767strtotime()
PHP函数被多次使用,并受上述Unix时间戳的约束,处于中的最低级别mysql2date()
这会影响数据库中日期的所有读取,1902 to 2037 WordPress返回正则表达式进行日期分析get_gmt_from_date()
, 预计今年([0-9]{1,4})
, 限制它1 to 9999, 很可能在其他功能中进行类似的处理,这将需要更彻底的代码审计来枚举解决方法的可能性wp_checkdate()
有wp_checkdate
过滤器,允许覆盖针对最终用户的此验证检查date_i18n()
其中date_i18n
过滤器,理论上允许完全截取和重新处理接口的日期输出,但如果函数已超出范围,则具有挑战性(false
) 时间戳输入结论对于实际目的和数据的可移植性WordPress post日期范围似乎equal to that of 32 bit Unix timestamp and consist of years 1902 to 2037 inclusively.对于任何超出此范围的后期操作,必须审核环境(64位Unix时间戳范围、实际运行的MySQL或值的备用数据库存储)。用于更远的范围(below 1000, above 9999) 可能需要大量的自定义代码。
对于任意日期的任何实施,有必要:
将它们以不受数据库限制的格式存储在MySQL中Date/Time
-基于代码和/或WordPress功能,经审核不受Unix时间戳限制的影响,代码测试台使用以下代码和手工挑选的年份集进行上述研究和结论测试:
require ABSPATH . \'/wp-admin/includes/post.php\';
$timestamp_size_info = array(
\'PHP_INT_SIZE\' => PHP_INT_SIZE,
\'PHP_INT_MAX\' => number_format( PHP_INT_MAX ),
\'min timestamp\' => date( DATE_ISO8601, - PHP_INT_MAX ),
\'zero timestamp\' => date( DATE_ISO8601, 0 ),
\'max timestamp\' => date( DATE_ISO8601, PHP_INT_MAX ),
);
r( $timestamp_size_info );
// hand picked set of years to test for assorted limits
$years = array(
\'negative\' => - 1,
\'zero\' => 0,
\'one\' => 1,
\'wp min\' => 100,
\'mysql first\' => 1000,
\'before unix\' => 1899,
\'unix first\' => 1902,
\'current\' => 2013,
\'unix last\' => 2037,
\'after unix\' => 2039,
\'mysql last, wp max\' => 9999,
\'after checkdate\' => 33000,
);
// simulates form submission data
$post = array(
\'post_type\' => \'post\', // shut notice
\'edit_date\' => 1,
\'aa\' => 1,
\'mm\' => \'01\',
\'jj\' => \'01\',
\'hh\' => \'00\',
\'mn\' => \'00\',
\'ss\' => \'00\',
);
// add_filter( \'wp_checkdate\', \'__return_true\' );
foreach ( $years as $name => $year ) {
$post[\'aa\'] = $year;
$translated = _wp_translate_postdata( false, $post );
if ( is_wp_error( $translated ) ) { // wp_checkdate() failed
r( array( \'year\' => $year . " ({$name})", \'translated valid\' => false ) );
}
else {
$post_date = $translated[\'post_date\'];
$post_date_gmt = $translated[\'post_date_gmt\'];
$translated_valid = (string) $year == substr( $post_date, 0, strpos( $post_date, \'-\' ) );
$mysql2date = mysql2date( DATE_ISO8601, $post_date );
$mysql2date_valid = (string) $year == substr( $mysql2date, 0, strpos( $mysql2date, \'-\' ) );
r( array(
\'year\' => $year . " ({$name})",
\'post_date\' => $post_date,
\'translated valid\' => $translated_valid,
\'post_date_gmt\' => $post_date_gmt,
\'mysql2date\' => $mysql2date,
\'from sql valid\' => $mysql2date_valid,
) );
}
}
我有一个函数可以在一个页面上显示媒体库中的所有图像。我想显示每个图像的日期,但使用get\\u the\\u date()只返回今天的日期。下面是我使用的代码:function get_images_from_media_library() { $args = array( \'post_type\' => \'attachment\', \'post_mime_type\' =>\'image\', \'post_status\' =&