'acfe_dev_clean' ), $url); // redirect wp_redirect($url); exit; } // success message if(acf_maybe_get_GET('message') === 'acfe_dev_clean'){ $deleted = acf_get_array(get_transient('acfe_dev_clean')); $count = count($deleted); if(isset($deleted['single_meta']) || isset($deleted['normal'])){ $count = 0; $count += count(acf_maybe_get($deleted, 'single_meta', array())); $count += count(acf_maybe_get($deleted, 'normal', array())); } if(!$deleted){ acf_add_admin_notice(__('No orphan meta found', 'acfe'), 'warning'); }else{ $link = ' ' . __('View', 'acfe') . ''; add_action('admin_footer', function() use($deleted){ ?>
| Name | Value | Field Type | Field group | Autoload | |
|---|---|---|---|---|---|
' . print_r($value, true) . ''; } // Serialized elseif(is_serialized($value)){ $return = '
' . 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) . ''; } return $return; } function get_meta($post_id = 0){ // Validate post id $post_id = acf_get_valid_post_id($post_id); // Post id empty if(empty($post_id)) return; // Decode post id $info = acf_decode_post_id($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)); } // No meta found 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){ // Bail early if no prefix found if(!isset($wp_meta["_$key"])) continue; // Check if key is field_abcde123456? if(!acf_is_field_key($wp_meta["_$key"]['value'])) continue; // Vars $field_key = $wp_meta["_$key"]['value']; $field_type = 'Undefined'; $field_group_title = 'Undefined'; // Get field $field = acf_get_field($field_key); // Check clone in sub field: field_123456abcdef_field_123456abcfed if(!$field && substr_count($field_key, 'field_') > 1){ // get field key (last key) $_field_key = substr($field_key, strrpos($field_key, 'field_')); // get field $field = acf_get_field($_field_key); } // Found field if($field){ // Field type $field_type = acf_get_field_type($field['type']); $field_type = acfe_maybe_get($field_type, 'label', 'Undefined'); // Field Group $field_group = acfe_get_field_group_from_field($field); if($field_group){ $field_group_title = $field_group['title']; // no id setting, try to get raw field group from db if(!$field_group['ID']){ $field_group = acf_get_raw_field_group($field_group['key']); } // found db field group if($field_group && $field_group['ID']){ $post_status = get_post_status($field_group['ID']); if($post_status === 'publish' || $post_status === 'acf-disabled'){ $field_group_title = '' . $field_group['title'] . ''; } } } } // Assign ACF meta: prefix $_meta = $wp_meta["_$key"]; $_meta['field_type'] = $field_type; $_meta['field_group'] = $field_group_title; $acf_meta[] = $_meta; // Assign ACF meta: normal $_meta = $wp_meta[$key]; $_meta['field_type'] = $field_type; $_meta['field_group'] = $field_group_title; $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 foreach($ids as $id){ delete_metadata_by_mid($type, $id); } wp_die(1); } } acf_new_instance('acfe_dev'); endif; function acfe_dev_get_wp_meta(){ return acf_get_instance('acfe_dev')->wp_meta; } function acfe_dev_get_acf_meta(){ return acf_get_instance('acfe_dev')->acf_meta; } function acfe_dev_count_meta(){ return count(acfe_dev_get_wp_meta()) + count(acfe_dev_get_acf_meta()); }