admin
2 years ago
field-groups
2 years ago
fields
2 years ago
fields-settings
2 years ago
locations
3 years ago
modules
2 years ago
screens
3 years ago
acfe-deprecated-functions.php
2 years ago
acfe-field-functions.php
2 years ago
acfe-field-group-functions.php
2 years ago
acfe-file-functions.php
3 years ago
acfe-form-functions.php
2 years ago
acfe-helper-functions.php
2 years ago
acfe-meta-functions.php
3 years ago
acfe-post-functions.php
3 years ago
acfe-screen-functions.php
3 years ago
acfe-template-functions.php
3 years ago
acfe-term-functions.php
3 years ago
acfe-user-functions.php
3 years ago
acfe-wp-functions.php
3 years ago
assets.php
3 years ago
compatibility-6.0.php
2 years ago
compatibility.php
2 years ago
field-extend.php
3 years ago
field.php
3 years ago
hooks.php
3 years ago
init.php
3 years ago
local-meta.php
3 years ago
module-acf.php
2 years ago
module-db.php
3 years ago
module-l10n.php
3 years ago
module-legacy.php
3 years ago
module-manager.php
3 years ago
module-post.php
2 years ago
module-posts.php
2 years ago
module-upgrades.php
3 years ago
module.php
2 years ago
multilang.php
3 years ago
settings.php
3 years ago
template-tags.php
2 years ago
third-party.php
3 years ago
upgrades.php
3 years ago
module-manager.php
146 lines
| 1 | <?php |
| 2 | |
| 3 | if(!defined('ABSPATH')){ |
| 4 | exit; |
| 5 | } |
| 6 | |
| 7 | if(!class_exists('acfe_module_manager')): |
| 8 | |
| 9 | class acfe_module_manager{ |
| 10 | |
| 11 | /** |
| 12 | * construct |
| 13 | */ |
| 14 | function __construct(){ |
| 15 | |
| 16 | add_action('acfe/init', array($this, 'register_items'), 99); |
| 17 | add_action('init', array($this, 'register_items')); |
| 18 | add_action('init', array($this, 'register_post_types')); |
| 19 | |
| 20 | } |
| 21 | |
| 22 | |
| 23 | /** |
| 24 | * register_items |
| 25 | */ |
| 26 | function register_items(){ |
| 27 | |
| 28 | // get current hook |
| 29 | // ini or acf/init |
| 30 | $hook = current_filter(); |
| 31 | |
| 32 | // query modules by register hook |
| 33 | $modules = acfe_query_modules(array( |
| 34 | 'register' => $hook |
| 35 | )); |
| 36 | |
| 37 | // bail early |
| 38 | if(!$modules){ |
| 39 | return; |
| 40 | } |
| 41 | |
| 42 | // loop modules |
| 43 | foreach($modules as $module){ |
| 44 | |
| 45 | // check active |
| 46 | if(!$module->is_active()){ |
| 47 | continue; |
| 48 | } |
| 49 | |
| 50 | // get loaded items |
| 51 | $items = $module->get_local_items(); |
| 52 | $items = $module->apply_module_filters('acfe/module/register_items', $items); |
| 53 | |
| 54 | // loop items |
| 55 | foreach($items as $item){ |
| 56 | |
| 57 | // cleanup keys (ID, local, _valid...) |
| 58 | $item = $module->prepare_item_for_export($item); |
| 59 | |
| 60 | // filters |
| 61 | $item = $module->apply_module_filters('acfe/module/register_item_args', $item); |
| 62 | |
| 63 | // bail early |
| 64 | if($item === false){ |
| 65 | continue; |
| 66 | } |
| 67 | |
| 68 | // bail early |
| 69 | if(!$item['active']){ |
| 70 | continue; |
| 71 | } |
| 72 | |
| 73 | // actions |
| 74 | $module->do_module_action('acfe/module/register_item', $item); |
| 75 | |
| 76 | } |
| 77 | |
| 78 | } |
| 79 | |
| 80 | } |
| 81 | |
| 82 | |
| 83 | /** |
| 84 | * register_post_types |
| 85 | */ |
| 86 | function register_post_types(){ |
| 87 | |
| 88 | // get all modules |
| 89 | $modules = acfe_get_modules(); |
| 90 | |
| 91 | // loop modules |
| 92 | foreach($modules as $module){ |
| 93 | |
| 94 | // check active |
| 95 | if(!$module->is_active()){ |
| 96 | continue; |
| 97 | } |
| 98 | |
| 99 | // capability |
| 100 | $capability = acf_get_setting('show_admin') ? acf_get_setting('capability') : false; |
| 101 | |
| 102 | // arguments |
| 103 | $args = wp_parse_args($module->args, array( |
| 104 | 'label' => '', |
| 105 | 'labels' => array(), |
| 106 | 'supports' => array('title'), |
| 107 | 'hierarchical' => false, |
| 108 | 'public' => false, |
| 109 | 'show_ui' => true, |
| 110 | 'show_in_menu' => false, |
| 111 | 'menu_icon' => 'dashicons-layout', |
| 112 | 'show_in_admin_bar' => false, |
| 113 | 'show_in_nav_menus' => false, |
| 114 | 'can_export' => false, |
| 115 | 'has_archive' => false, |
| 116 | 'rewrite' => false, |
| 117 | 'exclude_from_search' => true, |
| 118 | 'publicly_queryable' => false, |
| 119 | 'capabilities' => array( |
| 120 | 'publish_posts' => $capability, |
| 121 | 'edit_posts' => $capability, |
| 122 | 'edit_others_posts' => $capability, |
| 123 | 'delete_posts' => $capability, |
| 124 | 'delete_others_posts' => $capability, |
| 125 | 'read_private_posts' => $capability, |
| 126 | 'edit_post' => $capability, |
| 127 | 'delete_post' => $capability, |
| 128 | 'read_post' => $capability, |
| 129 | ), |
| 130 | 'acfe_admin_orderby' => 'title', |
| 131 | 'acfe_admin_order' => 'ASC', |
| 132 | 'acfe_admin_ppp' => 999, |
| 133 | )); |
| 134 | |
| 135 | // register post type |
| 136 | register_post_type($module->post_type, $args); |
| 137 | |
| 138 | } |
| 139 | |
| 140 | } |
| 141 | |
| 142 | } |
| 143 | |
| 144 | acf_new_instance('acfe_module_manager'); |
| 145 | |
| 146 | endif; |