我也是法国人,但我必须用英语回答。您需要使用wp\\u localize\\u script(),它允许在js脚本中处理本地化。
add_action(\'wp_enqueue_scripts\', \'load_script\');
function load_script(){
wp_register_script( \'popup\', plugins_url(\'yourscript/js/yourjs.js\'), array( \'jquery\' ), false, true );
wp_localize_script(
\'popup\',
\'popUp\',
array(
\'popupTitle\'=> __(\'\', \'your-text-domain)
)
);
wp_enqueue_script(\'popup\');
}
在js文件中,您将能够检索值:
function save_image($id){
var mediaUploader;
event.preventDefault();
// If the uploader object has already been created, reopen the dialog
if (mediaUploader) {
mediaUploader.open();
return;
}
// Extend the wp.media object
var popupTitle = popUp.popupTitle;
mediaUploader = wp.media.frames.file_frame = wp.media({
title: popupTitle,
button: {
text: popupTitle
},
multiple: false,
type: \'image\'
});
// When a file is selected, grab the URL and set it as the text field\'s value
mediaUploader.on(\'select\', function() {
attachment = mediaUploader.state().get(\'selection\').first().toJSON();
});
// Open the uploader dialog
mediaUploader.open();
}
https://codex.wordpress.org/Function_Reference/wp_localize_script
您可以安装插件WordPress Media Javascript指南。它通过屏幕截图和示例说明了wp必须使用的方法。媒体对象。
只需一个片段即可更改按钮文本和标题:
wp_register_script( \'media-bbss-uploader-js\', BBSSLIDERS_DIR_URL .\'/js/bbss-multiple-media-upload.js\', array(\'jquery\') );
wp_localize_script(
\'media-bbss-uploader-js\',
\'screenHelp\',
array(
\'title\' => __(\'Select or upload new slides\', $this->plugin_text_domain),
\'buttomText\' => __(\'Add slides\', $this->plugin_text_domain),
)
);
wp_enqueue_script( \'media-bbss-uploader-js\' );