Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

clean up and minor issues #5

Merged
merged 2 commits into from

2 participants

@franz-josef-kaiser
Collaborator

No description provided.

@franz-josef-kaiser
Collaborator

Looks like I deleted everything and added it back in, but it's just GitHub marking every line, where I changed from space to tab.

Is most of this just changing spaces to tabs? Why?

Collaborator

Yes, it's just changing leading spaces to tabs. This fixes alignment issues due to mixed spaces and tabs like for example here.

I'll send another pull request that fixes other readability issues with GitHub and adds consistency as well as it removes PHP 4 compatibility (wp doesn't support PHP4 any more) adds some other minor PHP5 fixes.

The pull requests after that, then will fix some issues, like for example having a centralized repo for all your local installations, that doesn't work with WP_CONTENT_DIR, but a local domain. See this WPSE question as an example.

@chrisguitarguy

K, I'll take a look later tonight and merge.

@chrisguitarguy chrisguitarguy merged commit 2eaa64b into chrisguitarguy:master
@chrisguitarguy

I'm a "softtab" sort of guy, but I'm okay with this for now. There might be an accidental :retab at some point in the future, though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 26, 2012
  1. clean up: from spaces to tabs

    franz-josef-kaiser authored
  2. minor readability clean ups

    franz-josef-kaiser authored
This page is out of date. Refresh to see the latest.
Showing with 433 additions and 369 deletions.
  1. +318 −269 inc/admin.php
  2. +106 −92 inc/core.php
  3. +9 −8 plugin-dirs.php
View
587 inc/admin.php
@@ -1,275 +1,324 @@
<?php
+! defined( 'ABSPATH' ) && exit();
+
+
class CD_APD_Admin
{
-
- /**
- * The container for all of our custom plugins
- */
- protected $plugins = array();
-
- /**
- * What custom actions are we allowed to handle here?
- */
- protected $actions = array();
-
- /**
- * The original count of the plugins
- */
- protected $all_count = 0;
-
- /**
- * constructor
- *
- * @since 0.1
- */
- function __construct()
- {
- add_action( 'load-plugins.php', array( &$this, 'init' ) );
- add_action( 'plugins_loaded', array( &$this, 'setup_actions' ), 1 );
-
- }
-
- /**
- * Sets up which actions we can handle with this plugin. We'll use this
- * to catch activations and deactivations as the normal way won't work
- *
- * @since 0.1
- */
- function setup_actions()
- {
- $tmp = array(
- 'custom_activate',
- 'custom_deactivate'
- );
- $this->actions = apply_filters( 'custom_plugin_actions', $tmp );
- }
-
- /**
- * Makes the magic happen. Loads all the other hooks to modify the
- * plugin list table
- *
- * @since 0.1
- */
- function init()
- {
- global $wp_plugin_directories;
-
- $screen = get_current_screen();
-
- $this->get_plugins();
-
- $this->handle_actions();
-
- add_filter( 'views_' . $screen->id, array( &$this, 'views' ) );
-
- // check to see if we're using one of our custom directories
- if( $this->get_plugin_status() )
- {
- add_filter( 'views_' . $screen->id, array( &$this, 'views_again' ) );
- add_filter( 'all_plugins', array( &$this, 'filter_plugins' ) );
- // TODO: support bulk actions
- add_filter( 'bulk_actions-' . $screen->id, '__return_empty_array' );
- add_filter( 'plugin_action_links', array( &$this, 'action_links' ), 10, 2 );
- add_action( 'admin_enqueue_scripts', array( &$this, 'scripts' ) );
- }
- }
-
- /**
- * Adds our custom plugin directories to the list of plugin types
- *
- * @since 0.1
- */
- function views( $views )
- {
- global $wp_plugin_directories;
-
- // bail if we don't have any extra dirs
- if( empty( $wp_plugin_directories ) ) return $views;
-
- // Add our directories to the action links
- foreach( $wp_plugin_directories as $key => $info )
- {
- if( ! count( $this->plugins[$key] ) ) continue;
- $class = $this->get_plugin_status() == $key ? ' class="current" ' : '';
- $views[$key] = sprintf(
- '<a href="%s"' . $class . '>%s <span class="count">(%d)</span></a>',
- add_query_arg( 'plugin_status', $key, 'plugins.php' ),
- esc_html( $info['label'] ),
- count( $this->plugins[$key] )
- );
- }
- return $views;
- }
-
- /**
- * Unset inactive plugin link as it doesn't really work for this view
- */
- function views_again( $views )
- {
- if( isset( $views['inactive'] ) ) unset( $views['inactive'] );
- return $views;
- }
-
- /**
- * Filters the plugins list to include all the plugins in our custom directory
- */
- function filter_plugins( $plugins )
- {
- if( $key = $this->get_plugin_status() )
- {
- $this->all_count = count( $plugins );
- $plugins = $this->plugins[$key];
- }
- return $plugins;
- }
-
- /**
- * Correct some action links so we can actually "activate" plugins
- */
- function action_links( $links, $plugin_file )
- {
- $context = $this->get_plugin_status();
-
- // let's just start over
- $links = array();
- $links['activate'] = sprintf(
- '<a href="%s" title="Activate this plugin">%s</a>',
- wp_nonce_url( 'plugins.php?action=custom_activate&amp;plugin=' . $plugin_file . '&amp;plugin_status=' . esc_attr( $context ), 'custom_activate-' . $plugin_file ),
- __( 'Activate' )
- );
-
- $active = get_option( 'active_plugins_' . $context, array() );
- if( in_array( $plugin_file, $active ) )
- {
- $links['deactivate'] = sprintf(
- '<a href="%s" title="Deactivate this plugin" class="cd-apd-deactivate">%s</a>',
- wp_nonce_url( 'plugins.php?action=custom_deactivate&amp;plugin=' . $plugin_file . '&amp;plugin_status=' . esc_attr( $context ), 'custom_deactivate-' . $plugin_file ),
- __( 'Deactivate' )
- );
- }
- return $links;
- }
-
- /**
- * Enqueues on JS file for fun hacks
- *
- * @since 0.1
- * @uses wp_enqueue_script
- */
- function scripts()
- {
- wp_enqueue_script(
- 'cd-apd-js',
- CD_APD_URL . 'js/apd.js',
- array( 'jquery' ),
- null
- );
- wp_localize_script(
- 'cd-apd-js',
- 'cd_apd',
- array(
- 'count' => esc_js( $this->all_count )
- )
- );
- }
-
- /**
- * Fetch all the custom plugins we have!
- *
- * @since 0.1
- * @uses cd_adp_get_plugins To fetch all the custom plugins
- */
- function get_plugins()
- {
- global $wp_plugin_directories;
- if( empty( $wp_plugin_directories ) ) $wp_plugin_directories = array();
- foreach( array_keys( $wp_plugin_directories ) as $key )
- {
- $this->plugins[$key] = cd_apd_get_plugins( $key );
- }
- }
-
- /**
- * Handle activations and deactivations as the standard way will
- * fail with "plugin file does not exist
- *
- * @since 0.1
- */
- function handle_actions()
- {
- $action = isset( $_REQUEST['action'] ) ? $_REQUEST['action'] : '';
-
- // not allowed to handle this action? bail.
- if( ! in_array( $action, $this->actions ) ) return;
-
- // Get the plugin we're going to activate
- $plugin = isset( $_REQUEST['plugin'] ) ? $_REQUEST['plugin'] : false;
- if( ! $plugin ) return;
-
- $context = $this->get_plugin_status();
-
- switch( $action )
- {
- case 'custom_activate':
- if( ! current_user_can('activate_plugins') )
- wp_die( __('You do not have sufficient permissions to manage plugins for this site.') );
-
- check_admin_referer( 'custom_activate-' . $plugin );
-
- $result = cd_apd_activate_plugin( $plugin, $context );
- if ( is_wp_error( $result ) )
- {
- if ( 'unexpected_output' == $result->get_error_code() )
- {
- $redirect = add_query_arg( 'plugin_status', $context, self_admin_url( 'plugins.php' ) );
- wp_redirect( add_query_arg( '_error_nonce', wp_create_nonce( 'plugin-activation-error_' . $plugin ), $redirect ) ) ;
- exit();
- }
- else
- {
- wp_die( $result );
- }
- }
-
- wp_redirect( add_query_arg( array( 'plugin_status' => $context, 'activate' => 'true' ), self_admin_url( 'plugins.php' ) ) );
- exit();
- break;
- case 'custom_deactivate':
- if ( ! current_user_can( 'activate_plugins' ) )
- wp_die( __('You do not have sufficient permissions to deactivate plugins for this site.') );
-
- check_admin_referer('custom_deactivate-' . $plugin);
- cd_apd_deactivate_plugins( $plugin, $context );
- if ( headers_sent() )
- echo "<meta http-equiv='refresh' content='" . esc_attr( "0;url=plugins.php?deactivate=true&plugin_status=$status&paged=$page&s=$s" ) . "' />";
- else
- wp_redirect( self_admin_url("plugins.php?deactivate=true&plugin_status=$context") );
- exit();
- break;
- default:
- do_action( 'custom_plugin_dir_' . $action );
- break;
- }
-
- }
-
- /**
- * Utility function to get the current `plugin_status` key returns
- * false if our key isn't in the the custom directories
- *
- * @since 0.1
- * @return bool|string False on failure, the `$wp_plugin_directories` key on success
- */
- function get_plugin_status()
- {
- global $wp_plugin_directories;
- $rv = false;
- if( isset( $_GET['plugin_status'] ) && in_array( $_GET['plugin_status'], array_keys( $wp_plugin_directories ) ) )
- {
- $rv = $_GET['plugin_status'];
- }
- return $rv;
- }
+ /**
+ * The container for all of our custom plugins
+ */
+ protected $plugins = array();
+
+ /**
+ * What custom actions are we allowed to handle here?
+ */
+ protected $actions = array();
+
+ /**
+ * The original count of the plugins
+ */
+ protected $all_count = 0;
+
+ /**
+ * constructor
+ *
+ * @since 0.1
+ */
+ public function __construct()
+ {
+ add_action( 'load-plugins.php', array( $this, 'init' ) );
+ add_action( 'plugins_loaded', array( $this, 'setup_actions' ), 1 );
+ }
+
+
+ /**
+ * Sets up which actions we can handle with this plugin. We'll use this
+ * to catch activations and deactivations as the normal way won't work
+ *
+ * @since 0.1
+ */
+ public function setup_actions()
+ {
+ $tmp = array(
+ 'custom_activate',
+ 'custom_deactivate'
+ );
+ $this->actions = apply_filters( 'custom_plugin_actions', $tmp );
+ }
+
+
+ /**
+ * Makes the magic happen. Loads all the other hooks to modify the
+ * plugin list table
+ *
+ * @since 0.1
+ */
+ public function init()
+ {
+ global $wp_plugin_directories;
+
+ $screen = get_current_screen();
+
+ $this->get_plugins();
+
+ $this->handle_actions();
+
+ add_filter( "views_{$screen->id}", array( $this, 'views' ) );
+
+ // check to see if we're using one of our custom directories
+ if ( $this->get_plugin_status() )
+ {
+ add_filter( "views_{$screen->id}", array( $this, 'views_again' ) );
+ add_filter( 'all_plugins', array( $this, 'filter_plugins' ) );
+ // @TODO: support bulk actions
+ add_filter( "bulk_actions-{$screen->id}", '__return_empty_array' );
+ add_filter( 'plugin_action_links', array( $this, 'action_links' ), 10, 2 );
+ add_action( 'admin_enqueue_scripts', array( $this, 'scripts' ) );
+ }
+ }
+
+
+ /**
+ * Adds our custom plugin directories to the list of plugin types
+ *
+ * @since 0.1
+ */
+ public function views( $views )
+ {
+ global $wp_plugin_directories;
+
+ // bail if we don't have any extra dirs
+ if ( empty( $wp_plugin_directories ) )
+ return $views;
+
+ // Add our directories to the action links
+ foreach ( $wp_plugin_directories as $key => $info )
+ {
+ if ( ! count( $this->plugins[$key] ) )
+ continue;
+
+ $views[ $key ] = sprintf(
+ '<a href="%s"%s>%s <span class="count">(%d)</span></a>',
+ add_query_arg( 'plugin_status', $key, 'plugins.php' ),
+ $this->get_plugin_status() == $key ? ' class="current" ' : '',
+ esc_html( $info['label'] ),
+ count( $this->plugins[ $key ] )
+ );
+ }
+
+ return $views;
+ }
+
+
+ /**
+ * Unset inactive plugin link as it doesn't really work for this view
+ */
+ public function views_again( $views )
+ {
+ if ( isset( $views['inactive'] ) )
+ unset( $views['inactive'] );
+
+ return $views;
+ }
+
+
+ /**
+ * Filters the plugins list to include all the plugins in our custom directory
+ */
+ public function filter_plugins( $plugins )
+ {
+ if ( $key = $this->get_plugin_status() )
+ {
+ $this->all_count = count( $plugins );
+ $plugins = $this->plugins[ $key] ;
+ }
+
+ return $plugins;
+ }
+
+
+ /**
+ * Correct some action links so we can actually "activate" plugins
+ */
+ public function action_links( $links, $plugin_file )
+ {
+ $context = $this->get_plugin_status();
+
+ // let's just start over
+ $links = array();
+ $links['activate'] = sprintf(
+ '<a href="%s" title="Activate this plugin">%s</a>',
+ wp_nonce_url(
+ "plugins.php?action=custom_activate&amp;plugin={$plugin_file}&amp;plugin_status=".esc_attr( $context ),
+ "custom_activate-{$plugin_file}"
+ ),
+ __( 'Activate' )
+ );
+
+ $active = get_option( "active_plugins_{$context}", array() );
+ if ( in_array( $plugin_file, $active ) )
+ {
+ $links['deactivate'] = sprintf(
+ '<a href="%s" title="Deactivate this plugin" class="cd-apd-deactivate">%s</a>',
+ wp_nonce_url(
+ "plugins.php?action=custom_deactivate&amp;plugin={$plugin_file}&amp;plugin_status=".esc_attr( $context ),
+ "custom_deactivate-{$plugin_file}"
+ ),
+ __( 'Deactivate' )
+ );
+ }
+
+ return $links;
+ }
+
+
+ /**
+ * Enqueues on JS file for fun hacks
+ *
+ * @since 0.1
+ * @uses wp_enqueue_script
+ */
+ public function scripts()
+ {
+ wp_enqueue_script(
+ 'cd-apd-js',
+ CD_APD_URL . 'js/apd.js',
+ array( 'jquery' ),
+ null
+ );
+ wp_localize_script(
+ 'cd-apd-js',
+ 'cd_apd',
+ array(
+ 'count' => esc_js( $this->all_count )
+ )
+ );
+ }
+
+
+ /**
+ * Fetch all the custom plugins we have!
+ *
+ * @since 0.1
+ * @uses cd_adp_get_plugins To fetch all the custom plugins
+ */
+ public function get_plugins()
+ {
+ global $wp_plugin_directories;
+
+ empty( $wp_plugin_directories ) AND $wp_plugin_directories = array();
+
+ foreach ( array_keys( $wp_plugin_directories ) as $key )
+ {
+ $this->plugins[ $key ] = cd_apd_get_plugins( $key );
+ }
+ }
+
+
+ /**
+ * Handle activations and deactivations as the standard way will
+ * fail with "plugin file does not exist
+ *
+ * @since 0.1
+ */
+ public function handle_actions()
+ {
+ $action = isset( $_REQUEST['action'] ) ? $_REQUEST['action'] : '';
+
+ // not allowed to handle this action? bail.
+ if ( ! in_array( $action, $this->actions ) ) return;
+
+ // Get the plugin we're going to activate
+ $plugin = isset( $_REQUEST['plugin'] ) ? $_REQUEST['plugin'] : false;
+
+ if ( ! $plugin )
+ return;
+
+ $context = $this->get_plugin_status();
+
+ switch( $action )
+ {
+ case 'custom_activate':
+ if ( ! current_user_can('activate_plugins') )
+ wp_die( __('You do not have sufficient permissions to manage plugins for this site.') );
+
+ check_admin_referer( "custom_activate-{$plugin}" );
+
+ $result = cd_apd_activate_plugin( $plugin, $context );
+ if ( is_wp_error( $result ) )
+ {
+ if ( 'unexpected_output' == $result->get_error_code() )
+ {
+ wp_redirect( add_query_arg(
+ '_error_nonce',
+ wp_create_nonce( "plugin-activation-error_{$plugin}" ),
+ add_query_arg(
+ 'plugin_status',
+ $context,
+ self_admin_url( 'plugins.php' )
+ )
+ ) );
+ exit();
+ }
+ else
+ {
+ wp_die( $result );
+ }
+ }
+
+ wp_redirect( add_query_arg(
+ array( 'plugin_status' => $context, 'activate' => 'true' ),
+ self_admin_url( 'plugins.php' )
+ ) );
+ exit();
+ break;
+
+ case 'custom_deactivate':
+ if ( ! current_user_can( 'activate_plugins' ) )
+ wp_die( __( 'You do not have sufficient permissions to deactivate plugins for this site.' ) );
+
+ check_admin_referer( "custom_deactivate-{$plugin}" );
+ cd_apd_deactivate_plugins( $plugin, $context );
+ if ( headers_sent() )
+ printf(
+ "<meta http-equiv='refresh' content='%s' />",
+ esc_attr( "0;url=plugins.php?deactivate=true&plugin_status={$status}&paged={$page}&s={$s}" )
+ );
+ else
+ wp_redirect( self_admin_url("plugins.php?deactivate=true&plugin_status={$context}") );
+ exit();
+ break;
+
+ default:
+ do_action( "custom_plugin_dir_{$action}" );
+ break;
+ }
+ }
+
+
+ /**
+ * Utility function to get the current `plugin_status` key returns
+ * false if our key isn't in the the custom directories
+ *
+ * @since 0.1
+ * @return bool|string False on failure, the `$wp_plugin_directories` key on success
+ */
+ public function get_plugin_status()
+ {
+ global $wp_plugin_directories;
+
+ $rv = false;
+
+ if (
+ isset( $_GET['plugin_status'] )
+ AND in_array( $_GET['plugin_status'], array_keys( $wp_plugin_directories ) )
+ )
+ {
+ $rv = $_GET['plugin_status'];
+ }
+
+ return $rv;
+ }
} // end class
new CD_APD_Admin();
View
198 inc/core.php
@@ -1,4 +1,7 @@
<?php
+! defined( 'ABSPATH' ) AND exit();
+
+
/**
* The central API: registers a new plugin directory
*
@@ -9,18 +12,19 @@
*/
function register_plugin_directory( $key, $dir, $label )
{
- global $wp_plugin_directories;
- if( empty( $wp_plugin_directories ) ) $wp_plugin_directories = array();
-
- if( ! file_exists( $dir ) && file_exists( trailingslashit( WP_CONTENT_DIR ) . $dir ) )
- {
- $dir = trailingslashit( WP_CONTENT_DIR ) . $dir;
- }
-
- $wp_plugin_directories[$key] = array(
- 'label' => $label,
- 'dir' => $dir
- );
+ global $wp_plugin_directories;
+
+ empty( $wp_plugin_directories ) AND $wp_plugin_directories = array();
+
+ if ( ! file_exists( $dir ) AND file_exists( trailingslashit( WP_CONTENT_DIR ) . $dir ) )
+ {
+ $dir = trailingslashit( WP_CONTENT_DIR ) . $dir;
+ }
+
+ $wp_plugin_directories[ $key ] = array(
+ 'label' => $label,
+ 'dir' => $dir
+ );
}
add_action( 'plugins_loaded', 'cd_apd_load_more', 99 );
@@ -31,21 +35,24 @@ function register_plugin_directory( $key, $dir, $label )
*/
function cd_apd_load_more()
{
- global $wp_plugin_directories;
- if( empty( $wp_plugin_directories ) ) $wp_plugin_directories = array();
- foreach( array_keys( $wp_plugin_directories) as $key )
- {
- $active = get_option( 'active_plugins_' . $key, array() );
- foreach( $active as $a )
- {
- if( file_exists( $wp_plugin_directories[$key]['dir'] . '/' . $a ) )
- {
- include_once( $wp_plugin_directories[$key]['dir'] . '/' . $a );
- }
- }
- }
+ global $wp_plugin_directories;
+
+ empty( $wp_plugin_directories ) AND $wp_plugin_directories = array();
+
+ foreach ( array_keys( $wp_plugin_directories ) as $key )
+ {
+ $active = get_option( "active_plugins_{$key}", array() );
+ foreach( $active as $a )
+ {
+ if ( file_exists( "{$wp_plugin_directories[ $key ]['dir']}/{$a}" ) )
+ {
+ include_once( "{$wp_plugin_directories[ $key ]['dir']}/{$a}" );
+ }
+ }
+ }
}
+
/**
* Get the valid plugins from the custom directory
*
@@ -55,23 +62,19 @@ function cd_apd_load_more()
*/
function cd_apd_get_plugins( $dir_key )
{
- global $wp_plugin_directories;
-
- // invalid dir key? bail
- if( ! isset( $wp_plugin_directories[$dir_key] ) )
- {
- return array();
- }
- else
- {
- $plugin_root = $wp_plugin_directories[$dir_key]['dir'];
- }
-
+ global $wp_plugin_directories;
+
+ // invalid dir key? bail
+ if ( ! isset( $wp_plugin_directories[ $dir_key ] ) )
+ return array();
+
+ $plugin_root = $wp_plugin_directories[ $dir_key ]['dir'];
+
if ( ! $cache_plugins = wp_cache_get( 'plugins', 'plugins') )
$cache_plugins = array();
- if ( isset( $cache_plugins[$dir_key] ) )
- return $cache_plugins[$dir_key];
+ if ( isset( $cache_plugins[ $dir_key ] ) )
+ return $cache_plugins[ $dir_key ];
$wp_plugins = array();
@@ -81,78 +84,88 @@ function cd_apd_get_plugins( $dir_key )
while ( ( $file = readdir( $plugins_dir ) ) !== false ) {
if ( substr($file, 0, 1) == '.' )
continue;
- if ( is_dir( $plugin_root.'/'.$file ) ) {
- $plugins_subdir = @ opendir( $plugin_root.'/'.$file );
+ if ( is_dir( "{$plugin_root}/{$file}" ) ) {
+ $plugins_subdir = @ opendir( "{$plugin_root}/{$file}" );
if ( $plugins_subdir ) {
- while (($subfile = readdir( $plugins_subdir ) ) !== false ) {
+ while ( ( $subfile = readdir( $plugins_subdir ) ) !== false ) {
if ( substr($subfile, 0, 1) == '.' )
continue;
if ( substr($subfile, -4) == '.php' )
- $plugin_files[] = "$file/$subfile";
+ $plugin_files[] = "{$file}/{$subfile}";
}
closedir( $plugins_subdir );
}
} else {
- if ( substr($file, -4) == '.php' )
- $plugin_files[] = $file;
+ '.php' === substr( $file, -4 ) AND $plugin_files[] = $file;
}
}
closedir( $plugins_dir );
}
- if ( empty($plugin_files) )
+ if ( empty( $plugin_files ) )
return $wp_plugins;
foreach ( $plugin_files as $plugin_file ) {
- if ( !is_readable( "$plugin_root/$plugin_file" ) )
+ if ( ! is_readable( "{$plugin_root}/{$plugin_file}" ) )
continue;
- $plugin_data = get_plugin_data( "$plugin_root/$plugin_file", false, false ); //Do not apply markup/translate as it'll be cached.
+ // Do not apply markup/translate as it'll be cached.
+ $plugin_data = get_plugin_data( "{$plugin_root}/{$plugin_file}", false, false );
if ( empty ( $plugin_data['Name'] ) )
continue;
- $wp_plugins[trim( $plugin_file )] = $plugin_data;
+ $wp_plugins[ trim( $plugin_file ) ] = $plugin_data;
}
uasort( $wp_plugins, '_sort_uname_callback' );
- $cache_plugins[$dir_key] = $wp_plugins;
- wp_cache_set('plugins', $cache_plugins, 'plugins');
+ $cache_plugins[ $dir_key ] = $wp_plugins;
+ wp_cache_set( 'plugins', $cache_plugins, 'plugins' );
return $wp_plugins;
}
+
/**
* Custom plugin activation function.
*/
function cd_apd_activate_plugin( $plugin, $context, $silent = false )
{
$plugin = trim( $plugin );
-
- $redirect = add_query_arg( 'plugin_status', $context, admin_url( 'plugins.php' ) );
- $redirect = apply_filters( 'custom_plugin_redirect', $redirect );
- $current = get_option( 'active_plugins_' . $context, array() );
+ $redirect = add_query_arg( 'plugin_status', $context, admin_url( 'plugins.php' ) );
+ $redirect = apply_filters( 'custom_plugin_redirect', $redirect );
+
+ $current = get_option( "active_plugins_{$context}", array() );
$valid = cd_apd_validate_plugin( $plugin, $context );
+
if ( is_wp_error( $valid ) )
return $valid;
- if ( !in_array($plugin, $current) ) {
- if ( !empty($redirect) )
- wp_redirect(add_query_arg('_error_nonce', wp_create_nonce('plugin-activation-error_' . $plugin), $redirect)); // we'll override this later if the plugin can be included without fatal error
+ if ( ! in_array( $plugin, $current ) ) {
+ if ( ! empty( $redirect ) )
+ {
+ // we'll override this later if the plugin can be included without fatal error
+ wp_redirect( add_query_arg(
+ '_error_nonce'
+ ,wp_create_nonce( "plugin-activation-error_{$plugin}" )
+ ,$redirect
+ ) );
+ }
+
ob_start();
include_once( $valid );
if ( ! $silent ) {
do_action( 'custom_activate_plugin', $plugin, $context );
- do_action( 'custom_activate_' . $plugin, $context );
+ do_action( "custom_activate_{$plugin}", $context );
}
- $current[] = $plugin;
- sort( $current );
- update_option( 'active_plugins_' . $context, $current );
+ $current[] = $plugin;
+ sort( $current );
+ update_option( "active_plugins_{$context}", $current );
if ( ! $silent ) {
do_action( 'custom_activated_plugin', $plugin, $context );
@@ -160,7 +173,7 @@ function cd_apd_activate_plugin( $plugin, $context, $silent = false )
if ( ob_get_length() > 0 ) {
$output = ob_get_clean();
- return new WP_Error('unexpected_output', __('The plugin generated unexpected output.'), $output);
+ return new WP_Error( 'unexpected_output', __( 'The plugin generated unexpected output.' ), $output );
}
ob_end_clean();
}
@@ -173,28 +186,28 @@ function cd_apd_activate_plugin( $plugin, $context, $silent = false )
* Deactivate custom plugins
*/
function cd_apd_deactivate_plugins( $plugins, $context, $silent = false ) {
- $current = get_option( 'active_plugins_' . $context, array() );
+ $current = get_option( "active_plugins_{$context}", array() );
foreach ( (array) $plugins as $plugin )
- {
+ {
$plugin = trim( $plugin );
if ( ! in_array( $plugin, $current ) ) continue;
if ( ! $silent )
do_action( 'custom_deactivate_plugin', $plugin, $context );
- $key = array_search( $plugin, $current );
- if ( false !== $key ) {
- array_splice( $current, $key, 1 );
- }
+ $key = array_search( $plugin, $current );
+ if ( false !== $key ) {
+ array_splice( $current, $key, 1 );
+ }
if ( ! $silent ) {
- do_action( 'custom_deactivate_' . $plugin, $context );
+ do_action( "custom_deactivate_{$plugin}", $context );
do_action( 'custom_deactivated_plugin', $plugin, $context );
}
}
- update_option( 'active_plugins_' . $context, $current );
+ update_option( "active_plugins_{$context}", $current );
}
@@ -206,30 +219,31 @@ function cd_apd_deactivate_plugins( $plugins, $context, $silent = false ) {
*/
function cd_apd_validate_plugin( $plugin, $context )
{
- $rv = true;
+ $rv = true;
if ( validate_file( $plugin ) )
- {
- $rv = new WP_Error('plugin_invalid', __('Invalid plugin path.'));
- }
-
- global $wp_plugin_directories;
- if( ! isset( $wp_plugin_directories[$context] ) )
- {
- $rv = new WP_Error( 'invalid_context', __( 'The context for this plugin does not exist' ) );
- }
-
- $dir = $wp_plugin_directories[$context]['dir'];
- if( ! file_exists( $dir . '/' . $plugin) )
- {
+ {
+ $rv = new WP_Error( 'plugin_invalid', __( 'Invalid plugin path.' ) );
+ }
+
+ global $wp_plugin_directories;
+
+ if ( ! isset( $wp_plugin_directories[ $context ] ) )
+ {
+ $rv = new WP_Error( 'invalid_context', __( 'The context for this plugin does not exist' ) );
+ }
+
+ $dir = $wp_plugin_directories[ $context ]['dir'];
+ if ( ! file_exists( "{$dir}/{$plugin}" ) )
+ {
$rv = new WP_Error( 'plugin_not_found', __( 'Plugin file does not exist.' ) );
- }
+ }
$installed_plugins = cd_apd_get_plugins( $context );
- if ( ! isset($installed_plugins[$plugin]) )
- {
+ if ( ! isset( $installed_plugins[ $plugin ] ) )
+ {
$rv = new WP_Error( 'no_plugin_header', __('The plugin does not have a valid header.') );
- }
-
- $rv = $dir . '/' . $plugin;
+ }
+
+ $rv = "{$dir}/{$plugin}";
return $rv;
-}
+}
View
17 plugin-dirs.php
@@ -1,21 +1,22 @@
<?php
+! defined( 'ABSPATH' ) && exit();
/*
Plugin Name: Additional Plugin Directories
-Plugin URI: http://github.com/chrisguitarugy
+Plugin URI: http://github.com/chrisguitarugy
Description: A framework for adding additional plugin directories to WordPress
-Version: 0.1
-Author: Christopher Davis
-Author URI: http://christopherdavis.me
-License: GPL2
+Version: 0.1
+Author: Christopher Davis
+Author URI: http://christopherdavis.me
+License: GPL2
*/
-! defined( 'ABSPATH' ) && exit();
+
define( 'CD_APD_PATH', plugin_dir_path( __FILE__ ) );
define( 'CD_APD_URL', plugin_dir_url( __FILE__ ) );
-require_once( CD_APD_PATH . 'inc/core.php' );
+require_once( CD_APD_PATH.'inc/core.php' );
if( is_admin() )
{
- require_once( CD_APD_PATH . 'inc/admin.php' );
+ require_once( CD_APD_PATH.'inc/admin.php' );
}
Something went wrong with that request. Please try again.