-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwp-field.php
More file actions
79 lines (66 loc) · 2.5 KB
/
wp-field.php
File metadata and controls
79 lines (66 loc) · 2.5 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
<?php
/**
* Plugin Name: WP_Field — HTML Fields Library for WordPress
* Plugin URI: https://github.com/tikhomirov/wp-field-plugin
* Description: HTML fields library for WordPress, designed as a foundation for custom frameworks, settings systems, and admin UI builders. Includes Fluent API, 52 unique field types (+4 aliases), and React/Vanilla UI.
* Version: 4.0.0
* Requires at least: 6.0
* Tested up to: 7.0
* Requires PHP: 8.3
* Author: Aleksei Tikhomirov
* Author URI: https://rwsite.ru
* License: GPL-2.0-or-later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: wp-field
* Domain Path: /lang/
*/
declare(strict_types=1);
if (! defined('ABSPATH')) {
return;
}
if (! defined('WP_FIELD_PLUGIN_FILE')) {
define('WP_FIELD_PLUGIN_FILE', __FILE__);
}
if (! defined('WP_FIELD_PLUGIN_DIR')) {
define('WP_FIELD_PLUGIN_DIR', __DIR__.'/');
}
if (! defined('WP_FIELD_PLUGIN_URL')) {
define('WP_FIELD_PLUGIN_URL', plugin_dir_url(__FILE__));
}
if (file_exists(WP_FIELD_PLUGIN_DIR.'vendor/autoload.php')) {
require_once WP_FIELD_PLUGIN_DIR.'vendor/autoload.php';
} else {
// Fallback autoloader for environments without Composer
spl_autoload_register(function ($class): void {
$prefix = 'WpField\\';
$base_dir = WP_FIELD_PLUGIN_DIR.'src/';
$len = strlen($prefix);
if (strncmp($prefix, $class, $len) !== 0) {
return;
}
$relative_class = substr($class, $len);
$file = $base_dir.str_replace('\\', '/', $relative_class).'.php';
if (file_exists($file)) {
require $file;
}
});
}
$legacy_enabled = function_exists('apply_filters')
? (bool) apply_filters('wp_field_enable_legacy', true)
: true;
$is_components_page = function_exists('is_admin') && is_admin()
&& isset($_GET['page'])
&& $_GET['page'] === 'wp-field-components';
if ($legacy_enabled && ! $is_components_page) {
// Legacy class + isolated vanilla bootstrap.
require_once WP_FIELD_PLUGIN_DIR.'vanilla/bootstrap.php';
}
// Loading demo pages strictly within WordPress admin debug context.
if (function_exists('is_admin') && is_admin() && defined('WP_DEBUG') && WP_DEBUG) {
if ($legacy_enabled) {
require_once WP_FIELD_PLUGIN_DIR.'vanilla/example.php';
}
// Modern demos: wp-field-components (React docs) + wp-field-ui-demo (Flux UI showcase).
require_once WP_FIELD_PLUGIN_DIR.'examples/components/index.php';
require_once WP_FIELD_PLUGIN_DIR.'examples/ui-demo/index.php';
}