7 Commits

Author SHA1 Message Date
b4b31f8123 add custom event parse request
For some reason it doesn't run through sportspress' query parser. i can't figure out why, but this is a way around it.
2024-05-20 16:40:08 -05:00
3ecb7ea937 Merge branch 'permalink'
# Conflicts:
#	tonys-sportspress-enhancements.php
2024-05-17 10:28:27 -05:00
78bf5207ab Merge branch 'open-graph-tags' 2024-05-17 10:27:17 -05:00
47433a939c first init 2024-05-17 10:26:42 -05:00
6a373208dd remove spaces from score 2024-05-17 07:19:09 -05:00
a9a6ab3207 remove hook for update post
this was leftover from when i was updating the featured image
2024-05-17 11:14:39 +00:00
8c0b1e3c19 check for image_path exists and set http status header 2024-05-16 16:07:20 -05:00
4 changed files with 103 additions and 3 deletions

View File

@@ -6,8 +6,6 @@ Version: 1.0
Author: Your Name
*/
add_action('save_post_sp_event', 'generate_event_featured_image', 10, 3);
function generate_bisected_image($color1, $color2, $logo1_path, $logo2_path) {
$width = 1200;
$height = 628;
@@ -184,6 +182,17 @@ add_action('template_redirect', 'handle_image_request');
function serve_image($image_path) {
header('Content-Type: image/png');
if (file_exists($image_path)) {
status_header( 200 );
} else {
status_header( 404 );
die("Image not found.");
}
// Clear all output buffering to prevent any extra output
while (ob_get_level()) {
ob_end_clean();
}
readfile($image_path);
}

View File

@@ -91,6 +91,7 @@ function custom_open_graph_tags_with_sportspress_integration() {
);
$i++;
endforeach;
$publish_date = get_the_date('F j, Y', $post);
$title = "{$teams_result_array[0]['team_name']} {$teams_result_array[0]['result']['r']}-{$teams_result_array[1]['result']['r']} {$teams_result_array[1]['team_name']} ({$publish_date})";
$description .= " " . "{$teams_result_array[0]['team_name']} ({$teams_result_array[0]['outcome']}), {$teams_result_array[1]['team_name']} ({$teams_result_array[1]['outcome']}).";;
}

View File

@@ -0,0 +1,89 @@
<?php
/*
Plugin Name: Custom Event Permalinks
Description: Adds a custom permalink structure for the sp_event post type.
Version: 1.0
Author: Your Name
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
// Register custom rewrite rules
function custom_event_rewrite_rules() {
add_rewrite_rule(
'(?:event|game)/.*?[/]?([0-9]+)[/]?$',
'index.php?post_type=sp_event&p=$matches[1]',
'top'
);
}
add_action('init', 'custom_event_rewrite_rules');
// Customize the permalink structure
function custom_event_permalink($permalink, $post) {
if ($post->post_type !== 'sp_event') {
return $permalink;
}
$event = new SP_Event($post->ID);
$teams = get_post_meta($post->ID,'sp_team', false);
$format = get_post_meta($post->ID,'sp_format', true);
sort($teams);
$seasons = get_the_terms($post->ID, 'sp_season', true );
if ($seasons) {
$seasons_slug = implode(
"-",
array_map(function($season){return $season->slug;},$seasons),
);
} else {
$seasons_slug = "no-season";
};
// Get the teams associated with the event
$team_1 = get_post($teams[0]);
$team_2 = get_post($teams[1]);
switch ($format) {
case 'league':
$format_string = 'game';
break;
case 'tournament':
$format_string = 'game';
break;
case 'friendly':
$format_string = 'event';
break;
default:
$format_string = 'event';
break;
}
if ($team_1 && $team_2) {
$permalink = home_url($format_string ."/". $seasons_slug . '/' . $team_1->post_name . '-' . $team_2->post_name . '/' . $post->ID);
}
return $permalink;
}
add_filter('post_type_link', 'custom_event_permalink', 10, 2);
// Flush rewrite rules on activation and deactivation
function custom_event_rewrite_flush() {
custom_event_rewrite_rules();
flush_rewrite_rules();
}
register_activation_hook(__FILE__, 'custom_event_rewrite_flush');
register_deactivation_hook(__FILE__, 'flush_rewrite_rules');
// Modify the query to handle custom permalinks and include future posts
function custom_event_parse_request($query) {
$post_type = sp_array_value( $query->query, 'post_type', null );
if (isset($query->query_vars['post_type']) && $query->query_vars['post_type'] === 'sp_event') {
if (isset($query->query_vars['p'])) {
$query->set('post_type', 'sp_event');
$query->set('p', $query->query_vars['p']);
$query->set('post_status', array('publish', 'future'));
}
}
}
add_action('pre_get_posts', 'custom_event_parse_request');

View File

@@ -16,3 +16,4 @@
// Include other files here
require_once plugin_dir_path(__FILE__) . 'includes/open-graph-tags.php';
require_once plugin_dir_path(__FILE__) . 'includes/featured-image-generator.php';
require_once plugin_dir_path(__FILE__) . 'includes/sp-event-permalink.php';