wp_admin_bar_new_content_menu

The timeline below displays how wordpress function wp_admin_bar_new_content_menu has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.5

/**
 * Adds "Add New" menu.
 *
 * @since 3.1.0
 * @since 6.5.0 Added a New Site link for network installations.
 *
 * @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance.
 */
function wp_admin_bar_new_content_menu($wp_admin_bar)
{
    $actions = array();
    $cpts = (array) get_post_types(array('show_in_admin_bar' => true), 'objects');
    if (isset($cpts['post']) && current_user_can($cpts['post']->cap->create_posts)) {
        $actions['post-new.php'] = array($cpts['post']->labels->name_admin_bar, 'new-post');
    }
    if (isset($cpts['attachment']) && current_user_can('upload_files')) {
        $actions['media-new.php'] = array($cpts['attachment']->labels->name_admin_bar, 'new-media');
    }
    if (current_user_can('manage_links')) {
        $actions['link-add.php'] = array(_x('Link', 'add new from admin bar'), 'new-link');
    }
    if (isset($cpts['page']) && current_user_can($cpts['page']->cap->create_posts)) {
        $actions['post-new.php?post_type=page'] = array($cpts['page']->labels->name_admin_bar, 'new-page');
    }
    unset($cpts['post'], $cpts['page'], $cpts['attachment']);
    // Add any additional custom post types.
    foreach ($cpts as $cpt) {
        if (!current_user_can($cpt->cap->create_posts)) {
            continue;
        }
        $key = 'post-new.php?post_type=' . $cpt->name;
        $actions[$key] = array($cpt->labels->name_admin_bar, 'new-' . $cpt->name);
    }
    // Avoid clash with parent node and a 'content' post type.
    if (isset($actions['post-new.php?post_type=content'])) {
        $actions['post-new.php?post_type=content'][1] = 'add-new-content';
    }
    if (current_user_can('create_users') || is_multisite() && current_user_can('promote_users')) {
        $actions['user-new.php'] = array(_x('User', 'add new from admin bar'), 'new-user');
    }
    if (!$actions) {
        return;
    }
    $title = '<span class="ab-icon" aria-hidden="true"></span><span class="ab-label">' . _x('New', 'admin bar menu group label') . '</span>';
    $wp_admin_bar->add_node(array('id' => 'new-content', 'title' => $title, 'href' => admin_url(current(array_keys($actions))), 'meta' => array('menu_title' => _x('New', 'admin bar menu group label'))));
    foreach ($actions as $link => $action) {
        list($title, $id) = $action;
        $wp_admin_bar->add_node(array('parent' => 'new-content', 'id' => $id, 'title' => $title, 'href' => admin_url($link)));
    }
    if (is_multisite() && current_user_can('create_sites')) {
        $wp_admin_bar->add_node(array('parent' => 'new-content', 'id' => 'add-new-site', 'title' => _x('Site', 'add new from admin bar'), 'href' => network_admin_url('site-new.php')));
    }
}

WordPress Version: 5.9

/**
 * Adds "Add New" menu.
 *
 * @since 3.1.0
 *
 * @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance.
 */
function wp_admin_bar_new_content_menu($wp_admin_bar)
{
    $actions = array();
    $cpts = (array) get_post_types(array('show_in_admin_bar' => true), 'objects');
    if (isset($cpts['post']) && current_user_can($cpts['post']->cap->create_posts)) {
        $actions['post-new.php'] = array($cpts['post']->labels->name_admin_bar, 'new-post');
    }
    if (isset($cpts['attachment']) && current_user_can('upload_files')) {
        $actions['media-new.php'] = array($cpts['attachment']->labels->name_admin_bar, 'new-media');
    }
    if (current_user_can('manage_links')) {
        $actions['link-add.php'] = array(_x('Link', 'add new from admin bar'), 'new-link');
    }
    if (isset($cpts['page']) && current_user_can($cpts['page']->cap->create_posts)) {
        $actions['post-new.php?post_type=page'] = array($cpts['page']->labels->name_admin_bar, 'new-page');
    }
    unset($cpts['post'], $cpts['page'], $cpts['attachment']);
    // Add any additional custom post types.
    foreach ($cpts as $cpt) {
        if (!current_user_can($cpt->cap->create_posts)) {
            continue;
        }
        $key = 'post-new.php?post_type=' . $cpt->name;
        $actions[$key] = array($cpt->labels->name_admin_bar, 'new-' . $cpt->name);
    }
    // Avoid clash with parent node and a 'content' post type.
    if (isset($actions['post-new.php?post_type=content'])) {
        $actions['post-new.php?post_type=content'][1] = 'add-new-content';
    }
    if (current_user_can('create_users') || is_multisite() && current_user_can('promote_users')) {
        $actions['user-new.php'] = array(_x('User', 'add new from admin bar'), 'new-user');
    }
    if (!$actions) {
        return;
    }
    $title = '<span class="ab-icon" aria-hidden="true"></span><span class="ab-label">' . _x('New', 'admin bar menu group label') . '</span>';
    $wp_admin_bar->add_node(array('id' => 'new-content', 'title' => $title, 'href' => admin_url(current(array_keys($actions)))));
    foreach ($actions as $link => $action) {
        list($title, $id) = $action;
        $wp_admin_bar->add_node(array('parent' => 'new-content', 'id' => $id, 'title' => $title, 'href' => admin_url($link)));
    }
}

WordPress Version: 5.8

/**
 * Add "Add New" menu.
 *
 * @since 3.1.0
 *
 * @param WP_Admin_Bar $wp_admin_bar
 */
function wp_admin_bar_new_content_menu($wp_admin_bar)
{
    $actions = array();
    $cpts = (array) get_post_types(array('show_in_admin_bar' => true), 'objects');
    if (isset($cpts['post']) && current_user_can($cpts['post']->cap->create_posts)) {
        $actions['post-new.php'] = array($cpts['post']->labels->name_admin_bar, 'new-post');
    }
    if (isset($cpts['attachment']) && current_user_can('upload_files')) {
        $actions['media-new.php'] = array($cpts['attachment']->labels->name_admin_bar, 'new-media');
    }
    if (current_user_can('manage_links')) {
        $actions['link-add.php'] = array(_x('Link', 'add new from admin bar'), 'new-link');
    }
    if (isset($cpts['page']) && current_user_can($cpts['page']->cap->create_posts)) {
        $actions['post-new.php?post_type=page'] = array($cpts['page']->labels->name_admin_bar, 'new-page');
    }
    unset($cpts['post'], $cpts['page'], $cpts['attachment']);
    // Add any additional custom post types.
    foreach ($cpts as $cpt) {
        if (!current_user_can($cpt->cap->create_posts)) {
            continue;
        }
        $key = 'post-new.php?post_type=' . $cpt->name;
        $actions[$key] = array($cpt->labels->name_admin_bar, 'new-' . $cpt->name);
    }
    // Avoid clash with parent node and a 'content' post type.
    if (isset($actions['post-new.php?post_type=content'])) {
        $actions['post-new.php?post_type=content'][1] = 'add-new-content';
    }
    if (current_user_can('create_users') || is_multisite() && current_user_can('promote_users')) {
        $actions['user-new.php'] = array(_x('User', 'add new from admin bar'), 'new-user');
    }
    if (!$actions) {
        return;
    }
    $title = '<span class="ab-icon" aria-hidden="true"></span><span class="ab-label">' . _x('New', 'admin bar menu group label') . '</span>';
    $wp_admin_bar->add_node(array('id' => 'new-content', 'title' => $title, 'href' => admin_url(current(array_keys($actions)))));
    foreach ($actions as $link => $action) {
        list($title, $id) = $action;
        $wp_admin_bar->add_node(array('parent' => 'new-content', 'id' => $id, 'title' => $title, 'href' => admin_url($link)));
    }
}

WordPress Version: 5.4

/**
 * Add "Add New" menu.
 *
 * @since 3.1.0
 *
 * @param WP_Admin_Bar $wp_admin_bar
 */
function wp_admin_bar_new_content_menu($wp_admin_bar)
{
    $actions = array();
    $cpts = (array) get_post_types(array('show_in_admin_bar' => true), 'objects');
    if (isset($cpts['post']) && current_user_can($cpts['post']->cap->create_posts)) {
        $actions['post-new.php'] = array($cpts['post']->labels->name_admin_bar, 'new-post');
    }
    if (isset($cpts['attachment']) && current_user_can('upload_files')) {
        $actions['media-new.php'] = array($cpts['attachment']->labels->name_admin_bar, 'new-media');
    }
    if (current_user_can('manage_links')) {
        $actions['link-add.php'] = array(_x('Link', 'add new from admin bar'), 'new-link');
    }
    if (isset($cpts['page']) && current_user_can($cpts['page']->cap->create_posts)) {
        $actions['post-new.php?post_type=page'] = array($cpts['page']->labels->name_admin_bar, 'new-page');
    }
    unset($cpts['post'], $cpts['page'], $cpts['attachment']);
    // Add any additional custom post types.
    foreach ($cpts as $cpt) {
        if (!current_user_can($cpt->cap->create_posts)) {
            continue;
        }
        $key = 'post-new.php?post_type=' . $cpt->name;
        $actions[$key] = array($cpt->labels->name_admin_bar, 'new-' . $cpt->name);
    }
    // Avoid clash with parent node and a 'content' post type.
    if (isset($actions['post-new.php?post_type=content'])) {
        $actions['post-new.php?post_type=content'][1] = 'add-new-content';
    }
    if (current_user_can('create_users') || is_multisite() && current_user_can('promote_users')) {
        $actions['user-new.php'] = array(_x('User', 'add new from admin bar'), 'new-user');
    }
    if (!$actions) {
        return;
    }
    $title = '<span class="ab-icon"></span><span class="ab-label">' . _x('New', 'admin bar menu group label') . '</span>';
    $wp_admin_bar->add_node(array('id' => 'new-content', 'title' => $title, 'href' => admin_url(current(array_keys($actions)))));
    foreach ($actions as $link => $action) {
        list($title, $id) = $action;
        $wp_admin_bar->add_node(array('parent' => 'new-content', 'id' => $id, 'title' => $title, 'href' => admin_url($link)));
    }
}

WordPress Version: 4.8

/**
 * Add "Add New" menu.
 *
 * @since 3.1.0
 *
 * @param WP_Admin_Bar $wp_admin_bar
 */
function wp_admin_bar_new_content_menu($wp_admin_bar)
{
    $actions = array();
    $cpts = (array) get_post_types(array('show_in_admin_bar' => true), 'objects');
    if (isset($cpts['post']) && current_user_can($cpts['post']->cap->create_posts)) {
        $actions['post-new.php'] = array($cpts['post']->labels->name_admin_bar, 'new-post');
    }
    if (isset($cpts['attachment']) && current_user_can('upload_files')) {
        $actions['media-new.php'] = array($cpts['attachment']->labels->name_admin_bar, 'new-media');
    }
    if (current_user_can('manage_links')) {
        $actions['link-add.php'] = array(_x('Link', 'add new from admin bar'), 'new-link');
    }
    if (isset($cpts['page']) && current_user_can($cpts['page']->cap->create_posts)) {
        $actions['post-new.php?post_type=page'] = array($cpts['page']->labels->name_admin_bar, 'new-page');
    }
    unset($cpts['post'], $cpts['page'], $cpts['attachment']);
    // Add any additional custom post types.
    foreach ($cpts as $cpt) {
        if (!current_user_can($cpt->cap->create_posts)) {
            continue;
        }
        $key = 'post-new.php?post_type=' . $cpt->name;
        $actions[$key] = array($cpt->labels->name_admin_bar, 'new-' . $cpt->name);
    }
    // Avoid clash with parent node and a 'content' post type.
    if (isset($actions['post-new.php?post_type=content'])) {
        $actions['post-new.php?post_type=content'][1] = 'add-new-content';
    }
    if (current_user_can('create_users') || is_multisite() && current_user_can('promote_users')) {
        $actions['user-new.php'] = array(_x('User', 'add new from admin bar'), 'new-user');
    }
    if (!$actions) {
        return;
    }
    $title = '<span class="ab-icon"></span><span class="ab-label">' . _x('New', 'admin bar menu group label') . '</span>';
    $wp_admin_bar->add_menu(array('id' => 'new-content', 'title' => $title, 'href' => admin_url(current(array_keys($actions)))));
    foreach ($actions as $link => $action) {
        list($title, $id) = $action;
        $wp_admin_bar->add_menu(array('parent' => 'new-content', 'id' => $id, 'title' => $title, 'href' => admin_url($link)));
    }
}

WordPress Version: 4.2

/**
 * Add "Add New" menu.
 *
 * @since 3.1.0
 *
 * @param WP_Admin_Bar $wp_admin_bar
 */
function wp_admin_bar_new_content_menu($wp_admin_bar)
{
    $actions = array();
    $cpts = (array) get_post_types(array('show_in_admin_bar' => true), 'objects');
    if (isset($cpts['post']) && current_user_can($cpts['post']->cap->create_posts)) {
        $actions['post-new.php'] = array($cpts['post']->labels->name_admin_bar, 'new-post');
    }
    if (isset($cpts['attachment']) && current_user_can('upload_files')) {
        $actions['media-new.php'] = array($cpts['attachment']->labels->name_admin_bar, 'new-media');
    }
    if (current_user_can('manage_links')) {
        $actions['link-add.php'] = array(_x('Link', 'add new from admin bar'), 'new-link');
    }
    if (isset($cpts['page']) && current_user_can($cpts['page']->cap->create_posts)) {
        $actions['post-new.php?post_type=page'] = array($cpts['page']->labels->name_admin_bar, 'new-page');
    }
    unset($cpts['post'], $cpts['page'], $cpts['attachment']);
    // Add any additional custom post types.
    foreach ($cpts as $cpt) {
        if (!current_user_can($cpt->cap->create_posts)) {
            continue;
        }
        $key = 'post-new.php?post_type=' . $cpt->name;
        $actions[$key] = array($cpt->labels->name_admin_bar, 'new-' . $cpt->name);
    }
    // Avoid clash with parent node and a 'content' post type.
    if (isset($actions['post-new.php?post_type=content'])) {
        $actions['post-new.php?post_type=content'][1] = 'add-new-content';
    }
    if (current_user_can('create_users') || current_user_can('promote_users')) {
        $actions['user-new.php'] = array(_x('User', 'add new from admin bar'), 'new-user');
    }
    if (!$actions) {
        return;
    }
    $title = '<span class="ab-icon"></span><span class="ab-label">' . _x('New', 'admin bar menu group label') . '</span>';
    $wp_admin_bar->add_menu(array('id' => 'new-content', 'title' => $title, 'href' => admin_url(current(array_keys($actions)))));
    foreach ($actions as $link => $action) {
        list($title, $id) = $action;
        $wp_admin_bar->add_menu(array('parent' => 'new-content', 'id' => $id, 'title' => $title, 'href' => admin_url($link)));
    }
}

WordPress Version: 3.7

/**
 * Add "Add New" menu.
 *
 * @since 3.1.0
 *
 * @param WP_Admin_Bar $wp_admin_bar
 */
function wp_admin_bar_new_content_menu($wp_admin_bar)
{
    $actions = array();
    $cpts = (array) get_post_types(array('show_in_admin_bar' => true), 'objects');
    if (isset($cpts['post']) && current_user_can($cpts['post']->cap->create_posts)) {
        $actions['post-new.php'] = array($cpts['post']->labels->name_admin_bar, 'new-post');
    }
    if (isset($cpts['attachment']) && current_user_can('upload_files')) {
        $actions['media-new.php'] = array($cpts['attachment']->labels->name_admin_bar, 'new-media');
    }
    if (current_user_can('manage_links')) {
        $actions['link-add.php'] = array(_x('Link', 'add new from admin bar'), 'new-link');
    }
    if (isset($cpts['page']) && current_user_can($cpts['page']->cap->create_posts)) {
        $actions['post-new.php?post_type=page'] = array($cpts['page']->labels->name_admin_bar, 'new-page');
    }
    unset($cpts['post'], $cpts['page'], $cpts['attachment']);
    // Add any additional custom post types.
    foreach ($cpts as $cpt) {
        if (!current_user_can($cpt->cap->create_posts)) {
            continue;
        }
        $key = 'post-new.php?post_type=' . $cpt->name;
        $actions[$key] = array($cpt->labels->name_admin_bar, 'new-' . $cpt->name);
    }
    // Avoid clash with parent node and a 'content' post type.
    if (isset($actions['post-new.php?post_type=content'])) {
        $actions['post-new.php?post_type=content'][1] = 'add-new-content';
    }
    if (current_user_can('create_users') || current_user_can('promote_users')) {
        $actions['user-new.php'] = array(_x('User', 'add new from admin bar'), 'new-user');
    }
    if (!$actions) {
        return;
    }
    $title = '<span class="ab-icon"></span><span class="ab-label">' . _x('New', 'admin bar menu group label') . '</span>';
    $wp_admin_bar->add_menu(array('id' => 'new-content', 'title' => $title, 'href' => admin_url(current(array_keys($actions))), 'meta' => array('title' => _x('Add New', 'admin bar menu group label'))));
    foreach ($actions as $link => $action) {
        list($title, $id) = $action;
        $wp_admin_bar->add_menu(array('parent' => 'new-content', 'id' => $id, 'title' => $title, 'href' => admin_url($link)));
    }
}