PluginProbe
Block Manager / 3.1.0
Block Manager v3.1.0
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 3.1.0, at block-manager.php

158 lines 4.0 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 and patterns.
6 * Text Domain: block-manager
7 * Author: Darren Cooney
8 * Author URI: https://connekthq.com
9 * Version: 3.1.0
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', '3.1.0' );
22 define( 'BLOCK_MANAGER_RELEASE', 'November 4, 2024' );
23 define( 'BLOCK_MANAGER_BASENAME', plugin_basename( __FILE__ ) );
24 define( 'BLOCK_MANAGER_DIR_PATH', plugin_dir_path( __FILE__ ) );
25 define( 'BLOCK_MANAGER_URL', plugins_url( '', __FILE__ ) );
26 define( 'BLOCK_MANAGER_OPTION', 'gbm_disabled_blocks' );
27 define( 'BLOCK_MANAGER_CATEGORIES', 'gbm_categories' );
28 define( 'BLOCK_MANAGER_PATTERNS', 'gbm_disabled_patterns' );
29
30 /**
31 * Block Manager Class.
32 *
33 * @since 1.0
34 */
35 class Gutenberg_Block_Manager {
36
37 /**
38 * Block Manager Instance variable.
39 *
40 * @var $instance
41 * @since 1.0
42 */
43 private static $instance = null;
44
45
46 /**
47 * Define the Block Manager Instance
48 *
49 * @author ConnektMedia
50 * @since 1.0
51 * @return self
52 */
53 public static function instance() {
54 if ( null === self::$instance ) {
55 self::$instance = new Gutenberg_Block_Manager();
56 }
57 return self::$instance;
58 }
59
60
61 /**
62 * Initialize plugin.
63 *
64 * @author ConnektMedia
65 * @since 1.0
66 */
67 private function __construct() {
68 add_action( 'enqueue_block_editor_assets', [ $this, 'gbm_enqueue' ] );
69 load_plugin_textdomain( 'block-manager', false, dirname( plugin_basename( __FILE__ ) ) . '/lang' );
70
71 require_once 'classes/class-admin.php';
72 require_once 'classes/class-blocks.php';
73 require_once 'classes/class-categories.php';
74 require_once 'classes/class-patterns.php';
75 require_once 'api/blocks-toggle.php';
76 require_once 'api/blocks-reset.php';
77 require_once 'api/category-reset.php';
78 require_once 'api/category-update.php';
79 require_once 'api/patterns-toggle.php';
80 require_once 'api/patterns-reset.php';
81 require_once 'api/bulk-process.php';
82 require_once 'api/export.php';
83 require_once 'includes/connekt-plugin-installer/class-connekt-plugin-installer.php';
84 }
85
86 /**
87 * Enqueue the scripts.
88 *
89 * @author ConnektMedia
90 * @since 1.0
91 */
92 public function gbm_enqueue() {
93 $screen = get_current_screen();
94 $wp_asset_file = require BLOCK_MANAGER_DIR_PATH . 'build/block-manager.asset.php'; // Get webpack asset file.
95 $dependencies = $wp_asset_file['dependencies'];
96
97 // Update script dependencies based on current screen.
98 if ( is_object( get_current_screen() ) ) {
99 if ( $screen === 'site-editor' ) {
100 $dependencies[] = 'wp-edit-site';
101 } elseif ( $screen->id === 'widgets' ) {
102 $dependencies[] = 'wp-edit-widgets';
103 } else {
104 $dependencies[] = 'wp-edit-post';
105 }
106 } else {
107 $dependencies[] = 'wp-edit-post';
108 }
109
110 wp_enqueue_script(
111 'block-manager',
112 plugins_url( 'build/block-manager.js', __FILE__ ),
113 $dependencies,
114 BLOCK_MANAGER_VERSION,
115 false
116 );
117
118 wp_localize_script(
119 'block-manager',
120 'gutenberg_block_manager',
121 [
122 'blocks' => GBM_Blocks::gbm_get_all_disabled_blocks(),
123 'categories' => GBM_Categories::gbm_get_all_block_categories(),
124 'patterns' => GBM_Patterns::gbm_get_all_disabled_patterns(),
125 ]
126 );
127 }
128
129 /**
130 * Confirm user has access to Block Manager.
131 *
132 * @author ConnektMedia
133 * @since 1.1
134 * @return Boolean
135 */
136 public static function has_access() {
137 $access = false;
138 if ( is_user_logged_in() && current_user_can( apply_filters( 'block_manager_user_role', 'activate_plugins' ) ) ) {
139 $access = true;
140 }
141 return $access;
142 }
143 }
144
145 /**
146 * The main function for Gutenberg_Block_Manager_Init
147 *
148 * @author ConnektMedia
149 * @since 1.0
150 */
151 function gbm_init() {
152 include_once ABSPATH . 'wp-admin/includes/plugin.php';
153 if ( is_plugin_active( 'gutenberg/gutenberg.php' ) || version_compare( get_bloginfo( 'version' ), '4.9.9', '>' ) ) {
154 Gutenberg_Block_Manager::instance();
155 }
156 }
157 add_action( 'plugins_loaded', 'gbm_init', 100 );
158