From d16b32f3cff69bd092291a597eed968528b6d8fd Mon Sep 17 00:00:00 2001 From: LisaCee Date: Mon, 15 Nov 2021 12:22:08 -0800 Subject: [PATCH] code challenge render_cb fix two undefined index variables corrected linting errors escape all content for security excaping for contatenated mixed content --- php/Block.php | 94 ++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 78 insertions(+), 16 deletions(-) diff --git a/php/Block.php b/php/Block.php index b5aab89..10b3071 100644 --- a/php/Block.php +++ b/php/Block.php @@ -8,6 +8,7 @@ namespace XWP\SiteCounts; use WP_Block; +use WP_Query; /** * The Site Counts dynamic block. @@ -63,28 +64,89 @@ public function register_block() { */ public function render_callback( $attributes, $content, $block ) { $post_types = get_post_types( [ 'public' => true ] ); - $class_name = $attributes['className']; + $class_name = $block->block_type->attributes['className']; ob_start(); ?> -
-

Post Counts

+
+

+ +

+
    + $post_type_slug, + 'posts_per_page' => -1, + ] + ) + ); + + ?> +
  • + labels->name ) . esc_html( '.', 'site-counts' ); + ?> +
  • + +
+

+ +

+ $post_type_slug, - 'posts_per_page' => -1, - ] - ) - ); + $query = new WP_Query( + ( [ + 'post_type' => [ 'post', 'page' ], + 'post_status' => 'any', + 'date_query' => ( [ + ( [ + 'hour' => 9, + 'compare' => '>=', + ] ), + ( [ + 'hour' => 17, + 'compare' => '<=', + ] ), + ] ), + 'tag' => 'foo', + 'category_name' => 'baz', + 'post__not_in' => [ get_the_ID() ], + ] ) + ); + if ( $query->found_posts ) : ?> -

labels->name . '.'; ?>

- -

+

+ +

+
    + posts, 0, 5 ) as $post ) : + ?> +
  • + post_title ); + ?> +
  • + +