PluginProbe
Block Manager / 1.0.1
Block Manager v1.0.1
trunk 1.0 1.0.1 1.1 1.2 1.2.1 1.2.2 1.2.3c 1.2.4 1.2.5 2.0.0 2.1.0 2.1.0.1 2.1.1 3.0.0 3.1.0 3.1.1 3.1.2 3.2.0 3.2.1
block-manager / block-manager.php

block-manager.php in Block Manager 1.0.1, at block-manager.php

108 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: Block Manager
4 Plugin URI: https://connekthq.com/plugins/block-manager/
5 Description: Globally manage the active state of each Gutenberg block.
6 Text Domain: block-manager
7 Author: Darren Cooney
8 Author URI: https://connekthq.com
9 Version: 1.0.1
10 License: GPL
11 Copyright: Darren Cooney & Connekt Media
12 */
13
14
15 // Exit if accessed directly.
16 if ( ! defined( 'ABSPATH' ) ) {
17 exit;
18 }
19
20 define( 'BLOCK_MANAGER_VERSION', '1.0.1' );
21 define( 'BLOCK_MANAGER_RELEASE', 'January 2, 2021' );
22 define( 'BLOCK_MANAGER_DIR_PATH', plugin_dir_path( __FILE__ ) );
23 define( 'BLOCK_MANAGER_OPTION', 'gbm_disabled_blocks' );
24
25
26 class Gutenberg_Block_Manager {
27
28 private static $instance = null;
29
30 public static function instance() {
31 if ( null === self::$instance ) {
32 self::$instance = new Gutenberg_Block_Manager();
33 }
34 return self::$instance;
35 }
36
37
38 /**
39 * Initialize plugin.
40 */
41 private function __construct() {
42
43 add_action( 'enqueue_block_editor_assets', array( $this, 'gbm_enqueue' ) );
44 load_plugin_textdomain( 'gutenberg-block-manager', false, dirname(plugin_basename( __FILE__ )).'/lang');
45 add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), array(&$this, 'gbm_action_links') );
46 require_once(BLOCK_MANAGER_DIR_PATH . 'class-admin.php');
47 require_once('api/toggle.php');
48 require_once('api/bulk_process.php');
49 include_once('vendor/connekt-plugin-installer/class-connekt-plugin-installer.php');
50
51 }
52
53 /**
54 * Enqueue the scripts.
55 */
56 public function gbm_enqueue() {
57 $script = 'dist/js/gbm.js';
58 wp_enqueue_script( 'gutenberg-block-manager', plugins_url( $script, __FILE__ ), array( 'wp-edit-post' ), BLOCK_MANAGER_VERSION, false );
59 wp_localize_script( 'gutenberg-block-manager', 'gutenberg_block_manager', $this->gbm_get_disabled_blocks() );
60
61 }
62
63 /**
64 * Get all disabled blocks.
65 */
66 public function gbm_get_disabled_blocks() {
67 return (array) get_option( BLOCK_MANAGER_OPTION, array() );
68 }
69
70 /**
71 * Add plugin action links to WP plugin screen
72 *
73 * @since 1.0
74 */
75 public function gbm_action_links( $links ) {
76 $settings = '<a href="' . get_admin_url(null, 'options-general.php?page=gutenberg-block-manager') . '">' . __('Manage Blocks', 'gutenberg-block-manager').'</a>';
77 array_unshift( $links, $settings );
78 return $links;
79 }
80
81 /**
82 * Confirm user has access to Block Manager.
83 *
84 * @since 1.1
85 * @return {Boolean}
86 */
87 public static function has_access() {
88 $access = false;
89 if ( is_user_logged_in() && current_user_can( apply_filters( 'gutenberg_block_manager_user_role', 'activate_plugins' ) ) ) {
90 $access = true;
91 }
92 return $access;
93 }
94
95 }
96
97 /**
98 * The main function for Gutenberg_Block_Manager_Init
99 */
100 function Gutenberg_Block_Manager_Init() {
101 include_once ABSPATH . 'wp-admin/includes/plugin.php';
102 if ( is_plugin_active('gutenberg/gutenberg.php') || version_compare(get_bloginfo('version'), '4.9.9', '>')){
103 Gutenberg_Block_Manager::instance();
104 }
105 }
106
107 add_action( 'plugins_loaded', 'Gutenberg_Block_Manager_Init', 100 );
108