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 / insert_menu_separator.php
Last active February 21, 2023 11:21
Add separators to WP Admin menus
<?php
namespace WCM;
// Add the filter
add_action( 'admin_menu', __NAMESPACE__.'\add_menu_separator' );
function add_menu_separator()
{
add_filter( 'add_menu_classes', __NAMESPACE__.'\insert_admin_menu_separator' );
}
@franz-josef-kaiser
franz-josef-kaiser / filter_var_array.php
Last active January 27, 2023 13:44
PHP filter_var_array() example
<?php
namespace WCM;
# USES PHP 5.3 + Closures
// No white surrounding space
$data = array_map( 'trim', $_POST['foo'] );
$data = filter_var_array( $data, array(
@franz-josef-kaiser
franz-josef-kaiser / user_deamon.php
Created July 25, 2011 18:17
Current User Data - Plugin (wordpress)
<?php
/*
Plugin Name: Your friendly "Current User Data" Deamon
Plugin URI: http://not-going-to-come-anytime.com
Description: Gives you an overview about any Data of the currently logged in user including all code to get or display it. Includes different code-approaches of user_role and the (depracated) user_level inside the code. So just take a look at the code and inline-comments. Makes a new menu at "Tools" > "Show User Data".
Version: 0.5
Author: F. J. Kaiser
Author URI: http://unserkaiser.com
License: GPL2
=========================================================================
@franz-josef-kaiser
franz-josef-kaiser / simplepie_example.php
Created June 7, 2013 17:31
SimplePie - example method to list what information we can retrieve about a feed as a whole and for single items when looping through
<?php
defined( 'ABSPATH' ) OR exit;
/**
* Plugin Name: (WCM) RSS Importer
*/
add_action( 'plugins_loaded', array( 'WCMRSSImporterBootstrap', 'init' ) );
class WCMRSSImporterBootstrap
{
protected static $instance = null;
@franz-josef-kaiser
franz-josef-kaiser / paranoia-config.php
Last active July 29, 2022 10:01
WordPress debug - Error Reporting Level: Paranoia
<?php
define( 'DS', DIRECTORY_SEPARATOR );
# ==================================
# PHP errors & log
error_reporting(
E_ALL | E_STRICT | E_CORE_ERROR | E_CORE_WARNING
| E_COMPILE_ERROR | E_ERROR | E_WARNING | E_PARSE
| E_USER_ERROR | E_USER_WARNING | E_RECOVERABLE_ERROR
);
# OR: shorter and all together
@franz-josef-kaiser
franz-josef-kaiser / 3vs4.md
Last active July 13, 2022 08:37
PHP Regex vs. DOMDocument
@franz-josef-kaiser
franz-josef-kaiser / ajax.js
Last active May 31, 2022 15:53
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.' );
@franz-josef-kaiser
franz-josef-kaiser / curl_dump.php
Last active May 22, 2022 14:57
Debug and dump a WordPress cURL Request and it's response during a WP HTTP API call.
<?php
/**
* Plugin Name: Dump WP HTTP API cURL Request & Response
* Author: Franz Josef Kaiser
*/
add_action( 'plugins_loaded', array( 'WPSE81791_cURL', 'init' ) );
class WPSE81791_cURL
{
protected static $instance;
@franz-josef-kaiser
franz-josef-kaiser / README.md
Last active May 13, 2022 01:01
Bash installer for different OS

Bash Installer

If you are collaborating with others, chances that not everyone's on the same OS are good. If you want to avoid "running on my machine" kind of problems, just share an installer script for your favorite binaries installers/ upgrader/ uninstallers. This is one way to do it.

This is a simple installer script that selects different installation methods based on the OS you are running this on.

How to

Just replace @TODO with whatever you are installing. Make sure to adjust the different installation methods some project/ program offers.

Linux currently is running a Git clone installer that symlinks into some $PATH supporting place. This does not clone the complete repo, but just the last commit!

Uninstallation

Git

@franz-josef-kaiser
franz-josef-kaiser / delay_publish.php
Created March 29, 2012 14:52
Delay the ability to publish posts
<?php
/**
* Plugin Name: Delay post publishing
* Plugin URI: http://unserkaiser.com
* Description: Only allows publishing a post if the user registered one week ago.
* Version: 0.1
* Author: Franz Josef Kaiser
* Author URI: http://unserkaiser.com
*/
// Not a WordPress context? Stop. Why? Ask @toscho