Skip to content

Commit f1858b3

Browse files
authored
Merge pull request #4 from BeAPI/version/1.0.1
Version/1.0.1
2 parents 43c00d0 + c61dc4e commit f1858b3

File tree

5 files changed

+60
-45
lines changed

5 files changed

+60
-45
lines changed

.plugin-data

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"version": "1.0.0",
2+
"version": "1.0.1",
33
"slug": "multisite-shared-blocks"
44
}

includes/Main.php

Lines changed: 0 additions & 29 deletions
This file was deleted.

multisite-shared-blocks.php

Lines changed: 53 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Plugin Name: Multisite Shared Blocks
44
* Plugin URI: https://github.com/BeAPI/multisite-shared-blocks
55
* Description: Share blocks between network's sites.
6-
* Version: 1.0.0
6+
* Version: 1.0.1
77
* Requires at least: 5.9
88
* Requires PHP: 7.2
99
* Author: Be API Technical team
@@ -14,6 +14,13 @@
1414
* Network: true
1515
*/
1616

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+
1724
// Don't load directly
1825
if ( ! defined( 'ABSPATH' ) ) {
1926
die( '-1' );
@@ -24,7 +31,7 @@
2431
}
2532

2633
// Plugin constants
27-
define( 'MULTISITE_SHARED_BLOCKS_VERSION', '1.0.0' );
34+
define( 'MULTISITE_SHARED_BLOCKS_VERSION', '1.0.1' );
2835
define( 'MULTISITE_SHARED_BLOCKS_CACHE_VERSION', '1' );
2936
define( 'MULTISITE_SHARED_BLOCKS_VIEWS_FOLDER_NAME', 'multisite-shared-blocks' );
3037

@@ -33,29 +40,62 @@
3340
define( 'MULTISITE_SHARED_BLOCKS_DIR', plugin_dir_path( __FILE__ ) );
3441
define( 'MULTISITE_SHARED_BLOCKS_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
3542

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+
3650
register_activation_hook( __FILE__, [ \Beapi\MultisiteSharedBlocks\Plugin::class, 'activate' ] );
3751

38-
add_action( 'plugins_loaded', 'init_multisite_shared_blocks_plugin' );
52+
add_action( 'plugins_loaded', __NAMESPACE__ . '\\init' );
3953
/**
4054
* Init the plugin
4155
*/
42-
function init_multisite_shared_blocks_plugin(): void {
56+
function init(): void {
4357

4458
// Register custom table and check for schema updates
45-
\Beapi\MultisiteSharedBlocks\Database::setup();
59+
Database::setup();
4660

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();
5366

5467
if ( is_admin() ) {
55-
\Beapi\MultisiteSharedBlocks\Admin\Main::get_instance();
68+
AdminMain::get_instance();
5669
}
5770

5871
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;
6086
}
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+
);
61101
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "multisite-shared-blocks",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "Share blocks between network's sites.",
55
"main": "build/index.js",
66
"scripts": {

readme.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Contributors: beapi, momo360modena, rahe, asadowski10, petitphp
33
Tags: network, multisite, block, share, gutenberg
44
Requires at least: 5.9
55
Tested up to: 6.0
6-
Stable tag: 1.0.0
6+
Stable tag: 1.0.1
77
Requires PHP: 7.2
88
License: GPL v2 or later
99
License URI: https://www.gnu.org/licenses/gpl-2.0.html
@@ -26,5 +26,9 @@ This plugin allow contributors to share blocks from posts on the network. Other
2626

2727
== Changelog ==
2828

29+
= 1.0.1 - 2022-10-07 =
30+
* Add check for multisite installation
31+
* WP.org release
32+
2933
= 1.0.0 - 2022-09-02 =
3034
* Initial plugin release

0 commit comments

Comments
 (0)