Skip to content

PHP Functions Reference

This document provides a complete reference for all helper functions available in LamaPress. These functions simplify common tasks and provide a consistent API for working with components, fields, and assets.

Component Loading Functions

llSection()

Load a full-width section component.

php
llSection($name, $key)

Parameters:

  • $name (string) - Section name (e.g., 'hero_basic', 'rich_content')
  • $key (string) - Unique key for ACF field group

Example:

php
llSection('hero_basic', 'hero_section_1');

Location: components/sections/{$name}/index.php


llBlock()

Load a content block component.

php
llBlock($name, $props = false, $wrapped = false)

Parameters:

  • $name (string) - Block name (e.g., 'accordion', 'image', 'video')
  • $props (array|false) - Optional props to pass to the component
  • $wrapped (bool) - Whether to wrap the component (default: false)

Example:

php
llBlock('accordion', [
    'fields' => [
        'title' => 'FAQ Section',
        'items' => $accordion_items
    ],
    'classes' => 'my-custom-class'
]);

Location: components/blocks/{$name}/index.php

Props Structure:

  • fields (array) - Field data for the component
  • classes (string) - Additional CSS classes

llPart()

Load a small reusable part component.

php
llPart($name, $props = false)

Parameters:

  • $name (string) - Part name (e.g., 'button', 'icon', 'img')
  • $props (array|false) - Optional props to pass to the component

Example:

php
llPart('button', [
    'text' => 'Click Me',
    'url' => '/contact',
    'classes' => 'll-btn-primary'
]);

Location: components/parts/{$name}/index.php


llComponent()

Low-level function for loading components. Usually you'll use llBlock() or llPart() instead.

php
llComponent($name, $type, $props = false)

Parameters:

  • $name (string) - Component name
  • $type (string) - Component type ('block' or 'part')
  • $props (array|false) - Optional props

ACF Field Functions

llField()

Get a single ACF field value.

php
llField($name, $key = false, $section = false)

Parameters:

  • $name (string) - Field name
  • $key (string|false) - Optional key prefix for field names
  • $section (array|false) - Optional section data array

Returns: Field value or null if not found

Examples:

php
// Get field from current post/page
$title = llField('title');

// Get field with key prefix
$title = llField('title', 'hero_section_1');

// Get field from section array
$title = llField('title', false, $section);

llFields()

Get multiple ACF field values at once.

php
llFields(...$fields)

Parameters:

  • Variable arguments - Field names or field mapping arrays
  • Last argument can be $key (string|false) - Optional key prefix
  • Second-to-last argument can be $section (array|false) - Optional section data

Returns: Array of field values

Examples:

php
// Get multiple fields
$data = llFields('title', 'content', 'image');

// With key prefix
$data = llFields('title', 'content', 'hero_section_1');

// With section array
$data = llFields('title', 'content', false, $section);

// With field name mapping
$data = llFields(
    ['title' => 'heading'],
    ['content' => 'body'],
    'hero_section_1'
);
// Returns: ['heading' => '...', 'body' => '...']

llGetFields()

Get ACF field definitions from a component's acf.php file.

php
llGetFields($type = 'block', $name = '', $key = '')

Parameters:

  • $type (string) - Component type ('block' or 'part')
  • $name (string) - Component name
  • $key (string) - Optional key prefix

Returns: Array of field definitions or null

Example:

php
$fields = llGetFields('block', 'accordion', 'accordion_1');

Section Helper Functions

llSectionHeader()

Output the opening HTML for a section.

php
llSectionHeader($name, $sectionClasses = false, $containerClasses = false, $constructorName = false)

Parameters:

  • $name (string) - Section name (for CSS class)
  • $sectionClasses (string|false) - Additional section classes
  • $containerClasses (string|false) - Additional container classes
  • $constructorName (string|false) - JavaScript component name

Example:

php
llSectionHeader('hero', 'll-section--dark', 'll-container--wide', 'hero_basic');
// Outputs: <section class="ll-section ll-section--hero ll-section--dark" data-component="sections/hero_basic">
//          <div class="ll-container ll-container--wide">

llSectionFooter()

Output the closing HTML for a section.

php
llSectionFooter()

Example:

php
llSectionFooter();
// Outputs: </div></section>

Usage Pattern:

php
llSectionHeader('hero', 'll-section--dark');
// Section content here
llSectionFooter();

Template Functions

llStartTemplate()

Start output buffering for template rendering.

php
llStartTemplate($routerName = false)

Parameters:

  • $routerName (string|false) - Optional router name

Usage: Usually called at the start of a template file.


llEndTemplate()

End output buffering and render the layout.

php
llEndTemplate()

Usage: Usually called at the end of a template file.

Pattern:

php
<?php
llStartTemplate();
// Template content here
llEndTemplate();
?>

Asset Functions

llDistUri()

Get the URI to a file in the dist/ directory.

php
llDistUri($path = '')

Parameters:

  • $path (string) - Path relative to dist/ directory

Returns: Full URI to the asset

Examples:

php
// Get dist directory URI
$distUri = llDistUri();
// Returns: http://yoursite.com/wp-content/themes/lamapress/dist/

// Get specific file URI
$imageUri = llDistUri('images/logo.png');
// Returns: http://yoursite.com/wp-content/themes/lamapress/dist/images/logo.png

llDistPath()

Get the filesystem path to a file in the dist/ directory.

php
llDistPath($path)

Parameters:

  • $path (string) - Path relative to dist/ directory

Returns: Full filesystem path

Example:

php
$imagePath = llDistPath('images/logo.png');
// Returns: /path/to/theme/dist/images/logo.png

Environment Functions

llIsLocal()

Check if the current environment is local (detects .test domain extension).

php
llIsLocal(): bool

Returns: true if running on local environment

Example:

php
if (llIsLocal()) {
    // Local development code
}

llIsStaging()

Check if the current environment is staging (detects .dev domain extension).

php
llIsStaging(): bool

Returns: true if running on staging environment

Example:

php
if (llIsStaging()) {
    // Staging-specific code
}

llIsProduction()

Check if the current environment is production (not local or staging).

php
llIsProduction(): bool

Returns: true if running on production environment

Example:

php
if (llIsProduction()) {
    // Production-specific code
}

Location: functions/environments.php


Utility Functions

llSvg()

Return an SVG string from the dist/svg/ directory.

php
llSvg(string $filename): ?string

Parameters:

  • $filename (string) - SVG filename without extension

Returns: SVG string or null if not found

Example:

php
$arrowIcon = llSvg('arrow-right');
// Returns: <svg>...</svg> or null

Usage in templates:

php
<?= llSvg('arrow-right') ?>

llConfig()

Load a configuration file.

php
llConfig(string $file): ?array

Parameters:

  • $file (string) - Config filename without extension

Returns: Config array or null

Example:

php
$aliases = llConfig('aliases');
$postTypes = llConfig('post-types');

Location: config/{$file}.php


slugify()

Convert a string to a URL-friendly slug.

php
slugify(string $text): string

Parameters:

  • $text (string) - Text to convert

Returns: URL-friendly slug

Example:

php
$slug = slugify('Hello World!');
// Returns: 'hello-world'

llHasCredentials()

Check if the current user has editor or administrator credentials.

php
llHasCredentials(): bool

Returns: true if user is logged in and has editor/administrator role

Example:

php
if (llHasCredentials()) {
    // Show admin-only content
}

convertToBytes()

Convert a string representation of file size to bytes.

php
convertToBytes(string $from): ?int

Parameters:

  • $from (string) - Size string (e.g., '10MB', '500KB')

Returns: Size in bytes or null if invalid

Example:

php
$bytes = convertToBytes('10MB');
// Returns: 10485760

dd()

Dump and die function for debugging.

php
dd($contents): void

Parameters:

  • $contents (mixed) - Variable to dump

Example:

php
dd($myVariable);
// Outputs var_dump and exits

Common Patterns

Loading a Component with ACF Fields

php
<?php
$fields = [
    'title' => llField('title', $key),
    'content' => llField('content', $key),
    'image' => llField('image', $key),
];

llBlock('image', [
    'fields' => $fields,
    'classes' => 'my-custom-class'
]);
?>
php
<?php
llSectionHeader('hero', 'll-section--dark', 'll-container--wide', 'hero_basic');

$title = llField('title', $key);
$content = llField('content', $key);
?>

<h1><?= esc_html($title) ?></h1>
<div><?= wp_kses_post($content) ?></div>

<?php llSectionFooter(); ?>

Getting Multiple Fields

php
<?php
$data = llFields('title', 'content', 'image', $key);
// $data = ['title' => '...', 'content' => '...', 'image' => '...']
?>

Using SVG Icons

php
<button>
    <?= llSvg('arrow-right') ?>
    Click Me
</button>

Function Locations

All helper functions are defined in:

  • functions/includes.php - Main helper functions (component loading, ACF fields, templates)
  • functions/helpers.php - Additional utility functions (SVG, config, credentials)
  • functions/environments.php - Environment detection functions
  • functions/media.php - Media handling functions
  • functions/nav.php - Navigation functions
  • functions/vite.php - Vite integration functions
  • Other function files in functions/ directory

Best Practices

  1. Always escape output:

    php
    <?= esc_html($title) ?>
    <?= wp_kses_post($content) ?>
  2. Use llField() with key prefixes when working with ACF field groups:

    php
    $title = llField('title', 'section_key');
  3. Pass fields as arrays to components:

    php
    llBlock('component', ['fields' => $fields]);
  4. Use llFields() when you need multiple fields:

    php
    $data = llFields('title', 'content', 'image', $key);
  5. Check for null values when using field functions:

    php
    $image = llField('image', $key);
    if ($image) {
        // Use image
    }


Next Steps:

Released under the MIT License.