Make WordPress Core

Ticket #8964: trac-8964-demo.php

File trac-8964-demo.php, 1.6 KB (added by strider72, 15 years ago)

"Plugin Header Test" plugin that demonstrates usage and tests against potential abuse. See source for notes.

Line 
1<?php
2/*
3Plugin Name: Plugin Header Test
4Plugin URI: http://core.trac.wordpress.org/ticket/8964
5Description: 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.
6Author: Stephen Rider
7Author URI: http://striderweb.com/nerdaphernalie
8Version: 0.1
9Demo 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
14function header_demo( $extra_headers ) {
15        $extra_headers[] = 'Demo Header';
16        return $extra_headers;
17}
18add_filter( 'plugin_headers', 'header_demo' );
19
20function header_demo2( $extra_headers ) {
21        $extra_headers[] = 'Another Demo Header';
22        return $extra_headers;
23}
24add_filter( 'plugin_headers', 'header_demo2' );
25
26// This demonstrated that a person can NOT mess up existing headers
27function 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}
37add_filter( 'plugin_headers', 'header_demo_malicious_attempt' );
38
39// echo to the PHP log
40function 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}
45add_action( 'admin_init', 'log_headers_demo' );
46
47?>