### Access Genesis Custom Blocks Plugin Instance (PHP) Source: https://context7.com/studiopress/genesis-custom-blocks/llms.txt Demonstrates how to retrieve the singleton instance of the Genesis Custom Blocks plugin to access its methods. This provides access to block loading, utilities, and registered controls. It shows examples of getting post type slugs, template locations, and stylesheet locations. ```php get_post_type_slug(); // Returns: 'genesis_custom_block' // Get template locations for a block $locations = genesis_custom_blocks()->get_template_locations( 'hero-banner', 'block' ); // Returns: [ // 'blocks/hero-banner/block.php', // 'blocks/block-hero-banner.php', // 'blocks/block.php', // ] // Locate a template file (searches theme directories) $template_path = genesis_custom_blocks()->locate_template( $locations ); // Get stylesheet locations for a block $css_locations = genesis_custom_blocks()->get_stylesheet_locations( 'hero-banner', 'block' ); // Returns: [ // 'blocks/hero-banner/block.css', // 'blocks/css/block-hero-banner.css', // 'blocks/hero-banner.css', // ] // Get allowed SVG tags for icon rendering $allowed_tags = genesis_custom_blocks()->allowed_svg_tags(); ``` -------------------------------- ### Genesis Custom Blocks PHP Template Structure Example Source: https://context7.com/studiopress/genesis-custom-blocks/llms.txt This PHP code demonstrates the structure of a block template file for Genesis Custom Blocks. It shows how to retrieve block values using `block_value()` and how to construct HTML markup with dynamic classes based on block attributes. ```php
'testimonial__avatar', 'alt' => esc_attr( $author_name ), ]); ?>
``` -------------------------------- ### Image Control for Block Fields Source: https://context7.com/studiopress/genesis-custom-blocks/llms.txt Adds an image upload control to block settings, storing the WordPress attachment ID. It facilitates retrieving the image URL or ID for display and offers functions to get different image sizes or responsive images. ```php 'Featured Image', 'control' => 'image', 'settings' => [ 'location' => 'editor', 'help' => 'Select or upload a featured image', ], ]); // In template: // block_field( 'featured-image' ) echoes the full image URL // block_value( 'featured-image' ) returns the attachment ID (integer) $image_id = block_value( 'featured-image' ); if ( $image_id ) { // Get different sizes $thumbnail = wp_get_attachment_image_src( $image_id, 'thumbnail' ); $medium = wp_get_attachment_image_src( $image_id, 'medium' ); $full = wp_get_attachment_image_src( $image_id, 'full' ); // Get image with responsive srcset echo wp_get_attachment_image( $image_id, 'large', false, [ 'class' => 'featured-img', 'alt' => 'Featured image', ]); } ``` -------------------------------- ### Customize Block Template Path with genesis_custom_blocks_template_path Source: https://context7.com/studiopress/genesis-custom-blocks/llms.txt This filter allows you to customize the directory where Genesis Custom Blocks looks for template files. It receives the current path and an array of template names. You can return a custom path, for example, from a plugin directory. ```php ``` -------------------------------- ### Retrieve Full Block Configuration (PHP) Source: https://context7.com/studiopress/genesis-custom-blocks/llms.txt Returns the complete block configuration array, which includes metadata like name, title, icon, and field definitions. ```php '; foreach ( $fields as $field_slug => $field ) { printf( "Field: %s | Control: %s | Type: %s\n", $field_slug, $field->control, $field->type ); } echo ''; } ``` -------------------------------- ### Define Testimonial Block Stylesheet (CSS) Source: https://context7.com/studiopress/genesis-custom-blocks/llms.txt This CSS file defines the styling for a testimonial block. It includes styles for the base testimonial component, a featured variation, and individual elements like quotes and author information. The file is automatically loaded when the corresponding block is rendered in WordPress. ```css /* File: blocks/testimonial/block.css */ /* Automatically loaded when the block is rendered */ .testimonial { padding: 2rem; background: #f8f9fa; border-radius: 8px; border-left: 4px solid #007bff; } .testimonial--featured { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; border-left-color: #ffd700; } .testimonial__quote { font-size: 1.25rem; font-style: italic; margin: 0 0 1.5rem; line-height: 1.6; } .testimonial__author { display: flex; align-items: center; gap: 1rem; } .testimonial__avatar { width: 60px; height: 60px; border-radius: 50%; object-fit: cover; } .testimonial__name { display: block; font-weight: 600; font-style: normal; } .testimonial__company { color: #6c757d; font-size: 0.875rem; } .testimonial__rating { margin-top: 1rem; } .star--filled { color: #ffc107; } .star--empty { color: #dee2e6; } ``` -------------------------------- ### Register New Custom Block Programmatically (PHP) Source: https://context7.com/studiopress/genesis-custom-blocks/llms.txt Shows how to register a new custom Gutenberg block using the `add_block` function. This function requires the block's unique name and an array of configuration properties like title, icon, category, keywords, and field definitions. It must be called within the `genesis_custom_blocks_add_blocks` action hook. ```php 'Testimonial', 'icon' => 'format_quote', 'category' => 'common', 'keywords' => [ 'quote', 'review', 'feedback' ], 'fields' => [ 'quote' => [ 'label' => 'Quote', 'control' => 'textarea', 'settings' => [ 'new_lines' => 'autop', 'rows' => 4, ], ], 'author-name' => [ 'label' => 'Author Name', 'control' => 'text', ], 'author-image' => [ 'label' => 'Author Photo', 'control' => 'image', ], 'rating' => [ 'label' => 'Star Rating', 'control' => 'range', 'settings' => [ 'min' => 1, 'max' => 5, 'default' => 5, ], ], ], ]); // Block with excluded post types add_block( 'page-hero', [ 'title' => 'Page Hero', 'icon' => 'image', 'category' => 'layout', 'excluded' => [ 'post' ], // Only available on pages 'fields' => [ 'background' => [ 'label' => 'Background Image', 'control' => 'image', ], ], ]); }); ``` -------------------------------- ### Define Custom Block Configuration (JSON) Source: https://context7.com/studiopress/genesis-custom-blocks/llms.txt This JSON file defines the configuration for a 'card' custom block. It specifies the block's name, title, icon, category, keywords, and the fields it will contain, such as title, content, image, and link. This configuration allows for version control and portability of block definitions. ```json // File: {theme}/blocks/blocks.json { "genesis-custom-blocks/card": { "name": "card", "title": "Content Card", "icon": "dashboard", "category": { "slug": "layout", "title": "Layout", "icon": null }, "keywords": ["box", "container", "panel"], "fields": { "title": { "name": "title", "label": "Card Title", "control": "text", "type": "string", "order": 0, "location": "editor", "width": "100" }, "content": { "name": "content", "label": "Card Content", "control": "textarea", "type": "string", "order": 1, "new_lines": "autop" }, "image": { "name": "image", "label": "Card Image", "control": "image", "type": "integer", "order": 2 }, "link": { "name": "link", "label": "Card Link", "control": "url", "type": "string", "order": 3 } } } } ``` -------------------------------- ### Retrieve Specific Field Configuration (PHP) Source: https://context7.com/studiopress/genesis-custom-blocks/llms.txt Returns the configuration array for a specific block field, providing access to its control type, label, and settings. ```php 'Download File', 'control' => 'file', 'settings' => [ 'help' => 'Select a file for download', ], ]); // In template: $file_id = block_value( 'download-file' ); if ( $file_id ) { $file_url = wp_get_attachment_url( $file_id ); $file_name = get_the_title( $file_id ); ?> Download ``` -------------------------------- ### Registering Custom Blocks Programmatically (PHP) Source: https://context7.com/studiopress/genesis-custom-blocks/llms.txt Registers custom Gutenberg blocks using the 'genesis_custom_blocks_add_blocks' action hook. This allows defining block titles, icons, categories, and fields. ```php 'Pricing Table', 'icon' => 'attach_money', 'category' => 'widgets', 'fields' => [ 'plan-name' => [ 'label' => 'Plan Name', 'control' => 'text' ], 'price' => [ 'label' => 'Price', 'control' => 'text' ], 'features' => [ 'label' => 'Features', 'control' => 'textarea' ], 'is-popular' => [ 'label' => 'Popular Plan', 'control' => 'toggle' ], ], ]); }); ?> ``` -------------------------------- ### Hook into Block Rendering with genesis_custom_blocks_render_template Source: https://context7.com/studiopress/genesis-custom-blocks/llms.txt This action fires when a block template is rendered on the front-end, excluding the editor. It's useful for enqueuing block-specific scripts or styles. The callback receives the block object and its attributes. A dynamic hook is also available for specific blocks. ```php name ) { wp_enqueue_script( 'carousel-script', get_theme_file_uri( 'js/carousel.js' ), [ 'jquery' ], '1.0.0', true // Load in footer ); } }, 10, 2 ); // Block-specific action (dynamic hook name) add_action( 'genesis_custom_blocks_render_template_carousel', function( $block, $attributes ) { // Only fires for the 'carousel' block wp_enqueue_style( 'carousel-styles', get_theme_file_uri( 'css/carousel.css' ) ); }, 10, 2 ); ?> ``` -------------------------------- ### Textarea Control for Block Fields Source: https://context7.com/studiopress/genesis-custom-blocks/llms.txt Implements a multi-line textarea field for block settings. It supports default values, placeholders, maximum length, and automatic handling of new lines for paragraph or line break formatting. ```php 'Description', 'control' => 'textarea', 'settings' => [ 'default' => '', 'placeholder' => 'Enter description...', 'maxlength' => 500, 'number_rows' => 4, 'new_lines' => 'autop', // 'autop' (paragraphs), 'autobr' (line breaks), or '' (none) ], ]); // In template with 'autop' setting: // block_field( 'description' ) outputs text wrapped in

tags ``` -------------------------------- ### URL Control for Block Fields Source: https://context7.com/studiopress/genesis-custom-blocks/llms.txt Adds a URL input field to block settings, optionally with a placeholder. The entered URL can be used for links or other external references within the block. ```php 'Button Link', 'control' => 'url', 'settings' => [ 'default' => '', 'placeholder' => 'https://example.com', ], ]); // In template: $link = block_value( 'link' ); if ( $link ) : ?> Learn More 'Layout Style', 'control' => 'select', 'settings' => [ 'options' => [ 'left' => 'Image Left', 'right' => 'Image Right', 'center' => 'Centered', 'full' => 'Full Width', ], 'default' => 'left', 'help' => 'Choose the block layout', ], ]); // In template: $layout = block_value( 'layout' ); // Returns 'left', 'right', 'center', or 'full' ?>

``` -------------------------------- ### Color Control for Block Fields Source: https://context7.com/studiopress/genesis-custom-blocks/llms.txt Integrates a color picker control for block settings, returning a hex color value. This allows users to customize the appearance of blocks with specific colors. ```php 'Background Color', 'control' => 'color', 'settings' => [ 'default' => '#ffffff', ], ]); // In template: $bg_color = block_value( 'background-color' ); // Returns hex string: '#ffffff' ?>
``` -------------------------------- ### Filtering Available Controls (PHP) Source: https://context7.com/studiopress/genesis-custom-blocks/llms.txt Filters the available control types for custom blocks using the 'genesis_custom_blocks_controls' filter. This allows removing existing controls or adding custom ones by implementing the ControlAbstract class. ```php ``` -------------------------------- ### Multiselect Control for Block Fields Source: https://context7.com/studiopress/genesis-custom-blocks/llms.txt Provides a multi-value selection field for block settings, returning an array of selected choices. This is useful for enabling multiple features or options for a block. ```php 'Display Features', 'control' => 'multiselect', 'settings' => [ 'options' => [ 'icon' => 'Show Icon', 'title' => 'Show Title', 'desc' => 'Show Description', 'button' => 'Show Button', ], 'default' => [ 'title', 'desc' ], ], ]); // In template: $features = block_value( 'features' ); // Returns array: ['title', 'desc'] if ( is_array( $features ) && in_array( 'icon', $features, true ) ) { // Render icon } ``` -------------------------------- ### Numeric Input Field for Integers (PHP) Source: https://context7.com/studiopress/genesis-custom-blocks/llms.txt Adds a numeric input field for integer values to a block. It uses the 'number' control type and shows how to retrieve the integer value in the template. ```php 'Items to Display', 'control' => 'number', 'settings' => [ 'default' => 5, ], ]); // In template: $count = block_value( 'items-count' ); // Returns integer ?> ``` -------------------------------- ### Add Text Control Field (PHP) Source: https://context7.com/studiopress/genesis-custom-blocks/llms.txt Registers a 'text' control type field for a block. This control allows for single-line text input with options for location, width, help text, default value, placeholder, and maximum length. ```php 'Headline', 'control' => 'text', 'settings' => [ 'location' => 'editor', // 'editor' or 'inspector' 'width' => '100', // 25, 50, 75, or 100 'help' => 'Enter a compelling headline', 'default' => 'Welcome!', 'placeholder' => 'Enter headline...', 'maxlength' => 100, ], ]); // In template: // block_field( 'headline' ) echoes escaped string // block_value( 'headline' ) returns raw string ``` -------------------------------- ### Toggle Control for Block Fields Source: https://context7.com/studiopress/genesis-custom-blocks/llms.txt Implements a boolean toggle switch for block settings, returning either true or false. This is ideal for enabling or disabling features within a block. ```php 'Enable Shadow', 'control' => 'toggle', 'settings' => [ 'default' => true, 'help' => 'Add a drop shadow to the container', ], ]); // In template: $show_shadow = block_value( 'show-shadow' ); // Returns boolean true/false $classes = [ 'card' ]; if ( $show_shadow ) { $classes[] = 'card--shadow'; } ?>
``` -------------------------------- ### Add Field to Existing Block (PHP) Source: https://context7.com/studiopress/genesis-custom-blocks/llms.txt Demonstrates how to add a new field to an already registered block using the `add_field` function. This is useful for modular block definitions or extending blocks defined elsewhere. Fields can be configured with labels, controls, order, and specific settings. This function also needs to be called within the `genesis_custom_blocks_add_blocks` action hook. ```php 'Company Name', 'control' => 'text', 'order' => 3, ]); add_field( 'testimonial', 'featured', [ 'label' => 'Featured Testimonial', 'control' => 'toggle', 'order' => 5, 'settings' => [ 'default' => false, ], ]); // Add a select field with predefined choices add_field( 'testimonial', 'style', [ 'label' => 'Display Style', 'control' => 'select', 'order' => 6, 'settings' => [ 'options' => [ 'card' => 'Card Layout', 'inline' => 'Inline Quote', 'fullwidth' => 'Full Width Banner', ], 'default' => 'card', ], ]); }); ``` -------------------------------- ### Inner Blocks Control for Nesting (PHP) Source: https://context7.com/studiopress/genesis-custom-blocks/llms.txt Allows nesting of other Gutenberg blocks inside a custom block. It uses the 'inner_blocks' control type. The content of inner blocks is automatically rendered in the template. ```php 'Content Area', 'control' => 'inner_blocks', 'settings' => [ 'help' => 'Add blocks inside this container', ], ]); // In template (inner blocks content is automatically rendered) // The inner blocks content is available through the template automatically ?> ``` -------------------------------- ### Checkbox Input Field (PHP) Source: https://context7.com/studiopress/genesis-custom-blocks/llms.txt Adds a single checkbox that returns a boolean true/false value. It uses the 'checkbox' control type and demonstrates checking the value in the template. ```php 'Mark as Featured', 'control' => 'checkbox', 'settings' => [ 'default' => false, ], ]); // In template: if ( block_value( 'is-featured' ) ) { echo 'Featured'; } ?> ``` -------------------------------- ### Range Control for Block Fields Source: https://context7.com/studiopress/genesis-custom-blocks/llms.txt Adds a slider input for selecting numeric values within a specified range. The selected integer value can be used for dynamic styling or layout adjustments. ```php 'Number of Columns', 'control' => 'range', 'settings' => [ 'min' => 1, 'max' => 6, 'step' => 1, 'default' => 3, 'help' => 'Set the grid column count', ], ]); // In template: $columns = block_value( 'columns' ); // Returns integer between 1-6 ?>
``` -------------------------------- ### Output Block Field Value (PHP) Source: https://context7.com/studiopress/genesis-custom-blocks/llms.txt Outputs or returns a block field value. By default, it echoes the escaped value. Setting the second parameter to false returns the raw value. ```php
<?php block_field( 'author-name' ); ?>
``` -------------------------------- ### Email Input Field with Validation (PHP) Source: https://context7.com/studiopress/genesis-custom-blocks/llms.txt Adds an email input field to a block with validation. It uses the 'email' control type and demonstrates how to retrieve and validate the email value in the template. ```php 'Contact Email', 'control' => 'email', 'settings' => [ 'placeholder' => 'email@example.com', ], ]); // In template: $email = block_value( 'contact-email' ); if ( is_email( $email ) ) : ?> Contact Us ``` -------------------------------- ### Radio Button Group Control (PHP) Source: https://context7.com/studiopress/genesis-custom-blocks/llms.txt Adds a radio button group for mutually exclusive single selection. It uses the 'radio' control type and allows defining options and a default value. The selected value is retrieved in the template. ```php 'Text Alignment', 'control' => 'radio', 'settings' => [ 'options' => [ 'left' => 'Left', 'center' => 'Center', 'right' => 'Right', ], 'default' => 'left', ], ]); // In template: $alignment = block_value( 'alignment' ); ?>
?> ``` -------------------------------- ### Modify Available Blocks with genesis_custom_blocks_available_blocks Source: https://context7.com/studiopress/genesis-custom-blocks/llms.txt This filter enables modification of the block list before they are registered with WordPress. It receives an array of blocks and can be used to hide blocks from specific user roles or alter block configurations, such as adding keywords. ```php ``` -------------------------------- ### Retrieve Raw Block Field Value (PHP) Source: https://context7.com/studiopress/genesis-custom-blocks/llms.txt Returns the raw value of a block field without echoing it, allowing for custom processing and transformations. ```php

``` -------------------------------- ### Modifying Field Values with Filters (PHP) Source: https://context7.com/studiopress/genesis-custom-blocks/llms.txt Modifies field values before they are output in templates using the 'genesis_custom_blocks_field_value' filter. This is useful for transformations, such as applying a CDN to image URLs or sanitizing textarea output. ```php ``` -------------------------------- ### Add Custom Block Fields with genesis_custom_blocks_default_fields Source: https://context7.com/studiopress/genesis-custom-blocks/llms.txt This filter allows you to add custom attributes to Genesis Custom Blocks that can be accessed using the `block_field()` function. It takes an array of default fields and the block name as arguments. You can add new fields by assigning them a data type (e.g., 'string'). ```php ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.