Skip to content

Instantly share code, notes, and snippets.

@michaeluno
michaeluno / my-admin-page-template.php
Created February 5, 2013 10:32
A simple admin page template.
<?php
/* Plugin Name: My Admin Page Template */
add_action( 'admin_menu', 'my_admin_menu_func' );
function my_admin_menu_func() {
add_options_page( "My Admin Page", "My Admin Page", "manage_options", "my_admin_page_slug", "my_admin_page_func" );
}
function my_admin_page_func() {
?>
<div class="wrap">
@michaeluno
michaeluno / GetNumberOfCallbacks
Created February 15, 2013 13:04
WordPress function. Retrieves the number of callbacks registered to the given hook.
function GetNumberOfCallbacks( $strHook='' ) {
global $wp_filter;
if( empty( $strHook ) || !isset( $wp_filter[$strHook] ) ) return;
return count( $wp_filter[$strHook] );
}
@michaeluno
michaeluno / post.php
Last active December 13, 2015 19:58
An example to submit POST data with arrays to a web page that has a POST form.
<?php
if ( isset( $_POST['login'] ) )
die( '<pre>' . print_r( $_POST, true ) . '</pre>' ) ;
?>
<html>
<body>
<form accept-charset="UTF-8" action="" method="post">
<ul class="clear-float">
<li><label for="user_login">Login ID</label>
@michaeluno
michaeluno / test-kses-allow-tags.php
Created February 19, 2013 05:52
Applies allowing HTML tags with the KSES filter.
<?php
/*
Plugin Name: Test - Kses Allow Tags
Plugin URI:
Description:
Version: 0.0.0.1
Author: Michael Uno
Author URI: http://michaeluno.jp
*/
@michaeluno
michaeluno / sample_array_merge.php
Last active December 13, 2015 22:39
array_merge() is useful to merge arrays but it is confusing which parameter takes precedence. Also it is different from the method with the plus operator. ( e.g. $arr1 + $arr2 ). It could be more like join two array elements. So it may be used to append or pre-pend numerically indexed arrays.
<?php
$array1 = array( 'a', 'b', 'c' );
$array2 = array( 'd', 'e', );
$result1 = array_merge( $array2, $array1 );
$result2 = array_merge( $array1, $array2 );
echo '<pre>' . print_r( $result1, true ) . '</pre>';
echo '<pre>' . print_r( $result2, true ) . '</pre>';
@michaeluno
michaeluno / admin-page-framework-demo-footer-link.php
Last active December 21, 2015 02:49
This is a demonstration plugin that shows how to add a custom link in the footer with Admin Page Framework ( v1.0.4.x ).
@michaeluno
michaeluno / admin-page-framework-demo-form.php
Last active December 21, 2015 09:18
This is a very simple sample plugin for Admin Page Framework v2 that adds form elements.
<?php
/*
Plugin Name: Admin Page Framework - Sample Form Elements
Plugin URI: http://en.michaeluno.jp/admin-page-framework
Description: Demonstrates adding a form elements for Admin Page Framework v2.0.0 or above.
Author: Michael Uno
Author URI: http://michaeluno.jp
Version: 0.0.1
Requirements: PHP 5.2.4 or above, WordPress 3.2 or above, Admin Page Framework 2.0.0 or above.
*/
@michaeluno
michaeluno / admin-page-framework-import-csv.php
Last active February 2, 2018 18:32
Demonstrates the use of the import field with Admin Page Framework v2.
<?php
/*
Plugin Name: Admin Page Framework - Import CSV
Plugin URI: http://en.michaeluno.jp/admin-page-framework
Description: Demonstrates the use of the import field.
Author: Michael Uno
Author URI: http://michaeluno.jp
Version: 0.0.2
Requirements: PHP 5.2.4 or above, WordPress 3.3 or above. Admin Page Framework v2.1.7b or above.
*/
@michaeluno
michaeluno / form_select.php
Created December 29, 2013 08:34
A PHP form demo to show the data structure of the submitted select fields.
<?php
if ( isset( $_POST['save'] ) )
die( '<pre>' . print_r( $_POST, true ) . '</pre>' );
?>
<html>
<body>
<form accept-charset="UTF-8" action="" method="post">
<select name="single_select" size="1" >
<option value="apple">Apple</option>
(function($) {
$.Gridster.generate_stylesheet = function(opts) {
var styles = '';
var max_size_x = this.options.max_size_x || this.cols;
var max_rows = 0;
var max_cols = 0;
var i;
var rules;
opts || (opts = {});