WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Intercepting the New "home" and "siteurl" bloginfo (8 posts)

  1. cmarshall
    Member
    Posted 7 years ago #

    In the old WP, I could run it on a local server quite easily, as the server URI was consistent. However, WP 2+ now has a couple of new options that scrag that.

    I need to be able to intercept the bloginfo('home') and bloginfo('siteurl') to spit out a modified URI (I use a Mac with Parallels for testing, and the URI becomes a local IP). This also prevents me from just wholesale copying the WP databases for my local work.

    Adding a filter for bloginfo doesn't work, as WP just goes and executes the regular one afterwards anyway, which makes a real mess.

    Even better, is there a way for my theme to intercept get_bloginfo()?

  2. peiqinglong
    Member
    Posted 7 years ago #

    <?php bloginfo('stylesheet_directoy'); ?> doesn't work?

  3. cmarshall
    Member
    Posted 7 years ago #

    I'm not sure I understand.

    I need to intercept it so that the "native" WP code uses my reassignments.

    I don't want to do any hacking at all in the native code (I could quite easily do it by messing with the main function). I want to overload the main function, so that it returns localized versions of the URI, if I am running it on my laptop (localhost) or I'm accessing the laptop version from a Parallels VM (10.211.50.2).

    I know that get_bloginfo('home') and/or get_bloginfo('siteurl') are called from within the code, because I see my pages getting really screwed up in the Location Bar, and everything goes pear-shaped.

  4. macbis
    Member
    Posted 7 years ago #

    Are you using the 'bloginfo_url' filter?

    Blog Information and Option Filters

  5. cmarshall
    Member
    Posted 7 years ago #

    That looks like what I need. Let me experiment...

    Thanks!

  6. cmarshall
    Member
    Posted 7 years ago #

    option_home and option_siteurl give me what I need, but the E3Calendar plugin is doing some whacky stuff that I'll have to dissect...

  7. cmarshall
    Member
    Posted 7 years ago #

    Okay, that went pear-shaped. WP completely ignores this:

    <?php
    /*
    Plugin Name: localhosts
    Plugin URI: http://sasna.org/
    Description: Makes things local, for testing.
    Version: 1.0
    */
    function GetMainURI( $ret )
        {
        if ( preg_match ( '|10\.211\.55\.2|', $_SERVER['REQUEST_URI'] ) )
            {
            $ret = "http://10.211.55.2/.../public_html/main";
            }
        elseif ( preg_match ( '|127\.0\.0\.1|', $_SERVER['REQUEST_URI'] ) || preg_match ( '|localhost|', $_SERVER['REQUEST_URI'] ) )
            {
            $ret = "http://localhost/.../public_html/main";
            }
        return $ret;
        }
    
    add_filter ( 'option_home', 'GetMainURI' );
    add_filter ( 'option_siteurl', 'GetMainURI' );
    ?>

    The plugin is installed and activated (I redacted the interiors of the URIs).

    Obviously, "add_filter('option_xxx" isn't working. Either I misread the docs, or I'm just thick. I can't find examples of this particular capability no matter how hard I Google...

  8. cmarshall
    Member
    Posted 7 years ago #

Topic Closed

This topic has been closed to new replies.

About this Topic