Skip to:
Content
Pages
Categories
Search
Top
Bottom

wp_insert_comment and activity comments


  • wilsos6
    Participant

    @wilsos6

    Hi there,

    I’ve written a plugin which sends SMS notifications when new posts or comments are added to a site. The plugin works fine for ‘standard’ posts and comments. For new comments, I use the wp_insert_comment hook to capture the new comment event and then use get_comment_url to get the comment’s URL and then send that in an SMS.

    Comments made on BP activities, also fire the wp_insert_comment hook, but the URL derived from get_comment_url, results in a 404 error.

    Is there a way of getting the URL to this new activity comment using the ‘comment’ object passed by the wp_insert_comment hook?

    Thank you,
    Stuart

Viewing 4 replies - 1 through 4 (of 4 total)

  • shanebp
    Moderator

    @shanebp

    Have you tried using get_comment_link( $post_comment_id ); ?


    wilsos6
    Participant

    @wilsos6

    Hi Shane,

    Thanks for your reply. Would $post_comment_id be passed into the wp_insert_comment actioner function?

    As an example, when I add a comment to a BP activity, I get a comment object like the one below passed into the wp_insert_comment handler.

        [comment_ID] => 108
        [comment_post_ID] => 1385
        [comment_author] => SW
        [comment_author_email] => 
        [comment_author_url] => 
        [comment_author_IP] => 
        [comment_date] => 2015-04-15 06:23:01
        [comment_date_gmt] => 2015-04-15 13:23:01
        [comment_content] => test comment
        [comment_karma] => 0
        [comment_approved] => 1
        [comment_agent] => 
        [comment_type] => 
        [comment_parent] => 0
        [user_id] => 34

    if I get_comment_link(108) or get_permalink($comment->comment_post_ID), I get URLs returned, but both give 404 errors. If I go into the WordPress admin panel and go into ‘Comments’ I can see the comment and the URL given is the same as the one given by get_comment_link, but when I try to access it I get the 404. If I go into the admin panel and select Activities, I can see the same comment, but “View Activity” takes me to the activity panel, were I can see the parent activity and the post successfully.

    So I’m struggle to tie in the comment object I’m getting above and its URL, with the BP activity/comment URL.

    Any assistance would be greatly appreciated,

    Thanks,
    Stuart


    shanebp
    Moderator

    @shanebp

    Please use the code button when posting code.

    If I go into the admin panel and select Activities, I can see the same comment, but “View Activity” takes me to the activity panel, were I can see the parent activity and the post successfully.

    As you can see, the url is being rewritten when you click on ‘view activity’.
    You can either figure how the url is being rewritten.
    Or create your own url using the fields from the comment object.
    Something like:
    $url = bp_core_get_userlink( comment[user_id] ) . '/activity/' . comment[comment_ID] . '/';

    bp_core_get_userlink()


    wilsos6
    Participant

    @wilsos6

    Hi Shane,

    Thank you for your help.

    I can see two comments in the Activity screen, with IDs 105 & 109. Both have the same “View Activity” URL http://oursite.com/activity-stream/p/362. I’m not clear yet how 105 and 109 are mapped to activity 362, but I’ll do some digging.

    Thank you,
    Stuart

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘wp_insert_comment and activity comments’ is closed to new replies.
Skip to toolbar