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

class-admin.php in Block Manager 1.2.3c, at class-admin.php

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