I’m about to pull my hair out. I’ve found exactly where to fix this problem, but I can’t figure out how to code it.
I’m trying to stop pingbacks from pinging my own posts when I link to them. (Yes, I know there’s one plugin that does this. It doesn’t work with Spam Karma, because SK is somehow overriding it to allow any pingbacks from the administrator to go through).
So I was trying to write my own plugin. Here’s what I figured out.
In comment-functions.php, around line 645, WP is loading up all the links in a post that are to get pinged, into an array called $post_links.
On line 656 a hook exists that should allow me to get at this array and modify it. In theory, all I need to do in a plugin is loop over this array, remove any links that link back to my own blog, and then pass the array back to WP.
Take a look at the following URL which explains (though not very well if you ask me) the available hook.
Here’s the code I’ve been playing with. (I’ve tried many different approaches to the code below hoping to stumble upon the right method). It doesn’t work, and I humbly admit that I’m not 100% sure what’s going on.
add_filter('pre_ping', 'stop_self_pingback', 10, 2);
foreach($post_links as $link_test) :
if ( in_array($link_test, 'ocellated.com')
Also, ideally I’d like to pull a variable for my blog URL, instead of hard coding it like I did above (ocellated.com) This would make it useable for everyone.
If someone could just explain how WP is passing the $post_links array (what’s in the array) and how to look over it and remove any iunteral links, I would be so grateful.
- The topic ‘Plugin To Stop Self Pingbacks’ is closed to new replies.