Each built-in condition type has a filter for its list of rules. Every filter receives and returns an array of rule key => label. The labels fill the Rule select in the editor. To change the rules of every type from one place, use generateblocks_condition_rules.
How a rule you add behaves depends on the type, because the type’s evaluator decides what a rule key means:
- Field types (post meta, user meta, options, cookie, query parameter): the rule key is the name of the field, so adding a key adds a ready-made choice.
- Language and user role: a locale (such as
sv_SE), a role slug or acap:capability key is checked directly, so adding one works. - Author, device, date and time, location, referrer: the evaluator only understands its own rule keys. Use these filters to remove or relabel rules, not to add new ones.
Jump to
- Field types
- Visitor types
- Other types
Field types
generateblocks_post_meta_rules
GB Pro
The generateblocks_post_meta_rules filter changes the rules of the Post Meta condition.
Parameters: $rules (array of rule key => label). Default: custom (Custom Meta Key), _thumbnail_id (Has Featured Image) and _wp_page_template (Page Template).
add_filter( 'generateblocks_post_meta_rules', function( $rules ) {
$rules['event_date'] = __( 'Event date', 'my-plugin' );
return $rules;
} );
Related: generateblocks_user_meta_rules, generateblocks_condition_rules Guide: Block Conditions
generateblocks_user_meta_rules
GB Pro
The generateblocks_user_meta_rules filter changes the rules of the User Meta condition. The condition is only met for logged in users.
Parameters: $rules (array of rule key => label). Default: custom (Custom Meta Key), first_name, last_name, nickname, description and show_admin_bar_front.
add_filter( 'generateblocks_user_meta_rules', function( $rules ) {
$rules['membership_level'] = __( 'Membership level', 'my-plugin' );
return $rules;
} );
Related: generateblocks_post_meta_rules, generateblocks_author_rules Guide: Block Conditions
generateblocks_options_rules
GB Pro
The generateblocks_options_rules filter changes the rules of the Options condition, which compares WordPress options.
Parameters: $rules (array of rule key => label). Default: custom (Custom Option), blogname, blogdescription, timezone_string, date_format and time_format.
add_filter( 'generateblocks_options_rules', function( $rules ) {
$rules['my_plugin_banner'] = __( 'Show banner', 'my-plugin' );
return $rules;
} );
Related: generateblocks_post_meta_rules Guide: Block Conditions
generateblocks_cookie_rules
GB Pro
The generateblocks_cookie_rules filter changes the rules of the Cookie condition. Add the names of cookies you check often.
Parameters: $rules (array of rule key => label). Default: custom (Custom Cookie), wordpress_logged_in and comment_author.
add_filter( 'generateblocks_cookie_rules', function( $rules ) {
$rules['my_consent'] = __( 'Consent cookie', 'my-plugin' );
return $rules;
} );
Related: generateblocks_query_arg_rules Guide: Block Conditions
generateblocks_query_arg_rules
GB Pro
The generateblocks_query_arg_rules filter changes the rules of the Query Parameter condition. Add the names of URL parameters you check often.
Parameters: $rules (array of rule key => label). Default: custom (Custom Parameter).
add_filter( 'generateblocks_query_arg_rules', function( $rules ) {
$rules['utm_source'] = __( 'UTM source', 'my-plugin' );
return $rules;
} );
Related: generateblocks_referrer_rules Guide: Block Conditions
Visitor types
generateblocks_language_rules
GB Pro
The generateblocks_language_rules filter changes the rules of the Language condition. A locale key you add is compared with the current locale, which also follows WPML and Polylang when they are active.
Parameters: $rules (array of rule key => label). Default: locale (Full Locale), language (Language Code), rtl (RTL Language) and custom (Custom Locale), then 20 common locales such as en_US and fr_FR, then any other installed language.
add_filter( 'generateblocks_language_rules', function( $rules ) {
$rules['sv_SE'] = __( 'Swedish', 'my-plugin' );
return $rules;
} );
Related: generateblocks_location_rules Guide: Block Conditions
generateblocks_user_role_rules
GB Pro
The generateblocks_user_role_rules filter changes the rules of the User Role condition. A role slug is matched against the user’s roles, and a key starting with cap: is checked as a capability.
Parameters: $rules (array of rule key => label). Default: general:logged_in, general:logged_out, every editable role, and these capabilities as cap: keys: edit_posts, edit_pages, edit_published_posts, edit_others_posts, publish_posts, manage_options and moderate_comments.
add_filter( 'generateblocks_user_role_rules', function( $rules ) {
$rules['cap:upload_files'] = __( 'Can Upload Files', 'my-plugin' );
return $rules;
} );
Related: generateblocks_user_meta_rules Guide: Block Conditions
generateblocks_author_rules
GB Pro
The generateblocks_author_rules filter changes the rules of the Author condition, which checks the author of the current post.
Parameters: $rules (array of rule key => label). Default: author_id, author_name, author_meta (Author Meta Key), first_name, last_name, nickname and description.
add_filter( 'generateblocks_author_rules', function( $rules ) {
unset( $rules['description'] );
return $rules;
} );
Related: generateblocks_user_meta_rules Guide: Block Conditions
generateblocks_device_rules
GB Pro
The generateblocks_device_rules filter changes the rules of the Device condition.
Parameters: $rules (array of rule key => label). Default: mobile, tablet, desktop, ios and android.
add_filter( 'generateblocks_device_rules', function( $rules ) {
unset( $rules['android'] );
return $rules;
} );
Related: generateblocks_language_rules Guide: Block Conditions
Other types
generateblocks_date_time_rules
GB Pro
The generateblocks_date_time_rules filter changes the rules of the Date & Time condition.
Parameters: $rules (array of rule key => label). Default: current_date, current_time, day_of_week and time_of_day (hidden in the interface, kept for backward compatibility).
add_filter( 'generateblocks_date_time_rules', function( $rules ) {
unset( $rules['time_of_day'] );
return $rules;
} );
Related: generateblocks_language_rules Guide: Block Conditions
generateblocks_location_rules
GB Pro
The generateblocks_location_rules filter changes the rules of the Location condition.
Parameters: $rules (array of rule key => label). Default: general:site, general:front_page, general:blog, general:singular, general:archive, general:author, general:date, general:search, general:no_results and general:404, then child_of and parent_of. For each public post type, a post:{type} rule and, when it has an archive, an archive:{type} rule. For each public taxonomy, a taxonomy:{taxonomy} archive rule and a post_terms:{taxonomy} rule.
add_filter( 'generateblocks_location_rules', function( $rules ) {
unset( $rules['general:no_results'] );
return $rules;
} );
Related: generateblocks_condition_rules Guide: Block Conditions
generateblocks_referrer_rules
GB Pro
The generateblocks_referrer_rules filter changes the rules of the Referrer condition.
Parameters: $rules (array of rule key => label). Default: direct (Direct Traffic, no referrer) and custom (Custom Referrer).
add_filter( 'generateblocks_referrer_rules', function( $rules ) {
$rules['direct'] = __( 'No referrer', 'my-plugin' );
return $rules;
} );
Related: generateblocks_query_arg_rules Guide: Block Conditions