Code structure
Principle
Section titled “Principle”The theme renders. A must-use plugin enforces environment rules and keeps the theme active. A call into a plugin checks that the plugin is loaded.
The theme registers supports, styles, blocks, and patterns. It does not decide whether the site is production.
One file in wp-content/mu-plugins/ does four things:
- Switches to the theme after setup, when it is not already active.
- Forces
blog_publicto0off production, by filteringoption_blog_public. The stored option is0as well. The filter covers reads. The stored value covers anything that ignores the filter. - Answers
/robots.txt:Disallow: /off production,Allow: /on production. - Stops mail off production. A non-null return from
pre_wp_mailshort-circuitswp_mail. PHPMailer recipients are cleared as well, for anything that sends mail withoutwp_mail.
add_filter( 'pre_wp_mail', static function ( $short_circuit ) { if ( wp_get_environment_type() === 'production' ) { return $short_circuit; } return false;} );wp_get_environment_type() reads WP_ENVIRONMENT_TYPE. That value is set in the environment. PHP does not branch on the hostname.
Functions and globals use the theme slug as a prefix (acme_) so they do not collide with plugins.
A linter that needs to see concatenated class strings gets them through one helper that returns the string unchanged. The helper is not a styling system.