我无法使用plugin_dir_path( __FILE__ )
在wordpress中获取我的插件网址
该函数返回没有斜杠的URL。像下面一样
F:INSTALLEDXAMPPhtdocswordpresswp-contentpluginssubscribe /
if ( !function_exists( 'add_action' ) ) {
echo 'Hi there! I\'m just a plugin, not much I can do when called directly.';
}
define( 'PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
include_once(PLUGIN_DIR."/includes/admin/widget-class.php");
function enqueue_scripts(){
wp_enqueue_style( 'bootstrap', 'https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css', array() ); //bootstrap CSS
wp_enqueue_script( 'bootstrap', 'https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js', array('jquery'), null, true ); //bootstrap js
wp_enqueue_script( 'sub_subscribe', PLUGIN_DIR.'js/subscribe.js', array('jquery'),null ,true );
// this is where I'm getting a the wrong path of the plugin
$ajax_url = admin_url( 'admin-ajax.php' );
// localize script
wp_localize_script( 'sub_subscribe', 'ajax_url', $ajax_url );
}
add_action( 'wp_enqueue_scripts', 'enqueue_scripts' );
这是我得到的错误
(索引):182 GET http://localhost/wordpressF:INSTALLEDXAMPPhtdocswordpresswp-contentpluginssubscribe/js/subscribe.js 403(禁止访问)