PHP hooks
Byte fires these hooks for site code. Add them in a must-use plugin or your
theme’s functions.php, not in a snippet, because Byte reads most of them
before snippets run. Their parameters and return values are listed in the
hooks reference.
Where snippets come from
sleekByte/snippets/paths returns the source folders Byte reads snippets
from. Sources explains the entries and where
new files go.
add_filter('sleekByte/snippets/paths', function ($sources) {
$sources[] = [
'name' => 'Theme Snippets',
'path' => get_stylesheet_directory() . '/snippets',
'sort' => 50,
];
return $sources;
});
Defaults for snippets
sleekByte/snippets/defaults/context sets the context of every snippet whose
snippet.json has no context, frontend by default. Return a context or a
list of them:
add_filter('sleekByte/snippets/defaults/context', function ($context) {
return wp_get_environment_type() === 'staging' ? ['admin'] : $context;
});
sleekByte/snippets/defaults/hook sets the default hook, init. PHP files
without a hook of their own or of their snippet run on it, and the CSS, SCSS
and JavaScript files of snippets without conditions are registered on it. A
front-end-only hook such as wp therefore also stops those stylesheets and
scripts in wp-admin and the block editor, and every PHP file without a hook in
REST and AJAX requests, which never fire wp.
sleekByte/snippets/defaults/php/hook receives the hook each PHP file has
already resolved, its own, its snippet’s or the default, and returns the one
it runs on. Unlike the default hook it also replaces a hook set in
snippet.json:
add_filter('sleekByte/snippets/defaults/php/hook', function ($hook) {
return $hook === 'init' ? 'wp_loaded' : $hook;
});
Byte registers snippet files during after_setup_theme, so none of these
filters can move a file onto a hook that has already fired.
Git history
sleekByte/snippets/git turns per-snippet history on; it is off by default.
History describes what it records.
add_filter('sleekByte/snippets/git', '__return_true');
Boot and lifecycle
sleekByte/init fires once Byte has booted, with the Byte instance, which
the sleekByte() function also returns. sleekByte/activated fires when Byte
is activated and sleekByte/deactivated when it is deactivated; deactivating
keeps every snippet.
add_action('sleekByte/init', function ($byte) {
// Byte's CLI commands, snippet runtime and REST routes are registered.
});
An exported plugin fires its own copies of the snippet filters under a prefix unique to it, so these hooks do not reach it.