如果post具有图像附件,则将gallery选项卡添加回tabs数组

原型

update_gallery_tab( array $tabs )

参数

$tabs (array) (Required)

返回值

(array)  如果帖子有图片附件,则带有图库的$标签

源文件

路径:wp-admin/includes/media.php

<?php
...
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;
}
...
?>

其他

英文文档:https://developer.wordpress.org/reference/functions/update_gallery_tab/