|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Gravity Perks // Entry Blocks // Entries Table Block: Show Entry Count |
| 4 | + * https://gravitywiz.com/documentation/gravity-forms-entry-blocks/ |
| 5 | + * |
| 6 | + * Add a count of entries before and after the table. |
| 7 | + */ |
| 8 | + |
| 9 | +/** |
| 10 | + * @param string $block_content The block content. |
| 11 | + * @param array $block The full block, including name and attributes. |
| 12 | + * @param WP_Block $instance The block instance. |
| 13 | + * |
| 14 | + * @return string |
| 15 | + */ |
| 16 | +function gpeb_show_entry_count( $block_content, $block, $instance ) { |
| 17 | + // Only show if the block name is "gp-entry-blocks/entries-table" |
| 18 | + if ( $instance->name !== 'gp-entry-blocks/entries-table' ) { |
| 19 | + return $block_content; |
| 20 | + } |
| 21 | + |
| 22 | + // Ensure that GF_Queryer exists. |
| 23 | + if ( ! class_exists( 'GP_Entry_Blocks\GF_Queryer' ) ) { |
| 24 | + return $block_content; |
| 25 | + } |
| 26 | + |
| 27 | + $queryer = GP_Entry_Blocks\GF_Queryer::attach( $instance->context ); |
| 28 | + |
| 29 | + // Display the count before and after the table. |
| 30 | + $entry_label = _n( 'entry', 'entries', $queryer->total_count, 'gp-entry-blocks' ); |
| 31 | + $count = '<div class="gpeb-entry-count"><span>' . $queryer->total_count . '</span> ' . $entry_label . ' found.</div>'; |
| 32 | + |
| 33 | + // If you want it to show before the table |
| 34 | + // return $count . $block_content; |
| 35 | + |
| 36 | + // If you want it to show after the table |
| 37 | + // return $block_content . $count; |
| 38 | + |
| 39 | + // Show before and after the table |
| 40 | + return $count . $block_content . $count; |
| 41 | +} |
| 42 | + |
| 43 | +add_filter( 'render_block', 'gpeb_show_entry_count', 10, 3 ); |
0 commit comments