Extending a custom framework built into WordPress to automatically turn the ‘Search Engine Visibility’ setting ON / OFF, dependant on environment

Those “definable settings” are constants. WordPress defines its default constants in this file. If a constant definition is wrapped in a defined() check, like this:

if ( ! defined( 'WP_DEBUG_DISPLAY' ) ) {
    define( 'WP_DEBUG_DISPLAY', true );
}

Then it means you can define it first in the wp-config.php file (or, apparently, this framework’s config files).

The “Search engine visibility” setting does not have a constant you can define from wp-config.php. It’s a setting that’s saved in the database. You can filter the results of checks to this setting like this:

add_filter( 'option_blog_public', '__return_false' );

This would likely not work in these config files though, as the add_filter() function will not be defined yet.

There’s no reason that a framework could not use a companion plugin to allow you to define this with a constant, but whether nor not that is possible is something you will need to as the framework author.

For a bonus point, do I need to define ‘use Roots\WPConfig\Config’
twice; once in the root config and again in the .env specific files?

Yes, you do. use statements are per-file.


To address your update:

I have located this set up in the framework:

if (defined('WP_ENV') && WP_ENV !== 'production' && !is_admin()) {
    add_action('pre_option_blog_public', '__return_zero');
}


Am I right in thinking I just need to adjust the existing code for the first line provided…

No, your suggestion is not correct. Or, at least there’s a much better way.

The add_action() in your edit is, for all intents and purposes, the same as what I gave you. The important part is that the framework will apply this for you if WP_ENV is not 'production'.

I found this in the documentation of your framework: https://roots.io/docs/bedrock/master/environment-variables/#wp-env