From 5b48d3782dabbfe4eb4e290f38dfb8a30676e2cf Mon Sep 17 00:00:00 2001 From: Brian Miyaji Date: Wed, 27 Apr 2016 12:27:32 +1000 Subject: [PATCH] Fix auto event title based on teams when empty --- .../post-types/class-sp-admin-cpt-event.php | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/includes/admin/post-types/class-sp-admin-cpt-event.php b/includes/admin/post-types/class-sp-admin-cpt-event.php index b0da4184..cd227bb2 100644 --- a/includes/admin/post-types/class-sp-admin-cpt-event.php +++ b/includes/admin/post-types/class-sp-admin-cpt-event.php @@ -5,7 +5,7 @@ * @author ThemeBoy * @category Admin * @package SportsPress/Admin/Post_Types - * @version 1.8.3 + * @version 2.0.2 */ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly @@ -29,6 +29,9 @@ class SP_Admin_CPT_Event extends SP_Admin_CPT { // Post title fields add_filter( 'enter_title_here', array( $this, 'enter_title_here' ), 1, 2 ); + // Empty data filter + add_filter( 'wp_insert_post_empty_content', array( $this, 'wp_insert_post_empty_content' ), 99, 2 ); + // Before data updates add_filter( 'wp_insert_post_data', array( $this, 'wp_insert_post_data' ), 99, 2 ); @@ -57,10 +60,28 @@ class SP_Admin_CPT_Event extends SP_Admin_CPT { return $text; } + /** + * Mark as not empty when saving event if teams are selected for auto title. + * + * @param array $maybe_empty + * @param array $postarr + * @return bool + */ + public function wp_insert_post_empty_content( $maybe_empty, $postarr ) { + if ( $maybe_empty && 'sp_event' === sp_array_value( $postarr, 'post_type' ) ): + $teams = sp_array_value( $postarr, 'sp_team', array() ); + $teams = array_filter( $teams ); + if ( sizeof( $teams ) ) return false; + endif; + + return $maybe_empty; + } + /** * Auto-generate an event title based on the team playing if left blank. * * @param array $data + * @param array $postarr * @return array */ public function wp_insert_post_data( $data, $postarr ) {