【问题标题】:Change Wordpress schedule post dropdown options更改 Wordpress 计划发布下拉选项
【发布时间】:2019-04-03 17:13:05
【问题描述】:

在任何地方都找不到解决方案。我已经链接了图片:Image here

我想删除该月之前的号码。我不知道这是在哪里生成的——我浏览了代码库没有成功。

它不需要大的改变,我只是不想要日期之前的数字。例如,我想要:“Aug”而不是“08-Aug”。

提前感谢任何可以帮助解决问题的人!

【问题讨论】:

  • 我不确定这是可配置的,你永远不应该编辑核心代码。它似乎是由the get_month_choices function 生成的。您可能能够滥用翻译系统来设置您自己的自定义翻译,因为它的值是通过__() 函数运行的。不过,我怀疑这是否值得。

标签: javascript php wordpress options


【解决方案1】:

正如有人在评论中所说,您永远不应该编辑核心代码。

这是被调用函数的源代码。

public function get_month_choices() {
global $wp_locale;
$months = array();
for ( $i = 1; $i < 13; $i++ ) {
    $month_text = $wp_locale->get_month_abbrev( $wp_locale->get_month( $i ) );

    /* translators: 1: month number (01, 02, etc.), 2: month abbreviation */
    $months[ $i ]['text'] = sprintf( __( '%1$s-%2$s' ), $i, $month_text );
    $months[ $i ]['value'] = $i;
}
return array(
    'month_choices' => $months,
);
}

您在这里看到的是 __() 函数内部的 sprintf() 函数调用中的 %1$s 是生成该数字的原因。您可以使用默认参数扩展函数 get_month_choices(),该默认参数是默认为 false 的布尔值。这样,每当核心 WP 调用此函数时,它将正常运行,因为核心 WP 期望此函数不接受任何值 - 因此,当它没有得到争论时,如果该布尔值为 false(默认情况下),它将正常运行。如果那个布尔值是真的,那么你就可以按照你想要的方式使用函数“函数”。

免责声明: 我没有使用 wordpress 的经验。

例如,您可以将上述来源更改为:

public function get_month_choices($foo = False) {
global $wp_locale;
$months = array();
for ( $i = 1; $i < 13; $i++ ) {
    $month_text = $wp_locale->get_month_abbrev( $wp_locale->get_month( $i ) );

    /* translators: 1: month number (01, 02, etc.), 2: month abbreviation */

    if(!$foo) {
    $months[ $i ]['text'] = sprintf( __( '%1$s-%2$s' ), $i, $month_text );
    $months[ $i ]['value'] = $i;
    } 
/*Your functionality here*/
else {
    $months[ $i ]['text'] = sprintf( __( '%1$s%2$s' ), "", $month_text );
    $months[ $i ]['value'] = $i;
}

}
return array(
    'month_choices' => $months,
);
}

再说一次,我没有使用 wordpress 的经验,你不应该编辑核心代码。但这是你可以做的。我也没有测试过。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-05-17
    • 1970-01-01
    • 1970-01-01
    • 2020-02-06
    • 2013-07-12
    • 2023-03-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多