• Resolved cmarshall

    (@cmarshall)


    For some reason, the posting went nuts, so you are graced with three copies of an empty post.

    Here’s what I was trying to say:


    My last query got demoted from a support question (probably because it deserved to be).

    I got some good feedback, but now I am stuck.

    I normally look for example code to shine a cluelight upon my moronity, but there seems to be a dearth of examples for this.

    I wrote a plugin, as recommended, and set up a filter, as recommended, but the filter function is never called, which leads me to believe that there is some problem with the way I set it up. I can’t see the forest for the trees. This is as simple a plugin as it gets, yet it doesn’t work.

    Any ideas?

    The Code:

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

    (@cmarshall)

    Okay, I got it working.

    I remember someone once saying that filter/hook function names should always be lowercase, so that’s what I did, and now it works just ducky.

    This could be a useful function for people who like to have test laptops with all kinds of virtual systems (like I do), so I’ll share my very simple patcher. You will need to add your own local URIs:

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

    (@cmarshall)

    REALLY ANNOYING FOLLOW-UP:
    This won’t work for admin. Admin re-loads straight from the DB, so it can’t be patched. Probably more secure, but it means that you need to hack the core to use admin on local machines without going in and changing the database.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Sorry-WP Went Whacky. I Need Examples of Using the “option_xxx” Filter.’ is closed to new replies.