Add bulk actions to postpone and cancel events
This commit is contained in:
@@ -45,6 +45,9 @@ class SP_Admin_CPT_Event extends SP_Admin_CPT {
|
|||||||
add_action( 'restrict_manage_posts', array( $this, 'filters' ) );
|
add_action( 'restrict_manage_posts', array( $this, 'filters' ) );
|
||||||
add_filter( 'parse_query', array( $this, 'filters_query' ) );
|
add_filter( 'parse_query', array( $this, 'filters_query' ) );
|
||||||
|
|
||||||
|
// Post states
|
||||||
|
add_filter( 'display_post_states', array( $this, 'post_states' ), 10, 2 );
|
||||||
|
|
||||||
// Call SP_Admin_CPT constructor
|
// Call SP_Admin_CPT constructor
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
@@ -315,6 +318,26 @@ class SP_Admin_CPT_Event extends SP_Admin_CPT {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Replace displayed post state for events
|
||||||
|
*
|
||||||
|
* @param array $post_states
|
||||||
|
* @param object $post
|
||||||
|
*/
|
||||||
|
public function post_states( $post_states, $post ) {
|
||||||
|
$status = get_post_meta( $post->ID, 'sp_status', true );
|
||||||
|
|
||||||
|
if ( 'postponed' == $status ) {
|
||||||
|
$post_states = array( __( 'Postponed', 'sportspress' ) );
|
||||||
|
} elseif ( 'cancelled' == $status ) {
|
||||||
|
$post_states = array( __( 'Canceled', 'sportspress' ) );
|
||||||
|
} elseif ( 'tbd' == $status ) {
|
||||||
|
$post_states = array( __( 'TBD', 'sportspress' ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
return $post_states;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
endif;
|
endif;
|
||||||
|
|||||||
@@ -31,6 +31,12 @@ class SportsPress_Bulk_Actions {
|
|||||||
// Teams
|
// Teams
|
||||||
add_filter( 'bulk_actions-edit-sp_team', array( $this, 'team_actions' ) );
|
add_filter( 'bulk_actions-edit-sp_team', array( $this, 'team_actions' ) );
|
||||||
add_filter( 'handle_bulk_actions-edit-sp_team', array( $this, 'team_actions_handler' ), 10, 3 );
|
add_filter( 'handle_bulk_actions-edit-sp_team', array( $this, 'team_actions_handler' ), 10, 3 );
|
||||||
|
|
||||||
|
// Events
|
||||||
|
add_filter( 'bulk_actions-edit-sp_event', array( $this, 'event_actions' ) );
|
||||||
|
add_filter( 'handle_bulk_actions-edit-sp_event', array( $this, 'event_actions_handler' ), 10, 3 );
|
||||||
|
|
||||||
|
// Notices
|
||||||
add_action( 'admin_notices', array( $this, 'admin_notices' ) );
|
add_action( 'admin_notices', array( $this, 'admin_notices' ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,6 +88,38 @@ class SportsPress_Bulk_Actions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$redirect_to = add_query_arg( 'sp_bulk_generated_calendars', count( $post_ids ), $redirect_to );
|
$redirect_to = add_query_arg( 'sp_bulk_generated_calendars', count( $post_ids ), $redirect_to );
|
||||||
|
return $redirect_to;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add option to the event bulk actions dropdown.
|
||||||
|
*/
|
||||||
|
public function event_actions( $bulk_actions ) {
|
||||||
|
$bulk_actions['sp_postpone'] = __( 'Postpone events', 'sportspress' );
|
||||||
|
$bulk_actions['sp_cancel'] = __( 'Cancel events', 'sportspress' );
|
||||||
|
return $bulk_actions;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle form submission for event bulk actions.
|
||||||
|
*/
|
||||||
|
public function event_actions_handler( $redirect_to, $doaction, $post_ids ) {
|
||||||
|
if ( ! in_array( $doaction, array( 'sp_postpone', 'sp_cancel' ) ) ) {
|
||||||
|
return $redirect_to;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( 'sp_postpone' == $doaction ) {
|
||||||
|
foreach ( $post_ids as $post_id ) {
|
||||||
|
update_post_meta( $post_id, 'sp_status', 'postponed' );
|
||||||
|
}
|
||||||
|
$redirect_to = add_query_arg( 'sp_bulk_postponed_events', count( $post_ids ), $redirect_to );
|
||||||
|
} elseif ( 'sp_cancel' == $doaction ) {
|
||||||
|
foreach ( $post_ids as $post_id ) {
|
||||||
|
update_post_meta( $post_id, 'sp_status', 'cancelled' );
|
||||||
|
}
|
||||||
|
$redirect_to = add_query_arg( 'sp_bulk_cancelled_events', count( $post_ids ), $redirect_to );
|
||||||
|
}
|
||||||
|
|
||||||
return $redirect_to;
|
return $redirect_to;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,6 +136,24 @@ class SportsPress_Bulk_Actions {
|
|||||||
$count,
|
$count,
|
||||||
'sportspress'
|
'sportspress'
|
||||||
) . ' <a href="' . admin_url('edit.php?post_type=sp_calendar') . '">' . __( 'View', 'sportspress' ) . '</a></p><button type="button" class="notice-dismiss"><span class="screen-reader-text">Dismiss this notice.</span></button></div>', $count );
|
) . ' <a href="' . admin_url('edit.php?post_type=sp_calendar') . '">' . __( 'View', 'sportspress' ) . '</a></p><button type="button" class="notice-dismiss"><span class="screen-reader-text">Dismiss this notice.</span></button></div>', $count );
|
||||||
|
} elseif ( ! empty( $_REQUEST['sp_bulk_postponed_events'] ) ) {
|
||||||
|
$count = intval( $_REQUEST['sp_bulk_postponed_events'] );
|
||||||
|
|
||||||
|
printf( '<div id="message" class="updated notice notice-success is-dismissible"><p>' .
|
||||||
|
_n( 'Postponed %s event.',
|
||||||
|
'Postponed %s events.',
|
||||||
|
$count,
|
||||||
|
'sportspress'
|
||||||
|
) . '</p><button type="button" class="notice-dismiss"><span class="screen-reader-text">Dismiss this notice.</span></button></div>', $count );
|
||||||
|
} elseif ( ! empty( $_REQUEST['sp_bulk_cancelled_events'] ) ) {
|
||||||
|
$count = intval( $_REQUEST['sp_bulk_cancelled_events'] );
|
||||||
|
|
||||||
|
printf( '<div id="message" class="updated notice notice-success is-dismissible"><p>' .
|
||||||
|
_n( 'Canceled %s event.',
|
||||||
|
'Canceled %s events.',
|
||||||
|
$count,
|
||||||
|
'sportspress'
|
||||||
|
) . '</p><button type="button" class="notice-dismiss"><span class="screen-reader-text">Dismiss this notice.</span></button></div>', $count );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user