diff --git a/includes/core/classes/class-assets.php b/includes/core/classes/class-assets.php index a42004c89..17be41b2f 100644 --- a/includes/core/classes/class-assets.php +++ b/includes/core/classes/class-assets.php @@ -21,7 +21,9 @@ * @since 1.0.0 */ class Assets { - + /** + * Enforces a single instance of this class. + */ use Singleton; /** @@ -386,5 +388,4 @@ protected function get_asset_data( string $asset ): array { return $this->asset_data[ $asset ]; } - } diff --git a/includes/core/classes/class-autoloader.php b/includes/core/classes/class-autoloader.php index 985374dbf..d47c270a9 100644 --- a/includes/core/classes/class-autoloader.php +++ b/includes/core/classes/class-autoloader.php @@ -20,7 +20,6 @@ * @since 1.0.0 */ class Autoloader { - /** * Register method for autoloader. * @@ -46,8 +45,9 @@ static function( $class ): bool { array_unshift( $structure, 'includes' ); switch ( $class_type ) { - case 'traits': + case 'commands': case 'settings': + case 'traits': array_pop( $structure ); array_push( $structure, 'classes', $class_type ); break; @@ -69,5 +69,4 @@ static function( $class ): bool { } ); } - } diff --git a/includes/core/classes/class-block.php b/includes/core/classes/class-block.php index c30f55215..778945156 100644 --- a/includes/core/classes/class-block.php +++ b/includes/core/classes/class-block.php @@ -20,7 +20,9 @@ * @since 1.0.0 */ class Block { - + /** + * Enforces a single instance of this class. + */ use Singleton; /** @@ -63,5 +65,4 @@ public function register_blocks(): void { register_block_type( sprintf( '%1$s/build/blocks/%2$s', GATHERPRESS_CORE_PATH, $block ) ); } } - } diff --git a/includes/core/classes/class-cli.php b/includes/core/classes/class-cli.php index 4018459c1..8bc85acd8 100644 --- a/includes/core/classes/class-cli.php +++ b/includes/core/classes/class-cli.php @@ -1,8 +1,8 @@ add_response( $event_id, $assoc_args ); - } - } + use Singleton; /** - * Generate credits data for the credits page. + * Constructor for the Setup class. * - * This method generates credits data for displaying on the credits page. - * It retrieves user data from WordPress.org profiles based on the provided version. + * Registers WP-CLI commands for GatherPress if WP-CLI is present. * * @since 1.0.0 - * - * @param array $args Positional arguments for the script. - * @param array $assoc_args Associative arguments for the script. - * @return void */ - public function generate_credits( array $args = array(), array $assoc_args = array() ): void { - $credits = require_once GATHERPRESS_CORE_PATH . '/includes/data/credits/credits.php'; - $version = $assoc_args['version'] ?? GATHERPRESS_VERSION; - $latest = GATHERPRESS_CORE_PATH . '/includes/data/credits/latest.php'; - $data = array(); - - if ( empty( $credits[ $version ] ) ) { - WP_CLI::error( 'Version does not exist' ); - } - - unlink( $latest ); - $file = fopen( $latest, 'w' ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_fopen - - $data['version'] = $version; - - foreach ( $credits[ $version ] as $group => $users ) { - if ( 'contributors' === $group ) { - sort( $users ); - } - - $data[ $group ] = array(); - - foreach ( $users as $user ) { - $response = wp_remote_request( sprintf( 'https://profiles.wordpress.org/wp-json/wporg/v1/users/%s', $user ) ); - $user_data = json_decode( $response['body'], true ); - - // Remove unsecure data (eg http) and data we do not need. - unset( $user_data['description'], $user_data['url'], $user_data['meta'], $user_data['_links'] ); - - $data[ $group ][] = $user_data; - } + protected function __construct() { + if ( defined( 'WP_CLI' ) && WP_CLI ) { // @codeCoverageIgnore + WP_CLI::add_command( 'gatherpress', Cli_General::class ); // @codeCoverageIgnore + WP_CLI::add_command( 'gatherpress event', Cli_Event::class ); // @codeCoverageIgnore } - fwrite( $file, 'rsvp->save( $user_id, $status, $guests ); - - WP_CLI::success( $response ); - } - } diff --git a/includes/core/classes/class-event-query.php b/includes/core/classes/class-event-query.php index 07200fbe3..318266307 100644 --- a/includes/core/classes/class-event-query.php +++ b/includes/core/classes/class-event-query.php @@ -23,7 +23,9 @@ * @since 1.0.0 */ class Event_Query { - + /** + * Enforces a single instance of this class. + */ use Singleton; /** @@ -340,5 +342,4 @@ public function adjust_event_sql( array $pieces, string $type = 'all', string $o return $pieces; } - } diff --git a/includes/core/classes/class-event.php b/includes/core/classes/class-event.php index cd5b98b0e..0234a872b 100644 --- a/includes/core/classes/class-event.php +++ b/includes/core/classes/class-event.php @@ -23,7 +23,6 @@ * @since 1.0.0 */ class Event { - /** * Cache key format for storing and retrieving event datetimes. * @@ -251,7 +250,8 @@ public function get_display_datetime(): string { } if ( ! empty( $start ) && ! empty( $end ) ) { - return sprintf( '%s to %s', $start, $end ); + /* translators: %1$s: start datetime, %2$s: end datetime. */ + return sprintf( __( '%1$s to %2$s', 'gatherpress' ), $start, $end ); } return __( '—', 'gatherpress' ); @@ -951,5 +951,4 @@ public function maybe_get_online_event_link(): string { return $event_link; } - } diff --git a/includes/core/classes/class-rest-api.php b/includes/core/classes/class-rest-api.php index c1ec0a9d1..2ed006b75 100644 --- a/includes/core/classes/class-rest-api.php +++ b/includes/core/classes/class-rest-api.php @@ -27,7 +27,9 @@ * @since 1.0.0 */ class Rest_Api { - + /** + * Enforces a single instance of this class. + */ use Singleton; /** @@ -677,5 +679,4 @@ public function prepare_event_data( WP_REST_Response $response ): WP_REST_Respon return $response; } - } diff --git a/includes/core/classes/class-rsvp.php b/includes/core/classes/class-rsvp.php index 341d70649..2a5021d1f 100644 --- a/includes/core/classes/class-rsvp.php +++ b/includes/core/classes/class-rsvp.php @@ -22,7 +22,6 @@ * @since 1.0.0 */ class Rsvp { - /** * Table format for RSVPs. * @@ -413,5 +412,4 @@ function( $role ) { public function sort_by_timestamp( array $first, array $second ): bool { return ( strtotime( $first['timestamp'] ) < strtotime( $second['timestamp'] ) ); } - } diff --git a/includes/core/classes/class-settings.php b/includes/core/classes/class-settings.php index cee588a6b..6e650e195 100644 --- a/includes/core/classes/class-settings.php +++ b/includes/core/classes/class-settings.php @@ -25,7 +25,9 @@ * @since 1.0.0 */ class Settings { - + /** + * Enforces a single instance of this class. + */ use Singleton; const PARENT_SLUG = 'edit.php?post_type=gp_event'; @@ -639,5 +641,4 @@ public function datetime_preview( string $name, string $value ): void { ); } } - } diff --git a/includes/core/classes/class-setup.php b/includes/core/classes/class-setup.php index 3e2912bb1..f201c155a 100644 --- a/includes/core/classes/class-setup.php +++ b/includes/core/classes/class-setup.php @@ -13,7 +13,6 @@ use Exception; use GatherPress\Core\Traits\Singleton; -use WP_CLI; use WP_Post; /** @@ -24,7 +23,9 @@ * @since 1.0.0 */ class Setup { - + /** + * Enforces a single instance of this class. + */ use Singleton; /** @@ -55,14 +56,11 @@ protected function __construct() { protected function instantiate_classes(): void { Assets::get_instance(); Block::get_instance(); + Cli::get_instance(); Event_Query::get_instance(); Rest_Api::get_instance(); Settings::get_instance(); Venue::get_instance(); - - if ( defined( 'WP_CLI' ) && WP_CLI ) { // @codeCoverageIgnore - WP_CLI::add_command( 'gatherpress', Cli::class ); // @codeCoverageIgnore - } } /** @@ -671,5 +669,4 @@ public function check_users_can_register() : void { ); } } - } diff --git a/includes/core/classes/class-utility.php b/includes/core/classes/class-utility.php index 8ca3e856b..055a44a11 100644 --- a/includes/core/classes/class-utility.php +++ b/includes/core/classes/class-utility.php @@ -20,7 +20,6 @@ * @since 1.0.0 */ class Utility { - /** * Renders a template file. * @@ -117,5 +116,4 @@ public static function timezone_choices(): array { return $timezones_clean; } - } diff --git a/includes/core/classes/class-venue.php b/includes/core/classes/class-venue.php index 64f6b9c3b..9261fb8c6 100644 --- a/includes/core/classes/class-venue.php +++ b/includes/core/classes/class-venue.php @@ -22,7 +22,9 @@ * @since 1.0.0 */ class Venue { - + /** + * Enforces a single instance of this class. + */ use Singleton; /** @@ -392,5 +394,4 @@ public function get_venue_meta( int $post_id, string $post_type ): array { return $venue_meta; } - } diff --git a/includes/core/classes/commands/class-cli-event.php b/includes/core/classes/commands/class-cli-event.php new file mode 100644 index 000000000..c744f9583 --- /dev/null +++ b/includes/core/classes/commands/class-cli-event.php @@ -0,0 +1,80 @@ +] + * : ID of an event. + * + * [--user_id=] + * : ID of a user. + * + * [--status=] + * : Attendance status. + * --- + * default: attending + * options: + * - attending + * - not_attending + * - waiting_list + * + * ## EXAMPLES + * + * # Update RSVP for an event. + * $ wp gatherpress event rsvp --event_id=525 --user_id=1 --status="not_attending" + * Success: The RSVP status for Event ID "525" has been successfully set to "not_attending" for User ID "1". + * + * @since 1.0.0 + * + * @param array $args Positional arguments for the script. + * @param array $assoc_args Associative arguments for the script. + * + * @return void + */ + public function rsvp( array $args = array(), array $assoc_args = array() ): void { + $event_id = (int) $assoc_args['event_id']; + $user_id = (int) $assoc_args['user_id']; + $status = (string) $assoc_args['status'] ?? 'attending'; + $event = new Event( $event_id ); + + $response = $event->rsvp->save( $user_id, $status ); + + WP_CLI::success( + sprintf( + /* translators: %1$d: event ID, %2$s: attendance status, %3$d: user ID. */ + __( 'The RSVP status for Event ID "%1$d" has been successfully set to "%2$s" for User ID "%3$d".', 'gatherpress' ), + $event_id, + $response, + $user_id + ), + ); + } +} diff --git a/includes/core/classes/commands/class-cli-general.php b/includes/core/classes/commands/class-cli-general.php new file mode 100644 index 000000000..2c6706e7e --- /dev/null +++ b/includes/core/classes/commands/class-cli-general.php @@ -0,0 +1,86 @@ +] + * : Plugin version to generate. + * + * ## EXAMPLES + * + * # Generate credits. + * $ wp gatherpress generate_credits --version=1.0.0 + * Success: New latest.php file has been generated. + * + * @since 1.0.0 + * + * @param array $args Positional arguments for the script. + * @param array $assoc_args Associative arguments for the script. + * @return void + */ + public function generate_credits( array $args = array(), array $assoc_args = array() ): void { + $credits = require_once GATHERPRESS_CORE_PATH . '/includes/data/credits/credits.php'; + $version = $assoc_args['version'] ?? GATHERPRESS_VERSION; + $latest = GATHERPRESS_CORE_PATH . '/includes/data/credits/latest.php'; + $data = array(); + + if ( empty( $credits[ $version ] ) ) { + WP_CLI::error( 'Version does not exist' ); + } + + unlink( $latest ); + $file = fopen( $latest, 'w' ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_fopen + + $data['version'] = $version; + + foreach ( $credits[ $version ] as $group => $users ) { + if ( 'contributors' === $group ) { + sort( $users ); + } + + $data[ $group ] = array(); + + foreach ( $users as $user ) { + $response = wp_remote_request( sprintf( 'https://profiles.wordpress.org/wp-json/wporg/v1/users/%s', $user ) ); + $user_data = json_decode( $response['body'], true ); + + // Remove unsecure data (eg http) and data we do not need. + unset( $user_data['description'], $user_data['url'], $user_data['meta'], $user_data['_links'] ); + + $data[ $group ][] = $user_data; + } + } + + fwrite( $file, ' $this->sections, ); } - } diff --git a/includes/core/classes/settings/class-credits.php b/includes/core/classes/settings/class-credits.php index 205eaa0d8..eaefc7317 100644 --- a/includes/core/classes/settings/class-credits.php +++ b/includes/core/classes/settings/class-credits.php @@ -22,7 +22,9 @@ * @since 1.0.0 */ class Credits extends Base { - + /** + * Enforces a single instance of this class. + */ use Singleton; /** @@ -96,5 +98,4 @@ protected function credits_page(): void { true ); } - } diff --git a/includes/core/classes/settings/class-general.php b/includes/core/classes/settings/class-general.php index 213586708..e7eed5f72 100644 --- a/includes/core/classes/settings/class-general.php +++ b/includes/core/classes/settings/class-general.php @@ -24,7 +24,9 @@ * @since 1.0.0 */ class General extends Base { - + /** + * Enforces a single instance of this class. + */ use Singleton; /** @@ -169,5 +171,4 @@ protected function get_section(): array { ), ); } - } diff --git a/includes/core/classes/settings/class-leadership.php b/includes/core/classes/settings/class-leadership.php index f568fa1de..1a45f04d8 100644 --- a/includes/core/classes/settings/class-leadership.php +++ b/includes/core/classes/settings/class-leadership.php @@ -23,7 +23,9 @@ * @since 1.0.0 */ class Leadership extends Base { - + /** + * Enforces a single instance of this class. + */ use Singleton; /** @@ -118,5 +120,4 @@ public function get_user_role( int $user_id ): string { return $default; } - } diff --git a/includes/core/requirements-check.php b/includes/core/requirements-check.php index 43f9f4bd0..95c659a5f 100644 --- a/includes/core/requirements-check.php +++ b/includes/core/requirements-check.php @@ -20,7 +20,7 @@ static function () {

assertSame( $blocks, $expected ); } - } diff --git a/test/unit/php/includes/core/classes/class-test-event-query.php b/test/unit/php/includes/core/classes/class-test-event-query.php index 1b2531475..2654c7216 100644 --- a/test/unit/php/includes/core/classes/class-test-event-query.php +++ b/test/unit/php/includes/core/classes/class-test-event-query.php @@ -20,7 +20,6 @@ * @coversDefaultClass \GatherPress\Core\Event_Query */ class Test_Event_Query extends Base { - /** * Coverage for setup_hooks method. * @@ -246,5 +245,4 @@ public function test_adjust_event_sql(): void { $this->assertStringContainsString( 'ASC', $retval['orderby'] ); $this->assertStringContainsString( "AND {$table}.datetime_end_gmt >=", $retval['where'] ); } - } diff --git a/test/unit/php/includes/core/classes/class-test-event.php b/test/unit/php/includes/core/classes/class-test-event.php index 42b563d4f..6497d04c0 100644 --- a/test/unit/php/includes/core/classes/class-test-event.php +++ b/test/unit/php/includes/core/classes/class-test-event.php @@ -24,7 +24,6 @@ * @coversDefaultClass \GatherPress\Core\Event */ class Test_Event extends Base { - /** * Coverage for __construct method. * @@ -837,5 +836,4 @@ public function test_maybe_get_online_event_link(): void { 'Failed to assert empty string due to RSVP being set to null.' ); } - } diff --git a/test/unit/php/includes/core/classes/class-test-rest-api.php b/test/unit/php/includes/core/classes/class-test-rest-api.php index e54223562..fb767c287 100644 --- a/test/unit/php/includes/core/classes/class-test-rest-api.php +++ b/test/unit/php/includes/core/classes/class-test-rest-api.php @@ -22,7 +22,6 @@ * @coversDefaultClass \GatherPress\Core\Rest_Api */ class Test_Rest_Api extends Base { - /** * Coverage for setup_hooks method. * @@ -674,5 +673,4 @@ public function test_update_rsvp(): void { 'Failed to assert that event ID matches.' ); } - } diff --git a/test/unit/php/includes/core/classes/class-test-rsvp.php b/test/unit/php/includes/core/classes/class-test-rsvp.php index 818b3a419..9f30db5df 100644 --- a/test/unit/php/includes/core/classes/class-test-rsvp.php +++ b/test/unit/php/includes/core/classes/class-test-rsvp.php @@ -19,7 +19,6 @@ * @coversDefaultClass \GatherPress\Core\Rsvp */ class Test_Rsvp extends Base { - /** * Coverage for get method. * @@ -196,5 +195,4 @@ public function test_sort_by_timestamp(): void { 'Failed to assert correct sorting of timestamp.' ); } - } diff --git a/test/unit/php/includes/core/classes/class-test-settings.php b/test/unit/php/includes/core/classes/class-test-settings.php index 7bc0a1e1e..b24a9a3ae 100644 --- a/test/unit/php/includes/core/classes/class-test-settings.php +++ b/test/unit/php/includes/core/classes/class-test-settings.php @@ -18,7 +18,6 @@ * @coversDefaultClass \GatherPress\Core\Settings */ class Test_Settings extends Base { - /** * Coverage for setup_hooks. * @@ -290,5 +289,4 @@ public function test_get_sub_pages(): void { 'Failed to assert that credits is last key.' ); } - } diff --git a/test/unit/php/includes/core/classes/class-test-setup.php b/test/unit/php/includes/core/classes/class-test-setup.php index db947dc35..7c6704325 100644 --- a/test/unit/php/includes/core/classes/class-test-setup.php +++ b/test/unit/php/includes/core/classes/class-test-setup.php @@ -20,7 +20,6 @@ * @coversDefaultClass \GatherPress\Core\Setup */ class Test_Setup extends Base { - /** * Coverage for setup_hooks. * @@ -287,5 +286,4 @@ public function test_sortable_columns(): void { 'Failed to assert correct sortable columns.' ); } - } diff --git a/test/unit/php/includes/core/classes/class-test-utility.php b/test/unit/php/includes/core/classes/class-test-utility.php index a924a87a6..fc17229cc 100644 --- a/test/unit/php/includes/core/classes/class-test-utility.php +++ b/test/unit/php/includes/core/classes/class-test-utility.php @@ -20,7 +20,6 @@ * @coversDefaultClass \GatherPress\Core\Utility */ class Test_Utility extends Base { - /** * Coverage for render_template method. * @@ -107,5 +106,4 @@ public function test_timezone_choices(): void { $this->assertIsArray( $timezones[ $key ] ); } } - } diff --git a/test/unit/php/includes/core/classes/class-test-venue.php b/test/unit/php/includes/core/classes/class-test-venue.php index f48d47c10..0d5462e75 100644 --- a/test/unit/php/includes/core/classes/class-test-venue.php +++ b/test/unit/php/includes/core/classes/class-test-venue.php @@ -19,7 +19,6 @@ * @coversDefaultClass \GatherPress\Core\Venue */ class Test_Venue extends Base { - /** * Coverage for __construct and setup_hooks. * @@ -367,5 +366,4 @@ public function test_get_venue_meta(): void { 'Failed to assert venue title matches the venue meta title.' ); } - } diff --git a/test/unit/php/includes/core/classes/settings/class-test-base.php b/test/unit/php/includes/core/classes/settings/class-test-base.php index 930094a8e..48ae3ccca 100644 --- a/test/unit/php/includes/core/classes/settings/class-test-base.php +++ b/test/unit/php/includes/core/classes/settings/class-test-base.php @@ -18,7 +18,6 @@ * @coversDefaultClass \GatherPress\Core\Settings\Base */ class Test_Base extends Base_Unit_Test { - /** * Coverage for setup_up method. * @@ -75,5 +74,4 @@ public function test_get(): void { $this->assertNull( $instance->get( 'unit-test' ), 'Failed to assert property is null.' ); $this->assertSame( $slug, $instance->get( 'slug' ), 'Failed to assert property is unit-test.' ); } - } diff --git a/test/unit/php/includes/core/classes/settings/class-test-credits.php b/test/unit/php/includes/core/classes/settings/class-test-credits.php index ec7fa8a04..f832084a5 100644 --- a/test/unit/php/includes/core/classes/settings/class-test-credits.php +++ b/test/unit/php/includes/core/classes/settings/class-test-credits.php @@ -19,7 +19,6 @@ * @coversDefaultClass \GatherPress\Core\Settings\Credits */ class Test_Credits extends Base { - /** * Coverage for __construct method. * @@ -100,5 +99,4 @@ public function test_settings_section(): void { $this->assertNotEmpty( $response, 'Failed to assert markup was returned.' ); } - } diff --git a/test/unit/php/includes/core/classes/settings/class-test-general.php b/test/unit/php/includes/core/classes/settings/class-test-general.php index 68c8c6654..6f223fbda 100644 --- a/test/unit/php/includes/core/classes/settings/class-test-general.php +++ b/test/unit/php/includes/core/classes/settings/class-test-general.php @@ -18,7 +18,6 @@ * @coversDefaultClass \GatherPress\Core\Settings\General */ class Test_General extends Base { - /** * Coverage for __construct method. * @@ -67,5 +66,4 @@ public function test_get_section(): void { 'Failed to assert pages section is an array.' ); } - } diff --git a/test/unit/php/includes/core/classes/settings/class-test-leadership.php b/test/unit/php/includes/core/classes/settings/class-test-leadership.php index c9fcb30c8..05c5eb632 100644 --- a/test/unit/php/includes/core/classes/settings/class-test-leadership.php +++ b/test/unit/php/includes/core/classes/settings/class-test-leadership.php @@ -18,7 +18,6 @@ * @coversDefaultClass \GatherPress\Core\Settings\Leadership */ class Test_Leadership extends Base { - /** * Coverage for __construct method. * @@ -110,5 +109,4 @@ public function test_get_user_role(): void { delete_option( 'gp_leadership' ); } - }