Skip to content

Instantly share code, notes, and snippets.

View tzkmx's full-sized avatar
🎉
estrenando repositorios privados

Jesus Franco tzkmx

🎉
estrenando repositorios privados
View GitHub Profile
@tzkmx
tzkmx / center_youtube_iframe.php
Created January 31, 2017 23:51
Mini plugin to center Youtube iframes inserted with oEmbed in WordPress
<?php
/**
* @package Uploads_Media
* @version 0.1
* @see http://wordpress.stackexchange.com/a/50781/16301
*/
/*
Plugin Name: Center Youtube Iframe
Plugin URI: https://core.trac.wordpress.org/ticket/32920
Description: Wraps youtube iframe in a centered paragraph
@tzkmx
tzkmx / jail.local
Created February 3, 2017 20:35 — forked from Nihisil/jail.local
Send notifications to the Slack from fail2ban
...
action_with_slack_notification = %(banaction)s[name=%(__name__)s, port="%(port)$
slack[name=%(__name__)s]
action = %(action_with_slack_notification)s
...
@tzkmx
tzkmx / README.md
Last active February 16, 2017 23:28
Custom Perl Module for NginX in order to remove single URIs cached

Custom module to purge cached URIs

Let's suppose you have this fastcgi_cache config:

fastcgi_cache_path /var/run/nginx-cache levels=2:2 keys_zone=WORDPRESS:2048m inactive=120m;

By using this module, in order to purge a single cached uri you can use a query like:

curl localhost/invalid_cache/mydomain.com/my_uri
@tzkmx
tzkmx / nginx.md
Created February 16, 2017 23:33
Preserve cache busting without query strings for WordPress

With this simple plugin, your URLs will be stripped of their query string, but the version is preserved to allow for cache busting.

However you need instruct your webserver to strip the version added in order to let clients use the files.

    location ~ /Versioned/ {
        rewrite ^/Versioned/([^/]+)(/.*)(\.[0-9a-zA-Z]+)$ /$2$3 last;
    }
@tzkmx
tzkmx / Lazy Load FB Like
Created February 18, 2017 00:02 — forked from giacomopaita/Lazy Load FB Like
Lazy Load Facebook Like Box
$('.tab a').on('click', function(){
if ($(this).html() == 'FACEBOOK' && typeof xx == 'undefined') {
// DUMMY VARIABLE TO CALL THE FUNCTION ONLY THE FIRST TIME THE USER CLICKS THE TAB:
xx = 1;
(function(d, s, id) {
var js;
var fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
@tzkmx
tzkmx / validate_amp_collection.bat
Created February 27, 2017 20:20
Windows batch file to validate list of URLs with AMP errors
@ECHO OFF
FOR /F "usebackq tokens=1 delims=," %%A IN (`grep -v "URL" elsemanario-com__etiqueta_HTML_prohibida.csv`) DO (
FOR /F "usebackq" %%B IN (`amphtml-validator --format=json %%A`) DO (
echo %%B|findstr /C:"PASS" >NUL 2>&1
IF not errorlevel 1 (
echo %%A | tee -a valid_urls.txt
) ELSE (
echo %%A | tee -a nonvalid_urls.txt
)
)
@tzkmx
tzkmx / README.md
Last active March 17, 2017 22:05
Filter function to fix uploads directory (customized WordPress paths)

Moving WordPress to custom subdirectory and customize its managed paths

This is a must-use plugin to fix your uploads paths (URL & directory), for advanced paths customization for your wordpress intallation.

  • WordPress is installed at /wp subdirectory.
//wp-config.php
define('WP_HOME', 'http://example.com');
define('WP_SITEURL', 'http://example.com/wp');
@tzkmx
tzkmx / app.php
Created December 16, 2015 19:20
Silex password MD5 encoding service
<?php
use Silex\Application;
use Silex\SecurityServiceProvider;
use Symfony\Component\Security\Core\Encoder\MessageDigestPasswordEncoder;
$app = new Application();
$app->register(new SecurityServiceProvider(), array(
'security.encoder.digest' => $app->share(function () use ($app) {
return new MessageDigestPasswordEncoder('md5', false, 1);
})
@tzkmx
tzkmx / path_opcache_invalidation.php
Created July 4, 2017 16:44
OpCache path invalidation script
<?php
// Untested, retrieved and reformatted from:
// https://ihaveabackup.net/article/invalidating-the-opcache-in-php-5-5#comment-19
if (!function_exists('opcache_get_configuration')) {
die('OPCache is not installed/running');
}
$data = opcache_get_status(); $expired = array();
@tzkmx
tzkmx / lazyload-fixorder-enqueuing.php
Created July 21, 2017 16:22
Force footer registration of scripts for lazyload when assetsminify plugin present
<?php
/** After registering scripts, A3 Lazy Load plugin fires action
* we use to fix registration, adding data to load it
* in footer, because assetsminify mangles the order of files */
add_action('after_a3_lazy_load_xt_script', function() {
$plugins = get_option('active_plugins');
if( in_array('assetsminify/plugin.php', $plugins) ) {
$scripts = wp_scripts();
foreach($scripts->registered as $handle => $dep) {
if( false !== strpos( $handle, 'lazyloadxt' ) ) {