author.php
3 years ago
autosync.php
3 years ago
block-types.php
3 years ago
dev-clean-meta.php
3 years ago
dev-delete-meta.php
3 years ago
dev.php
3 years ago
forms-action-custom.php
3 years ago
forms-action-email.php
3 years ago
forms-action-post.php
3 years ago
forms-action-redirect.php
3 years ago
forms-action-term.php
3 years ago
forms-action-user.php
3 years ago
forms-cheatsheet.php
3 years ago
forms-front.php
3 years ago
forms-helpers.php
3 years ago
forms-hooks.php
3 years ago
forms-shortcode.php
3 years ago
forms.php
3 years ago
module.php
3 years ago
options-pages.php
3 years ago
options.class.php
3 years ago
options.php
3 years ago
post-types.php
3 years ago
single-meta.php
3 years ago
taxonomies.php
3 years ago
ui-attachment.php
3 years ago
ui-settings.php
3 years ago
ui-term.php
3 years ago
ui-user.php
3 years ago
ui.php
3 years ago
dev.php
889 lines
| 1 | <?php |
| 2 | |
| 3 | if(!defined('ABSPATH')){ |
| 4 | exit; |
| 5 | } |
| 6 | |
| 7 | if(!class_exists('acfe_dev')): |
| 8 | |
| 9 | class acfe_dev{ |
| 10 | |
| 11 | var $wp_meta = array(), |
| 12 | $acf_meta = array(), |
| 13 | $type = ''; |
| 14 | |
| 15 | function __construct(){ |
| 16 | |
| 17 | // check settings |
| 18 | if((!acfe_is_dev() && !acfe_is_super_dev()) || !acf_current_user_can_admin()){ |
| 19 | return; |
| 20 | } |
| 21 | |
| 22 | // enqueue |
| 23 | add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts')); |
| 24 | |
| 25 | // load |
| 26 | add_action('acfe/load_post', array($this, 'load_post')); |
| 27 | |
| 28 | // add meta boxes |
| 29 | add_action('acfe/add_post_meta_boxes', array($this, 'add_post_meta_boxes'), 10, 2); |
| 30 | add_action('acfe/add_posts_meta_boxes', array($this, 'add_posts_meta_boxes')); |
| 31 | add_action('acfe/add_term_meta_boxes', array($this, 'add_term_meta_boxes'), 10, 2); |
| 32 | add_action('acfe/add_terms_meta_boxes', array($this, 'add_terms_meta_boxes')); |
| 33 | add_action('acfe/add_user_meta_boxes', array($this, 'add_user_meta_boxes')); |
| 34 | add_action('acfe/add_option_meta_boxes', array($this, 'add_option_meta_boxes')); |
| 35 | |
| 36 | add_action('acfe/add_settings_meta_boxes', array($this, 'add_settings_meta_boxes')); |
| 37 | add_action('acfe/add_attachment_meta_boxes', array($this, 'add_attachment_meta_boxes')); |
| 38 | add_action('acfe/add_attachments_meta_boxes', array($this, 'add_attachments_meta_boxes')); |
| 39 | add_action('acfe/add_users_meta_boxes', array($this, 'add_users_meta_boxes')); |
| 40 | |
| 41 | // table render |
| 42 | add_filter('acfe/dev/meta/columns', array($this, 'meta_columns'), 10, 3); |
| 43 | add_action('acfe/dev/meta/render_column', array($this, 'meta_render_column'), 10, 4); |
| 44 | |
| 45 | } |
| 46 | |
| 47 | |
| 48 | /** |
| 49 | * admin_enqueue_scripts |
| 50 | */ |
| 51 | function admin_enqueue_scripts(){ |
| 52 | |
| 53 | // enqueue acf on network screen |
| 54 | if(acf_is_screen(array('profile-network', 'user-edit-network', 'user-network'))){ |
| 55 | acf_enqueue_scripts(); |
| 56 | } |
| 57 | |
| 58 | } |
| 59 | |
| 60 | |
| 61 | /** |
| 62 | * load_post |
| 63 | * |
| 64 | * acfe/load_post |
| 65 | */ |
| 66 | function load_post(){ |
| 67 | |
| 68 | // force remove wp post meta metabox |
| 69 | remove_meta_box('postcustom', false, 'normal'); |
| 70 | |
| 71 | } |
| 72 | |
| 73 | |
| 74 | /** |
| 75 | * add_post_meta_boxes |
| 76 | * |
| 77 | * acfe/add_post_meta_boxes |
| 78 | * |
| 79 | * @param $post_type |
| 80 | * @param $post |
| 81 | */ |
| 82 | function add_post_meta_boxes($post_type, $post){ |
| 83 | |
| 84 | // check restricted post types |
| 85 | if(acfe_is_post_type_reserved_dev($post_type)){ |
| 86 | return; |
| 87 | } |
| 88 | |
| 89 | // post id |
| 90 | $post_id = $post->ID; |
| 91 | |
| 92 | // add meta boxes |
| 93 | $this->add_meta_boxes($post_id, $post_type); |
| 94 | |
| 95 | // action |
| 96 | do_action('acfe/dev/clean_metabox', $post_id, $post_type, 'post'); |
| 97 | |
| 98 | } |
| 99 | |
| 100 | |
| 101 | /** |
| 102 | * add_posts_meta_boxes |
| 103 | * |
| 104 | * acfe/add_posts_meta_boxes |
| 105 | * |
| 106 | * @param $post_type |
| 107 | */ |
| 108 | function add_posts_meta_boxes($post_type){ |
| 109 | |
| 110 | // post id |
| 111 | $post_id = "{$post_type}_options"; |
| 112 | |
| 113 | // add meta boxes |
| 114 | $this->add_meta_boxes($post_id, 'edit'); |
| 115 | |
| 116 | // action |
| 117 | do_action('acfe/dev/clean_metabox', $post_id, 'edit', 'posts'); |
| 118 | |
| 119 | } |
| 120 | |
| 121 | |
| 122 | /** |
| 123 | * add_term_meta_boxes |
| 124 | * |
| 125 | * acfe/add_term_meta_boxes |
| 126 | * |
| 127 | * @param $taxonomy |
| 128 | * @param $term |
| 129 | */ |
| 130 | function add_term_meta_boxes($taxonomy, $term){ |
| 131 | |
| 132 | // post id |
| 133 | $post_id = "term_{$term->term_id}"; |
| 134 | |
| 135 | // add meta boxes |
| 136 | $this->add_meta_boxes($post_id, "edit-{$taxonomy}"); |
| 137 | |
| 138 | // action |
| 139 | do_action('acfe/dev/clean_metabox', $post_id, "edit-{$taxonomy}", 'term'); |
| 140 | |
| 141 | } |
| 142 | |
| 143 | |
| 144 | /** |
| 145 | * add_terms_meta_boxes |
| 146 | * |
| 147 | * acfe/add_terms_meta_boxes |
| 148 | * |
| 149 | * @param $taxonomy |
| 150 | */ |
| 151 | function add_terms_meta_boxes($taxonomy){ |
| 152 | |
| 153 | // post id |
| 154 | $post_id = "tax_{$taxonomy}_options"; |
| 155 | |
| 156 | // add meta boxes |
| 157 | $this->add_meta_boxes($post_id, 'edit'); |
| 158 | |
| 159 | // action |
| 160 | do_action('acfe/dev/clean_metabox', $post_id, 'edit', 'terms'); |
| 161 | |
| 162 | } |
| 163 | |
| 164 | |
| 165 | /** |
| 166 | * add_user_meta_boxes |
| 167 | * |
| 168 | * acfe/add_user_meta_boxes |
| 169 | * |
| 170 | * @param $user |
| 171 | */ |
| 172 | function add_user_meta_boxes($user){ |
| 173 | |
| 174 | // post id |
| 175 | $post_id = "user_{$user->ID}"; |
| 176 | |
| 177 | // add meta boxes |
| 178 | $this->add_meta_boxes($post_id, array('profile', 'user-edit')); |
| 179 | |
| 180 | // action |
| 181 | do_action('acfe/dev/clean_metabox', $post_id, array('profile', 'user-edit'), 'user'); |
| 182 | |
| 183 | } |
| 184 | |
| 185 | |
| 186 | /** |
| 187 | * add_option_meta_boxes |
| 188 | * |
| 189 | * acfe/add_option_meta_boxes |
| 190 | * |
| 191 | * @param $page |
| 192 | */ |
| 193 | function add_option_meta_boxes($page){ |
| 194 | |
| 195 | // post id |
| 196 | $post_id = $page['post_id']; |
| 197 | |
| 198 | // add meta boxes |
| 199 | $this->add_meta_boxes($post_id, 'acf_options_page'); |
| 200 | |
| 201 | // action |
| 202 | do_action('acfe/dev/clean_metabox', $post_id, 'acf_options_page', 'option'); |
| 203 | |
| 204 | } |
| 205 | |
| 206 | |
| 207 | /** |
| 208 | * add_settings_meta_boxes |
| 209 | * |
| 210 | * acfe/add_settings_meta_boxes |
| 211 | * |
| 212 | * @param $page |
| 213 | */ |
| 214 | function add_settings_meta_boxes($page){ |
| 215 | |
| 216 | // post id |
| 217 | $post_id = $page; |
| 218 | |
| 219 | // add meta boxes |
| 220 | $this->add_meta_boxes($post_id, $page); |
| 221 | |
| 222 | } |
| 223 | |
| 224 | |
| 225 | /** |
| 226 | * add_attachment_meta_boxes |
| 227 | * |
| 228 | * acfe/add_attachment_meta_boxes |
| 229 | * |
| 230 | * @param $post |
| 231 | */ |
| 232 | function add_attachment_meta_boxes($post){ |
| 233 | |
| 234 | // vars |
| 235 | $post_id = $post->ID; |
| 236 | $post_type = $post->post_type; |
| 237 | |
| 238 | // add meta boxes |
| 239 | $this->add_meta_boxes($post_id, $post_type); |
| 240 | |
| 241 | do_action('acfe/dev/clean_metabox', $post_id, $post_type, 'attachment'); |
| 242 | |
| 243 | } |
| 244 | |
| 245 | |
| 246 | /** |
| 247 | * add_attachments_meta_boxes |
| 248 | * |
| 249 | * acfe/add_attachments_meta_boxes |
| 250 | */ |
| 251 | function add_attachments_meta_boxes(){ |
| 252 | |
| 253 | // post id |
| 254 | $post_id = "attachment_options"; |
| 255 | |
| 256 | // add meta boxes |
| 257 | $this->add_meta_boxes($post_id, 'edit'); |
| 258 | |
| 259 | } |
| 260 | |
| 261 | |
| 262 | /** |
| 263 | * add_users_meta_boxes |
| 264 | * |
| 265 | * acfe/add_users_meta_boxes |
| 266 | */ |
| 267 | function add_users_meta_boxes(){ |
| 268 | |
| 269 | // post id |
| 270 | $post_id = "user_options"; |
| 271 | |
| 272 | // add meta boxes |
| 273 | $this->add_meta_boxes($post_id, 'edit'); |
| 274 | |
| 275 | } |
| 276 | |
| 277 | |
| 278 | /** |
| 279 | * add_meta_boxes |
| 280 | * |
| 281 | * @param $post_id |
| 282 | * @param $screen |
| 283 | */ |
| 284 | function add_meta_boxes($post_id, $screen){ |
| 285 | |
| 286 | // setup meta |
| 287 | $this->setup_meta($post_id); |
| 288 | |
| 289 | // do action |
| 290 | do_action('acfe/dev/add_meta_boxes', $post_id, $screen); |
| 291 | |
| 292 | // vars |
| 293 | $bulk = false; |
| 294 | $context = 'normal'; |
| 295 | $priority = 'low'; |
| 296 | |
| 297 | // wp meta |
| 298 | if(!empty($this->wp_meta)){ |
| 299 | |
| 300 | // display metabox on object lists screen |
| 301 | acf_set_filters(array( |
| 302 | 'acfe/post_type_list' => true, |
| 303 | 'acfe/taxonomy_list' => true, |
| 304 | 'acfe/user_list' => true, |
| 305 | 'acfe/attachment_list' => true, |
| 306 | )); |
| 307 | |
| 308 | if(empty($this->acf_meta)){ |
| 309 | $bulk = true; |
| 310 | } |
| 311 | |
| 312 | // vars |
| 313 | $id = 'acfe-wp-custom-fields'; |
| 314 | $title = $this->type === 'option' ? __('WP Options Meta', 'acfe') : __('WP Custom Fields', 'acfe'); |
| 315 | $title .= '<span class="acfe-dev-meta-count">' . count($this->wp_meta) . '</span>'; |
| 316 | |
| 317 | add_meta_box($id, $title, array($this, 'render_meta_box'), $screen, $context, $priority, array('table' => 'wp_meta', 'type' => $this->type, 'bulk' => $bulk)); |
| 318 | |
| 319 | } |
| 320 | |
| 321 | // acf meta |
| 322 | if(!empty($this->acf_meta)){ |
| 323 | |
| 324 | // display metabox on object lists screen |
| 325 | acf_set_filters(array( |
| 326 | 'acfe/post_type_list' => true, |
| 327 | 'acfe/taxonomy_list' => true, |
| 328 | 'acfe/user_list' => true, |
| 329 | 'acfe/attachment_list' => true, |
| 330 | )); |
| 331 | |
| 332 | if(!$bulk){ |
| 333 | $bulk = true; |
| 334 | } |
| 335 | |
| 336 | $id = 'acfe-acf-custom-fields'; |
| 337 | $title = $this->type === 'option' ? __('ACF Options Meta', 'acfe') : __('ACF Custom Fields', 'acfe'); |
| 338 | $title .= '<span class="acfe-dev-meta-count">' . count($this->acf_meta) . '</span>'; |
| 339 | |
| 340 | add_meta_box($id, $title, array($this, 'render_meta_box'), $screen, $context, $priority, array('table' => 'acf_meta', 'type' => $this->type, 'bulk' => $bulk)); |
| 341 | |
| 342 | } |
| 343 | |
| 344 | } |
| 345 | |
| 346 | |
| 347 | /** |
| 348 | * render_meta_box |
| 349 | * |
| 350 | * @param $post |
| 351 | * @param $metabox |
| 352 | */ |
| 353 | function render_meta_box($post, $metabox){ |
| 354 | |
| 355 | //vars |
| 356 | $args = $metabox['args']; |
| 357 | $columns = apply_filters('acfe/dev/meta/columns', array(), $args); |
| 358 | |
| 359 | ?> |
| 360 | <table class="wp-list-table widefat fixed striped"> |
| 361 | |
| 362 | <thead> |
| 363 | <tr> |
| 364 | |
| 365 | <?php foreach($columns as $column_name => $column_label): ?> |
| 366 | |
| 367 | <?php |
| 368 | $el = $column_name === 'checkbox' ? 'td' : 'th'; |
| 369 | $class = $column_name === 'checkbox' ? 'check-column' : "col-{$column_name}"; |
| 370 | |
| 371 | echo "<{$el} scope='col' class='{$class}'>{$column_label}</{$el}>"; |
| 372 | ?> |
| 373 | |
| 374 | <?php endforeach; ?> |
| 375 | |
| 376 | </tr> |
| 377 | </thead> |
| 378 | |
| 379 | <tbody> |
| 380 | |
| 381 | <?php foreach($this->{$args['table']} as $meta): ?> |
| 382 | |
| 383 | <tr> |
| 384 | |
| 385 | <?php foreach($columns as $column_name => $column_label): ?> |
| 386 | |
| 387 | <?php |
| 388 | $el = $column_name === 'checkbox' ? 'th' : 'td'; |
| 389 | $attrs = $column_name === 'checkbox' ? array('scope' => 'row', 'class' => 'check-column') : array(); |
| 390 | |
| 391 | echo "<{$el} " . acf_esc_attrs($attrs) . ">"; |
| 392 | do_action('acfe/dev/meta/render_column', $column_name, $meta, $args); |
| 393 | echo "</{$el}>"; |
| 394 | ?> |
| 395 | |
| 396 | <?php endforeach; ?> |
| 397 | |
| 398 | </tr> |
| 399 | |
| 400 | <?php endforeach; ?> |
| 401 | |
| 402 | </tbody> |
| 403 | |
| 404 | </table> |
| 405 | |
| 406 | <?php do_action('acfe/dev/meta/after_table', $args); ?> |
| 407 | <script type="text/javascript"> |
| 408 | if(typeof acf !== 'undefined'){ |
| 409 | acf.newPostbox(<?php echo json_encode(array('id' => $metabox['id'])); ?>); |
| 410 | } |
| 411 | </script> |
| 412 | <?php |
| 413 | |
| 414 | } |
| 415 | |
| 416 | |
| 417 | /** |
| 418 | * meta_columns |
| 419 | * |
| 420 | * acfe/dev/meta/columns |
| 421 | * |
| 422 | * @param $columns |
| 423 | * @param $args |
| 424 | * |
| 425 | * @return array|string[] |
| 426 | */ |
| 427 | function meta_columns($columns, $args){ |
| 428 | |
| 429 | $columns = array( |
| 430 | 'name' => __('Name', 'acfe'), |
| 431 | 'value' => __('Value', 'acfe'), |
| 432 | ); |
| 433 | |
| 434 | if(current_user_can(acf_get_setting('capability'))){ |
| 435 | $columns = array_merge(array('checkbox' => '<input type="checkbox" />'), $columns); |
| 436 | } |
| 437 | |
| 438 | if($args['table'] === 'acf_meta'){ |
| 439 | $columns['field-type'] = __('Field Type', 'acf'); |
| 440 | $columns['field-group'] = __('Field Group', 'acf'); |
| 441 | } |
| 442 | |
| 443 | if($args['type'] === 'option'){ |
| 444 | $columns['autoload'] = __('Autoload', 'acfe'); |
| 445 | } |
| 446 | |
| 447 | return $columns; |
| 448 | |
| 449 | } |
| 450 | |
| 451 | |
| 452 | /** |
| 453 | * meta_render_column |
| 454 | * |
| 455 | * acfe/dev/meta/render_column |
| 456 | * |
| 457 | * @param $column_name |
| 458 | * @param $meta |
| 459 | * @param $args |
| 460 | */ |
| 461 | function meta_render_column($column_name, $meta, $args){ |
| 462 | |
| 463 | switch($column_name){ |
| 464 | |
| 465 | case 'checkbox': { |
| 466 | |
| 467 | ?> |
| 468 | <input type="checkbox" class="acfe-dev-bulk-checkbox" value="<?php echo $meta['id']; ?>" /> |
| 469 | <?php |
| 470 | break; |
| 471 | |
| 472 | } |
| 473 | |
| 474 | case 'name': { |
| 475 | |
| 476 | ?> |
| 477 | <strong><?php echo esc_attr($meta['key']); ?></strong> |
| 478 | <?php |
| 479 | |
| 480 | $row_actions = apply_filters('acfe/dev/meta/row_actions', array(), $meta, $args); |
| 481 | |
| 482 | if($row_actions){ |
| 483 | |
| 484 | echo '<div class="row-actions">'; |
| 485 | |
| 486 | echo implode(' | ', array_map(function($action_name, $action){ |
| 487 | return "<span class='{$action_name}'>{$action}</span>"; |
| 488 | }, array_keys($row_actions), $row_actions)); |
| 489 | |
| 490 | echo '</div>'; |
| 491 | |
| 492 | } |
| 493 | |
| 494 | break; |
| 495 | |
| 496 | } |
| 497 | |
| 498 | case 'value': { |
| 499 | |
| 500 | echo $this->render_meta_value($meta['value']); |
| 501 | break; |
| 502 | |
| 503 | } |
| 504 | |
| 505 | case 'field-type': { |
| 506 | |
| 507 | echo acf_maybe_get($meta, 'field_type'); |
| 508 | break; |
| 509 | |
| 510 | } |
| 511 | |
| 512 | case 'field-group': { |
| 513 | |
| 514 | echo acf_maybe_get($meta, 'field_group'); |
| 515 | break; |
| 516 | |
| 517 | } |
| 518 | |
| 519 | case 'autoload': { |
| 520 | |
| 521 | echo $meta['autoload']; |
| 522 | break; |
| 523 | |
| 524 | } |
| 525 | |
| 526 | } |
| 527 | |
| 528 | } |
| 529 | |
| 530 | |
| 531 | /** |
| 532 | * render_meta_value |
| 533 | * |
| 534 | * @param $value |
| 535 | * |
| 536 | * @return string |
| 537 | */ |
| 538 | function render_meta_value($value){ |
| 539 | |
| 540 | // raw |
| 541 | $raw = map_deep($value, '_wp_specialchars'); |
| 542 | |
| 543 | // string (default) |
| 544 | $return = '<pre>' . print_r($raw, true) . '</pre>'; |
| 545 | |
| 546 | // empty value |
| 547 | if(acf_is_empty($value)){ |
| 548 | |
| 549 | $return = '<pre style="color:#aaa;">(' . __('empty', 'acf') . ')</pre>'; |
| 550 | |
| 551 | // serialized value |
| 552 | }elseif(is_serialized($value)){ |
| 553 | |
| 554 | $value = maybe_unserialize($value); |
| 555 | $value = @map_deep($value, '_wp_specialchars'); |
| 556 | |
| 557 | $return = '<pre>' . print_r($value, true) . '</pre>'; |
| 558 | $return .= '<pre class="raw">' . print_r($raw, true) . '</pre>'; |
| 559 | |
| 560 | // html value |
| 561 | }elseif(acfe_is_html($value)){ |
| 562 | |
| 563 | $return = '<pre>' . print_r($raw, true) . '</pre>'; |
| 564 | |
| 565 | // json value |
| 566 | }elseif(acfe_is_json($value)){ |
| 567 | |
| 568 | $value = json_decode($value); |
| 569 | $value = @map_deep($value, '_wp_specialchars'); |
| 570 | |
| 571 | $return = '<pre>' . print_r($value, true) . '</pre>'; |
| 572 | $return .= '<pre class="raw">' . print_r($raw, true) . '</pre>'; |
| 573 | |
| 574 | } |
| 575 | |
| 576 | // return |
| 577 | return $return; |
| 578 | |
| 579 | } |
| 580 | |
| 581 | |
| 582 | /** |
| 583 | * setup_meta |
| 584 | * |
| 585 | * @param $post_id |
| 586 | */ |
| 587 | function setup_meta($post_id = 0){ |
| 588 | |
| 589 | // validate |
| 590 | $post_id = acf_get_valid_post_id($post_id); |
| 591 | |
| 592 | // bail early |
| 593 | if(empty($post_id)){ |
| 594 | return; |
| 595 | } |
| 596 | |
| 597 | // extract decoded post_id |
| 598 | // $id |
| 599 | // $type |
| 600 | extract(acf_decode_post_id($post_id)); |
| 601 | |
| 602 | // set global type |
| 603 | $this->type = $type; |
| 604 | |
| 605 | // get meta |
| 606 | $all_meta = $this->get_meta($id, $type); |
| 607 | $wp_meta = $this->sort_meta($all_meta, $type); |
| 608 | |
| 609 | // bail early |
| 610 | if(empty($wp_meta)){ |
| 611 | return; |
| 612 | } |
| 613 | |
| 614 | // vars |
| 615 | $acf_meta = array(); |
| 616 | |
| 617 | // loop to prepare acf_meta |
| 618 | foreach($wp_meta as $key => $meta){ |
| 619 | |
| 620 | // no prefix, so not acf meta |
| 621 | if(!isset($wp_meta["_$key"])){ |
| 622 | continue; |
| 623 | } |
| 624 | |
| 625 | // check if key is field_abcde123456? |
| 626 | if(!acf_is_field_key($wp_meta["_$key"]['value'])){ |
| 627 | continue; |
| 628 | } |
| 629 | |
| 630 | // vars |
| 631 | $field_key = $wp_meta["_$key"]['value']; |
| 632 | $field_type = '<em>' . __('Undefined', 'acfe') . '</em>'; |
| 633 | $field_group_title = '<em>' . __('Undefined', 'acfe') . '</em>'; |
| 634 | |
| 635 | // get field |
| 636 | $field = acf_get_field($field_key); |
| 637 | |
| 638 | // check clone in sub field: field_123456abcdef_field_123456abcfed |
| 639 | if(!$field && substr_count($field_key, 'field_') > 1){ |
| 640 | |
| 641 | // get field key (last key) |
| 642 | $_field_key = substr($field_key, strrpos($field_key, 'field_')); |
| 643 | |
| 644 | // get field |
| 645 | $field = acf_get_field($_field_key); |
| 646 | |
| 647 | } |
| 648 | |
| 649 | // found field |
| 650 | if($field){ |
| 651 | |
| 652 | // Field type |
| 653 | $field_type = acf_get_field_type($field['type']); |
| 654 | $field_type = acfe_maybe_get($field_type, 'label', '<em>Undefined</em>'); |
| 655 | |
| 656 | // Field Group |
| 657 | $field_group = acfe_get_field_group_from_field($field); |
| 658 | |
| 659 | if($field_group){ |
| 660 | |
| 661 | $field_group_title = $field_group['title']; |
| 662 | |
| 663 | // no id setting, try to get raw field group from db |
| 664 | if(!$field_group['ID']){ |
| 665 | $field_group = acf_get_raw_field_group($field_group['key']); |
| 666 | } |
| 667 | |
| 668 | // found db field group |
| 669 | if($field_group && $field_group['ID']){ |
| 670 | |
| 671 | $post_status = get_post_status($field_group['ID']); |
| 672 | |
| 673 | if($post_status === 'publish' || $post_status === 'acf-disabled'){ |
| 674 | |
| 675 | $field_group_title = '<a href="' . admin_url('post.php?post=' . $field_group['ID'] . '&action=edit') . '">' . $field_group['title'] . '</a>'; |
| 676 | |
| 677 | } |
| 678 | |
| 679 | } |
| 680 | |
| 681 | } |
| 682 | |
| 683 | } |
| 684 | |
| 685 | // assign acf meta: prefix |
| 686 | $_meta = $wp_meta["_$key"]; |
| 687 | $_meta['field_type'] = $field_type; |
| 688 | $_meta['field_group'] = $field_group_title; |
| 689 | |
| 690 | $acf_meta[] = $_meta; |
| 691 | |
| 692 | // assign acf meta: normal |
| 693 | $_meta = $wp_meta[ $key ]; |
| 694 | $_meta['field_type'] = $field_type; |
| 695 | $_meta['field_group'] = $field_group_title; |
| 696 | |
| 697 | $acf_meta[] = $_meta; |
| 698 | |
| 699 | // unset wp meta |
| 700 | unset($wp_meta["_$key"]); |
| 701 | unset($wp_meta[$key]); |
| 702 | |
| 703 | } |
| 704 | |
| 705 | // assign global |
| 706 | $this->wp_meta = $wp_meta; |
| 707 | $this->acf_meta = $acf_meta; |
| 708 | |
| 709 | } |
| 710 | |
| 711 | |
| 712 | /** |
| 713 | * get_meta |
| 714 | * |
| 715 | * @param $id |
| 716 | * @param $type |
| 717 | * |
| 718 | * @return array|object|stdClass|null |
| 719 | */ |
| 720 | function get_meta($id, $type){ |
| 721 | |
| 722 | global $wpdb; |
| 723 | |
| 724 | $all_meta = null; |
| 725 | |
| 726 | switch($type){ |
| 727 | |
| 728 | case 'post': { |
| 729 | |
| 730 | $all_meta = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->postmeta} WHERE `post_id` = %d ", $id)); |
| 731 | break; |
| 732 | |
| 733 | } |
| 734 | |
| 735 | case 'term': { |
| 736 | |
| 737 | $all_meta = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->termmeta} WHERE `term_id` = %d ", $id)); |
| 738 | break; |
| 739 | |
| 740 | } |
| 741 | |
| 742 | case 'user': { |
| 743 | |
| 744 | $all_meta = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->usermeta} WHERE `user_id` = %d ", $id)); |
| 745 | break; |
| 746 | |
| 747 | } |
| 748 | |
| 749 | case 'option': { |
| 750 | |
| 751 | $search_ = $wpdb->esc_like("{$id}_") . '%'; |
| 752 | $_search_ = $wpdb->esc_like("_{$id}_") . '%'; |
| 753 | |
| 754 | $all_meta = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->options} WHERE `option_name` LIKE %s OR `option_name` LIKE %s OR `option_name` = %s", $search_, $_search_, $id)); |
| 755 | break; |
| 756 | |
| 757 | } |
| 758 | |
| 759 | } |
| 760 | |
| 761 | return $all_meta; |
| 762 | |
| 763 | } |
| 764 | |
| 765 | |
| 766 | /** |
| 767 | * sort_meta |
| 768 | * |
| 769 | * @param $all_meta |
| 770 | * @param $type |
| 771 | * |
| 772 | * @return array|false |
| 773 | */ |
| 774 | function sort_meta($all_meta, $type){ |
| 775 | |
| 776 | if(empty($all_meta)){ |
| 777 | return false; |
| 778 | } |
| 779 | |
| 780 | $wp_meta = array(); |
| 781 | |
| 782 | // re-order |
| 783 | switch($type){ |
| 784 | |
| 785 | case 'post': |
| 786 | case 'term': { |
| 787 | |
| 788 | usort($all_meta, function($a, $b){ |
| 789 | return strcmp($a->meta_key, $b->meta_key); |
| 790 | }); |
| 791 | |
| 792 | foreach($all_meta as $meta){ |
| 793 | |
| 794 | $wp_meta[ $meta->meta_key ] = array( |
| 795 | 'id' => $meta->meta_id, |
| 796 | 'key' => $meta->meta_key, |
| 797 | 'value' => $meta->meta_value, |
| 798 | 'type' => $type, |
| 799 | ); |
| 800 | |
| 801 | } |
| 802 | |
| 803 | break; |
| 804 | |
| 805 | } |
| 806 | |
| 807 | case 'user': { |
| 808 | |
| 809 | usort($all_meta, function($a, $b){ |
| 810 | return strcmp($a->meta_key, $b->meta_key); |
| 811 | }); |
| 812 | |
| 813 | foreach($all_meta as $meta){ |
| 814 | |
| 815 | $wp_meta[ $meta->meta_key ] = array( |
| 816 | 'id' => $meta->umeta_id, |
| 817 | 'key' => $meta->meta_key, |
| 818 | 'value' => $meta->meta_value, |
| 819 | 'type' => $type, |
| 820 | ); |
| 821 | |
| 822 | } |
| 823 | |
| 824 | break; |
| 825 | |
| 826 | } |
| 827 | |
| 828 | case 'option': { |
| 829 | |
| 830 | usort($all_meta, function($a, $b){ |
| 831 | return strcmp($a->option_name, $b->option_name); |
| 832 | }); |
| 833 | |
| 834 | foreach($all_meta as $meta){ |
| 835 | |
| 836 | $wp_meta[$meta->option_name] = array( |
| 837 | 'id' => $meta->option_id, |
| 838 | 'key' => $meta->option_name, |
| 839 | 'value' => $meta->option_value, |
| 840 | 'autoload' => $meta->autoload, |
| 841 | 'type' => $type, |
| 842 | ); |
| 843 | |
| 844 | } |
| 845 | |
| 846 | break; |
| 847 | |
| 848 | } |
| 849 | |
| 850 | } |
| 851 | |
| 852 | return $wp_meta; |
| 853 | |
| 854 | } |
| 855 | |
| 856 | } |
| 857 | |
| 858 | acf_new_instance('acfe_dev'); |
| 859 | |
| 860 | endif; |
| 861 | |
| 862 | /** |
| 863 | * acfe_dev_get_wp_meta |
| 864 | * |
| 865 | * @return mixed |
| 866 | */ |
| 867 | function acfe_dev_get_wp_meta(){ |
| 868 | return acf_get_instance('acfe_dev')->wp_meta; |
| 869 | } |
| 870 | |
| 871 | |
| 872 | /** |
| 873 | * acfe_dev_get_acf_meta |
| 874 | * |
| 875 | * @return mixed |
| 876 | */ |
| 877 | function acfe_dev_get_acf_meta(){ |
| 878 | return acf_get_instance('acfe_dev')->acf_meta; |
| 879 | } |
| 880 | |
| 881 | |
| 882 | /** |
| 883 | * acfe_dev_count_meta |
| 884 | * |
| 885 | * @return int |
| 886 | */ |
| 887 | function acfe_dev_count_meta(){ |
| 888 | return count(acfe_dev_get_wp_meta()) + count(acfe_dev_get_acf_meta()); |
| 889 | } |