/**
  * Display the reaction area at the end of post's content
  *
  * @param string $content
  * @return string Filtered content
  */
 public function display($content = '')
 {
     if (!Emoji_Reactions_Utils::can_react_to_post(get_the_ID())) {
         return $content;
     }
     $filtered_content = apply_filters('emoji_reactions_reaction_area', $content);
     $empty_flair = $this->before_display('') . $this->after_display('');
     if ($content . $empty_flair == $filtered_content) {
         return $content;
     } else {
         return $filtered_content;
     }
 }
Пример #2
0
 /**
  * Sends our reaction to the server
  */
 public function do_reaction()
 {
     if (empty($_REQUEST['post_ID']) || empty($_REQUEST['emoji'])) {
         wp_send_json_error(esc_html__('The required post ID and emoji fields were not provided.', 'emoji-reactions'));
     }
     $post_ID = $_REQUEST['post_ID'];
     $emoji = $_REQUEST['emoji'];
     if (!Emoji_Reactions_Utils::can_react_to_post($post_ID)) {
         wp_send_json_error(esc_html__('Post is not available.', 'emoji-reactions'));
     }
     if (!Emoji_Reactions_Utils::is_valid_emoji($emoji)) {
         wp_send_json_error(esc_html__('Provided emoji not recognized.', 'emoji-reactions'));
     }
     $ip_address = preg_replace('/[^0-9a-fA-F:., ]/', '', $_SERVER['REMOTE_ADDR']);
     $user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? substr($_SERVER['HTTP_USER_AGENT'], 0, 254) : '';
     $data = array('comment_post_ID' => $post_ID, 'comment_content' => $emoji, 'comment_type' => 'emoji-reaction', 'comment_approved' => 1, 'comment_author_IP' => $ip_address, 'comment_agent' => $user_agent);
     if (is_user_logged_in()) {
         $current_user = wp_get_current_user();
         if ($current_user->user_login !== $current_user->display_name) {
             $user_name = $current_user->display_name;
         } else {
             $user_name = $current_user->user_login;
         }
         $data['user_id'] = get_current_user_id();
         $data['comment_author'] = $user_name;
         $data['comment_author_email'] = $current_user->user_email;
     } else {
         $data['comment_author'] = esc_html__('Guest', 'emoji-reactions');
     }
     $id = wp_insert_comment($data);
     if (!$id) {
         wp_send_json_error(esc_html__('Reaction failed to post.', 'emoji-reactions'));
     }
     wp_send_json(array('success' => true, 'reaction_ID' => $id));
     die;
 }