0

我希望能够使用带有hook.

我已经实现了以下脚本,但它仍然无法工作:

class media{
    public function loadScripts($scripts){var_dump($scripts);
        foreach($scripts as $script){var_dump($script);
            wp_enqueue_script( $script['name'], plugins_url().$script['path'] ); 
        }
    }

    public function loadStyles($styles){
        foreach($styles as $style){
            wp_register_style($style['name'], plugins_url().$style['path']);
            wp_enqueue_style($style['name'], plugins_url().$style['path']);
        }
    }
}

$media = new media();
$scripts = array(
    array('name' => 'jquery1', 'path' => '/content-type/js/jquery.min.js'),
    array('name' => 'videos_js', 'path' => '/content-type/js/videos.js')
);

add_action('wp_print_scripts', 'loadScripts',10,1);
do_action('wp_print_scripts',$scripts);

我该如何解决 ?

4

1 回答 1

1

尝试这个

 add_action('wp_print_scripts', array('media','loadScripts'),10,1);
于 2012-08-06T15:35:21.597 回答