• jayp

    (@jayp)


    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.

    http://wphooks.flatearth.org/hooks/pre_ping/

    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);

    function stop_self_pingback($post_links)
    {
    foreach($post_links[0] as $link_test) :
    if ( in_array($link_test, 'ocellated.com')
    unset($post_links[]);
    endif;
    endforeach;

    return $post_links;
    }

    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.

    Thanks.

Viewing 10 replies - 1 through 10 (of 10 total)
  • Thread Starter jayp

    (@jayp)

    It’s so disheartening to spend several hours searching, trying, and isolating exactly where the problem / solution is — all so that I don’t ask a vague question with no supporting details — only to have the post disappear into oblivion without any response.

    If the WordPress support forums aren’t a good place to ask, are there any other places where a person could speak to people who develop plugins and work with WordPress?

    Chris_K

    (@handysolo)

    3 thoughts in no particular order.

    1) To stop self pingbacks, use relative instead of absolute urls to your content (ie /blog/4/9/slug instead of http://mydomain.com/blog/4/9/slug)

    2) Patience here. Volunteers and time constraints. 🙂

    3) Try the WordPress Hackers mailing list: http://codex.wordpress.org/Mailing_Lists#Hackers Some smart folks hang out there that don’t ever wander by here.

    angsuman

    (@angsuman)

    I often found hard-problems are not answered in this forum.
    Anyway this post will help to bump your thread one more time in case someone who can answer missed it.

    Chris_K

    (@handysolo)

    I just posted 3 options…

    altjira

    (@altjira)

    From my blog (Sorry if this comment is bulky, but I think it lays out the entire logic):

    At first I hated the way WordPress sent pingbacks to itself – if I put a link on a new post that referenced back to something I wrote earlier, the pingback registers itself as a comment on the original post, and takes a stab at a relevant quote from the new post to include in the comment. But after browsing the WP Support Forums, trying to figure out a way to turn this function off, I saw it tauted as a feature – the pingback notified the reader that there was more information posted, and I could see the utility in that. So I learned to live with it, stopped deleting the pingback comments, and just checked the quote so that it was no larger than it needed to be and gave a good idea of what the new post was about.

    But it’s still annoying, primarily because of the way my blog and most others are formatted. My main screen, the blog home, shows the last ten posts on the first page, most recent first. As you can see, each post is formatted something like this:

    Date

    Title (which links to a page that shows the post, all its comments, and space to enter yours)
    / – –
    {Body of Post}
    – – /

    Posted by {me} as {List of Categories} at {time}

    {#} Comments (the number of comments and the same link)

    I don’t think that’s a good arrangement, primarily because, in my experience, it takes a lot to get the casual visitor to click any link once they arrive. They are more inclined to just read the post and determine whether it contains the information they came looking for, and if it doesn’t, they leave. They don’t know that the comments might contain a link to a more recent post that has more information – as far as they know, it’s just some drongo saying “so what is the solution to the problem?”, when in actuality it might be a link to the answer they also want.

    I think it’s a better approach to distinguish between when the blog pings itself back and when someone else comments or sends their own pingback or trackback. I’d calling these self-pingbacks “forward links”, and although I have no desire to get into the trackback/pingback standard debate to suggest making forward links identify themselves, I think we can do something with WordPress. I have in mind something that looks like this:

    Date

    Title
    / – –
    {Body of Post}
    – – /

    Posted by {me} as {List of Categories} at {time}

    Updates: (or “Forward Links” or something configurable)
    {Date-time} {Forward Link, showing Title} {Excerpt/Summary?}
    {Date-time} {Forward Link, showing Title}

    {#} Comments (not including forward links)

    or the Forward Link section could look like this, relying purely on the linked post’s title:

    Updates: {Forward Link}, {Forward Link}

    Off the top of my head, I don’t know whether this could be achieved at the plugin or the theme level (probably both), or if it would require a core files hack. Although I think I could figure out how to do it, I just don’t have to time to do so. But it sure would be nice.

    angsuman – “I often found hard-problems are not answered in this forum.”

    You are welcome to assist…………

    BigDog

    (@bigdog)

    I have a hard enough time helping with the easy ones……

    I’ve run up against this problem now… relative URLs are a bad idea, aren’t they? Last I checked, they break in the feed. I switched to absolute paths all across my site, but now I am simply killing myself with self-pingbacks (owing to a dedicated interest in networking all my reviews)… any help?

    “relative URLs are a bad idea, aren’t they? Last I checked, they break in the feed.”

    This is ass-backwards, admittedly, but there is a plugin to fix those broken feeds.

    Here: http://robert.accettura.com/projects/absoluterss

    Crikey! Another plugin. These things stitch my Franken-WP together.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Plugin To Stop Self Pingbacks’ is closed to new replies.