正如有人在评论中所说,您永远不应该编辑核心代码。
这是被调用函数的源代码。
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 的经验,你不应该编辑核心代码。但这是你可以做的。我也没有测试过。