Skip to content

Instantly share code, notes, and snippets.

View flowtwo's full-sized avatar

Christian Laugesen flowtwo

View GitHub Profile
@flowtwo
flowtwo / youtube-jquery
Last active December 21, 2015 16:08
This YouTube shortcode for WordPress automatically grabs a video's thumbnail, stores it locally and presents the video as a clickable div with a responsive and lazy loading background. I found this useful after having paid a heavy loadtime on my archive of favourite YouTubes.
// Build lazy loading function - visible that is...
(function ($) {
$.fn.visible = function (partial, hidden) {
var $t = $(this).eq(0),
t = $t.get(0),
$w = $(window),
viewTop = $w.scrollTop(),
viewBottom = viewTop + $w.height(),
_top = $t.offset().top,
_bottom = _top + $t.height(),
@flowtwo
flowtwo / WP - Search and Replace in SQL
Last active December 23, 2015 14:49 — forked from chrisdigital/Wordpress global find and replace in SQL
Search and replace WordPress domains in phpMyAdmin
UPDATE prefix_options SET option_value = replace(option_value, 'demo.com', 'live.com') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE prefix_posts SET guid = replace(guid, 'demo.com','live.com');
UPDATE prefix_posts SET post_content = replace(post_content, 'demo.com', 'live.com');
UPDATE prefix_postmeta SET meta_value = replace(meta_value, 'demo.com', 'live.com');
UPDATE prefix_term_taxonomy SET taxonomy = replace(taxonomy, 'demo', 'live');
UPDATE prefix_posts SET post_type = replace(post_type, 'demo', 'live');
@flowtwo
flowtwo / WP - Online Users
Created October 11, 2013 18:19
WordPress - Add list of currently online users to admin bar
/*
* Apply online user status
*/
function gr_users_online_transient() {
if ( is_user_logged_in() ) {
$key = 'online';
$time = 60 * 5;
$user = wp_get_current_user();
$id = $user->ID;
$status = get_transient( $key .'_'. $id );
@flowtwo
flowtwo / WP - Danish slug
Created October 11, 2013 18:36
Sanitize Danish characters... fordi æ, ø og å skaber problemer nu og da.
function gr_sanitize_danish($title) {
if (!seems_utf8($title)) return $title;
$filter_chars = array(
// Character mapping from UTF-8 characters to ASCII characters.
chr(195).chr(32) => '_', // whitespace to underscore
chr(195).chr(133) => 'AA', // Å to AA
chr(195).chr(134) => 'AE', // Æ to Ae
chr(195).chr(143) => 'AA', // Å to AA
chr(195).chr(145) => 'ae', // æ to ae
chr(195).chr(146) => 'AE', // Æ to Ae
@flowtwo
flowtwo / WP - Get content LIX
Last active December 25, 2015 07:29
This sends the content to http://filip.journet.sdu.dk/berta/api.php, retrieves its LIX and stores it in a custom field.
/*
* GET SAVED LIX BY ID
*/
if ( !function_exists( 'get_lix' ) ) {
function get_lix( $id = NULL ) {
global $post;
if ( is_user_logged_in() && !is_home() && !is_front_page() ) {
if ( empty( $id ) && is_object( $post ) ) {
$id = $post->ID;
}
@flowtwo
flowtwo / WP - Standard settings
Created October 11, 2013 18:39
This sets standard settings on theme activation
/*
* Get standard settings upon installation
*/
function gr_set_defaults(){
$o = array(
'avatar_default' => 'blank',
'avatar_rating' => 'G',
'category_base' => '',
'comment_max_links' => 0,
'comment_whitelist' => 0,
@flowtwo
flowtwo / WP - Get language
Created October 11, 2013 18:41
This checks browser language and returns its prefix.
/**
* Browser language
*/
if ( !function_exists('gr_language') ) {
function gr_language() {
$lang = substr( $_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2 );
echo $lang;
}
}
@flowtwo
flowtwo / jQuery - External links
Created October 11, 2013 18:46
This makes sure external links are opened in new window and applies UTM parametres for statistics.
@flowtwo
flowtwo / wpdb.sql
Last active February 1, 2017 08:58
Renaming existing WordPress tables for security reasons
/* STEP 1 */
RENAME table `wp_commentmeta` TO `prefix_commentmeta`;
RENAME table `wp_comments` TO `prefix_comments`;
RENAME table `wp_icl_content_status` TO `prefix_icl_content_status`;
RENAME table `wp_icl_core_status` TO `prefix_icl_core_status`;
RENAME table `wp_icl_flags` TO `prefix_icl_flags`;
RENAME table `wp_icl_languages` TO `prefix_icl_languages`;
RENAME table `wp_icl_languages_translations` TO `prefix_icl_languages_translations`;
RENAME table `wp_icl_locale_map` TO `prefix_icl_locale_map`;
RENAME table `wp_icl_message_status` TO `prefix_icl_message_status`;
@flowtwo
flowtwo / Indlejringskode til eksempel
Created September 17, 2014 18:28
Indlejring af OnlineFundraising.dk
<div id="fund"></div><script type="text/javascript">window.onload=function(){var e=window.location.search.substring(1),n="https://onlinefundraising.dk/showcase/?"+e,t=document.getElementById("fund").offsetWidth,d=document.createElement("iframe");d.frameBorder=0,d.width=t,d.height="1450px",d.id="fundraising",d.frameborder="0",d.scrolling="no",d.setAttribute("src",n),document.getElementById("fund").appendChild(d)};</script>