Support » Requests and Feedback » Pointers for new plugin writer

  • Greetings,

    I have an idea for a plugin, and I’m trying to write it myself — A plugin to auto-approve trackbacks from certain blogs. There would be a configuration screen added to the admin menu where you would add in domain names from blogs that usually link to you in their posts. When a trackback comes in, WP would use the plugin to check if the domain name matches one on the list; if so, it would be automatically approved.

    But I’m still learning how WordPress (and PHP) works, so naturally I’m stuck. Can anyone provide any pointers (web links, tutorials, sample code/plugins, etc) on any of the following:

    • How can my plugin tell when a new trackback has been received?
    • How can I programmatically approve trackbacks?

    I’ve checked out actions like pre_ping and pingback_post, but none of them include the pingback URL as an argument. I know that you can configure WP to moderate first-time commenters, and thereafter comments from the same person are automatically approved. Would it be worth it to study that code? If so, where do I find it?

    Thanks for your time,

Viewing 2 replies - 1 through 2 (of 2 total)
  • How can my plugin tell when a new trackback has been received?

    What I would do is hook into the ‘comment_post’ action hook:

    function check_for_special_pingbacks($comment_id = 0, $comment_approval = 0) {
         $comment = get_comment($comment_id);
         if ( ! empty( $comment ) && in_array($comment->comment_type, array('trackback', 'pingback')) && preg_match('/some pattern matching desirable urls/', $comment->comment_author_url) ) {
              wp_set_comment_status($comment_id, 'approve');
    add_action('comment_post', 'check_for_special_pingbacks', 10, 2);

    I guess a pingback is a special type of comment. You made it look easy, thank you! By ‘pattern’ I assume you mean Regular Expressions.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Pointers for new plugin writer’ is closed to new replies.