update_gallery_tab

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

WordPress Version: 6.1

/**
 * Adds the gallery tab back to the tabs array if post has image attachments.
 *
 * @since 2.5.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param array $tabs
 * @return array $tabs with gallery if post has image attachment
 */
function update_gallery_tab($tabs)
{
    global $wpdb;
    if (!isset($_REQUEST['post_id'])) {
        unset($tabs['gallery']);
        return $tabs;
    }
    $post_id = (int) $_REQUEST['post_id'];
    if ($post_id) {
        $attachments = (int) $wpdb->get_var($wpdb->prepare("SELECT count(*) FROM {$wpdb->posts} WHERE post_type = 'attachment' AND post_status != 'trash' AND post_parent = %d", $post_id));
    }
    if (empty($attachments)) {
        unset($tabs['gallery']);
        return $tabs;
    }
    /* translators: %s: Number of attachments. */
    $tabs['gallery'] = sprintf(__('Gallery (%s)'), "<span id='attachments-count'>{$attachments}</span>");
    return $tabs;
}

WordPress Version: 5.6

/**
 * Adds the gallery tab back to the tabs array if post has image attachments
 *
 * @since 2.5.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param array $tabs
 * @return array $tabs with gallery if post has image attachment
 */
function update_gallery_tab($tabs)
{
    global $wpdb;
    if (!isset($_REQUEST['post_id'])) {
        unset($tabs['gallery']);
        return $tabs;
    }
    $post_id = (int) $_REQUEST['post_id'];
    if ($post_id) {
        $attachments = (int) $wpdb->get_var($wpdb->prepare("SELECT count(*) FROM {$wpdb->posts} WHERE post_type = 'attachment' AND post_status != 'trash' AND post_parent = %d", $post_id));
    }
    if (empty($attachments)) {
        unset($tabs['gallery']);
        return $tabs;
    }
    /* translators: %s: Number of attachments. */
    $tabs['gallery'] = sprintf(__('Gallery (%s)'), "<span id='attachments-count'>{$attachments}</span>");
    return $tabs;
}

WordPress Version: 5.3

/**
 * Adds the gallery tab back to the tabs array if post has image attachments
 *
 * @since 2.5.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param array $tabs
 * @return array $tabs with gallery if post has image attachment
 */
function update_gallery_tab($tabs)
{
    global $wpdb;
    if (!isset($_REQUEST['post_id'])) {
        unset($tabs['gallery']);
        return $tabs;
    }
    $post_id = intval($_REQUEST['post_id']);
    if ($post_id) {
        $attachments = intval($wpdb->get_var($wpdb->prepare("SELECT count(*) FROM {$wpdb->posts} WHERE post_type = 'attachment' AND post_status != 'trash' AND post_parent = %d", $post_id)));
    }
    if (empty($attachments)) {
        unset($tabs['gallery']);
        return $tabs;
    }
    /* translators: %s: Number of attachments. */
    $tabs['gallery'] = sprintf(__('Gallery (%s)'), "<span id='attachments-count'>{$attachments}</span>");
    return $tabs;
}

WordPress Version: 4.4

/**
 * Adds the gallery tab back to the tabs array if post has image attachments
 *
 * @since 2.5.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param array $tabs
 * @return array $tabs with gallery if post has image attachment
 */
function update_gallery_tab($tabs)
{
    global $wpdb;
    if (!isset($_REQUEST['post_id'])) {
        unset($tabs['gallery']);
        return $tabs;
    }
    $post_id = intval($_REQUEST['post_id']);
    if ($post_id) {
        $attachments = intval($wpdb->get_var($wpdb->prepare("SELECT count(*) FROM {$wpdb->posts} WHERE post_type = 'attachment' AND post_status != 'trash' AND post_parent = %d", $post_id)));
    }
    if (empty($attachments)) {
        unset($tabs['gallery']);
        return $tabs;
    }
    $tabs['gallery'] = sprintf(__('Gallery (%s)'), "<span id='attachments-count'>{$attachments}</span>");
    return $tabs;
}

WordPress Version: 4.3

/**
 * Adds the gallery tab back to the tabs array if post has image attachments
 *
 * @since 2.5.0
 *
 * @global wpdb $wpdb
 *
 * @param array $tabs
 * @return array $tabs with gallery if post has image attachment
 */
function update_gallery_tab($tabs)
{
    global $wpdb;
    if (!isset($_REQUEST['post_id'])) {
        unset($tabs['gallery']);
        return $tabs;
    }
    $post_id = intval($_REQUEST['post_id']);
    if ($post_id) {
        $attachments = intval($wpdb->get_var($wpdb->prepare("SELECT count(*) FROM {$wpdb->posts} WHERE post_type = 'attachment' AND post_status != 'trash' AND post_parent = %d", $post_id)));
    }
    if (empty($attachments)) {
        unset($tabs['gallery']);
        return $tabs;
    }
    $tabs['gallery'] = sprintf(__('Gallery (%s)'), "<span id='attachments-count'>{$attachments}</span>");
    return $tabs;
}

WordPress Version: 3.7

/**
 * Adds the gallery tab back to the tabs array if post has image attachments
 *
 * @since 2.5.0
 *
 * @param array $tabs
 * @return array $tabs with gallery if post has image attachment
 */
function update_gallery_tab($tabs)
{
    global $wpdb;
    if (!isset($_REQUEST['post_id'])) {
        unset($tabs['gallery']);
        return $tabs;
    }
    $post_id = intval($_REQUEST['post_id']);
    if ($post_id) {
        $attachments = intval($wpdb->get_var($wpdb->prepare("SELECT count(*) FROM {$wpdb->posts} WHERE post_type = 'attachment' AND post_status != 'trash' AND post_parent = %d", $post_id)));
    }
    if (empty($attachments)) {
        unset($tabs['gallery']);
        return $tabs;
    }
    $tabs['gallery'] = sprintf(__('Gallery (%s)'), "<span id='attachments-count'>{$attachments}</span>");
    return $tabs;
}