Make WordPress Core

Opened 17 years ago

Closed 16 years ago

Last modified 15 years ago

#4062 closed defect (bug) (wontfix)

Implicit global var references in menu-header.php

Reported by: rgovostes's profile rgovostes Owned by:
Milestone: Priority: low
Severity: normal Version: 2.1.2
Component: Administration Keywords:
Focuses: Cc:

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)

#1 @rob1n
17 years ago

  • Cc rob1n added

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.

#2 @rgovostes
17 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...

#3 @lloydbudd
16 years ago

  • Milestone 2.5 deleted

No traction closing a won't fix for now.

#4 @DD32
16 years ago

  • Resolution set to wontfix
  • Status changed from new to closed

Closing as wontfix on lloydbudd's comment

Note: See TracTickets for help on using tickets.