| 1 | <?php |
|---|
| 2 | /* |
|---|
| 3 | Plugin Name: Plugin Header Test |
|---|
| 4 | Plugin URI: http://core.trac.wordpress.org/ticket/8964 |
|---|
| 5 | Description: Test plugin for the "Custom Header" functionality introduced in <a href="http://core.trac.wordpress.org/ticket/8964">WP Trac ticket 8964</a>. It outputs headers for itself to the PHP log. See plugin source for notes. |
|---|
| 6 | Author: Stephen Rider |
|---|
| 7 | Author URI: http://striderweb.com/nerdaphernalie |
|---|
| 8 | Version: 0.1 |
|---|
| 9 | Demo Header: Hello World |
|---|
| 10 | */ |
|---|
| 11 | |
|---|
| 12 | // NOTE: Yes, we could add two headers in one function. Using separate hooked functions demonstrates that two plugins separately adding new headers will work. |
|---|
| 13 | |
|---|
| 14 | function header_demo( $extra_headers ) { |
|---|
| 15 | $extra_headers[] = 'Demo Header'; |
|---|
| 16 | return $extra_headers; |
|---|
| 17 | } |
|---|
| 18 | add_filter( 'plugin_headers', 'header_demo' ); |
|---|
| 19 | |
|---|
| 20 | function header_demo2( $extra_headers ) { |
|---|
| 21 | $extra_headers[] = 'Another Demo Header'; |
|---|
| 22 | return $extra_headers; |
|---|
| 23 | } |
|---|
| 24 | add_filter( 'plugin_headers', 'header_demo2' ); |
|---|
| 25 | |
|---|
| 26 | // This demonstrated that a person can NOT mess up existing headers |
|---|
| 27 | function header_demo_malicious_attempt( $extra_headers ) { |
|---|
| 28 | // this adds new "foo" and "bar" headers, but doesn't affect the existing "Plugin URI" header |
|---|
| 29 | $extra_headers['Plugin URI'] = 'foo'; |
|---|
| 30 | $extra_headers['PluginURI'] = 'bar'; |
|---|
| 31 | |
|---|
| 32 | // this does nothing |
|---|
| 33 | $extra_headers['fnord'] = 'Name'; |
|---|
| 34 | |
|---|
| 35 | return $extra_headers; |
|---|
| 36 | } |
|---|
| 37 | add_filter( 'plugin_headers', 'header_demo_malicious_attempt' ); |
|---|
| 38 | |
|---|
| 39 | // echo to the PHP log |
|---|
| 40 | function log_headers_demo() { |
|---|
| 41 | $plugin_data = get_plugin_data( __FILE__ ); |
|---|
| 42 | error_log( 'Plugin Header Test plugin output:' ); |
|---|
| 43 | error_log( print_r( $plugin_data, true ) ); |
|---|
| 44 | } |
|---|
| 45 | add_action( 'admin_init', 'log_headers_demo' ); |
|---|
| 46 | |
|---|
| 47 | ?> |
|---|