Skip to content

Commit befeef0

Browse files
committed
#746 Adding columns to CPTs to help manage the posts at a glance
Signed-off-by: James Hunt <[email protected]>
1 parent 321bc03 commit befeef0

File tree

2 files changed

+95
-1
lines changed

2 files changed

+95
-1
lines changed

web/wp-content/mu-plugins/custom/lfevents/admin/class-lfevents-admin.php

+90
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,96 @@ public function staff_custom_column( $columns ) {
370370
return $columns;
371371
}
372372

373+
/**
374+
* Add custom column data to lfe_speaker admin display.
375+
*
376+
* @param string $column The column.
377+
* @param int $post_id The post.
378+
* @return void
379+
*/
380+
public function speaker_custom_column_data( $column, $post_id ) {
381+
switch ( $column ) {
382+
case 'title_company':
383+
echo get_post_meta( $post_id, 'lfes_speaker_title', true ) ? get_post_meta( $post_id, 'lfes_speaker_title', true ) : "-";
384+
break;
385+
case 'linkedin_url':
386+
echo get_post_meta( $post_id, 'lfes_speaker_linkedin', true ) ? '<span class="dashicons dashicons-yes-alt" style="color:green"></span>' : '<span class="dashicons dashicons-no-alt" style="color:red"></span>';
387+
break;
388+
case 'twitter_url':
389+
echo get_post_meta( $post_id, 'lfes_speaker_twitter', true ) ? '<span class="dashicons dashicons-yes-alt" style="color:green"></span>' : '<span class="dashicons dashicons-no-alt" style="color:red"></span>';
390+
break;
391+
case 'website_url':
392+
echo get_post_meta( $post_id, 'lfes_speaker_website', true ) ? '<span class="dashicons dashicons-yes-alt" style="color:green"></span>' : '<span class="dashicons dashicons-no-alt" style="color:red"></span>';
393+
break;
394+
}
395+
}
396+
397+
/**
398+
* Add custom column header to lfe_speaker admin display.
399+
*
400+
* @param array $columns Column headers.
401+
*/
402+
public function speaker_custom_column( $columns ) {
403+
// take default columns.
404+
$date = $columns['date'];
405+
$author = $columns['author'];
406+
// unset so we can move it.
407+
unset( $columns['date'] );
408+
unset( $columns['author'] );
409+
// add new columns.
410+
$columns['title_company'] = 'Title, Company';
411+
$columns['linkedin_url'] = 'Linkedin URL';
412+
$columns['twitter_url'] = 'Twitter URL';
413+
$columns['website_url'] = 'Websiter URL';
414+
// add back in old columns.
415+
$columns['author'] = $author;
416+
$columns['date'] = $date;
417+
return $columns;
418+
}
419+
420+
/**
421+
* Add custom column data to lfe_sponsor admin display.
422+
*
423+
* @param string $column The column.
424+
* @param int $post_id The post.
425+
* @return void
426+
*/
427+
public function sponsor_custom_column_data( $column, $post_id ) {
428+
switch ( $column ) {
429+
case 'sponsor_logo':
430+
echo has_post_thumbnail($post_id) ? '<span class="dashicons dashicons-yes-alt" style="color:green"></span>' : '<span class="dashicons dashicons-no-alt" style="color:red"></span>';
431+
break;
432+
case 'forwarding_url':
433+
echo get_post_meta( $post_id, 'lfe_sponsor_url', true ) ? get_post_meta( $post_id, 'lfe_sponsor_url', true ) : "-";
434+
break;
435+
case 'alt_text':
436+
echo get_post_meta( $post_id, 'lfe_sponsor_alt_text', true ) ? get_post_meta( $post_id, 'lfe_sponsor_alt_text', true ) : "-";
437+
break;
438+
}
439+
}
440+
441+
/**
442+
* Add custom column header to lfe_sponsor admin display.
443+
*
444+
* @param array $columns Column headers.
445+
*/
446+
public function sponsor_custom_column( $columns ) {
447+
// take default columns.
448+
$date = $columns['date'];
449+
$author = $columns['author'];
450+
// unset so we can move it.
451+
unset( $columns['date'] );
452+
unset( $columns['author'] );
453+
// add new columns.
454+
$columns['sponsor_logo'] = 'Sponsor Logo';
455+
$columns['forwarding_url'] = 'Forwarding URL';
456+
$columns['alt_text'] = 'Alt text';
457+
// add back in old columns.
458+
$columns['author'] = $author;
459+
$columns['date'] = $date;
460+
return $columns;
461+
}
462+
373463
/**
374464
* Remove tags support from posts
375465
*/

web/wp-content/mu-plugins/custom/lfevents/includes/class-lfevents.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ private function define_admin_hooks() {
160160
$this->loader->add_action( 'enqueue_block_editor_assets', $plugin_admin, 'enqueue_editor_scripts' );
161161
$this->loader->add_action( 'init', $plugin_admin, 'new_cpts' );
162162
$this->loader->add_action( 'init', $plugin_admin, 'register_event_categories' );
163-
$this->loader->add_filter( 'pmc_create_sidebar', $plugin_admin, 'create_sidebar' );
164163
$this->loader->add_action( 'init', $plugin_admin, 'change_page_label' );
164+
$this->loader->add_filter( 'pmc_create_sidebar', $plugin_admin, 'create_sidebar' );
165165
$this->loader->add_action( 'restrict_manage_posts', $plugin_admin, 'event_filters' );
166166
$this->loader->add_action( 'pre_get_posts', $plugin_admin, 'event_list_filter' );
167167
$this->loader->add_action( 'save_post', $plugin_admin, 'synchronize_noindex_meta' );
@@ -171,6 +171,10 @@ private function define_admin_hooks() {
171171
$this->loader->add_action( 'init', $plugin_admin, 'theme_unregister_tags' );
172172
$this->loader->add_filter( 'manage_lfe_staff_posts_columns', $plugin_admin, 'staff_custom_column' );
173173
$this->loader->add_action( 'manage_lfe_staff_posts_custom_column', $plugin_admin, 'staff_custom_column_data', 10, 2 );
174+
$this->loader->add_filter( 'manage_lfe_speaker_posts_columns', $plugin_admin, 'speaker_custom_column' );
175+
$this->loader->add_action( 'manage_lfe_speaker_posts_custom_column', $plugin_admin, 'speaker_custom_column_data', 10, 2 );
176+
$this->loader->add_filter( 'manage_lfe_sponsor_posts_columns', $plugin_admin, 'sponsor_custom_column' );
177+
$this->loader->add_action( 'manage_lfe_sponsor_posts_custom_column', $plugin_admin, 'sponsor_custom_column_data', 10, 2 );
174178

175179
// Hook to save year in a meta field for events.
176180
$this->loader->add_action( 'save_post', $plugin_admin, 'set_event_year', 10, 3 );

0 commit comments

Comments
 (0)