使用wp_localize_脚本将短代码$atts从PHP传递到Javascript

使用wp_localize_脚本将短代码$atts从PHP传递到Javascript,php,javascript,wordpress,shortcode,Php,Javascript,Wordpress,Shortcode,我想使用Wordpress'wp\u localize\u script来传递javascript脚本可用的快捷码$atts 似乎wp\u localize\u script仅在引用脚本的同一功能中工作 我在另一个函数中访问快捷码$atts function csf_enqueue () { //other enqueued scripts wp_enqueue_script( 'csf_script_jquery', plugins_url( 'js/path/to/file', __FI

我想使用Wordpress'
wp\u localize\u script
来传递javascript脚本可用的快捷码
$atts

似乎
wp\u localize\u script
仅在引用脚本的同一功能中工作

我在另一个函数中访问快捷码
$atts

function csf_enqueue () {

//other enqueued scripts

wp_enqueue_script( 'csf_script_jquery', plugins_url( 'js/path/to/file', __FILE__ ), array ( 'jquery', 'jquery-ui-core') );

    $myvars = array('value' => 'one');
    wp_localize_script('csf_map_script_jquery', 'myVars', $myvars);
}
我想用短代码“
$atts
替换
$myvars

function csf_shortcode_ajax_frontend( $atts, $content = null ) {

      $atts = shortcode_atts( array ( 
      'width'=> 600,
      'height'=> 400,
      'myinfo' => 'blah'
      ), $atts );  

//continues
}
我添加了如下短代码

add_shortcode("csf_map", "csf_shortcode_ajax_frontend");
csf\u shortcode\u ajax\u frontend()
中,我访问短代码
$atts

function csf_shortcode_ajax_frontend( $atts, $content = null ) {

      $atts = shortcode_atts( array ( 
      'width'=> 600,
      'height'=> 400,
      'myinfo' => 'blah'
      ), $atts );  

//continues
}

当wp_localize_脚本(?)包含
wp_enequeue_脚本
行时,如何在包含
wp_localize_脚本的函数中访问shortcode
$atts
,最好在csf_shortcode\u ajax\u前端()中创建一个选项字段,并使用update\u选项(“this\u is\u is\u field”,$atts)然后在调用wp_localize_script()钩子时访问csf_enqueue()中相同的数据库选项字段?

在csf_shortcode_ajax_frontend()中创建一个带有update_选项的选项字段(“this_is_a_field”,$atts),然后在调用wp_localize_script()时访问csf_enqueue()中相同的数据库选项字段不是最好吗钩子

然后提取函数中的ATT

extract($atts);
希望这对你有用。 祝你好运

然后提取函数中的ATT

extract($atts);
希望这对你有用。 祝你好运