PHP code example of stellarwp / banners

1. Go to this page and download the library: Download stellarwp/banners library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

stellarwp / banners example snippets


use StraussGeneratedNamespace\Nexcess\Banners\Banner;
use StraussGeneratedNamespace\Nexcess\Banners\BannerFields;
use StraussGeneratedNamespace\Nexcess\Banners\Registry;

add_action(
	'init',
	static function (): void {
		$fields           = new BannerFields();
		$fields->heading  = __( 'Black Friday: 40% off Pro.', 'my-plugin' );
		$fields->body     = __( 'Unlock every block and priority support.', 'my-plugin' );
		$fields->ctaLabel = __( 'Shop the sale', 'my-plugin' );
		$fields->ctaUrl   = 'https://example.com/black-friday?utm_source=my-plugin';

		( new Registry() )->register(
			new Banner(
				'nexcess-black-friday-2026',
				'1.0.0',
				$fields,
				plugins_url( 'vendor-prefixed/stellarwp/banners/', MY_PLUGIN_FILE ),
				new DateTimeImmutable( '2026-11-27 00:00', new DateTimeZone( 'America/New_York' ) ),
				new DateTimeImmutable( '2026-12-01 00:00', new DateTimeZone( 'America/New_York' ) )
			)
		);
	}
);

add_action(
	'admin_notices',
	static function (): void {
		( new Registry() )->get( 'nexcess-black-friday-2026' )->render( static fn(): bool => my_plugin_is_admin_page() );
	}
);

$banner                   = ( new Registry() )->get( 'nexcess-black-friday-2026' );
$banner->fields()->ctaUrl = add_query_arg( 'utm_source', 'my-plugin', $banner->fields()->ctaUrl );
$banner->render();

$registry = new Registry();

if ( $registry->has( 'nexcess-black-friday-2026' ) ) {
	$registry->get( 'nexcess-black-friday-2026' )->render();
}

$banner->render(
	static fn(): bool => my_plugin_is_admin_page(),
	__DIR__ . '/templates/pro-upsell-banner.php',
	plugins_url( 'assets/pro-upsell-banner.css', MY_PLUGIN_FILE )
);

add_filter( 'nx_banners_scheduled:nexcess-black-friday-2026', '__return_true' );