-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinseri-core.php
103 lines (90 loc) · 3.06 KB
/
inseri-core.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
<?php
/**
* Plugin Name: inseri core
* Description: Scientific and Interactive Gutenberg Blocks to facilitate Open Science
* Requires at least: 6.3
* Requires PHP: 7.4
* Version: 1.0.0
* Author: inseri.swiss
* Author URI: https://inseri.swiss
* License: GPL-3.0-or-later
* License URI: https://www.gnu.org/licenses/gpl-3.0.html
* Text Domain: inseri-core
*
* @package inseri
*
* inseri core is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* inseri core is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with inseri core. If not, see <http://www.gnu.org/licenses/>.
*/
// Exit if accessed directly
if (!defined('ABSPATH')) {
exit();
}
require_once plugin_dir_path(__FILE__) . 'includes/blueprint.php';
require_once plugin_dir_path(__FILE__) . 'includes/rest_api.php';
require_once plugin_dir_path(__FILE__) . 'includes/utils.php';
$inseri_core_blueprint_builder = new inseri_core\Builder();
$inseri_core_rest_api = new inseri_core\RestApi($inseri_core_blueprint_builder);
/**
* main script
*/
add_action('init', function () {
global $wp_scripts;
$handle_path_pairs = [
['inseri-core', 'inseri-core'],
['inseri-core-editor', 'inseri-core-editor'],
['inseri-core-python-worker', 'blocks/python/worker'],
['inseri-core-javascript-worker', 'blocks/javascript/worker'],
];
foreach ($handle_path_pairs as [$handle, $path]) {
$asset_file = include plugin_dir_path(__FILE__) . "build/{$path}.asset.php";
wp_register_script($handle, plugins_url("build/{$path}.js", __FILE__), $asset_file['dependencies'], $asset_file['version']);
}
wp_localize_script('inseri-core', 'inseriApiSettings', [
'root' => esc_url_raw(rest_url()),
'nonce' => wp_create_nonce('wp_rest'),
'pyWorker' => $wp_scripts->registered['inseri-core-python-worker']->src,
'jsWorker' => $wp_scripts->registered['inseri-core-javascript-worker']->src,
]);
});
/**
* Blocks
*/
add_filter('block_categories_all', 'inseri_core_add_block_category');
function inseri_core_add_block_category($block_categories) {
return array_merge(
[
[
'slug' => 'inseri',
'title' => 'inseri',
],
],
$block_categories
);
}
add_action('init', 'inseri_core_block_init');
function inseri_core_block_init() {
$blocks = inseri_core\get_blocks();
foreach ($blocks as $block) {
register_block_type($block);
}
}
/**
* Enable additional file MIMEs
*/
add_filter('upload_mimes', 'inseri_core\extend_upload_mimes');
add_filter('wp_check_filetype_and_ext', 'inseri_core\wp_check_filetype_and_ext', 10, 4);
/**
* REST API
*/
add_action('rest_api_init', [$inseri_core_rest_api, 'register_routes']);