]> CyberLeo.Net >> Repos - Github/YOURLS.git/blob - user/plugins/sample-plugin/plugin.php
Prevent full path disclosure in case of direct calls. Fixes issue 646.
[Github/YOURLS.git] / user / plugins / sample-plugin / plugin.php
1 <?php\r
2 /*\r
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
6 Version: 0.1\r
7 Author: Ozh\r
8 Author URI: http://ozh.org/\r
9 */\r
10 \r
11 // No direct call\r
12 if( !defined( 'YOURLS_ABSPATH' ) ) die();\r
13 \r
14 /* Example of an action\r
15  *\r
16  * We're going to add an entry to the menu.\r
17  *\r
18  * The menu is drawn by function yourls_html_menu() in file includes/functions-html.php.\r
19  * Right before the function outputs the closing </ul>, notice the following function call:\r
20  * yourls_do_action( 'admin_menu' );\r
21  * This function says: "hey, for your information, I've just done something called 'admin menu', thought I'd let you know..."\r
22  *\r
23  * We're going to hook into this action and add our menu entry\r
24  */\r
25  \r
26 yourls_add_action( 'admin_menu', 'ozh_sample_add_menu' );\r
27 /* This says: when YOURLS does action 'admin_menu', call function 'ozh_sample_add_menu'\r
28  */\r
29 \r
30 function ozh_sample_add_menu() {\r
31         echo '<li><a href="http://ozh.org/">Ozh</a></li>';\r
32 }\r
33 /* And that's it. Activate the plugin and notice the new menu entry.\r
34  */\r
35 \r
36  \r
37 \r
38 /* Example of a filter\r
39  *\r
40  * We're going to modify the <title> of pages in the admin area\r
41  *\r
42  * The <title> tag is generated by function yourls_html_head() in includes/functions-html.php\r
43  * Notice the following function call:\r
44  * $title = yourls_apply_filter( 'html_title', 'YOURLS: Your Own URL Shortener' );\r
45  * This function means: give $title the value "YOURLS: Your Own URL Shortener", unless a\r
46  * filter modifies this value.\r
47  *\r
48  * We're going to hook into this filter and modify this value.\r
49  */\r
50  \r
51 yourls_add_filter( 'html_title', 'ozh_sample_change_title' );\r
52 /* This says: when filter 'html_title' is triggered, send its value to function 'ozh_sample_change_title'\r
53  * and use what this function will return.\r
54  */\r
55  \r
56 function ozh_sample_change_title( $value ) {\r
57         $value = $value . ' (we have hacked this title)';\r
58         return $value; // a filter *always* has to return a value\r
59 }\r
60 /* And that's it. Activate the plugin and notice how the page title changes */\r
61 \r