Exemplo n.º 1
0
/**
 * Fix submenu highlights
 *
 * @since 0.1.0
 *
 * @global  string  $plugin_page
 * @global  string  $submenu_file
 */
function wp_user_profiles_admin_menu_highlight()
{
    global $plugin_page, $submenu_file;
    // Bail if in user dashboard area
    if (is_user_admin()) {
        return;
    }
    // If not current user's profile page, set to Users and bail
    if (!empty($_GET['user_id']) && get_current_user_id() !== (int) $_GET['user_id']) {
        $submenu_file = wp_user_profiles_get_file();
        return;
    }
    // Get slugs from profile sections
    $plucked = wp_user_profiles_get_section_hooknames();
    // Maybe tweak the highlighted submenu
    if (!in_array($plugin_page, array($plucked), true)) {
        if (current_user_can('list_users')) {
            $submenu_file = 'profile';
        } elseif (is_blog_admin()) {
            $plugin_page = 'profile';
        }
    }
}
/**
 * Return the admin area URL for a user
 *
 * This function exists to make it easier to determine which admin area URL to
 * use in what context. It also comes with its own filter to make it easier to
 * target its usages.
 *
 * @since 0.1.0
 *
 * @param  int     $user_id
 * @param  string  $scheme
 * @param  array   $args
 *
 * @return string
 */
function wp_user_profiles_get_admin_area_url($user_id = 0, $scheme = '', $args = array())
{
    $file = wp_user_profiles_get_file();
    // User admin (multisite only)
    if (is_user_admin()) {
        $url = user_admin_url($file, $scheme);
        // Network admin editing
    } elseif (is_network_admin()) {
        $url = network_admin_url($file, $scheme);
        // Fallback dashboard
    } else {
        $url = get_dashboard_url($user_id, $file, $scheme);
    }
    // Add user ID to args array for other users
    if (!empty($user_id) && $user_id !== get_current_user_id()) {
        $args['user_id'] = $user_id;
    }
    // Add query args
    $url = add_query_arg($args, $url);
    // Filter and return
    return apply_filters('wp_user_profiles_get_admin_area_url', $url, $user_id, $scheme, $args);
}