Skip to content

Instantly share code, notes, and snippets.

View Tabrisrp's full-sized avatar

Rémy Perona Tabrisrp

View GitHub Profile
@Tabrisrp
Tabrisrp / minify-inline-js.php
Last active February 20, 2018 20:49
Minify inline JS
<?php
add_filter( 'rocket_minify_html_options', 'wp_rocket_minify_inline_js' );
function wp_rocket_minify_inline_js( $options ) {
$options['jsMinifier'] = 'rocket_minify_inline_js';
return $options;
}
<?php
$user_agent = $_SERVER['HTTP_USER_AGENT'];
if ( strpos( $_SERVER['HTTP_USER_AGENT'], 'WP-Rocket' ) === false ) {
if ( strpos( $_SERVER['HTTP_X_ROCKET'], 'WP-Rocket' ) === false ) {
die( 'BAD_UA_XR: ' . ( isset( $_SERVER['HTTP_USER_AGENT'] ) ? htmlspecialchars( $_SERVER['HTTP_USER_AGENT'] ) : 'not set' ) . ' & ' . ( isset( $_SERVER['HTTP_X_ROCKET'] ) ? htmlspecialchars( $_SERVER['HTTP_X_ROCKET'] ) : 'not set' ) );
}
$user_agent = $_SERVER['HTTP_X_ROCKET'];
}
@Tabrisrp
Tabrisrp / main.js
Created February 1, 2018 15:45
Problematic JS file
// ================================================================================== //
// # Document on Ready
// # Document on Resize
// # Document on Scroll
// # Document on Load
// # Header Settings
@Tabrisrp
Tabrisrp / rocket-exclude-automatic-generation.php
Created December 22, 2017 16:20
Exclude specific post type/taxonomy from automatic critical CSS generation
<?php
function wp_rocket_cpcss_exclude_post_type( $excluded_post_types ) {
$excluded_post_types[] = 'page';
return $excluded_post_types;
}
add_filter( 'rocket_cpcss_excluded_post_types', 'wp_rocket_cpcss_exclude_post_type' );
function wp_rocket_cpcss_exclude_taxonomy( $excluded_taxonomies ) {
<?php
defined( 'ABSPATH' ) or die();
/**
* Plugin Name: WP Rocket | Fix Polylang conflict
* Description: Prevent warning when adding a new translation with Polylang
* Author: WP Rocket Support Team
* Author URI: https://wp-rocket.me/
* License: GNU General Public License v3 or later
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
*/
@Tabrisrp
Tabrisrp / rocket-clean-cache-polylang-redirect-lang.php
Created October 3, 2017 20:14
Correctly clean cache when front page URL contains page name in Polylang
<?php
function wp_rocket_clean_domain_polylang( $urls, $lang ) {
foreach( $urls as $key => $url ) {
if ( empty( $lang ) ) {
$urls[ $key ] = parse_url( $url, PHP_URL_HOST );
} else {
if ( function_exists( 'PLL' ) ) {
$urls[ $key ] = PLL()->links->get_home_url( $lang, true );
}
}
@Tabrisrp
Tabrisrp / rocket-clear-user-cache-logout
Created September 26, 2017 18:29
Clear cache on logout
function wp_rocket_clear_user_cache_logout() {
$user = wp_get_current_user();
rocket_clean_user( $user->ID );
}
add_action( 'clear_auth_cookie', 'wp_rocket_clear_user_cache_logout' );
<?php
/**
* Plugin Name: No cache after logged-in user comment
* Description: Don't use cache after a user made a comment
* Author: WP Rocket team
* License: GNU General Public License v3 or later
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
*/
// Basic security, prevents file from being loaded directly.
@Tabrisrp
Tabrisrp / rocket-cache-feed.php
Last active October 11, 2018 14:59
Allow caching of WP feed by WP Rocket
function wp_rocket_cache_feed( $uri ) {
$feed = '/(.+/)?' . $GLOBALS['wp_rewrite']->feed_base . '/?';
if ( in_array( $feed, $uri ) ) {
$uri = array_flip( $uri );
unset( $uri[ $feed ] );
$uri = array_flip( $uri );
}
return $uri;
}
<?php
add_filter( 'rocket_cache_busting_filename', 'wp_rocket_filter_cache_busting_filename' );
function wp_rocket_filter_cache_busting_filename( $filename ) {
$filename = str_replace( '../', '', $filename );
return $filename;
}