Skip to content

Commit

Permalink
Started work on saving datetimes as meta; fixed bug that called datet…
Browse files Browse the repository at this point in the history
…ime endpoint many times on save rather than just once.
  • Loading branch information
mauteri committed Aug 27, 2024
1 parent 15624da commit 330dc71
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 7 deletions.
2 changes: 1 addition & 1 deletion build/blocks/event-date/index.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('moment', 'react-jsx-runtime', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-date', 'wp-element', 'wp-i18n'), 'version' => '0f22ffb28fbe7d004c9f');
<?php return array('dependencies' => array('moment', 'react-jsx-runtime', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-date', 'wp-element', 'wp-i18n'), 'version' => '00019915fe473a5617eb');
4 changes: 2 additions & 2 deletions build/blocks/event-date/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/panels.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('moment', 'react-jsx-runtime', 'wp-api-fetch', 'wp-components', 'wp-compose', 'wp-data', 'wp-date', 'wp-edit-post', 'wp-element', 'wp-i18n', 'wp-plugins'), 'version' => '052bad33e07326687357');
<?php return array('dependencies' => array('moment', 'react-jsx-runtime', 'wp-api-fetch', 'wp-components', 'wp-compose', 'wp-data', 'wp-date', 'wp-edit-post', 'wp-element', 'wp-i18n', 'wp-plugins'), 'version' => 'fd8759db317610523313');
4 changes: 2 additions & 2 deletions build/panels.js

Large diffs are not rendered by default.

45 changes: 45 additions & 0 deletions includes/core/classes/class-event-setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,51 @@ public function register_post_type(): void {
*/
public function register_post_meta(): void {
$post_meta = array(
'gatherpress_datetime_start' => array(
'auth_callback' => function () {
return current_user_can( 'edit_posts' );
},
'sanitize_callback' => 'sanitize_text_field',
'show_in_rest' => true,
'single' => true,
'type' => 'string',
),
'gatherpress_datetime_start_gmt' => array(
'auth_callback' => function () {
return current_user_can( 'edit_posts' );
},
'sanitize_callback' => 'sanitize_text_field',
'show_in_rest' => true,
'single' => true,
'type' => 'string',
),
'gatherpress_datetime_end' => array(
'auth_callback' => function () {
return current_user_can( 'edit_posts' );
},
'sanitize_callback' => 'sanitize_text_field',
'show_in_rest' => true,
'single' => true,
'type' => 'string',
),
'gatherpress_datetime_end_gmt' => array(
'auth_callback' => function () {
return current_user_can( 'edit_posts' );
},
'sanitize_callback' => 'sanitize_text_field',
'show_in_rest' => true,
'single' => true,
'type' => 'string',
),
'gatherpress_timezone' => array(
'auth_callback' => function () {
return current_user_can( 'edit_posts' );
},
'sanitize_callback' => 'sanitize_text_field',
'show_in_rest' => true,
'single' => true,
'type' => 'string',
),
'gatherpress_max_guest_limit' => array(
'auth_callback' => function () {
return current_user_can( 'edit_posts' );
Expand Down
23 changes: 23 additions & 0 deletions includes/core/classes/class-event.php
Original file line number Diff line number Diff line change
Expand Up @@ -685,11 +685,34 @@ function ( $key ) {
$fields,
array( 'post_id' => $fields['post_id'] )
);

delete_transient( sprintf( self::DATETIME_CACHE_KEY, $fields['post_id'] ) );
} else {
$value = $wpdb->insert( $table, $fields ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
}

foreach ( $fields as $key => $field ) {
if ( 'post_id' === $key ) {
continue;
}

$meta_key = sprintf( 'gatherpress_%s', sanitize_key( $key ) );

if ( ! empty( $exists ) ) {
update_post_meta(
$fields['post_id'],
$meta_key,
sanitize_text_field( $field )
);
} else {
add_post_meta(
$fields['post_id'],
$meta_key,
sanitize_text_field( $field )
);
}
}

return (bool) $value;
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/DateTimeRange.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const DateTimeRange = () => {
const [dateTimeEnd, setDateTimeEnd] = useState();
const [timezone, setTimezone] = useState();

subscribe(saveDateTime);
saveDateTime();

return (
<>
Expand Down

0 comments on commit 330dc71

Please sign in to comment.