如果你调查/wp-admin/edit-form-advanced.php
, 您将找到元框:
add_meta_box(\'submitdiv\', __(\'Publish\'), \'post_submit_meta_box\', $post_type, \'side\', \'core\');
请注意
__(\'Publish\')
– 功能
__()
导致
translate()
从哪里获得过滤器
\'gettext\'
.
有两种方法可以解决您的问题:1。在单个专用函数中寻址字符串(确保匹配正确的textdomain!)或者2。使用更通用的方法。
@Rarst刚刚发布了版本1,所以我将添加版本2.)
<?php
/*
Plugin Name: Retranslate
Description: Adds translations.
Version: 0.1
Author: Thomas Scholz
Author URI: http://toscho.de
License: GPL v2
*/
class Toscho_Retrans {
// store the options
protected $params;
/**
* Set up basic information
*
* @param array $options
* @return void
*/
public function __construct( array $options )
{
$defaults = array (
\'domain\' => \'default\'
, \'context\' => \'backend\'
, \'replacements\' => array ()
, \'post_type\' => array ( \'post\' )
);
$this->params = array_merge( $defaults, $options );
// When to add the filter
$hook = \'backend\' == $this->params[\'context\']
? \'admin_head\' : \'template_redirect\';
add_action( $hook, array ( $this, \'register_filter\' ) );
}
/**
* Conatiner for add_filter()
* @return void
*/
public function register_filter()
{
add_filter( \'gettext\', array ( $this, \'translate\' ), 10, 3 );
}
/**
* The real working code.
*
* @param string $translated
* @param string $original
* @param string $domain
* @return string
*/
public function translate( $translated, $original, $domain )
{
// exit early
if ( \'backend\' == $this->params[\'context\'] )
{
global $post_type;
if ( ! empty ( $post_type )
&& ! in_array( $post_type, $this->params[\'post_type\'] ) )
{
return $translated;
}
}
if ( $this->params[\'domain\'] !== $domain )
{
return $translated;
}
// Finally replace
return strtr( $original, $this->params[\'replacements\'] );
}
}
// Sample code
// Replace \'Publish\' with \'Save\' and \'Preview\' with \'Lurk\' on pages and posts
$Toscho_Retrans = new Toscho_Retrans(
array (
\'replacements\' => array (
\'Publish\' => \'Save\'
, \'Preview\' => \'Lurk\'
)
, \'post_type\' => array ( \'page\', \'post\' )
)
);
您不需要将代码用作插件。将其包含在主题的功能中。php就足够了。
更新要删除原始的保存按钮(不确定“草稿”按钮是什么),请向函数中添加以下代码。php/a插件:
add_action( \'admin_print_footer_scripts\', \'remove_save_button\' );
function remove_save_button()
{
?>
<script>
jQuery(document).ready(function($){$(\'#save-post\').remove();});
</script><?php
}
是的,很难看。