Skip to content

Commit

Permalink
Introduce filter to conditionally load block styles (godaddy-wordpres…
Browse files Browse the repository at this point in the history
…s#1173)

* use filter to conditionally load block styles

* update to reference utility styles

* fix spacing

* update documentation with details on filters for pro users

* Use core provided __return_false callback
  • Loading branch information
AnthonyLedesma authored and jrtashjian committed Dec 14, 2019
1 parent 87f245b commit 5a3eefe
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,36 @@ The vision for CoBlocks is to create a suite of WordPress blocks and tools to he
1. You'll need to install the [Gutenberg](https://wordpress.org/plugins/gutenberg/) plugin if you are not running WordPress 5.0+
2. Download CoBlocks from the [WordPress plugin directory](https://wordpress.org/plugins/coblocks/).

### Advanced Controls

Disable CoBlocks utility styes with an optional filter.
```php
/**
* Disable block utility styles.
*/
add_filter( 'coblocks_utility_styles_enabled', '__return_false' );
```

Disable sending of email upon Form block submission.
```php
/**
* Disable form submission emails.
*/
add_filter( 'coblocks_form_disable_emails', '__return_true' );

/**
* Set a custom success message to mimic a successful form submission
*
* @return string Form submission success message
*/
function coblocks_form_sent_message() {

return __( 'Your message was sent.', 'textdomain' );

}
add_filter( 'coblocks_form_sent_notice', 'coblocks_form_sent_message' );
```

## Development

1. Clone the GitHub repository: `https://github.com/godaddy-wordpress/coblocks.git`
Expand Down
17 changes: 17 additions & 0 deletions includes/class-coblocks-block-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,23 @@ public function block_assets() {
COBLOCKS_VERSION
);

/**
* Filters whether to load utilitiy styles.
*
* @param bool $load_utility_styles whether the utility css should be loaded. Default true.
*/
$load_utility_styles = (bool) apply_filters( 'coblocks_utility_styles_enabled', true );

if ( $load_utility_styles ) {

// Mock wp_enqueue_style for utility styles.
wp_enqueue_style(
$this->slug . '-utilities',
$this->url . '/dist/utilities.style.build.css',
array(),
COBLOCKS_VERSION
);
};
}

/**
Expand Down

0 comments on commit 5a3eefe

Please sign in to comment.