Skip to content

Instantly share code, notes, and snippets.

Avatar

Michael Uno michaeluno

View GitHub Profile
@michaeluno
michaeluno / my-admin-page-template.php
Created Feb 5, 2013
A simple admin page template.
View my-admin-page-template.php
<?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 Feb 15, 2013
WordPress function. Retrieves the number of callbacks registered to the given hook.
View GetNumberOfCallbacks
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 Dec 13, 2015
An example to submit POST data with arrays to a web page that has a POST form.
View post.php
<?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 Feb 19, 2013
Applies allowing HTML tags with the KSES filter.
View test-kses-allow-tags.php
<?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 Dec 13, 2015
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.
View sample_array_merge.php
<?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 Dec 21, 2015
This is a demonstration plugin that shows how to add a custom link in the footer with Admin Page Framework ( v1.0.4.x ).
View admin-page-framework-demo-footer-link.php
@michaeluno
michaeluno / admin-page-framework-demo-form.php
Last active Dec 21, 2015
This is a very simple sample plugin for Admin Page Framework v2 that adds form elements.
View admin-page-framework-demo-form.php
<?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 Feb 2, 2018
Demonstrates the use of the import field with Admin Page Framework v2.
View admin-page-framework-import-csv.php
<?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 Dec 29, 2013
A PHP form demo to show the data structure of the submitted select fields.
View form_select.php
<?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>
View gridster.resize-patch.js
(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 = {});