From 6eb51a89b2fee674889e9adb41d4eb3d44cd1825 Mon Sep 17 00:00:00 2001 From: Anthony Correa Date: Mon, 6 Apr 2026 08:33:15 -0500 Subject: [PATCH] Replace old plugin headers with proper file docblocks, add ABSPATH guards - open-graph-tags.php: replace Plugin Name header with package docblock - featured-image-generator.php: same cleanup - sp-event-permalink.php: same cleanup, normalize indentation to tabs, collapse redundant switch cases (league/tournament both map to 'game') Co-Authored-By: Claude Sonnet 4.6 --- includes/featured-image-generator.php | 17 ++-- includes/open-graph-tags.php | 19 ++-- includes/sp-event-permalink.php | 134 ++++++++++++++------------ 3 files changed, 96 insertions(+), 74 deletions(-) diff --git a/includes/featured-image-generator.php b/includes/featured-image-generator.php index f756c89..2661ba5 100644 --- a/includes/featured-image-generator.php +++ b/includes/featured-image-generator.php @@ -1,10 +1,15 @@ post_type !== 'sp_event') { - return $permalink; - } +/** + * Customize the permalink structure for sp_event posts. + * + * @param string $permalink Existing permalink. + * @param WP_Post $post Post object. + * @return string + */ +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"; - }; + $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 ); - // Get the teams associated with the event - $team_1 = get_post($teams[0]); - $team_2 = get_post($teams[1]); + if ( $seasons ) { + $seasons_slug = implode( + '-', + array_map( function( $season ) { return $season->slug; }, $seasons ) + ); + } else { + $seasons_slug = 'no-season'; + } - 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; - } + $team_1 = isset( $teams[0] ) ? get_post( $teams[0] ) : null; + $team_2 = isset( $teams[1] ) ? get_post( $teams[1] ) : null; - if ($team_1 && $team_2) { - $permalink = home_url($format_string ."/". $seasons_slug . '/' . $team_1->post_name . '-' . $team_2->post_name . '/' . $post->ID); - } + switch ( $format ) { + case 'league': + case 'tournament': + $format_string = 'game'; + break; + default: + $format_string = 'event'; + break; + } - return $permalink; + 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); +add_filter( 'post_type_link', 'custom_event_permalink', 10, 2 ); -// Flush rewrite rules on activation and deactivation +/** + * Flush rewrite rules on activation. + * + * @return void + */ function custom_event_rewrite_flush() { - custom_event_rewrite_rules(); - flush_rewrite_rules(); + custom_event_rewrite_rules(); + flush_rewrite_rules(); } -register_activation_hook(__FILE__, 'custom_event_rewrite_flush'); -register_deactivation_hook(__FILE__, 'flush_rewrite_rules'); +register_activation_hook( __FILE__, 'custom_event_rewrite_flush' ); +register_deactivation_hook( __FILE__, 'flush_rewrite_rules' ); -// Modify the front-end single event query to allow scheduled events to resolve. +/** + * Allow scheduled events to resolve on the frontend. + * + * @param WP_Query $query Current query. + * @return void + */ function custom_event_parse_request( $query ) { if ( ! $query instanceof WP_Query ) { return; @@ -98,4 +110,4 @@ function custom_event_parse_request( $query ) { $query->set( 'p', $post_id ); $query->set( 'post_status', array( 'publish', 'future' ) ); } -add_action('pre_get_posts', 'custom_event_parse_request'); +add_action( 'pre_get_posts', 'custom_event_parse_request' );