PluginProbe
Block Manager / 1.2.5
Block Manager v1.2.5
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.5, at class-admin.php

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