From af73b62f54a36e7022f45a8d43f2b64e9977444c Mon Sep 17 00:00:00 2001 From: Brian Miyaji Date: Thu, 26 Jun 2014 23:49:12 +1000 Subject: [PATCH] Add content position hooks --- includes/class-sp-template-loader.php | 49 ++++++++++++++++++++------- includes/sp-template-hooks.php | 22 +++++------- templates/content-single-calendar.php | 27 --------------- templates/content-single-event.php | 27 --------------- templates/content-single-list.php | 27 --------------- templates/content-single-player.php | 27 --------------- templates/content-single-staff.php | 27 --------------- templates/content-single-table.php | 27 --------------- templates/content-single-team.php | 27 --------------- 9 files changed, 44 insertions(+), 216 deletions(-) delete mode 100644 templates/content-single-calendar.php delete mode 100644 templates/content-single-event.php delete mode 100644 templates/content-single-list.php delete mode 100644 templates/content-single-player.php delete mode 100644 templates/content-single-staff.php delete mode 100644 templates/content-single-table.php delete mode 100644 templates/content-single-team.php diff --git a/includes/class-sp-template-loader.php b/includes/class-sp-template-loader.php index c7b36e08..b94de438 100644 --- a/includes/class-sp-template-loader.php +++ b/includes/class-sp-template-loader.php @@ -24,54 +24,77 @@ class SP_Template_Loader { add_filter( 'the_content', array( $this, 'staff_content' ) ); } - public function add_content( $content, $template, $append = false ) { + public function add_content( $content, $template, $position = 10 ) { + if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly + if ( ! in_the_loop() ) return; // Return if not in main loop + ob_start(); - call_user_func( 'sp_get_template_part', 'content', 'single-' . $template ); - if ( $append ) - return $content . ob_get_clean(); - else - return ob_get_clean() . $content; + + if ( $position <= 0 ) + echo $content; + + do_action( 'sportspress_before_single_' . $template ); + + if ( post_password_required() ) { + echo get_the_password_form(); + return; + } + + if ( $position > 0 && $position <= 5 ) + echo $content; + + do_action( 'sportspress_single_' . $template . '_content' ); + + if ( $position > 5 && $position <= 10 ) + echo $content; + + do_action( 'sportspress_after_single_' . $template ); + + if ( $position > 10 ) + echo $content; + + return ob_get_clean(); } public function event_content( $content ) { if ( is_singular( 'sp_event' ) ) - $content = self::add_content( $content, 'event' ); + $content = self::add_content( $content, 'event', apply_filters( 'sportspress_event_content_priority', 10 ) ); return $content; } public function calendar_content( $content ) { if ( is_singular( 'sp_calendar' ) ) - $content = self::add_content( $content, 'calendar' ); + $content = self::add_content( $content, 'calendar', apply_filters( 'sportspress_calendar_content_priority', 10 ) ); return $content; } public function team_content( $content ) { if ( is_singular( 'sp_team' ) ) - $content = self::add_content( $content, 'team' ); + $content = self::add_content( $content, 'team', apply_filters( 'sportspress_team_content_priority', 10 ) ); return $content; } public function table_content( $content ) { if ( is_singular( 'sp_table' ) ) - $content = self::add_content( $content, 'table' ); + $content = self::add_content( $content, 'table', apply_filters( 'sportspress_table_content_priority', 10 ) ); return $content; } public function player_content( $content ) { if ( is_singular( 'sp_player' ) ) - $content = self::add_content( $content, 'player' ); + $content = self::add_content( $content, 'player', apply_filters( 'sportspress_player_content_priority', 10 ) ); return $content; } public function list_content( $content ) { if ( is_singular( 'sp_list' ) ) - $content = self::add_content( $content, 'list' ); + $content = self::add_content( $content, 'list', apply_filters( 'sportspress_list_content_priority', 10 ) ); return $content; } public function staff_content( $content ) { if ( is_singular( 'sp_staff' ) ) - $content = self::add_content( $content, 'staff' ); + $content = self::add_content( $content, 'staff', apply_filters( 'sportspress_staff_content_priority', 10 ) ); return $content; } diff --git a/includes/sp-template-hooks.php b/includes/sp-template-hooks.php index 64650a64..adb48cd0 100644 --- a/includes/sp-template-hooks.php +++ b/includes/sp-template-hooks.php @@ -36,8 +36,7 @@ add_action( 'sportspress_single_event_content', 'sportspress_output_event_result add_action( 'sportspress_single_event_content', 'sportspress_output_event_details', 30 ); add_action( 'sportspress_single_event_content', 'sportspress_output_event_venue', 40 ); add_action( 'sportspress_single_event_content', 'sportspress_output_event_performance', 50 ); - -add_action( 'sportspress_after_single_event', 'sportspress_output_br_tag', 100 ); +add_action( 'sportspress_single_event_content', 'sportspress_output_br_tag', 100 ); /** * Single Calendar Content @@ -45,8 +44,7 @@ add_action( 'sportspress_after_single_event', 'sportspress_output_br_tag', 100 ) * @see sportspress_output_calendar() */ add_action( 'sportspress_single_calendar_content', 'sportspress_output_calendar', 10 ); - -add_action( 'sportspress_after_single_calendar', 'sportspress_output_br_tag', 100 ); +add_action( 'sportspress_single_calendar_content', 'sportspress_output_br_tag', 100 ); /** * Single Team Content @@ -55,11 +53,11 @@ add_action( 'sportspress_after_single_calendar', 'sportspress_output_br_tag', 10 * @see sportspress_output_team_columns() * @see sportspress_output_team_lists() */ -add_action( 'sportspress_single_team_content', 'sportspress_output_team_link', 10 ); add_action( 'sportspress_single_team_content', 'sportspress_output_team_columns', 20 ); add_action( 'sportspress_single_team_content', 'sportspress_output_team_lists', 30 ); +add_action( 'sportspress_single_team_content', 'sportspress_output_br_tag', 100 ); -add_action( 'sportspress_after_single_team', 'sportspress_output_br_tag', 100 ); +add_action( 'sportspress_after_single_team', 'sportspress_output_team_link', 10 ); /** * Single Table Content @@ -67,8 +65,7 @@ add_action( 'sportspress_after_single_team', 'sportspress_output_br_tag', 100 ); * @see sportspress_output_league_table() */ add_action( 'sportspress_single_table_content', 'sportspress_output_league_table', 10 ); - -add_action( 'sportspress_after_single_table', 'sportspress_output_br_tag', 100 ); +add_action( 'sportspress_single_table_content', 'sportspress_output_br_tag', 100 ); /** * Single Player Content @@ -78,8 +75,7 @@ add_action( 'sportspress_after_single_table', 'sportspress_output_br_tag', 100 ) */ add_action( 'sportspress_single_player_content', 'sportspress_output_player_details', 10 ); add_action( 'sportspress_single_player_content', 'sportspress_output_player_statistics', 20 ); - -add_action( 'sportspress_after_single_player', 'sportspress_output_br_tag', 100 ); +add_action( 'sportspress_single_player_content', 'sportspress_output_br_tag', 100 ); /** * Single List Content @@ -87,8 +83,7 @@ add_action( 'sportspress_after_single_player', 'sportspress_output_br_tag', 100 * @see sportspress_output_player_list() */ add_action( 'sportspress_single_list_content', 'sportspress_output_player_list', 10 ); - -add_action( 'sportspress_after_single_list', 'sportspress_output_br_tag', 100 ); +add_action( 'sportspress_single_list_content', 'sportspress_output_br_tag', 100 ); /** * Single Staff Content @@ -96,8 +91,7 @@ add_action( 'sportspress_after_single_list', 'sportspress_output_br_tag', 100 ); * @see sportspress_output_staff_details() */ add_action( 'sportspress_single_staff_content', 'sportspress_output_staff_details', 10 ); - -add_action( 'sportspress_after_single_staff', 'sportspress_output_br_tag', 100 ); +add_action( 'sportspress_single_staff_content', 'sportspress_output_br_tag', 100 ); /** * Venue Archive Content diff --git a/templates/content-single-calendar.php b/templates/content-single-calendar.php deleted file mode 100644 index 7c970c8c..00000000 --- a/templates/content-single-calendar.php +++ /dev/null @@ -1,27 +0,0 @@ -