Filters
A normaliser makes different browsers render a website's CSS consistently, by providing a standard set of CSS rules that are compatible with all browsers. This ensures that the layout and styling of a website looks the same across different browsers and devices, by resetting and normalising the default styles applied by the browser.
If you want to provide your own normaliser for the frontend, use the following snippet:
add_filter('cc_normaliser_frontend', function ($arguments) {
$normaliser_frontend = wp_upload_dir()['baseurl'] . '/custom/normaliser.css';
return $normaliser_frontend;
});
If you want to provide your own normaliser for the editor, use the following snippet:
add_filter('cc_normaliser_editor', function ($arguments) {
$normaliser_editor = wp_upload_dir()['basedir'] . '/custom/normaliser-editor.css';
return $normaliser_editor;
});
The query args filter allows you to modify the query arguments before they are processed in the Query block.
add_filter( 'cwicly/query/args', function( $query_args, $attributes, $id ) {
// Change the post_type to location if the user is logged in
if ($id === 'query-c0d6112' && is_user_logged_in()) {
$query_args['post_type'] = array('location');
}
return $query_args;
}, 10, 3 );
The filter accepts three arguments:
- 1.
$query_args
: an associative array containing the dissected$query
: an array of the query variables and their respective values. - 2.
$attributes
: an associative array containing all set and unset attributes on the specific Query block - 3.
$id
: a string reference to the Query block ID
The shortcode whitelist filter allows you to specify the shortcodes that you consider safe to run when using Frontend Rendering with Cwicly blocks.
add_filter('cwicly/frontend/shortcodes_whitelist', function ($array) {
// Add two shortcodes to the list if the user is logged in, otherwise just one
if (is_user_logged_in()) {
$array[] = 'my_public_shortcode';
$array[] = 'my_private_shortcode';
} else {
$array[] = 'my_public_shortcode';
}
return $array;
});
The filter accepts one argument:
- 1.
$array
: an empty index array
The custom code priority constant allows you to specify the priority with which the Cwicly Custom Code snippets are loaded. This is useful in the eventuality you want to load custom snippets before/after specific items.
Simply define
CC_CUSTOM_CODE_PRIORITY
constant in your wp-config.php
file to the desired value.define('CC_CUSTOM_CODE_PRIORITY', 5);
Remember to insert the previous definition before the famous line:
/* That's all, stop editing! Happy publishing. */
You can add a list of custom classes to the Class Selector within its own column. The filter's main use if for plugin developers who wish to integrate their framework classes inside Cwicly without having to manually modify different database tables.
function cwicly_plugin_classes_example( $plugin_classes ) {
// Add a new entry to the $plugin_classes array with a unique key.
$plugin_classes['pluginName'] = array(
'name' => 'Plugin Name', // Set the label.
// Specify a custom color palette for the class list view
// 'colors' => array(
// 'list' => array(
// 'light' => array(
// 'background' => 'your-color',
// 'color' => 'your-color',
// ),
// 'dark' => array(
// 'background' => 'your-color',
// 'color' => 'your-color',
// ),
// ),
// ),
// Define an array of CSS classes under the 'classes' key.
'classes' => array(
'first-class',
'second-class',
),
);
// Return the modified $plugin_classes array.
return $plugin_classes;
}
add_filter( 'cwicly_plugin_classes', 'cwicly_plugin_classes_example', 10, 1 );
Last modified 8d ago