PluginProbe
Block Manager / 1.0.1
Block Manager v1.0.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.0.1, at class-admin.php

155 lines 4.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class GBM_Admin {
4
5 /**
6 * Autoload method
7 */
8 public function __construct() {
9
10 // Register the submenu.
11 add_action( 'admin_menu', array( $this, 'gbm_register_sub_menu' ) );
12 add_action( 'admin_enqueue_scripts', array( $this, 'gbm_admin_enqueue' ) );
13
14 }
15
16 /**
17 * Enqueue the scripts and styles.
18 *
19 * @param string $hook The current page ID.
20 */
21 public function gbm_admin_enqueue( $hook ) {
22
23 if ( 'settings_page_gutenberg-block-manager' !== $hook ) {
24 return;
25 }
26
27 // Register Block Categories
28 $block_categories = array();
29 if (function_exists('get_block_categories')){
30 $block_categories = get_block_categories(get_post());
31 }
32 wp_add_inline_script( 'wp-blocks', sprintf( 'wp.blocks.setCategories( %s );', wp_json_encode( $block_categories ) ), 'after');
33
34 do_action('enqueue_block_editor_assets');
35 wp_dequeue_script('gutenberg-block-manager');
36
37 $block_registry = WP_Block_Type_Registry::get_instance();
38 foreach ( $block_registry->get_all_registered() as $block_name => $block_type ) {
39 // Front-end script.
40 if ( ! empty( $block_type->editor_script ) ) {
41 wp_enqueue_script( $block_type->editor_script );
42 }
43 }
44
45 // Enqueue Scripts.
46 $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min'; // Use minified libraries if SCRIPT_DEBUG is turned off
47
48 wp_enqueue_style(
49 'gutenberg-block-manager-styles',
50 plugins_url( 'dist/css/style.css',
51 __FILE__ ),
52 array(),
53 BLOCK_MANAGER_VERSION
54 );
55
56 wp_enqueue_script(
57 'gutenberg-block-manager-admin',
58 plugins_url( 'dist/js/gbm-admin'. $suffix .'.js', __FILE__ ),
59 array( 'wp-blocks', 'wp-element', 'wp-data', 'wp-edit-post', 'wp-components', 'wp-block-library' ),
60 BLOCK_MANAGER_VERSION,
61 true
62 );
63
64 // Localize Scripts.
65 wp_localize_script(
66 'gutenberg-block-manager-admin',
67 'gbm_localize',
68 array(
69 'disabledBlocks' => get_option( BLOCK_MANAGER_OPTION, array() ),
70 'root' => esc_url_raw( rest_url() ),
71 'nonce' => wp_create_nonce( 'wp_rest' ),
72 'enable' => __( 'Enable', 'gutenberg-block-manager' ),
73 'disable' => __( 'Disable', 'gutenberg-block-manager' ),
74 'enable_all' => __( 'Enable All', 'gutenberg-block-manager' ),
75 'disable_all' => __( 'Disable All', 'gutenberg-block-manager' ),
76 'toggle_all' => __( 'Toggle All Blocks', 'gutenberg-block-manager' ),
77 'toggle' => __( 'Toggle Block Activation', 'gutenberg-block-manager' ),
78 'search_label' => __( 'Filter Blocks', 'gutenberg-block-manager' ),
79 'submit' => __( 'Submit', 'gutenberg-block-manager' ),
80 'loading' => __( 'Loading Blocks', 'gutenberg-block-manager' )
81 )
82 );
83
84 }
85
86 /**
87 * gbm_register_sub_menu
88 * Register submenu item
89 */
90 public function gbm_register_sub_menu() {
91
92 add_submenu_page(
93 'options-general.php',
94 esc_html__( 'Block Manager', 'gutenberg-block-manager' ),
95 esc_html__( 'Block Manager', 'gutenberg-block-manager' ),
96 apply_filters( 'gutenberg_block_manager_user_role', 'activate_plugins' ),
97 'gutenberg-block-manager',
98 array( $this, 'gbm_submenu_page_callback' )
99 );
100
101 }
102
103 /**
104 * gbm_submenu_page_callback
105 * The admin page
106 */
107 public function gbm_submenu_page_callback() {
108 //update_option( BLOCK_MANAGER_OPTION, []);
109 ?>
110 <div class="gbm-page-wrap">
111 <div class="gbm-page-wrap--header">
112 <h2><?php _e( 'Gutenberg Block Manager', 'gutenberg-block-manager' ); ?> <span><a href="https://connekthq.com" target="_blank"><?php _e( 'by Connekt', 'gutenberg-block-manager' ); ?></a></span></h2>
113 <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>'); ?>
114
115 <button class="button" id="otherPlugins"><span class="dashicons dashicons-admin-plugins"></span> <?php _e( 'Other Plugins', 'gutenberg-block-manager' ); ?></button>
116 </div>
117 <div id="gbm-container">
118 <div id="gbm-other-plugins">
119 <?php
120 $plugin_array = array(
121 array(
122 'slug' => 'ajax-load-more'
123 ),
124 array(
125 'slug' => 'easy-query'
126 ),
127 array(
128 'slug' => 'instant-images'
129 ),
130 array(
131 'slug' => 'velocity'
132 )
133 );
134 ?>
135 <section>
136 <h2><?php echo sprintf(__("Other Plugins from %s Connekt %s", 'gutenberg-block-manager'), '<a href="https://connekthq.com" target="_blank">', '</a>');?></h2>
137 <button class="button button-secondary" id="otherPluginsClose">&times; <?php _e( 'Close', 'gutenberg-block-manager' ); ?></button>
138 <div class="cta-wrap">
139 <?php
140 if(class_exists('Connekt_Plugin_Installer')){
141 Connekt_Plugin_Installer::init($plugin_array);
142 }
143 ?>
144 </div>
145 </section>
146 </div>
147 <div id="app" class="gbm"></div>
148 </div>
149 </div>
150 <?php
151 }
152 }
153
154 new GBM_Admin();
155