$value ) { if ( property_exists( $this, $key ) ) { $this->$key = $value; } } } /** * Convert to array for database * * @return array Database-ready data. */ public function to_array() { return array( 'user_id' => $this->user_id, 'form_id' => $this->form_id, 'post_id' => $this->post_id, 'submission_type' => $this->submission_type, 'ip_address' => $this->ip_address, 'user_agent' => $this->user_agent, 'captcha_score' => $this->captcha_score, ); } /** * Validate model data * * @return bool|array True if valid, array of errors otherwise. */ public function validate() { $errors = array(); if ( empty( $this->user_id ) ) { $errors[] = __( 'User ID is required.', 'airy-frontend-forms' ); } if ( empty( $this->form_id ) ) { $errors[] = __( 'Form ID is required.', 'airy-frontend-forms' ); } if ( empty( $this->post_id ) ) { $errors[] = __( 'Post ID is required.', 'airy-frontend-forms' ); } if ( ! in_array( $this->submission_type, array( 'new', 'edit' ), true ) ) { $this->submission_type = 'new'; } return empty( $errors ) ? true : $errors; } }