-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathblock-areas.php
More file actions
140 lines (130 loc) · 3.43 KB
/
block-areas.php
File metadata and controls
140 lines (130 loc) · 3.43 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?php
/**
* Plugin initialization file
*
* @package WP_Rig\Block_Areas
* @license GNU General Public License v2 (or later)
* @link https://wordpress.org/plugins/block-areas
*
* @wordpress-plugin
* Plugin Name: Block Areas
* Plugin URI: https://wordpress.org/plugins/block-areas
* Description: Introduces a simple method for defining block areas to use the block editor outside of the post content.
* Version: 0.2.0
* Author: The WP Rig Contributors
* Author URI: https://github.com/wprig
* License: GNU General Public License v2 (or later)
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: block-areas
*/
/* This file must be parseable by PHP 5.2. */
/**
* Gets the block areas API instance.
*
* Do not call this function before the plugin has been loaded.
*
* @since 0.1.0
*
* @return WP_Rig\Block_Areas\Block_Areas
*/
function block_areas() {
return call_user_func( [ 'WP_Rig\\Block_Areas\\Plugin', 'instance' ] )->block_areas();
}
/**
* Loads the plugin.
*
* @since 0.1.0
* @access private
*/
function block_areas_load() {
if ( version_compare( phpversion(), '7.0', '<' ) ) {
add_action( 'admin_notices', 'block_areas_display_php_version_notice' );
return;
}
if ( version_compare( get_bloginfo( 'version' ), '5.0', '<' ) ) {
add_action( 'admin_notices', 'block_areas_display_wp_version_notice' );
return;
}
// Load Composer autoloader or custom autoloader.
if ( ! class_exists( 'WP_Rig\\Block_Areas\\Plugin' ) ) {
if ( file_exists( __DIR__ . '/vendor/autoload.php' ) ) {
require __DIR__ . '/vendor/autoload.php';
} else {
spl_autoload_register( 'block_areas_autoload' );
}
}
call_user_func( [ 'WP_Rig\\Block_Areas\\Plugin', 'load' ], __FILE__ );
}
/**
* Custom autoloader function for plugin classes.
*
* Simplified autoloader that respects PSR-4 specific to the plugin.
*
* @since 1.0.0
* @access private
*
* @param string $class_name Class name to load.
* @return bool True if the class was loaded, false otherwise.
*/
function block_areas_autoload( $class_name ) {
$namespace = 'WP_Rig\Block_Areas';
if ( strpos( $class_name, $namespace . '\\' ) !== 0 ) {
return false;
}
$parts = explode( '\\', substr( $class_name, strlen( $namespace . '\\' ) ) );
$path = plugin_dir_path( __FILE__ ) . 'src';
foreach ( $parts as $part ) {
$path .= '/' . $part;
}
$path .= '.php';
if ( ! file_exists( $path ) ) {
return false;
}
require_once $path;
return true;
}
/**
* Displays an admin notice about an unmet PHP version requirement.
*
* @since 0.1.0
* @access private
*/
function block_areas_display_php_version_notice() {
?>
<div class="notice notice-error">
<p>
<?php
sprintf(
/* translators: 1: required version, 2: currently used version */
__( 'Block Areas requires at least PHP version %1$s. Your site is currently running on PHP %2$s.', 'block-areas' ),
'7.0',
phpversion()
);
?>
</p>
</div>
<?php
}
/**
* Displays an admin notice about an unmet WordPress version requirement.
*
* @since 0.1.0
* @access private
*/
function block_areas_display_wp_version_notice() {
?>
<div class="notice notice-error">
<p>
<?php
sprintf(
/* translators: 1: required version, 2: currently used version */
__( 'Block Areas requires at least WordPress version %1$s. Your site is currently running on WordPress %2$s.', 'block-areas' ),
'5.0',
get_bloginfo( 'version' )
);
?>
</p>
</div>
<?php
}
block_areas_load();