Skip to content

Commit

Permalink
fixes #3
Browse files Browse the repository at this point in the history
  • Loading branch information
kjroelke committed Nov 6, 2023
1 parent b4f25c1 commit 8f5e0f6
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 24 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ A WordPress Plugin for Event Displays.

# Changelog

## v2.0.5

- Update AddToCalendar logic to be registered immediately and enqueud in the `single` file.

## v2.0.4

- Further bug fixes for namespacing.
Expand Down
24 changes: 10 additions & 14 deletions inc/class-plugin-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ 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' ) );
include_once __DIR__ . '/acf/objects/class-event-venue.php';
register_activation_hook( dirname( __DIR__ ) . '/index.php', array( $this, 'activate_plugin' ) );
// register_activation_hook( dirname( __DIR__ ) . '/index.php', array( $this, 'activate_plugin' ) );
}


Expand All @@ -37,19 +38,17 @@ public function __construct( string $cpt_slug = 'choctaw-events', string $rewrit
public function update_template_loader( string $template ): string {
$is_single = is_singular( 'choctaw-events' );
$is_archive = is_archive( 'choctaw-events' );
$is_search = is_search();
// $is_search = is_search();
if ( $is_single ) {
$template = $this->get_the_template( 'single' );
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_single_js' ) );
}
if ( $is_archive ) {
$template = $this->get_the_template( 'archive' );
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_search_tsx' ) );
}
if ( is_search() ) {
$template = $this->get_the_search_page( $template );

// add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_search_tsx' ) );
}
// if ( is_search() ) {
// $template = $this->get_the_search_page( $template );
// }
return $template;
}

Expand All @@ -75,21 +74,18 @@ private function get_the_template( string $type ): string|\WP_Error {
*/
private function get_the_search_page(): string|\WP_Error {
$search_page = dirname( __DIR__, 1 ) . '/templates/search.php';
global $wp_query;
// $post_type = $wp_query->
if ( file_exists( $search_page ) ) {

return $search_page;
} else {
return new \WP_Error( 'Choctaw Events Error', 'Search page not found!' );
}
}

/** Enqueues the "Add to Calendar" logic */
public function enqueue_single_js() {
public function add_to_calendar_js() {
$asset_file = require_once dirname( __DIR__, 1 ) . '/dist/choctaw-events.asset.php';
wp_enqueue_script(
'choctaw-events',
wp_register_script(
'choctaw-events-add-to-calendar',
plugin_dir_url( __DIR__ ) . 'dist/choctaw-events.js',
$asset_file['dependencies'],
$asset_file['version'],
Expand Down
18 changes: 9 additions & 9 deletions inc/plugin-logic/class-admin-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@
/** Handles the WP Hooks & Filters logic */
class Admin_Handler extends Post_Type_Builder {
/** Handle Plugin Activation */
// public function activate_plugin() {
// if ( ! is_plugin_active( plugin_dir_path( 'wp-graphql/wp-graphql.php' ) ) ) {
// add_action( 'admin_notices', 'display_dependency_notice' );
// }
public function activate_plugin() {
if ( ! is_plugin_active( plugin_dir_path( 'wp-graphql/wp-graphql.php' ) ) ) {
add_action( 'admin_notices', 'display_dependency_notice' );
}

// add_action( 'admin_notices', array( $this, 'display_dependency_notice' ) );
// }
add_action( 'admin_notices', array( $this, 'display_dependency_notice' ) );
}

// public function display_dependency_notice() {
// echo '<div class="notice notice-error"><p>This plugin requires "WPGraphQL" to be active.</p></div>';
// }
public function display_dependency_notice() {
echo '<div class="notice notice-error"><p>This plugin requires "WPGraphQL" to be active.</p></div>';
}

/** Handles the WordPress Admin Columns Hooks & Filters */
protected function init() {
Expand Down
2 changes: 1 addition & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* Plugin Name: Choctaw Events Plugin
* Description: Choctaw Events Plugin creates the Events and displays them in a nice way.
* Version: 2.0.4
* Version: 2.0.5
* Author: Choctaw Nation of Oklahoma
* Author URI: https://www.choctawnation.com
* Text Domain: cno
Expand Down
1 change: 1 addition & 0 deletions templates/single-choctaw-events.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use ChoctawNation\Events\Choctaw_Event;

get_header();
wp_enqueue_script( 'choctaw-events-add-to-calendar' );
$event = new Choctaw_Event( get_field( 'event_details' ), get_the_ID() );
?>
<div class="container my-5 py-5">
Expand Down

0 comments on commit 8f5e0f6

Please sign in to comment.