PluginProbe
Block Manager / 1.1
Block Manager v1.1
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.1, at class-admin.php

178 lines 5.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 'root' => esc_url_raw( rest_url() ),
83 'nonce' => wp_create_nonce( 'wp_rest' ),
84 'enable' => __( 'Enable', 'gutenberg-block-manager' ),
85 'disable' => __( 'Disable', 'gutenberg-block-manager' ),
86 'enable_all' => __( 'Enable All', 'gutenberg-block-manager' ),
87 'disable_all' => __( 'Disable All', 'gutenberg-block-manager' ),
88 'toggle_all' => __( 'Toggle All Blocks', 'gutenberg-block-manager' ),
89 'toggle' => __( 'Toggle Block Activation', 'gutenberg-block-manager' ),
90 'search_label' => __( 'Filter Blocks', 'gutenberg-block-manager' ),
91 'submit' => __( 'Submit', 'gutenberg-block-manager' ),
92 'loading' => __( 'Loading Blocks', 'gutenberg-block-manager' ),
93 'loading_export' => __( 'Getting export data...', 'gutenberg-block-manager' ),
94 'copy' => __( 'Copy Code', 'gutenberg-block-manager' ),
95 'copied' => __( 'Copied', 'gutenberg-block-manager' ),
96 'close' => __( 'Close', 'gutenberg-block-manager' ),
97 'grid' => __( 'Grid', 'gutenberg-block-manager' ),
98 'list' => __( 'List', 'gutenberg-block-manager' ),
99 'export' => __( 'Export', 'gutenberg-block-manager' ),
100 'export_intro' => __( 'Add the the following code to your functions.php to remove blocks at the theme level.', 'gutenberg-block-manager' ),
101 'filtered_alert' => __( 'This block has been globally disabled via the `gbm_disabled_blocks` filter and cannot be activated.', 'gutenberg-block-manager' ),
102 )
103 );
104
105 }
106
107 /**
108 * Register submenu item.
109 *
110 * @author ConnektMedia
111 * @since 1.0
112 */
113 public function gbm_register_sub_menu() {
114
115 add_submenu_page(
116 'options-general.php',
117 esc_html__( 'Block Manager', 'gutenberg-block-manager' ),
118 esc_html__( 'Block Manager', 'gutenberg-block-manager' ),
119 apply_filters( 'gutenberg_block_manager_user_role', 'activate_plugins' ),
120 'gutenberg-block-manager',
121 array( $this, 'gbm_submenu_page_callback' )
122 );
123
124 }
125
126 /**
127 * The Block Manager admin page.
128 *
129 * @author ConnektMedia
130 * @since 1.0
131 */
132 public function gbm_submenu_page_callback() {
133 ?>
134 <div class="gbm-page-wrap">
135 <div class="gbm-page-wrap--header">
136 <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>
137 <p><?php printf( __( 'Manage the activation status of your %s blocks - disabled blocks will be removed from the block inserter.', 'gutenberg-block-manager' ), '<span class="cnkt-block-totals block-total">--</span>'); ?>
138 <button class="button" id="otherPlugins"><span class="dashicons dashicons-admin-plugins"></span> <?php esc_html_e( 'Other Plugins', 'gutenberg-block-manager' ); ?></button>
139 </div>
140 <div id="gbm-container">
141 <div id="gbm-other-plugins">
142 <?php
143 $plugin_array = array(
144 array(
145 'slug' => 'ajax-load-more',
146 ),
147 array(
148 'slug' => 'easy-query',
149 ),
150 array(
151 'slug' => 'instant-images',
152 ),
153 array(
154 'slug' => 'velocity',
155 ),
156 );
157 ?>
158 <section>
159 <h2><?php echo sprintf( __("Other Plugins from %s Connekt %s", 'gutenberg-block-manager' ), '<a href="https://connekthq.com" target="_blank">', '</a>' ); ?></h2>
160 <button class="button button-secondary" id="otherPluginsClose">&times; <?php esc_html_e( 'Close', 'gutenberg-block-manager' ); ?></button>
161 <div class="cta-wrap">
162 <?php
163 if ( class_exists( 'Connekt_Plugin_Installer' ) ) {
164 Connekt_Plugin_Installer::init( $plugin_array );
165 }
166 ?>
167 </div>
168 </section>
169 </div>
170 <div id="app" class="gbm"></div>
171 </div>
172 </div>
173 <?php
174 }
175 }
176
177 new GBM_Admin();
178