Skip to content

Commit 2eff9ad

Browse files
committed
gpeb-show-entry-count.php: Added snippet to show entry count above/below the Entries Table block.
1 parent 8410abe commit 2eff9ad

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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

Comments
 (0)