Falcon_Connector_WordPress::notify_on_reply PHP Метод

notify_on_reply() публичный Метод

Send a notification to subscribers
public notify_on_reply ( $id, $comment = null )
    public function notify_on_reply($id = 0, $comment = null)
    {
        if (empty($this->handler) || !Falcon::is_enabled_for_site()) {
            return false;
        }
        if (wp_get_comment_status($comment) !== 'approved') {
            return false;
        }
        // Is the post published?
        $post = get_post($comment->comment_post_ID);
        if (get_post_status($post) !== 'publish') {
            return false;
        }
        // Grab the users we should notify
        $users = $this->get_comment_subscribers($comment);
        if (empty($users)) {
            return false;
        }
        $message = new Falcon_Message();
        // Poster name
        $message->set_author(apply_filters('falcon.connector.wordpress.comment_author', $comment->comment_author));
        // Don't send notifications to the person who made the post
        $send_to_author = Falcon::get_option('bbsub_send_to_author', false);
        if (!$send_to_author && !empty($comment->user_id)) {
            $author = (int) $comment->user_id;
            $users = array_filter($users, function ($user) use($author) {
                return $user->ID !== $author;
            });
        }
        // Sanitize the HTML into text
        $message->set_text($this->get_comment_content_as_text($comment));
        $message->set_html($this->get_comment_content_as_html($comment));
        $subject = apply_filters('bbsub_email_subject', 'Re: [' . get_option('blogname') . '] ' . html_entity_decode(get_the_title($post), ENT_QUOTES), $id, $post->ID);
        $message->set_subject($subject);
        $message->set_reply_address_handler(function (WP_User $user, Falcon_Message $message) use($comment) {
            return Falcon::get_reply_address('comment_' . $comment->comment_ID, $user);
        });
        $options = array();
        if ($this->handler->supports_message_ids()) {
            $options['references'] = $this->get_references_for_comment($comment);
            $options['message-id'] = $this->get_message_id_for_comment($comment);
            if (!empty($comment->comment_parent)) {
                $parent = get_comment($comment->comment_parent);
                $options['in-reply-to'] = $this->get_message_id_for_comment($parent);
            } else {
                $options['in-reply-to'] = $this->get_message_id_for_post($post);
            }
        } else {
            $message_ids = get_post_meta($id, self::MESSAGE_ID_KEY, $responses);
            $options['in-reply-to'] = $message_ids;
        }
        $message->set_options($options);
        $this->handler->send_mail($users, $message);
        return true;
    }