Skip to content

Commit

Permalink
Core meta values should update whether set or not.
Browse files Browse the repository at this point in the history
Unchecked checkboxes *are* unset, so only updating them when checked is a problem.
  • Loading branch information
joedolson committed Sep 25, 2024
1 parent 6b310d1 commit 21bc1c1
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions src/my-calendar-event-editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ function mc_event_post( $action, $data, $event_id, $result = false ) {
* Add post meta data to an event post.
*
* @param int $post_id Post ID.
* @param array $post Post object.
* @param array $post POST data.
* @param array $data Event POST data or event data.
* @param int $event_id Event ID.
*/
Expand All @@ -174,33 +174,29 @@ function mc_add_post_meta_data( $post_id, $post, $data, $event_id ) {
}
}
$time_label = '';
if ( isset( $_POST['event_time_label'] ) ) {
$time_label = sanitize_text_field( $_POST['event_time_label'] );
if ( isset( $post['event_time_label'] ) ) {
$time_label = sanitize_text_field( $post['event_time_label'] );
} else {
// If this is not set, don't change it.
$time_label = get_post_meta( $post_id, '_event_time_label', true );
// My Calendar Rest API.
if ( isset( $post['data'] ) && isset( $post['data']['event_time_label'] ) ) {
$time_label = $post['data']['event_time_label'];
}
}
$same_day = '';
if ( isset( $_POST['event_same_day'] ) ) {
$same_day = sanitize_text_field( $_POST['event_same_day'] );
$same_day = 'false';
if ( isset( $post['event_same_day'] ) ) {
$same_day = 'true';
} else {
// My Calendar Rest API.
if ( isset( $post['data'] ) && isset( $post['data']['event_same_day'] ) ) {
$same_day = $post['data']['event_same_day'];
$same_day = 'true';
}
}
if ( $events_access ) {
// Event access characteristics.
update_post_meta( $post_id, '_mc_event_access', $events_access );
}
if ( $time_label ) {
update_post_meta( $post_id, '_event_time_label', $time_label );
}
if ( $same_day ) {
update_post_meta( $post_id, '_event_same_day', 'true' );
}
// Event access characteristics.
update_post_meta( $post_id, '_mc_event_access', $events_access );
update_post_meta( $post_id, '_event_time_label', $time_label );
update_post_meta( $post_id, '_event_same_day', $same_day );

$mc_event_id = get_post_meta( $post_id, '_mc_event_id', true );
if ( ! $mc_event_id ) {
Expand Down

0 comments on commit 21bc1c1

Please sign in to comment.