Skip to content

Instantly share code, notes, and snippets.

View glueckpress's full-sized avatar

Caspar Hübinger glueckpress

View GitHub Profile
@glueckpress
glueckpress / wp-rocket-disable-inline-css-minify.php
Created December 21, 2017 08:08
[WordPress][WP Rocket] Disable minification of inline CSS when Minify HTML is enabled.
<?php
/**
* Disables Minify for inline CSS.
* https://github.com/wp-media/wp-rocket/blob/v2.11.3/inc/front/minify.php#L72
*/
add_filter( 'rocket_minify_html_options', function ( $html_options ) {
$html_options = array();
return $html_options;
@glueckpress
glueckpress / wp-rocket-critical-css-params.php
Created December 15, 2017 14:55
[WordPress][WP Rocket] As of 2.11, WP Rocket generates critical CSS automatically. Here’s how to adjust parameters for maximum viewport width and height.
<?php
/**
* Customise parameters for critical CSS generator.
*/
add_filter( 'rocket_cpcss_job_request', function ( $item ) {
return array(
'url' => $item['url'],
'mobile' => 0, // 1 = Emulate a mobile device
'viewport_width' => 1300 // px maximum width of the viewport
'viewport_height' => 900 // px maximum height of the viewport
@glueckpress
glueckpress / wp-rocket-remove-cache-options-meta-box.php
Last active October 5, 2023 09:54
[WordPress][WP Rocket] Remove Cache Options meta box from Edit screens.
<?php
/**
* PLEASE SEE COMMENT BELOW:
* https://gist.github.com/glueckpress/0fcd12a8ada43e37e400facd987016a1#gistcomment-3009533
*/
defined( 'ABSPATH' ) or die();
/**
* Plugin Name: WP Rocket | Remove Cache Options Meta Boxx
* Description: Removes the Cache Options meta box from Edit screens.
* Author: Caspar Hübinger
@glueckpress
glueckpress / exclude
Last active January 4, 2023 17:57
[git] Exclude .gitignore and all of WordPress, except specified directories
# Sample of .git/info/exclude
# Documentation: https://git-scm.com/docs/gitignore
# Exclude .gitignore file.
# If an initial .gitignore file has been added to the repo,
# you might have to delete it first and sync the change.
# Then create a new one which will be excluded according to this rule.
.gitignore
# Exclude all of WordPress, but keep these directories synced:
@glueckpress
glueckpress / wp-rocket-debug-minify-options.php
Created November 29, 2017 18:42
[WordPress][WP Rocket] Print values of minify options as HTML comments to wp_footer().
<?php
/**
* Quick and dirty addition to:
* https://github.com/wp-media/wp-rocket-helpers/tree/master/wp-rocket-debug-helper
*/
add_action( 'wp_footer', function () {
if ( ! function_exists( 'get_rocket_option' ) ) {
return;
}
@glueckpress
glueckpress / wp_rocket__wp_get_attachment_image__lazyload.php
Last active January 6, 2020 08:18
[WordPress][WP Rocket] [deprecated] Wrapper function: Applies WP Rocket’s LazyLoad to wp_get_attachment_image()
<?php
/**
* Wrapper function: Applies WP Rocket’s LazyLoad to wp_get_attachment_image()
*
* @link https://developer.wordpress.org/reference/functions/wp_get_attachment_image/
* @link https://github.com/wp-media/wp-rocket/blob/v2.10.9/inc/front/lazyload.php#L24-L47
*
* @param int $attachment_id (Required) Image attachment ID.
* @param string|array $size (Optional) Image size. Accepts any
* valid image size, or an array of width
@glueckpress
glueckpress / shoo.php
Created July 24, 2017 21:46
[WordPress] Plugin or MU plugin: Sends an HTTP status of 403 when a login has failed. Idea previously published by Sergej Müller.
<?php
defined( 'ABSPATH' ) && function_exists( 'add_action' ) or exit;
/**
* Plugin Name: Shoo
* Plugin URI: https://gist.github.com/glueckpress/3a15c8a070f9451c18e10f6d6e76c56d
* Description: Sends an HTTP status of 403 when a login has failed. Idea previously <a href="https://plus.google.com/u/0/110569673423509816572/posts/T1gnqbiYjZZ">published by Sergej Müller</a>.
* Version: 0.0.2
* Author: Caspar Hübinger
* Author URI: https://profiles.wordpress.org/glueckpress
* License: GNU General Public License v3
@glueckpress
glueckpress / simple-map-defer.php
Last active April 28, 2019 10:51
[WordPress][Simple Map] Load Google Maps API script from Simple Map deferred.
<?php
defined( 'ABSPATH' ) or die( 'No direct access here.' );
/**
* Plugin Name: Simple Map | Defer
* Description: Makes sure Google Maps API script from <a href="https://wordpress.org/plugins/simple-map/">Simple Map</a> gets loaded deferred.
* Author: Caspar Hübinger
* Author URI: https://profiles.wordpress.org/glueckpress
* Plugin URI: https://gist.github.com/glueckpress/56c88900aad391b95b5d44f4e752a1a4
* License: GNU General Public License v3 or later
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
@glueckpress
glueckpress / wp-rocket-is-preload.php
Created April 27, 2017 13:37
[WordPress][WP Rocket] Check if a visitor is WP Rocket’s preload user agent.
<?php
/**
* More about WP Rocket’s preload options in this document:
* @link http://docs.wp-rocket.me/article/8-how-the-cache-is-preloaded
*/
/**
* Check if a visitor is WP Rocket’s preload user agent (bot or sitemap).
* This will trigger only on a document that has not been cached yet.
*
@glueckpress
glueckpress / ama-42.php
Created February 8, 2017 13:20
[WordPress] Ask me anything on post #42. Auto-approves comments and replies automatically on post ID 42 until a given date. CUSTOM EDITS REQUIRED!
<?php
/**
* Plugin Name: AMA 42
* Description: Ask me anything on post 42.
* Version: 2017-02-08
* Author: Caspar Hübinger
* Author URI: https://profiles.wordpress.org/glueckpress
* License: GNU General Public License v3 or later
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
*/