#4062 closed defect (bug) (wontfix)
Implicit global var references in menu-header.php
| Reported by: | rgovostes | Owned by: | |
|---|---|---|---|
| Priority: | low | Milestone: | |
| Component: | Administration | Version: | 2.1.2 |
| Severity: | normal | Keywords: | |
| Cc: | Focuses: |
Description
menu-header.php references several global variables ($menu, $submenu, $parent_file, $submenu_file, maybe others). These should be explicitly referenced via the 'global' keyword at the top of the file.
Change History (4)
#2
@
19 years ago
I am writing a plugin to replace WordPress's page editor. I was originally doing this by starting an output buffer in the admin_header and then replacing the contents of the buffer with my custom PHP file, but I ran into problems with WP_Scripts not outputting JavaScript calls that had already been printed in the "first rendering."
My second solution was to exploit the fact that pages.php calls wp_redirect if the action specified isn't handled by its switch. First, I rewrote all the Edit links in the pages list to use a different action. (thus, #4058). Then I used a filter on wp_redirect to handle the action myself -- including the admin header, the new form, and finally, the admin footer.
However, I was getting PHP errors from the script that generates the menubar because $menu wasn't defined (in the foreach loop, line 8). The solution was to write "global $menu, $submenu, ..." on the line before I include'd the header.
If there is a better way than how I'm going about this, save for replacing the in-built edit form, I'd be open to hear it. It seems that each method I've looked into requires hacks and workarounds...
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Why? My understanding of PHP is that any code in the global scope uses global variables. Only in functions and classes do you have to explicitly declare global variables.