PHP可变范围问题

时间:2010-08-08 21:01:09

标签: php wordpress-plugin

我正在为WordPress编写一个插件,但我似乎无法让我的旗帜继续下去。它让我疯了!这是没有类包装器的代码:

static $js_flag;

function init() 
{
    add_shortcode('jw_html5', array(__CLASS__, 'jw_html5_shortcode'));
    add_action('init', array(__CLASS__, 'jw_add_js' ));
}

public function jw_html5_shortcode( $atts, $content = null ) 
{

    self::$js_flag = true;
    $vid = '';

    extract( shortcode_atts( array(
        'src' => '/vids/video.mp4',
        'width' => 480,
        'height' => 320
        ), $atts ) );

    $vid = "<video id='player' src='$src' width='$width' height='$height' type='video/mp4'> </video>";

    return self::$js_flag;
    //return $vid;
}


public function jw_add_js()
{


    if(self::$js_flag)
    {
        wp_register_script('jw_player', plugins_url('scripts/player.php', __FILE__), array('jquery'), '.01', true);
        wp_register_script('jw_player_script', plugins_url('scripts/jquery.jwplayer.js', __FILE__), array('jquery'), '.01', false);
        wp_register_script('jw_playlist', plugins_url('scripts/jquery.playlist.js', __FILE__), array('jquery'), '.01', false);

        wp_enqueue_script('jw_player_script');
        wp_enqueue_script('jw_playlist');
        wp_enqueue_script('jquery');
        wp_enqueue_script('jw_player');
    }   


}

我在短代码函数中设置了标志,但它没有将它传递给jw_add_js()函数。在WP中调试它是一种婊子。任何建议都会受到超级赞赏。

更新:我在弄乱之后找到了答案。我必须注册我的脚本,然后将句柄存储在一个数组中。然后我用wp_print_scripts()方法传递数组。希望这会对某人有所帮助!

1 个答案:

答案 0 :(得分:0)

在弄乱之后我找到了答案。我必须注册我的脚本,然后将句柄存储在一个数组中。然后我用wp_print_scripts()方法传递数组。希望这会对某人有所帮助!