-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjam-cms.php
295 lines (261 loc) · 13.5 KB
/
jam-cms.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
<?php
/**
* @link http://example.com
* @since 0.0.1
* @package jamCMS
*
* @wordpress-plugin
* Plugin Name: jamCMS
* Plugin URI: https://github.com/robinzimmer1989/jam-cms-wordpress
* Description: A CMS for the JAMStack world. Made for developers.
* Version: 1.12.0
* Author: Robin Zimmer
* Author URI: https://github.com/robinzimmer1989
* License:
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* Text Domain: jam-cms
*/
// Exit if accessed directly
if( ! defined( 'ABSPATH' ) ) exit;
if( ! class_exists('JamCMS') ) :
class JamCMS {
/** @var string The plugin version number. */
var $version = '0.0.1';
/**
* __construct
*
* A dummy constructor to ensure JamCMS is only setup once.
*
* @date 20/11/20
* @since 0.0.1
*
* @param void
* @return void
*/
function __construct() {
// Do nothing.
}
/**
* initialize
*
* Sets up the Gatsby CMS plugin.
*
* @date 20/11/20
* @since 0.0.1
*
* @param void
* @return void
*/
function initialize() {
// Define constants.
$this->define( 'JAM_CMS', true );
$this->define( 'JAM_CMS_PATH', plugin_dir_path( __FILE__ ) );
$this->define( 'JAM_CMS_BASENAME', plugin_basename( __FILE__ ) );
$this->define( 'JAM_CMS_VERSION', $this->version );
// Utilities
include_once( JAM_CMS_PATH . '/includes/utils/error_log.php');
include_once( JAM_CMS_PATH . '/includes/utils/format_url.php');
include_once( JAM_CMS_PATH . '/includes/utils/format_post.php');
include_once( JAM_CMS_PATH . '/includes/utils/format_post_type.php');
include_once( JAM_CMS_PATH . '/includes/utils/format_taxonomy.php');
include_once( JAM_CMS_PATH . '/includes/utils/format_term.php');
include_once( JAM_CMS_PATH . '/includes/utils/format_media_item.php');
include_once( JAM_CMS_PATH . '/includes/utils/format_menu_item.php');
include_once( JAM_CMS_PATH . '/includes/utils/format_user.php');
include_once( JAM_CMS_PATH . '/includes/utils/format_action_monitor.php');
include_once( JAM_CMS_PATH . '/includes/utils/format_language.php');
include_once( JAM_CMS_PATH . '/includes/utils/generate_id.php');
include_once( JAM_CMS_PATH . '/includes/utils/array_flatten.php');
include_once( JAM_CMS_PATH . '/includes/utils/build_menu_tree.php');
include_once( JAM_CMS_PATH . '/includes/utils/api_base_check.php');
include_once( JAM_CMS_PATH . '/includes/utils/check_for_missing_plugins.php');
include_once( JAM_CMS_PATH . '/includes/utils/get_template_key.php');
include_once( JAM_CMS_PATH . '/includes/utils/create_template.php');
include_once( JAM_CMS_PATH . '/includes/utils/generate_slug_by_id.php');
include_once( JAM_CMS_PATH . '/includes/utils/duplicate_post.php');
include_once( JAM_CMS_PATH . '/includes/utils/duplicate_term.php');
include_once( JAM_CMS_PATH . '/includes/utils/create_revision.php');
include_once( JAM_CMS_PATH . '/includes/utils/create_post_type.php');
include_once( JAM_CMS_PATH . '/includes/utils/create_taxonomy.php');
include_once( JAM_CMS_PATH . '/includes/utils/generate_preview_link.php');
include_once( JAM_CMS_PATH . '/includes/utils/generate_preview_key.php');
include_once( JAM_CMS_PATH . '/includes/utils/post_lock.php');
include_once( JAM_CMS_PATH . '/includes/utils/get_user_roles.php');
include_once( JAM_CMS_PATH . '/includes/utils/get_languages.php');
include_once( JAM_CMS_PATH . '/includes/utils/array_search_partial.php');
// Admin
include_once( JAM_CMS_PATH . '/includes/admin/fix_page_query.php');
include_once( JAM_CMS_PATH . '/includes/admin/whitelist_apis.php');
include_once( JAM_CMS_PATH . '/includes/admin/settings.php');
include_once( JAM_CMS_PATH . '/includes/admin/emails.php');
include_once( JAM_CMS_PATH . '/includes/admin/settings_page.php');
include_once( JAM_CMS_PATH . '/includes/admin/page_templater.php');
include_once( JAM_CMS_PATH . '/includes/admin/preview_button.php');
include_once( JAM_CMS_PATH . '/includes/admin/add_svg_field_to_image_query.php');
include_once( JAM_CMS_PATH . '/includes/admin/add_archive_fields_to_page_query.php');
include_once( JAM_CMS_PATH . '/includes/admin/notifications.php');
include_once( JAM_CMS_PATH . '/includes/admin/register_menu_locations.php');
// ACF
include_once( JAM_CMS_PATH . '/includes/acf/generate_acf_fields_recursively.php');
include_once( JAM_CMS_PATH . '/includes/acf/update_acf_fields.php');
include_once( JAM_CMS_PATH . '/includes/acf/update_acf_fields_options.php');
include_once( JAM_CMS_PATH . '/includes/acf/upsert_acf_template.php');
include_once( JAM_CMS_PATH . '/includes/acf/upsert_acf_template_options.php');
include_once( JAM_CMS_PATH . '/includes/acf/format_fields.php');
include_once( JAM_CMS_PATH . '/includes/acf/get_group_items_recursively.php');
include_once( JAM_CMS_PATH . '/includes/acf/get_flexible_content_items_recursively.php');
include_once( JAM_CMS_PATH . '/includes/acf/get_repeater_items_recursively.php');
include_once( JAM_CMS_PATH . '/includes/acf/add_acf_options_page.php');
include_once( JAM_CMS_PATH . '/includes/acf/get_acf_field_id.php');
include_once( JAM_CMS_PATH . '/includes/acf/generate_sub_fields_recursively.php');
include_once( JAM_CMS_PATH . '/includes/acf/format_acf_field_type_for_frontend.php');
include_once( JAM_CMS_PATH . '/includes/acf/format_acf_field_type_for_db.php');
include_once( JAM_CMS_PATH . '/includes/acf/format_acf_field_value_for_frontend.php');
include_once( JAM_CMS_PATH . '/includes/acf/format_acf_field_value_for_db.php');
include_once( JAM_CMS_PATH . '/includes/acf/get_option_group_fields.php');
include_once( JAM_CMS_PATH . '/includes/acf/get_flexible_content_sub_blocks.php');
include_once( JAM_CMS_PATH . '/includes/acf/add_menu_picker_field.php');
include_once( JAM_CMS_PATH . '/includes/acf/add_google_maps_api_key.php');
include_once( JAM_CMS_PATH . '/includes/acf/get_default_field_values.php');
include_once( JAM_CMS_PATH . '/includes/acf/add_acf_field_group_for_menu.php');
include_once( JAM_CMS_PATH . '/includes/acf/get_menu_fields_recursively.php');
// Queries
include_once( JAM_CMS_PATH . '/includes/queries/get_site_by_id.php');
include_once( JAM_CMS_PATH . '/includes/queries/get_site_for_build_by_id.php');
include_once( JAM_CMS_PATH . '/includes/queries/get_post_by_id.php');
include_once( JAM_CMS_PATH . '/includes/queries/get_media_items.php');
include_once( JAM_CMS_PATH . '/includes/queries/get_media_item_by_id.php');
include_once( JAM_CMS_PATH . '/includes/queries/get_menu_by_id.php');
include_once( JAM_CMS_PATH . '/includes/queries/get_user_by_id.php');
include_once( JAM_CMS_PATH . '/includes/queries/get_users.php');
include_once( JAM_CMS_PATH . '/includes/queries/get_relevant_plugins.php');
// Mutations
include_once( JAM_CMS_PATH . '/includes/mutations/update_menu.php');
// APIs
include_once( JAM_CMS_PATH . '/includes/api/test.php');
include_once( JAM_CMS_PATH . '/includes/api/site/update_site.php');
include_once( JAM_CMS_PATH . '/includes/api/site/get_site.php');
include_once( JAM_CMS_PATH . '/includes/api/site/get_site_for_build.php');
include_once( JAM_CMS_PATH . '/includes/api/site/deploy_site.php');
include_once( JAM_CMS_PATH . '/includes/api/post/create_post.php');
include_once( JAM_CMS_PATH . '/includes/api/post/update_post.php');
include_once( JAM_CMS_PATH . '/includes/api/post/get_post.php');
include_once( JAM_CMS_PATH . '/includes/api/post/delete_post.php');
include_once( JAM_CMS_PATH . '/includes/api/post/duplicate_post.php');
include_once( JAM_CMS_PATH . '/includes/api/post/reorder_posts.php');
include_once( JAM_CMS_PATH . '/includes/api/post/take_over_post.php');
include_once( JAM_CMS_PATH . '/includes/api/post/empty_trash.php');
include_once( JAM_CMS_PATH . '/includes/api/post/refresh_post_lock.php');
include_once( JAM_CMS_PATH . '/includes/api/post/remove_post_lock.php');
include_once( JAM_CMS_PATH . '/includes/api/term/create_term.php');
include_once( JAM_CMS_PATH . '/includes/api/term/update_term.php');
include_once( JAM_CMS_PATH . '/includes/api/term/delete_term.php');
include_once( JAM_CMS_PATH . '/includes/api/media_item/create_media_item.php');
include_once( JAM_CMS_PATH . '/includes/api/media_item/update_media_item.php');
include_once( JAM_CMS_PATH . '/includes/api/media_item/delete_media_item.php');
include_once( JAM_CMS_PATH . '/includes/api/media_item/get_media_items.php');
include_once( JAM_CMS_PATH . '/includes/api/user/create_user.php');
include_once( JAM_CMS_PATH . '/includes/api/user/update_user.php');
include_once( JAM_CMS_PATH . '/includes/api/user/delete_user.php');
include_once( JAM_CMS_PATH . '/includes/api/user/get_users.php');
include_once( JAM_CMS_PATH . '/includes/api/user/get_user.php');
include_once( JAM_CMS_PATH . '/includes/api/preview/get_site_preview.php');
include_once( JAM_CMS_PATH . '/includes/api/preview/get_post_preview.php');
include_once( JAM_CMS_PATH . '/includes/api/preview/get_preview_link.php');
include_once( JAM_CMS_PATH . '/includes/api/language/translate_post.php');
include_once( JAM_CMS_PATH . '/includes/api/language/translate_term.php');
include_once( JAM_CMS_PATH . '/includes/api/language/add_language.php');
include_once( JAM_CMS_PATH . '/includes/api/language/get_languages.php');
include_once( JAM_CMS_PATH . '/includes/api/language/delete_language.php');
include_once( JAM_CMS_PATH . '/includes/api/language/update_language.php');
include_once( JAM_CMS_PATH . '/includes/api/language/update_language_settings.php');
include_once( JAM_CMS_PATH . '/includes/api/language/set_language_in_mass.php');
// Misc APIs
include_once( JAM_CMS_PATH . '/includes/api/sync/sync_fields.php');
include_once( JAM_CMS_PATH . '/includes/api/get_unpublished_changes.php');
// Add actions.
add_action( 'init', array($this, 'init'), 100 );
}
/**
* init
*
* Completes the setup process on "init" of earlier.
*
* @date 20/11/20
* @since 0.0.1
*
* @param void
* @return void
*/
function init() {
// Bail early if called directly from functions.php or plugin file.
if( !did_action('plugins_loaded') ) {
return;
}
}
/**
* define
*
* Defines a constant if doesnt already exist.
*
* @date 20/11/20
* @since 0.0.1
*
* @param string $name The constant name.
* @param mixed $value The constant value.
* @return void
*/
function define( $name, $value = true ) {
if( !defined($name) ) {
define( $name, $value );
}
}
}
/*
* jam_cms
*
* The main function responsible for returning the one true Jam CMS Instance to functions everywhere.
*
* @date 20/11/20
* @since 0.0.1
*
* @param void
* @return JamCMS
*/
function jam_cms_initialize_jam_cms() {
global $jam_cms;
// Instantiate only once.
if( !isset($jam_cms) ) {
$jam_cms = new JamCMS();
$jam_cms->initialize();
}
return $jam_cms;
}
// Instantiate.
add_action( 'plugins_loaded', 'jam_cms_initialize_jam_cms' );
/*
* jam_cms_activate
*
* Add basic ACF field setup and API key on plugin activation
*
* @date 20/11/20
* @since 0.0.1
*
* @param void
* @return JamCMS
*/
function jam_cms_activate() {
// Initialize main plugin first so functions are available
jam_cms_initialize_jam_cms();
// Create deployment api key if doesn't exist yet
$settings = get_option('jam_cms_settings');
if(!$settings){
$settings = [
'admin_api_key' => wp_generate_uuid4(),
'emails_to_frontend' => 0
];
update_option('jam_cms_settings', $settings);
}
}
register_activation_hook( __FILE__, 'jam_cms_activate' );
endif; // class_exists check