WordPress plugin development plugin development (with pictures) Simon Wheatley WordPress plugin...

67
WordPress plugin development (with pictures) Simon Wheatley www.simonwheatley.co.uk

Transcript of WordPress plugin development plugin development (with pictures) Simon Wheatley WordPress plugin...

Page 1: WordPress plugin development plugin development (with pictures) Simon Wheatley WordPress plugin development (with pictures) Simon Wheatley plugins photo by djking anatomy of a plugin

WordPressplugin development

(with pictures)

Simon Wheatleywww.simonwheatley.co.uk

Page 2: WordPress plugin development plugin development (with pictures) Simon Wheatley WordPress plugin development (with pictures) Simon Wheatley plugins photo by djking anatomy of a plugin

WordPressplugin development

(with pictures)

Simon Wheatleywww.simonwheatley.co.uk

Page 5: WordPress plugin development plugin development (with pictures) Simon Wheatley WordPress plugin development (with pictures) Simon Wheatley plugins photo by djking anatomy of a plugin

<?php

/*Plugin Name: Flickr InsertPlugin URI: http://www.simonwheatley.co.uk/wordpress/Version: 1.0Description: Allows you to embed Flickr photos and photosets.Author: Simon WheatleyAuthor URI: http://www.simonwheatley.co.uk/

Copyright 2007 Simon Wheatley

(any licensing legal gubbins.)*/

?>

Page 6: WordPress plugin development plugin development (with pictures) Simon Wheatley WordPress plugin development (with pictures) Simon Wheatley plugins photo by djking anatomy of a plugin
Page 7: WordPress plugin development plugin development (with pictures) Simon Wheatley WordPress plugin development (with pictures) Simon Wheatley plugins photo by djking anatomy of a plugin

<?php

/*Plugin Name: Flickr Insert*/

?>

Page 8: WordPress plugin development plugin development (with pictures) Simon Wheatley WordPress plugin development (with pictures) Simon Wheatley plugins photo by djking anatomy of a plugin

actions

photo from Davidson College

Page 10: WordPress plugin development plugin development (with pictures) Simon Wheatley WordPress plugin development (with pictures) Simon Wheatley plugins photo by djking anatomy of a plugin

actions

Page 11: WordPress plugin development plugin development (with pictures) Simon Wheatley WordPress plugin development (with pictures) Simon Wheatley plugins photo by djking anatomy of a plugin
Page 12: WordPress plugin development plugin development (with pictures) Simon Wheatley WordPress plugin development (with pictures) Simon Wheatley plugins photo by djking anatomy of a plugin

function bi_insert_bg_css() {$img_id = bi_get_bg_img_id();$img_path = bi_img_path( $img_id );

$css = "<style type='text/css'>\n";$css .= "body {\n";$css .= "background-image: url($img_path)\n”";$css .= "}\n";$css .= "</style>\n";

echo $css;}

add_action('wp_head', 'bi_insert_bg_css');

Page 14: WordPress plugin development plugin development (with pictures) Simon Wheatley WordPress plugin development (with pictures) Simon Wheatley plugins photo by djking anatomy of a plugin

function bi_insert_bg_css() {$img_id = bi_get_bg_img_id();$img_path = bi_img_path( $img_id );

$css = "<style type='text/css'>\n";$css .= "body {\n";$css .= "background-image: url($img_path)\n”";$css .= "}\n";$css .= "</style>\n";

echo $css;}

add_action('wp_head', 'bi_insert_bg_css');

Page 15: WordPress plugin development plugin development (with pictures) Simon Wheatley WordPress plugin development (with pictures) Simon Wheatley plugins photo by djking anatomy of a plugin

function bi_insert_bg_css() {$img_id = bi_get_bg_img_id();$img_path = bi_img_path( $img_id );

$css = "<style type='text/css'>\n";$css .= "body {\n";$css .= "background-image: url($img_path)\n”";$css .= "}\n";$css .= "</style>\n";

echo $css;}

add_action('wp_head', 'bi_insert_bg_css');

Page 16: WordPress plugin development plugin development (with pictures) Simon Wheatley WordPress plugin development (with pictures) Simon Wheatley plugins photo by djking anatomy of a plugin

filters

Page 17: WordPress plugin development plugin development (with pictures) Simon Wheatley WordPress plugin development (with pictures) Simon Wheatley plugins photo by djking anatomy of a plugin
Page 18: WordPress plugin development plugin development (with pictures) Simon Wheatley WordPress plugin development (with pictures) Simon Wheatley plugins photo by djking anatomy of a plugin

function ep_exclude_pages( $pages ){$excluded_ids = ep_get_excluded_ids();$length = count( $pages );for ( $i=0; $i<$length; $i++ ) { $page = & $pages[$i]; if ( in_array( $page->ID, $excluded_ids ) ) { unset( $pages[$i] ); }}// Reindex the array, for neatness$pages = array_values( $pages );return $pages;}

add_filter('get_pages','ep_exclude_pages');

Page 19: WordPress plugin development plugin development (with pictures) Simon Wheatley WordPress plugin development (with pictures) Simon Wheatley plugins photo by djking anatomy of a plugin

function ep_exclude_pages( $pages ){$excluded_ids = ep_get_excluded_ids();$length = count( $pages );for ( $i=0; $i<$length; $i++ ) { $page = & $pages[$i]; if ( in_array( $page->ID, $excluded_ids ) ) { unset( $pages[$i] ); }}// Reindex the array, for neatness$pages = array_values( $pages );return $pages;}

add_filter('get_pages','ep_exclude_pages');

Page 20: WordPress plugin development plugin development (with pictures) Simon Wheatley WordPress plugin development (with pictures) Simon Wheatley plugins photo by djking anatomy of a plugin

function ep_exclude_pages( $pages ){$excluded_ids = ep_get_excluded_ids();$length = count( $pages );for ( $i=0; $i<$length; $i++ ) { $page = & $pages[$i]; if ( in_array( $page->ID, $excluded_ids ) ) { unset( $pages[$i] ); }}// Reindex the array, for neatness$pages = array_values( $pages );return $pages;}

add_filter('get_pages','ep_exclude_pages');

Page 21: WordPress plugin development plugin development (with pictures) Simon Wheatley WordPress plugin development (with pictures) Simon Wheatley plugins photo by djking anatomy of a plugin

actions

Page 22: WordPress plugin development plugin development (with pictures) Simon Wheatley WordPress plugin development (with pictures) Simon Wheatley plugins photo by djking anatomy of a plugin

filters

Page 23: WordPress plugin development plugin development (with pictures) Simon Wheatley WordPress plugin development (with pictures) Simon Wheatley plugins photo by djking anatomy of a plugin
Page 24: WordPress plugin development plugin development (with pictures) Simon Wheatley WordPress plugin development (with pictures) Simon Wheatley plugins photo by djking anatomy of a plugin
Page 25: WordPress plugin development plugin development (with pictures) Simon Wheatley WordPress plugin development (with pictures) Simon Wheatley plugins photo by djking anatomy of a plugin
Page 26: WordPress plugin development plugin development (with pictures) Simon Wheatley WordPress plugin development (with pictures) Simon Wheatley plugins photo by djking anatomy of a plugin
Page 27: WordPress plugin development plugin development (with pictures) Simon Wheatley WordPress plugin development (with pictures) Simon Wheatley plugins photo by djking anatomy of a plugin
Page 28: WordPress plugin development plugin development (with pictures) Simon Wheatley WordPress plugin development (with pictures) Simon Wheatley plugins photo by djking anatomy of a plugin
Page 31: WordPress plugin development plugin development (with pictures) Simon Wheatley WordPress plugin development (with pictures) Simon Wheatley plugins photo by djking anatomy of a plugin
Page 32: WordPress plugin development plugin development (with pictures) Simon Wheatley WordPress plugin development (with pictures) Simon Wheatley plugins photo by djking anatomy of a plugin

define( 'FI_WEB_PATH', '/wp-content/plugins/flickr-insert' );

function fi_mce_external_plugins( $plugins ) {$plugins['flickr'] = get_bloginfo('wpurl') . FI_WEB_PATH . '/tinymce/editor_plugin.js';return $plugins;}function fi_addbuttons() {if ( ! current_user_can('edit_posts') && !current_user_can('edit_pages') ) return;if ( ! get_user_option('rich_editing') ) return;add_filter( 'mce_external_plugins', 'fi_mce_external_plugins' );}

add_action('init', 'fi_addbuttons' );

Page 33: WordPress plugin development plugin development (with pictures) Simon Wheatley WordPress plugin development (with pictures) Simon Wheatley plugins photo by djking anatomy of a plugin

define( 'FI_WEB_PATH', '/wp-content/plugins/flickr-insert' );

function fi_mce_external_plugins( $plugins ) {$plugins['flickr'] = get_bloginfo('wpurl') . FI_WEB_PATH . '/tinymce/editor_plugin.js';return $plugins;}function fi_addbuttons() {if ( ! current_user_can('edit_posts') && !current_user_can('edit_pages') ) return;if ( ! get_user_option('rich_editing') ) return;add_filter( 'mce_external_plugins', 'fi_mce_external_plugins' );}

add_action('init', 'fi_addbuttons' );

Page 34: WordPress plugin development plugin development (with pictures) Simon Wheatley WordPress plugin development (with pictures) Simon Wheatley plugins photo by djking anatomy of a plugin

define( 'FI_WEB_PATH', '/wp-content/plugins/flickr-insert' );

function fi_mce_external_plugins( $plugins ) {$plugins['flickr'] = get_bloginfo('wpurl') . FI_WEB_PATH . '/tinymce/editor_plugin.js';return $plugins;}function fi_addbuttons() {if ( ! current_user_can('edit_posts') && !current_user_can('edit_pages') ) return;if ( ! get_user_option('rich_editing') ) return;add_filter( 'mce_external_plugins', 'fi_mce_external_plugins' );}

add_action('init', 'fi_addbuttons' );

Page 35: WordPress plugin development plugin development (with pictures) Simon Wheatley WordPress plugin development (with pictures) Simon Wheatley plugins photo by djking anatomy of a plugin

define( 'FI_WEB_PATH', '/wp-content/plugins/flickr-insert' );

function fi_mce_external_plugins( $plugins ) {$plugins['flickr'] = get_bloginfo('wpurl') . FI_WEB_PATH . '/tinymce/editor_plugin.js';return $plugins;}function fi_addbuttons() {if ( ! current_user_can('edit_posts') && !current_user_can('edit_pages') ) return;if ( ! get_user_option('rich_editing') ) return;add_filter( 'mce_external_plugins', 'fi_mce_external_plugins' );}

add_action('init', 'fi_addbuttons' );

Page 36: WordPress plugin development plugin development (with pictures) Simon Wheatley WordPress plugin development (with pictures) Simon Wheatley plugins photo by djking anatomy of a plugin

(function() { tinymce.PluginManager.requireLangPack('flickr');tinymce.create('tinymce.plugins.FlickrInsert', {init : function(ed, url) {ed.addButton('flickr', { title : 'flickr.desc', cmd : 'mceFlickr', image : url + '/img/flickr.gif' });ed.onNodeChange.add(function(ed, cm, n) {cm.setActive('flickr', n.nodeName == 'IMG');});}

tinymce.PluginManager.add('flickr', tinymce.plugins.FlickrInsert);})();

Page 37: WordPress plugin development plugin development (with pictures) Simon Wheatley WordPress plugin development (with pictures) Simon Wheatley plugins photo by djking anatomy of a plugin

(function() { tinymce.PluginManager.requireLangPack('flickr');tinymce.create('tinymce.plugins.FlickrInsert', {init : function(ed, url) {ed.addButton('flickr', { title : 'flickr.desc', cmd : 'mceFlickr', image : url + '/img/flickr.gif' });ed.onNodeChange.add(function(ed, cm, n) {cm.setActive('flickr', n.nodeName == 'IMG');});}

tinymce.PluginManager.add('flickr', tinymce.plugins.FlickrInsert);})();

Page 38: WordPress plugin development plugin development (with pictures) Simon Wheatley WordPress plugin development (with pictures) Simon Wheatley plugins photo by djking anatomy of a plugin

(function() { tinymce.PluginManager.requireLangPack('flickr');tinymce.create('tinymce.plugins.FlickrInsert', {init : function(ed, url) {ed.addButton('flickr', { title : 'flickr.desc', cmd : 'mceFlickr', image : url + '/img/flickr.gif' });ed.onNodeChange.add(function(ed, cm, n) {cm.setActive('flickr', n.nodeName == 'IMG');});}

tinymce.PluginManager.add('flickr', tinymce.plugins.FlickrInsert);})();

Page 39: WordPress plugin development plugin development (with pictures) Simon Wheatley WordPress plugin development (with pictures) Simon Wheatley plugins photo by djking anatomy of a plugin

(function() { tinymce.PluginManager.requireLangPack('flickr');tinymce.create('tinymce.plugins.FlickrInsert', {init : function(ed, url) {ed.addButton('flickr', { title : 'flickr.desc', cmd : 'mceFlickr', image : url + '/img/flickr.gif' });ed.onNodeChange.add(function(ed, cm, n) {cm.setActive('flickr', n.nodeName == 'IMG');});}

tinymce.PluginManager.add('flickr', tinymce.plugins.FlickrInsert);})();

Page 40: WordPress plugin development plugin development (with pictures) Simon Wheatley WordPress plugin development (with pictures) Simon Wheatley plugins photo by djking anatomy of a plugin

(function() { tinymce.PluginManager.requireLangPack('flickr');tinymce.create('tinymce.plugins.FlickrInsert', {init : function(ed, url) {ed.addButton('flickr', { title : 'flickr.desc', cmd : 'mceFlickr', image : url + '/img/flickr.gif' });ed.onNodeChange.add(function(ed, cm, n) {cm.setActive('flickr', n.nodeName == 'IMG');});}

tinymce.PluginManager.add('flickr', tinymce.plugins.FlickrInsert);})();

Page 41: WordPress plugin development plugin development (with pictures) Simon Wheatley WordPress plugin development (with pictures) Simon Wheatley plugins photo by djking anatomy of a plugin

popup dialog

photo by Kiff ta race / undercensure

Page 42: WordPress plugin development plugin development (with pictures) Simon Wheatley WordPress plugin development (with pictures) Simon Wheatley plugins photo by djking anatomy of a plugin
Page 43: WordPress plugin development plugin development (with pictures) Simon Wheatley WordPress plugin development (with pictures) Simon Wheatley plugins photo by djking anatomy of a plugin

(function() { tinymce.PluginManager.requireLangPack('flickr');tinymce.create('tinymce.plugins.FlickrInsert', {init : function(ed, url) {ed.addButton('flickr', { title : 'flickr.desc', cmd : 'mceFlickr', image : url + '/img/flickr.gif' });ed.onNodeChange.add(function(ed, cm, n) {cm.setActive('flickr', n.nodeName == 'IMG');});}

tinymce.PluginManager.add('flickr', tinymce.plugins.FlickrInsert);})();

Page 44: WordPress plugin development plugin development (with pictures) Simon Wheatley WordPress plugin development (with pictures) Simon Wheatley plugins photo by djking anatomy of a plugin

ed.addCommand('mceFlickr', function() { ed.windowManager.open({ file : url + '/../../../../wp-admin/?fi_dialog=1', width : 640 + parseInt(ed.getLang('flickr.delta_width', 0)), height : 430 + parseInt(ed.getLang('flickr.delta_height', 0)), inline : 1}, { plugin_url : url });});

Page 45: WordPress plugin development plugin development (with pictures) Simon Wheatley WordPress plugin development (with pictures) Simon Wheatley plugins photo by djking anatomy of a plugin

(function() { tinymce.PluginManager.requireLangPack('flickr');tinymce.create('tinymce.plugins.FlickrInsert', {init : function(ed, url) {ed.addCommand('mceFlickr', function() { ed.windowManager.open({ file : url + '/../../../../wp-admin/?fi_dialog=1', width : 640 + parseInt(ed.getLang('flickr.delta_width', 0)), height : 430 + parseInt(ed.getLang('flickr.delta_height', 0)), inline : 1}, { plugin_url : url });});}tinymce.PluginManager.add('flickr', tinymce.plugins.FlickrInsert);})();

Page 46: WordPress plugin development plugin development (with pictures) Simon Wheatley WordPress plugin development (with pictures) Simon Wheatley plugins photo by djking anatomy of a plugin
Page 48: WordPress plugin development plugin development (with pictures) Simon Wheatley WordPress plugin development (with pictures) Simon Wheatley plugins photo by djking anatomy of a plugin

function fi_photo_query() { $fi_photo = @ $_GET['fi_photo']; if ( ! $fi_photo ) return; $f = & fi_flickr(); $fi_photo_id = @ $_GET['fi_photo_id']; $photo = $f->photos_getInfo( $fi_photo_id ); $href = $f->buildPhotoURL($photo, "medium"); $src = $f->buildPhotoURL($photo, "small"); $alt = addslashes( $photo['title'] ); $data = array( 'href' => $href, 'src' => $src, 'alt' => $alt ); $json = new Moxiecode_JSON(); echo $json->encode( $data ); exit;}

// Answer various AJAX queriesadd_action('init', 'fi_photo_query', -10 );

Page 49: WordPress plugin development plugin development (with pictures) Simon Wheatley WordPress plugin development (with pictures) Simon Wheatley plugins photo by djking anatomy of a plugin

require_once( ABSPATH . "/wp-includes/js/tinymce/plugins/spellchecker/classes/utils/JSON.php" );

Page 50: WordPress plugin development plugin development (with pictures) Simon Wheatley WordPress plugin development (with pictures) Simon Wheatley plugins photo by djking anatomy of a plugin
Page 53: WordPress plugin development plugin development (with pictures) Simon Wheatley WordPress plugin development (with pictures) Simon Wheatley plugins photo by djking anatomy of a plugin

// Parse the photoset shortcodefunction fi_shortcode( $atts, $content ) { $photoset_id = fi_photoset_id( $content ); $html = fi_photoset( $photoset_id ); return $html;}

// Register the Flickr shortcodeadd_shortcode('flickr-photoset', 'fi_shortcode');

Page 54: WordPress plugin development plugin development (with pictures) Simon Wheatley WordPress plugin development (with pictures) Simon Wheatley plugins photo by djking anatomy of a plugin

// Parse the photoset shortcodefunction fi_shortcode( $atts, $content ) { $photoset_id = fi_photoset_id( $content ); $html = fi_photoset( $photoset_id ); return $html;}

// Register the Flickr shortcodeadd_shortcode('flickr-photoset', 'fi_shortcode');

Page 55: WordPress plugin development plugin development (with pictures) Simon Wheatley WordPress plugin development (with pictures) Simon Wheatley plugins photo by djking anatomy of a plugin

// Parse the photoset shortcodefunction fi_shortcode( $atts, $content ) { $photoset_id = fi_photoset_id( $content ); $html = fi_photoset( $photoset_id ); return $html;}

// Register the Flickr shortcodeadd_shortcode('flickr-photoset', 'fi_shortcode');

Page 56: WordPress plugin development plugin development (with pictures) Simon Wheatley WordPress plugin development (with pictures) Simon Wheatley plugins photo by djking anatomy of a plugin
Page 57: WordPress plugin development plugin development (with pictures) Simon Wheatley WordPress plugin development (with pictures) Simon Wheatley plugins photo by djking anatomy of a plugin
Page 59: WordPress plugin development plugin development (with pictures) Simon Wheatley WordPress plugin development (with pictures) Simon Wheatley plugins photo by djking anatomy of a plugin

define( 'FI_WEB_PATH', '/wp-content/plugins/flickr-insert' );

function fi_js(){$site_url = get_option( 'siteurl' );$lightbox_script = $site_url . FI_WEB_PATH . '/jquery.lightbox-0.5.pack.js';

wp_enqueue_script( 'jquery-lightbox', $lightbox_script, array('jquery'), '0.5' );}

add_action('wp_head', 'sd_js', 5);

Page 60: WordPress plugin development plugin development (with pictures) Simon Wheatley WordPress plugin development (with pictures) Simon Wheatley plugins photo by djking anatomy of a plugin

define( 'FI_WEB_PATH', '/wp-content/plugins/flickr-insert' );

function fi_js(){$site_url = get_option( 'siteurl' );$lightbox_script = $site_url . FI_WEB_PATH . '/jquery.lightbox-0.5.pack.js';

wp_enqueue_script( 'jquery-lightbox', $lightbox_script, array('jquery'), '0.5' );}

add_action('wp_head', 'sd_js', 5);

Page 61: WordPress plugin development plugin development (with pictures) Simon Wheatley WordPress plugin development (with pictures) Simon Wheatley plugins photo by djking anatomy of a plugin

define( 'FI_WEB_PATH', '/wp-content/plugins/flickr-insert' );

function fi_js(){$site_url = get_option( 'siteurl' );$lightbox_script = $site_url . FI_WEB_PATH . '/jquery.lightbox-0.5.pack.js';

wp_enqueue_script( 'jquery-lightbox', $lightbox_script, array('jquery'), '0.5' );}

add_action('wp_head', 'sd_js', 5);

Page 63: WordPress plugin development plugin development (with pictures) Simon Wheatley WordPress plugin development (with pictures) Simon Wheatley plugins photo by djking anatomy of a plugin

define( 'FI_WEB_PATH', '/wp-content/plugins/flickr-insert' );

function fi_css(){$site_url = get_option( 'siteurl' );$css = $site_url . FI_WEB_PATH . '/screen.css';

wp_enqueue_style( 'fi_screen', $css );}

add_action('wp_head', 'fi_js', 5);

Page 64: WordPress plugin development plugin development (with pictures) Simon Wheatley WordPress plugin development (with pictures) Simon Wheatley plugins photo by djking anatomy of a plugin

define( 'FI_WEB_PATH', '/wp-content/plugins/flickr-insert' );

function fi_css(){$site_url = get_option( 'siteurl' );$css = $site_url . FI_WEB_PATH . '/screen.css';

wp_enqueue_style( 'fi_screen', $css );}

add_action('wp_head', 'fi_js', 5);

Page 65: WordPress plugin development plugin development (with pictures) Simon Wheatley WordPress plugin development (with pictures) Simon Wheatley plugins photo by djking anatomy of a plugin

define( 'FI_WEB_PATH', '/wp-content/plugins/flickr-insert' );

function fi_css(){$site_url = get_option( 'siteurl' );$css = $site_url . FI_WEB_PATH . '/screen.css';

wp_enqueue_style( 'fi_screen', $css );}

add_action('wp_head', 'fi_js', 5);

Page 67: WordPress plugin development plugin development (with pictures) Simon Wheatley WordPress plugin development (with pictures) Simon Wheatley plugins photo by djking anatomy of a plugin

that was an WordPress

plugin development(with pictures)

Simon Wheatleywww.simonwheatley.co.uk