From 28b6cec59d959f3e269a546acae89688fadd4da5 Mon Sep 17 00:00:00 2001 From: ozhozh Date: Fri, 28 May 2010 08:30:57 +0000 Subject: [PATCH] Sample plugin to illustrate how things work git-svn-id: http://yourls.googlecode.com/svn/trunk@365 12232710-3e20-11de-b438-597f59cd7555 --- user/plugins/sample-plugin/plugin.php | 58 +++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 user/plugins/sample-plugin/plugin.php diff --git a/user/plugins/sample-plugin/plugin.php b/user/plugins/sample-plugin/plugin.php new file mode 100644 index 0000000..ba90d37 --- /dev/null +++ b/user/plugins/sample-plugin/plugin.php @@ -0,0 +1,58 @@ +Plugin API documentation for more details. +Version: 0.1 +Author: Ozh +Author URI: http://ozh.org/ +*/ + +/* Example of an action + * + * We're going to add an entry to the menu. + * + * The menu is drawn by function yourls_html_menu() in file includes/functions-html.php. + * Right before the function outputs the closing , notice the following function call: + * yourls_do_action( 'admin_menu' ); + * This function says: "hey, for your information, I've just done something called 'admin menu', thought I'd let you know..." + * + * We're going to hook into this action and add our menu entry + */ + +yourls_add_action( 'admin_menu', 'ozh_sample_add_menu' ); +/* This says: when YOURLS does action 'admin_menu', call function 'ozh_sample_add_menu' + */ + +function ozh_sample_add_menu() { + echo '
  • Ozh
  • '; +} +/* And that's it. Activate the plugin and notice the new menu entry. + */ + + + +/* Example of a filter + * + * We're going to modify the of pages in the admin area + * + * The <title> tag is generated by function yourls_html_head() in includes/functions-html.php + * Notice the following function call: + * $title = yourls_apply_filter( 'html_title', 'YOURLS: Your Own URL Shortener' ); + * This function means: give $title the value "YOURLS: Your Own URL Shortener", unless a + * filter modifies this value. + * + * We're going to hook into this filter and modify this value. + */ + +yourls_add_filter( 'html_title', 'ozh_sample_change_title' ); +/* This says: when filter 'html_title' is triggered, send its value to function 'ozh_sample_change_title' + * and use what this function will return. + */ + +function ozh_sample_change_title( $value ) { + $value = $value . ' (we have hacked this title)'; + return $value; // a filter *always* has to return a value +} +/* And that's it. Activate the plugin and notice how the page title changes */ + -- 2.45.0