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

TRACKING-PR: Export & Import, plus block cherries #25

Closed
Closed
Changes from all commits
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', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-date', 'wp-element', 'wp-i18n'), 'version' => '9a693c52f333685e40d8');
<?php return array('dependencies' => array('moment', 'react', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-date', 'wp-element', 'wp-i18n'), 'version' => '7e39cbc446a04833fd2d');
2 changes: 1 addition & 1 deletion build/blocks/event-date/index.js

Large diffs are not rendered by default.

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' => '312b602bf15d128a6649');
<?php return array('dependencies' => array('react', 'react-dom', 'wp-api-fetch', 'wp-components', 'wp-data', 'wp-dom-ready', 'wp-element', 'wp-i18n'), 'version' => '425cbfc777f973f269e8');
10 changes: 5 additions & 5 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' => '4418243136224c349ef8');
<?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' => '52e9a2c60b1e9c4bd949');
10 changes: 5 additions & 5 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' => '22c4d9952ae84d4f8973');
<?php return array('dependencies' => array('react', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => 'ff0e9054014152ff4254');
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' => 'f43e82fe6319c886ac86');
<?php return array('dependencies' => array('react', 'wp-components', 'wp-data', 'wp-dom-ready', 'wp-element', 'wp-i18n'), 'version' => '05f1e5613efaf2de28d8');
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' => '2999d8fa4ee33d0629f3');
<?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' => '66dc6181d71b53497b9b');
10 changes: 5 additions & 5 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' => '9c0620b4f014481d9eb4');
<?php return array('dependencies' => array('react', 'react-dom', 'wp-api-fetch', 'wp-components', 'wp-data', 'wp-dom-ready', 'wp-element', 'wp-i18n'), 'version' => '5ff709f139c55900a4f1');
10 changes: 5 additions & 5 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-date', 'wp-element', 'wp-i18n'), 'version' => 'be4e990d06a384882695');
<?php return array('dependencies' => array('moment', 'react', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-date', 'wp-element', 'wp-i18n'), 'version' => 'ca97c7f43478ea502d02');
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' => '099b5eebfcf36f51f05e');
<?php return array('dependencies' => array('react', 'wp-components', 'wp-data', 'wp-dom-ready', 'wp-element', 'wp-i18n'), 'version' => '9ba1e4313b72a8d0d2e6');
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' => '0e9cff2f47704ffb8596');
<?php return array('dependencies' => array('moment', 'react', 'wp-api-fetch', 'wp-components', 'wp-core-data', 'wp-data', 'wp-date', 'wp-edit-post', 'wp-element', 'wp-i18n', 'wp-plugins'), 'version' => '35cd67adc5273b90d0ae');
2 changes: 1 addition & 1 deletion build/panels.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion gatherpress.php
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
* Author URI: https://gatherpress.org/
* Version: 0.29.0-alpha
* Requires PHP: 7.4
* Requires at least: 6.4
* Requires at least: 6.5
* Text Domain: gatherpress
* Domain Path: /languages
* License: GNU General Public License v2.0 or later
48 changes: 48 additions & 0 deletions includes/core/classes/class-block.php
Original file line number Diff line number Diff line change
@@ -49,6 +49,7 @@ protected function __construct() {
* @return void
*/
protected function setup_hooks(): void {
add_action( 'init', array( $this, 'register_block_patterns' ), 10 );
// Priority 11 needed for block.json translations of title and description.
add_action( 'init', array( $this, 'register_blocks' ), 11 );
add_filter( 'load_script_translation_file', array( $this, 'fix_translation_location' ), 10, 3 );
@@ -94,4 +95,51 @@ public function register_blocks(): void {
);
}
}

/**
* Register custom block patterns.
*
* This method ...
*
* @since 0.30.0
*
* @return void
*/
public function register_block_patterns(): void {

/**
* Mainly for use with the 'venue-details' block,
* which is a group block under the hood
* and uses this pattern as innerBlocks template.
*/
\register_block_pattern(
'gatherpress/venue-details',
array(
'title' => 'Invisible Venue Details Block Pattern',
// Even this post-title seems useless, it's not.
// It is the entry point for all our hooked blocks
// and as such absolutely important!
'content' => '<!-- wp:post-title /-->', // this will a be hooked ;)
'inserter' => false,
'source' => 'plugin',
)
);

/**
* Made to be used with the 'template' parameter
* when registering of the 'gatherpress_event' post type.
*/
\register_block_pattern(
'gatherpress/venue-template',
array(
'title' => 'Invisible Venue Template Block Pattern',
// Even this paragraph seems useless, it's not.
// It is the entry point for all our hooked blocks
// and as such absolutely important!
'content' => '<!-- wp:post-featured-image /--><!-- wp:paragraph {"placeholder":"Add some infos about the venue and maybe a nice picture."} --><p></p><!-- /wp:paragraph -->', // this will a be hooked ;)
'inserter' => false,
'source' => 'plugin',
)
);
}
}
101 changes: 79 additions & 22 deletions includes/core/classes/class-event-query.php
Original file line number Diff line number Diff line change
@@ -53,7 +53,7 @@ protected function __construct() {
*/
protected function setup_hooks(): void {
add_action( 'pre_get_posts', array( $this, 'prepare_event_query_before_execution' ) );
add_filter( 'posts_clauses', array( $this, 'adjust_admin_event_sorting' ) );
add_filter( 'posts_clauses', array( $this, 'adjust_admin_event_sorting' ), 10, 2 );
}

/**
@@ -231,10 +231,10 @@ static function () use ( $page_id ) {
switch ( $events_query ) {
case 'upcoming':
remove_filter( 'posts_clauses', array( $this, 'adjust_sorting_for_past_events' ) );
add_filter( 'posts_clauses', array( $this, 'adjust_sorting_for_upcoming_events' ) );
add_filter( 'posts_clauses', array( $this, 'adjust_sorting_for_upcoming_events' ), 10, 2 );
break;
case 'past':
add_filter( 'posts_clauses', array( $this, 'adjust_sorting_for_past_events' ) );
add_filter( 'posts_clauses', array( $this, 'adjust_sorting_for_past_events' ), 10, 2 );
remove_filter( 'posts_clauses', array( $this, 'adjust_sorting_for_upcoming_events' ) );
break;
default:
@@ -251,11 +251,27 @@ static function () use ( $page_id ) {
*
* @since 1.0.0
*
* @param array $query_pieces An array containing pieces of the SQL query.
* @see https://developer.wordpress.org/reference/hooks/posts_clauses/
*
* @param array $query_pieces An array containing pieces of the SQL query.
* @param WP_Query $query The WP_Query instance (passed by reference).
* @return array The modified SQL query pieces with adjusted sorting criteria for upcoming events.
*/
public function adjust_sorting_for_upcoming_events( array $query_pieces ): array {
return $this->adjust_event_sql( $query_pieces, 'upcoming', 'ASC' );
public function adjust_sorting_for_upcoming_events( array $query_pieces, \WP_Query $query ): array {


// \error_log( 'adjust_sorting_for_upcoming_events: ' . \var_export( [
// (bool) $query->get( 'include_unfinished' ),
// $query
// ], true ) );

return $this->adjust_event_sql(
$query_pieces,
'upcoming',
$query->get( 'order' ),
$query->get( 'orderby' ),
(bool) $query->get( 'include_unfinished' )
);
}

/**
@@ -264,12 +280,18 @@ public function adjust_sorting_for_upcoming_events( array $query_pieces ): array
* This method modifies the SQL query pieces, including join, where, orderby, etc., to adjust the sorting criteria
* for past events in the query. It ensures that events are ordered by their start datetime in the desired order.
*
* @param array $query_pieces An array containing pieces of the SQL query.
*
* @param array $query_pieces An array containing pieces of the SQL query.
* @param WP_Query $query The WP_Query instance (passed by reference).
* @return array The modified SQL query pieces with adjusted sorting criteria for past events.
*/
public function adjust_sorting_for_past_events( array $query_pieces ): array {
return $this->adjust_event_sql( $query_pieces, 'past' );
public function adjust_sorting_for_past_events( array $query_pieces, \WP_Query $query ): array {
return $this->adjust_event_sql(
$query_pieces,
'past',
$query->get( 'order' ),
$query->get( 'orderby' ),
(bool) $query->get( 'include_unfinished' )
);
}

/**
@@ -280,18 +302,17 @@ public function adjust_sorting_for_past_events( array $query_pieces ): array {
*
* @since 1.0.0
*
* @param array $query_pieces An array containing pieces of the SQL query.
* @param array $query_pieces An array containing pieces of the SQL query.
* @param WP_Query $query The WP_Query instance (passed by reference).
* @return array The modified SQL query pieces with adjusted sorting criteria.
*/
public function adjust_admin_event_sorting( array $query_pieces ): array {
public function adjust_admin_event_sorting( array $query_pieces, \WP_Query $query ): array {
if ( ! is_admin() ) {
return $query_pieces;
}

global $wp_query;

if ( 'datetime' === $wp_query->get( 'orderby' ) ) {
$query_pieces = $this->adjust_event_sql( $query_pieces, 'all', $wp_query->get( 'order' ) );
if ( 'datetime' === $query->get( 'orderby' ) ) {
$query_pieces = $this->adjust_event_sql( $query_pieces, 'all', $query->get( 'order' ) );
}

return $query_pieces;
@@ -304,14 +325,24 @@ public function adjust_admin_event_sorting( array $query_pieces ): array {
* the `gatherpress_events` table in the database join. It allows querying events based on different
* criteria such as upcoming or past events and specifying the event order (DESC or ASC).
*
* @see https://developer.wordpress.org/reference/hooks/posts_join/
* @see https://developer.wordpress.org/reference/hooks/posts_orderby/
* @see https://developer.wordpress.org/reference/hooks/posts_where/
*
* @since 1.0.0
*
* @param array $pieces An array of query pieces, including join, where, orderby, and more.
* @param string $type The type of events to query (options: 'all', 'upcoming', 'past').
* @param string $order The event order ('DESC' for descending or 'ASC' for ascending).
* @return array An array containing adjusted SQL clauses for the Event query.
*/
public function adjust_event_sql( array $pieces, string $type = 'all', string $order = 'DESC' ): array {
public function adjust_event_sql(
array $pieces,
string $type = 'all',
string $order = 'DESC',
array|string $order_by = ['datetime'],
bool $inclusive = true
): array {
global $wpdb;

$defaults = array(
@@ -324,13 +355,37 @@ public function adjust_event_sql( array $pieces, string $type = 'all', string $o
'limits' => '',
);
$pieces = array_merge( $defaults, $pieces );
$table = sprintf( Event::TABLE_FORMAT, $wpdb->prefix );
$table = sprintf( Event::TABLE_FORMAT, $wpdb->prefix ); // could also (just) be $wpdb->{gatherpress_events}
$pieces['join'] .= ' LEFT JOIN ' . esc_sql( $table ) . ' ON ' . esc_sql( $wpdb->posts ) . '.ID='
. esc_sql( $table ) . '.post_id';
$order = strtoupper( $order );

if ( in_array( $order, array( 'DESC', 'ASC' ), true ) ) {
$pieces['orderby'] = sprintf( esc_sql( $table ) . '.datetime_start_gmt %s', esc_sql( $order ) );

// ORDERBY is an array, which allows to orderby multiple values.
// Currently it is only allowed to order events by ONE value.
$order_by = ( is_array( $order_by ) ) ? $order_by[0] : $order_by;
switch ( strtolower( $order_by ) ) {
case 'id':
$pieces['orderby'] = sprintf( esc_sql( $wpdb->posts ) . '.ID %s', esc_sql( $order ) );
break;

case 'title':
$pieces['orderby'] = sprintf( esc_sql( $wpdb->posts ) . '.post_name %s', esc_sql( $order ) );
break;

case 'modified':
$pieces['orderby'] = sprintf( esc_sql( $wpdb->posts ) . '.post_modified_gmt %s', esc_sql( $order ) );
break;

case 'rand':
$pieces['orderby'] = esc_sql( 'RAND()' );
break;

case 'datetime':
default:
$pieces['orderby'] = sprintf( esc_sql( $table ) . '.datetime_start_gmt %s', esc_sql( $order ) );
break;
}
}

if ( 'all' === $type ) {
@@ -339,10 +394,12 @@ public function adjust_event_sql( array $pieces, string $type = 'all', string $o

$current = gmdate( Event::DATETIME_FORMAT, time() );

$column = ( ($inclusive && 'upcoming' === $type) || (! $inclusive && 'past' === $type) ) ? 'datetime_end_gmt' : 'datetime_start_gmt';

if ( 'upcoming' === $type ) {
$pieces['where'] .= $wpdb->prepare( ' AND %i.datetime_end_gmt >= %s', $table, $current ); // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.UnsupportedIdentifierPlaceholder
$pieces['where'] .= $wpdb->prepare( ' AND %i.%i >= %s', $table, $column, $current ); // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.UnsupportedIdentifierPlaceholder
} elseif ( 'past' === $type ) {
$pieces['where'] .= $wpdb->prepare( ' AND %i.datetime_end_gmt < %s', $table, $current ); // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.UnsupportedIdentifierPlaceholder
$pieces['where'] .= $wpdb->prepare( ' AND %i.%i < %s', $table, $column, $current ); // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.UnsupportedIdentifierPlaceholder
}

return $pieces;
1 change: 1 addition & 0 deletions includes/core/classes/class-event-setup.php
Original file line number Diff line number Diff line change
@@ -136,6 +136,7 @@ public function register_post_type(): void {
'custom-fields',
),
'menu_icon' => 'dashicons-nametag',
'has_archive' => true,
'rewrite' => array(
'slug' => _x( 'event', 'Post Type Slug', 'gatherpress' ),
),
Loading