Skip to content

Instantly share code, notes, and snippets.

@michaeluno
michaeluno / LinkFieldType.php
Created May 26, 2014 09:35
An example definition class of the link custom field type for Admin Page Framework.
<?php
if ( ! class_exists( 'LinkFieldType' ) ) :
class LinkFieldType extends AdminPageFramework_FieldType {
/**
* Defines the field type slugs used for this field type.
*/
public $aFieldTypeSlugs = array( 'link', );
/**
@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 / tutorials-01-create-an-admin-page.php
Last active December 24, 2015 07:37
Creates an admin page with Admin Page Framework v3. This is an example plugin introduced in the tutorial, Create an Admin Page (http://en.michaeluno.jp/admin-page-framework/tutorials-v3/01-create-an-admin-page/).
<?php
/*
Plugin Name: Admin Page Framework Tutorial 01 - Create an Admin Page
Plugin URI: http://en.michaeluno.jp/admin-page-framework
Description: Creates an admin page with Admin Page Framework v3
Author: Michael Uno
Author URI: http://michaeluno.jp
Version: 1.0.2
Requirements: PHP 5.2.4 or above, WordPress 3.4 or above. Admin Page Framework 3.0.0 or above
*/
@michaeluno
michaeluno / tutorials-02-create-a-form.php
Last active December 24, 2015 08:05
Creates a form in an admin page with Admin Page Framework v3. This is an example plugin introduced in the tutorial, Create a Form (http://en.michaeluno.jp/admin-page-framework/tutorials-v3/02-create-a-form/).
<?php
/*
Plugin Name: Admin Page Framework Tutorial 02 - Create a Form
Plugin URI: http://en.michaeluno.jp/admin-page-framework
Description: Creates a form in an admin page with Admin Page Framework v3
Author: Michael Uno
Author URI: http://michaeluno.jp
Version: 1.0.2
Requirements: PHP 5.2.4 or above, WordPress 3.4 or above. Admin Page Framework 3.1.3 or above
*/