Skip to content

Instantly share code, notes, and snippets.

Avatar

Rémy Perona Tabrisrp

View GitHub Profile
View minify-inline-js.php
<?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;
}
View valid_key.php
<?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 Feb 1, 2018
Problematic JS file
View main.js
// ================================================================================== //
// # Document on Ready
// # Document on Resize
// # Document on Scroll
// # Document on Load
// # Header Settings
@Tabrisrp
Tabrisrp / rocket-exclude-automatic-generation.php
Created Dec 22, 2017
Exclude specific post type/taxonomy from automatic critical CSS generation
View rocket-exclude-automatic-generation.php
<?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 ) {
View rocket-fix-polylang-term-bug.php
<?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 Oct 3, 2017
Correctly clean cache when front page URL contains page name in Polylang
View rocket-clean-cache-polylang-redirect-lang.php
<?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 );
}
}
View rocket-clear-user-cache-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' );
View rocket-nocache-loggedin-comment
<?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 Oct 11, 2018
Allow caching of WP feed by WP Rocket
View rocket-cache-feed.php
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;
}
View rocket-filter-cache-busting-filename.php
<?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;
}