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

Native WordPress functions don't work #380

Closed
vielhuber opened this issue Feb 5, 2020 · 4 comments
Closed

Native WordPress functions don't work #380

vielhuber opened this issue Feb 5, 2020 · 4 comments

Comments

@vielhuber
Copy link

vielhuber commented Feb 5, 2020

Question Answer
Box version 0.13.1
PHP version 7.3.12
Platform with version Windows WSL

I use php-scoper inside my own wordpress plugin.

However when using a native WP function inside my plugin (like update_option), I get the error:

Fatal error: Uncaught Error: Call to undefined function _PhpScoper530411ca8549\update_option()

php-scoper spits out the following code:

namespace _PhpScoper530411ca8549;
require_once __DIR__ . '/vendor/autoload.php';
\_PhpScoper530411ca8549\update_option('foo', 'bar');

Since update_option is not inside the namespace of the plugin (and comes outside from wordpress), this cannot work, or am I wrong?

Fiddling around with whitelist-global-functions doesn't change this behaviour.

Can you please help out? How do I exclude native wordpress functions from prefixing or even get them running with prefixing?

@vielhuber
Copy link
Author

I fixed this with:

  • Add a namespace MyCustomPlugin to my WordPress plugin file
  • Add 'whitelist' => ['MyCustomPlugin\*'] to scoper.inc.php to exclude all global functions called in this file.

@theofidry
Copy link
Member

@vielhuber to me it looks like you are missing the scoper-autoload.php file which is critical for any sort of whitelisting

@vielhuber
Copy link
Author

I included scoper-autoload.php. The problem is, that WordPress is outside of php-scopers influence.

@theofidry
Copy link
Member

Saw #303, I'll try to have a look to see if there is anything to change there

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants