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