Skip to content

Instantly share code, notes, and snippets.

@stephenharris
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stephenharris/26d09f5cfe4d0f5651f0 to your computer and use it in GitHub Desktop.
Save stephenharris/26d09f5cfe4d0f5651f0 to your computer and use it in GitHub Desktop.
A snippet which adds a custom column, and removes an existing column from the Events admin table
<?php
/**
* A snippet which adds a custom column, and removes an existing column from the Events admin table
*
* Specifically, this snippet removes the existing 'Reoccurrence' column and replaces it with another column.
* This new column does exactly the same thing, but you can change it's behaviour as desired.
*
* @see http://wp-event-organiser.com/forums/topic/better-reoccurrence-display-in-admin-panel/
*/
/**
* Adds custom columns to Event CPT table
*/
function my_add_event_add_column( $columns ) {
$columns['recurrence_detail'] = __( 'Reoccurrence', 'eventorganiser' );
//Optional, remove default column
unset( $columns['reoccurence'] );
return $columns;
}
add_filter( 'manage_edit-event_columns', 'my_add_event_add_column', 15 );
/**
* What to display in custom columns of Event CPT table
*/
function my_event_fill_columns( $column_name, $id ) {
global $post;
$event_id = ( empty( $post->event_id) ? $id :'' );
if( 'recurrence_detail' != $column_name ){
return false;
}
//Change this as required.
eo_display_reoccurence( $event_id );
}
add_action( 'manage_event_posts_custom_column', 'my_event_fill_columns', 10, 2 );
@Hexodus
Copy link

Hexodus commented Nov 6, 2014

Thank you so much Stephen! This is really a big help. If someone needs the snippet for having the reoccurences listed in my way here we go.
The function first:

/**
 * Custom reoccurence list function
 */
function show_custom_reoccurence( $event_id, $max_display_count = 10, $max_reoccurrence_count = 24 )
{
        $occur_datelist = array();
        $occur_array =  eo_get_the_future_occurrences_of($event_id);

        if($occur_array)
        {
          //lets assume that to big list should be displayed by EO 
          if(count($occur_array) >= $max_reoccurrence_count)
          {
               eo_display_reoccurence( $event_id );
          }
          else //shorter ones will be listed by us 
          {
            foreach ($occur_array as $value) 
            {
                $date = $value["start"];    
                $occur_datelist[] = $date->format('d-m-Y');
            }
            //Shorten the Array when needed
            if(count($occur_datelist) > $max_display_count)
            {
                $list_overhead = count($occur_datelist)-$max_display_count;
                $occur_datelist = array_slice($occur_datelist, 0, $max_display_count);
                echo implode(", ", $occur_datelist )." ... (".$list_overhead."+)";
            }
            else
            {
              echo implode(", ", $occur_datelist );
            }
          }
        }
        else 
            echo "---";
}

Then change the function call in Stephens code from:

eo_display_reoccurence( $event_id );

To:

show_custom_reoccurence( $event_id );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment