Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
fnpen committed Feb 22, 2022
1 parent 65d5e69 commit be9ea2a
Show file tree
Hide file tree
Showing 13 changed files with 168 additions and 43 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

All notable changes to this project will be documented in this file.

### 0.8.17 (2022-02-22)


##### Features

* Plugins activation/deactivation

### 0.8.16 (2022-02-22)


Expand Down
4 changes: 2 additions & 2 deletions barista.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Author: WP Busters
* Author URI: https://wpbusters.com/
*
* Version: 0.8.16
* Version: 0.8.17
* Requires at least: 5.8
* Tested up to: 5.9
* Requires PHP: 7.1
Expand All @@ -26,7 +26,7 @@
define( 'BARISTA_URL', \plugins_url( '/', __FILE__ ) );
define( 'BARISTA_PLUGIN_FILE', __FILE__ );
define( 'BARISTA_PLUGIN_DIR', __DIR__ );
define( 'BARISTA_VERSION', '0.8.16' );
define( 'BARISTA_VERSION', '0.8.17' );

// define( 'BARISTA_DEMO', 'animate-up' ); phpcs:ignore Squiz.PHP.CommentedOutCode.Found.

Expand Down
2 changes: 1 addition & 1 deletion build/index.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array(), 'version' => '036a206284edb80617787507e4eba83a');
<?php return array('dependencies' => array(), 'version' => 'ac30ee897364440a7f043a4a2f363fbc');
2 changes: 1 addition & 1 deletion build/index.js

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions classes/class-option.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,17 @@ public function reset() {
$this->write_to_option( [] );
}

/**
* Remove option
*
* @return void
*/
public function remove() {
$this->data = [];
$this->loaded = false;
delete_option( 'barista_' . $this->option_name );
}

/**
* Reads settings from WP option.
*
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "A blazing fast, highly extendable command launcher that helps to do your routine tasks much faster. You can search posts, control your site, and much more.",
"type": "wordpress-plugin",
"license": "ISC",
"version": "0.8.16",
"version": "0.8.17",
"require": {
"php": ">=7.1"
}
Expand Down
3 changes: 2 additions & 1 deletion inc/assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ function scripts() {
'ajaxUrl' => admin_url( 'admin-ajax.php' ),
'collection' => Collection::get_instance()->get_all(),
'isAdmin' => is_admin(),
// 'openAtStart' => BARISTA_DEVELOPMENT,
'openAtStart' => BARISTA_DEVELOPMENT,
// 'startParent'=> 'history',
'startParent'=> 'plugins',
// 'startParent'=> 'level1_1',
// 'startParent'=> 'woocommerce_settings_sections',
// 'startParent'=> 'barista-settings',
Expand Down
28 changes: 15 additions & 13 deletions inc/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,20 @@

add_action( 'init', __NAMESPACE__ . '\\init' );

require BARISTA_PLUGIN_DIR . '/vendor/autoload.php';
require BARISTA_PLUGIN_DIR . '/inc/utils.php';
require BARISTA_PLUGIN_DIR . '/inc/updating.php';
require BARISTA_PLUGIN_DIR . '/classes/class-singleton.php';
require BARISTA_PLUGIN_DIR . '/classes/class-action-request.php';
require BARISTA_PLUGIN_DIR . '/classes/class-action-response.php';
require BARISTA_PLUGIN_DIR . '/classes/class-option.php';
require BARISTA_PLUGIN_DIR . '/classes/class-settings.php';
require BARISTA_PLUGIN_DIR . '/classes/class-collection.php';
require BARISTA_PLUGIN_DIR . '/classes/class-recently-edited-posts.php';
require BARISTA_PLUGIN_DIR . '/classes/class-bookmarks.php';
require BARISTA_PLUGIN_DIR . '/classes/class-history.php';
require BARISTA_PLUGIN_DIR . '/inc/uninstall.php';

/**
* Init all hooks.
*/
Expand All @@ -19,18 +33,6 @@ function init() {
return;
}

require BARISTA_PLUGIN_DIR . '/vendor/autoload.php';
require BARISTA_PLUGIN_DIR . '/classes/class-singleton.php';
require BARISTA_PLUGIN_DIR . '/classes/class-action-request.php';
require BARISTA_PLUGIN_DIR . '/classes/class-action-response.php';
require BARISTA_PLUGIN_DIR . '/classes/class-option.php';
require BARISTA_PLUGIN_DIR . '/classes/class-settings.php';
require BARISTA_PLUGIN_DIR . '/classes/class-collection.php';
require BARISTA_PLUGIN_DIR . '/classes/class-recently-edited-posts.php';
require BARISTA_PLUGIN_DIR . '/classes/class-bookmarks.php';
require BARISTA_PLUGIN_DIR . '/classes/class-history.php';
require BARISTA_PLUGIN_DIR . '/inc/utils.php';
require BARISTA_PLUGIN_DIR . '/inc/updating.php';
require BARISTA_PLUGIN_DIR . '/inc/admin.php';
require BARISTA_PLUGIN_DIR . '/inc/frontend.php';
require BARISTA_PLUGIN_DIR . '/inc/assets.php';
Expand All @@ -49,7 +51,7 @@ function init() {
function admin_init() {
global $menu, $menu_order, $default_menu_order, $_wp_menu_nopriv, $_wp_submenu_nopriv; // it's important for including.

if ( is_ajax() && 'barista_run_action' === $_REQUEST['action'] ) {
if ( defined( 'DOING_AJAX' ) && DOING_AJAX && 'barista_run_action' === $_REQUEST['action'] ) {
if ( ! defined( 'WP_NETWORK_ADMIN' ) ) {
define( 'WP_NETWORK_ADMIN', false );
}
Expand Down
110 changes: 96 additions & 14 deletions inc/commands/plugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
add_action( 'barista_init_commands', __NAMESPACE__ . '\\add', 200 );
add_filter( 'barista_command_plugins_load_children', __NAMESPACE__ . '\\load_children', 100, 2 );
add_filter( 'barista_command_plugins_refresh', __NAMESPACE__ . '\\load_children', 100, 2 );
add_filter( 'barista_action_activate_plugin', __NAMESPACE__ . '\\activate_plugin', 100, 2 );
add_filter( 'barista_action_deactivate_plugin', __NAMESPACE__ . '\\deactivate_plugin', 100, 2 );

const COMMAND_NAME = 'plugins';

Expand Down Expand Up @@ -56,25 +58,105 @@ function load_children( \Barista\Ajax\Action_Response $response ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}

$all_plugins = get_plugins();
$all_plugins = apply_filters( 'all_plugins', get_plugins() );

$items = [];

foreach ( $all_plugins as $plugin_file => $plugin ) {
$id = COMMAND_NAME . '-' . $plugin_file;
$title = implode( ' ', [ $plugin['Title'], '(v.' . $plugin['Version'] . ')', 'by ' . $plugin['Author'] ] );
$title = implode( ' ', array_filter([ $plugin['Title'], $plugin['Version'] ? '(v.' . $plugin['Version'] . ')' : '', 'by ' . $plugin['Author'] ] ));

$status = 'Inactive';
if( is_plugin_active( $plugin_file ) ) {
$status = 'Active';
}

$items[] = [
'parent' => COMMAND_NAME,
'id' => $id,
'title' => $title,
'titleShort' => $plugin['Title'],
'description' => $plugin['Description'],
'group' => $status,
'icon' => 'dashicons-admin-plugins',
'actions' => [
[
'title' => 'Activate',
'name' => 'activate_plugin',
],
[
'title' => 'Deactivate',
'name' => 'deactivate_plugin',
]
],
'suffix' => $status,
'pluginFile' => $plugin_file,
];

$collection->add_command(
[
'parent' => COMMAND_NAME,
'id' => $id,
'title' => $title,
'titleShort' => $plugin['Title'],
'description' => $plugin['Description'],
'icon' => 'dashicons-admin-plugins',
'suffix' => is_plugin_active( $plugin_file ) ? 'Active' : 'Deactivated',
'pluginFile' => $plugin_file,
]
);
}

$mustuse_plugins = get_mu_plugins();
//dd($mustuse_plugins);

foreach ( $mustuse_plugins as $plugin_file => $plugin ) {
$id = COMMAND_NAME . '-' . $plugin_file;
$title = implode( ' ', array_filter([ $plugin['Title'], $plugin['Version'] ? '(v.' . $plugin['Version'] . ')' : '', 'by ' . $plugin['Author'] ] ));

$items[] = [
'parent' => COMMAND_NAME,
'id' => $id,
'title' => $title,
'titleShort' => $plugin['Title'],
'selectable' => false,
'description' => $plugin['Description'],
'group' => 'Must-Use',
'icon' => 'dashicons-admin-plugins',
'suffix' => 'Active',
'pluginFile' => $plugin_file,
];

}

$collection->add_command(
$items
);

return $response->replace( COMMAND_NAME, false, $collection );
}


/**
*
*
* @param \Barista\Ajax\Action_Response $response Response data.
* @param \Barista\Ajax\Action_Request $request Request body data.
*/
function activate_plugin( \Barista\Ajax\Action_Response $response, \Barista\Ajax\Action_Request $request ) {
if ( ! current_user_can( 'activate_plugin', $request['pluginFile'] ) ) {
wp_die( __( 'Sorry, you are not allowed to activate plugins for this site.' ) );
}

$result = \activate_plugin( $request['pluginFile'], '', false, null );
if ( is_wp_error( $result ) ) {
return load_children($response)->failure( $result->get_error_message() );
}

return load_children($response)->success( __( 'The plugin successfully activated.', 'barista' ) );
}


/**
*
*
* @param \Barista\Ajax\Action_Response $response Response data.
* @param \Barista\Ajax\Action_Request $request Request body data.
*/
function deactivate_plugin( \Barista\Ajax\Action_Response $response, \Barista\Ajax\Action_Request $request ) {
if ( ! current_user_can( 'deactivate_plugin', $request['pluginFile'] ) ) {
wp_die( __( 'Sorry, you are not allowed to activate plugins for this site.' ) );
}

\deactivate_plugins( $request['pluginFile'], '', false, null );

return load_children($response)->success( __( 'The plugin successfully deactivated.', 'barista' ) );
}
22 changes: 22 additions & 0 deletions inc/uninstall.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
/**
* Actions for menu items.
*
* @package barista
*/

declare(strict_types=1);

namespace Barista;

/**
* Uninstall all data.
*/
function uninstall() {
Bookmarks::get_instance()->remove();
History::get_instance()->remove();
Recently_Edited_Posts::get_instance()->remove();
Settings::get_instance()->remove();
}

register_uninstall_hook( BARISTA_PLUGIN_FILE, __NAMESPACE__ . '\\uninstall' );
2 changes: 1 addition & 1 deletion vendor/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

require_once __DIR__ . '/composer/autoload_real.php';

return ComposerAutoloaderInit8008ad6f9117ab20bcb3f1c63300a8f1::getLoader();
return ComposerAutoloaderInit54e26057bc09e0191afe287806b2dabd::getLoader();
14 changes: 7 additions & 7 deletions vendor/composer/autoload_real.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// autoload_real.php @generated by Composer

class ComposerAutoloaderInit8008ad6f9117ab20bcb3f1c63300a8f1
class ComposerAutoloaderInit54e26057bc09e0191afe287806b2dabd
{
private static $loader;

Expand All @@ -22,15 +22,15 @@ public static function getLoader()
return self::$loader;
}

spl_autoload_register(array('ComposerAutoloaderInit8008ad6f9117ab20bcb3f1c63300a8f1', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit54e26057bc09e0191afe287806b2dabd', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
spl_autoload_unregister(array('ComposerAutoloaderInit8008ad6f9117ab20bcb3f1c63300a8f1', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit54e26057bc09e0191afe287806b2dabd', 'loadClassLoader'));

$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
if ($useStaticLoader) {
require __DIR__ . '/autoload_static.php';

call_user_func(\Composer\Autoload\ComposerStaticInit8008ad6f9117ab20bcb3f1c63300a8f1::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInit54e26057bc09e0191afe287806b2dabd::getInitializer($loader));
} else {
$map = require __DIR__ . '/autoload_namespaces.php';
foreach ($map as $namespace => $path) {
Expand All @@ -51,12 +51,12 @@ public static function getLoader()
$loader->register(true);

if ($useStaticLoader) {
$includeFiles = Composer\Autoload\ComposerStaticInit8008ad6f9117ab20bcb3f1c63300a8f1::$files;
$includeFiles = Composer\Autoload\ComposerStaticInit54e26057bc09e0191afe287806b2dabd::$files;
} else {
$includeFiles = require __DIR__ . '/autoload_files.php';
}
foreach ($includeFiles as $fileIdentifier => $file) {
composerRequire8008ad6f9117ab20bcb3f1c63300a8f1($fileIdentifier, $file);
composerRequire54e26057bc09e0191afe287806b2dabd($fileIdentifier, $file);
}

return $loader;
Expand All @@ -68,7 +68,7 @@ public static function getLoader()
* @param string $file
* @return void
*/
function composerRequire8008ad6f9117ab20bcb3f1c63300a8f1($fileIdentifier, $file)
function composerRequire54e26057bc09e0191afe287806b2dabd($fileIdentifier, $file)
{
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
Expand Down
4 changes: 2 additions & 2 deletions vendor/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Composer\Autoload;

class ComposerStaticInit8008ad6f9117ab20bcb3f1c63300a8f1
class ComposerStaticInit54e26057bc09e0191afe287806b2dabd
{
public static $files = array (
'49a1299791c25c6fd83542c6fedacddd' => __DIR__ . '/..' . '/yahnis-elsts/plugin-update-checker/load-v4p11.php',
Expand All @@ -17,7 +17,7 @@ class ComposerStaticInit8008ad6f9117ab20bcb3f1c63300a8f1
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->classMap = ComposerStaticInit8008ad6f9117ab20bcb3f1c63300a8f1::$classMap;
$loader->classMap = ComposerStaticInit54e26057bc09e0191afe287806b2dabd::$classMap;

}, null, ClassLoader::class);
}
Expand Down

0 comments on commit be9ea2a

Please sign in to comment.