Skip to content

Instantly share code, notes, and snippets.

View franz-josef-kaiser's full-sized avatar

Franz Josef Kaiser franz-josef-kaiser

View GitHub Profile
@franz-josef-kaiser
franz-josef-kaiser / jquery_in_viewport.php
Created March 22, 2011 23:21
load jQuery in WordPress only when comments are inside the viewport
<?php
add_action ( 'wp_head', 'add_jquery_when_comments_in_viewport', 11 );
function add_jquery_when_comments_in_viewport()
{
?>
<script type="text/javascript">
/* <![CDATA[ */
function jquery_for_comments_onLoad() {
var element = document.getElementById( "comments" ),
current = document.body.clientHeight+document.body.scrollTop,
@franz-josef-kaiser
franz-josef-kaiser / get_device_template.php
Created March 25, 2011 07:33
Loads a template part incl. the appropriate stylesheet for desktop or mobile devices, based on custom conditional tags.
<?php
/**
* STYLESHEETS
*/
function print_device_styles( $client = 'desktop' )
{
$client = apply_filters( 'set_theme_client', $client );
wp_enqueue_style( $client.'-css' );
}
add_action( 'wp_head', 'print_device_styles', 11 );
@franz-josef-kaiser
franz-josef-kaiser / editor_plugin.js
Created April 23, 2011 18:18
Example plugin for how to add a button to tinymce in wordpress
(function()
{
tinymce.create('tinymce.plugins.BrettsYouTube',
{
init : function(ed, url) {
ed.addButton('brettsyoutube',
{
title : 'brettsyoutube.youtube',
image : 'http://localhost/wordpress/wp-includes/js/tinymce/themes/advanced/img/icons.gif',
onclick : function()
@franz-josef-kaiser
franz-josef-kaiser / unset-admin-menu.php
Created April 26, 2011 15:49
How to unset certain admin menu groups in wordpress for specific (named) groups of users.
<?php
/*
Plugin Name:Unset Menu Items
Plugin URI: http://example.com
Description:How to unset certain admin menu groups in wordpress for specific (named) groups of users.
Author: Franz Josef Kaiser
Author URI: http://example.com
Version: 0.1
License: extended MIT/Expat license
@franz-josef-kaiser
franz-josef-kaiser / nav-menus.php
Created May 7, 2011 22:26
How-to: Alter nav menu output (in this case adding blueprint css classes)
<?php
/**
* Classes for a navigation named "Topnav" in the nav location "top".
*
* You will have to re-create this function inside your Child Theme.
* Just edit the data - "editing" comments - inside your Child Themes function.
*
* @since 0.1
* @since 0.2 - replaced by the new function that saves 24(!) queries.
*
@franz-josef-kaiser
franz-josef-kaiser / cron-list.php
Last active September 25, 2015 21:27
Plugin: List wp cron jobs in wp_footer
<?php
defined( 'ABSPATH' ) OR exit;
/*
Plugin Name: WP Cron Jobs List
Plugin URI: https://github.com/franz-josef-kaiser
Description: List WordPress internal cron jobs (array data) after the footer.
Author: Franz Josef Kaiser
Author URI: https://github.com/franz-josef-kaiser
Version: 0.3.1
License: MIT
@franz-josef-kaiser
franz-josef-kaiser / list_plugin_updates.php
Created May 27, 2011 15:59
WordPress Plugin: List all plugins that need updates in wp_footer()
<?php
/*
Plugin Name: Plugin update lister
Plugin URI: https://gist.github.com/995560
Description: Adds a table to your ´wp_footer()´ that lists all plugins that need updates. The plugin works out of the box.
Author: Franz Josef Kaiser
Author URI: https://github.com/franz-josef-kaiser
Version: 0.1.
License: GPL v2 - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
@franz-josef-kaiser
franz-josef-kaiser / ultimate-answer.php
Created May 27, 2011 18:07
WordPress Plugin: Give the ultimate answer
<?php
// Straight from "The Hitchhiker's Guide to the Galaxy"
// Try to put 'Taylor' as first name & 'Yates' as $last_name
function answer_my_question( $first_name, $last_name )
{
$answer_to_all_questions = floor( intval( octdec( decoct( md5( $last_name ) ) ) ) / intval( octdec( decoct( md5( $first_name ) ) ) ) * 9 );
echo $answer_to_all_questions;
}
?>
@franz-josef-kaiser
franz-josef-kaiser / debug-meta-box.php
Last active June 3, 2020 01:29
Wordpress Debug Meta Box
<?php
/**
* Debugging
*
* @example: add_filter( 'debug', create_function( '$a', 'return $handle;' ) );
*
* @param unknown_type $input
* @param unknown_type $print_r_dump
* @param unknown_type $print
* @return (mixed) $output
@franz-josef-kaiser
franz-josef-kaiser / handle_data.php
Created June 3, 2011 17:58
Data handling & parsing in wordpress
<?php
/**
* The "global" data handle function
*
* This function can serve a lot of different purposes.
* Incl. merging db values from an options entry with input arguments.
*
* Throws a fully translateable Error if no database option name was specified.
* Tells you from which file the Error was triggered and in which line you should search it.
* Also tells you the "global_$args['UID']" name of the action hook where the Error occured.