ideasonpurpose / wp-theme-init
A common baseline of repeated functions, filters and actions used across WordPress themes.
Requires (Dev)
- ideasonpurpose/wp-test-stubs: dev-main@dev
- php-stubs/acf-pro-stubs: dev-master
- php-stubs/wordpress-stubs: ^6
- phpunit/phpunit: ^10
- dev-master
- v2.14.5
- v2.14.4
- v2.14.3
- v2.14.2
- 2.14.1
- v2.14.0
- v2.13.2
- v2.13.1
- v2.13.0
- v2.12.0
- v2.11.1
- v2.11.0
- v2.10.1
- v2.10.0
- v2.9.1
- v2.9.0
- v2.8.1
- v2.8.0
- v2.7.3
- v2.7.2
- v2.7.1
- v2.7.0
- v2.6.1
- v2.6.0
- v2.5.5
- v2.5.4
- v2.5.3
- v2.5.2
- v2.5.1
- v2.5.0
- v2.4.2
- 2.4.1
- 2.4.0
- 2.3.1
- 2.3.0
- 2.2.1
- v2.2.0
- v2.0.2
- v1.7.1
- v1.7.0
- v1.5.0
- dev-namespace
This package is auto-updated.
Last update: 2024-11-21 22:41:04 UTC
README
Version: 2.14.5
A common baseline of repeated functions, filters and actions used across our WordPress themes.
Some of what's included:
-
Webpack dependency manifest asset loading
Uses the Dependency Manifest Plugin from ideasonpurpose/docker-build.Scripts will be enqueued using the stylesheet "slug" combined with their entrypoint name.
For example, if the theme directory was
ldco
, the following manifest entry would be enqueued asldco-main
{ "main": { "files": { "main.js": "/wp-content/themes/ldco/dist/main-b4216f6b.js" } } }
Editor assets are enqueued using the appropriate hooks;
enqueue_block_editor_assets
for scripts andenqueue_block_assets
for styles. All scripts are enqueued as ESM by adding thetype="module"
to included script tags. -
Miscellaneous Fixes and Cleanup
- Add a design credit to the WordPress dashboard.
- "Howdy" is removed from the admin menu bar.
- Lots of junk is removed from wp_head. Many optimizations come from the Soil plugin.
- WordPress will attempt to trigger a webpack devServer reload from the
save_post
hook. - Override the
DISALLOW_FILE_EDIT
constant and block access to the Theme File Editor.
-
ShowIncludes A div showing all included theme files will be appended to the page when
WP_DEBUG
is true. To disable it, initialize the class with an array containing:['showIncludes' => false]
-
Template Audit
Adds a Template column to Pages admin and a summary table to the Appearance menu showing which templates have been assigned to pages. -
Record Users' Last Login time User's last successful login are recorded and added to the WordPress Admin User table.
-
Reset Metabox Order & Visibility Adds buttons to the bottom of user profiles which will reset all metabox order and visibility from user_meta.
-
Enable and limit WP_POST_REVISIONS Revisions are set to 6, this overrides any constants set in wp-config.php.
-
Global Comments Disable Comments and Trackbacks are completely disabled. To re-enable comments, initialize the ThemeInit class with an array containing:
['enableComments' => true]
-
Remove jQuery Migrate (optional) Prevent jQuery Migrate from loading by removing it from the list of WordPress dependencies. To remove jquery-migrate, initialize the ThemeInit class with an array containing:
['jQueryMigrate' => false]
-
Admin Separators Admin Separators have been moved to their own library: wp-admin-separators
-
Remove Stale Login Cookies Repeatedly spinning up local dev environments often bloats localhost cookies with stale
wordpress_logged_in
entries. Once these accumulate, the local server will eventually fail with a bad request and the error message "Your browser sent a request that this server could not understand. Size of a request header field exceeds server limit." The cookie can be removed using the browser's dev tools, if the error is recognized -- but it often isn't. Instead, wp-theme-init removes stale login cookies from thewp_login
hook, preventing the issue. This only runs on development environments when WP_DEBUG is set. -
Media Several media related features will be enabled:
- The JPEG Compression value can be set by defining a
JPEG_QUALITY
constant before invokingThemeInit()
. Numeric values will be clamped between 0-100 then passed to the WordPressjpeg_quality
filter.JPEG_QUALITY
defaults to82
. - A high-quality Lanczos scaling filter will be used for scaling images.
- All image uploads will be re-compressed if their filesize can be reduced by at least 75%.
- The JPEG Compression value can be set by defining a
-
Search A few improvements to native WordPress search
- Short-circuit search queries <2 characters long
- Redirect query searches to
/search/
- Workaround leading-dot search failures
-
SEO Framework Tweaks We apply several tweaks to the excellent The SEO Framework plugin:
- Hide the author's name
- Move the metabox to the bottom of admin pages
- Show the default image from the first post in archives
WordPress Integration
Dependency manifest processing is designed to work with the WordPress Dependency Extraction Webpack Plugin. This omits a subset of script libraries included with WordPress, and outputs a PHP snippet for each entry point which includes a dependency list for enqueuing scripts.
The set of WordPress scripts which will be omitted is listed here and includes jquery
, lodash
, moment
, react
and react-dom
as well as all scripts from the @wordpress
namespace.
Development
Run the PHPUnit test suite with: npm run test
Brought to you by IOP
This project is actively developed and used in production at Ideas On Purpose.