static function Add_fb_link_comment($comment) { // Get data $fb_comment_id = get_comment_meta($comment->comment_ID, c_al2fb_meta_fb_comment_id, true); if (!empty($fb_comment_id)) { return; } $post = get_post($comment->comment_post_ID); if (empty($post)) { return; } $link_id = get_post_meta($post->ID, c_al2fb_meta_link_id, true); if (empty($link_id)) { return; } if (get_post_meta($post->ID, c_al2fb_meta_nointegrate, true)) { return; } $user_ID = WPAL2Facebook::Get_user_ID($post); if (!get_user_meta($user_ID, c_al2fb_meta_fb_comments_postback, true)) { return; } if (get_user_meta($user_ID, c_al2fb_meta_fb_comments_only, true)) { if ($comment->comment_type == 'pingback' || $comment->comment_type == 'trackback') { return; } } if (WPAL2Facebook::Is_excluded_post_type($post)) { return; } // Build message $message = ''; if ($post->post_author != $comment->user_id || $post->post_author != $user_ID) { $message .= $comment->comment_author . ' ' . __('commented on', c_al2fb_text_domain) . ' '; $message .= html_entity_decode(get_bloginfo('title'), ENT_QUOTES, get_bloginfo('charset')) . ":\n\n"; } $message .= $comment->comment_content; $message = apply_filters('al2fb_comment', $message, $comment, $post); $message = WPAL2Int::Convert_encoding($user_ID, $message); // Do not disturb WordPress try { $url = 'https://graph.facebook.com/v2.2/' . $link_id . '/comments'; $url = apply_filters('al2fb_url', $url); $query_array = array('access_token' => WPAL2Int::Get_access_token_by_post($post), 'message' => $message); // http://developers.facebook.com/docs/reference/api/Comment/ $query = http_build_query($query_array, '', '&'); // Execute request $response = WPAL2Int::Request($url, $query, 'POST'); // Process response $fb_comment = json_decode($response); add_comment_meta($comment->comment_ID, c_al2fb_meta_fb_comment_id, $fb_comment->id); if (get_option(c_al2fb_option_debug)) { add_post_meta($post->ID, c_al2fb_meta_log, date('c') . ' added comment=' . $comment->comment_ID . ' fib=' . $fb_comment->id); } // Remove previous errors $error = get_post_meta($post->ID, c_al2fb_meta_error, true); if (strpos($error, 'Add comment: ') !== false) { delete_post_meta($post->ID, c_al2fb_meta_error, $error); delete_post_meta($post->ID, c_al2fb_meta_error_time); } } catch (Exception $e) { update_post_meta($post->ID, c_al2fb_meta_error, 'Add comment: ' . $e->getMessage()); update_post_meta($post->ID, c_al2fb_meta_error_time, date('c')); } }