-
Notifications
You must be signed in to change notification settings - Fork 46
Minit Action and Filter Hooks
Viktor Szépe edited this page Nov 30, 2016
·
5 revisions
Called when the global cache gets purged.
This is not called but hooked by Minit, you may clear the cache with do_action( 'minit-cache-purge-delete' );
@todo create a fallback
Disable async script loading. (boolean)
Exclude specific style and script handles. (array)
// Exclude handles that are known to cause problems
add_filter( 'minit-exclude-js', 'minit_exclude_defaults' );
function minit_exclude_defaults( $handles ) {
$exclude = array(
'this-is-a-handle-of-a-script-you-want-to-exclude',
);
return array_merge( $exclude, $handles );
}
Modify minited file URL-s.
Change the content of minited files.
add_filter( 'minit-content-js', 'minit_jsqueeze' );
add_filter( 'minit-content-css', 'minit_cssmin' );
function minit_jsqueeze( $javascript ) {
// https://github.com/tchwork/jsqueeze
require_once 'lib/JSqueeze.php';
$jz = new Patchwork\JSqueeze();
$content = $jz->squeeze( $javascript, true, true, false );
return $content;
}
function minit_cssmin( $stylesheet ) {
// https://github.com/tubalmartin/YUI-CSS-compressor-PHP-port
require_once 'lib/cssmin.php';
$compressor = new CSSmin();
$content = $compressor->run($content);
return $content;
}
Default cache expiration time of all minited files' data.
Cache expiration time of minited style's and script's data.
Support custom directory structure.
add_filter( 'minit-asset-local-path', 'minit_custom_content_dir', 10, 2 );
function minit_custom_content_dir( $local_path, $item_url ) {
// Bail out if get_local_path_from_url() succeeded
if ( false !== $local_path ) {
return $local_path;
}
// Replace custom MU plugin URL
$full_path = str_replace( WPMU_PLUGIN_URL, WPMU_PLUGIN_DIR, $item_url );
// Replace custom plugin URL
$full_path = str_replace( plugins_url(), WP_PLUGIN_DIR, $full_path );
// Replace custom theme URL
$full_path = str_replace( get_theme_root_uri(), get_theme_root(), $full_path );
// Replace remaining custom wp-content URL
$full_path = str_replace( content_url(), WP_CONTENT_DIR, $full_path );
if ( file_exists( $full_path ) ) {
return $full_path;
}
return false;
}