当用户激活插件时,我想用正确的翻译存储我的自定义帖子。
$a_custom_post = array(
\'post_type\' => "foo-page",
\'post_status\' => \'publish\',
\'post_title\' => __( \'Foo page name\', PLUGIN_DOMAIN ),
\'post_content\' => "",
\'comment_status\' => \'closed\',
\'ping_status\' => \'closed\',
\'post_author\' => 1,
\'guid\' => null
);
wp_insert_post( $a_custom_post, true);
我该怎么做?
最合适的回答,由SO网友:J.BizMai 整理而成
我找到了解决办法!问题是我只在加载插件时加载插件域,而不是为激活插件加载插件。
它解决了我的问题。。。
MyPLugin.php
class WPGroupSubs {
public function __construct(){
// Install needed components on plugin activation
/* need to add this */
register_activation_hook( __FILE__, array( $this, \'load_text_domain\' ) );
register_activation_hook( __FILE__, array( $this, \'install\' ) );
//Translation when plugins are loaded
add_action( \'plugins_loaded\', array( $this, \'load_text_domain\' ) );
...
}
public function load_text_domain(){
load_plugin_textdomain( $this->domain, false, plugin_basename( dirname( __FILE__ ) ) . \'/translations\' );
}
}