Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .plugin-data
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"version": "1.0.0",
"version": "1.0.1",
"slug": "multisite-shared-blocks"
}
29 changes: 0 additions & 29 deletions includes/Main.php

This file was deleted.

66 changes: 53 additions & 13 deletions multisite-shared-blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Multisite Shared Blocks
* Plugin URI: https://github.com/BeAPI/multisite-shared-blocks
* Description: Share blocks between network's sites.
* Version: 1.0.0
* Version: 1.0.1
* Requires at least: 5.9
* Requires PHP: 7.2
* Author: Be API Technical team
Expand All @@ -14,6 +14,13 @@
* Network: true
*/

namespace Beapi\MultisiteSharedBlocks;

use Beapi\MultisiteSharedBlocks\Admin\Main as AdminMain;
use Beapi\MultisiteSharedBlocks\Blocks\SharedBlock;
use Beapi\MultisiteSharedBlocks\Gutenberg\SharedBlocksAttributes;
use Beapi\MultisiteSharedBlocks\Rest\Rest;

// Don't load directly
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
Expand All @@ -24,7 +31,7 @@
}

// Plugin constants
define( 'MULTISITE_SHARED_BLOCKS_VERSION', '1.0.0' );
define( 'MULTISITE_SHARED_BLOCKS_VERSION', '1.0.1' );
define( 'MULTISITE_SHARED_BLOCKS_CACHE_VERSION', '1' );
define( 'MULTISITE_SHARED_BLOCKS_VIEWS_FOLDER_NAME', 'multisite-shared-blocks' );

Expand All @@ -33,29 +40,62 @@
define( 'MULTISITE_SHARED_BLOCKS_DIR', plugin_dir_path( __FILE__ ) );
define( 'MULTISITE_SHARED_BLOCKS_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );

// Plugin only support multisite installation.
if ( ! is_multisite() ) {
add_action( 'admin_init', __NAMESPACE__ . '\\handle_multisite_support_issue' );

return;
}

register_activation_hook( __FILE__, [ \Beapi\MultisiteSharedBlocks\Plugin::class, 'activate' ] );

add_action( 'plugins_loaded', 'init_multisite_shared_blocks_plugin' );
add_action( 'plugins_loaded', __NAMESPACE__ . '\\init' );
/**
* Init the plugin
*/
function init_multisite_shared_blocks_plugin(): void {
function init(): void {

// Register custom table and check for schema updates
\Beapi\MultisiteSharedBlocks\Database::setup();
Database::setup();

\Beapi\MultisiteSharedBlocks\Main::get_instance();
\Beapi\MultisiteSharedBlocks\Gutenberg\SharedBlocksAttributes::get_instance();
\Beapi\MultisiteSharedBlocks\Blocks\SharedBlock::get_instance();
\Beapi\MultisiteSharedBlocks\Listener::get_instance();
\Beapi\MultisiteSharedBlocks\Rest\Rest::get_instance();
\Beapi\MultisiteSharedBlocks\Preview::get_instance();
SharedBlocksAttributes::get_instance();
SharedBlock::get_instance();
Listener::get_instance();
Rest::get_instance();
Preview::get_instance();

if ( is_admin() ) {
\Beapi\MultisiteSharedBlocks\Admin\Main::get_instance();
AdminMain::get_instance();
}

if ( defined( 'WP_CLI' ) && WP_CLI ) {
\WP_CLI::add_command( 'multisite-shared-blocks', \Beapi\MultisiteSharedBlocks\Cli::class );
\WP_CLI::add_command( 'multisite-shared-blocks', Cli::class );
}
}

/**
* Handle multisite support issue.
*
* Deactivate the plugin and display an admin notices to users if they are able to manage plugins.
*
* @return void
*/
function handle_multisite_support_issue(): void {
if ( wp_doing_ajax() || ! current_user_can( 'activate_plugins' ) ) {
return;
}

// Deactivate plugin
deactivate_plugins( __FILE__ );
unset( $_GET['activate'] ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended

// Display admin notices
add_action(
'admin_notices',
function () {
echo '<div class="notice error">';
echo sprintf( '<p>%s</p>', esc_html__( 'Multisite Shared Blocks require a multisite installation to work.', 'multisite-shared-blocks' ) );
echo '</div>';
}
);
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "multisite-shared-blocks",
"version": "1.0.0",
"version": "1.0.1",
"description": "Share blocks between network's sites.",
"main": "build/index.js",
"scripts": {
Expand Down
6 changes: 5 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Contributors: beapi, momo360modena, rahe, asadowski10, petitphp
Tags: network, multisite, block, share, gutenberg
Requires at least: 5.9
Tested up to: 6.0
Stable tag: 1.0.0
Stable tag: 1.0.1
Requires PHP: 7.2
License: GPL v2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Expand All @@ -26,5 +26,9 @@ This plugin allow contributors to share blocks from posts on the network. Other

== Changelog ==

= 1.0.1 - 2022-10-07 =
* Add check for multisite installation
* WP.org release

= 1.0.0 - 2022-09-02 =
* Initial plugin release