Skip to content

Instantly share code, notes, and snippets.

Avatar

Kadai Crosshansen kadai

View GitHub Profile
View block_with_abuseipdb.php
<?php
/**
* This little add-on blocks a visitor using the country reported by AbuseIPDB. This code is intended to be placed
* inside a functions.php file into a WordPress theme.
*
* Also, this check happens as soon as possible, using the very first available hook for the theme. Other good options
* include "init" and "wp_loaded" hooks.
*
* You can also try and use the "plugins_loaded" hook, but it is meant to be used more when this code is into
View abuseipdb_firewall.py
#!/usr/bin/python3
# coding=utf-8
from subprocess import run
import requests
abuseipdb_apikey = 'YOUR_API_KEY'
abuseipdb_url = 'https://api.abuseipdb.com/api/v2/blacklist'
set_name = 'abuseipdb_blacklist'
View accion-001.php
<?php
add_action('wp_enqueue_scripts', 'dtorrer_agregarFontAwesome');
function dtorrer_agregarFontAwesome(){
wp_enqueue_script('fontawesome', 'https://use.fontawesome.com/releases/v5.7.2/js/all.js', array(), '5.7.2');
wp_enqueue_style('miestilo', plugin_dir_url( __FILE__ ) . 'estilos/miestilo.css', array('jquery', 'fontawesome'), '1.0.0');
}
?>
@kadai
kadai / 001-filterbyhttpcode.php
Created Oct 29, 2018
Some solutions to some common problems found in the plugin Swift Performance.
View 001-filterbyhttpcode.php
<?php
/*
* We verify the HTTP code that WordPress will send and then we decide if the current page
* should be allowed to be cached.
*/
add_filter('swift_performance_is_cacheable', 'dtorrer_swift_iscacheable', 20, 1);
function dtorrer_swift_iscacheable( $cacheable = FALSE ){
if( FALSE === $cacheable ){ return $cacheable; }
View functions.php
<?php
add_action( 'wp_enqueue_scripts', 'dtorrer_agregar_estilos_al_tema' );
function dtorrer_agregar_estilos_al_tema() {
wp_enqueue_style( 'estilos-temapadre', get_template_directory_uri() . '/style.css' );
wp_enqueue_style( 'estilos-temahijo', get_stylesheet_directory_uri() . '/style.css',array( 'estilos-temapadre' ) );
}
?>
View wp-config.php
<?php
/* SI TENEMOS UN REDIRECTING LOOP CON CLOUDFLARE Y HTTPS */
/* LE OBLIGAMOS AL SERVIDOR A "ACTIVAR" EL MODO HTTPS */
define('FORCE_SSL_ADMIN', true);
if (strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false)
$_SERVER['HTTPS']='on';
/* SI USAMOS CLOUDFLARE, USAMOS ESTO PARA RESTAURAR EL IP DEL VISITANTE */
if ( !empty( $_SERVER['REMOTE_ADDR'] ) && !empty( $_SERVER['HTTP_CF_CONNECTING_IP'] ) )
@kadai
kadai / functions.php
Created May 8, 2018
Función para conocer el desempeño de WordPress
View functions.php
<?php
add_filter('wp_footer', dtorrer_diagnostico);
function dtorrer_diagnostico(){
$datos = array();
$datos[] = 'Fecha: ' . date('Y-m-d H:i:s');
$datos[] = 'Tiempo: ' . timer_stop(0, 2) . ' segundos.';
if (function_exists('memory_get_usage')) {
$unidades = array('b','kb','mb','gb','tb','pb');
View monarch.sql
CREATE TABLE $tableprefix_et_social_stats (
id mediumint(9) NOT NULL AUTO_INCREMENT,
sharing_date datetime DEFAULT '1000-01-01 00:00:00' NOT NULL,
network varchar(20) NOT NULL,
action varchar(10) NOT NULL,
post_id bigint(20) NOT NULL,
ip_address varchar(45) NOT NULL,
media_url varchar(2083) NOT NULL,
location varchar(20) NOT NULL,
UNIQUE KEY id (id)) DEFAULT CHARACTER SET utf8
View demostracion.php
<?php
function dtorrer_agregar_seguimiento_envio() {
?>
<script type="text/javascript">
document.addEventListener( 'wpcf7mailsent', function( event ) {
ga( 'send', 'event', 'Contact Form', 'submit' );
location = 'https://dtorrer.com/url-destino';
}, false );
</script>
View destino-url-fixed.php
<?php
function dtorrer_agregar_seguimiento_envio() {
?>
<script type="text/javascript">
document.addEventListener( 'wpcf7mailsent', function( event ) {
location = 'https://dtorrer.com/url-destino';
}, false );
</script>
<?php