admin
2 years ago
field-groups
2 years ago
fields
2 years ago
fields-settings
2 years ago
locations
3 years ago
modules
1 year ago
screens
2 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
2 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
2 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
2 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-post.php
277 lines
| 1 | <?php |
| 2 | |
| 3 | if(!defined('ABSPATH')){ |
| 4 | exit; |
| 5 | } |
| 6 | |
| 7 | if(!class_exists('acfe_module_post')): |
| 8 | |
| 9 | class acfe_module_post{ |
| 10 | |
| 11 | /** |
| 12 | * construct |
| 13 | */ |
| 14 | function __construct(){ |
| 15 | |
| 16 | add_action('add_meta_boxes', array($this, 'add_meta_boxes'), 5, 2); |
| 17 | add_action('trashed_post', array($this, 'trashed_post')); |
| 18 | add_action('untrashed_post', array($this, 'untrashed_post')); |
| 19 | add_action('deleted_post', array($this, 'deleted_post')); |
| 20 | add_filter('post_updated_messages', array($this, 'post_updated_messages')); |
| 21 | |
| 22 | } |
| 23 | |
| 24 | |
| 25 | /** |
| 26 | * add_meta_boxes |
| 27 | * |
| 28 | * add_meta_boxes |
| 29 | * |
| 30 | * @param $post_type |
| 31 | * @param $post |
| 32 | */ |
| 33 | function add_meta_boxes($post_type, $post){ |
| 34 | |
| 35 | // globals |
| 36 | global $item, $module; |
| 37 | |
| 38 | // validate post |
| 39 | if(!isset($post)){ |
| 40 | return; |
| 41 | } |
| 42 | |
| 43 | // validate WP_Post |
| 44 | if(!is_a($post, 'WP_Post')){ |
| 45 | return; |
| 46 | } |
| 47 | |
| 48 | // get module |
| 49 | $module = acfe_get_module_by_item($post->ID); |
| 50 | |
| 51 | if(!$module){ |
| 52 | return; |
| 53 | } |
| 54 | |
| 55 | $item = $module->get_item($post->ID); |
| 56 | |
| 57 | add_filter('admin_body_class', array($this, 'admin_body_class')); |
| 58 | add_action('acf/input/admin_enqueue_scripts', array($this, 'admin_enqueue_scripts')); |
| 59 | add_filter('acfe/localize_data', array($this, 'localize_data')); |
| 60 | add_action('post_submitbox_misc_actions', array($this, 'post_submitbox_misc_actions')); |
| 61 | add_filter('submenu_file', array($this, 'submenu_file')); |
| 62 | |
| 63 | // remove native wp slug metabox |
| 64 | remove_meta_box('slugdiv', $module->post_type, 'normal'); |
| 65 | |
| 66 | // register field groups |
| 67 | foreach($module->get_field_groups() as $field_group){ |
| 68 | acf_add_local_field_group($field_group); |
| 69 | } |
| 70 | |
| 71 | // actions |
| 72 | $module->do_module_action('acfe/module/load_post'); |
| 73 | |
| 74 | } |
| 75 | |
| 76 | |
| 77 | /** |
| 78 | * admin_body_class |
| 79 | * |
| 80 | * @param $classes |
| 81 | * |
| 82 | * @return string |
| 83 | */ |
| 84 | function admin_body_class($classes){ |
| 85 | |
| 86 | global $module; |
| 87 | |
| 88 | $classes .= " acfe-module acfe-module-post acfe-module-{$module->name}"; |
| 89 | return $classes; |
| 90 | |
| 91 | } |
| 92 | |
| 93 | |
| 94 | /** |
| 95 | * admin_enqueue_scripts |
| 96 | * |
| 97 | * acf/input/admin_enqueue_scripts |
| 98 | */ |
| 99 | function admin_enqueue_scripts(){ |
| 100 | |
| 101 | // no autosave |
| 102 | wp_dequeue_script('autosave'); |
| 103 | |
| 104 | // remove default 'draft' post status on post-new.php |
| 105 | // this fix an issue when user press 'enter' when creating a new item |
| 106 | global $post; |
| 107 | $post->post_status = 'publish'; |
| 108 | |
| 109 | } |
| 110 | |
| 111 | |
| 112 | /** |
| 113 | * localize_data |
| 114 | * |
| 115 | * acfe/localize_data |
| 116 | * |
| 117 | * @param $data |
| 118 | * |
| 119 | * @return mixed |
| 120 | */ |
| 121 | function localize_data($data){ |
| 122 | |
| 123 | global $module, $item; |
| 124 | |
| 125 | $data['module'] = array( |
| 126 | 'name' => $module->name, |
| 127 | 'screen' => 'post', |
| 128 | 'messages' => array( |
| 129 | 'status' => $item['active'] ? __('Active', 'acf') : __('Inactive', 'acf'), |
| 130 | 'label' => sprintf(__('%s value is required', 'acf'), $module->get_label('enter_title')), |
| 131 | ), |
| 132 | ); |
| 133 | |
| 134 | return $data; |
| 135 | |
| 136 | } |
| 137 | |
| 138 | |
| 139 | /** |
| 140 | * post_submitbox_misc_actions |
| 141 | */ |
| 142 | function post_submitbox_misc_actions(){ |
| 143 | |
| 144 | global $module, $item; |
| 145 | |
| 146 | $links = $module->get_export_links($item); |
| 147 | |
| 148 | if($links): ?> |
| 149 | <div class="misc-pub-section acfe-misc-export"> |
| 150 | <span class="dashicons dashicons-editor-code"></span> |
| 151 | <?php _e('Export', 'acfe'); ?>: <?php echo implode(' ', $links); ?> |
| 152 | </div> |
| 153 | <?php endif; |
| 154 | |
| 155 | } |
| 156 | |
| 157 | |
| 158 | /** |
| 159 | * submenu_file |
| 160 | * @return string |
| 161 | */ |
| 162 | function submenu_file(){ |
| 163 | |
| 164 | global $module; |
| 165 | return "edit.php?post_type={$module->post_type}"; |
| 166 | |
| 167 | } |
| 168 | |
| 169 | |
| 170 | /** |
| 171 | * trashed_post |
| 172 | * |
| 173 | * @param $post_id |
| 174 | */ |
| 175 | function trashed_post($post_id){ |
| 176 | |
| 177 | // get module |
| 178 | $module = acfe_get_module_by_item($post_id); |
| 179 | |
| 180 | if($module){ |
| 181 | $module->trash_item($post_id); |
| 182 | } |
| 183 | |
| 184 | } |
| 185 | |
| 186 | |
| 187 | /** |
| 188 | * untrashed_post |
| 189 | * |
| 190 | * @param $post_id |
| 191 | */ |
| 192 | function untrashed_post($post_id){ |
| 193 | |
| 194 | // get module |
| 195 | $module = acfe_get_module_by_item($post_id); |
| 196 | |
| 197 | if($module){ |
| 198 | $module->untrash_item($post_id); |
| 199 | } |
| 200 | |
| 201 | } |
| 202 | |
| 203 | |
| 204 | /** |
| 205 | * deleted_post |
| 206 | * |
| 207 | * @param $post_id |
| 208 | */ |
| 209 | function deleted_post($post_id){ |
| 210 | |
| 211 | // get module |
| 212 | $module = acfe_get_module_by_item($post_id); |
| 213 | |
| 214 | if($module){ |
| 215 | $module->delete_item($post_id); |
| 216 | } |
| 217 | |
| 218 | } |
| 219 | |
| 220 | |
| 221 | /** |
| 222 | * post_updated_messages |
| 223 | * |
| 224 | * @param $messages |
| 225 | * |
| 226 | * @return mixed |
| 227 | */ |
| 228 | function post_updated_messages($messages){ |
| 229 | |
| 230 | /* |
| 231 | * 0 => '', // Unused. Messages start at index 1. |
| 232 | * 1 => __( 'Post updated.' ) . $view_post_link_html, |
| 233 | * 2 => __( 'Custom field updated.' ), |
| 234 | * 3 => __( 'Custom field deleted.' ), |
| 235 | * 4 => __( 'Post updated.' ), |
| 236 | * 5 => isset( $_GET['revision'] ) ? sprintf( __( 'Post restored to revision from %s.' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
| 237 | * 6 => __( 'Post published.' ) . $view_post_link_html, |
| 238 | * 7 => __( 'Post saved.' ), |
| 239 | * 8 => __( 'Post submitted.' ) . $preview_post_link_html, |
| 240 | * 9 => sprintf( __( 'Post scheduled for: %s.' ), '<strong>' . $scheduled_date . '</strong>' ) . $scheduled_post_link_html, |
| 241 | * 10 => __( 'Post draft updated.' ) . $preview_post_link_html, |
| 242 | */ |
| 243 | |
| 244 | $modules = acfe_get_modules(); |
| 245 | |
| 246 | foreach($modules as $module){ |
| 247 | |
| 248 | // label |
| 249 | $label = $module->get_label(); |
| 250 | |
| 251 | // append to messages |
| 252 | $messages[ $module->post_type ] = array( |
| 253 | 0 => '', // unused. messages start at index 1 |
| 254 | 1 => sprintf(__('%s updated.', 'acfe'), $label), |
| 255 | 2 => sprintf(__('%s updated.', 'acfe'), $label), |
| 256 | 3 => sprintf(__('%s deleted.', 'acfe'), $label), |
| 257 | 4 => sprintf(__('%s updated.', 'acfe'), $label), |
| 258 | 5 => false, // no revisions support |
| 259 | 6 => sprintf(__('%s published.', 'acfe'), $label), |
| 260 | 7 => sprintf(__('%s saved.', 'acfe'), $label), |
| 261 | 8 => sprintf(__('%s submitted.', 'acfe'), $label), |
| 262 | 9 => sprintf(__('%s scheduled.', 'acfe'), $label), |
| 263 | 10 => sprintf(__('%s draft updated.', 'acfe'), $label), |
| 264 | ); |
| 265 | |
| 266 | } |
| 267 | |
| 268 | // return |
| 269 | return $messages; |
| 270 | |
| 271 | } |
| 272 | |
| 273 | } |
| 274 | |
| 275 | acf_new_instance('acfe_module_post'); |
| 276 | |
| 277 | endif; |