API Documentation - Juzt Studio

Technical Code Documentation: Juzt Studio (Community Version)

Technical overview of the core components of the Juzt Studio Community plugin, detailing class structure, properties, and methods.

Plugin Structure Overview

Text
__juzt-studio-community.php:__ Main plugin file, handles constants, Composer autoloading, and primary initialization (juzt_studio_community_init()).

__src/:__ Directory containing all namespaced PHP classes (Juztstack\JuztStudio\Community).

__src/Core.php:__ The main Singleton orchestrator, managing component instantiation and main hook registration.

__src/ExtensionRegistry.php:__ Handles discovery, indexing, and caching of all template resources (sections, templates, snippets) from theme and extensions.

__src/Builder.php:__ Contains all AJAX and REST API logic for the Admin Builder UI (loading schemas, saving templates, media pickers).

__src/ThemeRuntime.php:__ Manages front-end runtime features, including template preview mode (via cookie) and AJAX section rendering.

__src/Templates.php:__ Handles the loading and rendering of JSON Templates.

__src/Sections.php:__ Handles the loading and rendering of individual Sections (Twig files).

__src/TimberExtension.php:__ Custom Twig Extension to simplify WordPress media handling.

__src/Snippets.php:__ Handles the discovery and rendering of Snippets.

__src/Compatibility.php:__ Defines global helper functions for backward compatibility.

Class

Core

get_instance()

Purpose: Get the single instance of the class (Singleton pattern).

construct()

Purpose: Private constructor for Singleton control.

init()

Purpose: Initialize the plugin flow.Actions: Initializes the $extension_registry, runs auto_discover_extensions(), loads all components, sets up theme compatibility, and registers necessary hooks.

register_extension_templates($templates)

Purpose: Integrates templates from extensions into the WordPress Page Template selector.Hook: theme_page_templates filter.

load_extension_template($template)

Purpose: Overrides the template path to load the selected template file from the correct extension directory.Hook: template_include filter.

handle_plugin_deactivation($plugin_file)

Purpose: Removes the extension's data from the registry cache when its plugin is deactivated.Hook: deactivated_plugin action.

invalidate_registry_cache()

Purpose: Clears the registry cache transient and rebuilds the index.Hooks: activated_plugin, switch_theme, upgrader_process_complete.

find_snippet_file($name)

Purpose: Delegates the search for a snippet file to the $snippets component.

get_registry()

Purpose: Helper to retrieve the ExtensionRegistry instance.

Extension Registry

construct()

Purpose: Loads the unified index and extensions from cache (juzt_registry_index_v1).

register_extension(array $config)

Purpose: Registers an extension configuration.Actions: Prevents duplicates, logs registration, and schedules asset loading via wp_enqueue_scripts (supporting Vite or production assets).

auto_discover_extensions()

Purpose: Scans active plugins for juzt-extension.php configuration files and registers discovered extensions.

build_index()

Purpose: Scans all sources (theme, extensions, core) and builds the unified $index of sections, templates, and snippets, then saves to cache.

scan_theme()

scan_extensions()

scan_core()

Purpose: Private methods to scan files based on directory structure (separated schemas/twig or consolidated folders).

load_assets($config)

Purpose: Enqueues JavaScript and CSS based on the extension's assets config, distinguishing between development (Vite) and production modes.

get_section($section_id)

Purpose: Retrieves a section's data, respecting priority: Theme > Extensions > Core.

remove_extension($ext_id)

Purpose: Removes an extension's config and all its resources from the live index and cache.

Builder

register_ajax_endpoints()

Purpose: Registers all administrative AJAX actions (wp_ajax_*) for the Builder UI.

ajax_get_all_section_schemas()

Purpose: Fetches all section schemas (schemas/*.php or section/schema.php) from the Registry, parses them, and returns them in the required JSON Schema format (including blocks and properties).

convert_settings_to_properties($settings)

Purpose: Converts the legacy/Shopify-style array of settings into JSON Schema properties expected by the frontend builder.

ajax_save_template()

Purpose: Saves the JSON template data.Actions: Determines the correct save location (theme or extension), writes the .json file, and optionally generates stub PHP/Twig files for the theme.

determine_template_save_location($template_name)

Purpose: Finds the source (theme or extension) of the template to determine the correct directory for saving changes.

ajax_preview_template()

Purpose: Loads and renders the sections of a template for the Builder's preview iframe. Requires Timber/Twig.

ajax_get_general_settings_schema()

ajax_save_general_settings()

Purpose: CRUD endpoints for global theme settings defined in config/settings_schema.php and saved in config/settings_data.json.

ajax_search_posts()

ajax_search_terms()

ajax_get_menus()

ajax_get_sidebars()

Purpose: Lookup endpoints for custom fields (Post, Taxonomy, Menu, Sidebar) within the Builder UI.

generate_php_template(...)

generate_twig_template(...)

Purpose: Generates boilerplate code for PHP and Twig files when a template is saved in the theme.

Theme Runtime

handle_view_param()

Purpose: Intercepts ?view=template-name query parameter, sets the preview cookie, and redirects to clean the URL.

override_template($template)

Purpose: Overrides the template file if a preview cookie (juzt_preview_template) is active for the current path.

enqueue_global_data()

Purpose: Enqueues inline JavaScript with global data (JuztTheme object) and utility functions for client-side template manipulation (e.g., switchTemplate() without reload).

add_preview_bar()

Purpose: Renders a fixed, visible bar on the frontend when preview mode is active, providing an option to exit the preview.

ajax_set_preview()

ajax_clear_preview()

Purpose: Sets or clears the preview cookie (juzt_preview_template) via AJAX request, used by client-side tools like Growthbook or the Builder itself.

ajax_render_sections()

Purpose: Renders specific sections of a template via AJAX (used for partial updates).

get_preview_template()

Purpose: Retrieves the active preview template name from the cookie.

Timber Extension

getFilters()

Purpose: Registers custom Twig filters for attachment data.Filters: attachment_url, attachment_alt, attachment_title, attachment_caption, attachment_srcset, attachment_img.

getFunctions()

Purpose: Registers custom Twig functions.Functions: attachment, get_menu_items.

attachmentUrl($attachment_id, $size = 'full')

Purpose: Returns the URL for a given attachment ID and size (or returns the URL if input is a URL string).

attachmentAlt($attachment_id)

Purpose: Returns the alt text of a WordPress attachment.

attachmentImg($attachment_id, $size = 'full', $attr = [])

Purpose: Generates a complete

Html
<img>

tag using wp_get_attachment_image.

getAttachment($attachment_id)

Purpose: Returns a structured object containing comprehensive data about the attachment (URL, alt, sizes, dimensions).

getMenuItems($menu_name)

Purpose: Retrieves all items for a given WordPress menu slug.