143 lines
3.0 KiB
PHP
143 lines
3.0 KiB
PHP
<?php
|
|
/**
|
|
* Main plugin bootstrap.
|
|
*
|
|
* @package ModernAudioPlayer
|
|
*/
|
|
|
|
namespace ModernAudioPlayer;
|
|
|
|
defined( 'ABSPATH' ) || exit;
|
|
|
|
class Plugin {
|
|
/**
|
|
* Settings service.
|
|
*
|
|
* @var Settings
|
|
*/
|
|
private $settings;
|
|
|
|
/**
|
|
* Admin service.
|
|
*
|
|
* @var Admin
|
|
*/
|
|
private $admin;
|
|
|
|
/**
|
|
* Shortcode service.
|
|
*
|
|
* @var Shortcode
|
|
*/
|
|
private $shortcode;
|
|
|
|
/**
|
|
* REST service.
|
|
*
|
|
* @var Rest_API
|
|
*/
|
|
private $rest_api;
|
|
|
|
/**
|
|
* Initialize service objects.
|
|
*/
|
|
public function __construct() {
|
|
$this->settings = new Settings();
|
|
$this->admin = new Admin();
|
|
$this->shortcode = new Shortcode();
|
|
$this->rest_api = new Rest_API();
|
|
}
|
|
|
|
/**
|
|
* Plugin activation callback.
|
|
*
|
|
* @return void
|
|
*/
|
|
public static function activate() {
|
|
Settings::maybe_install_defaults();
|
|
Analytics::create_table();
|
|
}
|
|
|
|
/**
|
|
* Register hooks.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function init() {
|
|
add_action( 'init', array( $this, 'load_textdomain' ) );
|
|
add_action( 'init', array( $this, 'register_block' ) );
|
|
|
|
$this->shortcode->register();
|
|
$this->admin->register();
|
|
$this->rest_api->register();
|
|
}
|
|
|
|
/**
|
|
* Load translations.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function load_textdomain() {
|
|
load_plugin_textdomain( 'modern-audio-player', false, dirname( plugin_basename( MAP_PLUGIN_FILE ) ) . '/languages' );
|
|
}
|
|
|
|
/**
|
|
* Register the Gutenberg block.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function register_block() {
|
|
register_block_type_from_metadata(
|
|
MAP_PLUGIN_DIR . 'blocks/block.json',
|
|
array(
|
|
'render_callback' => array( $this, 'render_block' ),
|
|
)
|
|
);
|
|
|
|
$this->register_legacy_block_alias();
|
|
}
|
|
|
|
/**
|
|
* Server-render block markup.
|
|
*
|
|
* @param array<string, mixed> $attributes Block attributes.
|
|
* @return string
|
|
*/
|
|
public function render_block( $attributes ) {
|
|
return Renderer::render_player( (array) $attributes, is_admin() ? 'editor' : 'frontend' );
|
|
}
|
|
|
|
/**
|
|
* Register the legacy block name as an alias for backward compatibility.
|
|
*
|
|
* @return void
|
|
*/
|
|
private function register_legacy_block_alias() {
|
|
$primary_block = \WP_Block_Type_Registry::get_instance()->get_registered( 'velora/audio-player' );
|
|
|
|
if ( ! $primary_block ) {
|
|
return;
|
|
}
|
|
|
|
register_block_type(
|
|
'map/audio-player',
|
|
array(
|
|
'api_version' => $primary_block->api_version,
|
|
'title' => $primary_block->title,
|
|
'category' => $primary_block->category,
|
|
'icon' => $primary_block->icon,
|
|
'description' => $primary_block->description,
|
|
'keywords' => $primary_block->keywords,
|
|
'attributes' => $primary_block->attributes,
|
|
'supports' => $primary_block->supports,
|
|
'style_handles' => $primary_block->style_handles,
|
|
'editor_style_handles' => $primary_block->editor_style_handles,
|
|
'script_handles' => $primary_block->script_handles,
|
|
'editor_script_handles'=> $primary_block->editor_script_handles,
|
|
'render_callback' => array( $this, 'render_block' ),
|
|
)
|
|
);
|
|
}
|
|
|
|
}
|