Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Event date block and functionality refactor #820

Merged
merged 18 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 )
);
}
mauteri marked this conversation as resolved.
Show resolved Hide resolved
}

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
@@ -1,7 +1,7 @@
/**
* WordPress dependencies.
*/
import { subscribe } from '@wordpress/data';

Check failure on line 4 in src/components/DateTimeRange.js

View workflow job for this annotation

GitHub Actions / JavaScript Coding Standards

'subscribe' is defined but never used
import { useState } from '@wordpress/element';
import { __ } from '@wordpress/i18n';

Expand Down Expand Up @@ -31,7 +31,7 @@
const [dateTimeEnd, setDateTimeEnd] = useState();
const [timezone, setTimezone] = useState();

subscribe(saveDateTime);
saveDateTime();
mauteri marked this conversation as resolved.
Show resolved Hide resolved

return (
<>
Expand Down
Loading