Skip to content

Instantly share code, notes, and snippets.

View cfoellmann's full-sized avatar
🐶
Dogging on

Christian Foellmann cfoellmann

🐶
Dogging on
  • W&S Technik GmbH
  • Castrop-Rauxel, NRW, Germany
View GitHub Profile
@tott
tott / ip_in_range.php
Created November 27, 2013 22:46
php check if IP is in given network range
/**
* Check if a given ip is in a network
* @param string $ip IP to check in IPV4 format eg. 127.0.0.1
* @param string $range IP/CIDR netmask eg. 127.0.0.0/24, also 127.0.0.1 is accepted and /32 assumed
* @return boolean true if the ip is in this range / false if not.
*/
function ip_in_range( $ip, $range ) {
if ( strpos( $range, '/' ) == false ) {
$range .= '/32';
}
@debloper
debloper / notes.md
Created November 26, 2013 01:11
WordPress Multisite on OpenShift Express

To start from scratch

  • Create a quickstart WordPress 3.x app with PHP & MySQL cartridge
  • Setup WordPress by visiting app-url/wp-admin/install.php
  • Clone the app locally for making further changes

OPTIONAL: version update

  • Update source with new WP version

Multisite configuration

  • Add define('WP_ALLOW_MULTISITE', true); to wp-config.php
@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 );
@thomasgriffin
thomasgriffin / gist:7521701
Created November 18, 2013 02:56
Add custom HTML to Soliloquy slides.
<?php
add_filter( 'tgmsp_caption_output', 'tgm_soliloquy_custom_html', 10, 4 );
function tgm_soliloquy_custom_html( $html, $id, $image, $i ) {
// If the ID doesn't match the one we want to modify, return the default HTML output. Change 324 to your slider ID.
if ( '324' !== $id )
return $html;
// Append custom code output of the caption to do whatever. $i is the number of the slide.
$html .= '<div class="my-custom-class"><p>My custom stuff!</p></div>';
@tott
tott / alter-robots-txt.php
Created November 14, 2013 14:15
alter robots.txt
add_filter( 'robots_txt', 'sav_add_sitemap_to_robots' );
function sav_add_sitemap_to_robots( $robots ) {
$robots .= 'Sitemap: ' . site_url( 'sitemap_index.xml' );
return $robots;
}
@tott
tott / frontend-force-mapped-domain.php
Created November 14, 2013 14:14
Enforce domain mapping mapped domain for all front-end urls ran through esc_url()
add_filter( 'clean_url', 'sav_force_mapped_url' );
function sav_force_mapped_url( $url ) {
if ( ! is_admin() ) {
if ( function_exists( 'get_original_url' ) && strpos( '/wp-admin', $url ) === false ) {
$original = preg_replace( '#^https?://#', '', get_original_url('') );
$new = preg_replace( '#^https?://#', '', site_url() );
$url = str_ireplace( $original, $new, $url );
}
}
return $url;
@remkus
remkus / functions.php
Created November 10, 2013 11:12
Clear APC cache with a single click
<?php
*/
* Clear APC cache with a single click
* @link http://kaspars.net/blog/wordpress/clear-apc-cache-button-for-wordpress
*/
if (function_exists('apc_clear_cache')) {
// Clear cache if something is edited
if (!empty($_POST) && is_admin())
apc_clear_cache();
@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' );
@franz-josef-kaiser
franz-josef-kaiser / ajax.js
Last active September 5, 2024 01:43
AJAX in WordPress. Class based example.
( function( $, plugin ) {
"use strict";
// Working with promises to bubble event later than core.
$.when( someObjectWithEvents ).done( function() {
console.log( 'AJAX request done.' );
} )
.then( function() {
setTimeout( function() {
console.log( 'AJAX requests resolved.' );
@pepegar
pepegar / newservice.php
Created August 22, 2013 09:01
This is a plugin for WordPress that extends the Media Explorer plugin with a new service. You may want to use it as a template
<?php
/*
Plugin Name: new service
Plugin URI: garhdez.com
Description: new service
Author: Pepe
*/
class MEXP_New_Template extends MEXP_Template {