• I’m trying to use update_blog_public() to force a site to be public or private.

    Since I cannot use it in wp-config I put
    define('blog_public', '0' ); in wp-config
    and this snippet in mu-plugins:

    add_action( 'shutdown', 'MyInit');
    function MyInit() {
    	if (defined('blog_public')) {
    		if (constant('blog_public')=='0') {
    			update_blog_public( $old_value, false );
    		}
    		if (constant('blog_public')=='1') {
    			update_blog_public( $old_value, true );
    		}
    	}
    }

    It is surely runned (I can do fatals) but it doesn’t work.

    I chose ‘shutdown’ because most of earlier hooks like ‘wp_loaded’ get me

    Call to undefined function update_blog_public()

    .

    Is there something wickedly evil that I’m tring to do or is it just a minor bug?

    My aim is to define whether a wordpress installation is public or private directly in the wp-config, so to be sure that productions are public and developments are private.

    Thank you

Viewing 3 replies - 1 through 3 (of 3 total)
  • Try this:

    add_action( 'wp_loaded', 'thissite_blog_public' );
    function thissite_blog_public() {
    	if (get_option('blog_public') == "0") {
    		add_filter( 'pre_option_blog_public', '__return_true' );
    	}
    }
    Thread Starter Cyberchicken

    (@cyberchicken)

    What the heck, it works! Thank you!
    Option looks OFF whatever I try to save. This alone could be a saver.
    I’ll need some explanation, but first I will connect it to my constant in the wp-config and make some tests.
    I will post back asap.

    Thread Starter Cyberchicken

    (@cyberchicken)

    Ok, a bit of refinement:
    in wp-config.php
    define('blog_public', '1' ); // option "discourage search engines" '0': checked true, '1': unchecked empty

    in mu-plugins/config_blog_public.php

    add_action( 'wp_loaded', 'config_blog_public' );
    function config_blog_public() {
    	if (defined('blog_public')) {
    		if (constant('blog_public')=='0') {
    	 		add_filter( 'pre_option_blog_public', '__return_false' );
    		}
    		if (constant('blog_public')=='1') {
     			add_filter( 'pre_option_blog_public', '__return_true' );
    		}
    	}
    }

    Now the “discourage” option is basically dead: whatever I check this plugin overrides it. I should find the way to “grey out” the option and add an explanation. (Any suggestion about where to look? 🙂

    Note that if I don’t set the constant to ‘0’ or ‘1’ strings the behaviour is normal.
    PS It really works: I can see <meta name="robots" content="noindex,follow"/> appear and disappear just by changing the option in wp-config.php

    With a bit of more work I could release this as a complete reusable plugin.

    Thank you!

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘mu-plugins and options override’ is closed to new replies.