Refactor theme structure and update to use rtcamp/framework#689
Refactor theme structure and update to use rtcamp/framework#689pratik-londhe4 wants to merge 20 commits into
Conversation
…ettings registration
There was a problem hiding this comment.
Pull request overview
Migrates theme-elementary from a vendored in-repo framework (inc/Framework/) to the upstream rtcamp/wp-framework Composer dependency, and updates theme bootstrapping/services/docs to align with the framework’s Singleton/Loader/Registrable patterns.
Changes:
- Replace the local framework layer with
rtcamp/wp-frameworkvia Composer and update theme bootstrap/autoloading to use upstream traits/contracts. - Refactor theme services to be loaded through the framework
Loader(assets, block extension, and a new example settings page). - Update documentation and housekeeping (PSR-4 helpers class, README/DEVELOPMENT.md rewrites, workflow adjustments).
Reviewed changes
Copilot reviewed 16 out of 17 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| README.md | Updates structural docs to reflect vendor/rtcamp/wp-framework + inc/ layout. |
| phpstan-baseline.neon | Adds a new suppression for a PHPStan always-true boolean warning. |
| inc/Modules/Settings/ThemeOptions.php | Introduces a declarative settings page built on the framework’s AbstractSettingsPage. |
| inc/Modules/BlockExtensions/MediaTextInteractive.php | Converts to Registrable and renames hook wiring to register_hooks(). |
| inc/Main.php | Switches to framework Singleton + Loader and loads services via $this->load([...]). |
| inc/Helpers/Util.php | Replaces empty global helpers file with a PSR-4 static utility class placeholder. |
| inc/helpers/custom-functions.php | Removes the old non-namespaced (empty) helpers file. |
| inc/Framework/Traits/Singleton.php | Removes local framework singleton trait (now provided by dependency). |
| inc/Framework/Traits/AutoloaderTrait.php | Removes local autoloader trait (now provided by dependency). |
| inc/Framework/Traits/AssetLoaderTrait.php | Removes local asset loader trait (now provided by dependency). |
| inc/Framework/README.md | Removes framework-layer documentation (now replaced by DEVELOPMENT.md guidance). |
| inc/Core/Assets.php | Converts assets service to Registrable and swaps to framework AssetLoaderTrait. |
| inc/Autoloader.php | Switches to framework AutoloaderTrait and points at dependency location. |
| DEVELOPMENT.md | Rewrites dev docs to match the new vendor/framework boundary and module patterns. |
| composer.lock | Locks rtcamp/wp-framework and updates dependency graph accordingly. |
| composer.json | Adds VCS repo + requires rtcamp/wp-framework, removes autoload.files. |
| .github/workflows/test-measure.yml | Adjusts PHP lint job for VCS installs; removes the PHP unit test job. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| - name: Summarize skipped jobs | ||
| run: | | ||
| SKIPPED=() | ||
|
|
||
| [[ "${{ steps.determine-file-counts.outputs.css-count }}" -le 0 ]] && SKIPPED+=("lint-css") | ||
| [[ "${{ steps.determine-file-counts.outputs.js-count }}" -le 0 ]] && SKIPPED+=("lint-js" "unit-tests-js" "build-prod") | ||
| [[ "${{ steps.determine-file-counts.outputs.php-count }}" -le 0 ]] && SKIPPED+=("lint-php" "unit-test-php") | ||
| [[ "${{ steps.determine-file-counts.outputs.php-count }}" -le 0 ]] && SKIPPED+=("lint-php") | ||
|
|
| $this->setup_hooks(); | ||
| public function __construct() { | ||
| $this->plugin_dir = ELEMENTARY_THEME_TEMP_DIR . '/'; | ||
| $this->plugin_url = trailingslashit( get_template_directory_uri() ) . '/'; |
There was a problem hiding this comment.
Double trailing slash in plugin_url. trailingslashit() already appends a /, then you concatenate another '/'. This produces URLs like https://example.com/wp-content/themes/elementary//assets/build/... which, while browsers tolerate, can break string comparisons and caching.
| $this->plugin_url = trailingslashit( get_template_directory_uri() ) . '/'; | |
| $this->plugin_url = trailingslashit( get_template_directory_uri() ); |
| // Setup hooks. | ||
| $this->setup_hooks(); | ||
| public function __construct() { | ||
| $this->plugin_dir = ELEMENTARY_THEME_TEMP_DIR . '/'; |
There was a problem hiding this comment.
Redundant trailing slash on plugin_dir. ELEMENTARY_THEME_TEMP_DIR likely already ends without a slash, but appending '/' here while AssetLoaderTrait may also add one could cause double-slash issues in file paths. Consider using trailingslashit() for consistency, or verify the trait's expectations.
|
|
||
| if ( ! trait_exists( 'rtCamp\Theme\Elementary\Framework\Traits\AutoloaderTrait' ) ) { | ||
| require_once ELEMENTARY_THEME_TEMP_DIR . '/inc/Framework/Traits/AutoloaderTrait.php'; | ||
| if ( ! trait_exists( 'rtCamp\WPFramework\AutoloaderTrait' ) ) { |
There was a problem hiding this comment.
Manual require_once before Composer autoload defeats the purpose. If vendor/autoload.php hasn't been loaded yet (which is the whole point of this class), the trait_exists check will always be false, and you'll always hit the require_once. This hardcodes the framework's internal file path (inc/AutoloaderTrait.php), which could break if the framework restructures.
There was a problem hiding this comment.
fixed this in upstream and updated the theme and plugin
| * Derives the register_setting() args from get_fields() by stripping | ||
| * the UI-only keys. | ||
| */ | ||
| protected function get_settings(): array { |
There was a problem hiding this comment.
Missing return type annotation in PHPDoc. The get_settings() method returns array but lacks a @return PHPDoc with the array shape. While native types are declared, the array structure documentation would help consumers understand the expected format.
| // Setup hooks. | ||
| $this->setup_hooks(); | ||
| public function __construct() { | ||
| $this->plugin_dir = ELEMENTARY_THEME_TEMP_DIR . '/'; |
There was a problem hiding this comment.
Also can we fix this here, the name ELEMENTARY_THEME_TEMP_DIR sounds like a temporary name
Conflicts: DEVELOPMENT.md inc/Core/Assets.php
Description
Migrates
theme-elementaryoff its copy of the framework and onto the upstreamrtcamp/wp-frameworkComposer package.Also folds in a few stale-doc / stale-code follow-ons that were left over from the migration: converts the now-empty
inc/helpers/custom-functions.phpto a PSR-4Helpers\Utilstatic class, drops the Composerfilesautoload entry, and rewritesDEVELOPMENT.md(which still describedinc/Framework/as a real subdirectory).Technical Details
type: vcsrepository entry pointing atgithub.com/rtCamp/wp-framework.gitandrequire rtcamp/wp-framework: dev-frameworktocomposer.json. Dropped the legacyfilesautoload block — the whole theme is now PSR-4 with no special cases.inc/Framework/deleted in its entirety. The local copy only hadAutoloaderTrait,AssetLoaderTrait, andSingleton; the missing pieces (Loader,Container,Registrable,Shareable) now come from the package along with the abstracts.inc/Autoloader.phpusesrtCamp\WPFramework\AutoloaderTrait(the package's graceful-failure wrapper aroundvendor/autoload.php).inc/Main.phpuses the packageSingleton+Loadertraits and loads the theme's services via$this->load( [ Assets::class, MediaTextInteractive::class, ThemeOptions::class ] ). Noget_instance()anywhere except onMainitself.Core\AssetsimplementsRegistrableand uses the frameworkAssetLoaderTrait.Modules\BlockExtensions\MediaTextInteractiveimplementsRegistrable(previously aget_instance()singleton — now plain).Modules\Settings\ThemeOptionsextendsAbstractSettingsPage. Uses a declarativeget_fields()pattern with auto-generated Settings API sections + a genericrender_field()so adding another option is a one-entry change.use/ namespace reference re-pointed fromrtCamp\Theme\Elementary\Framework\…tortCamp\WPFramework\….inc/helpers/custom-functions.php→inc/Helpers/Util.php. The old file was empty (placeholder comment only). Replaced with afinalstatic class (private __construct()) mirroring the plugin'sHelpers\Utilpattern — ready to host theme-wide helpers without growing the global function table or relying on thefilesautoload directive.DEVELOPMENT.mdrewritten. The previous version still described aninc/Framework/subdirectory and a "two-layer model" rooted in it. New content reframes the layers aroundvendor/rtcamp/wp-framework/vsinc/, lists the actual on-disk PSR-4 reference table, documents theHelpers/convention, and adds a "Picking a base" table mapping feature types to the package's abstracts/interfaces.Checklist
Acceptance criteria from the issue:
theme-elementaryboots without fatal (fixes the broken hand-edit state)get_instance()calls remain except the bootstrap class (Main::get_instance()infunctions.php)inc/Framework/directory deletedgrep -rn "inc/Framework\|\\Framework\\" inc/returns nothing)requireincludesrtcamp/wp-framework+type: vcsrepository entry pointing at the framework repoinc/Autoloader.phpuses the package'sAutoloaderTraitMainkeepsuse Singleton; use Loader;— every other former singleton became a plainRegistrableThemeOptions→AbstractSettingsPage)Out-of-ticket cleanup landed alongside the migration:
inc/helpers/custom-functions.php(empty) converted to PSR-4Helpers\Utilstatic class;filesautoload entry removedDEVELOPMENT.mdrewritten to drop staleinc/Framework/references and document the current architectureFixes/Covers issue
Fixes #
https://github.com/rtCamp/wp-framework/issues/26