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 / gist:3497696
Created August 28, 2012 12:38
Easy Custom Fields Richtext area
if( !class_exists( 'Easy_CF_Field_RichText' )) {
class Easy_CF_Field_RichText extends Easy_CF_Field {
public function print_form() {
$class = ( empty( $this->_field_data['class'] ) ) ? $this->_field_data['id'] . '_class' : $this->_field_data['class'];
$input_class = ( empty( $this->_field_data['input_class'] ) ) ? $this->_field_data['id'] . '_input_class' : $this->_field_data['input_class'];
$id = ( empty( $this->_field_data['id'] ) ) ? $this->_field_data['id'] : $this->_field_data['id'];
$label = ( empty( $this->_field_data['label'] ) ) ? $this->_field_data['id'] : $this->_field_data['label'];
$value = $this->get();
$hint = ( empty( $this->_field_data['hint'] ) ) ? '' : '<p><em>' . $this->_field_data['hint'] . '</em></p>';
@tott
tott / gist:3619324
Created September 4, 2012 09:54
wp-pass.php replacement for wp > 3.4
<?php
add_action( 'plugins_loaded', 'bypass_wp_login_for_pw_protected_posts' );
function bypass_wp_login_for_pw_protected_posts() {
// this functionality is a fork of http://core.trac.wordpress.org/browser/trunk/wp-login.php#L385
// keep this in sync with Core
$action = isset( $_REQUEST['action'] ) ? $_REQUEST['action'] : 'login';
if ( 'postpass' <> $action )
return;
@tott
tott / gist:3775415
Created September 24, 2012 10:44
mini backtrace
function mini_backtrace( $log = true ) {
$trax = array();
$trace = debug_backtrace();
foreach ( $trace as $key => $trc ) {
$trax[$key] = '[' . $key . '] : ' . $trc['file'] . '::' . $trc['line'] . ' - ' . $trc['function'];
}
if ( true === $log )
error_log( var_export( $trax, true ) );
return $trax;
}
@tott
tott / get-system-info.sh
Created October 30, 2012 11:42
Get system information
#!/bin/bash
# This is a simple script to gather some basic information about the system
# usage:
# git clone git://gist.github.com/3979756.git get-system-info
# cd get-system-info ; sh ./get-system-info.sh > system-info.log
header(){
echo '-------------------------------------------------------------------'
echo $1
@tott
tott / gist:4153726
Created November 27, 2012 11:19
produce_load.py
#!/usr/bin/env python
"""
Produces load on all available CPU cores
"""
from multiprocessing import Pool
from multiprocessing import cpu_count
def f(x):
while True:
@tott
tott / gist:1220235
Created September 15, 2011 19:29
hide certain posts from search
if ( function_exists( 'wpcom_is_vip' ) && wpcom_is_vip() ) {
wpcom_vip_load_helper_wpcom();
} else {
require_once( WP_CONTENT_DIR . '/themes/vip/plugins/vip-do-not-include-on-wpcom/vip-local-development-helper/vip-local-development-helper.php' );
require_once( WP_CONTENT_DIR . '/themes/vip/plugins/vip-do-not-include-on-wpcom/vip-powered-wpcom/vip-powered-wpcom.php' );
}
wpcom_vip_load_helper();
wpcom_vip_load_plugin( 'easy-custom-fields' );
@tott
tott / gist:7372827
Created November 8, 2013 15:41
Make sure WordPress upload urls follow the same scheme as the main page.
add_filter( 'upload_dir', '_enforce_https_uploads' );
function _enforce_https_uploads( $upload_dir ) {
$upload_dir['url'] = preg_replace( '#^https?://#', '//', $upload_dir['url'] );
$upload_dir['baseurl'] = preg_replace( '#^https?://#', '//', $upload_dir['baseurl'] );
return $upload_dir;
}
@tott
tott / gist:7378575
Created November 8, 2013 22:18
redirect pages with gravity forms to https
// redirect all gravity forms to ssl
add_action( 'template_redirect', 'sav_force_ssl_for_contact_forms', 1 );
function sav_force_ssl_for_contact_forms() {
if ( is_page() && ! is_ssl() ) {
global $post;
if ( ! preg_match( '#\[gravityform#msiU', $post->post_content ) )
return;
@tott
tott / gist:7384971
Created November 9, 2013 12:33
Enable exporting of Nav menus via WP Exporter
<?php
function tott_enable_menu_export() {
global $wp_post_types;
$wp_post_types['nav_menu_item']->_builtin = false;
}
add_action( 'load-export.php', 'tott_enable_menu_export' );
@tott
tott / force-referer-for-import.php
Created November 13, 2013 19:35
Force http referer for imports to bypass some bad servers who would not want to serve the static assets otherwise
add_filter( 'http_request_args', 'force_referer_for_import' );
function force_referer_for_import( $r ) {
if ( defined( 'WP_IMPORTING' ) && WP_IMPORTING ) {
$r['headers']['Referer'] = 'http://<referer>/';
}
return $r;
}