Skip to content

Commit

Permalink
Merge pull request #554 from GatherPress/correct-meta-keys
Browse files Browse the repository at this point in the history
Remove _ from event and venue meta keys.
  • Loading branch information
mauteri authored Feb 18, 2024
2 parents 42c0c27 + b93bb61 commit 3dcb9c5
Show file tree
Hide file tree
Showing 28 changed files with 51 additions and 51 deletions.
2 changes: 1 addition & 1 deletion build/blocks/events-list/events-list.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('react', 'react-dom', 'wp-api-fetch', 'wp-components', 'wp-data', 'wp-dom-ready', 'wp-element', 'wp-i18n'), 'version' => '544880ff338d8ccff8ca');
<?php return array('dependencies' => array('react', 'react-dom', 'wp-api-fetch', 'wp-components', 'wp-data', 'wp-dom-ready', 'wp-element', 'wp-i18n'), 'version' => '380b1cff8defae071d12');
6 changes: 3 additions & 3 deletions build/blocks/events-list/events-list.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/blocks/events-list/index.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('lodash', 'react', 'react-dom', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-core-data', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => '4abed82a496f41f1331c');
<?php return array('dependencies' => array('lodash', 'react', 'react-dom', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-core-data', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => '0a3fc55d2d1001698116');
6 changes: 3 additions & 3 deletions build/blocks/events-list/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/blocks/online-event/index.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('react', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => '9a2c88cc2643e563f963');
<?php return array('dependencies' => array('react', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => '3d490eba28b954298b23');
2 changes: 1 addition & 1 deletion build/blocks/online-event/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/blocks/online-event/online-event.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('react', 'wp-components', 'wp-data', 'wp-dom-ready', 'wp-element', 'wp-i18n'), 'version' => 'fc0087c5b56d9367eea5');
<?php return array('dependencies' => array('react', 'wp-components', 'wp-data', 'wp-dom-ready', 'wp-element', 'wp-i18n'), 'version' => '2885c7db3505b947ee06');
2 changes: 1 addition & 1 deletion build/blocks/online-event/online-event.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/blocks/rsvp/index.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('react', 'react-dom', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => '5f0770103fe9bfa2b0a6');
<?php return array('dependencies' => array('react', 'react-dom', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => '77bb891a5092540a12c2');
6 changes: 3 additions & 3 deletions build/blocks/rsvp/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/blocks/rsvp/rsvp.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('react', 'react-dom', 'wp-api-fetch', 'wp-components', 'wp-data', 'wp-dom-ready', 'wp-element', 'wp-i18n'), 'version' => '5cbd53eb1c07d034b630');
<?php return array('dependencies' => array('react', 'react-dom', 'wp-api-fetch', 'wp-components', 'wp-data', 'wp-dom-ready', 'wp-element', 'wp-i18n'), 'version' => 'd7cc3da7e1f48eaab21c');
6 changes: 3 additions & 3 deletions build/blocks/rsvp/rsvp.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/blocks/venue/index.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('moment', 'react', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => 'c518a05eb64374adcd69');
<?php return array('dependencies' => array('moment', 'react', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => 'bae7a7b1ab0d4fa8d028');
2 changes: 1 addition & 1 deletion build/blocks/venue/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/blocks/venue/venue.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('react', 'wp-components', 'wp-data', 'wp-dom-ready', 'wp-element', 'wp-i18n'), 'version' => '45799fe7d3784f3e347e');
<?php return array('dependencies' => array('react', 'wp-components', 'wp-data', 'wp-dom-ready', 'wp-element', 'wp-i18n'), 'version' => 'cb3a95a3f635bb108e85');
2 changes: 1 addition & 1 deletion build/blocks/venue/venue.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', 'wp-api-fetch', 'wp-components', 'wp-data', 'wp-date', 'wp-edit-post', 'wp-element', 'wp-i18n', 'wp-plugins'), 'version' => '5cbe33b7e8ac982931fd');
<?php return array('dependencies' => array('moment', 'react', 'wp-api-fetch', 'wp-components', 'wp-data', 'wp-date', 'wp-edit-post', 'wp-element', 'wp-i18n', 'wp-plugins'), 'version' => '6d392ba00e9ef6095b1e');
2 changes: 1 addition & 1 deletion build/panels.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions includes/core/classes/class-event.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public static function get_post_type_registration_args(): array {
*/
public static function get_post_meta_registration_args(): array {
return array(
'_online_event_link' => array(
'online_event_link' => array(
'auth_callback' => function () {
return current_user_can( 'edit_posts' );
},
Expand Down Expand Up @@ -640,7 +640,7 @@ public function get_venue_information(): array {
}

if ( is_a( $venue, 'WP_Post' ) ) {
$venue_meta = json_decode( get_post_meta( $venue->ID, '_venue_information', true ) );
$venue_meta = json_decode( get_post_meta( $venue->ID, 'venue_information', true ) );
$venue_information['full_address'] = $venue_meta->fullAddress ?? ''; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
$venue_information['phone_number'] = $venue_meta->phoneNumber ?? ''; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
$venue_information['website'] = $venue_meta->website ?? '';
Expand Down Expand Up @@ -932,7 +932,7 @@ function ( $key ) {
* @return string The online event link if all conditions are met; otherwise, an empty string.
*/
public function maybe_get_online_event_link(): string {
$event_link = (string) get_post_meta( $this->event->ID, '_online_event_link', true );
$event_link = (string) get_post_meta( $this->event->ID, 'online_event_link', true );

/**
* Filters whether to force the display of the online event link.
Expand Down
2 changes: 1 addition & 1 deletion includes/core/classes/class-rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ public function prepare_event_data( WP_REST_Response $response ): WP_REST_Respon
// - The user is attending the event.
// - The event is in the future.
// - The code is not in an admin context.
$response->data['meta']['_online_event_link'] = $event->maybe_get_online_event_link();
$response->data['meta']['online_event_link'] = $event->maybe_get_online_event_link();

return $response;
}
Expand Down
4 changes: 2 additions & 2 deletions includes/core/classes/class-venue.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public static function get_post_type_registration_args(): array {
*/
public static function get_post_meta_registration_args(): array {
return array(
'_venue_information' => array(
'venue_information' => array(
'auth_callback' => static function () {
return current_user_can( 'edit_posts' );
},
Expand Down Expand Up @@ -388,7 +388,7 @@ public function get_venue_meta( int $post_id, string $post_type ): array {
$venue_meta['name'] = get_the_title( $venue_post );
$venue_meta = array_merge(
$venue_meta,
(array) json_decode( get_post_meta( $venue_post->ID, '_venue_information', true ) )
(array) json_decode( get_post_meta( $venue_post->ID, 'venue_information', true ) )
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/blocks/online-event/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const Edit = ({ isSelected }) => {
const onlineEventLink = useSelect(
(select) =>
select('core/editor')?.getEditedPostAttribute('meta')
?._online_event_link
?.online_event_link
);

return (
Expand Down
4 changes: 2 additions & 2 deletions src/blocks/venue/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ const Edit = ({ attributes, setAttributes, isSelected }) => {
const onlineEventLink = useSelect(
(select) =>
select('core/editor')?.getEditedPostAttribute('meta')
?._online_event_link
?.online_event_link
);

let { mapShow } = attributes;

let venueInformationMetaData = useSelect(
(select) =>
select('core/editor')?.getEditedPostAttribute('meta')
?._venue_information
?.venue_information
);

if (venueInformationMetaData) {
Expand Down
4 changes: 2 additions & 2 deletions src/components/OnlineEventLink.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ const OnlineEventLink = () => {
const onlineEventLinkMetaData = useSelect(
(select) =>
select('core/editor').getEditedPostAttribute('meta')
._online_event_link
.online_event_link
);
const [onlineEventLink, setOnlineEventLink] = useState(
onlineEventLinkMetaData
);
const updateEventLink = (value) => {
const meta = { _online_event_link: value };
const meta = { online_event_link: value };

editPost({ meta });
setOnlineEventLink(value);
Expand Down
4 changes: 2 additions & 2 deletions src/components/VenueInformation.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ const VenueInformation = () => {
...venueInformationMetaData,
[key]: value,
});
const meta = { _venue_information: payload };
const meta = { venue_information: payload };

editPost({ meta });
};

let venueInformationMetaData = useSelect(
(select) =>
select('core/editor').getEditedPostAttribute('meta')
._venue_information
.venue_information
);

if (venueInformationMetaData) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/VenueSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const VenueSelector = () => {
let venueInformation = {};

if (venueSlug && Array.isArray(venuePost)) {
const jsonString = venuePost[0]?.meta?._venue_information ?? '{}';
const jsonString = venuePost[0]?.meta?.venue_information ?? '{}';

if (jsonString) {
venueInformation = JSON.parse(jsonString);
Expand Down
16 changes: 8 additions & 8 deletions test/unit/php/includes/core/classes/class-test-event.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,17 @@ public function test_get_post_meta_registration_args(): void {
$args = Event::get_post_meta_registration_args();

$this->assertIsArray(
$args['_online_event_link'],
'Failed to assert that _online_event_link is an array.'
$args['online_event_link'],
'Failed to assert that online_event_link is an array.'
);
$this->assertIsArray(
$args['enable_anonymous_rsvp'],
'Failed to assert that _online_event_link is an array.'
'Failed to assert that online_event_link is an array.'
);

$this->mock->user( 'subscriber' );
$this->assertFalse(
$args['_online_event_link']['auth_callback'](),
$args['online_event_link']['auth_callback'](),
'Failed to assert that user cannot edit posts.'
);
$this->assertFalse(
Expand All @@ -92,7 +92,7 @@ public function test_get_post_meta_registration_args(): void {

$this->mock->user( 'admin' );
$this->assertTrue(
$args['_online_event_link']['auth_callback'](),
$args['online_event_link']['auth_callback'](),
'Failed to assert that user can edit posts.'
);
$this->assertTrue(
Expand Down Expand Up @@ -448,7 +448,7 @@ public function test_get_venue_information(): void {
$event = new Event( $event_id );
$venue_info = '{"fullAddress":"123 Main Street, Montclair, NJ 07042","phoneNumber":"(123) 123-1234","website":"https://gatherpress.org/"}';

update_post_meta( $venue->ID, '_venue_information', $venue_info );
update_post_meta( $venue->ID, 'venue_information', $venue_info );
wp_set_post_terms( $event_id, '_unit-test-venue', Venue::TAXONOMY );

$response = $event->get_venue_information();
Expand Down Expand Up @@ -549,7 +549,7 @@ public function test_get_calendar_links(): void {
'datetime_end' => '2020-05-11 17:00:00',
);

update_post_meta( $venue->ID, '_venue_information', $venue_info );
update_post_meta( $venue->ID, 'venue_information', $venue_info );
wp_set_post_terms( $post->ID, '_unit-test-venue', Venue::TAXONOMY );

$event->save_datetimes( $params );
Expand Down Expand Up @@ -827,7 +827,7 @@ public function test_maybe_get_online_event_link(): void {

$event->save_datetimes( $params );

update_post_meta( $event_id, '_online_event_link', $link );
update_post_meta( $event_id, 'online_event_link', $link );

$this->assertEmpty(
$event->maybe_get_online_event_link(),
Expand Down
6 changes: 3 additions & 3 deletions test/unit/php/includes/core/classes/class-test-venue.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,19 @@ public function test_get_post_type_registration_args(): void {
public function test_get_post_meta_registration_args(): void {
$args = Venue::get_post_meta_registration_args();

$this->assertIsArray( $args['_venue_information'], 'Failed to assert that _online_event_link is an array.' );
$this->assertIsArray( $args['venue_information'], 'Failed to assert that _online_event_link is an array.' );

$this->mock->user( 'subscriber' );

$this->assertFalse(
$args['_venue_information']['auth_callback'](),
$args['venue_information']['auth_callback'](),
'Failed to assert false on auth_callback for subscriber'
);

$this->mock->user( 'admin' );

$this->assertTrue(
$args['_venue_information']['auth_callback'](),
$args['venue_information']['auth_callback'](),
'Failed to assert true on auth_callback for admin'
);
}
Expand Down

0 comments on commit 3dcb9c5

Please sign in to comment.