-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathembed-block-figma.php
99 lines (89 loc) · 3.04 KB
/
embed-block-figma.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
<?php
/**
* Plugin Name: Embed Block for Figma
* Plugin URI: https://github.com/10up/embed-block-figma
* Description: Adds a Figma embed block to the WordPress Block Editor.
* Version: 0.3.1
* Requires at least: 6.5
* Requires PHP: 7.4
* Author: 10up
* Author URI: https://10up.com
* License: GPL-2.0-or-later
* License URI: https://spdx.org/licenses/GPL-2.0-or-later.html
* Text Domain: embed-block-figma
* Domain Path: /languages
*
* @package FigmaBlock
*/
namespace FigmaBlock;
use function TenUpToolkit\set_dist_url_path;
// Useful global constants.
define( 'FIGMA_BLOCK_VERSION', '0.3.1' );
define( 'FIGMA_BLOCK_URL', plugin_dir_url( __FILE__ ) );
define( 'FIGMA_BLOCK_PATH', plugin_dir_path( __FILE__ ) );
define( 'FIGMA_BLOCK_INC', FIGMA_BLOCK_PATH . 'includes/' );
define( 'FIGMA_BLOCK_DIST_URL', FIGMA_BLOCK_URL . 'dist/' );
define( 'FIGMA_BLOCK_DIST_PATH', FIGMA_BLOCK_PATH . 'dist/' );
/**
* Get the minimum version of PHP required by this plugin.
*
* @return string Minimum version required.
*/
function minimum_php_requirement() {
return '7.4';
}
/**
* Whether PHP installation meets the minimum requirements
*
* @return bool True if meets minimum requirements, false otherwise.
*/
function site_meets_php_requirements() {
return version_compare( phpversion(), minimum_php_requirement(), '>=' );
}
// Ensuring our PHP version requirement is met first before loading plugin.
if ( ! site_meets_php_requirements() ) {
add_action(
'admin_notices',
function () {
?>
<div class="notice notice-error">
<p>
<?php
echo wp_kses_post(
sprintf(
/* translators: %s: Minimum required PHP version */
__( 'The Embed Block for Figma plugin requires PHP version %s or later. Please upgrade PHP or disable the plugin.', 'embed-block-figma' ),
esc_html( minimum_php_requirement() )
)
);
?>
</p>
</div>
<?php
}
);
return;
}
// Require Composer autoloader if it exists.
if ( file_exists( __DIR__ . '/vendor/autoload.php' ) ) {
require_once __DIR__ . '/vendor/autoload.php';
} else {
add_action(
'admin_notices',
function () {
$message = __( 'Error: Please run $ composer install in the Embed Block for Figma plugin directory.', 'embed-block-figma' );
printf( '<div class="%1$s"><p>%2$s</p></div>', 'notice notice-error', esc_html( $message ) );
error_log( esc_html( $message ) ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
}
);
return;
}
$is_local_env = in_array( wp_get_environment_type(), [ 'local', 'development' ], true );
$is_local_url = strpos( home_url(), '.test' ) || strpos( home_url(), '.local' );
$is_local = $is_local_env || $is_local_url;
if ( $is_local && file_exists( __DIR__ . '/dist/fast-refresh.php' ) && function_exists( '\TenUpToolkit\set_dist_url_path' ) ) {
require_once __DIR__ . '/dist/fast-refresh.php';
set_dist_url_path( basename( __DIR__ ), FIGMA_BLOCK_DIST_URL, FIGMA_BLOCK_DIST_PATH );
}
$plugin = Plugin::get_instance();
$plugin->enable();