$context Extra sync details. */ public function add_entry( $source, $status, $message, array $context = array() ) { $entries = $this->get_entries(); array_unshift( $entries, array( 'time' => time(), 'source' => sanitize_key( $source ), 'status' => sanitize_key( $status ), 'message' => sanitize_text_field( $message ), 'context' => $this->sanitize_context( $context ), ) ); update_option( self::OPTION_NAME, array_slice( $entries, 0, self::MAX_ENTRIES ), false ); } /** * Returns recent sync history entries. * * @return array> */ public function get_entries() { $entries = get_option( self::OPTION_NAME, array() ); return is_array( $entries ) ? $entries : array(); } /** * Removes all stored debug history entries. */ public function clear() { delete_option( self::OPTION_NAME ); } /** * Sanitizes structured context before saving it to the database. * * @param array $context Raw context. * @return array */ private function sanitize_context( array $context ) { $clean = array(); foreach ( $context as $key => $value ) { $key = sanitize_key( $key ); if ( is_array( $value ) ) { $clean[ $key ] = $this->sanitize_context( $value ); continue; } if ( is_scalar( $value ) ) { $clean[ $key ] = sanitize_text_field( (string) $value ); } } return $clean; } }