Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

everything OOP, fixed bugs, etc. #7

Merged
merged 7 commits into from

2 participants

@franz-josef-kaiser
Collaborator

Dozen of stuff. Will comment inline.

@franz-josef-kaiser

As discussed.

@franz-josef-kaiser

Just for edge cases.

@franz-josef-kaiser

This function now takes care of the right path/URl. It's also used to get last time when a file changed, so version tracking is obsolete for scripts and files will automagically bypass browser caching.

@franz-josef-kaiser

In case we'll get a translation file at some point.

@franz-josef-kaiser

Bootstrap hooks into the plugins_loaded hook with a priority of 5, so users can add their subplugins with the default priority.

@franz-josef-kaiser
Collaborator

The only things missing now are

  • Bulk actions
  • "Delete" links
  • Fixing the bug, that we're loosing the "Active/Inactive" links on top, when viewing a custom dirs plugins.

Pagination gladly works by default.

If you got any ideas where to start: Please tell me, so we can move this to version 1.0. Thanks.

@franz-josef-kaiser
Collaborator

The above ↑ extension for the pull request fetches the changelog.txt file from the GitHub remote location and extends the update message in the plugins.php WP List Table with a diff-log between the currently installed version and the latest available version note.

This currently only works if the plugin is also hosted in the wp.org Repo, as Updates from GitHub don't work so far.

@chrisguitarguy chrisguitarguy merged commit 305304f into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
4 .gitmodules
@@ -0,0 +1,4 @@
+
+[submodule "inc/updater"]
+ path = inc/updater
+ url = git://github.com/franz-josef-kaiser/WordPress-GitHub-Plugin-Updater.git
View
28 changelog.txt
@@ -0,0 +1,28 @@
+*0.1*
+Initial version.
+*0.2*
+Clean Up & code styling alignment.
+*0.3*
+Minor styling fixes.
+*0.4*
+Moved to OOP concept.
+*0.5*
+Improved API: now supports different plugin locations aside from the `WP_CONTENT_DIR`.
+*0.5.1*
+Minor fix for left over debug code.
+*0.5.2*
+JS styling for readability.
+*0.6*
+Removed "activate" link when plugin is already active, as suggested by Julien Chaumond in Issue #3.
+*0.7*
+Added the "adp_root_{$root}" filter to allow completely custom locations. Moved changelog to separate file.
+*0.7.1*
+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.
+*0.8*
+Moved Bootstrap to OOP construct. Regular child plugins are now allowed to use the default priority.
+*0.9*
+Added better update message (as seen here).
View
37 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()
@@ -266,10 +268,10 @@ public function scripts( $screen )
return;
wp_enqueue_script(
- 'cd-apd-js',
- CD_APD_URL.'js/apd.js',
- array( 'jquery' ),
- null
+ 'cd-apd-js'
+ ,$this->scripts_file_cb( 'url' )."apd.js"
+ ,array( 'jquery' )
+ ,filemtime( $this->scripts_file_cb( 'path' )."apd.js" )
);
wp_localize_script(
'cd-apd-js',
@@ -282,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
5 inc/api.php
@@ -125,9 +125,12 @@ function _get_new_plugin_directory_root( $root )
break;
case 'content' :
- default :
$root = WP_CONTENT_DIR;
break;
+
+ default :
+ $root = apply_filters( "adp_root_{$root}", WP_CONTENT_DIR );
+ break;
}
return trailingslashit( $root );
1  inc/updater
@@ -0,0 +1 @@
+Subproject commit e18b83d4d2817bc8f8ba4df5e3c8142b8f4d4f2e
View
1  index.html
@@ -0,0 +1 @@
+<!-- Hi there. Nice try! ...but sorry, no. -->
View
224 plugin-dirs.php
@@ -1,24 +1,228 @@
<?php
! defined( 'ABSPATH' ) AND exit();
/*
-Plugin Name: Additional Plugin Directories
+Plugin Name: Additional Plugin Directories 2
Plugin URI: http://github.com/chrisguitarguy
Description: A framework to allow adding additional plugin directories to WordPress
-Version: 0.6
+Version: 1.0
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
+ );
+
+
+ /**
+ * Used for update notices
+ * Fetches the readme file from the official plugin repo trunk.
+ * Adds to the "in_plugin_update_message-$file" hook
+ *
+ * @var (string)
+ */
+ public $remote_changelog = 'https://raw.github.com/chrisguitarguy/WP-Plugin-Directories/master/changelog.txt';
+
+
+ /**
+ * 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' ) );
+ }
+
+ if ( ! is_admin() )
+ return;
+
+ // Updates from GitHub
+ // $ git submodule add git://github.com/franz-josef-kaiser/WordPress-GitHub-Plugin-Updater inc/updater
+ add_action( 'admin_init', array( $this, 'update_from_github' ) );
+
+ // Better update message
+ $folder = basename( dirname( __FILE__ ) );
+ $file = basename( __FILE__ );
+ $hook = "in_plugin_update_message-{$folder}/{$file}";
+ add_action( $hook, array( $this, 'update_message' ), 20, 2 );
+ }
+
+
+ /**
+ *
+ * @since 1.0
+ *
+ * @return void
+ */
+ public function update_from_github()
+ {
+ if ( 'plugins.php' !== $GLOBALS['pagenow'] )
+ return;
+
+ global $wp_version;
+
+ // Load the updater
+ include_once plugin_dir_path( __FILE__ ).'inc/updater/updater.php';
+
+ // Fix this strange WP bug(?)
+ add_action( 'http_request_args', array( $this, 'update_request_args' ), 0, 2 );
+
+ $host = 'github.com';
+ $http = 'https://';
+ $name = 'franz-josef-kaiser';
+ $repo = 'WP-Plugin-Directories';
+ new wp_github_updater( array(
+ 'slug' => plugin_basename( __FILE__ )
+ ,'proper_folder_name' => dirname( plugin_basename(__FILE__) ) #plugin_basename( __FILE__ )
+ ,'api_url' => "{$http}api.{$host}/repos/{$name}/{$repo}"
+ ,'raw_url' => "{$http}raw.{$host}/{$name}/{$repo}/master"
+ ,'github_url' => "{$http}{$host}/{$name}/{$repo}"
+ ,'zip_url' => "{$http}{$host}/{$name}/{$repo}/zipball/master"
+ ,'sslverify' => true
+ ,'requires' => $wp_version
+ ,'tested' => $wp_version
+ ,'readme_file' => 'readme.md'
+ ) );
+ }
+
+
+ public function update_request_args( $args, $url )
+ {
+ // Only needed once - this saves us checking the $url
+ remove_filter( current_filter(), __FUNCTION__ );
+
+ return array_merge( $args, array(
+ 'sslverify' => false
+ ) );
+ }
+
+
+ /**
+ * Displays an update message for plugin list screens.
+ * Shows only the version updates from the current until the newest version
+ *
+ * @uses WordPress HTTP API
+ *
+ * @since 0.9
+ * @param array $plugin_data Data of the plugin itself
+ * @param object $r Data of the remote request to the repo
+ * @return string The actual Output message
+ */
+ public function update_message( $plugin_data, $r )
+ {
+ if ( 'plugins.php' !== $GLOBALS['pagenow'] )
+ return;
+
+ // Get `changelog.txt` from GitHub via WP HTTP API
+ $changelog = wp_remote_get(
+ $this->remote_changelog
+ ,array(
+ // We can't force anyone to alter the `~/.ssh/config` on the server
+ 'sslverify' => false
+ )
+ );
+
+ // Die silently
+ if ( is_wp_error( $changelog ) )
+ return;
+
+ // Only retrieve what's new since the installed version
+ $details = explode(
+ '*'
+ ,stristr(
+ $changelog['body']
+ ,"*{$plugin_data['Version']}*"
+ )
+ );
+ // Build the update note
+ $whats_new = '';
+ for ( $i = 0; $i < count( $details ); $i++ )
+ {
+ $whats_new .= ( 0 != $i % 2 ) ? "<strong>{$details[ $i ]}" : "</strong><br />{$details[ $i ]}";
+ }
+
+ return printf(
+ "%sThe Update from %s to %s brings you the following new features, bug fixes and additions.%s"
+ ,'<hr />'
+ ,"<code>{$plugin_data['Version']}</code>"
+ ,"<code>{$r->new_version}</code>"
+ ,"<p style='font-weight:normal;'>{$whats_new}</p>"
+ );
+ }
+} // END Class CD_APD_Bootstrap
+
+} // endif;
View
14 readme.md
@@ -10,16 +10,4 @@ For an example, take a look at the `example_plugin` folder and the `register_add
You need to copy this folder to your actual plugins folder and then activate it from within your plugins list. It only works if the main plugin is activated.
-*) the one you defined with the `WP_PLUGIN_DIR` or `WPMU_PLUGIN_DIR` in your wp-config.php file - or the default `plugins` folder in your install.
-
-
-CHANGELOG
-
-0.1 Initial version
-0.2 Clean Up & code styling alignment
-0.3 Minor styling fixes
-0.4 Moved to OOP concept
-0.5 Improved API - now supports different plugin locations aside from the `WP_CONTENT_DIR`.
-0.5.1 Minor fix for left over debug code
-0.5.2 JS styling for readability
-0.6 Removed "activate" link when plugin is already active, as suggested by Julien Chaumond in Issue #3
+*) the one you defined with the `WP_PLUGIN_DIR` or `WPMU_PLUGIN_DIR` in your wp-config.php file - or the default `plugins` folder in your install.
Something went wrong with that request. Please try again.