WordPress.org

Make WordPress Core

Ticket #18699: noheader-test.php

File noheader-test.php, 1.0 KB (added by shauno, 3 years ago)

Short plugin demo'ing the issue described

Line 
1<?php
2/*
3Plugin Name: Demonstration of noheader bug
4Plugin URI:
5Description: Demonstration of noheader bug
6*/
7
8add_action('admin_menu', 'test_admin_menus');
9
10function test_admin_menus() {
11        $pluginPage = add_options_page('noheader test', 'noheader test', 'manage_options', 'noheader-test', 'test_display');
12        add_action('admin_head-'.$pluginPage,'test_admin_head');
13       
14}
15
16function test_admin_head() {
17        //create a global var, so we know if run
18        global $test_variable_to_test;
19        $test_variable_to_test = 'PHP included!';
20}
21
22function test_display() {
23        if ($_GET['noheader']) {require_once(ABSPATH.'wp-admin/admin-header.php');} //include the header if not included by WP
24       
25        global $test_variable_to_test;
26       
27        echo '<p>$test_variable_to_test was set to: <strong>'.$test_variable_to_test.'</strong></p>';
28
29        echo '<form method="POST" action="'.get_bloginfo('url').'/wp-admin/options-general.php?page='.$_GET['page'].'&noheader=1">';
30        echo '<p>Submit this form to see the $test_variable_to_test variable disapper</p>';
31        echo '<input type="submit" />';
32        echo '</form>';
33}