-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathinit.php
62 lines (49 loc) · 1.79 KB
/
init.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
<?php
if (!defined("ABSPATH")) {
die("You're not supposed to be here.");
}
$package = json_decode(file_get_contents("package.json", "r"));
$manifest = json_decode(file_get_contents("builder/asset-manifest.json", "r"));
define("WPLFB_VERSION", $package->version);
require_once "classes/class.wp-libre-formbuilder.php";
add_action("admin_enqueue_scripts", function ($hook) use ($package, $manifest) {
global $post;
// make sure we're on the correct view
if ($hook !== 'post-new.php' && $hook !== 'post.php') {
return;
}
if (!in_array($post->post_type, ['wplf-form', 'wplfb-field'])) {
return;
}
$path = plugin_dir_url(__FILE__) . "/builder/";
$version = $package->version;
// wp_enqueue_style("wplfb-css", $path . "main.css", false, $version);
wp_enqueue_style("wplfb-css", $path . $manifest->{"main.css"}, [], $version);
wp_enqueue_script("wplfb-js", $path . $manifest->{"main.js"}, [], $version, true);
$active = get_post_meta($post->ID, "wplfb-enabled", true);
$state = stripslashes(get_post_meta($post->ID, "wplfb-state", true));
// Can only pass strings
wp_localize_script("wplfb-js", "wplfb", [
"isAdmin" => "1",
"state" => $state,
"active" => !empty($active) && $active === "1" ? 1 : 0,
"restURL" => rest_url(),
]);
});
if (function_exists("wplf")) {
add_action("plugins_loaded", function () {
$wplf = wplf();
$builder = WP_Libre_Formbuilder::instance();
$wplf->plugins->register([
"name" => "Formbuilder",
"description" => "Visual editor for the HTML impaired.",
"link" => "https://github.com/k1sul1/wp-libre-formbuilder",
"version" => WPLFB_VERSION,
"instance" => $builder,
"settings_page" => [$builder, "renderSettingsPage"],
]);
});
} else {
// Pre 1.5
WP_Libre_Formbuilder::instance();
}