admin
1 month ago
field-groups
1 month ago
fields
1 month ago
fields-settings
1 month ago
forms
1 month ago
locations
1 month ago
modules
1 month ago
screens
1 month ago
acfe-deprecated-functions.php
2 years ago
acfe-field-functions.php
1 month ago
acfe-field-group-functions.php
1 month ago
acfe-file-functions.php
1 year ago
acfe-form-functions.php
1 month ago
acfe-helper-array-functions.php
1 month ago
acfe-helper-functions.php
1 month ago
acfe-helper-multi-functions.php
1 month ago
acfe-helper-string-functions.php
1 month ago
acfe-meta-functions.php
1 month ago
acfe-post-functions.php
1 month ago
acfe-screen-functions.php
1 month ago
acfe-template-functions.php
1 month ago
acfe-term-functions.php
1 month ago
acfe-user-functions.php
1 month ago
acfe-wp-functions.php
3 years ago
assets.php
1 month ago
compatibility-acf-5.8.php
2 months ago
compatibility-acf-5.9.php
1 month ago
compatibility-acf-6.5.php
1 month ago
compatibility.php
1 month ago
field-extend.php
2 months ago
field.php
2 months ago
hooks.php
1 month ago
init.php
1 month ago
local-meta.php
3 years ago
media.php
1 month ago
module-acf.php
1 month ago
module-db.php
1 month ago
module-l10n.php
1 month ago
module-legacy.php
3 years ago
module-manager.php
2 months ago
module-post.php
1 month ago
module-posts.php
2 months ago
module-upgrades.php
3 years ago
module.php
1 month ago
multilang.php
1 month ago
revisions.php
2 months ago
screen.php
1 month ago
settings.php
1 month ago
template-tags.php
1 month ago
third-party.php
3 years ago
upgrades.php
1 month ago
module-post.php
296 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_action('acf/input/form_data', array($this, 'form_data')); |
| 60 | add_filter('acfe/localize_data', array($this, 'localize_data')); |
| 61 | add_action('post_submitbox_misc_actions', array($this, 'post_submitbox_misc_actions')); |
| 62 | add_filter('submenu_file', array($this, 'submenu_file')); |
| 63 | |
| 64 | // remove native wp slug metabox |
| 65 | remove_meta_box('slugdiv', $module->post_type, 'normal'); |
| 66 | |
| 67 | // register field groups |
| 68 | foreach($module->get_field_groups() as $field_group){ |
| 69 | acf_add_local_field_group($field_group); |
| 70 | } |
| 71 | |
| 72 | // actions |
| 73 | $module->do_module_action('acfe/module/load_post'); |
| 74 | |
| 75 | } |
| 76 | |
| 77 | |
| 78 | /** |
| 79 | * admin_body_class |
| 80 | * |
| 81 | * @param $classes |
| 82 | * |
| 83 | * @return string |
| 84 | */ |
| 85 | function admin_body_class($classes){ |
| 86 | |
| 87 | global $module; |
| 88 | |
| 89 | $classes .= " acfe-module acfe-module-post acfe-module-{$module->name}"; |
| 90 | return $classes; |
| 91 | |
| 92 | } |
| 93 | |
| 94 | |
| 95 | /** |
| 96 | * admin_enqueue_scripts |
| 97 | * |
| 98 | * acf/input/admin_enqueue_scripts |
| 99 | */ |
| 100 | function admin_enqueue_scripts(){ |
| 101 | |
| 102 | // no autosave |
| 103 | wp_dequeue_script('autosave'); |
| 104 | |
| 105 | // remove default 'draft' post status on post-new.php |
| 106 | // this fix an issue when user press 'enter' when creating a new item |
| 107 | global $post; |
| 108 | $post->post_status = 'publish'; |
| 109 | |
| 110 | } |
| 111 | |
| 112 | |
| 113 | /** |
| 114 | * form_data |
| 115 | * |
| 116 | * @param $data |
| 117 | * |
| 118 | * @return void |
| 119 | */ |
| 120 | function form_data($data){ |
| 121 | |
| 122 | acf_hidden_input(array( |
| 123 | 'id' => '_acfe_module_nonce', |
| 124 | 'name' => '_acfe_module_nonce', |
| 125 | 'value' => wp_create_nonce('acfe_module'), |
| 126 | )); |
| 127 | |
| 128 | } |
| 129 | |
| 130 | |
| 131 | /** |
| 132 | * localize_data |
| 133 | * |
| 134 | * acfe/localize_data |
| 135 | * |
| 136 | * @param $data |
| 137 | * |
| 138 | * @return mixed |
| 139 | */ |
| 140 | function localize_data($data){ |
| 141 | |
| 142 | global $module, $item; |
| 143 | |
| 144 | $data['module'] = array( |
| 145 | 'name' => $module->name, |
| 146 | 'screen' => 'post', |
| 147 | 'messages' => array( |
| 148 | 'status' => $item['active'] ? __('Active', 'acf') : __('Inactive', 'acf'), |
| 149 | 'label' => sprintf(__('%s value is required', 'acf'), $module->get_label('enter_title')), |
| 150 | ), |
| 151 | ); |
| 152 | |
| 153 | return $data; |
| 154 | |
| 155 | } |
| 156 | |
| 157 | |
| 158 | /** |
| 159 | * post_submitbox_misc_actions |
| 160 | */ |
| 161 | function post_submitbox_misc_actions(){ |
| 162 | |
| 163 | global $module, $item; |
| 164 | |
| 165 | $links = $module->get_export_links($item); |
| 166 | |
| 167 | if($links): ?> |
| 168 | <div class="misc-pub-section acfe-misc-export"> |
| 169 | <span class="dashicons dashicons-editor-code"></span> |
| 170 | <?php _e('Export', 'acfe'); ?>: <?php echo implode(' ', $links); ?> |
| 171 | </div> |
| 172 | <?php endif; |
| 173 | |
| 174 | } |
| 175 | |
| 176 | |
| 177 | /** |
| 178 | * submenu_file |
| 179 | * @return string |
| 180 | */ |
| 181 | function submenu_file(){ |
| 182 | |
| 183 | global $module; |
| 184 | return "edit.php?post_type={$module->post_type}"; |
| 185 | |
| 186 | } |
| 187 | |
| 188 | |
| 189 | /** |
| 190 | * trashed_post |
| 191 | * |
| 192 | * @param $post_id |
| 193 | */ |
| 194 | function trashed_post($post_id){ |
| 195 | |
| 196 | // get module |
| 197 | $module = acfe_get_module_by_item($post_id); |
| 198 | |
| 199 | if($module){ |
| 200 | $module->trash_item($post_id); |
| 201 | } |
| 202 | |
| 203 | } |
| 204 | |
| 205 | |
| 206 | /** |
| 207 | * untrashed_post |
| 208 | * |
| 209 | * @param $post_id |
| 210 | */ |
| 211 | function untrashed_post($post_id){ |
| 212 | |
| 213 | // get module |
| 214 | $module = acfe_get_module_by_item($post_id); |
| 215 | |
| 216 | if($module){ |
| 217 | $module->untrash_item($post_id); |
| 218 | } |
| 219 | |
| 220 | } |
| 221 | |
| 222 | |
| 223 | /** |
| 224 | * deleted_post |
| 225 | * |
| 226 | * @param $post_id |
| 227 | */ |
| 228 | function deleted_post($post_id){ |
| 229 | |
| 230 | // get module |
| 231 | $module = acfe_get_module_by_item($post_id); |
| 232 | |
| 233 | if($module){ |
| 234 | $module->delete_item($post_id); |
| 235 | } |
| 236 | |
| 237 | } |
| 238 | |
| 239 | |
| 240 | /** |
| 241 | * post_updated_messages |
| 242 | * |
| 243 | * @param $messages |
| 244 | * |
| 245 | * @return mixed |
| 246 | */ |
| 247 | function post_updated_messages($messages){ |
| 248 | |
| 249 | /* |
| 250 | * 0 => '', // Unused. Messages start at index 1. |
| 251 | * 1 => __( 'Post updated.' ) . $view_post_link_html, |
| 252 | * 2 => __( 'Custom field updated.' ), |
| 253 | * 3 => __( 'Custom field deleted.' ), |
| 254 | * 4 => __( 'Post updated.' ), |
| 255 | * 5 => isset( $_GET['revision'] ) ? sprintf( __( 'Post restored to revision from %s.' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
| 256 | * 6 => __( 'Post published.' ) . $view_post_link_html, |
| 257 | * 7 => __( 'Post saved.' ), |
| 258 | * 8 => __( 'Post submitted.' ) . $preview_post_link_html, |
| 259 | * 9 => sprintf( __( 'Post scheduled for: %s.' ), '<strong>' . $scheduled_date . '</strong>' ) . $scheduled_post_link_html, |
| 260 | * 10 => __( 'Post draft updated.' ) . $preview_post_link_html, |
| 261 | */ |
| 262 | |
| 263 | $modules = acfe_get_modules(); |
| 264 | |
| 265 | foreach($modules as $module){ |
| 266 | |
| 267 | // label |
| 268 | $label = $module->get_label(); |
| 269 | |
| 270 | // append to messages |
| 271 | $messages[ $module->post_type ] = array( |
| 272 | 0 => '', // unused. messages start at index 1 |
| 273 | 1 => sprintf(__('%s updated.', 'acfe'), $label), |
| 274 | 2 => sprintf(__('%s updated.', 'acfe'), $label), |
| 275 | 3 => sprintf(__('%s deleted.', 'acfe'), $label), |
| 276 | 4 => sprintf(__('%s updated.', 'acfe'), $label), |
| 277 | 5 => false, // no revisions support |
| 278 | 6 => sprintf(__('%s published.', 'acfe'), $label), |
| 279 | 7 => sprintf(__('%s saved.', 'acfe'), $label), |
| 280 | 8 => sprintf(__('%s submitted.', 'acfe'), $label), |
| 281 | 9 => sprintf(__('%s scheduled.', 'acfe'), $label), |
| 282 | 10 => sprintf(__('%s draft updated.', 'acfe'), $label), |
| 283 | ); |
| 284 | |
| 285 | } |
| 286 | |
| 287 | // return |
| 288 | return $messages; |
| 289 | |
| 290 | } |
| 291 | |
| 292 | } |
| 293 | |
| 294 | acf_new_instance('acfe_module_post'); |
| 295 | |
| 296 | endif; |