-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
103 lines (86 loc) · 3.56 KB
/
index.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
namespace Tangible\FieldsExample;
use tangible\framework;
defined('ABSPATH') or die();
$plugin = \tangible\create_object([
'name' => 'tangible-field-example',
'title' => 'Tangible Field Example',
'setting_prefix' => 'tangible_field_example',
'version' => tangible_fields()->version,
'file_path' => __FILE__,
'base_path' => plugin_basename( __FILE__ ),
'dir_path' => plugin_dir_path( __FILE__ ),
'url' => framework\module_url( '/', __FILE__ ),
'assets_url' => framework\module_url( '/../assets', __FILE__ ),
]);
if (!function_exists('tangible_field_example')) {
function tangible_field_example($instance = false) {
static $plugin;
return $plugin ? $plugin : ($plugin = $instance);
}
}
tangible_field_example($plugin);
require_once __DIR__ . '/ajax/index.php';
require_once __DIR__ . '/Documentation.php';
require_once __DIR__ . '/register/index.php';
require_once __DIR__ . '/enqueue.php';
framework\register_admin_menu([
'name' => 'tangible-field-example',
'title' => 'Fields Example',
// 'css' => $plugin->assets_url . '/build/settings.min.css',
// 'js' => $plugin->assets_url . '/build/settings.min.js',
'callback' => function() use ($fields, $plugin) {
$documentation = Documentation::$instance;
$plugin->enqueue();
$current_page = $_GET['type'] ?? 'introduction';
$current_section = $_GET['section'] ?? 'introduction';
if( $current_page && $current_section ) {
$documentation->register_page_fields($current_section, $current_page);
}
$current_context = $_GET['context'] ?? 'default';
$current_page_url = admin_url( sprintf('admin.php?%s', http_build_query($_GET)) );
$fields->set_context($current_context);
?>
<form method="POST">
<script>window.addEventListener('load', () => hljs.highlightAll())</script>
<div class="tangible-field-example-settings">
<div class="tf-example-container">
<!-- Sidebar -->
<div class="tf-example-list">
<!-- Change context select -->
<strong>Context</strong>
<div class="tf-context-select-container">
<select id="tf-context-select">
<?php foreach( $fields->contexts as $context ): ?>
<option value="<?= $context ?>" <?= $context === $current_context ? 'selected' : '' ?>>
<?= ucfirst($context) ?>
</option>
<?php endforeach; ?>
</select>
</div>
<!-- Links -->
<?php foreach($documentation->sections as $section_slug => $section): ?>
<strong><?= $section['title'] ?></strong>
<ul>
<?php foreach($section['pages'] as $slug => $page): ?>
<li style="<?= $current_page === $slug ? 'font-weight: bold' : '' ?>">
<a href="<?= $current_page_url ?>&type=<?= $slug ?>§ion=<?= $section_slug ?>">
<?= $page['title'] ?>
</a>
</li>
<?php endforeach; ?>
</ul>
<?php endforeach; ?>
</div>
<!-- Content -->
<?php if( !empty($current_page) && !empty($current_section) ): ?>
<div class="tf-example-field">
<?php $documentation->require_template($current_section, $current_page) ?>
</div>
<?php endif; ?>
</div>
</div>
<form>
<?php
}
]);