From 8f5e0f62d1d5ba13efa0fb7b8948efdf8841d454 Mon Sep 17 00:00:00 2001 From: KJ Roelke Date: Mon, 6 Nov 2023 14:23:22 -0600 Subject: [PATCH] fixes #3 --- README.md | 4 ++++ inc/class-plugin-loader.php | 24 ++++++++++-------------- inc/plugin-logic/class-admin-handler.php | 18 +++++++++--------- index.php | 2 +- templates/single-choctaw-events.php | 1 + 5 files changed, 25 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index e6536aa..5365ead 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/inc/class-plugin-loader.php b/inc/class-plugin-loader.php index be6d4b3..256a1ad 100644 --- a/inc/class-plugin-loader.php +++ b/inc/class-plugin-loader.php @@ -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' ) ); } @@ -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; } @@ -75,10 +74,7 @@ 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!' ); @@ -86,10 +82,10 @@ private function get_the_search_page(): string|\WP_Error { } /** 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'], diff --git a/inc/plugin-logic/class-admin-handler.php b/inc/plugin-logic/class-admin-handler.php index 5f51a47..594bb7e 100644 --- a/inc/plugin-logic/class-admin-handler.php +++ b/inc/plugin-logic/class-admin-handler.php @@ -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 '

This plugin requires "WPGraphQL" to be active.

'; - // } + public function display_dependency_notice() { + echo '

This plugin requires "WPGraphQL" to be active.

'; + } /** Handles the WordPress Admin Columns Hooks & Filters */ protected function init() { diff --git a/index.php b/index.php index b30f231..76acd34 100644 --- a/index.php +++ b/index.php @@ -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 diff --git a/templates/single-choctaw-events.php b/templates/single-choctaw-events.php index e51c83b..4b8c04e 100644 --- a/templates/single-choctaw-events.php +++ b/templates/single-choctaw-events.php @@ -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() ); ?>