2 Commits

Author SHA1 Message Date
dbe3048af7 Improve webhook testing and provider UI
Some checks failed
Release Plugin Zip / release (push) Has been cancelled
2026-04-05 14:28:17 -04:00
4ed968a045 Add configurable event webhook notifications 2026-04-05 14:14:12 -04:00
4 changed files with 1814 additions and 1 deletions

View File

@@ -8,6 +8,18 @@ Author: Your Name
add_action('wp_head', 'custom_open_graph_tags_with_sportspress_integration');
function asc_sp_event_matchup_image_url( $post ) {
if ( is_numeric( $post ) ) {
$post = get_post( $post );
}
if ( ! $post || 'sp_event' !== $post->post_type ) {
return '';
}
return get_site_url() . '/head-to-head?post=' . $post->ID;
}
function asc_generate_sp_event_title( $post ) {
// See https://github.com/ThemeBoy/SportsPress/blob/770fa8c6654d7d6648791e877709c2428677635b/includes/admin/post-types/class-sp-admin-cpt-event.php#L99C40-L99C55
if ( is_numeric( $post ) ) {
@@ -175,7 +187,7 @@ function custom_open_graph_tags_with_sportspress_integration() {
$description .= " " . "{$teams_result_array[0]['team_name']} ({$teams_result_array[0]['outcome']}), {$teams_result_array[1]['team_name']} ({$teams_result_array[1]['outcome']})." ;
}
$description .= " " . $post->post_content;
$image = get_site_url() . "/head-to-head?post={$post->ID}";
$image = asc_sp_event_matchup_image_url( $post );
echo '<meta property="og:type" content="article" />' . "\n";
echo '<meta property="og:image" content="'. $image . '" />' . "\n";
echo '<meta property="og:title" content="' . $title . '" />' . "\n";

1717
includes/sp-webhooks.php Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,83 @@
<?php
/**
* Tests for configurable SportsPress webhooks.
*
* @package Tonys_Sportspress_Enhancements
*/
/**
* Webhook feature tests.
*/
class Test_SP_Webhooks extends WP_UnitTestCase {
/**
* Template placeholders should resolve nested values and JSON serialization.
*/
public function test_render_template_supports_dot_paths_and_tojson() {
$webhooks = Tony_Sportspress_Webhooks::instance();
$template = 'Trigger={{ trigger.key }} Team={{ event.teams.0.name }} Image={{ event.image }} Payload={{ event|tojson }}';
$context = array(
'trigger' => array(
'key' => 'event_results_updated',
),
'event' => array(
'id' => 55,
'image' => 'https://example.com/head-to-head?post=55',
'teams' => array(
array(
'name' => 'Blue Team',
),
),
),
);
$rendered = $webhooks->render_template( $template, $context );
$this->assertStringContainsString( 'Trigger=event_results_updated', $rendered );
$this->assertStringContainsString( 'Team=Blue Team', $rendered );
$this->assertStringContainsString( 'Image=https://example.com/head-to-head?post=55', $rendered );
$this->assertStringContainsString( '"id":55', $rendered );
}
/**
* Sanitization should keep only complete provider-specific webhook rows.
*/
public function test_sanitize_settings_keeps_only_valid_webhooks() {
$webhooks = Tony_Sportspress_Webhooks::instance();
$sanitized = $webhooks->sanitize_settings(
array(
'webhooks' => array(
array(
'name' => 'Results',
'enabled' => '1',
'provider' => 'google_chat',
'url' => 'https://chat.googleapis.com/v1/spaces/AAA/messages?key=test&token=test',
'triggers' => array( 'event_results_updated' ),
'template' => '{"summary":"{{ results.summary }}"}',
),
array(
'name' => 'Invalid',
'enabled' => '1',
'provider' => 'groupme_bot',
'url' => 'invalid bot id',
'triggers' => array( 'event_datetime_changed' ),
'template' => 'ignored',
),
array(
'name' => 'Missing trigger',
'enabled' => '1',
'provider' => 'generic_json',
'url' => 'https://example.com/missing-trigger',
'template' => 'ignored',
),
),
)
);
$this->assertCount( 1, $sanitized['webhooks'] );
$this->assertSame( 'Results', $sanitized['webhooks'][0]['name'] );
$this->assertSame( 'google_chat', $sanitized['webhooks'][0]['provider'] );
$this->assertSame( 'https://chat.googleapis.com/v1/spaces/AAA/messages?key=test&token=test', $sanitized['webhooks'][0]['url'] );
$this->assertSame( array( 'event_results_updated' ), $sanitized['webhooks'][0]['triggers'] );
}
}

View File

@@ -46,6 +46,7 @@ require_once plugin_dir_path(__FILE__) . 'includes/sp-event-quick-edit-officials
require_once plugin_dir_path(__FILE__) . 'includes/sp-event-team-ordering.php';
require_once plugin_dir_path(__FILE__) . 'includes/sp-printable-calendars.php';
require_once plugin_dir_path(__FILE__) . 'includes/sp-url-builder.php';
require_once plugin_dir_path(__FILE__) . 'includes/sp-webhooks.php';
require_once plugin_dir_path(__FILE__) . 'includes/sp-schedule-exporter.php';
require_once plugin_dir_path(__FILE__) . 'includes/sp-venue-meta.php';