forked from typisttech/wp-better-settings
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwp-better-settings.php
105 lines (91 loc) · 2.77 KB
/
wp-better-settings.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
<?php
/**
* WP Better Settings
*
* A simplified OOP implementation of the WP Settings API.
*
* @package TypistTech\WPBetterSettings
*
* @author Typist Tech <[email protected]>
* @copyright 2017 Typist Tech
* @license GPL-2.0+
*
* @see https://www.typist.tech/projects/wp-better-settings
* @see https://github.com/TypistTech/wp-better-settings
*/
/**
* Plugin Name: WP Better Settings
* Plugin URI: https://github.com/TypistTech/wp-better-settings
* Description: Example Plugin for WP Better Settings
* Version: 0.14.0
* Author: Tang Rufus
* Author URI: https://www.typist.tech/
* Text Domain: wp-better-settings
* Domain Path: src/languages
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
*/
declare(strict_types=1);
namespace TypistTech\WPBetterSettings;
use TypistTech\WPOptionStore\Factory as OptionStoreFactory;
// If this file is called directly, abort.
if (! defined('WPINC')) {
die;
}
require_once __DIR__ . '/vendor/autoload.php';
const WPBS_DEMO_PAGE_SLUG = 'wpbs-demo';
add_action(
'admin_init',
function () {
$builder = new Builder(
OptionStoreFactory::build()
);
$basicSection = new Section(
'basic-fields',
'Basic Fields'
);
$basicSection->add(
$builder->text('my_text', 'My Text'),
$builder->password('my_password', 'My Password'),
$builder->email('my_email', 'My Email'),
$builder->url('my_url', 'My Url'),
$builder->number('my_number', 'My Number'),
$builder->textarea('my_textarea', 'My Textarea'),
$builder->checkbox('my_checkbox', 'My Checkbox'),
$builder->select(
'my_select',
'My Select',
[
'a' => 'Option A',
'b' => 'Option B',
'c' => 'Option C',
]
)
);
$registrar = new Registrar(WPBS_DEMO_PAGE_SLUG);
$registrar->add($basicSection);
$registrar->run();
}
);
add_action(
'admin_menu',
function () {
add_menu_page(
'WPBS Demo',
'WP Better Settings Demo',
'manage_options',
WPBS_DEMO_PAGE_SLUG,
function () {
echo '<div class="wrap">';
settings_errors();
echo '<h1>' . esc_html(get_admin_page_title()) . '</h1>';
echo '<form action="options.php" method="post">';
settings_fields(WPBS_DEMO_PAGE_SLUG);
do_settings_sections(WPBS_DEMO_PAGE_SLUG);
submit_button();
echo '</form>';
echo '</div>';
}
);
}
);