-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustom-content-type.php
More file actions
86 lines (67 loc) · 2.4 KB
/
custom-content-type.php
File metadata and controls
86 lines (67 loc) · 2.4 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
<?php
use ImportWPAddon\JetEngine\Importer\Mapper\CustomContentTypeMapper;
use ImportWPAddon\JetEngine\Importer\Template\CustomContentTypeTemplate;
add_action('jet-engine/init', function ($jet_engine) {
if (!jet_engine()->modules->is_module_active('custom-content-types')) {
return;
}
// TODO: Module is enabled
add_action('init', function () {
$content_types = Jet_Engine\Modules\Custom_Content_Types\Module::instance()->manager->data->get_items();
$content_types = array_map(function ($item) {
$item['args'] = maybe_unserialize($item['args']);
$item['meta_fields'] = maybe_unserialize($item['meta_fields']);
return $item;
}, $content_types);
// Create new template with the meta_fields
});
}, 999);
/**
* Hook into Import WP Event handler
*
* @param EventHandler $event_handler
* @return void
*/
function iwp_jet_engine_cct_register_events($event_handler)
{
$event_handler->listen('templates.register', 'iwp_jet_engine_cct_register_templates');
$event_handler->listen('mappers.register', 'iwp_jet_engine_cct_register_mappers');
}
add_action('iwp/register_events', 'iwp_jet_engine_cct_register_events');
/**
* Add PropertyTemplate to list
*
* @param string[] $templates
* @return string[]
*/
function iwp_jet_engine_cct_register_templates($templates)
{
if (!jet_engine()->modules->is_module_active('custom-content-types')) {
return $templates;
}
$content_types = Jet_Engine\Modules\Custom_Content_Types\Module::instance()->manager->data->get_items();
$content_types = array_map(function ($item) {
$item['args'] = maybe_unserialize($item['args']);
$item['meta_fields'] = maybe_unserialize($item['meta_fields']);
return $item;
}, $content_types);
if (!empty($content_types)) {
foreach ($content_types as $item) {
$templates['jet-engine-cct'] = CustomContentTypeTemplate::class;
}
}
return $templates;
}
function iwp_jet_engine_cct_register_mappers($mappers)
{
$mappers['jet-engine-cct'] = CustomContentTypeMapper::class;
return $mappers;
}
function iwp_jet_engine_cct_mapper_unique_fields($unique_fields, $mapper_id)
{
if ($mapper_id == 'jet-engine-cct') {
return ['_ID'];
}
return $unique_fields;
}
add_filter('iwp/mapper/unique_fields', 'iwp_jet_engine_cct_mapper_unique_fields', 10, 2);