update_gallery_tab

Adds the gallery tab back to the tabs array if post has image attachments.

Description

(array) update_gallery_tab( (array) $tabs ); 

Returns (array)

$tabs with gallery if post has image attachment

Parameters (1)

0. $tabs (array)
The tabs.

Usage

  1. if ( !function_exists( 'update_gallery_tab' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/media.php'; 
  3.  
  4. // The tabs. 
  5. $tabs = array(); 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = update_gallery_tab($tabs); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/media.php  
  1. function update_gallery_tab($tabs) { 
  2. global $wpdb; 
  3.  
  4. if ( !isset($_REQUEST['post_id']) ) { 
  5. unset($tabs['gallery']); 
  6. return $tabs; 
  7.  
  8. $post_id = intval($_REQUEST['post_id']); 
  9.  
  10. if ( $post_id ) 
  11. $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 ) ) ); 
  12.  
  13. if ( empty($attachments) ) { 
  14. unset($tabs['gallery']); 
  15. return $tabs; 
  16.  
  17. $tabs['gallery'] = sprintf(__('Gallery (%s)'), "<span id='attachments-count'>$attachments</span>"); 
  18.  
  19. return $tabs;