Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View tott's full-sized avatar

Thorsten Ott tott

  • Germany, Cologne area
View GitHub Profile
@tott
tott / run-wp-cron.sh
Created November 16, 2019 00:04
Execute WP-Cron on multisite through wp-cli
#!/bin/bash
function run_cron_due_now {
for SITE_URL in $(wp --allow-root site list --fields=url --format=csv | tail -n +2 | sort); do
wp --allow-root cron event run --due-now --url="$SITE_URL" && echo -e "\t+ Completed Crons for $SITE_URL" &
done
wait $(jobs -p)
echo "Done"
}
@tott
tott / set-exact.php
Created September 11, 2019 10:28
Set ElasticPress Exact match
function set_to_exact( $formatted_args, $args ) {
if ( ! empty( $formatted_args['query']['bool']['should'] ) ) {
$formatted_args['query']['bool']['must'] = $formatted_args['query']['bool']['should'];
$formatted_args['query']['bool']['must'][0]['multi_match']['operator'] = 'AND';
unset( $formatted_args['query']['bool']['should'] );
unset( $formatted_args["query"]["bool"]["must"][0]["multi_match"]["type"] );
}
return $formatted_args;
}
add_filter( 'ep_formatted_args', 'set_to_exact', 10, 2 );
@tott
tott / gist:9d061c750f0e80703390a1f5571cf7e3
Created September 5, 2019 09:49
search term highlighting elasticpress
add_filter(
'ep_formatted_args',
function( $formatted_args ) {
if ( ! empty( $_GET['s'] ) ) {
foreach ( [ 'post_title', 'post_excerpt', 'author_name', 'terms.post_tag.name', 'terms.category.name' ] as $field ) {
$formatted_args['highlight']['fields'][ $field ] = [
'pre_tags' => [ '<strong style="background:yellow">' ],
'post_tags' => [ '</strong>' ],
'type' => 'plain',
];
@tott
tott / minions-post-pusher.php
Last active April 24, 2019 16:39
WP-Minions ( https://github.com/tott/WP-Minions/tree/alter-job-data ) for multisite syndication to one site.
<?php
/**
* Plugin Name: WP Minions Post Pusher
* Description: Pushes all published posts to one blog using wp-minions
* Version: 1.0
* Author: Thorsten ott
* Author URI: http://thorsten-ott.de/
* License: GPLv2 or later
*/
@tott
tott / read-backlight.py
Created November 22, 2018 11:41
Read backlight for x230 / x330 taobao FHD mod
#!/usr/bin/env python
import sys
import array
import usb.core
import usb.util
import os
path = "/tmp/backlight-value"
# decimal vendor and product values
@tott
tott / gist:7767218
Created December 3, 2013 10:38
.htaccess rule to force www and preserving the protocol http/https
# Force www
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
@tott
tott / gist:a10bebe067d517455e423eb32f7d1d3d
Created October 16, 2018 21:59
Sending multipart mail with wp_mail (untested)
<?php
$to = "receipt@domain.com";
$subject = "My Multipart test";
$message = "I am the plain text message";
$boundary = uniqid(rand(), true);
$header = "MIME-Version: 1.0\n"
@tott
tott / options-monitor.sh
Last active July 10, 2018 03:32
WordPress options table size Nagios monitor
#!/bin/bash
OPTIND=1
verbose=0
dbuser=""
dbpasswd=""
while getopts "vh?U:P:H:" opt; do
case "$opt" in
@tott
tott / secure-auth-cookies.php
Last active February 17, 2017 15:17
Encrypt WordPress auth cookies
<?php
function sav_encrypt_cookie( $decrypted ) {
$encrypted = mcrypt_encrypt( MCRYPT_RIJNDAEL_256, substr( AUTH_SALT, 0, 32 ), $decrypted, MCRYPT_MODE_ECB, mcrypt_create_iv( mcrypt_get_iv_size( MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB ), MCRYPT_RAND ) );
return trim( base64_encode( $encrypted ) );
}
function sav_decrypt_cookie( $encrypted ) {
$decrypted = mcrypt_decrypt( MCRYPT_RIJNDAEL_256, substr( AUTH_SALT, 0, 32 ), base64_decode( $encrypted ), MCRYPT_MODE_ECB, mcrypt_create_iv( mcrypt_get_iv_size( MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB ), MCRYPT_RAND ) );
return trim( $decrypted );
@tott
tott / gist:0cc78e7dcad18024d1c8
Created July 1, 2014 20:35
Create a full list of sites with domain mapping with wp-cli
for i in `wp site list | cut -f 2 | grep -v url`; do wp --url=$i eval 'global $wpdb, $blog_id; $blogname=get_option("blogname"); $blogurl=home_url(); $domains=$wpdb->get_results( "SELECT * FROM {$wpdb->dmtable} WHERE blog_id = $blog_id;" ); foreach( $domains as $data ) { echo $blog_id.",".$blogname.",".$blogurl.",".$data->domain.",".$data->active."\n"; }'; done