add_meta_boxes(0, $post_type); } /* * Term */ function load_term(){ $screen = get_current_screen(); $taxonomy = $screen->taxonomy; // actions add_action("{$taxonomy}_edit_form", array($this, 'edit_term'), 20, 2); } function edit_term($term, $taxonomy){ // Get Term ID $post_id = acf_get_term_post_id($term->taxonomy, $term->term_id); // Add Meta Boxes $this->add_meta_boxes($post_id, 'edit-term'); // Poststuff echo '
'; do_meta_boxes('edit-term', 'normal', array()); echo '
'; } /* * User */ function load_user(){ // Get User ID global $user_id; $user_id = (int) $user_id; if(empty($user_id)) return; // Add Meta Boxes $this->add_meta_boxes('user_' . $user_id, 'edit-user'); // Poststuff echo '
'; do_meta_boxes('edit-user', 'normal', array()); echo '
'; } /* * Admin */ function load_admin($page){ $this->add_meta_boxes($page['post_id'], 'acf_options_page'); } /* * Add Meta Boxes */ function add_meta_boxes($post_id = 0, $object_type){ // Get Meta $this->get_meta($post_id); // WP Metabox if(!empty($this->wp_meta)){ $id = 'acfe-wp-custom-fields'; $title = 'WP Custom fields ' . count($this->wp_meta) . ''; $context = 'normal'; $priority = 'low'; add_meta_box($id, $title, array($this, 'wp_render_meta_box'), $object_type, $context, $priority); } // ACF Metabox if(!empty($this->acf_meta)){ $id = 'acfe-acf-custom-fields'; $title = 'ACF Custom fields ' . count($this->acf_meta) . ''; $context = 'normal'; $priority = 'low'; add_meta_box($id, $title, array($this, 'acf_render_meta_box'), $object_type, $context, $priority); } } function wp_render_meta_box($post, $metabox){ ?> wp_meta as $meta_key => $meta_value){ ?> render_meta_value($meta_value); ?>
Name Value
acf_meta as $meta){ ?> ' . $field_group['title'] . ''; } } } $value_display = $this->render_meta_value($meta['value']); ?>
Name Value Field group
' . 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{ $css = ''; if(empty($value)){ $css = 'color:#aaa;'; $value = '(' . __('empty', 'acf') . ')'; } $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 = 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", $search, $_search)); } if(empty($get_meta)) return; $wp_meta = array(); // Post / Term / User if($info['type'] !== 'option'){ usort($get_meta, function($a, $b){ return strcmp($a->meta_key, $b->meta_key); }); foreach($get_meta as $meta){ $wp_meta[$meta->meta_key] = $meta->meta_value; } // Option }else{ usort($get_meta, function($a, $b){ return strcmp($a->option_name, $b->option_name); }); foreach($get_meta as $meta){ $wp_meta[$meta->option_name] = $meta->option_value; } } $acf_meta = array(); foreach($wp_meta as $key => $value){ // ACF Meta if(isset($wp_meta["_$key"])){ $field = false; $field_group = false; if(acf_is_field_key($wp_meta["_$key"])){ $field = acf_get_field($wp_meta["_$key"]); $field_group = acfe_get_field_group_from_field($field); } $acf_meta[] = array( 'key' => "_$key", 'value' => $wp_meta["_$key"], 'field' => $field, 'field_group' => $field_group, ); $acf_meta[] = array( 'key' => $key, 'value' => $wp_meta[$key], 'field' => $field, 'field_group' => $field_group, ); unset($wp_meta["_$key"]); unset($wp_meta[$key]); } } $this->wp_meta = $wp_meta; $this->acf_meta = $acf_meta; } } new acfe_dev(); endif;