-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.functions.php
executable file
·460 lines (444 loc) · 14.1 KB
/
example.functions.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
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
<?php
/** debug */
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
global $wpdb,
$wp_rewrite,
$pagenow;
$kitt_instance = KiTT\ThemeSetUp::get_instance();
$kitt_instance->set_up_theme(
$wpdb,
/** reqiured */
$wp_rewrite,
/** reqiured */
$pagenow,
/** reqiured */
[
'set_up' => [
/** custom favicon, logos and login logo url */
'favicon' => $kitt_instance->theme_url . '/image/wp-favicon.png',
'login_logo' => $kitt_instance->theme_url . '/image/wp-login-logo.svg',
'login_logo_url' => WP_HOME,
'admin_bar_logo' => $kitt_instance->theme_url . '/image/wp-admin-bar-logo.svg',
'permalink_structure' => '/%postname%/',
'default_user_role' => 'editor',
'remove_welcome' => true,
/** 1 = Mon, 2 = Thu ... 7 = Sun */
'start_of_week' => 1,
'timezone_string' => 'Europe/Berlin',
'time_format' => 'H:i',
'date_format' => 'd/m/Y',
/**
* install backend languages
*
* list of available translations
* https://translate.wordpress.org/
*
* to remove a translation
* delete the language code and the
* files in the /web/storage/lang directory
*/
'install_languages' => ['de_DE'],
/** configure ACF (Advanced Custom Fields) */
'ACF' => [
/** add background color button to WYSIWYG editor */
'WYSIWYG_BG_color' => true,
'save_load' => [
/** default: null, if null = ACF default -> /themes/your-theme/acf-json */
'JSON_save' => constant('WP_STORAGE_DIR') . '/acf/acf-json',
/** default: null, if null = ACF default -> /themes/your-theme/acf-json */
'JSON_load' => constant('WP_STORAGE_DIR') . '/acf/acf-json',
/** default: null, if null = ACF default -> /themes/your-theme/acf-json */
'AutoSync_JSON_save' => constant('WP_STORAGE_DIR') . '/acf/acf-json',
/** default: null, if null = ACF default -> /themes/your-theme/acf-json */
'AutoSync_JSON_load' => constant('WP_STORAGE_DIR') . '/acf/acf-json',
/** default: null, if null = ACF default -> /themes/your-theme/acf-php */
'AutoSync_PHP_save' => constant('WP_STORAGE_DIR') . '/acf/acf-php',
/** default: null, if null = ACF default -> /themes/your-theme/acf-php */
'AutoSync_PHP_load' => constant('WP_STORAGE_DIR') . '/acf/acf-php'
],
'google_api_key' => false
],
/** add or remove company settings menu page */
'company_settings' => true,
]
]
);
$kitt_instance->post([
/** removes completely the default post section */
'remove_post' => false,
'post' => [
/**
* info:
* https://developer.wordpress.org/reference/functions/remove_post_type_support/
*
* NOTE:
* Gutenberg editor is always disabled
*/
'remove_support' => ['excerpt', 'comments', 'trackbacks', 'author'],
/** inspect the label attribute for="" in the screen options panel */
'remove_meta_box' => ['commentsdiv', 'slugdiv'],
/** en- or disable the SEO meta box */
'SEO' => true,
/** to disable tag support */
'tag' => true,
/** to disable category support */
'category' => true,
/** set default post slug */
'post_slug' => false,
/** rename default post section */
'rename_labels' => [
'name' => 'Posts',
'singular_name' => 'Post',
'menu_name' => 'Posts',
'all_items' => 'All Posts',
'add_new' => 'Add New',
'add_new_item' => 'Add New Post',
'edit' => 'Edit',
'edit_item' => 'Edit Post',
'new_item' => 'New Post',
'view' => 'View',
'view_item' => 'View Post',
'search_items' => 'Search Posts',
'not_found' => 'No Posts found',
'not_found_in_trash' => 'No Posts found in trash'
]
]
]);
$kitt_instance->page([
/** removes completely the default page section */
'remove_page' => false,
'page' => [
/**
* info:
* https://developer.wordpress.org/reference/functions/remove_post_type_support/
*
* NOTE:
* Gutenberg editor is always disabled
*/
'remove_support' => ['excerpt', 'comments', 'trackbacks', 'author'],
/** inspect the label attribute for="" in the screen options panel */
'remove_meta_box' => ['commentsdiv', 'slugdiv'],
/** en- or disable the SEO meta box */
'SEO' => true,
/** to enable tag support */
'tag' => true,
/** to enable category support */
'category' => true,
/** rename default post section */
'rename_labels' => [
'name' => __('Pages') . ' DE',
'singular_name' => __('Page') . ' DE',
'menu_name' => __('Pages') . ' DE',
'all_items' => 'All ' . __('Pages') . ' DE',
'add_new' => 'Add New',
'add_new_item' => 'Add New ' . __('Page') . ' DE',
'edit' => 'Edit',
'edit_item' => 'Edit ' . __('Page') . ' DE',
'new_item' => 'New ' . __('Page') . ' DE',
'view' => 'View',
'view_item' => 'View Page',
'search_items' => 'Search ' . __('Pages') . ' DE',
'not_found' => 'No Pages found',
'not_found_in_trash' => 'No Pages found in trash'
]
]
]);
$kitt_instance->attachment([
'attachment' => [
/** to enable tag support */
'tag' => false,
/** to enable category support */
'category' => false,
/** enable search duplicates support */
'search_duplicates' => true
],
/**
* set custom upload mimes
*
* extend_defaults = true|false
* true = merges the default upload mimes
* false = replaces the default upload mimes
*
* list of defaulst:
* https://developer.wordpress.org/reference/functions/get_allowed_mime_types/
*/
'upload_mimes' => [
'extend_defaults' => true,
'jpg|jpeg|jpe' => 'image/jpeg',
'gif' => 'image/gif',
'png' => 'image/png',
/**
* NOTE:
* the XML declaration is required
* in each SVG file, otherwise
* the SVG upload is not accepted
*
* enter the version and the encoding
* charset at the top of each SVG file
*
* <?xml version="1.0" encoding="utf-8"?>
* <svg xmlns="http://www.w3.org/2000/svg" ... viewBox="0 0 100 57">
* ...
* </svg>
*/
'svg' => 'image/svg+xml',
'pdf' => 'application/pdf',
'mp3|m4a|m4b' => 'audio/mpeg',
'mp4|m4v' => 'video/mp4',
'zip' => 'application/zip'
],
'options_media' => [
/** WP default 150x150px */
'thumbnail_size' => [
'thumbnail_size_w' => 150,
'thumbnail_size_h' => 150
],
/** WP default 1 */
'thumbnail_crop' => 1,
/** WP default 300x300px */
'medium_size' => [
'medium_size_w' => 300,
'medium_size_h' => 300
],
/** WP default 768x768px */
'medium_large_size' => [
'medium_large_size_w' => 768,
'medium_large_size_h' => 768
],
/** WP default 1024x1024px */
'large_size' => [
'large_size_w' => 1024,
'large_size_h' => 1024
],
/** WP default 0 */
'uploads_yearmonth' => 1,
/** WP default open */
'ping_status' => 'closed',
/** WP default open */
'comment_status' => 'closed',
/** /wp-content/uploads */
'upload_path' => constant('WP_UPLOAD_DIR'),
/** http://127.0.0.1/uploads */
'upload_url_path' => constant('WP_UPLOAD_URL')
]
]);
$kitt_instance->comments([
/** removes completely the default comments section */
'remove_comments' => true
]);
$kitt_instance->menu([
/** register main menu locations */
'menu' => [
'locations' => [
'header' => 'Header',
'main' => 'Main',
'footer' => 'Footer'
]
]
]);
/**
* register new post type
* example: "Pages EN"
*
* menu icon info:
* https://developer.wordpress.org/resource/dashicons/#menu
*/
$kitt_instance->custom_post_type([
'custom_post_type' => [
/** similar to the WP method */
'post_type' => 'pages_en',
'description' => 'Pages EN',
'capability_type' => 'post',
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'map_meta_cap' => true,
'hierarchical' => true,
'query_var' => true,
'has_archive' => true,
'rewrite' => ['slug' => 'en'],
'supports' => ['title', 'revisions', 'page-attributes', 'thumbnail', 'custom-fields', 'post-formats'],
'menu_position' => 21,
'menu_icon' => 'dashicons-admin-page',
'taxonomies' => ['post_tag', 'category'],
'labels' => [
'name' => __('Pages') . ' EN',
'singular_name' => __('Page') . ' EN',
'menu_name' => __('Pages') . ' EN',
'all_items' => 'All ' . __('Pages') . ' EN',
'add_new' => 'Add New',
'add_new_item' => 'Add New ' . __('Page') . ' EN',
'edit' => 'Edit',
'edit_item' => 'Edit ' . __('Page') . ' EN',
'new_item' => 'New ' . __('Page') . ' EN',
'view' => 'View',
'view_item' => 'View Page',
'search_items' => 'Search ' . __('Pages') . ' EN',
'not_found' => 'No Pages found',
'not_found_in_trash' => 'No Pages found in trash',
'attributes' => 'Page Attributes'
],
'tag' => true,
'category' => true,
'remove_meta_box' => ['commentsdiv', 'slugdiv'],
/**
* dashboard at a glance widget icon
* post-count, page-count, comment-count
* or custom CSS class
*/
'dashboard_icon' => 'page-count',
/**
* menu locations will be registered if a slug exists
* caution, do not overwrite existing locations
*/
'menu_locations' => [
'header_en' => 'Header EN',
'main_en' => 'Main EN',
'footer_en' => 'Footer EN'
],
/** add or remove SEO support */
'SEO' => true
]
]);
$kitt_instance->REST_API([
'rest_api' => [
/**
* set the namespace for your routes
* => example.com/wp-json/->namespace<-/route
*/
'namespace' => explode('.', parse_url(WP_HOME)['host'])[0],
/** removes the default REST API */
'remove_default' => true,
/**
* examples:
* 'Access-Control-Allow-Origin: ' . WP_HOME
* 'Access-Control-Allow-Methods: POST, GET'
* 'Access-Control-Allow-Credentials: true'
* 'Access-Control-Max-Age: 600'
*/
'headers' => [
'Access-Control-Allow-Headers: Authorization, X-WP-Nonce, Content-Disposition, Content-MD5, Content-Type',
'Access-Control-Allow-Origin: ' . WP_HOME,
'Access-Control-Allow-Methods: POST, GET',
'Access-Control-Allow-Credentials: true',
'Access-Control-Max-Age: 600'
],
/** JWT token arguments */
'token' => [
'expiration_time' => time() + (DAY_IN_SECONDS * 7),
'header' => 'Access-Control-Allow-Headers, Access-Control-Allow-Origin, Content-Type, Authorization'
]
]
]);
/**
* register custom REST routes
*
* functions.php
* modifing default args
* $kitt_instance->rest_routes['route']['args']['param'] = ['default' => 'value']
*
* add route
* extend $this->rest_routes array
* e.g.
* $kitt_instance->rest_routes['endpoint'] = [
* 'methods' => \WP_REST_Server::CREATABLE,
* 'callback' => 'call_callback_API',
* 'permission_callback' => 'edit_others_posts',
* 'args' => [
* 'param_one' => ['default' => 'one']
* ]
* ];
* add REST route method
* extend $instance
* e.g.
* $kitt_instance->call_callback_API = function (\WP_REST_Request $request)
* {
* // $_GET and $_POST params
* $params = $request->get_params();
* $response = new \WP_REST_Response($params, 200);
* return $response;
* };
*/
$kitt_instance->rest_routes['endpoint'] = [
/**
* add a custom REST route
* example: return Vue.js routes
*
* const READABLE = 'GET';
* const CREATABLE = 'POST';
* ...
* const ALLMETHODS = 'GET, POST, PUT, PATCH, DELETE';
*
* NOTE: axios GET request can not send data via body
*
* documentation
* https://developer.wordpress.org/reference/classes/wp_rest_server/
*/
'methods' => \WP_REST_Server::CREATABLE,
'callback' => 'my_custom_callback', // string required
/**
* string required
* ... current_user_can($route['permission_callback']); ...
*
* list of roles and capabilities
* https://wordpress.org/support/article/roles-and-capabilities/
*/
'permission_callback' => 'rest_api_user',
/** set the defaults */
'args' => [
'param_one' => ['default' => false]
]
];
/**
* add a custom REST callback method
*/
$kitt_instance->my_custom_callback = function (\WP_REST_Request $request) use ($kitt_instance) {
/** $_GET and $_POST params */
$params = $request->get_params();
/** get the default params */
$default = $request->get_default_params();
/** update posts default arguments with request data */
$args = $kitt_instance->replace_val_in_array($default, $params);
/** do stuff!!! */
$response = "my custom response";
return new \WP_REST_Response($response, 200);
};
/**
* update email route arguments
* set server settings
*
* update values with WP constants
* or set your custom settings
*/
$kitt_instance->rest_routes['email']['args']['host'] = ['default' => constant('SMTP_HOST')]; // 'smtp.gmail.com'
$kitt_instance->rest_routes['email']['args']['SMTP_auth'] = ['default' => constant('SMTP_AUTH')]; // boolean
$kitt_instance->rest_routes['email']['args']['username'] = ['default' => constant('SMTP_USERNAME')]; // '[email protected]'
/**
* use google app password:
* https://support.google.com/accounts/answer/185833?hl=en
*/
$kitt_instance->rest_routes['email']['args']['password'] = ['default' => constant('SMTP_PASSWORD')]; // 'app-password'
$kitt_instance->rest_routes['email']['args']['SMTP_secure'] = ['default' => constant('SMTP_SECURE')]; // 'tls'
$kitt_instance->rest_routes['email']['args']['port'] = ['default' => constant('SMTP_PORT')]; // 587
/** PHPMailer debug */
$kitt_instance->rest_routes['email']['args']['debug'] = ['default' => false];
/**
* email test data
*
* test e.g. via postman
* send data with route -> /wp-json/namespace/email
*/
$kitt_instance->rest_routes['email']['args']['set_from'] = ['default' => [
'address' => '[email protected]',
'name' => 'User Foo'
]];
$kitt_instance->rest_routes['email']['args']['add_address'] = ['default' => [[
'address' => '[email protected]',
'name' => 'User Bar'
]]];
$kitt_instance->rest_routes['email']['args']['add_reply_to'] = ['default' => [
'address' => '[email protected]',
'name' => 'User Foo'
]];