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

I have a WordPress framework that I am currently working in, it is a thing of beauty, however it is not what I am used to. I am attempting to extend this framework to automatically turn the toggle (found here: Dashboard -> Settings -> Reading -> Search engine visibility) ON or OFF dependant on the environment (Local / Develop / Staging / Live).

I have .env files set up that contain different parts of the settings for that environment, and that environment only. These .env files are called in after there are base settings made to the config.

An example is like so:

<?php
use RootsWPConfigConfig;

/**
 * Debugging Settings
 */
Config::define('WP_DEBUG_DISPLAY', false);
Config::define('WP_DEBUG_LOG', env('WP_DEBUG_LOG') ?? false);
Config::define('SCRIPT_DEBUG', false);
ini_set('display_errors', '0');

/**
 * Pull in relevant .env file
 */
Code to pull in .env file.

Then within an .env file we are looking like this:

<?php
/**
 * Configuration overrides for WP_ENV === 'local'
 */

use RootsWPConfigConfig;

Config::define('SAVEQUERIES', true);
Config::define('WP_DEBUG', true);
Config::define('WP_DEBUG_DISPLAY', true);
Config::define('WP_DISABLE_FATAL_ERROR_HANDLER', true);
Config::define('SCRIPT_DEBUG', true);

ini_set('display_errors', '1');

// Enable plugin and theme updates and installation from the admin
Config::define('DISALLOW_FILE_MODS', false);

Its clever, however, now we know how this is happening, I am trying to add in a line that will update the Search engine visibility toggle (found here: Dashboard -> Settings -> Reading -> Search engine visibility).

Can anyone point me towards a complete list of these definable settings (such as define(‘WP_DEBUG’, true)), specifically the Search engine visibility toggle?

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

Any information would be greatly appreciated, happy coding.

EDIT: Following on from Sir Peattie’s advice.

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');
} 

If I then try track ‘pre_option_blog_public’ elsewhere, it leads nowhere. However, there is results for:

add_action( 'update_option_blog_public', 'update_blog_public', 10, 2 );

And also:

add_action( 'update_blog_public', 'wp_update_blog_public_option_on_site_update', 1, 2 );

Which leads me towards:

/**
 * Update this blog's 'public' setting in the global blogs table.
 *
 * Public blogs have a setting of 1, private blogs are 0.
 *
 * @since MU (3.0.0)
 *
 * @param int $old_value
 * @param int $value     The new public value
 */
function update_blog_public( $old_value, $value ) {
    update_blog_status( get_current_blog_id(), 'public', (int) $value );
}

This:

if ( $new_site->public != $old_site->public ) {

    /**
     * Fires after the current blog's 'public' setting is updated.
     *
     * @since MU (3.0.0)
     *
     * @param int    $site_id Site ID.
     * @param string $value   The value of the site status.
     */
    do_action( 'update_blog_public', $site_id, $new_site->public );
}

And lastly this:

/**
 * Updates the `blog_public` option for a given site ID.
 *
 * @since 5.1.0
 *
 * @param int    $site_id Site ID.
 * @param string $public  The value of the site status.
 */
function wp_update_blog_public_option_on_site_update( $site_id, $public ) {

    // Bail if the site's database tables do not exist (yet).
    if ( ! wp_is_site_initialized( $site_id ) ) {
        return;
    }

    update_blog_option( $site_id, 'blog_public', $public );
}

Am I right in thinking I just need to adjust the existing code for the first line provided in this edit, to not use:

add_action('pre_option_blog_public', '__return_zero');

But instead the line you graciously provided earlier:

add_filter( 'option_blog_public', '__return_false' );

Thoughts?

$299 Affordable Web Design WordPress

This article was republished from its original source.
Call Us: 1(800)730-2416

Pixeldust is a 20-year-old web development agency specializing in Drupal and WordPress and working with clients all over the country. With our best in class capabilities, we work with small businesses and fortune 500 companies alike. Give us a call at 1(800)730-2416 and let’s talk about your project.

FREE Drupal SEO Audit

Test your site below to see which issues need to be fixed. We will fix them and optimize your Drupal site 100% for Google and Bing. (Allow 30-60 seconds to gather data.)

Powered by

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

On-Site Drupal SEO Master Setup

We make sure your site is 100% optimized (and stays that way) for the best SEO results.

With Pixeldust On-site (or On-page) SEO we make changes to your site’s structure and performance to make it easier for search engines to see and understand your site’s content. Search engines use algorithms to rank sites by degrees of relevance. Our on-site optimization ensures your site is configured to provide information in a way that meets Google and Bing standards for optimal indexing.

This service includes:

  • Pathauto install and configuration for SEO-friendly URLs.
  • Meta Tags install and configuration with dynamic tokens for meta titles and descriptions for all content types.
  • Install and fix all issues on the SEO checklist module.
  • Install and configure XML sitemap module and submit sitemaps.
  • Install and configure Google Analytics Module.
  • Install and configure Yoast.
  • Install and configure the Advanced Aggregation module to improve performance by minifying and merging CSS and JS.
  • Install and configure Schema.org Metatag.
  • Configure robots.txt.
  • Google Search Console setup snd configuration.
  • Find & Fix H1 tags.
  • Find and fix duplicate/missing meta descriptions.
  • Find and fix duplicate title tags.
  • Improve title, meta tags, and site descriptions.
  • Optimize images for better search engine optimization. Automate where possible.
  • Find and fix the missing alt and title tag for all images. Automate where possible.
  • The project takes 1 week to complete.