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 / class-admin.php

class-admin.php in Block Manager 1.2.2, at class-admin.php

204 lines 7.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Block Manager admin class.
4 *
5 * @author ConnektMedia
6 * @since 1.0
7 */
8 class GBM_Admin {
9
10 /**
11 * Construct method.
12 *
13 * @author ConnektMedia
14 * @since 1.0
15 */
16 public function __construct() {
17
18 // Register the submenu.
19 add_action( 'admin_menu', array( $this, 'gbm_register_sub_menu' ) );
20 add_action( 'admin_enqueue_scripts', array( $this, 'gbm_admin_enqueue' ) );
21
22 }
23
24 /**
25 * Enqueue the scripts and styles.
26 *
27 * @author ConnektMedia
28 * @since 1.0
29 * @param string $hook The current page ID.
30 * @return null
31 */
32 public function gbm_admin_enqueue( $hook ) {
33
34 if ( 'settings_page_gutenberg-block-manager' !== $hook ) {
35 return;
36 }
37
38 // Register Block Categories.
39 $block_categories = array();
40 if ( function_exists( 'get_block_categories' ) ) {
41 $block_categories = get_block_categories( get_post() );
42 }
43 wp_add_inline_script( 'wp-blocks', sprintf( 'wp.blocks.setCategories( %s );', wp_json_encode( $block_categories ) ), 'after' );
44
45 do_action( 'enqueue_block_editor_assets' );
46 wp_dequeue_script( 'gutenberg-block-manager' );
47
48 $block_registry = WP_Block_Type_Registry::get_instance();
49 foreach ( $block_registry->get_all_registered() as $block_name => $block_type ) {
50 // Front-end script.
51 if ( ! empty( $block_type->editor_script ) ) {
52 wp_enqueue_script( $block_type->editor_script );
53 }
54 }
55
56 // Enqueue Scripts.
57 $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min'; // Use minified libraries if SCRIPT_DEBUG is turned off.
58
59 wp_enqueue_style(
60 'gutenberg-block-manager-styles',
61 plugins_url( 'dist/css/style.css',
62 __FILE__ ),
63 array(),
64 BLOCK_MANAGER_VERSION
65 );
66
67 wp_enqueue_script(
68 'gutenberg-block-manager-admin',
69 plugins_url( 'dist/js/gbm-admin' . $suffix . '.js', __FILE__ ),
70 array( 'wp-blocks', 'wp-element', 'wp-data', 'wp-edit-post', 'wp-components', 'wp-block-library' ),
71 BLOCK_MANAGER_VERSION,
72 true
73 );
74
75 // Localize Scripts.
76 wp_localize_script(
77 'gutenberg-block-manager-admin',
78 'gbm_localize',
79 array(
80 'disabledBlocks' => Gutenberg_Block_Manager::gbm_get_disabled_blocks(),
81 'filteredBlocks' => Gutenberg_Block_Manager::gbm_get_filtered_blocks(),
82 'filteredCategories' => Gutenberg_Block_Manager::gbm_get_filtered_cats(),
83 'root' => esc_url_raw( rest_url() ),
84 'nonce' => wp_create_nonce( 'wp_rest' ),
85 'enable' => __( 'Enable', 'gutenberg-block-manager' ),
86 'disable' => __( 'Disable', 'gutenberg-block-manager' ),
87 'enable_all' => __( 'Enable All', 'gutenberg-block-manager' ),
88 'disable_all' => __( 'Disable All', 'gutenberg-block-manager' ),
89 'toggle_all' => __( 'Toggle All Blocks', 'gutenberg-block-manager' ),
90 'toggle' => __( 'Toggle Block Activation', 'gutenberg-block-manager' ),
91 'search_label' => __( 'Filter Blocks', 'gutenberg-block-manager' ),
92 'submit' => __( 'Submit', 'gutenberg-block-manager' ),
93 'loading' => __( 'Loading Blocks', 'gutenberg-block-manager' ),
94 'loading_export' => __( 'Getting export data...', 'gutenberg-block-manager' ),
95 'copy' => __( 'Copy Code', 'gutenberg-block-manager' ),
96 'copied' => __( 'Copied', 'gutenberg-block-manager' ),
97 'close' => __( 'Close', 'gutenberg-block-manager' ),
98 'grid' => __( 'Grid', 'gutenberg-block-manager' ),
99 'list' => __( 'List', 'gutenberg-block-manager' ),
100 'cat_switch' => __( 'Block Category', 'gutenberg-block-manager' ),
101 'updated' => __( 'Category Updated', 'gutenberg-block-manager' ),
102 'block_switch' => __( 'Block Name', 'gutenberg-block-manager' ),
103 'reset_blocks' => __( 'Reset', 'gutenberg-block-manager' ),
104 'reset_blocks_title' => __( 'Clear all disabled blocks.', 'gutenberg-block-manager' ),
105 'reset_cats' => __( 'Reset Categories', 'gutenberg-block-manager' ),
106 'cat_intro' => __( 'The Category Switcher provides functionality for changing the categories of Gutenberg blocks.', 'gutenberg-block-manager' ),
107 'cat_intro2' => __( 'Changing a block category will update it\'s location in the Gutenberg Block Inserter while editing posts.', 'gutenberg-block-manager' ),
108 'export' => __( 'Export', 'gutenberg-block-manager' ),
109 'export_title' => __( 'Export a list of disabled blocks via WordPress filter. ', 'gutenberg-block-manager' ),
110 'export_intro' => __( 'Add the the following code to your functions.php to remove blocks at the theme level.', 'gutenberg-block-manager' ),
111 'filtered_alert' => __( 'This block has been globally disabled via the `gbm_disabled_blocks` filter and cannot be activated.', 'gutenberg-block-manager' ),
112 )
113 );
114
115 }
116
117 /**
118 * Register submenu item.
119 *
120 * @author ConnektMedia
121 * @since 1.0
122 */
123 public function gbm_register_sub_menu() {
124 add_submenu_page(
125 'options-general.php',
126 esc_html__( 'Block Manager', 'gutenberg-block-manager' ),
127 esc_html__( 'Block Manager', 'gutenberg-block-manager' ),
128 apply_filters( 'gutenberg_block_manager_user_role', 'activate_plugins' ),
129 'gutenberg-block-manager',
130 array( $this, 'gbm_submenu_page_callback' )
131 );
132 }
133
134 /**
135 * The Block Manager admin page.
136 *
137 * @author ConnektMedia
138 * @since 1.0
139 */
140 public function gbm_submenu_page_callback() {
141 $active = 'blocks';
142 if ( isset ( $_GET ) && isset ( $_GET['category-switcher'] ) && empty ( $_GET['category-switcher'] ) ) {
143 $active = 'categories';
144 }
145 ?>
146
147 <div class="gbm-page-wrap">
148 <div class="gbm-page-wrap--header">
149 <h2><?php esc_html_e( 'Gutenberg Block Manager', 'gutenberg-block-manager' ); ?> <span><a href="https://connekthq.com" target="_blank"><?php esc_html_e( 'by Connekt', 'gutenberg-block-manager' ); ?></a></span></h2>
150 <?php if ( 'blocks' === $active ) { ?>
151 <p><?php printf( esc_html__( 'Manage the status of your %s Gutenberg blocks - disabled blocks will be globally removed from the block inserter.', 'gutenberg-block-manager' ), '<span class="cnkt-block-totals block-total">--</span>'); ?>
152 <?php } ?>
153 <?php if ( 'categories' === $active ) { ?>
154 <p><?php printf( esc_html__( 'Update the categories of your %s blocks with the category switcher.', 'gutenberg-block-manager' ), '<span class="cnkt-block-totals block-total">--</span>'); ?>
155 <?php } ?>
156 <button class="button" id="otherPlugins"><span class="dashicons dashicons-admin-plugins"></span> <?php esc_html_e( 'Other Plugins', 'gutenberg-block-manager' ); ?></button>
157 </div>
158 <div id="gbm-container">
159 <div id="gbm-other-plugins">
160 <?php
161 $plugin_array = array(
162 array(
163 'slug' => 'ajax-load-more',
164 ),
165 array(
166 'slug' => 'easy-query',
167 ),
168 array(
169 'slug' => 'instant-images',
170 ),
171 array(
172 'slug' => 'velocity',
173 ),
174 );
175 ?>
176 <section>
177 <h2><?php echo sprintf( __("Other Plugins from %s Connekt %s", 'gutenberg-block-manager' ), '<a href="https://connekthq.com" target="_blank">', '</a>' ); ?></h2>
178 <button class="button button-secondary" id="otherPluginsClose">&times; <?php esc_html_e( 'Close', 'gutenberg-block-manager' ); ?></button>
179 <div class="cta-wrap">
180 <?php
181 if ( class_exists( 'Connekt_Plugin_Installer' ) ) {
182 Connekt_Plugin_Installer::init( $plugin_array );
183 }
184 ?>
185 </div>
186 </section>
187 </div>
188 <div class="nav-tab-wrapper">
189 <a class="nav-tab<?php if ( 'blocks' === $active ) { echo ' nav-tab-active'; } ?>" href="options-general.php?page=gutenberg-block-manager">
190 <?php esc_html_e( 'Blocks', 'gutenberg-block-manager' ); ?>
191 </a>
192 <a class="nav-tab<?php if ( 'categories' === $active ) { echo ' nav-tab-active'; } ?>" href="options-general.php?page=gutenberg-block-manager&category-switcher">
193 <?php esc_html_e( 'Categories', 'gutenberg-block-manager' ); ?>
194 </a>
195 </div>
196 <div id="app" class="gbm"></div>
197 </div>
198 </div>
199 <?php
200 }
201 }
202
203 new GBM_Admin();
204