public function widget( $args, $instance ) { global $wp_query; // Merge with defaults. $instance = wp_parse_args( (array) $instance, $this->defaults ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped echo $args['before_widget']; // Set up the author bio. if ( ! empty( $instance['title'] ) ) { // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ) . $args['after_title']; } $wp_query = new WP_Query( // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited -- Reset later. [ 'page_id' => $instance['page_id'], ] ); if ( have_posts() ) { while ( have_posts() ) { the_post(); genesis_markup( [ 'open' => '<article %s>', 'context' => 'entry', 'params' => [ 'is_widget' => true, ], ] ); $image = genesis_get_image( [ 'format' => 'html', 'size' => $instance['image_size'], 'context' => 'featured-page-widget', 'attr' => genesis_parse_attr( 'entry-image-widget', [] ), ] ); if ( $image && $instance['show_image'] ) { $role = empty( $instance['show_title'] ) ? '' : ' aria-hidden="true" tabindex="-1"'; printf( '<a href="%s" class="%s"%s>%s</a>', esc_url( get_permalink() ), esc_attr( $instance['image_alignment'] ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Escaping breaks output here $role, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Escaping breaks output here $image ); } if ( ! empty( $instance['show_title'] ) ) { $title = get_the_title() ?: __( '(no title)', 'genesis' ); /** * Filter the featured page widget title. * * @since 2.2.0 * * @param string $title Featured page title. * @param array $instance { * Widget settings for this instance. * * @type string $title Widget title. * @type int $page_id ID of the featured page. * @type bool $show_image True if featured image should be shown, false * otherwise. * @type string $image_alignment Image alignment: `alignnone`, `alignleft`, * `aligncenter` or `alignright`. * @type string $image_size Name of the image size. * @type bool $show_title True if featured page title should be shown, * false otherwise. * @type bool $show_content True if featured page content should be shown, * false otherwise. * @type int $content_limit Amount of content to show, in characters. * @type int $more_text Text to use for More link. * } * @param array $args { * Widget display arguments. * * @type string $before_widget Markup or content to display before the widget. * @type string $before_title Markup or content to display before the widget title. * @type string $after_title Markup or content to display after the widget title. * @type string $after_widget Markup or content to display after the widget. * } */ $title = apply_filters( 'genesis_featured_page_title', $title, $instance, $args ); $heading = genesis_a11y( 'headings' ) ? 'h4' : 'h2'; $entry_title = genesis_markup( [ 'open' => "<{$heading} %s>", 'close' => "</{$heading}>", 'context' => 'entry-title', 'content' => sprintf( '<a href="%s">%s</a>', get_permalink(), $title ), 'params' => [ 'is_widget' => true, 'wrap' => $heading, ], 'echo' => false, ] ); genesis_markup( [ 'open' => '<header %s>', 'close' => '</header>', 'context' => 'entry-header', 'content' => $entry_title, 'params' => [ 'is_widget' => true, ], ] ); } if ( ! empty( $instance['show_content'] ) ) { genesis_markup( [ 'open' => '<div %s>', 'context' => 'entry-content', 'params' => [ 'is_widget' => true, ], ] ); if ( empty( $instance['content_limit'] ) ) { global $more; $orig_more = $more; $more = 0; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited -- Temporary change. the_content( genesis_a11y_more_link( $instance['more_text'] ) ); $more = $orig_more; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited -- Global is being restored. } else { the_content_limit( (int) $instance['content_limit'], genesis_a11y_more_link( esc_html( $instance['more_text'] ) ) ); } genesis_markup( [ 'close' => '</div>', 'context' => 'entry-content', 'params' => [ 'is_widget' => true, ], ] ); } genesis_markup( [ 'close' => '</article>', 'context' => 'entry', 'params' => [ 'is_widget' => true, ], ] ); } } // Restore original query. wp_reset_query(); // phpcs:ignore WordPress.WP.DiscouragedFunctions.wp_reset_query_wp_reset_query -- Making sure the query is really reset. // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped echo $args['after_widget']; }