value, self::TERM_PREFIX ); } /** * The post type or taxonomy slug. */ public function name(): string { return substr( $this->value, strlen( $this->is_term() ? self::TERM_PREFIX : self::POST_PREFIX ) ); } /** * Value equality. * * @param self $other Type to compare with. */ public function equals( self $other ): bool { return $this->value === $other->value; } /** * Validates a post type or taxonomy slug. The value ends up in SQL, so be strict. * * @param string $slug Slug to validate. * @throws InvalidArgumentException When the slug contains anything but [a-z0-9_-]. */ private static function assert_slug( string $slug ): string { if ( 1 !== preg_match( '/^[a-z0-9_-]{1,32}$/', $slug ) ) { throw new InvalidArgumentException( 'Invalid post type or taxonomy slug.' ); } return $slug; } }