Skip to content

Instantly share code, notes, and snippets.

View bueltge's full-sized avatar
Always interested

Frank Bültge bueltge

Always interested
View GitHub Profile
@dnaber-de
dnaber-de / dna-save-attachment.php
Created December 5, 2012 11:57
Worpress Plugin: Calls the action 'save_post' for Attachment Post Types. Requires PHP 5.3
<?php
/**
* Plugin Name: dna Save Attachment
* Plugin URI: https://gist.github.com/4214994
* Author: David Naber
* Author URI: http://dnaber.de/
* Version: 2014.08.24
* Description: Calls the action 'save_post' for Attachment Post Types vor WordPress versions prior 4.0. Requires PHP 5.3. The plugin will have no effect in WordPress 4.0 or higher. (Getting obsolete when <a href="http://core.trac.wordpress.org/ticket/21963">#21963</a> is fixed.)
*/
namespace DNA\SaveAttachment;
@thefuxia
thefuxia / mlp-addon-post-meta.php
Last active November 26, 2015 09:00
MLP Addon: Sync post meta fields
<?php # -*- coding: utf-8 -*-
/**
* Plugin Name: MLP Addon: Sync post meta fields
* Plugin URI: https://gist.github.com/toscho/6393c79aacba0983a96a
* Description: Create a custom field, put it into the MLP translation box, and sync it across the sites.
* Version: 2015.03.03
* Required: 4.0
* Author: Thomas Scholz <info@toscho.de>
* Author URI: http://toscho.de
* License: MIT
<?php
spl_autoload_register( function ( $class_name ) {
$camelcase_to_snakecase = function ( $string ) {
return preg_replace( '/([a-z])([A-Z])/', '$1_$2', $string );
};
$split = explode( '\\\\', $class_name );
// remove "Inpsyde" namespace
$vendor = array_shift( $split );
@alexkingorg
alexkingorg / enqueue-heartbeat.php
Last active December 16, 2015 04:59
WordPress 3.5 Compatible Heartbeat API Usage
<?php
// enqueue the script,
// this fails gracefully if no 'heartbeat' script is registered
wp_enqueue_script('heartbeat');
@dnaber-de
dnaber-de / Class_Reflector.php
Created October 1, 2013 10:04
Example of a class reflection to make the availability of this class optional.
<?php
/**
* base reflector class to reflect plugins APIs without using
* plugin classes directly
*
*/
namespace Project\Theme\Reflector;
abstract class Class_Reflector {
@bueltge
bueltge / deploy.sh
Created January 23, 2014 15:15 — forked from BFTrick/deploy.sh
#! /bin/bash
# A modification of Dean Clatworthy's deploy script as found here: https://github.com/deanc/wordpress-plugin-git-svn
# The difference is that this script lives in the plugin's git repo & doesn't require an existing SVN repo.
# main config
PLUGINSLUG="______your-plugin-name______"
CURRENTDIR=`pwd`
MAINFILE="______your-plugin-name______.php" # this should be the name of your main php file in the wordpress plugin
# git config
@dnaber-de
dnaber-de / WP_Plugins_Unit_Tests.md
Last active November 9, 2016 13:55
Short description on how I prepared sucessfully a unit test for wordpress plugin.

Plugin UnitTest – How To

Assuming you have a separate WordPress installation for your project (eg. /var/www/my-project ) with your plugin you want to test in /var/www/my-project/wp-content/plugins/my-plugin. PHPUnit and SVN needs also to be installed on your system.

1. Get the WordPress test environment

Get the WordPress test environment as described here in step 1 and 2. You may want to use a separate directory for those stuff like ( ~/tmp/wordpress-test).

The repository looks like:

@eteubert
eteubert / similar_posts.php
Created June 15, 2012 09:59
WordPress: Similar posts by matching tags
<?php
/**
* Return posts with maximum age of one year.
*
* Usage:
* add_filter( 'posts_where', 'wp_query_filter_max_one_year_old' );
* $my_query = new WP_Query( array( ... ) );
* remove_filter( 'posts_where', 'wp_query_filter_max_one_year_old' );
*
* @param string $where
@mikeschinkel
mikeschinkel / parks-and-features.php
Created November 5, 2011 23:16
Plugin demonstrates how to route parent post/child post URLs WordPress 3.3
<?php
/**
* Plugin Name: MMC Parks and Features
* Description: This plugin demonstrates how to route parent/child URLs like http://example.com/parks/yosemite/half-dome/in WordPress 3.3
* Author: Mike Schinkel
* Author URL: http://about.me/mikeschinkel
* Notes:
* To answer http://lists.automattic.com/pipermail/wp-hackers/2011-November/041486.html
* Assumes a metabox that sets $post->post_parent field for a park feature with it's park's $post->ID.
*
@bueltge
bueltge / gist:998531
Created May 30, 2011 07:00
Example for add a Custom Post Type to the WordPress Post Feed
add_action( 'request', array( &$this, 'add_to_feed' ) );
// add to post-feed
function add_to_feed($request) {
if ( isset($request['feed']) && !isset($request['post_type']) ) {
$request['post_type'] = get_post_types( $args = array(
'public' => true,
'capability_type' => 'post'
) );