Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Without boring you with the details of "why" to keep a long story short, I need to change the domain that my site uses when it sends pings. I went and searched the WP source for where this gets set, and I see the domain is set in weblog_ping() in wp-includes/comment.php. Unfortunately this has no filters or actions, so no dice. It does use home_url() which ultimately has a filter, but I only want to filter it when it's being called for use in a ping. Anyone have any thoughts on how I might accomplish that?

... And as I was about to hit post, I had an idea of how I might do this. I'll post it as an answer, but I'd still love to hear what others have to suggest.

Thanks!

share|improve this question

1 Answer 1

up vote 2 down vote accepted

Here's what I came up with to accomplish this. I'm not naive enough to think this is the best way, but it works. Again, still interested to know if others have any better ideas. Ultimately, the reason why I needed to do this was because I use the domain mapping plugin, and I have it set to redirect admin requests to the original domain (the multisite subdomain). Now WordPress pings with the mapped domain and not e.g. child.parent.com

function ping_domain_map($home_url) {
    if (strpos($_SERVER['REQUEST_URI'], 'wp-cron.php') && strpos(print_r(debug_backtrace(),1), 'weblog_ping') ) {
        if ( !function_exists( 'domain_mapping_siteurl' ) )
            return $home_url;

        $mapped_url = domain_mapping_siteurl( false );
        if ( !$mapped_url )
            return $home_url;
        else
            return preg_replace('#^.*?//[^/]+#', $mapped_url, $home_url);
    }
    return $home_url;
}
add_filter( 'home_url', 'ping_domain_map');
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.