Skip to content

IPublishedStateAssessor Interface

intermediate

IPublishedStateAssessor determines the published state of content items by evaluating StartPublish, StopPublish, and Status properties. Inject it to check content visibility without manual date comparisons.

Optimizely.Cms.Core

MethodReturnsDescription
IsPublished(IContent)boolReturns true if the content is published and within its publish window
IsPublished(IContent, DateTime)boolChecks published state at a specific point in time
IsExpired(IContent)boolReturns true if StopPublish has passed
CheckPublishedStatus(IContent)PublishedStatusReturns the detailed publish status enum
ValueDescription
PublishedContent is published and within its publish date range
NotPublishedContent has never been published
ExpiredStopPublish date has passed
NotYetPublishedStartPublish date is in the future
DraftContent is saved as a draft

The assessor evaluates these IVersionable properties:

PropertyEffect
StartPublishContent is not visible before this date
StopPublishContent is not visible after this date
StatusMust be VersionStatus.Published

If StartPublish is null, the content is visible immediately upon publish. If StopPublish is null, the content never expires.

Check published state
csharp
public class ContentVisibilityService
{
  private readonly IPublishedStateAssessor _assessor;
  private readonly IContentLoader _loader;

  public ContentVisibilityService(
      IPublishedStateAssessor assessor,
      IContentLoader loader)
  {
      _assessor = assessor;
      _loader = loader;
  }

  public bool IsVisibleToVisitors(ContentReference contentRef)
  {
      var content = _loader.Get<IContent>(contentRef);
      return _assessor.IsPublished(content);
  }

  public string GetStatusLabel(IContent content)
  {
      return _assessor.CheckPublishedStatus(content) switch
      {
          PublishedStatus.Published => "Live",
          PublishedStatus.Expired => "Expired",
          PublishedStatus.NotYetPublished => "Scheduled",
          PublishedStatus.Draft => "Draft",
          _ => "Unpublished"
      };
  }
}
Filter visible content
csharp
// Filter a list to only published items
var publishedItems = allItems
  .Where(item => _assessor.IsPublished(item))
  .ToList();

// Check if content will be live at a future date
var isLiveNextWeek = _assessor.IsPublished(content, DateTime.Now.AddDays(7));