PluginProbe
Block Manager / 1.2.4
Block Manager v1.2.4
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.4, at class-admin.php

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