From 88aa74f65a1071bd6567dbea76881c435cade8a0 Mon Sep 17 00:00:00 2001 From: Takumi Date: Fri, 26 Jul 2013 04:15:20 +1000 Subject: [PATCH] Consolidate custom post type management actions --- actions.php | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++ calendar.php | 24 ------------- event.php | 33 ------------------ helpers.php | 74 +++++++++++++++++++--------------------- player.php | 96 +++------------------------------------------------- staff.php | 32 +----------------- table.php | 24 ------------- team.php | 30 ---------------- venue.php | 18 ---------- 9 files changed, 133 insertions(+), 291 deletions(-) diff --git a/actions.php b/actions.php index b3adfb32..27f05645 100644 --- a/actions.php +++ b/actions.php @@ -10,6 +10,99 @@ function sp_after_theme_setup() { } add_action( 'after_theme_setup', 'sp_after_theme_setup' ); +function sp_manage_posts_custom_column( $column, $post_id ) { + switch ( $column ): + case 'sp_icon': + the_post_thumbnail( 'sp_icon' ); + break; + case 'sp_position': + get_the_terms ( $post_id, 'sp_position' ) ? the_terms( $post_id, 'sp_position' ) : print '—'; + break; + case 'sp_team': + get_post_meta ( $post_id, 'sp_team' ) ? sp_the_posts( $post_id, 'sp_team', '', '
' ) : print '—'; + break; + case 'sp_league': + get_the_terms ( $post_id, 'sp_league' ) ? the_terms( $post_id, 'sp_league' ) : print '—'; + break; + case 'sp_season': + get_the_terms ( $post_id, 'sp_season' ) ? the_terms( $post_id, 'sp_season' ) : print '—'; + break; + case 'sp_sponsor': + get_the_terms ( $post_id, 'sp_sponsor' ) ? the_terms( $post_id, 'sp_sponsor' ) : print '—'; + break; + case 'sp_kickoff': + echo get_the_date ( get_option ( 'date_format' ) ) . '
' . get_the_time ( get_option ( 'time_format' ) ); + break; + case 'sp_address': + echo get_post_meta( $post_id, 'sp_address', true ); + break; + endswitch; +} +add_action( 'manage_posts_custom_column', 'sp_manage_posts_custom_column', 10, 2 ); +add_action( 'manage_pages_custom_column', 'sp_manage_posts_custom_column', 10, 2 ); + +function sp_restrict_manage_posts() { + global $typenow, $wp_query; + switch ( $typenow ): + case 'sp_player': + + // Teams + $selected = isset( $_REQUEST['sp_team'] ) ? $_REQUEST['sp_team'] : null; + $args = array( + 'show_option_none' => sprintf( __( 'All %s', 'sportspress' ), __( 'Teams', 'sportspress' ) ), + 'post_type' => 'sp_team', + 'name' => 'sp_team', + 'selected' => $selected + ); + wp_dropdown_pages( $args ); + + // Positions + $selected = isset( $_REQUEST['sp_position'] ) ? $_REQUEST['sp_position'] : null; + $args = array( + 'show_option_all' => sprintf( __( 'All %s', 'sportspress' ), __( 'Positions', 'sportspress' ) ), + 'taxonomy' => 'sp_position', + 'name' => 'sp_position', + 'selected' => $selected + ); + sp_dropdown_taxonomies( $args ); + echo PHP_EOL; + + // Leagues + $selected = isset( $_REQUEST['sp_league'] ) ? $_REQUEST['sp_league'] : null; + $args = array( + 'show_option_all' => sprintf( __( 'All %s', 'sportspress' ), __( 'Leagues', 'sportspress' ) ), + 'taxonomy' => 'sp_league', + 'name' => 'sp_league', + 'selected' => $selected + ); + sp_dropdown_taxonomies( $args ); + echo PHP_EOL; + + // Seasons + $selected = isset( $_REQUEST['sp_season'] ) ? $_REQUEST['sp_season'] : null; + $args = array( + 'show_option_all' => sprintf( __( 'All %s', 'sportspress' ), __( 'Seasons', 'sportspress' ) ), + 'taxonomy' => 'sp_season', + 'name' => 'sp_season', + 'selected' => $selected + ); + sp_dropdown_taxonomies( $args ); + echo PHP_EOL; + + // Sponsors + $selected = isset( $_REQUEST['sp_sponsor'] ) ? $_REQUEST['sp_sponsor'] : null; + $args = array( + 'show_option_all' => sprintf( __( 'All %s', 'sportspress' ), __( 'Sponsors', 'sportspress' ) ), + 'taxonomy' => 'sp_sponsor', + 'name' => 'sp_sponsor', + 'selected' => $selected + ); + sp_dropdown_taxonomies( $args ); + + endswitch; +} +add_action( 'restrict_manage_posts', 'sp_restrict_manage_posts' ); + function sp_nonce() { echo ''; } diff --git a/calendar.php b/calendar.php index 7c2da112..70c3b1d7 100644 --- a/calendar.php +++ b/calendar.php @@ -27,30 +27,6 @@ function sp_calendar_edit_columns( $columns ) { } add_filter( 'manage_edit-sp_calendar_columns', 'sp_calendar_edit_columns' ); -function sp_calendar_custom_columns( $column ) { - global $post, $post_id, $typenow; - if ( $typenow == 'sp_calendar' ): - switch ($column): - case 'sp_team': - echo 'TEAMS'; - break; - case 'sp_league': - if ( get_the_terms ( $post_id, 'sp_league' ) ) - the_terms( $post_id, 'sp_league' ); - else - echo '—'; - break; - case 'sp_season': - if ( get_the_terms ( $post_id, 'sp_season' ) ) - the_terms( $post_id, 'sp_season' ); - else - echo '—'; - break; - endswitch; - endif; -} -add_action( 'manage_posts_custom_column', 'sp_calendar_custom_columns' ); - function sp_calendar_request_filter_dropdowns() { global $typenow, $wp_query; if ( $typenow == 'sp_calendar' ) { diff --git a/event.php b/event.php index 22e97fae..113f54b9 100644 --- a/event.php +++ b/event.php @@ -182,39 +182,6 @@ function sp_event_edit_columns( $columns ) { } add_filter( 'manage_edit-sp_event_columns', 'sp_event_edit_columns' ); -function sp_event_custom_columns( $column, $post_id ) { - global $typenow; - if ( $typenow == 'sp_event' ): - switch ( $column ): - case 'sp_team': - sp_the_posts( $post_id, 'sp_team', '', '
' ); - break; - case 'sp_league': - if ( get_the_terms ( $post_id, 'sp_league' ) ) - the_terms( $post_id, 'sp_league' ); - else - echo '—'; - break; - case 'sp_season': - if ( get_the_terms ( $post_id, 'sp_season' ) ) - the_terms( $post_id, 'sp_season' ); - else - echo '—'; - break; - case 'sp_sponsor': - if ( get_the_terms ( $post_id, 'sp_sponsor' ) ) - the_terms( $post_id, 'sp_sponsor' ); - else - echo '—'; - break; - case 'sp_kickoff': - echo get_the_date ( get_option ( 'date_format' ) ) . '
' . get_the_time ( get_option ( 'time_format' ) ); - break; - endswitch; - endif; -} -add_action( 'manage_posts_custom_column', 'sp_event_custom_columns', 10, 2 ); - function sp_event_edit_sortable_columns( $columns ) { $columns['sp_kickoff'] = 'sp_kickoff'; return $columns; diff --git a/helpers.php b/helpers.php index 1adf7ea8..eb8fe18f 100644 --- a/helpers.php +++ b/helpers.php @@ -65,13 +65,14 @@ if ( ! function_exists( 'sp_dropdown_taxonomies' ) ) { } } } + if ( ! function_exists( 'sp_the_posts' ) ) { - function sp_the_posts( $post_id = null, $meta = 'post', $before = '', $sep = ',', $after = '' ) { + function sp_the_posts( $post_id = null, $meta = 'post', $before = '', $sep = ', ', $after = '' ) { echo $before; if ( ! isset( $post_id ) ) global $post_id; $posts = get_post_meta( $post_id, $meta, false ); - if ( isset( $posts ) && $posts ): + if ( isset( $posts ) && $posts && is_array( $posts ) ): foreach ( $posts as $post ): $parents = get_post_ancestors( $post ); $parents = array_combine( array_keys( $parents ), array_reverse( array_values( $parents ) ) ); @@ -84,8 +85,6 @@ if ( ! function_exists( 'sp_the_posts' ) ) { if ( $post != end( $posts ) ) echo $sep; endforeach; - else: - echo '—'; endif; echo $after; } @@ -109,47 +108,44 @@ if ( ! function_exists( 'sp_team_logo' ) ) { } } -if ( ! function_exists( 'sp_team_checklist' ) ) { - function sp_team_checklist( $post_id = null ) { - if ( ! isset( $post_id ) ) - global $post_id; - $selected = (array)get_post_meta( $post_id, 'sp_team', false ); - $teams = get_pages( array( 'post_type' => 'sp_team') ); - foreach ( $teams as $team ): - $parents = get_post_ancestors( $team ); - ?> -
  • -
  • ', sizeof( $parents ) ); ?> - - ', sizeof( $parents ) ); ?> -
  • - -
    -
    - +
    +
    +
      - + $meta) ); + foreach ( $teams as $team ): + $parents = get_post_ancestors( $team ); + ?> +
    • +
    • ', sizeof( $parents ) ); ?> + +
    ', sizeof( $parents ) ); ?> + +
    -
    -

    - - + - -

    -
    + + +
    ID, 'sp_team', true ); sp_nonce(); } -function sp_player_profile_meta( $post, $metabox ) { +function sp_player_profile_meta( $post ) { wp_editor( $post->post_content, 'content' ); } -function sp_player_edit_columns( $columns ) { +function sp_player_edit_columns() { $columns = array( 'cb' => '', 'title' => __( 'Name', 'sportspress' ), @@ -47,91 +46,4 @@ function sp_player_edit_columns( $columns ) { return $columns; } add_filter( 'manage_edit-sp_player_columns', 'sp_player_edit_columns' ); - -function sp_player_custom_columns( $column, $post_id ) { - global $post, $typenow; - if ( $typenow == 'sp_player' ): - switch ($column): - case 'sp_position': - if ( get_the_terms ( $post_id, 'sp_position' ) ) - the_terms( $post_id, 'sp_position' ); - else - echo '—'; - break; - case 'sp_team': - sp_the_posts( $post_id, 'sp_team', '', '
    ' ); - break; - case 'sp_league': - if ( get_the_terms ( $post_id, 'sp_league' ) ) - the_terms( $post_id, 'sp_league' ); - else - echo '—'; - break; - case 'sp_season': - if ( get_the_terms ( $post_id, 'sp_season' ) ) - the_terms( $post_id, 'sp_season' ); - else - echo '—'; - break; - case 'sp_sponsor': - if ( get_the_terms ( $post_id, 'sp_sponsor' ) ) - the_terms( $post_id, 'sp_sponsor' ); - else - echo '—'; - break; - endswitch; - endif; -} -add_action( 'manage_posts_custom_column', 'sp_player_custom_columns', 10, 2 ); - -function sp_player_request_filter_dropdowns() { - global $typenow, $wp_query; - if ( $typenow == 'sp_player' ) { - - // Positions - $selected = isset( $_REQUEST['sp_position'] ) ? $_REQUEST['sp_position'] : null; - $args = array( - 'show_option_all' => sprintf( __( 'All %s', 'sportspress' ), __( 'Positions', 'sportspress' ) ), - 'taxonomy' => 'sp_position', - 'name' => 'sp_position', - 'selected' => $selected - ); - sp_dropdown_taxonomies( $args ); - echo PHP_EOL; - - // Leagues - $selected = isset( $_REQUEST['sp_league'] ) ? $_REQUEST['sp_league'] : null; - $args = array( - 'show_option_all' => sprintf( __( 'All %s', 'sportspress' ), __( 'Leagues', 'sportspress' ) ), - 'taxonomy' => 'sp_league', - 'name' => 'sp_league', - 'selected' => $selected - ); - sp_dropdown_taxonomies( $args ); - echo PHP_EOL; - - // Seasons - $selected = isset( $_REQUEST['sp_season'] ) ? $_REQUEST['sp_season'] : null; - $args = array( - 'show_option_all' => sprintf( __( 'All %s', 'sportspress' ), __( 'Seasons', 'sportspress' ) ), - 'taxonomy' => 'sp_season', - 'name' => 'sp_season', - 'selected' => $selected - ); - sp_dropdown_taxonomies( $args ); - echo PHP_EOL; - - // Sponsors - $selected = isset( $_REQUEST['sp_sponsor'] ) ? $_REQUEST['sp_sponsor'] : null; - $args = array( - 'show_option_all' => sprintf( __( 'All %s', 'sportspress' ), __( 'Sponsors', 'sportspress' ) ), - 'taxonomy' => 'sp_sponsor', - 'name' => 'sp_sponsor', - 'selected' => $selected - ); - sp_dropdown_taxonomies( $args ); - - } -} -add_action( 'restrict_manage_posts', 'sp_player_request_filter_dropdowns' ); ?> \ No newline at end of file diff --git a/staff.php b/staff.php index 7cb34f65..bdb70f14 100644 --- a/staff.php +++ b/staff.php @@ -26,7 +26,7 @@ function sp_staff_meta_init() { } function sp_staff_team_meta( $post, $metabox ) { global $post_id; - sp_team_select_html( $post_id ); + sp_post_checklist( $post_id, 'sp_team', true ); sp_nonce(); } @@ -47,36 +47,6 @@ function sp_staff_edit_columns( $columns ) { } add_filter( 'manage_edit-sp_staff_columns', 'sp_staff_edit_columns' ); -function sp_staff_custom_columns( $column, $post_id ) { - global $post, $typenow; - if ( $typenow == 'sp_staff' ): - switch ($column): - case 'sp_position': - if ( get_the_terms ( $post_id, 'sp_position' ) ) - the_terms( $post_id, 'sp_position' ); - else - echo '—'; - break; - case 'sp_team': - sp_the_posts( $post_id, 'sp_team', '', '
    ' ); - break; - case 'sp_league': - if ( get_the_terms ( $post_id, 'sp_league' ) ) - the_terms( $post_id, 'sp_league' ); - else - echo '—'; - break; - case 'sp_season': - if ( get_the_terms ( $post_id, 'sp_season' ) ) - the_terms( $post_id, 'sp_season' ); - else - echo '—'; - break; - endswitch; - endif; -} -add_action( 'manage_posts_custom_column', 'sp_staff_custom_columns', 10, 2 ); - function sp_staff_request_filter_dropdowns() { global $typenow, $wp_query; if ( $typenow == 'sp_staff' ) { diff --git a/table.php b/table.php index 2db28541..4c61a36f 100644 --- a/table.php +++ b/table.php @@ -27,30 +27,6 @@ function sp_table_edit_columns( $columns ) { } add_filter( 'manage_edit-sp_table_columns', 'sp_table_edit_columns' ); -function sp_table_custom_columns( $column ) { - global $post, $post_id, $typenow; - if ( $typenow == 'sp_table' ): - switch ($column): - case 'sp_team': - echo 'TEAMS'; - break; - case 'sp_league': - if ( get_the_terms ( $post_id, 'sp_league' ) ) - the_terms( $post_id, 'sp_league' ); - else - echo '—'; - break; - case 'sp_season': - if ( get_the_terms ( $post_id, 'sp_season' ) ) - the_terms( $post_id, 'sp_season' ); - else - echo '—'; - break; - endswitch; - endif; -} -add_action( 'manage_posts_custom_column', 'sp_table_custom_columns' ); - function sp_table_request_filter_dropdowns() { global $typenow, $wp_query; if ( $typenow == 'sp_table' ) { diff --git a/team.php b/team.php index 685e02a9..7c1e34f7 100644 --- a/team.php +++ b/team.php @@ -36,36 +36,6 @@ function sp_team_edit_columns($columns) { } add_filter( 'manage_edit-sp_team_columns', 'sp_team_edit_columns' ); -function sp_team_custom_columns( $column ) { - global $post, $post_id, $typenow; - if ( $typenow == 'sp_team' ): - switch ( $column ): - case 'sp_icon': - the_post_thumbnail( 'sp_icon' ); - break; - case 'sp_league': - if ( get_the_terms ( $post_id, 'sp_league' ) ) - the_terms( $post_id, 'sp_league' ); - else - echo '—'; - break; - case 'sp_season': - if ( get_the_terms ( $post_id, 'sp_season' ) ) - the_terms( $post_id, 'sp_season' ); - else - echo '—'; - break; - case 'sp_sponsor': - if ( get_the_terms ( $post_id, 'sp_sponsor' ) ) - the_terms( $post_id, 'sp_sponsor' ); - else - echo '—'; - break; - endswitch; - endif; -} -add_action( 'manage_pages_custom_column', 'sp_team_custom_columns' ); - function sp_team_request_filter_dropdowns() { global $typenow, $wp_query; if ( $typenow == 'sp_team' ) { diff --git a/venue.php b/venue.php index 1db97d77..48d68686 100644 --- a/venue.php +++ b/venue.php @@ -26,24 +26,6 @@ function sp_venue_edit_columns( $columns ) { } add_filter( 'manage_edit-sp_venue_columns', 'sp_venue_edit_columns' ); -function sp_venue_custom_columns( $column, $post_id ) { - global $typenow; - if ( $typenow == 'sp_venue' ): - switch ( $column ): - case 'sp_sponsor': - if ( get_the_terms ( $post_id, 'sp_sponsor' ) ) - the_terms( $post_id, 'sp_sponsor' ); - else - echo '—'; - break; - case 'sp_address': - echo get_post_meta( $post_id, 'sp_address', true ); - break; - endswitch; - endif; -} -add_action( 'manage_posts_custom_column', 'sp_venue_custom_columns', 10, 2 ); - function sp_venue_request_filter_dropdowns() { global $typenow, $wp_query; if ( $typenow == 'sp_venue' ) {