How to change domain used when pinging sites

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.

Read More

Thanks!

Related posts

Leave a Reply

1 comment

  1. 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');