ClassesBigCommerceBannersBanners

Banners

Handles the management and display of banners on various pages of the BigCommerce WordPress theme. It provides methods to configure JavaScript settings, fetch banners from the API, and filter banners based on the current page context, visibility, and date range.

  • Full name: \BigCommerce\Banners\Banners

Constants

ConstantVisibilityTypeValue
CACHEpublicstring’bigcommerce_banners’
CACHE_TTLpublicint’3600’
PAGE_HOMEpublicstring’home_page’
PAGE_CATEGORYpublicstring’category_page’
PAGE_BRANDpublicstring’brand_page’
PAGE_SEARCHpublicstring’search_page’
DATE_TYPE_CUSTOMpublicstring’custom’

Methods

__construct

Banners constructor.

public __construct(object $banners_api): mixed

Initializes the Banners class with a banners API instance.

Parameters:

ParameterTypeDescription
$banners_apiobjectThe banners API instance.

js_config

Adds banner configuration to the JS config.

public js_config(array $config): array

This method adds the banner settings, including background color, text color, and the context-based banners, to the JavaScript configuration. The configuration is later localized in the theme.

Parameters:

ParameterTypeDescription
$configarrayThe current JavaScript configuration.

Return Value:

The modified JavaScript configuration.


get_context_banners

Retrieves banners for the current page context.

public get_context_banners(): array

This method filters banners based on the current page type (home, category, brand, search), visibility, and any custom date ranges that are defined for each banner. Only banners that match the current context will be returned.

Return Value:

The filtered list of banners for the current context.


get_banners

Fetches banners from the banners API.

public get_banners(): array

This method checks for cached banners and fetches them from the API if they are not already cached. The fetched banners are stored in the WordPress transient cache for future use.

Return Value:

The list of banners retrieved from the API or cache.



Automatically generated on 2025-01-21