Make WordPress Core

Opened 18 years ago

Closed 18 years ago

Last modified 18 years ago

#5297 closed defect (bug) (invalid)

Unexpected behavior with plugins and global variables

Reported by: paulbutler's profile PaulButler Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Administration Keywords:
Focuses: Cc:

Description

When a plugin is written as a class, if a class variable is modified in the 'content_save_pre', by the time WordPress calls the 'notices' action the class variable has the same value it did before 'content_save_pre'. I have attached a plugin called test.php to demonstrate this. Make and save a new post in the post editor to test it. This may be a symptom of a larger problem (or feature?) that global variables are not preserved between those two calls (as demonstrated in testglobal.php)

I am using WordPress 2.3.1 on PHP 5 (mod_php) on an Apache2 server.

Attachments (2)

test.php (557 bytes) - added by PaulButler 18 years ago.
Example plugin to demonstrate the bug
testglobals.php (358 bytes) - added by PaulButler 18 years ago.

Download all attachments as: .zip

Change History (7)

@PaulButler
18 years ago

Example plugin to demonstrate the bug

#1 follow-up: @santosj
18 years ago

This is not a good test, it might be that admin_notices hook is called before content_save_pre. A valid test would be using the post of the content_save_*, if there is one.

#2 @santosj
18 years ago

Switch the hooks or use the same hook and call the array($testplugin, 'save') with a priority of 1 and the second with a priority of 10. Then come back and tell the results. If not, then I'll try to verify when I get home.

#3 @santosj
18 years ago

Also, unlikely, but it might also be that two different classes are being referenced and changed.

Use: array(&$testplugin, 'save') and see if it works. PHP5 obects are passed by reference, which means you shouldn't need to do that, but try it anyway.

#4 in reply to: ↑ 1 @filosofo
18 years ago

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

Replying to santosj:

This is not a good test, it might be that admin_notices hook is called before content_save_pre. A valid test would be using the post of the content_save_*, if there is one.

That's correct: WP includes the admin header (which requires menu-header.php, which in turn calls "admin_notices") before calling content_save_pre.

#5 @Nazgul
18 years ago

  • Milestone 2.5 deleted
Note: See TracTickets for help on using tickets.