
WordPress用户角色和权限的终极指南
update_gallery_tab ( $tabs )
update_gallery_tab: 这个函数更新文章编辑器中的画廊标签设置。它用于添加或删除画廊标签的特定设置。
如果文章有图片附件,将画廊标签重新添加到标签阵列中。
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; }