Developer guide

Architecture, stored data, the PHP API, templates, markup, CSS custom properties, endpoints and JavaScript events.

FreePro

Architecture

FreePro
NamespaceSiteryn\SiterynProductGridListSiterynPro\SiterynProductGridList
Bootplugins_loaded; once PHP, WordPress and WooCommerce checks pass, fires siteryn_pgl_loadedBoots from siteryn_pgl_loaded, then fires siteryn_pgl_pro_loaded; features are registered only while licensed (siteryn_pgl_pro_features_loaded)
Shortcodes[siteryn_product_grid], [siteryn_product_list][siteryn_product_grid_tabs], [siteryn_product_category_list]
Helperssiteryn_pgl(), siteryn_pgl_render( $atts, $layout ), siteryn_pgl_get_template_html( $name, $args )Uses Free's API only
Handlessiteryn-pgl (CSS)siteryn-pgl-pro (CSS, depends on Free's; JS loaded only for carousel, load more, tabs and quick view), siteryn-pgl-pro-block-editor
Settings pageadmin.php?page=siteryn-product-grid-listSame page, tabs pro_features, pro_responsive, pro_license
Extension APISITERYN_PGL_API_VERSION = 1.0Requires Free 1.0.0 and API 1.0

A shortcode is parsed into query parameters and display arguments. WooCommerce\ProductQuery runs a WP_Query for product IDs (cached by QueryCache), and Frontend\Renderer draws them through the layout's templates, with each card element hooked onto the item actions by Frontend\Elements. Pro extends Free only through these documented hooks and the API.

PHP API

Siteryn\SiterynProductGridList\Api. Check Api::is_compatible( '1.0' ) before using it.

MethodReturns
version(), api_version()Plugin and API versions
is_compatible( $required )Same major version and a minor version at or above $required
is_ready()Whether requirements were met and the plugin booted
render( array $atts, $layout = 'grid' )HTML from shortcode-style attributes (what builders and the block use)
parse_attributes( array $atts, $layout )atts, query, display and no_match without rendering
query( array $params )ids, total, pages, page, params
render_products( array $ids, array $display )HTML for a known list of product IDs
render_items( array $ids, array $display, $instance_id )Only the <li> items, to append to an existing grid
get_layouts()Registered layouts
get_template_html( $name, $args )A rendered template (theme overrides apply)
allowed_html()The wp_kses() list for printing a rendered grid
get_setting( $key, $fallback )A stored Free setting
echo siteryn_pgl_render( array( 'category' => 'dresses', 'limit' => 4 ), 'grid' );

Query parameters: limit (1 to siteryn_pgl_max_limit), page, paginate (adds totals), orderby, order, category (term IDs), category_operator, include_children, ids. Unknown keys are passed through for extensions (Pro uses pro_* keys).

Display arguments: layout, columns, columns_tablet, columns_mobile, show_image, show_title, show_rating, show_price, show_excerpt, show_add_to_cart, excerpt_length, title_tag, heading, heading_tag, image_size, image_ratio, card_style, gap, class, empty_message, show_empty. Shortcodes also pass shortcode_atts and query_result.

Data stored

NameWhat
siteryn_pgl_settingsFree settings (one autoloaded array with schema_version)
siteryn_pgl_versionInstalled Free version
siteryn_pgl_cache_generationCache generation, changed to invalidate every cached query
siteryn_pgl_q_* (transients)Cached query results (IDs and totals), one day
siteryn_pgl_outdated_templates (transient)Outdated theme template overrides, one day
siteryn_pgl_pro_settingsPro settings
siteryn_pgl_pro_versionInstalled Pro version
siteryn_pgl_pro_license_key, _license_status, _license_updateLicense key, last confirmed status, cached update offer
siteryn_pgl_pro_rl_* (transients)Load more rate limit per IP, 5 minutes
WP-Cron siteryn_pgl_pro_license_refreshTwice-daily license check

No custom tables. Cache keys include the query, WooCommerce's product query version, the cache generation, locale, language (WPML / Polylang) and the visitor's roles. See Deactivating and deleting for what is removed.

Endpoints

EndpointPurpose
AJAX siteryn_pgl_save_settingsSaves one settings tab (settings nonce, manage_woocommerce); accepts the option groups from siteryn_pgl_ajax_option_groups
admin-post.php?action=siteryn_pgl_reset_settingsResets one Free tab
admin-post.php?action=siteryn_pgl_pro_reset_settingsResets one Pro tab (licensed only)
AJAX siteryn_pgl_pro_license with do = activate, deactivate, refreshLicense actions (nonce, manage_woocommerce)
REST POST /wp-json/siteryn-pgl-pro/v1/productsLoad more: state, sig, page (2 to 100), instance, optional lang. Returns html, page, pages, total, count. Public, signed and rate limited; always runs as a guest

Templates

Copy a file from the plugin's templates/ folder to yourtheme/siteryn-product-grid-list/ with the same relative path (child theme first, then parent). Every template has an @version tag; a theme copy that is older (or has none) is listed on the settings page, the Plugins screen and under WooCommerce → Status.

TemplateDraws
layouts/grid.php, layouts/list.phpThe wrapper, heading and item list
parts/grid-item.php, parts/list-item.phpOne card; content comes from the item actions
parts/image.php, title.php, rating.php, price.php, excerpt.php, add-to-cart.phpCard elements
parts/empty.php"No products found."
layouts/carousel.php (Pro)Carousel track and buttons
tabs.php, category-header.php (Pro)Tabs, category name, description and View all link
parts/badges.php, parts/load-more.php (Pro)Badges, load more status and button

Pro's templates are found after the theme and Free's folder, so they are overridden in the same theme folder. Keep the data-siteryn-pgl-pro-* attributes; the script relies on them.

Moving card elements

Card content is hooked onto siteryn_pgl_item_media (image 10), siteryn_pgl_item_body (title 10, rating 20, price 30, excerpt 40) and siteryn_pgl_item_footer (add to cart 10), with callbacks in Frontend\Elements:

add_action( 'siteryn_pgl_loaded', function () {
	$el = \Siteryn\SiterynProductGridList\Frontend\Elements::class;
	remove_action( 'siteryn_pgl_item_body', array( $el, 'price' ), 30 );
	add_action( 'siteryn_pgl_item_body', array( $el, 'price' ), 5, 2 );
} );

Custom layouts

add_filter( 'siteryn_pgl_layouts', function ( $layouts ) {
	$layouts['my-layout'] = array(
		'label'         => 'My layout',
		'template'      => 'layouts/my-layout.php',  // Theme, then template paths.
		'item_template' => 'parts/grid-item.php',    // Reuse Free's card.
		'base'          => 'grid',                   // Free CSS it builds on.
		'supports'      => array( 'columns' ),
	);
	return $layouts;
} );
add_filter( 'siteryn_pgl_template_paths', function ( $paths ) {
	$paths[] = MY_PLUGIN_DIR . 'templates/';
	return $paths;
} );

Layout templates receive $args and loop with Frontend\Renderer::render_item( $product_id, $args ), which sets and restores the WooCommerce loop globals. Use it with layout="my-layout".

Markup and classes

ClassMeaning
.siteryn-pglWrapper, also .woocommerce; data-siteryn-pgl-layout holds the layout
.siteryn-pgl--grid, --listBase layout
.siteryn-pgl--layout-{{layout}}grid, list; Pro adds carousel, masonry, overlay, compact
.siteryn-pgl--bordered, --plain, --card-linkCard style; the whole card is clickable
.siteryn-pgl__heading, __items, __item, __emptyHeading, list, item, empty message
.siteryn-pgl__item--{{type}}, --on-sale, --out-of-stockItem state classes
.siteryn-pgl-card, __media, __image, __body, __title, __footerCard parts (--no-media without image)
.siteryn-pgl-pro-badges, -badge--{{key}}, -carousel, -tabs, -more, -category-header, -quick-viewPro parts

CSS custom properties

Set on .siteryn-pgl (or with siteryn_pgl_wrapper_style): --siteryn-pgl-columns, --siteryn-pgl-columns-tablet, --siteryn-pgl-columns-mobile, --siteryn-pgl-gap, --siteryn-pgl-image-ratio, --siteryn-pgl-list-media (list image width, 200px) and --siteryn-pgl-radius (6px). Pro adds --siteryn-pgl-pro-gap-tablet and --siteryn-pgl-pro-gap-mobile.

.siteryn-pgl {
	--siteryn-pgl-radius: 12px;
	--siteryn-pgl-list-media: 160px;
}

JavaScript

Free has no front-end JavaScript (WooCommerce's add to cart script is loaded when AJAX add to cart is on). Pro's script:

APIUse
siteryn-pgl:items-addedDOM event on the item list after load more adds products (detail.page); jQuery also gets siteryn_pgl_items_added on document.body with the list
siteryn-pgl:quick-viewCancellable DOM event from Pro's Quick view button with detail.productId and detail.trigger
window.siterynPglProInit( scope )Starts carousels, tabs and load more inside scope, for example after a builder re-renders content
document.addEventListener( 'siteryn-pgl:quick-view', function ( event ) {
	event.preventDefault();
	myQuickView.open( event.detail.productId );
} );

Multilingual

WPML and Polylang are supported through their public hooks: product and category IDs are mapped to the shopper's language, the cache is kept per language, load more requests use the page's language, and the title and empty_message attributes are declared for translation in wpml-config.xml.