Snippets - Configuration

Every SleekByte snippet includes a snippet.json file that serves as its configuration center. This declarative approach controls when, where, and how your snippet files are loaded, making your code more organized and maintainable.

Schema: https://app.sleekwp.com/api/sleek-byte/snippets/schema

Core philosophy

The snippet.json file follows the same pattern as WordPress block development with block.json. Instead of scattered add_action() calls throughout your PHP code, you define loading behavior in one central configuration file that applies to all your snippet's assets.

Minimal setup

The simplest possible snippet only needs an empty snippet.json file:

            {}
  
                    
Copy

SleekByte will automatically:

  • Discover and enqueue all .php, .css, and .js files
  • Apply default loading behavior

Full configuration example

            {
      "name": "My Custom Feature",
      "description": "Adds custom functionality to WordPress",
      "version": "1.0.0",
      "tags": ["utility", "frontend"],
      "export": {
        "author": "Your Name",
        "uri": "https://yourwebsite.com",
        "textDomain": "my-custom-feature"
      }
    }
  
                    
Copy

Configuration properties

The snippet.json file can be as simple as an empty object {}. SleekByte will automatically detect and enqueue all files in the snippet folder. However, you can add configuration to control loading behavior and provide metadata.

Metadata properties

name (string)
Display name for your snippet in the SleekByte interface. Defaults to folder name.

description (string)
Brief explanation of what the snippet does.

version (string)
Semantic version number (e.g., "1.0.0"). Defaults to "1.0.0".

tags (array)
Categories for organizing and searching snippets. Defaults to empty array.

export (object)
Author and plugin information:

  • author - Your name or organization
  • uri - Your website URL
  • textDomain - Text domain for translations

File configuration

files (object)
Maps file paths to their configuration. If omitted, SleekByte automatically discovers and enqueues all files:

  • .php files are executed during the specified hook
  • .css files are enqueued as stylesheets
  • .js files are enqueued as scripts

Loading control properties

Context control

context (array)
Defines where files should load. Default is ["frontend"].

            {
      "context": ["frontend", "admin", "block-editor"]
    }
  
                    
Copy

Available contexts:

  • frontend - Public-facing pages
  • admin - WordPress admin area
  • block-editor - Gutenberg editor

Hook control

hook (string)
WordPress hook for PHP file execution. Default is "wp".

            {
      "hook": "init"
    }
  
                    
Copy

Common hooks:

  • wp - Default, after WordPress loads
  • init - During WordPress initialization
  • wp_head - In the document head
  • wp_footer - Before closing body tag
  • admin_init - Admin area initialization

Conditional loading

conditions (array)
Defines when the snippet should load using AND/OR logic.

            {
      "conditions": [
        [
          {
            "parameter": "userRole",
            "operator": "equals",
            "value": "administrator"
          },
          {
            "parameter": "isSingle",
            "operator": "equals",
            "value": true
          }
        ]
      ]
    }
  
                    
Copy

Structure Logic:

  • Outer array: OR groups (any group can match)
  • Inner array: AND conditions (all must match within a group)
  • Each condition: Has parameter, operator, value, and optional negate

Basic condition format

            {
      "parameter": "userRole",
      "operator": "equals", 
      "value": "administrator",
      "negate": false
    }
  
                    
Copy

Properties:

  • parameter - What to check (see available parameters below)
  • operator - How to compare (see available operators below)
  • value - Expected value to compare against
  • negate - Optional: reverse the condition result

Available condition parameters

User parameters

userId (number)
Current user's ID. Use with specific user IDs.

userRole (string)
Current user's primary role. Supports arrays for multiple roles.

isUserLoggedIn (boolean)
Whether user is logged in.

            {
      "parameter": "userRole",
      "operator": "equals",
      "value": ["administrator", "editor"]
    }
  
                    
Copy

Post parameters

postId (number)
Current post ID. Use for specific posts.

postType (string)
Current post type (post, page, product, etc.).

postStatus (string)
Current post status (publish, draft, private, etc.).

postParent (number)
Parent post ID (for hierarchical post types).

postAuthor (number)
Post author's user ID.

pageTemplate (string)
Page template slug for pages.

            {
      "parameter": "postType",
      "operator": "equals",
      "value": ["post", "page"]
    }
  
                    
Copy

WordPress conditional tags

isSingle (boolean) - Single post pages
isPage (boolean) - WordPress pages
isHome (boolean) - Blog home page
isFrontPage (boolean) - Site front page
isCategory (boolean) - Category archive pages
isTag (boolean) - Tag archive pages
isArchive (boolean) - Any archive page
isSearch (boolean) - Search results pages
is404 (boolean) - 404 error pages
isAttachment (boolean) - Attachment pages

WordPress context

isAdmin (boolean) - WordPress admin area
isAjax (boolean) - AJAX requests
isRest (boolean) - REST API requests
isFeed (boolean) - RSS/Atom feeds
isPreview (boolean) - Post/page previews
isCustomizePreview (boolean) - Customizer preview
isEmbed (boolean) - oEmbed requests
currentScreen (string) - Admin screen ID (admin context only)

            {
      "parameter": "currentScreen",
      "operator": "equals",
      "value": "dashboard"
    }
  
                    
Copy

Date and time parameters

currentTime (time - HH:MM) - Current time in 24-hour format
currentDate (date - YYYY-MM-DD) - Current date
dayOfWeek (number) - Day of week (0=Sunday, 6=Saturday)
timeOfDay (number) - Hour of day (0-23)

            {
      "parameter": "timeOfDay",
      "operator": "greaterThanOrEqual",
      "value": 9
    }
  
                    
Copy

Device and browser parameters

deviceType (string) - Device type: mobile, tablet, desktop
browserName (string) - Browser: chrome, firefox, safari, edge,opera, internet-explorer, unknown
browserVersion (string) - Browserversion number
operatingSystem (string) - OS: windows, macos, ios, android,linux, unknown
isMobile (boolean) - Mobile devices
isTablet (boolean) - Tablet devices
isDesktop (boolean) - Desktop devices

            {
      "parameter": "deviceType",
      "operator": "equals",
      "value": "mobile"
    }
  
                    
Copy

HTTP parameters

requestUri (string) - Current request URI
queryString (string) - URL query string
httpMethod (string) - HTTP method (GET, POST, etc.)
userAgent (string) - Full user agent string
referer (string) - HTTP referer
ipAddress (string) - User's IP address

Multisite parameters

currentBlogId (number) - Current blog ID (multisite only)
isMultisite (boolean) - WordPress multisite installation
isMainSite (boolean) - Main site in multisite (multisite only)
isNetworkAdmin (boolean) - Network admin area (multisite only)
currentLanguage (string) - Current language code

Available condition operators

Equality operators

equals - Exact match. Supports arrays for "any of" matching
contains (string) - String contains substring
startsWith (string) - String starts with value
endsWith (string) - String ends with value

Numeric operators

greaterThan - Numeric greater than
greaterThanOrEqual - Numeric greater than or equal
lessThan - Numeric less than
lessThanOrEqual - Numeric less than or equal

String length operators

lengthEquals - String length equals value
lengthGreaterThan - String length greater than value
lengthGreaterThanOrEqual - String length greater than or equal
lengthLessThan - String length less than value
lengthLessThanOrEqual - String length less than or equal

Word count operators

wordCountEquals - Word count equals value
wordCountGreaterThan - Word count greater than value
wordCountGreaterThanOrEqual - Word count greater than or equal
wordCountLessThan - Word count less than value
wordCountLessThanOrEqual - Word count less than or equal

File-specific configuration

Individual files can override global settings:

            {
      "context": ["frontend"],
      "files": {
        "index.php": {},
        "assets/admin.css": {
          "context": ["admin"],
        },
        "assets/script.js": {
          "dependencies": ["jquery"],
          "module": true
        }
      }
    }
  
                    
Copy

File options

context (array)
Override global context for this file.

hook (string)
Override global hook for this file.

dependencies (array)
Script or style dependencies.

module (boolean)
Load JavaScript as ES6 module.

conditions (array)
File-specific loading conditions.

Advanced examples

Multi-context feature

            {
      "name": "Site Enhancement Suite",
      "description": "Improvements for both frontend and admin",
      "version": "1.0.0",
      "tags": ["enhancement", "admin", "frontend"],
      "context": ["frontend", "admin"],
      "export": {
        "author": "Developer",
        "uri": "https://example.com",
        "textDomain": "site-enhancements"
      },
      "files": {
        "includes/core.php": {},
        "admin/settings.php": {
          "context": ["admin"],
          "hook": "admin_init"
        },
        "assets/frontend.css": {
          "context": ["frontend"]
        },
        "assets/admin.css": {
          "context": ["admin"]
        }
      }
    }
  
                    
Copy

Conditional WooCommerce feature

            {
      "name": "WooCommerce Checkout Enhancements",
      "description": "Custom checkout modifications",
      "version": "1.0.0",
      "tags": ["woocommerce", "checkout"],
      "export": {
        "author": "Developer",
        "uri": "https://example.com",
        "textDomain": "woo-checkout"
      },
      "conditions": [
        [
          {
            "parameter": "postType",
            "operator": "equals",
            "value": "product"
          }
        ]
      ],
      "files": {
        "checkout/modifications.php": {
          "conditions": [
            [
              {
                "parameter": "requestUri",
                "operator": "contains",
                "value": "checkout"
              }
            ]
          ]
        },
        "assets/checkout.css": {
          "conditions": [
            [
              {
                "parameter": "requestUri",
                "operator": "contains",
                "value": "checkout"
              }
            ]
          ]
        }
      }
    }
  
                    
Copy

Configuration vs code

Traditional approach:

            // ❌ Old way - scattered throughout files
    add_action('wp_head', 'my_function');
    if (current_user_can('administrator')) {
        add_action('admin_init', 'admin_function');
    }
  
                    
Copy

SleekByte approach:

            // ✅ New way - centralized configuration
    {
      "hook": "wp_head",
      "conditions": [
        [
          {
            "parameter": "userRole",
            "operator": "equals",
            "value": "administrator"
          }
        ]
      ],
      "files": {
        "index.php": {
          "hook": "admin_init"
        }
      }
    }
  
                    
Copy

Benefits

Declarative Configuration
All loading logic is defined in one place, making it easy to understand and modify.

Version Control Friendly
Configuration is stored as JSON, making changes clear in diffs and easy to track.

No Code Pollution
Your PHP files contain only the functional code, not loading logic.

Visual Editing
Switch between JSON and visual interface - both update the same file.

Reusable Conditions
Define complex loading rules once and apply to multiple files.

Performance
Files only load when conditions are met, reducing unnecessary overhead.

Practical condition examples

Admin-only dashboard widget

            {
      "conditions": [
        [
          {
            "parameter": "userRole",
            "operator": "equals",
            "value": "administrator"
          },
          {
            "parameter": "currentScreen",
            "operator": "equals",
            "value": "dashboard"
          }
        ]
      ]
    }
  
                    
Copy

Mobile users on product pages

            {
      "conditions": [
        [
          {
            "parameter": "isMobile",
            "operator": "equals",
            "value": true
          },
          {
            "parameter": "postType",
            "operator": "equals",
            "value": "product"
          }
        ]
      ]
    }
  
                    
Copy

Business hours only

            {
      "conditions": [
        [
          {
            "parameter": "timeOfDay",
            "operator": "greaterThanOrEqual",
            "value": 9
          },
          {
            "parameter": "timeOfDay",
            "operator": "lessThan",
            "value": 17
          },
          {
            "parameter": "dayOfWeek",
            "operator": "greaterThan",
            "value": 0
          },
          {
            "parameter": "dayOfWeek",
            "operator": "lessThan",
            "value": 6
          }
        ]
      ]
    }
  
                    
Copy

Multiple page types OR admin

            {
      "conditions": [
        [
          {
            "parameter": "postType",
            "operator": "equals",
            "value": ["post", "page"]
          }
        ],
        [
          {
            "parameter": "isAdmin",
            "operator": "equals",
            "value": true
          }
        ]
      ]
    }
  
                    
Copy

Negated conditions

            {
      "conditions": [
        [
          {
            "parameter": "userRole",
            "operator": "equals",
            "value": "subscriber",
            "negate": true
          }
        ]
      ]
    }
  
                    
Copy