$columns['cb'] ?? '',
'sg7g_thumbnail' => __( 'Cover', '7sgaleri' ),
'title' => __( 'Title', '7sgaleri' ),
'sg7g_featured' => __( 'Featured', '7sgaleri' ),
'sg7g_media_type' => __( 'Type', '7sgaleri' ),
'sg7g_source' => __( 'Source', '7sgaleri' ),
'taxonomy-sg7g_category' => __( 'Categories', '7sgaleri' ),
);
}
public static function column_content( string $column, int $post_id ): void {
if ( 'sg7g_thumbnail' === $column ) {
$image = get_the_post_thumbnail( $post_id, array( 96, 54 ), array( 'class' => 'sg7g-admin-cover', 'loading' => 'lazy' ) );
echo $image ? wp_kses_post( $image ) : '';
return;
}
if ( 'sg7g_featured' === $column ) {
echo 1 === (int) get_post_meta( $post_id, '_sg7g_featured', true )
? esc_html__( 'Yes', '7sgaleri' )
: '—';
return;
}
if ( 'sg7g_media_type' === $column ) {
$type = get_post_meta( $post_id, '_sg7g_media_type', true );
echo esc_html( 'audio' === $type ? __( 'Audio', '7sgaleri' ) : __( 'Video', '7sgaleri' ) );
return;
}
if ( 'sg7g_source' === $column ) {
$source = get_post_meta( $post_id, '_sg7g_source', true );
echo esc_html( SG7G_Meta_Boxes::source_label( (string) $source ) );
return;
}
}
public static function filters( string $post_type ): void {
if ( 'sg7g_media' !== $post_type ) {
return;
}
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only list-table filter.
$current_type = isset( $_GET['sg7g_media_type_filter'] ) ? sanitize_key( wp_unslash( $_GET['sg7g_media_type_filter'] ) ) : '';
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only list-table filter.
$current_source = isset( $_GET['sg7g_source_filter'] ) ? sanitize_key( wp_unslash( $_GET['sg7g_source_filter'] ) ) : '';
?>
__( 'All categories', '7sgaleri' ),
'taxonomy' => 'sg7g_category',
'name' => 'sg7g_category',
'orderby' => 'name',
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only list-table filter.
'selected' => isset( $_GET['sg7g_category'] ) ? sanitize_title( wp_unslash( $_GET['sg7g_category'] ) ) : '',
'hierarchical' => true,
'hide_empty' => false,
'value_field' => 'slug',
)
);
}
public static function filter_query( WP_Query $query ): void {
if ( ! is_admin() || ! $query->is_main_query() ) {
return;
}
$post_type = $query->get( 'post_type' );
if ( 'sg7g_media' !== $post_type ) {
return;
}
$meta_query = (array) $query->get( 'meta_query' );
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only list-table filter.
$type = isset( $_GET['sg7g_media_type_filter'] ) ? sanitize_key( wp_unslash( $_GET['sg7g_media_type_filter'] ) ) : '';
if ( in_array( $type, array( 'video', 'audio' ), true ) ) {
$meta_query[] = array(
'key' => '_sg7g_media_type',
'value' => $type,
);
}
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only list-table filter.
$source = isset( $_GET['sg7g_source_filter'] ) ? sanitize_key( wp_unslash( $_GET['sg7g_source_filter'] ) ) : '';
$all_sources = array_merge( array_keys( SG7G_Meta_Boxes::sources()['video'] ), array_keys( SG7G_Meta_Boxes::sources()['audio'] ) );
if ( in_array( $source, $all_sources, true ) ) {
$meta_query[] = array(
'key' => '_sg7g_source',
'value' => $source,
);
}
if ( $meta_query ) {
$query->set( 'meta_query', $meta_query );
}
}
}