__( 'Display recent album releases.', 'wp-fedistream' ), 'classname' => 'fedistream-widget fedistream-widget--recent-releases', ) ); } /** * Front-end display. * * @param array $args Widget arguments. * @param array $instance Saved values from database. * @return void */ public function widget( $args, $instance ): void { $title = ! empty( $instance['title'] ) ? $instance['title'] : __( 'Recent Releases', 'wp-fedistream' ); $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); $count = ! empty( $instance['count'] ) ? absint( $instance['count'] ) : 5; $type = ! empty( $instance['type'] ) ? $instance['type'] : ''; $query_args = array( 'post_type' => 'fedistream_album', 'posts_per_page' => $count, 'orderby' => 'meta_value', 'meta_key' => '_fedistream_release_date', 'order' => 'DESC', 'post_status' => 'publish', ); if ( ! empty( $type ) ) { $query_args['meta_query'][] = array( 'key' => '_fedistream_album_type', 'value' => $type, ); } $query = new \WP_Query( $query_args ); $posts = array(); if ( $query->have_posts() ) { while ( $query->have_posts() ) { $query->the_post(); $posts[] = TemplateLoader::get_album_data( get_post() ); } wp_reset_postdata(); } echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped if ( $title ) { echo $args['before_title'] . esc_html( $title ) . $args['after_title']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } try { $plugin = Plugin::get_instance(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped echo $plugin->render( 'widgets/recent-releases', array( 'posts' => $posts, ) ); } catch ( \Exception $e ) { if ( WP_DEBUG ) { echo '

' . esc_html( $e->getMessage() ) . '

'; } } echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } /** * Back-end widget form. * * @param array $instance Previously saved values from database. * @return void */ public function form( $instance ): void { $title = ! empty( $instance['title'] ) ? $instance['title'] : __( 'Recent Releases', 'wp-fedistream' ); $count = ! empty( $instance['count'] ) ? absint( $instance['count'] ) : 5; $type = ! empty( $instance['type'] ) ? $instance['type'] : ''; ?>