Skip to content

Instantly share code, notes, and snippets.

@srikat
Last active March 15, 2018 08:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save srikat/b3df2461bcddc87a1a160566db89cce6 to your computer and use it in GitHub Desktop.
Save srikat/b3df2461bcddc87a1a160566db89cce6 to your computer and use it in GitHub Desktop.
Additional custom Actions for Keyboard Action to navigate to the list of active and inactive plugins
<?php
/**
* Plugin Name: Keyboard Action - Active Plugins
* Description: Additional custom Action for Keyboard Action to navigate to the list of active plugins
* Version: 0.1.0
* Author: Sridhar Katakam
* Author URI: https://sridharkatakam.com/
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/**
* You can either put this in a separate file or in a function like this.
* (separate file(s) per Action would be recommended)
*
* This is to ensure the class is not loaded before Keyboard Action, and more specifically before
* the \Keyboard_Actions\Actions\Action abstract class is loaded / available.
*/
function sk_ka_register_custom_action_active_plugins() {
/**
* Create a new Lorem Ipsum post and Redirect to it.
*/
class Active_Plugins extends \Keyboard_Action\Actions\Action {
public function __construct() {
$this->id = 'active-plugins';
$this->description = 'Active Plugins list';
$this->aliases = array( 'activeplugins' ); // These are the keywords that trigger the Action in the suggestions
$this->title = __( 'Go to the list of active plugins', 'keyboard-action' );
$this->type = 'default';
$this->suggestions = array( '' );
parent::__construct();
}
/**
* @return bool True when the current logged in user is permitted to use this action.
*/
public function validate() {
// return current_user_can( 'create_posts' );
return true;
}
/**
* Execute the action
*/
public function execute( $data ) {
$this->execution_success_response();
}
/**
* Optional. Additional JS actions to execute after execute() is completed.
* @link https://keyboardaction.com/doc/performing-javascript-actions-after-action-execution
*/
public function get_js_actions( $args = array() ) {
return array(
array(
'action' => 'redirect',
'url' => admin_url( 'plugins.php?plugin_status=active', 'admin' )
),
);
}
}
}
add_filter( 'keyboard-action/actions', function( $actions ) {
sk_ka_register_custom_action_active_plugins();
$actions[] = new Active_Plugins;
return $actions;
} );
<?php
/**
* Plugin Name: Keyboard Action - Inactive Plugins
* Description: Additional custom Action for Keyboard Action to navigate to the list of inactive plugins
* Version: 0.1.0
* Author: Sridhar Katakam
* Author URI: https://sridharkatakam.com/
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/**
* You can either put this in a separate file or in a function like this.
* (separate file(s) per Action would be recommended)
*
* This is to ensure the class is not loaded before Keyboard Action, and more specifically before
* the \Keyboard_Actions\Actions\Action abstract class is loaded / available.
*/
function sk_ka_register_custom_action_inactive_plugins() {
/**
* Create a new Lorem Ipsum post and Redirect to it.
*/
class Inactive_Plugins extends \Keyboard_Action\Actions\Action {
public function __construct() {
$this->id = 'inactive-plugins';
$this->description = 'Inactive Plugins list';
$this->aliases = array( 'inactiveplugins' );
$this->title = __( 'Go to the list of inactive plugins', 'keyboard-action' );
$this->type = 'default';
$this->suggestions = array( '' );
parent::__construct();
}
/**
* @return bool True when the current logged in user is permitted to use this action.
*/
public function validate() {
// return current_user_can( 'create_posts' );
return true;
}
/**
* Execute the action
*/
public function execute( $data ) {
$this->execution_success_response();
}
/**
* Optional. Additional JS actions to execute after execute() is completed.
* @link https://keyboardaction.com/doc/performing-javascript-actions-after-action-execution
*/
public function get_js_actions( $args = array() ) {
return array(
array(
'action' => 'redirect',
'url' => admin_url( 'plugins.php?plugin_status=inactive', 'admin' )
),
);
}
}
}
add_filter( 'keyboard-action/actions', function( $actions ) {
sk_ka_register_custom_action_inactive_plugins();
$actions[] = new Inactive_Plugins;
return $actions;
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment