Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

made bootstrap OOP

  • Loading branch information...
commit c1b94a8eca84f8666000d1d220efa98b010239c1 1 parent af60a2c
franz-josef-kaiser authored
Showing with 118 additions and 25 deletions.
  1. +3 −1 changelog.txt
  2. +28 −15 inc/admin.php
  3. +87 −9 plugin-dirs.php
View
4 changelog.txt
@@ -21,4 +21,6 @@ Fix script path for remote locations.
*0.7.2*
Renamed main plugin file to index.php to avoid accidental directory listing.
*0.7.3*
-Reverted 0.7.2 to avoid plugin deactivation. Added index.html file instead.
+Reverted 0.7.2 to avoid plugin deactivation. Added index.html file instead.
+*0.8*
+Moved Bootstrap to OOP construct. Regular child plugins are now allowed to use the default priority.
View
43 inc/admin.php
@@ -5,7 +5,6 @@
if ( ! class_exists( 'CD_APD_Admin' ) )
{
- add_action( 'plugins_loaded', array( 'CD_APD_Admin', 'instance' ) );
/**
* Admin/Factory
@@ -81,7 +80,7 @@ public static function instance()
*/
public function __construct()
{
- add_action( 'plugins_loaded', array( $this, 'setup_actions' ), 1 );
+ add_action( 'plugins_loaded', array( $this, 'setup_actions' ), 11 );
add_action( 'load-plugins.php', array( $this, 'init' ) );
}
@@ -254,7 +253,10 @@ public function action_links( $links, $plugin_file )
/**
- * Enqueues on JS file for fun hacks
+ * Enqueues on JS file for fun hacks.
+ *
+ * @uses filemtime() to set the version number of files
+ * to their last changed date to prevent caching.
*
* @since 0.1
* @uses wp_enqueue_script()
@@ -265,21 +267,11 @@ public function scripts( $screen )
if ( 'plugins.php' !== $screen )
return;
- // Allow remote file directories
- $subject = plugin_dir_url( __FILE__ );
- $search = basename( plugin_dir_url( __FILE__ ) );
- $url = substr_replace(
- $subject
- ,"js"
- ,strrpos( $subject, $search )
- ,strlen( $search )
- );
-
wp_enqueue_script(
'cd-apd-js'
- ,"{$url}apd.js"
+ ,$this->scripts_file_cb( 'url' )."apd.js"
,array( 'jquery' )
- ,null
+ ,filemtime( $this->scripts_file_cb( 'path' )."apd.js" )
);
wp_localize_script(
'cd-apd-js',
@@ -292,6 +284,27 @@ public function scripts( $screen )
/**
+ * Callback to get the Path or URl to register scripts.
+ *
+ * @since 0.7.3
+ * @param string $case (Valid are:) 'path', 'url'
+ * @param string $sub_dir Defaults to: 'js'
+ * @return string
+ */
+ public function scripts_file_cb( $case, $sub_dir = 'js' )
+ {
+ $root = 'path' === $case ? plugin_dir_path( __FILE__ ) : plugin_dir_url( __FILE__ );
+
+ return substr_replace(
+ $root
+ ,$sub_dir
+ ,strrpos( $root, basename( $root ) )
+ ,strlen( basename( $root ) )
+ );
+ }
+
+
+ /**
* Fetch all the custom plugins we have!
*
* @since 0.1
View
96 plugin-dirs.php
@@ -4,21 +4,99 @@
Plugin Name: Additional Plugin Directories
Plugin URI: http://github.com/chrisguitarguy
Description: A framework to allow adding additional plugin directories to WordPress
-Version: 0.7.3
+Version: 0.8
Author: Christopher Davis
Contributors: Franz Josef Kaiser, Julien Chaumond
Author URI: http://christopherdavis.me
-License: GPL2
+License: GNU GPL 2
*/
-define( 'CD_APD_PATH', plugin_dir_path( __FILE__ ) );
-define( 'CD_APD_URL', plugin_dir_url( __FILE__ ) );
-require_once( CD_APD_PATH.'inc/api.php' );
-require_once( CD_APD_PATH.'inc/core.php' );
+// Avoid loading twice
+if ( ! class_exists( 'dmb_bootstrap' ) )
+{
+ add_action( 'plugins_loaded', array( 'CD_APD_Bootstrap', 'init' ), 5 );
-if ( is_admin() )
+/**
+ * Bootstrap for delayed Meta Boxes
+ *
+ * @author Franz Josef Kaiser, Christopher Davis
+ * @license GNU GPL 2
+ * @copyright © Franz Josef Kaiser, Christopher Davis 2011-2012
+ *
+ * @package WordPress
+ * @subpackage Additional Plugin Directories: Bootstrap
+ */
+class CD_APD_Bootstrap
{
- require_once( CD_APD_PATH.'inc/admin.php' );
-}
+ /**
+ * Instance
+ *
+ * @access protected
+ * @var object
+ */
+ static protected $instance;
+
+
+ /**
+ * The files that need to get included
+ *
+ * @since 0.8
+ * @access public
+ * @static
+ * @var array string Class Name w/o prefix (Hint: Naming convention!) Use the value to define if need to hook the class.
+ */
+ static public $includes = array(
+ 'api' => false
+ ,'core' => false
+ ,'admin' => true
+ );
+
+
+ /**
+ * Creates a new static instance
+ *
+ * @since 0.8
+ * @static
+ * @return void
+ */
+ static public function init()
+ {
+ null === self :: $instance AND self :: $instance = new self;
+ return self :: $instance;
+ }
+
+
+ /**
+ * Constructor
+ *
+ * @since 0.8
+ * @access public
+ * @return void
+ */
+ public function __construct()
+ {
+ // Localize
+ load_theme_textdomain( 'cd_apd_textdomain', plugin_dir_path( __FILE__ )."lang" );
+
+ // Load at the end of /wp-admin/admin.php
+ foreach ( self :: $includes as $inc => $init )
+ {
+ // Load file: trailingslashed by core
+ # Tested: calling plugin_dir_path() directly saves 1/2 time
+ # instead of saving the plugin_dir_path() in a $var and recalling here
+ require_once plugin_dir_path( __FILE__ )."inc/{$inc}.php";
+
+ if ( ! $init )
+ continue;
+
+ // Build class name
+ $class = "CD_APD_".ucwords( $inc );
+
+ class_exists( $class ) AND add_action( 'plugins_loaded', array( $class, 'instance' ) );
+ }
+ }
+} // END Class CD_APD_Bootstrap
+
+} // endif;
Please sign in to comment.
Something went wrong with that request. Please try again.