Skip to content

Commit

Permalink
3.0 (#12)
Browse files Browse the repository at this point in the history
init version 3.0!
  • Loading branch information
kjroelke authored Nov 17, 2023
1 parent cc93007 commit f503512
Show file tree
Hide file tree
Showing 33 changed files with 1,610 additions and 368 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ A WordPress Plugin for Event Displays.

# Changelog

## v3.0.0

- Inits the new Archive page that handles GraphQL + React Search

### Non-GraphQL Updates

- Allows a template override for the content parts at `template-parts/events/content-event-preview.php`
- Updates the Archive query to sort posts by ACF field (instead of publish date).
- Removes the Search form from the basic field

## v2.2.0

- Extended Choctaw_Events API
Expand Down
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,8 @@
},
"require-dev": {
"wp-coding-standards/wpcs": "*"
},
"require": {
"wp-graphql/wp-graphql-acf": "^0.6.1"
}
}
69 changes: 67 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/choctaw-events-search.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('react', 'wp-api-fetch', 'wp-element'), 'version' => 'd8898034ba6cf0b82e78');
<?php return array('dependencies' => array('react', 'react-dom'), 'version' => '899581dc216a0b4e495c');
75 changes: 74 additions & 1 deletion dist/choctaw-events-search.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion inc/acf/objects/class-choctaw-event.php
Original file line number Diff line number Diff line change
Expand Up @@ -475,4 +475,4 @@ public function get_the_excerpt(): string {
public function the_excerpt() {
return $this->get_the_excerpt();
}
}
}
2 changes: 1 addition & 1 deletion inc/acf/objects/class-event-venue.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,4 +205,4 @@ public function the_website() {
echo "<a href='{$url}' target='_blank' rel='noopener noreferrer' id='venue-website'>{$url}</a>";
}
}
}
}
45 changes: 41 additions & 4 deletions inc/class-plugin-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ public function __construct( string $cpt_slug = 'choctaw-events', string $rewrit
parent::__construct( $cpt_slug, $rewrite );
parent::init();
add_filter( 'template_include', array( $this, 'update_template_loader' ) );
add_action( 'wp_enqueue_scripts', array( $this, 'add_to_calendar_js' ) );
add_action( 'wp_enqueue_scripts', array( $this, 'register_scripts' ) );
include_once __DIR__ . '/acf/objects/class-event-venue.php';
// register_activation_hook( dirname( __DIR__ ) . '/index.php', array( $this, 'activate_plugin' ) );
add_action( 'after_setup_theme', array( $this, 'register_image_sizes' ) );
add_action( 'pre_get_posts', array( $this, 'custom_archive_query' ) );
add_filter( 'register_taxonomy_args', array( $this, 'add_venue_to_graphql' ), 10, 2 );
}

/**
Expand Down Expand Up @@ -80,7 +81,7 @@ private function get_the_search_page(): string|\WP_Error {
}

/** Enqueues the "Add to Calendar" logic */
public function add_to_calendar_js() {
public function register_scripts() {
$asset_file = require_once dirname( __DIR__, 1 ) . '/dist/choctaw-events.asset.php';
wp_register_script(
'choctaw-events-add-to-calendar',
Expand All @@ -89,6 +90,17 @@ public function add_to_calendar_js() {
$asset_file['version'],
array( 'strategy' => 'defer' )
);

$search_asset_file = require_once dirname( __DIR__, 1 ) . '/dist/choctaw-events-search.asset.php';
$deps = array_merge( array( 'main' ), $search_asset_file['dependencies'] );
wp_register_script(
'choctaw-events-search',
plugin_dir_url( __DIR__ ) . 'dist/choctaw-events-search.js',
$deps,
$search_asset_file['version'],
array( 'strategy' => 'defer' )
);
wp_localize_script( 'choctaw-events-search', 'cnoEventSearchData', array( 'rootUrl' => home_url() ) );
}

/** Enqueues the "Search" logic powered by TypeScript React (.tsx) */
Expand All @@ -108,4 +120,29 @@ public function register_image_sizes() {
add_image_size( 'choctaw-events-preview', 1392, 784 );
add_image_size( 'choctaw-events-single', 2592, 1458 );
}
}

/**
* Updates the Archive Page loop to display posts via ACF field instead of publish date
*
* @param \WP_Query $query the current query
*/
public function custom_archive_query( \WP_Query $query ) {
$is_archive = $query->is_post_type_archive( 'choctaw-events' );
if ( $is_archive && $query->is_main_query() ) {
$query->set( 'meta_key', 'event_details_time_and_date_start_date' );
$query->set( 'orderby', 'meta_value_num' );
$query->set( 'order', 'ASC' );
}
}

/** Registers Venues taxonommy to GraphQL if exists */
public function add_venue_to_graphql( array $args, string $taxonomy ) {
if ( 'choctaw-events-venue' === $taxonomy ) {
$args['show_in_graphql'] = true;
$args['graphql_single_name'] = 'choctawEventsVenue';
$args['graphql_plural_name'] = 'choctawEventsVenues';
}

return $args;
}
}
49 changes: 48 additions & 1 deletion inc/plugin-logic/class-admin-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,53 @@ protected function init() {
$this->add_acf_date_columns();
$this->make_acf_columns_sortable();
$this->add_cpt_to_search_loop();
$this->add_event_category_to_columns();
}


/**
* Adds event category to columns.
*
* @return void
*/
private function add_event_category_to_columns() {
add_filter( 'manage_posts_columns', array( $this, 'choctaw_events_admin_column' ) );
add_filter( 'manage_custom_post_type_columns', array( $this, 'choctaw_events_admin_column' ) );
add_action( 'manage_posts_custom_column', array( $this, 'choctaw_events_admin_column_data' ), 10, 2 );
add_action( 'manage_custom_post_type_custom_column', array( $this, 'choctaw_events_admin_column_data' ), 10, 2 );
}

/**
* Adds a new column to the admin events list table.
*
* @param array $columns The existing columns in the events list table.
* @return array The updated columns with the new 'Category' column.
*/
public function choctaw_events_admin_column( array $columns ) {
$columns['choctaw-events'] = 'Category';
return $columns;
}

/**
* Retrieves the data for the admin column of the Choctaw events custom post type.
*
* @param string $column The name of the column to retrieve data for.
* @param int $post_id The ID of the post to retrieve data for.
*/
public function choctaw_events_admin_column_data( string $column, int $post_id ) {
if ( 'choctaw-events' === $column ) {
$terms = get_the_terms( $post_id, 'choctaw-events-category' );

if ( $terms && ! is_wp_error( $terms ) ) {
$term_names = array();
foreach ( $terms as $term ) {
$term_names[] = "<a href='edit.php?post_type=choctaw-events&{$term->taxonomy}={$term->slug}'>{$term->name}</a>";
}
echo implode( ', ', $term_names );
} else {
echo '';
}
}
}

/** Adds ACF Start & End Date Columns */
Expand Down Expand Up @@ -122,4 +169,4 @@ public function include_choctaw_events_post_type_in_search( \WP_Query $query ) {
$query->set( 'post_type', array( 'choctaw-events' ) );
}
}
}
}
37 changes: 22 additions & 15 deletions inc/plugin-logic/class-cpt.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,33 +78,40 @@ public function init() {
/** Init the CPT */
private function init_cpt() {
$args = array(
'labels' => $this->cpt_labels,
'public' => true,
'has_archive' => true,
'show_in_rest' => true,
'rest_base' => 'choctaw-events',
'rewrite' => array( 'slug' => $this->rewrite ),
'supports' => array(
'labels' => $this->cpt_labels,
'public' => true,
'has_archive' => true,
'show_in_rest' => true,
'show_in_graphql' => true,
'graphql_single_name' => 'choctawEvent',
'graphql_plural_name' => 'choctawEvents',
'rest_base' => 'choctaw-events',
'rewrite' => array( 'slug' => $this->rewrite ),
'supports' => array(
'title',
'thumbnail',
'revisions',
'author',
),
'taxonomies' => array( 'post_tag' ),
'menu_icon' => 'dashicons-calendar',
'menu_position' => 6,
'taxonomies' => array( 'post_tag' ),
'menu_icon' => 'dashicons-calendar',
'menu_position' => 6,
);
register_post_type( $this->slug, $args );
}

/** Init custom event category taxonomy (for non-conflicting event categories outside the WP Core categories) */
private function init_category_taxonomy() {
$args = array(
'labels' => $this->event_category_labels,
'public' => true,
'hierarchical' => true,
'rewrite' => array( 'slug' => 'category' ),
'labels' => $this->event_category_labels,
'public' => true,
'hierarchical' => true,
'show_in_graphql' => true,
'graphql_single_name' => 'choctawEventCategory',
'graphql_plural_name' => 'choctawEventCategories',
'show_in_rest' => true,
'rewrite' => array( 'slug' => 'category' ),
);
register_taxonomy( 'choctaw-events-category', $this->slug, $args );
}
}
}
Loading

0 comments on commit f503512

Please sign in to comment.