mirror of
https://github.com/inretio/WordPress-Plugin-Boilerplate
synced 2024-12-22 11:53:53 +02:00
Updating the plugin URL and the plugin DIR to use native WordPress API functions (rather than constants)
This commit is contained in:
parent
cf819ba002
commit
c0b6b8f9ca
1 changed files with 11 additions and 11 deletions
18
plugin.php
18
plugin.php
|
@ -145,16 +145,16 @@ class PluginName {
|
|||
*/
|
||||
private function register_scripts_and_styles() {
|
||||
if ( is_admin() ) {
|
||||
$this->load_file( self::slug . '-admin-script', plugin_dir_path(__FILE__) . '/js/admin.js', true );
|
||||
$this->load_file( self::slug . '-admin-styles', plugin_dir_path(__FILE__) . '/css/admin.css' );
|
||||
$this->load_file( self::slug . '-admin-script', '/js/admin.js', true );
|
||||
$this->load_file( self::slug . '-admin-style', '/css/admin.css' );
|
||||
} else {
|
||||
$this->load_file( self::slug . '-scripts', plugin_dir_path(__FILE__) . '/js/display.js', true );
|
||||
$this->load_file( self::slug . '-styles', plugin_dir_path(__FILE__) . '/css/display.css' );
|
||||
$this->load_file( self::slug . '-script', '/js/widget.js', true );
|
||||
$this->load_file( self::slug . '-style', '/css/widget.css' );
|
||||
} // end if/else
|
||||
} // end register_scripts_and_styles
|
||||
|
||||
/**
|
||||
* Helper function for registering and loading scripts and styles.
|
||||
* Helper function for registering and enqueueing scripts and styles.
|
||||
*
|
||||
* @name The ID to register with WordPress
|
||||
* @file_path The path to the actual file
|
||||
|
@ -162,12 +162,12 @@ class PluginName {
|
|||
*/
|
||||
private function load_file( $name, $file_path, $is_script = false ) {
|
||||
|
||||
$url = WP_PLUGIN_URL . $file_path;
|
||||
$file = WP_PLUGIN_DIR . $file_path;
|
||||
$url = plugins_url($file_path, __FILE__);
|
||||
$file = plugins_dir_path(__FILE__) . $file_path;
|
||||
|
||||
if( file_exists( $file ) ) {
|
||||
if( $is_script ) {
|
||||
wp_register_script( $name, $url );
|
||||
wp_register_script( $name, $url, array('jquery') );
|
||||
wp_enqueue_script( $name );
|
||||
} else {
|
||||
wp_register_style( $name, $url );
|
||||
|
@ -175,7 +175,7 @@ class PluginName {
|
|||
} // end if
|
||||
} // end if
|
||||
|
||||
} // end _load_file
|
||||
} // end load_file
|
||||
|
||||
} // end class
|
||||
// TODO: update the instantiation call of your plugin to the name given at the class definition
|
||||
|
|
Loading…
Reference in a new issue