• Resolved urcomm

    (@urcomm)


    We run this snippet of PHP code;

    "require( dirname( __FILE__ ) . '/wp-config.php' ); echo site_url();"

    to determine the site URL of a particular WordPress install on our servers, so we can run the cron tasks out of band. This works great for all WordPress installs except one, which turns out to be a multisite setup.

    According to the Codex, calling ‘network_site_url()’ instead should resolve the problem, but that too returns absolutely nothing for the one multisite setup.

    Set up a clean install and converted it to multisite according to the Codex instructions, to see if the user had somehow changed something, but the exact same problem occurs again; no value for the site URL.

    As far as I can tell, ‘network_site_url()’ should cover both cases? Am I missing something here, going about it the wrong way?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    🏳️‍🌈 Advisor and Activist

    so we can run the cron tasks out of band

    Can you spell that one out? You really should never be calling wp-config.php outside of WP… it’s something we reject code for doing in the plugin repo.

    What you’re trying to do has never worked well on Multisite: http://codex.wordpress.org/Integrating_WordPress_with_Your_Website

    Thread Starter urcomm

    (@urcomm)

    Heh, figures. We actually do it as suggested;

    "require( dirname( __FILE__ ) . '/wp-blog-header.php' ); echo network_site_url();"

    But I ended up experimenting with various things, initializing the whole environment seemed needlessly complex, so the ‘wp-config.php’ was the last thing I tried before starting this thread.

    Anyway, what we’re trying to do is have a reliable way to detect the site URL for any given WordPress install on our servers, whether they’re in the root of a domain, any subdirectory, or on subdomains where the user has selected a different path for their DocumentRoot. Basically, it should yield a simple URL string we can tack ‘/wp-cron.php…’ onto, without putting our own code in the customer’s directory. The URL is then called by a shell script.

    As I read the Codex, ‘network_site_url()’ should cover the multisite use case, but it looks like that fails. Is there a better way to do this, preferably without needing to query the database directly?

    Thread Starter urcomm

    (@urcomm)

    It looks like WP-CLI (http://wp-cli.org) does what we want, and a lot more besides, for both normal and multisite installs, so we’ll use that 🙂

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    🏳️‍🌈 Advisor and Activist

    Please re-read that page I linked you to. Specifically the second paragraph:

    These directions will not work on a MultiSite Network.

    Yeah, we know. And because it’s really not the way you should do things, it’s okay by us. 🙂

    And the reason it ‘works’ on WP-CLI is because it’s actually running WP to get that for you 🙂

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

The topic ‘network_site_url() broken in 4.0.1?’ is closed to new replies.