Pilot-in / PiloPress

The most advanced WordPress Page Builder using Advanced Custom Fields & TailwindCSS
https://www.pilopress.com
63 stars 11 forks source link

Enhance TailwindCSS classes scan with generated cache files (WP Rocket...) #231

Open DamChtlv opened 1 year ago

DamChtlv commented 1 year ago

Some TailwindCSS classes are not found when they are only existing in back-office (example: text styles, width/height/padding classes...) To enhance the scan detection, it's possible to scan WP Rocket generated html cache files to find some classes which were only available in there.

Proof of concept using the Pilo'Press filter: pip/tailwind_api/content_to_scan :
(tested on Sunna)

// Tell Pilo'Press to scan WP Rocket cache files to find missing TailwindCSS classes
add_filter( 'pip/tailwind_api/content_to_scan', 'scan_cache_files_for_tailwind_classes' );
function scan_cache_files_for_tailwind_classes( $contents_to_scan ) {

    // Home page
    $contents_to_scan[] = trailingslashit( WP_CONTENT_DIR ) . 'cache/wp-rocket/**/*.html';

    // First level (posts / pages)
    $contents_to_scan[] = trailingslashit( WP_CONTENT_DIR ) . 'cache/wp-rocket/**/**/*.html';

    // Second level (post-types / terms)
    $contents_to_scan[] = trailingslashit( WP_CONTENT_DIR ) . 'cache/wp-rocket/**/**/**/*.html';

    return $contents_to_scan;
}

Those 3 new paths should be added here: https://github.com/Pilot-in/PiloPress/blob/ff1e79e67cf9abd6ce5e1fce4b087d8a094f44da/includes/classes/admin/modules/class-tailwind.php#L819-L832