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 <noreply@anthropic.com>
This commit is contained in:
@@ -1,10 +1,15 @@
|
|||||||
<?php
|
<?php
|
||||||
/*
|
/**
|
||||||
Plugin Name: SP Event Image Generator
|
* SP Event featured-image generator.
|
||||||
Description: Auto-generates featured images for SP Events by combining team colors and logos.
|
*
|
||||||
Version: 1.0
|
* Auto-generates bisected team-color images for SP Events.
|
||||||
Author: Your Name
|
*
|
||||||
*/
|
* @package Tonys_Sportspress_Enhancements
|
||||||
|
*/
|
||||||
|
|
||||||
|
if ( ! defined( 'ABSPATH' ) ) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
function generate_bisected_image($color1, $color2, $logo1_path, $logo2_path) {
|
function generate_bisected_image($color1, $color2, $logo1_path, $logo2_path) {
|
||||||
$width = 1200;
|
$width = 1200;
|
||||||
|
|||||||
@@ -1,12 +1,17 @@
|
|||||||
<?php
|
<?php
|
||||||
/*
|
/**
|
||||||
Plugin Name: Custom Open Graph Tags with SportsPress Integration
|
* Open Graph tags with SportsPress integration.
|
||||||
Description: Adds custom Open Graph tags to posts based on their type, specifically handling sp_event post types with methods from the SportsPress SP_Event class.
|
*
|
||||||
Version: 1.0
|
* Adds custom Open Graph meta tags to sp_event single pages.
|
||||||
Author: Your Name
|
*
|
||||||
*/
|
* @package Tonys_Sportspress_Enhancements
|
||||||
|
*/
|
||||||
|
|
||||||
add_action('wp_head', 'custom_open_graph_tags_with_sportspress_integration');
|
if ( ! defined( 'ABSPATH' ) ) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
add_action( 'wp_head', 'custom_open_graph_tags_with_sportspress_integration' );
|
||||||
|
|
||||||
function asc_sp_event_matchup_image_url( $post ) {
|
function asc_sp_event_matchup_image_url( $post ) {
|
||||||
if ( is_numeric( $post ) ) {
|
if ( is_numeric( $post ) ) {
|
||||||
|
|||||||
@@ -1,16 +1,19 @@
|
|||||||
<?php
|
<?php
|
||||||
/*
|
/**
|
||||||
Plugin Name: Custom Event Permalinks
|
* Custom permalink structure for sp_event post type.
|
||||||
Description: Adds a custom permalink structure for the sp_event post type.
|
*
|
||||||
Version: 1.0
|
* @package Tonys_Sportspress_Enhancements
|
||||||
Author: Your Name
|
*/
|
||||||
*/
|
|
||||||
|
|
||||||
if ( ! defined( 'ABSPATH' ) ) {
|
if ( ! defined( 'ABSPATH' ) ) {
|
||||||
exit; // Exit if accessed directly
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Register custom rewrite rules
|
/**
|
||||||
|
* Register custom rewrite rules for sp_event.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
function custom_event_rewrite_rules() {
|
function custom_event_rewrite_rules() {
|
||||||
add_rewrite_rule(
|
add_rewrite_rule(
|
||||||
'(?:event|game)/.*?[/]?([0-9]+)[/]?$',
|
'(?:event|game)/.*?[/]?([0-9]+)[/]?$',
|
||||||
@@ -18,64 +21,73 @@ function custom_event_rewrite_rules() {
|
|||||||
'top'
|
'top'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
add_action('init', 'custom_event_rewrite_rules');
|
add_action( 'init', 'custom_event_rewrite_rules' );
|
||||||
|
|
||||||
// Customize the permalink structure
|
/**
|
||||||
function custom_event_permalink($permalink, $post) {
|
* Customize the permalink structure for sp_event posts.
|
||||||
if ($post->post_type !== 'sp_event') {
|
*
|
||||||
|
* @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;
|
return $permalink;
|
||||||
}
|
}
|
||||||
|
|
||||||
$event = new SP_Event($post->ID);
|
$teams = get_post_meta( $post->ID, 'sp_team', false );
|
||||||
$teams = get_post_meta($post->ID,'sp_team', false);
|
$format = get_post_meta( $post->ID, 'sp_format', true );
|
||||||
$format = get_post_meta($post->ID,'sp_format', true);
|
sort( $teams );
|
||||||
sort($teams);
|
$seasons = get_the_terms( $post->ID, 'sp_season', true );
|
||||||
$seasons = get_the_terms($post->ID, 'sp_season', true );
|
|
||||||
if ($seasons) {
|
if ( $seasons ) {
|
||||||
$seasons_slug = implode(
|
$seasons_slug = implode(
|
||||||
"-",
|
'-',
|
||||||
array_map(function($season){return $season->slug;},$seasons),
|
array_map( function( $season ) { return $season->slug; }, $seasons )
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
$seasons_slug = "no-season";
|
$seasons_slug = 'no-season';
|
||||||
};
|
}
|
||||||
|
|
||||||
// Get the teams associated with the event
|
$team_1 = isset( $teams[0] ) ? get_post( $teams[0] ) : null;
|
||||||
$team_1 = get_post($teams[0]);
|
$team_2 = isset( $teams[1] ) ? get_post( $teams[1] ) : null;
|
||||||
$team_2 = get_post($teams[1]);
|
|
||||||
|
|
||||||
switch ($format) {
|
switch ( $format ) {
|
||||||
case 'league':
|
case 'league':
|
||||||
$format_string = 'game';
|
|
||||||
break;
|
|
||||||
case 'tournament':
|
case 'tournament':
|
||||||
$format_string = 'game';
|
$format_string = 'game';
|
||||||
break;
|
break;
|
||||||
case 'friendly':
|
|
||||||
$format_string = 'event';
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
$format_string = 'event';
|
$format_string = 'event';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($team_1 && $team_2) {
|
if ( $team_1 && $team_2 ) {
|
||||||
$permalink = home_url($format_string ."/". $seasons_slug . '/' . $team_1->post_name . '-' . $team_2->post_name . '/' . $post->ID);
|
$permalink = home_url( $format_string . '/' . $seasons_slug . '/' . $team_1->post_name . '-' . $team_2->post_name . '/' . $post->ID );
|
||||||
}
|
}
|
||||||
|
|
||||||
return $permalink;
|
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() {
|
function custom_event_rewrite_flush() {
|
||||||
custom_event_rewrite_rules();
|
custom_event_rewrite_rules();
|
||||||
flush_rewrite_rules();
|
flush_rewrite_rules();
|
||||||
}
|
}
|
||||||
register_activation_hook(__FILE__, 'custom_event_rewrite_flush');
|
register_activation_hook( __FILE__, 'custom_event_rewrite_flush' );
|
||||||
register_deactivation_hook(__FILE__, 'flush_rewrite_rules');
|
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 ) {
|
function custom_event_parse_request( $query ) {
|
||||||
if ( ! $query instanceof WP_Query ) {
|
if ( ! $query instanceof WP_Query ) {
|
||||||
return;
|
return;
|
||||||
@@ -98,4 +110,4 @@ function custom_event_parse_request( $query ) {
|
|||||||
$query->set( 'p', $post_id );
|
$query->set( 'p', $post_id );
|
||||||
$query->set( 'post_status', array( 'publish', 'future' ) );
|
$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' );
|
||||||
|
|||||||
Reference in New Issue
Block a user