Design System is here - Read the release post

Learn GeneratePress

Developers

Admin dashboard and platform

Hooks for the GenerateBlocks admin screens, the GenerateBlocks settings, the plugin’s feature flags and the scans that find where a style, token, condition or form is used.

Jump to

Dashboard screens

generateblocks_dashboard_screens

GB Free — since GenerateBlocks 1.2. GenerateBlocks Pro uses it for its own pages.

The generateblocks_dashboard_screens filter lists the admin screens that get the GenerateBlocks dashboard styles and scripts. Add the ID of a screen of your own to give it the same look.

Parameters: $screens (array of admin screen IDs). Default: generateblocks_page_generateblocks-settings. GenerateBlocks Pro adds its Asset Library, Global Styles, Forms, Editor Access, Conditions and Overlays screens.

add_filter( 'generateblocks_dashboard_screens', function( $screens ) {
    $screens[] = 'generateblocks_page_my-plugin-page';

    return $screens;
} );

Related: generateblocks_dashboard_header_icon Guide: Getting Started with GenerateBlocks

generateblocks_dashboard_header_icon

GB Free — since GenerateBlocks 2.4.

The generateblocks_dashboard_header_icon filter changes the icon in the header of a GenerateBlocks dashboard screen. Return SVG markup. It is sanitized with a list of allowed SVG tags and attributes, and it is shown white on an accent tile.

Parameters: $icon (string, SVG markup), $screen_id (string, the current admin screen ID). Default: the GenerateBlocks logo.

add_filter( 'generateblocks_dashboard_header_icon', function( $icon, $screen_id ) {
    if ( 'generateblocks_page_my-plugin-page' === $screen_id ) {
        return '<svg aria-hidden="true" viewBox="0 0 24 24"><circle cx="12" cy="12" r="10"/></svg>';
    }

    return $icon;
}, 10, 2 );

Related: generateblocks_dashboard_screens Guide: Getting Started with GenerateBlocks

generateblocks_show_upgrade_menu

GB Free — since GenerateBlocks 0.1.

The generateblocks_show_upgrade_menu filter chooses whether the Upgrade item shows in the GenerateBlocks admin menu.

Parameters: $show (bool). Default: true when GenerateBlocks Pro isn’t active, otherwise false.

add_filter( 'generateblocks_show_upgrade_menu', '__return_false' );

Related: generateblocks_dashboard_screens Guide: GenerateBlocks Pro

Back to top

Settings

The GenerateBlocks settings page holds the container width, the Google Fonts switch and the responsive preview sync. They are saved in the generateblocks option.

generateblocks_settings_area

GB Free — since GenerateBlocks 0.1.

The generateblocks_settings_area action fires inside the settings page, in the settings area. Echo your own settings markup here.

Parameters: none. Default: none. It is an action.

add_action( 'generateblocks_settings_area', function() {
    echo '<p>' . esc_html__( 'My plugin settings go here.', 'my-plugin' ) . '</p>';
} );

Related: generateblocks.dashboard.settings Guide: Getting Started with GenerateBlocks

generateblocks_option_defaults

GB Free — since GenerateBlocks 0.1.

The generateblocks_option_defaults filter sets the list of settings GenerateBlocks knows about and their default values. A setting that isn’t in this list isn’t saved from the settings page.

Parameters: $defaults (array of setting name => default value). Default: container_width is 1100, sync_responsive_previews is true and disable_google_fonts is true.

add_filter( 'generateblocks_option_defaults', function( $defaults ) {
    $defaults['my_setting'] = 'my-default';

    return $defaults;
} );

Related: generateblocks_option_sanitize_callbacks Guide: Getting Started with GenerateBlocks

generateblocks_option_sanitize_callbacks

GB Free — since GenerateBlocks 1.2.

The generateblocks_option_sanitize_callbacks filter sets how each setting is sanitized before it is saved.

Parameters: $callbacks (array of setting name => callable). Default: container_width uses absint, and sync_responsive_previews, disable_google_fonts and gb_use_v1_blocks use rest_sanitize_boolean. A setting with no callable is sanitized with sanitize_text_field.

add_filter( 'generateblocks_option_sanitize_callbacks', function( $callbacks ) {
    $callbacks['my_setting'] = 'sanitize_key';

    return $callbacks;
} );

Related: generateblocks_option_defaults Guide: Getting Started with GenerateBlocks

generateblocks.dashboard.beforeSettings

GB Free

The generateblocks.dashboard.beforeSettings filter adds content above the settings panel on the GenerateBlocks settings page.

Parameters: content (an empty string by default). Default: an empty string.

const { createElement } = wp.element;

wp.hooks.addFilter(
    'generateblocks.dashboard.beforeSettings',
    'my-plugin/before-settings',
    () => createElement( 'p', null, 'Shown above the settings.' )
);

Related: generateblocks.dashboard.afterSettings Guide: Getting Started with GenerateBlocks

generateblocks.dashboard.settings

GB Free

The generateblocks.dashboard.settings filter adds controls inside the settings panel, after the built-in settings and before the Save button.

Parameters: content (an empty string by default), context (object with settings, the current values, and setSettings, which updates them). Default: an empty string.

const { createElement } = wp.element;
const { ToggleControl } = wp.components;

wp.hooks.addFilter(
    'generateblocks.dashboard.settings',
    'my-plugin/settings',
    ( content, { settings, setSettings } ) => createElement( ToggleControl, {
        label: 'My setting',
        checked: !! settings.my_setting,
        onChange: ( value ) => setSettings( { ...settings, my_setting: value } ),
    } )
);

Related: generateblocks_option_defaults Guide: Getting Started with GenerateBlocks

generateblocks.dashboard.afterSettings

GB Free

The generateblocks.dashboard.afterSettings filter adds content below the settings panel on the GenerateBlocks settings page.

Parameters: content (an empty string by default), context (object with settings and setSettings). Default: an empty string.

const { createElement } = wp.element;

wp.hooks.addFilter(
    'generateblocks.dashboard.afterSettings',
    'my-plugin/after-settings',
    () => createElement( 'p', null, 'Shown below the settings.' )
);

Related: generateblocks.dashboard.beforeSettings Guide: Getting Started with GenerateBlocks

Back to top

Asset Library (Pro)

generateblocks_asset_library_area

GB Pro — since GenerateBlocks Pro 1.0.

The generateblocks_asset_library_area action fires inside the Asset Library page. Echo your own markup here.

Parameters: none. Default: none. It is an action.

add_action( 'generateblocks_asset_library_area', function() {
    echo '<p>' . esc_html__( 'Notes for the team.', 'my-plugin' ) . '</p>';
} );

Related: generateblocks_settings_area Guide: Asset Library

Back to top

Platform

generateblocks_supported_features

GB Free

The generateblocks_supported_features filter changes the map of features GenerateBlocks reports through generateblocks_supports( $feature ). Companion plugins call that function to find out what the free plugin supports, instead of checking its version number, so a mismatch between plugin versions degrades gracefully.

Parameters: $features (array of feature key => bool). Default: one feature, block-inspector-slot, which is true. It means the v2 blocks render their inspector through a wrapper that exposes generateblocks.editor.inspectorControls and generateblocks.editor.areInspectorControlsDisabled.

if ( function_exists( 'generateblocks_supports' ) && generateblocks_supports( 'block-inspector-slot' ) ) {
    // Safe to rely on the inspector filters.
}

Related: generateblocks.editor.inspectorControls Guide: Getting Started with GenerateBlocks

generateblocks_permissions

GB Free

The generateblocks_permissions filter changes the permissions object GenerateBlocks sends to the block editor, which is available there as gbPermissions. It is frozen once it has been printed.

Parameters: $permissions (array). Default: isAdminUser (the current user can manage options), canEditPosts, isGbProActive and isGpPremiumActive.

add_filter( 'generateblocks_permissions', function( $permissions ) {
    $permissions['canUseMyFeature'] = current_user_can( 'edit_others_posts' );

    return $permissions;
} );

Related: generateblocks_user_can_author_dynamic_data Guide: Getting Started with GenerateBlocks

Back to top

Usage scans (Pro)

GenerateBlocks Pro scans your recent posts to show where a condition, Global Style, Design Token or form is used. These two filters apply to all of those scans.

generateblocks_usage_search_post_types

GB Pro

The generateblocks_usage_search_post_types filter changes the post types that a usage scan searches.

Parameters: $post_types (array of post type names), $context (string: conditions, styles or design-tokens). Default: every post type that supports the editor, except revision, attachment and nav_menu_item.

add_filter( 'generateblocks_usage_search_post_types', function( $post_types, $context ) {
    return array_values( array_diff( $post_types, [ 'my_archive_type' ] ) );
}, 10, 2 );

Related: generateblocks_usage_search_max_posts Guide: Global Styles

generateblocks_usage_search_max_posts

GB Pro

The generateblocks_usage_search_max_posts filter sets the most posts a usage scan looks through, so the scan stays fast on large sites. When it is reached, the dashboard says the results are limited.

Parameters: $max_posts (int). Default: 5000.

add_filter( 'generateblocks_usage_search_max_posts', function( $max_posts ) {
    return 10000;
} );

Related: generateblocks_usage_search_post_types Guide: Global Styles

Back to top