forked from getblocklab/block-lab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblock-lab.php
133 lines (116 loc) · 3.5 KB
/
block-lab.php
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
<?php
/**
* Block Lab
*
* @package Block_Lab
* @copyright Copyright(c) 2019, Block Lab
* @license http://opensource.org/licenses/GPL-2.0 GNU General Public License, version 2 (GPL-2.0)
*
* Plugin Name: Block Lab
* Plugin URI: https://getblocklab.com
* Description: The easy way to build custom blocks for Gutenberg.
* Version: 1.3.5
* Author: Block Lab
* Author URI: https://getblocklab.com
* License: GPL2
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: block-lab
* Domain Path: languages
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
// Setup the plugin auto loader.
require_once 'php/autoloader.php';
/**
* Admin notice for incompatible versions of PHP.
*/
function block_lab_php_version_error() {
printf( '<div class="error"><p>%s</p></div>', esc_html( block_lab_php_version_text() ) );
}
/**
* String describing the minimum PHP version.
*
* "Namespace" is a PHP 5.3 introduced feature. This is a hard requirement
* for the plugin structure.
*
* "Traits" is a PHP 5.4 introduced feature. Remove "Traits" support from
* php/autoloader if you want to support a lower PHP version.
* Remember to update the checked version below if you do.
*
* @return string
*/
function block_lab_php_version_text() {
return __( 'Block Lab plugin error: Your version of PHP is too old to run this plugin. You must be running PHP 5.4 or higher.', 'block-lab' );
}
// If the PHP version is too low, show warning and return.
if ( version_compare( phpversion(), '5.4', '<' ) ) {
if ( defined( 'WP_CLI' ) ) {
WP_CLI::warning( block_lab_php_version_text() );
} else {
add_action( 'admin_notices', 'block_lab_php_version_error' );
}
return;
}
/**
* Admin notice for incompatible versions of WordPress or missing Gutenberg Plugin.
*/
function block_lab_wp_version_error() {
printf( '<div class="error"><p>%s</p></div>', esc_html( block_lab_wp_version_text() ) );
}
/**
* String describing the minimum WP version or Gutenberg Plugin requirement.
*
* "Blocks" are a feature of WordPress 5.0+ or require the Gutenberg plugin.
*
* @return string
*/
function block_lab_wp_version_text() {
return __( 'Block Lab plugin error: Your version of WordPress is too old. You must be running WordPress 5.0 to use Block Lab.', 'block-lab' );
}
// If the WordPress version is too low, show warning and return.
if ( ! function_exists( 'register_block_type' ) ) {
if ( defined( 'WP_CLI' ) ) {
WP_CLI::warning( block_lab_wp_version_text() );
} else {
add_action( 'admin_notices', 'block_lab_wp_version_error' );
}
}
// Load some helpers.
require_once __DIR__ . '/php/helpers.php';
// Handle deprecated functions.
require_once __DIR__ . '/php/deprecated.php';
/**
* Get the plugin object.
*
* @return \Block_Lab\Plugin
*/
function block_lab() {
static $instance;
if ( null === $instance ) {
$instance = new \Block_Lab\Plugin();
}
return $instance;
}
/**
* Setup the plugin instance.
*/
block_lab()
->set_basename( plugin_basename( __FILE__ ) )
->set_directory( plugin_dir_path( __FILE__ ) )
->set_file( __FILE__ )
->set_slug( 'block-lab' )
->set_url( plugin_dir_url( __FILE__ ) )
->set_version( __FILE__ )
->set_util();
/**
* Register plugin components.
*/
block_lab()
->register_component( new \Block_Lab\Post_Types\Block_Post() )
->register_component( new \Block_Lab\Blocks\Loader() );
/**
* Sometimes we need to do some things after the plugin is loaded, so call the Plugin_Interface::plugin_loaded().
*/
add_action( 'plugins_loaded', array( block_lab(), 'plugin_loaded' ) );