From 4fade6d93017dfe056d5bf2808385f86160ee994 Mon Sep 17 00:00:00 2001 From: KJ Roelke Date: Sat, 11 Apr 2026 14:16:16 -0500 Subject: [PATCH 1/2] swap to autoloading --- .vscode/settings.json | 6 +- CHANGELOG.md | 5 ++ composer.json | 5 ++ functions.php | 12 +++- inc/plugins/acf/class-acf-handler.php | 4 +- inc/theme/class-gutenberg-handler.php | 4 +- inc/theme/class-rest-router.php | 2 +- inc/theme/class-theme-init.php | 23 ++----- inc/theme/class-utils-loader.php | 80 ------------------------ inc/theme/navwalkers/class-navwalker.php | 4 +- style.css | 2 +- 11 files changed, 37 insertions(+), 110 deletions(-) delete mode 100644 inc/theme/class-utils-loader.php diff --git a/.vscode/settings.json b/.vscode/settings.json index 15f9023..9c78e74 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -39,9 +39,11 @@ "alignfull", "alignwide", "atts", + "autoloading", "azvr", "bloginfo", "choctawnationofoklahoma", + "classmap", "cpts", "Linktree", "macrosbysara", @@ -70,6 +72,6 @@ "html.format.templating": true, "phpSniffer.standard": "phpcs.xml.dist", "scss.format.spaceAroundSelectorSeparator": true, - "stylelint.snippet": [ "css", "scss" ], - "stylelint.validate": [ "css", "scss" ] + "stylelint.snippet": ["css", "scss"], + "stylelint.validate": ["css", "scss"] } diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d49834..39580f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## 3.0.0 - [April 11, 2026] + +- Breaking: Swap to autoloading classes +- Added: PMPro handler + ## 2.2.0 - [March 28, 2026] - Added: New Consistency Club Post Type & Taxonomies diff --git a/composer.json b/composer.json index 42097d1..c809347 100644 --- a/composer.json +++ b/composer.json @@ -2,6 +2,11 @@ "name": "macros-by-sara/wordpress-theme", "description": "a custom wordpress theme", "type": "project", + "autoload": { + "classmap": [ + "inc/" + ] + }, "repositories": [ { "type": "composer", diff --git a/functions.php b/functions.php index d167685..e4104be 100644 --- a/functions.php +++ b/functions.php @@ -5,7 +5,13 @@ * @package MacrosBySara */ -use MacrosBySara\Theme_Init; +use MacrosBySara\Theme\Theme_Init; -require_once get_stylesheet_directory() . '/inc/theme/class-theme-init.php'; -new Theme_Init(); +$autoloader = get_stylesheet_directory() . '/vendor/autoload.php'; +if ( file_exists( $autoloader ) ) { + require_once $autoloader; +} else { + wp_die( 'Autoloader not found. Please run composer install.' ); +} +$theme = new Theme_Init(); +add_action( 'after_setup_theme', array( $theme, 'bootstrap_theme' ) ); \ No newline at end of file diff --git a/inc/plugins/acf/class-acf-handler.php b/inc/plugins/acf/class-acf-handler.php index 9a6198d..1fa7286 100644 --- a/inc/plugins/acf/class-acf-handler.php +++ b/inc/plugins/acf/class-acf-handler.php @@ -7,7 +7,7 @@ * @package MacrosBySara */ -namespace MacrosBySara; +namespace MacrosBySara\Plugins; /** * ACF_Handler Class @@ -82,4 +82,4 @@ public function load_json_paths( array $paths ): array { $paths = array_map( fn( $dir ) => $this->base_path . $dir, array_values( $this->paths_array ) ); return $paths; } -} +} \ No newline at end of file diff --git a/inc/theme/class-gutenberg-handler.php b/inc/theme/class-gutenberg-handler.php index 0e47faf..f87f144 100644 --- a/inc/theme/class-gutenberg-handler.php +++ b/inc/theme/class-gutenberg-handler.php @@ -7,7 +7,7 @@ * @package MacrosBySara */ -namespace MacrosBySara; +namespace MacrosBySara\Theme; /** * Gutenberg Handler @@ -80,4 +80,4 @@ public function register_theme_blocks() { $blocks_path = get_template_directory() . '/build'; wp_register_block_types_from_metadata_collection( $blocks_path . '/js/blocks', $blocks_path . '/blocks-manifest.php' ); } -} \ No newline at end of file +} diff --git a/inc/theme/class-rest-router.php b/inc/theme/class-rest-router.php index 01a0629..56dfc29 100644 --- a/inc/theme/class-rest-router.php +++ b/inc/theme/class-rest-router.php @@ -5,7 +5,7 @@ * @package MacrosBySara */ -namespace MacrosBySara; +namespace MacrosBySara\Theme; use WP_REST_Controller; use WP_REST_Request; diff --git a/inc/theme/class-theme-init.php b/inc/theme/class-theme-init.php index 4cab468..0fc16f7 100644 --- a/inc/theme/class-theme-init.php +++ b/inc/theme/class-theme-init.php @@ -7,28 +7,18 @@ * @package MacrosBySara */ -namespace MacrosBySara; +namespace MacrosBySara\Theme; /** * Class: Theme Init */ class Theme_Init { /** - * Utils Loader - * - * @var Utils_Loader $loader + * Bootstrap the theme by setting up supports and disabling comments. */ - private Utils_Loader $loader; - - /** - * Constructor - */ - public function __construct() { - require_once get_stylesheet_directory() . '/inc/theme/class-utils-loader.php'; - $this->loader = new Utils_Loader(); - $this->loader->load_files(); + public function bootstrap_theme() { $this->disable_discussion(); - add_action( 'after_setup_theme', array( $this, 'configure_theme_support' ) ); + $this->configure_theme_support(); add_action( 'init', array( $this, 'alter_post_types' ) ); add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); add_filter( 'wp_speculation_rules_configuration', array( $this, 'handle_speculative_loading' ) ); @@ -91,7 +81,6 @@ public function alter_post_types() { ); } - /** * Enqueue scripts and styles. */ @@ -107,7 +96,7 @@ public function enqueue_scripts(): void { ), ); foreach ( $files as $handle => $paths ) { - $assets = require_once get_stylesheet_directory() . "/build/{$paths['js']}.asset.php"; + $assets = require get_stylesheet_directory() . "/build/{$paths['js']}.asset.php"; $deps = $assets['dependencies']; if ( 'bootstrap' !== $handle ) { @@ -143,4 +132,4 @@ public function handle_speculative_loading( $config ) { } return $config; } -} +} \ No newline at end of file diff --git a/inc/theme/class-utils-loader.php b/inc/theme/class-utils-loader.php deleted file mode 100644 index d8d3628..0000000 --- a/inc/theme/class-utils-loader.php +++ /dev/null @@ -1,80 +0,0 @@ -base_path = get_stylesheet_directory() . '/inc'; - } - - /** - * Load Required Files - */ - public function load_files() { - - // Require Navwalker - require_once $this->base_path . '/theme/navwalkers/class-navwalker.php'; - - // Theme Utils - $theme_files = array( - 'gutenberg-handler' => 'Gutenberg_Handler', - 'rest-router' => 'Rest_Router', - ); - $this->load_utils( '/theme', $theme_files ); - $this->load_acf_utils(); - } - - /** - * Load Utils - * - * @param string $path Path to utils. - * @param array $files Array of files to load. - */ - private function load_utils( string $path, array $files ) { - foreach ( $files as $file => $class ) { - require_once $this->base_path . "{$path}/class-{$file}.php"; - if ( $class ) { - $class = __NAMESPACE__ . "\\{$class}"; - new $class(); - } - } - } - - /** - * Load ACF Utils - */ - private function load_acf_utils() { - $plugin_files = array( - 'acf-handler' => array( - 'class' => 'ACF_Handler', - 'dir' => 'acf', - ), - ); - foreach ( $plugin_files as $file => $data ) { - require_once $this->base_path . "/plugins/{$data['dir']}/class-{$file}.php"; - if ( $data['class'] ) { - $class = __NAMESPACE__ . "\\{$data['class']}"; - new $class(); - - } - } - } -} diff --git a/inc/theme/navwalkers/class-navwalker.php b/inc/theme/navwalkers/class-navwalker.php index 1809e3c..9d3dff2 100644 --- a/inc/theme/navwalkers/class-navwalker.php +++ b/inc/theme/navwalkers/class-navwalker.php @@ -16,7 +16,7 @@ * @package MacrosBySara */ -namespace MacrosBySara; +namespace MacrosBySara\Theme\Navwalkers; use stdClass; use Walker_Nav_Menu; @@ -242,4 +242,4 @@ protected function get_the_attributes(): string { $attributes['class'] .= ' nav-link'; return $this->build_atts( $attributes ); } -} +} \ No newline at end of file diff --git a/style.css b/style.css index 0b23219..bf8e7dd 100644 --- a/style.css +++ b/style.css @@ -4,7 +4,7 @@ Theme URI: https://github.com/macrosbysara/wordpress-theme Author: KJ Roelke Author URI: https://kjroelke.online Description: A WordPress Theme built for Macros By Sara site -Version: 2.2.0 +Version: 3.0.0 Requires at least: 6.7.0 Tested up to: 6.9.4 Requires PHP: 8.2 From 6a3b8c42f4eb28eca1ab3e970b27dfecff789bf9 Mon Sep 17 00:00:00 2001 From: KJ Roelke Date: Sat, 11 Apr 2026 14:30:44 -0500 Subject: [PATCH 2/2] update deploy and package files list --- .github/workflows/deploy.yml | 2 ++ package.json | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index fe8a69b..b00ff77 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -16,6 +16,7 @@ jobs: REMOTE: "macrosbysara.com" # Remote folder to deploy to theme_name: "macros-by-sara" flags: "-azr --delete" + with_autoload: true secrets: inherit deploy-stg: @@ -26,4 +27,5 @@ jobs: REMOTE: staging6.macrosbysara.com theme_name: "macros-by-sara" flags: "-azvr --delete" + with_autoload: true secrets: inherit diff --git a/package.json b/package.json index 41a8a5b..eff1782 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "macros-by-sara-wp-theme", - "version": "2.0.2", + "version": "2.1.0", "description": "A WordPress theme for Macros By Sara", "homepage": "https://github.com/macrosbysara/wordpress-theme#readme", "bugs": { @@ -29,6 +29,7 @@ "assets/", "build/", "inc/", + "vendor/", "parts/", "patterns/", "templates/",