-
-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathwp-rest-blocks.php
More file actions
70 lines (61 loc) · 1.71 KB
/
wp-rest-blocks.php
File metadata and controls
70 lines (61 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
/**
* Plugin Name: REST API Blocks
* Plugin URI: https://github.com/spacedmonkey/wp-rest-blocks
* Description: Add gutenberg blocks data into post / page / widget REST API endpoints.
* Author: Jonathan Harris
* Author URI: https://www.spacedmonkey.com/
* Text Domain: wp-rest-blocks
* Domain Path: /languages
* Version: 2.0.0
* Requires at least: 5.9
* Requires PHP: 7.4
*
* @package WP_REST_Blocks
*/
namespace WP_REST_Blocks;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( is_readable( __DIR__ . '/vendor/autoload.php' ) ) {
require_once __DIR__ . '/vendor/autoload.php';
}
if ( ! class_exists( '\DiDom\Document' ) ) {
/**
* Displays an admin notice about why the plugin is unable to load.
*
* @return void
*/
function admin_notice() {
$message = sprintf(
/* translators: %s: build commands. */
__( ' Please run %s to finish installation.', 'wp-rest-blocks' ),
'<code>composer install</code>'
);
?>
<div class="notice notice-error">
<p><strong><?php esc_html_e( 'REST API Blocks plugin could not be initialized.', 'wp-rest-blocks' ); ?></strong></p>
<p><?php echo wp_kses( $message, [ 'code' => [] ] ); ?></p>
</div>
<?php
}
add_action( 'admin_notices', __NAMESPACE__ . '\admin_notice' );
return;
}
/**
* Initialize the plugin.
*
* @return void
*/
function init_plugin() {
// Create shared Data instance.
$data = new Data();
// Inject Data dependency into Posts and Widgets.
$posts = new Posts( $data );
$widgets = new Widgets( $data );
// Initialize components.
$posts->init();
$widgets->init();
}
add_action( 'plugins_loaded', __NAMESPACE__ . '\init_plugin' );