Skip to content

Naming Conventions

This guide provides detailed naming conventions for all code elements in LamaPress projects. Consistent naming improves code readability and maintainability.

Table of Contents

PHP Naming

Functions

Format: camelCase with ll prefix

php
// ✅ Good
function llGetField($name, $key) { }
function llRenderComponent($name, $props) { }
function llValidateInput($input) { }

// ❌ Bad
function get_field() { }           // Missing ll prefix
function renderComponent() { }     // Missing ll prefix
function getFieldValue() { }       // Missing ll prefix

WordPress Hooks:

  • Use descriptive names
  • Prefix with ll (standard prefix)
php
// ✅ Good
add_action('wp_head', 'llAddCustomMeta');
add_filter('the_content', 'llFilterContent');

// ❌ Bad
add_action('wp_head', 'add_meta');
add_filter('the_content', 'filter');
add_action('wp_head', 'lamaAddMeta');  // Use ll prefix, not lama

Variables

Format: camelCase

php
// ✅ Good
$fieldValue = llField('title', $key);
$componentProps = ['fields' => $fields];
$isActive = true;
$itemCount = 10;

// ❌ Bad
$field_value = llField('title', $key);  // snake_case
$FieldValue = llField('title', $key);    // PascalCase
$fv = llField('title', $key);           // Abbreviation

Boolean Variables:

  • Prefix with is, has, can, should
php
// ✅ Good
$isActive = true;
$hasContent = !empty($content);
$canEdit = current_user_can('edit_posts');
$shouldDisplay = $isActive && $hasContent;

// ❌ Bad
$active = true;
$content = !empty($content);

Classes

Format: PascalCase

php
// ✅ Good
class ComponentLoader { }
class FieldHelper { }
class DataValidator { }

// ❌ Bad
class component_loader { }  // snake_case
class componentLoader { }   // camelCase
class loader { }            // Too generic

Constants

Format: UPPER_SNAKE_CASE

php
// ✅ Good
define('LL_BUNNY_API_KEY', 'key');
define('LL_GTM_ID', 'GTM-XXXXX');
define('MAX_ITEMS', 10);

// ❌ Bad
define('ll_bunny_api_key', 'key');  // lowercase
define('LLBunnyApiKey', 'key');     // PascalCase

Arrays and Keys

Format: snake_case for keys

php
// ✅ Good
$fields = [
    'field_name' => 'value',
    'field_value' => 123,
    'is_active' => true,
];

// ❌ Bad
$fields = [
    'fieldName' => 'value',    // camelCase
    'FieldName' => 'value',    // PascalCase
];

JavaScript Naming

Variables

Format: camelCase

javascript
// ✅ Good
const fieldValue = getField('title');
const componentProps = { fields: fields };
const isActive = true;
const itemCount = 10;

// ❌ Bad
const field_value = getField('title');  // snake_case
const FieldValue = getField('title');    // PascalCase
const fv = getField('title');           // Abbreviation

Functions

Format: camelCase

javascript
// ✅ Good
function getFieldValue(name, key) { }
function renderComponent(name, props) { }
function handleClick() { }

// ❌ Bad
function get_field_value() { }      // snake_case
function GetFieldValue() { }         // PascalCase
function getFV() { }                // Abbreviation

Classes

Format: PascalCase

javascript
// ✅ Good
export default class Accordion { }
class ComponentLoader { }
class FieldHelper { }

// ❌ Bad
export default class accordion { }   // camelCase
export default class ACCORDION { }  // UPPER_CASE

Constants

Format: UPPER_SNAKE_CASE

javascript
// ✅ Good
const MAX_ITEMS = 10;
const API_BASE_URL = 'https://api.example.com';
const DEFAULT_TIMEOUT = 5000;

// ❌ Bad
const maxItems = 10;              // camelCase
const MaxItems = 10;              // PascalCase
const max_items = 10;             // snake_case

Component Methods

Format: camelCase (arrow functions)

javascript
// ✅ Good
export default class Component {
  init = () => { }
  bindEvents = () => { }
  handleClick = () => { }
  createAnimation = () => { }
}

// ❌ Bad
export default class Component {
  Init = () => { }              // PascalCase
  bind_events = () => { }       // snake_case
  init() { }                    // Regular function
}

File and Directory Naming

Directories

Format: snake_case

// ✅ Good
components/sections/hero_basic/
components/blocks/rich_content/
functions/register-section-fields.php

// ❌ Bad
components/sections/heroBasic/
components/blocks/richContent/
functions/registerSectionFields.php

Files

Format: snake_case for PHP, camelCase for JavaScript

// ✅ Good - PHP files
components/sections/hero_basic/index.php
functions/register-section-fields.php
config/post-types.php

// ✅ Good - JavaScript files
components/blocks/accordion/index.js
src/js/core/app.js
src/js/core/utils/helpers.js

// ❌ Bad
components/sections/heroBasic/index.php  // camelCase for PHP
components/blocks/Accordion/index.js     // PascalCase

Component Files

Standard Names:

  • index.php - Main template
  • index.js - JavaScript class
  • acf.php - ACF field definitions
  • style.scss - Component styles
  • functions.php - Component functions (sections only)
// ✅ Good
components/blocks/accordion/
├── index.php
├── index.js
├── acf.php
└── style.scss

// ❌ Bad
components/blocks/accordion/
├── accordion.php      // Should be index.php
├── accordion.js       // Should be index.js
├── fields.php         // Should be acf.php
└── styles.scss        // Should be style.scss

CSS/SCSS Naming

Classes

Format: ll-{type}--{name} (BEM-like)

php
<!-- Good -->
<div class="ll-block--accordion">
<div class="ll-section--hero">
<div class="ll-part--button">

<!-- Bad -->
<div class="accordion">           // Missing ll- prefix
<div class="ll-accordion">        // Missing type
<div class="block-accordion">    // Wrong format

Modifiers:

php
<!-- Good -->
<div class="ll-block--accordion ll-block--accordion--open">
<div class="ll-section--hero ll-section--hero--dark">

<!-- Bad -->
<div class="ll-block--accordion open">
<div class="ll-block--accordionOpen">

Custom Classes

Only when Tailwind doesn't suffice:

scss
// ✅ Good - Custom class when needed
.ll-block--accordion {
  // Specific styling not possible with Tailwind
}

// ❌ Bad - Recreating Tailwind
.ll-block--accordion {
  display: flex;
  padding: 1rem;
  // Use Tailwind classes instead
}

Database Naming

Table Names

Format: WordPress prefix + snake_case

php
// ✅ Good - WordPress handles prefixes
$wpdb->posts
$wpdb->postmeta
$wpdb->options

// Custom tables (if needed)
$wpdb->prefix . 'custom_table_name'

Column Names

Format: snake_case

php
// ✅ Good
$wpdb->get_results("SELECT post_id, meta_key, meta_value FROM ...");

// ❌ Bad
$wpdb->get_results("SELECT postId, metaKey, metaValue FROM ...");

ACF Field Keys

Format: snake_case with unique prefix

php
// ✅ Good
$key = 'section_hero_basic';
'key' => $name . '_01',  // hero_basic_01
'key' => $name . '_02',  // hero_basic_02

// ❌ Bad
$key = 'sectionHeroBasic';
'key' => $name . '01',   // Missing underscore

Naming Best Practices

1. Be Descriptive

php
// ✅ Good
$userEmailAddress = get_user_meta($userId, 'email', true);
function llGetFieldValue($name, $key) { }

// ❌ Bad
$email = get_user_meta($userId, 'email', true);  // Ambiguous
function llGet($n, $k) { }                        // Abbreviations

2. Use Consistent Abbreviations

If you must abbreviate, be consistent:

php
// ✅ Good - Consistent
$imgUrl = $image['url'];
$imgAlt = $image['alt'];
$imgId = $image['ID'];

// ❌ Bad - Inconsistent
$imageUrl = $image['url'];
$imgAlt = $image['alt'];
$imageId = $image['ID'];

3. Avoid Magic Numbers

php
// ✅ Good
const MAX_ITEMS = 10;
if ($count > MAX_ITEMS) { }

// ❌ Bad
if ($count > 10) { }  // What does 10 mean?

4. Use Boolean Naming

php
// ✅ Good
$isActive = true;
$hasContent = !empty($content);
$canEdit = current_user_can('edit_posts');

// ❌ Bad
$active = true;        // Not clear it's boolean
$content = !empty($content);  // Confusing

Next Steps:

Released under the MIT License.