PodsAPI::save_comment PHP Method

save_comment() public method

Save a comment and it's meta
Since: 2.0
public save_comment ( array $comment_data, array $comment_meta = null, boolean $strict = false, boolean $sanitized = false, array $fields = [] ) : integer
$comment_data array All comment data to be saved (using wp_insert_comment / wp_update_comment)
$comment_meta array (optional) All meta to be saved (set value to null to delete)
$strict boolean (optional) Whether to delete previously saved meta not in $comment_meta
$sanitized boolean (optional) Will unsanitize the data, should be passed if the data is sanitized before sending.
$fields array (optional) The array of fields and their options, for further processing with
return integer Comment ID
    public function save_comment($comment_data, $comment_meta = null, $strict = false, $sanitized = false, $fields = array())
    {
        if (!is_array($comment_data) || empty($comment_data)) {
            return pods_error(__('Comment data is required but is either invalid or empty', 'pods'), $this);
        }
        $conflicted = pods_no_conflict_check('comment');
        if (!$conflicted) {
            pods_no_conflict_on('comment');
        }
        if (!is_array($comment_meta)) {
            $comment_meta = array();
        }
        if ($sanitized) {
            $comment_data = pods_unsanitize($comment_data);
            $comment_meta = pods_unsanitize($comment_meta);
        }
        if (!isset($comment_data['comment_ID']) || empty($comment_data['comment_ID'])) {
            $comment_data['comment_ID'] = wp_insert_comment(pods_slash($comment_data));
        } elseif (1 < count($comment_data)) {
            wp_update_comment($comment_data);
        }
        if (is_wp_error($comment_data['comment_ID'])) {
            if (!$conflicted) {
                pods_no_conflict_off('comment');
            }
            /**
             * @var $comment_error WP_Error
             */
            $comment_error = $comment_data['comment_ID'];
            return pods_error($comment_error->get_error_message(), $this);
        }
        $this->save_comment_meta($comment_data['comment_ID'], $comment_meta, $strict, $fields);
        if (!$conflicted) {
            pods_no_conflict_off('comment');
        }
        return $comment_data['comment_ID'];
    }