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 / 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:

@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
@brasofilo
brasofilo / wp-admin-pointers.php
Last active September 3, 2023 20:25
WordPress Admin Pointers : based on code by Stephen Harris, Tim D and Frank Bueltge. See: http://stackoverflow.com/a/19328125/1287812 and http://brasofilo.com/como-incluir-admin-pointers-en-tu-theme-o-plugin
<?php
/**
* Plugin Name: My Amdin Pointers
* Plugin URI: https://gist.github.com/brasofilo/6947539
* Version: 0.1
* Author: Rodolfo Buaiz
* Author URI: http://brasofilo.com
* Licence: GPLv3
*
@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 {
@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');
<?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 );
@Fab1en
Fab1en / custom_media_menu.js
Created January 21, 2013 15:32
Draft plugin example to add a javascript menu into the WP3.5 Media Library popup. Answer to this Wordpress stackexchange question : http://wordpress.stackexchange.com/questions/76980/add-a-menu-item-to-wordpress-3-5-media-manager/
// for debug : trace every event
/*var originalTrigger = wp.media.view.MediaFrame.Post.prototype.trigger;
wp.media.view.MediaFrame.Post.prototype.trigger = function(){
console.log('Event Triggered:', arguments);
originalTrigger.apply(this, Array.prototype.slice.call(arguments));
}*/
// custom state : this controller contains your application logic
wp.media.controller.Custom = wp.media.controller.State.extend({
@tommcfarlin
tommcfarlin / meta-data-serialization.php
Last active November 4, 2022 00:28
An example function used to demonstrate how meta data is typically saved in a WordPress theme or plugin. The gist is made public so that developers can contribute to the standard security boilerplate functionality in order to simplify, reduce, and improve our serialization functions.
<?php
/**
* An example function used to demonstrate how to use the `user_can_save` function
* that provides boilerplate security checks when saving custom post meta data.
*
* The ultimate goal is provide a simple helper function to be used in themes and
* plugins without the need to use a set of complex conditionals and constants.
*
* Instead, the aim is to have a simplified function that's easy to read and that uses
* WordPress APIs.
@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;