Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Global variables not loaded into global scope #16

Open
dlh01 opened this issue Jan 6, 2025 · 1 comment
Open

Global variables not loaded into global scope #16

dlh01 opened this issue Jan 6, 2025 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@dlh01
Copy link
Member

dlh01 commented Jan 6, 2025

Description of the bug

Since the plugin loader includes plugin files within a function, variables defined by plugins in what would normally be global scope are not actually globalized.

Steps To Reproduce

See internal discussion at https://l.alley.dev/636711d9c8.

Additional Information

See workaround previously implemented at https://l.alley.dev/c0cc8fb23c, which is derived from https://github.com/Automattic/vip-go-mu-plugins/blob/60780fee97674a77a9ada2b25ce6dd4b6ebbd583/vip-helpers/vip-utils.php#L1381-L1424.

@dlh01 dlh01 added the bug Something isn't working label Jan 6, 2025
@attackant attackant self-assigned this Jan 24, 2025
@attackant
Copy link
Member

I tried these approaches, all resulting in the error:

  1. Using require_once in function scope
  2. Using require instead of require_once
  3. Using a closure with include
  4. Using extract($GLOBALS) with eval
  5. Manually declaring globals before evaluation
  6. Using Closure::bind() to unbind from current context
  7. Using output buffering with include
  8. Including wp-includes/plugin.php first
  9. Creating a temporary file for global scope execution

The core issue appears to be that we can't escape PHP's variable scoping rules within the class method, regardless of how we try to include the file.

Thinking we could use activate_plugin function?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants