ID; // Add Meta Boxes $this->add_meta_boxes($post_id, $post_type); } /* * Term */ function load_term(){ $screen = get_current_screen(); $taxonomy = $screen->taxonomy; // actions add_action("{$taxonomy}_edit_form", array($this, 'edit_term'), 10, 2); } function edit_term($term, $taxonomy){ // Get Term ID $post_id = 'term_' . $term->term_id; // Add Meta Boxes $this->add_meta_boxes($post_id, "edit-{$taxonomy}"); } /* * User */ function load_user($user){ $post_id = 'user_' . $user->ID; // Add Meta Boxes $this->add_meta_boxes($post_id, array('profile', 'user-edit')); } /* * Admin */ function load_options($page){ $this->add_meta_boxes($page['post_id'], 'acf_options_page'); } /* * Add Meta Boxes */ function add_meta_boxes($post_id, $object_type){ // Get Meta $this->get_meta($post_id); do_action('acfe/dev/add_meta_boxes', $post_id, $object_type); $render_bulk = false; // WP Metabox if(!empty($this->wp_meta)){ if(empty($this->acf_meta)) $render_bulk = true; $id = 'acfe-wp-custom-fields'; $title = 'WP Custom Fields'; if($object_type === 'acf_options_page'){ $title = 'WP Options Meta'; } $title .= ''; $context = 'normal'; $priority = 'low'; add_meta_box($id, $title, array($this, 'render_meta_box'), $object_type, $context, $priority, array('table_type' => 'wp', 'object_type' => $object_type, 'render_bulk' => $render_bulk)); } // ACF Metabox if(!empty($this->acf_meta)){ if(!$render_bulk) $render_bulk = true; $id = 'acfe-acf-custom-fields'; $title = 'ACF Custom Fields'; if($object_type === 'acf_options_page'){ $title = 'ACF Options Meta'; } $title .= ''; $context = 'normal'; $priority = 'low'; add_meta_box($id, $title, array($this, 'render_meta_box'), $object_type, $context, $priority, array('table_type' => 'acf', 'object_type' => $object_type, 'render_bulk' => $render_bulk)); } } function render_meta_box($post, $metabox){ $table_type = $metabox['args']['table_type']; $object_type = $metabox['args']['object_type']; $render_bulk = $metabox['args']['render_bulk']; $is_options = ($object_type === 'acf_options_page'); $is_acf = ($table_type === 'acf'); $metas = $this->wp_meta; if($is_acf) $metas = $this->acf_meta; ?>
| Name | Value | Field Type | Field group | Autoload | |
|---|---|---|---|---|---|
' . print_r(maybe_unserialize($value), true) . ''; $return .= '
' . print_r($value, true) . ''; } // HTML elseif($value != strip_tags($value)){ $return = '
' . print_r(htmlentities($value), true) . ''; } // Json elseif(acfe_is_json($value)){ $return = '
' . print_r(json_decode($value), true) . ''; $return .= '
' . print_r($value, true) . ''; } // String else{ $return = '
' . print_r($value, true) . ''; } return $return; } function get_meta($post_id = 0){ if(!$post_id) $post_id = acf_get_valid_post_id(); if(empty($post_id)) return; $info = acf_get_post_id_info($post_id); global $wpdb; // Post if($info['type'] === 'post'){ $get_meta = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->postmeta WHERE post_id = %d ", $info['id'])); } // Term elseif($info['type'] === 'term'){ $get_meta = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->termmeta WHERE term_id = %d ", $info['id'])); } // User elseif($info['type'] === 'user'){ $get_meta = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->usermeta WHERE user_id = %d ", $info['id'])); } // Option elseif($info['type'] === 'option'){ $id = $info['id']; $search = "{$id}_%"; $_search = "_{$id}_%"; $search_single = "{$id}"; $search = str_replace('_', '\_', $search); $_search = str_replace('_', '\_', $_search); $get_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, $search_single)); } if(empty($get_meta)) return; $wp_meta = array(); // Option if($info['type'] === 'option'){ usort($get_meta, function($a, $b){ return strcmp($a->option_name, $b->option_name); }); foreach($get_meta as $meta){ $wp_meta[$meta->option_name] = array( 'id' => $meta->option_id, 'key' => $meta->option_name, 'value' => $meta->option_value, 'autoload' => $meta->autoload, 'type' => $info['type'], ); } // Post / Term }elseif($info['type'] === 'post' || $info['type'] === 'term'){ usort($get_meta, function($a, $b){ return strcmp($a->meta_key, $b->meta_key); }); foreach($get_meta as $meta){ $wp_meta[$meta->meta_key] = array( 'id' => $meta->meta_id, 'key' => $meta->meta_key, 'value' => $meta->meta_value, 'type' => $info['type'], ); } // User }elseif($info['type'] === 'user'){ usort($get_meta, function($a, $b){ return strcmp($a->meta_key, $b->meta_key); }); foreach($get_meta as $meta){ $wp_meta[$meta->meta_key] = array( 'id' => $meta->umeta_id, 'key' => $meta->meta_key, 'value' => $meta->meta_value, 'type' => $info['type'], ); } } $acf_meta = array(); foreach($wp_meta as $key => $meta){ // ACF Meta if(isset($wp_meta["_$key"])){ $field = false; $field_type_display = false; $field_group_display = false; $field_key = $wp_meta["_$key"]['value']; // Value = field_abcde123456? if(acf_is_field_key($field_key)){ $field = acf_get_field($field_key); if(!$field){ $field_type_display = 'Undefined'; $field_group_display = 'Undefined'; // Check clone: field_123456abcdef_field_123456abcfed $count = substr_count($field_key, 'field_'); if($count === 2){ $keys = explode('field_', $field_key); $field_1 = 'field_' . substr($keys[1], 0, -1); $field_2 = 'field_' . $keys[2]; $field = acf_get_field($field_2); } } if($field){ $field_type = acf_get_field_type($field['type']); $field_type_display = 'Undefined'; if(isset($field_type->label)) $field_type_display = $field_type->label; $field_group = acfe_get_field_group_from_field($field); $field_group_display = 'Undefined'; if($field_group){ $field_group_display = $field_group['title']; if(!empty($field_group['ID'])){ $post_status = get_post_status($field_group['ID']); if($post_status === 'publish' || $post_status === 'acf-disabled'){ $field_group_display = '' . $field_group['title'] . ''; } } } } } $_meta = $wp_meta["_$key"]; $_meta['field_type'] = $field_type_display; $_meta['field_group'] = $field_group_display; $acf_meta[] = $_meta; $_meta = $wp_meta[$key]; $_meta['field_type'] = $field_type_display; $_meta['field_group'] = $field_group_display; $acf_meta[] = $_meta; // Unset WP Meta unset($wp_meta["_$key"]); unset($wp_meta[$key]); } } $this->wp_meta = $wp_meta; $this->acf_meta = $acf_meta; } function ajax_delete_meta(){ // Vars $id = acf_maybe_get_POST('id'); $key = acf_maybe_get_POST('key'); $type = acf_maybe_get_POST('type'); // Check vars if(!$id || !$key || !$type) wp_die(0); // Check referer check_ajax_referer("acfe_delete_meta_$id"); if(!current_user_can(acf_get_setting('capability'))){ wp_die(-1); } // Delete option if($type === 'option'){ if(delete_option($key)) wp_die(1); // Delete meta }else{ if(delete_metadata_by_mid($type, $id)) wp_die(1); } wp_die(0); } function ajax_bulk_delete_meta(){ // Vars $ids = acf_maybe_get_POST('ids'); $type = acf_maybe_get_POST('type'); // Check vars if(!$ids || !$type) wp_die(0); // Check referer check_ajax_referer('acfe_bulk_delete_meta'); if(!current_user_can(acf_get_setting('capability'))){ wp_die(-1); } // Delete option if($type === 'option'){ foreach($ids as $key){ delete_option($key); } wp_die(1); // Delete meta }else{ foreach($ids as $id){ delete_metadata_by_mid($type, $id); } wp_die(1); } wp_die(0); } } new acfe_dev(); endif;