Skip to content

Commit

Permalink
Show a bubble when the event is in draft status (#80)
Browse files Browse the repository at this point in the history
* Add a filter to generate the event slug if it is stored as draft

* Fixes style

* Remove an unused parameter
  • Loading branch information
amieiro authored Feb 15, 2024
1 parent 66e1094 commit f1c0f7d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
7 changes: 6 additions & 1 deletion templates/event.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@

<div class="event-details-page">
<div class="event-details-head">
<h1><?php echo esc_html( $event_title ); ?></h1>
<h1>
<?php echo esc_html( $event_title ); ?>
<?php if ( 'draft' === $event->post_status ): ?>
<span class="event-label-draft"><?php echo esc_html( $event->post_status ); ?></span>
<?php endif; ?>
</h1>
<p>Host: <a href="<?php echo esc_attr( get_author_posts_url( $event->post_author ) ); ?>"><?php echo esc_html( get_the_author_meta( 'display_name', $event->post_author ) ); ?></a></p>
</div>
<div class="event-details-left">
Expand Down
20 changes: 20 additions & 0 deletions wporg-gp-translation-events.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,26 @@ function gp_event_nav_menu_items( array $items ): array {
// Add the events link to the GlotPress main menu.
add_filter( 'gp_nav_menu_items', 'gp_event_nav_menu_items' );

/**
* Generate a slug for the event post type when we save a draft event.
*
* Generate a slug based on the event title if it's not provided.
*
* @param array $data An array of slashed post data.
* @return array The modified post data.
*/
function generate_event_slug( $data ) {
if ( 'event' === $data['post_type'] && 'draft' === $data['post_status'] ) {
if ( empty( $data['post_name'] ) ) {
$data['post_name'] = sanitize_title( $data['post_title'] );
}
}

return $data;
}

add_filter( 'wp_insert_post_data', 'generate_event_slug', 10, 1 );

add_action(
'gp_init',
function () {
Expand Down

0 comments on commit f1c0f7d

Please sign in to comment.