PluginProbe
Block Manager / 1.2.3c
Block Manager v1.2.3c
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.3c, at block-manager.php

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