Skip to content

Commit

Permalink
Add settings and labeling for cancelled events
Browse files Browse the repository at this point in the history
See #544
  • Loading branch information
joedolson committed Feb 19, 2025
1 parent fbc730d commit 1dd4e3e
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 4 deletions.
29 changes: 27 additions & 2 deletions src/includes/event-utilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,15 @@ function mc_event_states() {
),
'1' => array(
'type' => 'public',
'label' => __( 'Publish', 'my-calendar' ),
'label' => __( 'Published', 'my-calendar' ),
),
'2' => array(
'type' => 'hidden',
'label' => __( 'Trash', 'my-calendar' ),
),
'3' => array(
'type' => 'public',
'label' => __( 'Cancel', 'my-calendar' ),
'label' => __( 'Cancelled', 'my-calendar' ),
),
'4' => array(
'type' => 'private',
Expand Down Expand Up @@ -213,3 +213,28 @@ function mc_event_states_type( $state ) {
*/
return apply_filters( 'mc_event_states_type', $return, $states );
}


/**
* Get the label for an event state.
*
* @param int $state An integer state value.
*
* @return string Label for this state.
*/
function mc_event_states_label( $state ) {
$states = mc_event_states();
$return = $states[ $state ]['label'];

/**
* Filter the label for an event state.
*
* @hook mc_event_states_label
*
* @param {string} $return Type for the current status.
* @param {int} $states An integer representation of a status.
*
* @return {string}
*/
return apply_filters( 'mc_event_states_label', $return, $states );
}
2 changes: 2 additions & 0 deletions src/my-calendar-install.php
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ function mc_default_options() {
'ajax_javascript' => '0',
'show_js' => '',
'notime_text' => '',
'cancel_text' => '',
'hide_icons' => 'true',
'event_link_expires' => 'false',
'apply_color' => 'background',
Expand Down Expand Up @@ -407,6 +408,7 @@ function mc_default_options() {
'event_title_template' => '',
'heading_text' => '',
'notime_text' => '',
'cancel_text' => '',
'hosted_by' => '',
'posted_by' => '',
'buy_tickets' => '',
Expand Down
14 changes: 14 additions & 0 deletions src/my-calendar-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ function mc_update_text_settings( $post ) {
}
$options['heading_text'] = isset( $_POST['mc_heading_text'] ) ? wp_kses_post( wp_unslash( $_POST['mc_heading_text'] ) ) : $post['mc_heading_text'];
$options['notime_text'] = $post['mc_notime_text'];
$options['cancel_text'] = $post['mc_cancel_text'];
$options['hosted_by'] = $post['mc_hosted_by'];
$options['posted_by'] = $post['mc_posted_by'];
$options['buy_tickets'] = $post['mc_buy_tickets'];
Expand Down Expand Up @@ -1099,6 +1100,19 @@ function mc_remote_db() {
</li>
<li>
<?php
mc_settings_field(
array(
'name' => 'mc_cancel_text',
'label' => __( 'Cancelled events label', 'my-calendar' ),
'atts' => array(
'placeholder' => __( 'Cancelled:', 'my-calendar' ),
),
)
);
?>
</li>
<li>
<?php
mc_settings_field(
array(
'name' => 'mc_hosted_by',
Expand Down
5 changes: 3 additions & 2 deletions src/my-calendar-templates.php
Original file line number Diff line number Diff line change
Expand Up @@ -646,11 +646,12 @@ function mc_create_tags( $event, $context = 'filters' ) {

// Special.
$e['skip_holiday'] = ( 0 === (int) $event->event_holiday ) ? 'false' : 'true';
$e['event_status'] = ( 1 === (int) $event->event_approved ) ? __( 'Published', 'my-calendar' ) : __( 'Draft', 'my-calendar' );
$e['event_status'] = mc_event_states_label( $event->event_approved );
$cancelled = ( 3 === (int) $event->event_approved ) ? '<span class="mc-event-cancelled">' . trim( mc_get_option( 'cancel_text', mc_event_states_label( 3 ) . ':' ) ) . ' ' . '</span>' : '';

// General text fields.
$title = mc_search_highlight( $event->event_title );
$e['title'] = stripslashes( $title );
$e['title'] = $cancelled . stripslashes( $title );
$e['description'] = wpautop( stripslashes( $event->event_desc ) );
$e['description_raw'] = stripslashes( $event->event_desc );
$e['description_stripped'] = wp_strip_all_tags( stripslashes( $event->event_desc ) );
Expand Down

0 comments on commit 1dd4e3e

Please sign in to comment.