1
0
Fork 0
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:
Tom McFarlin 2012-01-19 08:25:40 -05:00
parent cf819ba002
commit c0b6b8f9ca

View file

@ -145,37 +145,37 @@ class PluginName {
*/ */
private function register_scripts_and_styles() { private function register_scripts_and_styles() {
if ( is_admin() ) { if ( is_admin() ) {
$this->load_file( self::slug . '-admin-script', plugin_dir_path(__FILE__) . '/js/admin.js', true ); $this->load_file( self::slug . '-admin-script', '/js/admin.js', true );
$this->load_file( self::slug . '-admin-styles', plugin_dir_path(__FILE__) . '/css/admin.css' ); $this->load_file( self::slug . '-admin-style', '/css/admin.css' );
} else { } else {
$this->load_file( self::slug . '-scripts', plugin_dir_path(__FILE__) . '/js/display.js', true ); $this->load_file( self::slug . '-script', '/js/widget.js', true );
$this->load_file( self::slug . '-styles', plugin_dir_path(__FILE__) . '/css/display.css' ); $this->load_file( self::slug . '-style', '/css/widget.css' );
} // end if/else } // end if/else
} // end register_scripts_and_styles } // 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 * @name The ID to register with WordPress
* @file_path The path to the actual file * @file_path The path to the actual file
* @is_script Optional argument for if the incoming file_path is a JavaScript source file. * @is_script Optional argument for if the incoming file_path is a JavaScript source file.
*/ */
private function load_file( $name, $file_path, $is_script = false ) { 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( file_exists( $file ) ) {
if( $is_script ) { if( $is_script ) {
wp_register_script( $name, $url ); wp_register_script( $name, $url, array('jquery') );
wp_enqueue_script( $name ); wp_enqueue_script( $name );
} else { } else {
wp_register_style( $name, $url ); wp_register_style( $name, $url );
wp_enqueue_style( $name ); wp_enqueue_style( $name );
} // end if } // end if
} // end if } // end if
} // end _load_file } // end load_file
} // end class } // end class
// TODO: update the instantiation call of your plugin to the name given at the class definition // TODO: update the instantiation call of your plugin to the name given at the class definition