id = $id; $this->title = $title; $this->message = $message; $this->types = $types; $this->create_at = strtotime( $create_at ); $this->form_id = $form_id; $this->entry_id = $entry_id; $this->user_id = $user_id; } /** * Get record ID. * * @since 1.6.3 * * @return int */ public function get_id() { return $this->id; } /** * Get record title. * * @since 1.6.3 * * @return string */ public function get_title() { return $this->title; } /** * Get record message. * * @since 1.6.3 * * @return string */ public function get_message() { return $this->message; } /** * Get record types. * * @since 1.6.3 * * @param string $view Keys or labels. * * @return array */ public function get_types( $view = 'key' ) { $this->types = is_array( $this->types ) ? $this->types : explode( ',', $this->types ); if ( 'label' === $view ) { return array_intersect_key( Log::get_log_types(), array_flip( $this->types ) ); } return $this->types; } /** * Get date of creating record. * * @since 1.6.3 * * @param string $format Date format full|short|default sql format. * * @return string */ public function get_date( $format = 'short' ) { if ( 'short' === $format ) { return date_i18n( get_option( 'date_format' ), $this->create_at + ( get_option( 'gmt_offset' ) * 3600 ) ); } elseif ( 'sql' === $format ) { return gmdate( 'Y-m-d H:i:s', $this->create_at ); } else { return date_i18n( sprintf( '%s %s', get_option( 'date_format' ), get_option( 'time_format' ) ), $this->create_at + ( get_option( 'gmt_offset' ) * 3600 ) ); } } /** * Get record form id. * * @since 1.6.3 * * @return int */ public function get_form_id() { return $this->form_id; } /** * Get record entry id. * * @since 1.6.3 * * @return int */ public function get_entry_id() { return $this->entry_id; } /** * Get record user id. * * @since 1.6.3 * * @return int */ public function get_user_id() { return $this->user_id; } /** * Create new record. * * @since 1.6.3 * * @param string $title Record title. * @param string $message Record message. * @param array|string $types Array, string, or string separated by commas types. * @param int $form_id Record form ID. * @param int $entry_id Record entry ID. * @param int $user_id Record user ID. * * @return \WPForms\Logger\Record */ public static function create( $title, $message, $types, $form_id = 0, $entry_id = 0, $user_id = 0 ) { return new Record( 0, sanitize_text_field( $title ), wp_kses( $message, [ 'pre' => [] ] ), $types, gmdate( 'Y-m-d H:i:s' ), absint( $form_id ), absint( $entry_id ), absint( $user_id ) ); } }