3 Plugin Name: Sample Plugin
\r
4 Plugin URI: http://yourls.org/
\r
5 Description: Sample plugin to illustrate how actions and filters work. Read its source. Refer to the <a href="http://yourls.org/pluginapi">Plugin API documentation</a> for more details.
\r
8 Author URI: http://ozh.org/
\r
11 /* Example of an action
\r
13 * We're going to add an entry to the menu.
\r
15 * The menu is drawn by function yourls_html_menu() in file includes/functions-html.php.
\r
16 * Right before the function outputs the closing </ul>, notice the following function call:
\r
17 * yourls_do_action( 'admin_menu' );
\r
18 * This function says: "hey, for your information, I've just done something called 'admin menu', thought I'd let you know..."
\r
20 * We're going to hook into this action and add our menu entry
\r
23 yourls_add_action( 'admin_menu', 'ozh_sample_add_menu' );
\r
24 /* This says: when YOURLS does action 'admin_menu', call function 'ozh_sample_add_menu'
\r
27 function ozh_sample_add_menu() {
\r
28 echo '<li><a href="http://ozh.org/">Ozh</a></li>';
\r
30 /* And that's it. Activate the plugin and notice the new menu entry.
\r
35 /* Example of a filter
\r
37 * We're going to modify the <title> of pages in the admin area
\r
39 * The <title> tag is generated by function yourls_html_head() in includes/functions-html.php
\r
40 * Notice the following function call:
\r
41 * $title = yourls_apply_filter( 'html_title', 'YOURLS: Your Own URL Shortener' );
\r
42 * This function means: give $title the value "YOURLS: Your Own URL Shortener", unless a
\r
43 * filter modifies this value.
\r
45 * We're going to hook into this filter and modify this value.
\r
48 yourls_add_filter( 'html_title', 'ozh_sample_change_title' );
\r
49 /* This says: when filter 'html_title' is triggered, send its value to function 'ozh_sample_change_title'
\r
50 * and use what this function will return.
\r
53 function ozh_sample_change_title( $value ) {
\r
54 $value = $value . ' (we have hacked this title)';
\r
55 return $value; // a filter *always* has to return a value
\r
57 /* And that's it. Activate the plugin and notice how the page title changes */
\r