#5297 closed defect (bug) (invalid)
Unexpected behavior with plugins and global variables
| Reported by: | PaulButler | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Administration | Version: | |
| Severity: | normal | Keywords: | |
| Cc: | Focuses: |
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)
Change History (7)
#1
follow-up:
↓ 4
@
19 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
@
19 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
@
19 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
@
19 years ago
- Resolution → invalid
- Status new → 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.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Example plugin to demonstrate the bug