PluginProbe ʕ •ᴥ•ʔ
GenerateBlocks / trunk
GenerateBlocks vtrunk
trunk 1.0 1.0.1 1.0.2 1.1.0 1.1.1 1.1.2 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.7.0 1.7.1 1.7.2 1.7.3 1.8.0 1.8.1 1.8.2 1.8.3 1.9.0 1.9.1 2.0.0 2.0.1 2.0.2 2.1.0 2.1.1 2.1.2 2.2.0 2.2.1 2.3.0
generateblocks / includes / blocks / class-loop-item.php
generateblocks / includes / blocks Last commit date
class-block.php 1 year ago class-button-container.php 2 years ago class-button.php 2 years ago class-container.php 2 years ago class-element.php 1 year ago class-grid.php 2 years ago class-headline.php 2 weeks ago class-image.php 2 years ago class-loop-item.php 1 year ago class-looper.php 1 year ago class-media.php 1 year ago class-query-loop.php 3 years ago class-query-no-results.php 1 year ago class-query-page-numbers.php 1 year ago class-query.php 1 year ago class-shape.php 1 year ago class-text.php 1 year ago
class-loop-item.php
68 lines
1 <?php
2 /**
3 * Handles the Element block.
4 *
5 * @package GenerateBlocks
6 */
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit; // Exit if accessed directly.
10 }
11
12 /**
13 * The Element block.
14 */
15 class GenerateBlocks_Block_Loop_Item extends GenerateBlocks_Block {
16 /**
17 * Keep track of all blocks of this type on the page.
18 *
19 * @var array $block_ids The current block id.
20 */
21 protected static $block_ids = [];
22
23 /**
24 * Store our block name.
25 *
26 * @var string $block_name The block name.
27 */
28 public static $block_name = 'generateblocks/loop-item';
29
30 /**
31 * Render the Element block.
32 *
33 * @param array $attributes The block attributes.
34 * @param string $block_content The block content.
35 * @param object $block The block.
36 */
37 public static function render_block( $attributes, $block_content, $block ) {
38 $query_type = $block->context['generateblocks/queryType'] ?? null;
39
40 if ( GenerateBlocks_Block_Query::TYPE_WP_QUERY === $query_type ) {
41 $post_classes = get_post_class();
42
43 if ( class_exists( 'WP_HTML_Tag_Processor' ) ) {
44 $tags = new WP_HTML_Tag_Processor( $block_content );
45
46 if ( $tags->next_tag( $attributes['tagName'] ) ) {
47 $existing_classes = $tags->get_attribute( 'class' );
48 $new_classes = $existing_classes . ' ' . implode( ' ', $post_classes );
49 $tags->set_attribute( 'class', $new_classes );
50 $block_content = $tags->get_updated_html();
51 }
52 }
53 }
54
55 // Add styles to this block if needed.
56 $block_content = generateblocks_maybe_add_block_css(
57 $block_content,
58 [
59 'class_name' => __CLASS__,
60 'attributes' => $attributes,
61 'block_ids' => self::$block_ids,
62 ]
63 );
64
65 return $block_content;
66 }
67 }
68