East Toronto Web Design Meetup

This is the web page that accompanies the lecture given on April 5, 2011.

You may download the powerpoint from HERE.

myplugin.php

<?php
/*
Plugin Name: Sample 1
Description: Sample 1 does very little indeed.
*/

//////////////////////// START - USING FILTERS //////////////////////////
add_filter('the_content', 'add_my_name');

function add_my_name($content) {
	$content .= 'Peter';
	return $content;
}
//////////////////////// END - USING FILTERS //////////////////////////


//////////////////////// START - ADDING A MENU & USING ACTIONS //////////////////////////
function my_plugin_menu() {
	// add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function )
	add_menu_page('My Plugin Options', 'My Plugin', 'manage_options', 'my-unique-identifier', 'my_plugin_options');
}

if ( is_admin() ){
	add_action( 'admin_menu', 'my_plugin_menu' );
}
//////////////////////// END - ADDING A MENU & USING ACTIONS //////////////////////////




//////////////////////// START - ADDING SETTINGS //////////////////////////
function my_plugin_options() {
	echo '
		<div class='wrap'>
			<h2>My Plugin Options</h2>
			<form method='post' action='options.php'>
	';
	
	settings_fields( 'myoption-group' );
	
	echo '
				Add to Post:
				<input type='text' id='addtopost' name='addtopost' value="' . get_option('addtopost') . '" />
				<p class='submit'><input type='submit' class='button-primary' value='Save Changes' /></p>
			</form>
		</div>
	';
}

if ( is_admin() ){
	add_action( 'admin_init', 'register_mysettings' );
}

function register_mysettings() {
	register_setting( 'myoption-group', 'addtopost' );
}
//////////////////////// END - ADDING SETTINGS //////////////////////////



//////////////////////// START - USING OPTIONS //////////////////////////
add_filter('the_content', 'add_fancy_text');

function add_fancy_text($content) {
	$content .= get_option('addtopost');
	return $content;
}
//////////////////////// END - USING OPTIONS //////////////////////////

?>