Skip to content
Open
Show file tree
Hide file tree
Changes from 52 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
956ace1
[MOOSE-263]: initial block creation
GeoffDusome Aug 28, 2025
58569a4
[MOOSE-263]: add markup + styling
GeoffDusome Aug 28, 2025
49480e7
[MOOSE-263]: ignore errors for now
GeoffDusome Aug 28, 2025
87f3f8f
[MOOSE-263]: phpcs ignore
GeoffDusome Aug 28, 2025
13d074f
[MOOSE-263]: ignore dist files in phpstan; ignore phpstan errors
GeoffDusome Aug 28, 2025
4b24949
[MOOSE-263]: comments
GeoffDusome Aug 28, 2025
1d57a4c
[MOOSE-263]: handle interaction / visibility
GeoffDusome Aug 28, 2025
9e27bef
[MOOSE-263]: post id as string in esc_attr
GeoffDusome Aug 28, 2025
669f7a2
[MOOSE-263]: editor styling; reset test values to default
GeoffDusome Aug 29, 2025
404a5a3
Merge pull request #243 from moderntribe/task/MOOSE-263/announcements…
GeoffDusome Sep 2, 2025
389de14
Add alert post type
dotjon Sep 16, 2025
13e452d
Correct domain
dotjon Sep 16, 2025
9ce4ac6
Scaffold meta
dotjon Sep 16, 2025
5500728
Format array
dotjon Sep 17, 2025
69569e7
Add alert component
dotjon Sep 17, 2025
deaeda1
Add alert render block
dotjon Sep 17, 2025
26c6480
Add controller and pipline rules
dotjon Sep 18, 2025
2a20913
Tribe Alert Block
dotjon Sep 18, 2025
a40f6dd
Rename to Announcement
dotjon Sep 18, 2025
089923f
Rename to Announcement
dotjon Sep 18, 2025
d5fca42
Rename to Announcement
dotjon Sep 18, 2025
32f16c9
Rename to Announcement
dotjon Sep 18, 2025
ee8f521
Add more rules
dotjon Sep 19, 2025
ec5797c
Add contexts
dotjon Sep 19, 2025
61ab2d5
Display rules
dotjon Oct 9, 2025
0eaf743
Add correct meta for block attributes
dotjon Oct 9, 2025
32030a4
Code fixer
dotjon Oct 9, 2025
d596d92
Update wp-content/themes/core/blocks/tribe/announcement-renderer/bloc…
dotjon Oct 9, 2025
ef17695
Update wp-content/themes/core/blocks/tribe/announcement-renderer/bloc…
dotjon Oct 9, 2025
3c786dc
Update wp-content/themes/core/blocks/tribe/announcement-renderer/edit.js
dotjon Oct 9, 2025
ce7b3a5
Remove tribe alerts
dotjon Oct 9, 2025
1d6455b
CS fixes
dotjon Oct 9, 2025
e4ff77f
Lint
dotjon Oct 9, 2025
6039223
No empty sources
dotjon Oct 9, 2025
a1a6998
Update wp-content/plugins/core/src/Components/Announcements/Rules/Sch…
dotjon Oct 9, 2025
2bc01dd
Alert -> announcement
dotjon Oct 9, 2025
a9fccb5
Merge branch 'feature/announcements-be' of github.com:moderntribe/moo…
dotjon Oct 9, 2025
98d60a0
Merge branch 'main' into feature/announcements
GeoffDusome Oct 9, 2025
0c761f3
clean up styles; prep for button overhaul
GeoffDusome Oct 9, 2025
d8378ca
Merge branch 'feature/announcements' into feature/announcements-be
GeoffDusome Oct 9, 2025
c6ed68a
attach FE; show renderer in editor
GeoffDusome Oct 9, 2025
171e49e
Hook up block attributes
dotjon Oct 14, 2025
c1525a6
Typo in value
dotjon Oct 14, 2025
46f1647
Update wp-content/themes/core/blocks/tribe/announcements/edit.js
dotjon Oct 14, 2025
4aa8035
clean up; animation support
GeoffDusome Oct 14, 2025
6c4c232
Add query limit
dotjon Oct 17, 2025
e1137b2
Merge branch 'feature/announcements-be' of github.com:moderntribe/moo…
dotjon Oct 17, 2025
0385364
Merge pull request #261 from moderntribe/feature/announcements-be
dotjon Oct 17, 2025
f301386
Merge branch 'main' into feature/announcements
GeoffDusome Oct 17, 2025
c6580ff
fix issue with phpstan
GeoffDusome Oct 17, 2025
1ea4809
fix issues with announcement meta
GeoffDusome Oct 17, 2025
1b540d4
reorder admin menu; cursor for dismiss button
GeoffDusome Oct 17, 2025
ec19932
Merge branch 'main' into feature/announcements
GeoffDusome Dec 29, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ parameters:
- wp-content/mu-plugins/
excludePaths:
- vendor
- wp-content/themes/core/dist/ (?)
bootstrapFiles:
- vendor/php-stubs/wordpress-stubs/wordpress-stubs.php
- vendor/php-stubs/acf-pro-stubs/acf-pro-stubs.php
Expand Down
2 changes: 2 additions & 0 deletions wp-content/plugins/core/src/Blocks/Blocks_Definer.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class Blocks_Definer implements Definer_Interface {
public function define(): array {
return [
self::TYPES => DI\add( [
'tribe/announcement-renderer',
'tribe/announcements',
'tribe/carousel',
'tribe/carousel-slide',
'tribe/copyright',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<?php declare(strict_types=1);

namespace Tribe\Plugin\Components\Announcements;

use Tribe\Plugin\Components\Abstract_Controller;
use Tribe\Plugin\Components\Announcements\Rules\Front_Page_Rule;
use Tribe\Plugin\Components\Announcements\Rules\Page_Visibility_Rule;
use Tribe\Plugin\Components\Announcements\Rules\Placement_Rule;
use Tribe\Plugin\Components\Announcements\Rules\Rule_Interface;
use Tribe\Plugin\Components\Announcements\Rules\Scheduling_Rule;
use Tribe\Plugin\Post_Types\Announcement\Announcement;

class Announcement_Controller extends Abstract_Controller {

private const int QUERY_LIMIT = 50;

/**
* @var \Tribe\Plugin\Components\Announcements\Rules\Rule_Interface[]
*/
private array $rules = [];

/**
* @var string[]|int[]|bool[]
*/
private array $context = [];

public function __construct() {
$this->add_rule( new Placement_Rule() );
$this->add_rule( new Front_Page_Rule() );
$this->add_rule( new Page_Visibility_Rule() );
$this->add_rule( new Scheduling_Rule() );
}

/**
* Get announcements for a specific placement
*
* @param string $placement The placement location (above_header|below_header)
* @param array $context Additional context for rule processing
*
* @return \WP_Post[]
*/
public function get_announcement_for_placement( string $placement, array $context = [] ): array {
$this->context = array_merge( $context, [
'placement' => $placement,
'current_post_id' => get_queried_object_id(),
'is_home' => is_home(),
'is_front_page' => is_front_page(),
'is_single' => is_single(),
'is_page' => is_page(),
'is_category' => is_category(),
'is_tag' => is_tag(),
'is_tax' => is_tax(),
'is_archive' => is_archive(),
'current_time' => current_time( 'U' ),
] );

$announcements = $this->get_all_announcements();

return $this->process_pipeline( $announcements );
}

/**
* Add a rule to the processing pipeline
*
* @param \Tribe\Plugin\Components\Announcements\Rules\Rule_Interface $rule
*/
public function add_rule( Rule_Interface $rule ): self {
$this->rules[] = $rule;

return $this;
}

/**
* Process announcements through the rule pipeline
*
* @param \WP_Post[] $announcements
*
* @return \WP_Post[]
*/
private function process_pipeline( array $announcements ): array {
foreach ( $this->rules as $rule ) {
$announcements = array_filter( $announcements, function ( $announcement ) use ( $rule ) {
return $rule->passes( $announcement, $this->context );
} );
}

return $announcements;
}

/**
* Get all published announcements
*
* @return \WP_Post[]
*/
private function get_all_announcements(): array {
$query = new \WP_Query( [
'post_type' => Announcement::NAME,
'post_status' => 'publish',
'posts_per_page' => self::QUERY_LIMIT,
'orderby' => [
'menu_order' => 'ASC',
'date' => 'DESC',
],
] );

return $query->posts;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php declare(strict_types=1);

namespace Tribe\Plugin\Components\Announcements;

use Tribe\Plugin\Object_Meta\Post_Types\Announcement_Meta;

class Announcement_Renderer {

private Announcement_Controller $controller;

public function __construct( Announcement_Controller $controller ) {
$this->controller = $controller;
}

/**
* Render Announcements for a specific placement as block markup
*
* @param string $placement
* @param array $context
*/
public function render_announcements( string $placement, array $context = [] ): string {
$announcements = $this->controller->get_announcement_for_placement( $placement, $context );

if ( empty( $announcements ) ) {
return '';
}

$output = '';

foreach ( $announcements as $announcement ) {
$output .= $this->render_announcement_block( $announcement );
}

return $output;
}

/**
* Render a single announcement as a block with JSON attributes
*
* @param \WP_Post $announcement
*/
public function render_announcement_block( \WP_Post $announcement ): string {
$attributes = $this->get_announcement_attributes( $announcement );
$json_attributes = wp_json_encode( $attributes, JSON_UNESCAPED_SLASHES );

return sprintf( '<!-- wp:tribe/announcements %s /-->', $json_attributes );
}

/**
* Parse and render block markup
*
* @param string $placement
* @param array $context
*
* @return string Rendered HTML
*/
public function parse_and_render( string $placement, array $context = [] ): string {
$block_markup = $this->render_announcements( $placement, $context );

if ( empty( $block_markup ) ) {
return '';
}

// Parse the blocks and render them
$blocks = parse_blocks( $block_markup );
$output = '';

foreach ( $blocks as $block ) {
$output .= render_block( $block );
}

return $output;
}

/**
* Get announcement data as block attributes
*
* @param \WP_Post $announcement
*/
private function get_announcement_attributes( \WP_Post $announcement ): array {
$link = get_field( Announcement_Meta::CTA_LINK, $announcement->ID ) ?? [];

return [
'announcementId' => $announcement->ID,
'heading' => get_field( Announcement_Meta::HEADING, $announcement->ID ) ?? '',
'body' => get_field( Announcement_Meta::BODY, $announcement->ID ) ?? '',
'ctaLabel' => $link['title'] ?? null,
'ctaLink' => $link['url'] ?? null,
'ctaStyle' => get_field( Announcement_Meta::CTA_STYLE, $announcement->ID ) ?? 'outlined',
'align' => get_field( Announcement_Meta::ALIGNMENT, $announcement->ID ) ?? 'center',
'theme' => get_field( Announcement_Meta::COLOR_THEME, $announcement->ID ) ?? 'brand',
'dismissible' => (bool) get_field( Announcement_Meta::DISMISSIBLE, $announcement->ID ),
];
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php declare(strict_types=1);

namespace Tribe\Plugin\Components\Announcements\Rules;

use Tribe\Plugin\Object_Meta\Post_Types\Announcement_Meta;

class Front_Page_Rule implements Rule_Interface {

public function passes( \WP_Post $announcement, array $context ): bool {
$is_front_page = $context['is_front_page'] ?? is_front_page();

if ( ! $is_front_page ) {
return true;
}

$display_type = get_field( Announcement_Meta::FIELD_RULES_DISPLAY_TYPE, $announcement->ID );
$apply_to_front_page = get_field( Announcement_Meta::FIELD_RULES_APPLY_TO_FRONT_PAGE, $announcement->ID );

// If not applying rules to front page, always show.
if ( ! $apply_to_front_page ) {
return true;
}

// If set to show everywhere, always show.
if ( $display_type === Announcement_Meta::OPTION_EVERY_PAGE ) {
return true;
}

// For include rule: show on front page
// For exclude rule: don't show on front page
return $display_type === Announcement_Meta::OPTION_INCLUDE;
}

public function get_name(): string {
return 'front_page';
}

}
Loading
Loading