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

189 lines 4.7 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.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.2' );
21 define( 'BLOCK_MANAGER_RELEASE', 'August 17, 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 require_once 'api/blocks_reset.php';
74 include_once 'vendor/connekt-plugin-installer/class-connekt-plugin-installer.php';
75 }
76
77 /**
78 * Enqueue the scripts.
79 *
80 * @author ConnektMedia
81 * @since 1.0
82 */
83 public function gbm_enqueue() {
84 $script = 'dist/js/gbm.js';
85 wp_enqueue_script(
86 'gutenberg-block-manager',
87 plugins_url( $script, __FILE__ ),
88 array( 'wp-edit-post' ),
89 BLOCK_MANAGER_VERSION,
90 false
91 );
92 wp_localize_script(
93 'gutenberg-block-manager',
94 'gutenberg_block_manager',
95 $this->gbm_get_disabled_blocks()
96 );
97 wp_localize_script(
98 'gutenberg-block-manager',
99 'gutenberg_block_manager_categories',
100 $this->gbm_get_filtered_cats()
101 );
102 }
103
104 /**
105 * Get all filtered categories.
106 *
107 * @author ConnektMedia
108 * @since 1.2
109 * @return array
110 */
111 public static function gbm_get_filtered_cats() {
112 $categories = (array) get_option( BLOCK_MANAGER_CATEGORIES, array() ); // Get option.
113
114 return $categories ? $categories : [];
115 }
116
117 /**
118 * Get all disabled blocks.
119 *
120 * @author ConnektMedia
121 * @since 1.0
122 * @return array
123 */
124 public static function gbm_get_disabled_blocks() {
125 $blocks_manual = (array) get_option( BLOCK_MANAGER_OPTION, array() ); // Get manually disabled blocks.
126 $blocks_filter = apply_filters( 'gbm_disabled_blocks', [] ); // Get filtered disabled blocks.
127 $blocks_array = array_merge( $blocks_manual, $blocks_filter ); // Merge arrays.
128 $blocks = array_unique( $blocks_array ); // Remove Duplicates.
129
130 return $blocks ? $blocks : [];
131 }
132
133 /**
134 * Get all filtered blocks.
135 *
136 * @author ConnektMedia
137 * @since 1.1
138 * @return array
139 */
140 public static function gbm_get_filtered_blocks() {
141 $blocks = apply_filters( 'gbm_disabled_blocks', [] ); // Get filtered disabled blocks.
142 return $blocks ? $blocks : [];
143 }
144
145 /**
146 * Add plugin action links to WP plugin screen
147 *
148 * @author ConnektMedia
149 * @since 1.0
150 * @param array $links The action links.
151 * @return array
152 */
153 public static function gbm_action_links( $links ) {
154 $settings = '<a href="' . get_admin_url( null, 'options-general.php?page=gutenberg-block-manager' ) . '">' . __( 'Manage Blocks', 'gutenberg-block-manager' ) . '</a>';
155 array_unshift( $links, $settings );
156 return $links;
157 }
158
159 /**
160 * Confirm user has access to Block Manager.
161 *
162 * @author ConnektMedia
163 * @since 1.1
164 * @return Boolean
165 */
166 public static function has_access() {
167 $access = false;
168 if ( is_user_logged_in() && current_user_can( apply_filters( 'gutenberg_block_manager_user_role', 'activate_plugins' ) ) ) {
169 $access = true;
170 }
171 return $access;
172 }
173
174 }
175
176 /**
177 * The main function for Gutenberg_Block_Manager_Init
178 *
179 * @author ConnektMedia
180 * @since 1.0
181 */
182 function block_manager_init() {
183 include_once ABSPATH . 'wp-admin/includes/plugin.php';
184 if ( is_plugin_active( 'gutenberg/gutenberg.php' ) || version_compare( get_bloginfo( 'version' ), '4.9.9', '>' ) ) {
185 Gutenberg_Block_Manager::instance();
186 }
187 }
188 add_action( 'plugins_loaded', 'block_manager_init', 100 );
189