-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_stool.php
More file actions
186 lines (167 loc) · 5.8 KB
/
_stool.php
File metadata and controls
186 lines (167 loc) · 5.8 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
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<?php
/*************************************************************************
Plugin Name: _stool
Plugin URI: https://vincurekf.cz/stool
Description: Simple Tools that bring custom post types, cached queries, metaboxes and AJAX capabilities to your theme.
Version: 1.0.8
Author: Filip Vincůrek
Author URI: https://vincurekf.cz
**************************************************************************
MIT License
Copyright (c) 2020 Filip Vincůrek (https://vincurekf.cz)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
**************************************************************************/
// Plugin Version
define('_STOOL_VERSION', '1.0.8');
define('_STOOL_TESTEDWP', '5.5.1');
// If this file is called directly, abort.
if (!defined('WPINC')) {
return;
}
// Plugin Root Folder
define('_STOOL_ROOT', dirname(__FILE__));
// Plugin Root Folder
define('_STOOL_URI', plugin_dir_url(__FILE__));
// Cache Config
define('_STOOL_USECACHE', get_option('_stool_transient_use'));
// Disable comments
define('_STOOL_DISABLE_COMMENTS', get_option('_stool_disable_comments'));
// Sanitize filenames
define('_STOOL_SANITIZE_FILENAMES', get_option('_stool_sanitize_filenames'));
// Is current session admins
define('_STOOL_IS_ADMIN', is_admin());
// Purge cache on post save
define('_STOOL_PURGE_CACHE', get_option('_stool_purge_cache'));
// Keep track of displayed posts
define('_STOOL_TRACK_POSTS', get_option('_stool_keep_track_of_post_ids'));
if (_STOOL_USECACHE) {
$_stool_transient_expiry = get_option('_stool_transient_expiry');
define('_STOOL_CACHEEXP', $_stool_transient_expiry ? $_stool_transient_expiry * 60 : 5 * 60);
}
require __DIR__ . '/vendor/autoload.php';
require __DIR__ . '/class/_autoload.php';
//
$dynamicFields = json_decode(get_option('_stool_posttypes', null), true);
if (!is_null($dynamicFields) && !empty($dynamicFields)) {
foreach ($dynamicFields as $type) {
//
_stool\Posts::addType($type);
//
if (isset($type["metaboxes"]) && !empty($type["metaboxes"])) {
$posmetabox = new _stool\Metabox($type["slug"], 'main_metabox', $type["main"] . ' Meta', 'side');
foreach ($type["metaboxes"] as $metabox) {
$posmetabox->addField(array(
"key" => $metabox["key"],
"label" => $metabox["label"],
"type" => $metabox["type"],
"media_type" => $metabox["media_type"],
"options" => isset($metabox["options"]) ? $metabox["options"] : array()
));
}
$posmetabox->init();
}
}
}
//
_stool\Core::init();
_stool\Posts::init();
_stool\Customizer::init();
//
if (_STOOL_IS_ADMIN) {
_stool\Admin::init();
_stool\Dashboard::init();
//
_stool\Settings::addSection("global", array(
"title" => "Global",
"fields" => array(
"_stool_transient_use" => array(
"label" => "Use cache for posts",
"tooltip" => "Cache posts internaly (turning this option ON will help decrease server load)",
"type" => "checkbox",
"default" => null
),
"_stool_transient_expiry" => array(
"label" => "Cache expiration time",
"tooltip" => "For how long to keep post queries in cache",
"type" => "range",
"options" => array(
"min" => 5,
"max" => 1440,
"step" => 5,
"unit" => "minutes"
),
"default" => 15,
"condition" => "form.data._stool_transient_use === true"
),
"_stool_purge_cache" => array(
"label" => "Purge cache upon save",
"tooltip" => "Purge internal cache upon post save",
"type" => "checkbox",
"default" => null
),
"_stool_disable_comments" => array(
"label" => "Completely disbale comments on site",
"tooltip" => "This toggle will completely disable comments everywhere on your site, including admin menu and old posts.",
"type" => "checkbox",
"default" => null
),
"_stool_sanitize_filenames" => array(
"label" => "Sanitize uploaded file names",
"tooltip" => "Checking this will make sure that all special and illegal characters are removed from uploaded file names.",
"type" => "checkbox",
"default" => null
),
"_stool_keep_track_of_post_ids" => array(
"label" => "Keep track of displayed posts",
"tooltip" => "Adds hook to the_post() action to keep track of displayed posts to ignore them later (in posts widget for example)",
"type" => "checkbox",
"default" => null
)
)
));
//
_stool\Settings::addSection("customizer", array(
"title" => "Customizer",
"fields" => array(
"_stool_customizer" => array(
"label" => "Customizer Fields",
"type" => "customizer",
"tooltip" => "",
"default" => null
)
)
));
//
_stool\Settings::addSection("posttypes", array(
"title" => "Post Types",
"fields" => array(
"_stool_posttypes" => array(
"label" => "Custom Post Types",
"type" => "posttypes",
"tooltip" => "",
"default" => null
)
)
));
//
_stool\Settings::init();
new _stool\Updater(__FILE__, '_stool', null);
}
//
if (_STOOL_DISABLE_COMMENTS) {
_stool\Comments::disable();
}