我试图在下面的javascript中本地化一个变量。。这种情况是,我希望动态获取post\\u id,并在通过wp\\u enqueue\\u脚本排队的jquery中对其进行本地化。这是我的代码:
function add_scripts() {
wp_enqueue_style(\'jplayercss\',plugins_url( \'skin/jplayer.blue.monday.css\',__FILE__));
wp_enqueue_script( \'jplayer\',plugins_url( \'js/jquery.jplayer.min.js\' , __FILE__ ) );
wp_enqueue_script( \'jplayerjs\',plugins_url( \'js/mfsjplayer.js\',__FILE__), array(\'jquery\') );
}
add_action( \'wp_enqueue_scripts\', \'add_scripts\' );
我在content\\u filter hook的另一个函数中调用它,
function the_content_filter( $content ) {
$post_id = $GLOBALS[\'post\']->ID;
$accessToken = get_option( \'dropbox_api_token\' );
$dbxClient = new dbx\\Client($accessToken, "PHP-Example/1.0");
$file_url_array = $dbxClient->createTemporaryDirectLink( "/recorded_file".$post_id.".wav" );
$file_url = isset( $file_url_array ) ? $file_url_array[0] : \'\';
if ( ! empty( $file_url ) ) {
require("lib/mfs_jplayer_interface.php");
$site_parameters = array(
\'file_url\' => $file_url,
\'plugin_url\' => plugins_url(),
\'theme_directory\' => get_template_directory_uri(),
\'post_id\' => $post_id,
);
$upload_dir = wp_upload_dir();
$upload_loc = $upload_dir[\'baseurl\']."/recorded_files";
wp_localize_script( \'jplayerjs\', \'mfs_var\', $site_parameters );
}
// Add play and record buttons to each post
// Returns the content.
return $content;
}
add_filter( \'the_content\', \'the_content_filter\', 20 );
所以我在控制台中将mfs\\u var作为未定义的变量。请任何人帮我解决这个问题。提前谢谢你。