PluginProbe
Block Manager / 2.1.1
Block Manager v2.1.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 2.1.1, at block-manager.php

266 lines 7.2 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: Take control of your WordPress blocks.
6 * Text Domain: block-manager
7 * Author: Darren Cooney
8 * Author URI: https://connekthq.com
9 * Version: 2.1.1
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', '2.1.1' );
22 define( 'BLOCK_MANAGER_RELEASE', 'November 1, 2023' );
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', [ $this, 'gbm_enqueue' ] );
66 load_plugin_textdomain( 'block-manager', false, dirname( plugin_basename( __FILE__ ) ) . '/lang' );
67 add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), [ &$this, 'gbm_action_links' ] );
68 add_filter( 'admin_footer_text', [ &$this, 'gbm_filter_admin_footer_text' ] );
69 require_once BLOCK_MANAGER_DIR_PATH . 'class-admin.php';
70 require_once 'api/blocks-reset.php';
71 require_once 'api/blocks-toggle.php';
72 require_once 'api/bulk-process.php';
73 require_once 'api/category-reset.php';
74 require_once 'api/category-update.php';
75 require_once 'api/export.php';
76 require_once 'includes/connekt-plugin-installer/class-connekt-plugin-installer.php';
77 }
78
79 /**
80 * Enqueue the scripts.
81 *
82 * @author ConnektMedia
83 * @since 1.0
84 */
85 public function gbm_enqueue() {
86 $screen = get_current_screen();
87 $wp_asset_file = require BLOCK_MANAGER_DIR_PATH . 'build/block-manager.asset.php'; // Get webpack asset file.
88 $dependencies = $wp_asset_file['dependencies'];
89
90 // Update script dependencies based on current screen.
91 if ( is_object( get_current_screen() ) ) {
92 if ( $screen === 'site-editor' ) {
93 $dependencies[] = 'wp-edit-site';
94 } elseif ( $screen->id === 'widgets' ) {
95 $dependencies[] = 'wp-edit-widgets';
96 } else {
97 $dependencies[] = 'wp-edit-post';
98 }
99 } else {
100 $dependencies[] = 'wp-edit-post';
101 }
102
103 wp_enqueue_script(
104 'block-manager',
105 plugins_url( 'build/block-manager.js', __FILE__ ),
106 $dependencies,
107 BLOCK_MANAGER_VERSION,
108 false
109 );
110 wp_localize_script(
111 'block-manager',
112 'gutenberg_block_manager',
113 [
114 'blocks' => $this->gbm_get_all_disabled_blocks(),
115 'categories' => $this->gbm_get_all_block_categories(),
116 ]
117 );
118 }
119
120 /**
121 * Get all filtered categories.
122 *
123 * @author ConnektMedia
124 * @since 1.2
125 * @return array
126 */
127 public static function gbm_get_block_categories() {
128 $categories = get_option( BLOCK_MANAGER_CATEGORIES, [] ); // Get option.
129 return $categories ? array_values( $categories ) : [];
130 }
131
132 /**
133 * Get all filtered categories.
134 *
135 * @author ConnektMedia
136 * @since 2.0
137 * @return array
138 */
139 public static function gbm_get_filtered_categories() {
140 $blocks = apply_filters( 'gbm_block_categories', [] ); // Get filtered block categories.
141 return ! empty( $blocks ) ? array_values( $blocks ) : [];
142 }
143
144 /**
145 * Get all disabled blocks.
146 *
147 * @author ConnektMedia
148 * @since 1.0
149 * @return array
150 */
151 public static function gbm_get_all_block_categories() {
152 $updated = self::gbm_get_block_categories();
153 $filtered = self::gbm_get_filtered_categories();
154 $blocks = array_merge( $updated, $filtered );
155 return ! empty( $blocks ) ? $blocks : [];
156 }
157
158 /**
159 * Get all disabled blocks.
160 *
161 * @author ConnektMedia
162 * @since 1.0
163 * @return array
164 */
165 public static function gbm_get_disabled_blocks() {
166 $blocks = get_option( BLOCK_MANAGER_OPTION, [] ); // Get disabled blocks.
167 return ! empty( $blocks ) ? array_values( $blocks ) : [];
168 }
169
170 /**
171 * Get all disabled blocks.
172 *
173 * @author ConnektMedia
174 * @since 1.0
175 * @return array
176 */
177 public static function gbm_get_all_disabled_blocks() {
178 $disabled = self::gbm_get_disabled_blocks();
179 $filtered = self::gbm_get_filtered_blocks();
180 $blocks = array_merge( $disabled, $filtered );
181 return ! empty( $blocks ) ? $blocks : [];
182 }
183
184 /**
185 * Get all filtered blocks.
186 *
187 * @author ConnektMedia
188 * @since 1.1
189 * @return array
190 */
191 public static function gbm_get_filtered_blocks() {
192 $blocks = apply_filters( 'gbm_disabled_blocks', [] ); // Get filtered disabled blocks.
193 return ! empty( $blocks ) ? array_values( $blocks ) : [];
194 }
195
196 /**
197 * Add plugin action links to WP plugin screen
198 *
199 * @author ConnektMedia
200 * @since 1.0
201 * @param array $links The action links.
202 * @return array
203 */
204 public static function gbm_action_links( $links ) {
205 $settings = '<a href="' . get_admin_url( null, 'options-general.php?page=block-manager' ) . '">' . __( 'Blocks', 'block-manager' ) . '</a>';
206 $cats = '<a href="' . get_admin_url( null, 'options-general.php?page=block-manager&category-switcher' ) . '">' . __( 'Block Categories', 'block-manager' ) . '</a>';
207 array_unshift( $links, $settings, $cats );
208 return $links;
209 }
210
211 /**
212 * Confirm user has access to Block Manager.
213 *
214 * @author ConnektMedia
215 * @since 1.1
216 * @return Boolean
217 */
218 public static function has_access() {
219 $access = false;
220 if ( is_user_logged_in() && current_user_can( apply_filters( 'block_manager_user_role', 'activate_plugins' ) ) ) {
221 $access = true;
222 }
223 return $access;
224 }
225
226 /**
227 * Filter the WP Admin footer text.
228 *
229 * @param string $text The footer display text.
230 * @author ConnektMedia
231 * @since 2.0
232 */
233 public function gbm_filter_admin_footer_text( $text ) {
234 $screen = get_current_screen();
235 $base_array = [
236 'settings_page_block-manager',
237 ];
238
239 if ( in_array( $screen->base, $base_array, true ) ) {
240 $divider = '<em>|</em>';
241 $love = '<span style="color: #e25555;">♥</span>';
242 $atts = ' target="_blank" style="font-weight: 500;"';
243
244 $msg = 'Block Manager is made with ' . $love . ' by <a href="https://connekthq.com/?utm_source=WPAdmin&utm_medium=BlockManager&utm_campaign=Footer" target="_blank" style="font-weight: 500;">Connekt</a> ';
245 $msg .= $divider . ' <a href="https://wordpress.org/support/plugin/block-manager/reviews/" ' . $atts . '>Leave Review</a> ';
246 $msg .= $divider . ' <a href="https://wordpress.org/support/plugin/block-manager/" ' . $atts . '>Support</a> ';
247 $msg .= $divider . ' <a href="https://github.com/dcooney/block-manager/" ' . $atts . '>Github</a>';
248 echo wp_kses_post( $msg );
249 }
250 }
251 }
252
253 /**
254 * The main function for Gutenberg_Block_Manager_Init
255 *
256 * @author ConnektMedia
257 * @since 1.0
258 */
259 function gbm_init() {
260 include_once ABSPATH . 'wp-admin/includes/plugin.php';
261 if ( is_plugin_active( 'gutenberg/gutenberg.php' ) || version_compare( get_bloginfo( 'version' ), '4.9.9', '>' ) ) {
262 Gutenberg_Block_Manager::instance();
263 }
264 }
265 add_action( 'plugins_loaded', 'gbm_init', 100 );
266