|
3 | 3 | * Plugin Name: Multisite Shared Blocks
|
4 | 4 | * Plugin URI: https://github.com/BeAPI/multisite-shared-blocks
|
5 | 5 | * Description: Share blocks between network's sites.
|
6 |
| - * Version: 1.0.0 |
| 6 | + * Version: 1.0.1 |
7 | 7 | * Requires at least: 5.9
|
8 | 8 | * Requires PHP: 7.2
|
9 | 9 | * Author: Be API Technical team
|
|
14 | 14 | * Network: true
|
15 | 15 | */
|
16 | 16 |
|
| 17 | +namespace Beapi\MultisiteSharedBlocks; |
| 18 | + |
| 19 | +use Beapi\MultisiteSharedBlocks\Admin\Main as AdminMain; |
| 20 | +use Beapi\MultisiteSharedBlocks\Blocks\SharedBlock; |
| 21 | +use Beapi\MultisiteSharedBlocks\Gutenberg\SharedBlocksAttributes; |
| 22 | +use Beapi\MultisiteSharedBlocks\Rest\Rest; |
| 23 | + |
17 | 24 | // Don't load directly
|
18 | 25 | if ( ! defined( 'ABSPATH' ) ) {
|
19 | 26 | die( '-1' );
|
|
24 | 31 | }
|
25 | 32 |
|
26 | 33 | // Plugin constants
|
27 |
| -define( 'MULTISITE_SHARED_BLOCKS_VERSION', '1.0.0' ); |
| 34 | +define( 'MULTISITE_SHARED_BLOCKS_VERSION', '1.0.1' ); |
28 | 35 | define( 'MULTISITE_SHARED_BLOCKS_CACHE_VERSION', '1' );
|
29 | 36 | define( 'MULTISITE_SHARED_BLOCKS_VIEWS_FOLDER_NAME', 'multisite-shared-blocks' );
|
30 | 37 |
|
|
33 | 40 | define( 'MULTISITE_SHARED_BLOCKS_DIR', plugin_dir_path( __FILE__ ) );
|
34 | 41 | define( 'MULTISITE_SHARED_BLOCKS_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
|
35 | 42 |
|
| 43 | +// Plugin only support multisite installation. |
| 44 | +if ( ! is_multisite() ) { |
| 45 | + add_action( 'admin_init', __NAMESPACE__ . '\\handle_multisite_support_issue' ); |
| 46 | + |
| 47 | + return; |
| 48 | +} |
| 49 | + |
36 | 50 | register_activation_hook( __FILE__, [ \Beapi\MultisiteSharedBlocks\Plugin::class, 'activate' ] );
|
37 | 51 |
|
38 |
| -add_action( 'plugins_loaded', 'init_multisite_shared_blocks_plugin' ); |
| 52 | +add_action( 'plugins_loaded', __NAMESPACE__ . '\\init' ); |
39 | 53 | /**
|
40 | 54 | * Init the plugin
|
41 | 55 | */
|
42 |
| -function init_multisite_shared_blocks_plugin(): void { |
| 56 | +function init(): void { |
43 | 57 |
|
44 | 58 | // Register custom table and check for schema updates
|
45 |
| - \Beapi\MultisiteSharedBlocks\Database::setup(); |
| 59 | + Database::setup(); |
46 | 60 |
|
47 |
| - \Beapi\MultisiteSharedBlocks\Main::get_instance(); |
48 |
| - \Beapi\MultisiteSharedBlocks\Gutenberg\SharedBlocksAttributes::get_instance(); |
49 |
| - \Beapi\MultisiteSharedBlocks\Blocks\SharedBlock::get_instance(); |
50 |
| - \Beapi\MultisiteSharedBlocks\Listener::get_instance(); |
51 |
| - \Beapi\MultisiteSharedBlocks\Rest\Rest::get_instance(); |
52 |
| - \Beapi\MultisiteSharedBlocks\Preview::get_instance(); |
| 61 | + SharedBlocksAttributes::get_instance(); |
| 62 | + SharedBlock::get_instance(); |
| 63 | + Listener::get_instance(); |
| 64 | + Rest::get_instance(); |
| 65 | + Preview::get_instance(); |
53 | 66 |
|
54 | 67 | if ( is_admin() ) {
|
55 |
| - \Beapi\MultisiteSharedBlocks\Admin\Main::get_instance(); |
| 68 | + AdminMain::get_instance(); |
56 | 69 | }
|
57 | 70 |
|
58 | 71 | if ( defined( 'WP_CLI' ) && WP_CLI ) {
|
59 |
| - \WP_CLI::add_command( 'multisite-shared-blocks', \Beapi\MultisiteSharedBlocks\Cli::class ); |
| 72 | + \WP_CLI::add_command( 'multisite-shared-blocks', Cli::class ); |
| 73 | + } |
| 74 | +} |
| 75 | + |
| 76 | +/** |
| 77 | + * Handle multisite support issue. |
| 78 | + * |
| 79 | + * Deactivate the plugin and display an admin notices to users if they are able to manage plugins. |
| 80 | + * |
| 81 | + * @return void |
| 82 | + */ |
| 83 | +function handle_multisite_support_issue(): void { |
| 84 | + if ( wp_doing_ajax() || ! current_user_can( 'activate_plugins' ) ) { |
| 85 | + return; |
60 | 86 | }
|
| 87 | + |
| 88 | + // Deactivate plugin |
| 89 | + deactivate_plugins( __FILE__ ); |
| 90 | + unset( $_GET['activate'] ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 91 | + |
| 92 | + // Display admin notices |
| 93 | + add_action( |
| 94 | + 'admin_notices', |
| 95 | + function () { |
| 96 | + echo '<div class="notice error">'; |
| 97 | + echo sprintf( '<p>%s</p>', esc_html__( 'Multisite Shared Blocks require a multisite installation to work.', 'multisite-shared-blocks' ) ); |
| 98 | + echo '</div>'; |
| 99 | + } |
| 100 | + ); |
61 | 101 | }
|
0 commit comments