PluginProbe
Block Manager / 1.2.4
Block Manager v1.2.4
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.4, at block-manager.php

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