PluginProbe
Block Manager / 1.2
Block Manager v1.2
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.2, at block-manager.php

187 lines 4.6 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.2
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.2' );
21 define( 'BLOCK_MANAGER_RELEASE', 'February 27, 2021' );
22 define( 'BLOCK_MANAGER_DIR_PATH', plugin_dir_path( __FILE__ ) );
23 define( 'BLOCK_MANAGER_OPTION', 'gbm_disabled_blocks' );
24 define( 'BLOCK_MANAGER_CATEGORIES', 'gbm_categories' );
25
26 /**
27 * Block Manager Class.
28 *
29 * @since 1.0
30 */
31 class Gutenberg_Block_Manager {
32
33 /**
34 * Block Manager Instance variable.
35 *
36 * @var $instance
37 * @since 1.0
38 */
39 private static $instance = null;
40
41
42 /**
43 * Define the Block Manager Instance
44 *
45 * @author ConnektMedia
46 * @since 1.0
47 * @return self
48 */
49 public static function instance() {
50 if ( null === self::$instance ) {
51 self::$instance = new Gutenberg_Block_Manager();
52 }
53 return self::$instance;
54 }
55
56
57 /**
58 * Initialize plugin.
59 *
60 * @author ConnektMedia
61 * @since 1.0
62 */
63 private function __construct() {
64 add_action( 'enqueue_block_editor_assets', array( $this, 'gbm_enqueue' ) );
65 load_plugin_textdomain( 'gutenberg-block-manager', false, dirname( plugin_basename( __FILE__ ) ) . '/lang' );
66 add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( &$this, 'gbm_action_links' ) );
67 require_once BLOCK_MANAGER_DIR_PATH . 'class-admin.php';
68 require_once 'api/toggle.php';
69 require_once 'api/bulk_process.php';
70 require_once 'api/export.php';
71 require_once 'api/category_switch.php';
72 require_once 'api/category_reset.php';
73 include_once 'vendor/connekt-plugin-installer/class-connekt-plugin-installer.php';
74 }
75
76 /**
77 * Enqueue the scripts.
78 *
79 * @author ConnektMedia
80 * @since 1.0
81 */
82 public function gbm_enqueue() {
83 $script = 'dist/js/gbm.js';
84 wp_enqueue_script(
85 'gutenberg-block-manager',
86 plugins_url( $script, __FILE__ ),
87 array( 'wp-edit-post' ),
88 BLOCK_MANAGER_VERSION, false
89 );
90 wp_localize_script(
91 'gutenberg-block-manager',
92 'gutenberg_block_manager',
93 $this->gbm_get_disabled_blocks()
94 );
95 wp_localize_script(
96 'gutenberg-block-manager',
97 'gutenberg_block_manager_categories',
98 $this->gbm_get_filtered_cats()
99 );
100 }
101
102 /**
103 * Get all filtered categories.
104 *
105 * @author ConnektMedia
106 * @since 1.2
107 * @return array
108 */
109 public static function gbm_get_filtered_cats() {
110 $categories = (array) get_option( BLOCK_MANAGER_CATEGORIES, array() ); // Get option.
111
112 return $categories ? $categories : [];
113 }
114
115 /**
116 * Get all disabled blocks.
117 *
118 * @author ConnektMedia
119 * @since 1.0
120 * @return array
121 */
122 public static function gbm_get_disabled_blocks() {
123 $blocks_manual = (array) get_option( BLOCK_MANAGER_OPTION, array() ); // Get manually disabled blocks.
124 $blocks_filter = apply_filters( 'gbm_disabled_blocks', [] ); // Get filtered disabled blocks.
125 $blocks_array = array_merge( $blocks_manual, $blocks_filter ); // Merge arrays.
126 $blocks = array_unique( $blocks_array ); // Remove Duplicates.
127
128 return $blocks ? $blocks : [];
129 }
130
131 /**
132 * Get all filtered blocks.
133 *
134 * @author ConnektMedia
135 * @since 1.1
136 * @return array
137 */
138 public static function gbm_get_filtered_blocks() {
139 $blocks = apply_filters( 'gbm_disabled_blocks', [] ); // Get filtered disabled blocks.
140 return $blocks ? $blocks : [];
141 }
142
143 /**
144 * Add plugin action links to WP plugin screen
145 *
146 * @author ConnektMedia
147 * @since 1.0
148 * @param array $links The action links.
149 * @return array
150 */
151 public static function gbm_action_links( $links ) {
152 $settings = '<a href="' . get_admin_url( null, 'options-general.php?page=gutenberg-block-manager' ) . '">' . __( 'Manage Blocks', 'gutenberg-block-manager' ).'</a>';
153 array_unshift( $links, $settings );
154 return $links;
155 }
156
157 /**
158 * Confirm user has access to Block Manager.
159 *
160 * @author ConnektMedia
161 * @since 1.1
162 * @return Boolean
163 */
164 public static function has_access() {
165 $access = false;
166 if ( is_user_logged_in() && current_user_can( apply_filters( 'gutenberg_block_manager_user_role', 'activate_plugins' ) ) ) {
167 $access = true;
168 }
169 return $access;
170 }
171
172 }
173
174 /**
175 * The main function for Gutenberg_Block_Manager_Init
176 *
177 * @author ConnektMedia
178 * @since 1.0
179 */
180 function block_manager_init() {
181 include_once ABSPATH . 'wp-admin/includes/plugin.php';
182 if ( is_plugin_active( 'gutenberg/gutenberg.php' ) || version_compare( get_bloginfo( 'version' ), '4.9.9', '>' ) ) {
183 Gutenberg_Block_Manager::instance();
184 }
185 }
186 add_action( 'plugins_loaded', 'block_manager_init', 100 );
187