function ameta_list_excluded_keys()
{
    global $wpdb;
    //we need to allow manual exclusion of metakeys becuase of s2members strange time keys on access_cap_limits and who knows there might be others.
    if (!($excluded_meta_keys = ausers_get_option('amr-users-excluded-meta-keys'))) {
        $excluded_meta_keys = amr_default_excluded_metakeys();
    }
    // check if we have any new keys since last time, no need to fetch
    $q = "SELECT meta_key, COUNT(umeta_id) AS Count FROM {$wpdb->usermeta} GROUP BY meta_key";
    $allkeys = $wpdb->get_results($q, ARRAY_A);
    $num_keys = count($allkeys);
    $exc_keys = 0;
    foreach ($allkeys as $i => $row) {
        if (!isset($excluded_meta_keys[$row['meta_key']])) {
            $excluded_meta_keys[$row['meta_key']] = false;
            //echo '<br />'.__('Added meta to report DB: ','amr-users').$row['meta_key'];
        }
        if ($excluded_meta_keys[$row['meta_key']]) {
            $exc_keys = $exc_keys + 1;
        }
        $totals[$row['meta_key']] = $allkeys[$i]['Count'];
    }
    ksort($excluded_meta_keys);
    echo PHP_EOL . '<div class="clear"> </div>' . PHP_EOL;
    echo '<div><!-- excluded keys list-->';
    echo '<h2>' . __('User meta keys in this site today', 'amr-users') . ' (' . $num_keys . ') - ' . sprintf(__('%s excluded', 'amr-users'), $exc_keys) . '</h2>';
    echo '<ul>' . '<li>' . __('Extracts the current distinct user meta keys used', 'amr-users') . ' - <strong>' . __('Sample data MUST exist!', 'amr-users') . '</strong>' . '</li>' . '</ul>';
    echo ameta_keys_update_buttons();
    // the buttons
    echo '<table class="widefat">';
    echo '<tr><th>' . __('Meta Key', 'amr-users') . '</th>' . '<th>' . __('Exclude?', 'amr-users') . '</th>' . '<th>' . __('Delete meta records?', 'amr-users') . '</th>' . '</tr>';
    foreach ($excluded_meta_keys as $i => $v) {
        if (empty($totals[$i])) {
            continue;
        }
        //ie it has not been deleted since we saved
        echo "\n\t" . '<tr>' . '<td>' . $i . '</td><td>';
        if ($i === 'ID') {
            echo ' ';
        } else {
            echo '<input type="checkbox" id="mex' . $i . '"  name="mex[' . $i . ']"';
            if (!empty($excluded_meta_keys[$i])) {
                echo ' value=true checked="checked" ';
            }
            echo ' />';
        }
        echo '</td><td>';
        if ($i === 'ID') {
            echo ' ';
        } else {
            echo '<input type="checkbox" id="del' . $i . '"  name="del[' . $i . ']"';
            echo ' />';
            echo ' (' . $totals[$i] . ')';
        }
        echo '</td></tr>';
    }
    echo "\n\t" . '</table>' . PHP_EOL . '</div><!-- excluded keys list-->' . PHP_EOL;
    return;
}
function amr_get_alluserkeys()
{
    global $wpdb, $amr_nicenames;
    /*  get all user data and attempt to extract out any object values into arrays for listing  */
    $keys = array('avatar' => 'avatar', 'comment_count' => 'comment_count', 'post_count' => 'post_count');
    $post_types = get_post_types();
    foreach ($post_types as $posttype) {
        $keys[$posttype] = $posttype . '_count';
    }
    $all = amr_get_usermasterfields();
    echo '<h3>' . sprintf(__('You have %s main user table fields', 'amr-users'), count($all)) . '</h3>';
    foreach ($all as $i2 => $v2) {
        if (!amr_excluded_userkey($v2)) {
            $keys[$v2] = $v2;
            if (isset($keys[$v2])) {
                echo ' &#10003;' . $v2;
            } else {
                echo '<br />' . __('Added to report DB:', 'amr-users') . ' ' . $v2;
            }
        } else {
            if (isset($keys[$v2])) {
                unset($keys[$v2]);
            }
            echo '<br />' . __('Excluded:', 'amr-users') . ' "' . $v2 . '"<br />';
        }
    }
    /* Do the meta first  */
    if (!($excluded_meta_keys = ausers_get_option('amr-users-excluded-meta-keys'))) {
        $excluded_meta_keys = amr_default_excluded_metakeys();
    }
    foreach ($excluded_meta_keys as $key => $on) {
        if ($on) {
            $text[] = $key;
        }
    }
    $string = "'" . implode($text, "','") . "'";
    $w = " WHERE meta_key NOT IN (" . $string . ")";
    $q = "SELECT DISTINCTROW meta_key, meta_value FROM {$wpdb->usermeta}" . $w;
    // need the meta value for those like ym where there is one key but there may be complex stuff in the meta.
    if ($mkeys = amr_get_next_level_keys($q)) {
        //if (WP_DEBUG) {echo '<br />For Debug: next level keys'; var_dump($mkeys);}
        if (is_array($mkeys)) {
            $keys = array_merge($keys, $mkeys);
            echo '<h3>' . count($mkeys) . ' distinct "fields" dug out from the meta key/value combination records. </h3>';
        }
        //if (WP_DEBUG) {echo '<br />For Debug: Merged keys'; var_dump($keys);}
    }
    unset($mkeys);
    echo '<h3>' . __('Check for fields from non wp tables.', 'amr-users') . '</h3>';
    $keys2 = apply_filters('amr_get_fields', $keys);
    //eg: 'avatar'=>'avatar',
    foreach ($keys2 as $k => $v) {
        if (!isset($keys[$k]) and !isset($amr_nicenames[$v])) {
            echo '"' . $v . '" added.<br />';
        }
    }
    return $keys2;
}