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

Issue with Namespacing Google Libraries in WordPress Plugin #2572

Open
bilal-ahmed-wpb opened this issue Mar 2, 2024 · 2 comments
Open

Issue with Namespacing Google Libraries in WordPress Plugin #2572

bilal-ahmed-wpb opened this issue Mar 2, 2024 · 2 comments
Assignees
Labels
priority: p3 Desirable enhancement or fix. May not be included in next release.

Comments

@bilal-ahmed-wpb
Copy link

bilal-ahmed-wpb commented Mar 2, 2024

Issue with Namespacing Google Libraries in WordPress Plugin

Description

Before using namespaces by php-scoper to google/apiclient, google/analytics-admin, google/analytics-data, all the functionality worked fine. Still, to avoid conflicts of the plugin, I used php-scoper and namespace the entire libraries by MyPlugin. However, after implementing this, errors are encountered. The provided error logs indicate issues with initializing and constructing certain classes from the Google libraries.

Steps to Reproduce

  1. Namespace the Google libraries using php-scoper.
  2. Implement the changes into the WordPress plugin.
  3. Observe errors related to class initialization and construction.

Expected Behavior

The plugin should function without errors after implementing namespaces to the Google libraries.

Actual Behavior

Errors related to class initialization and construction are encountered.

Additional Context

  • Autoloading has been verified and confirmed to be functioning correctly.
  • The entire Google library is properly namespaced.
  • Excluding Google namespaces leads to errors related to guzzlehttp, monolog, and psr.

Questions

  1. Does namespacing the Google libraries affect their functionality?
  2. How can conflicts arising from namespacing Google libraries be resolved in the WordPress environment?

Error Log

[01-Mar-2024 10:50:37 UTC]
[
{
"file": "C:\Users\WPB\Local Sites\MyPlugin-google-sdk\app\public\wp-content\plugins\wp-MyPlugin\lib\Google-GA4\vendor\google\protobuf\src\Google\Protobuf\Internal\Message.php",
"line": 51,
"function": "initWithGeneratedPool",
"class": "MyPlugin\Google\Protobuf\Internal\Message",
"type": "->",
"args": []
},
{
"file": "C:\Users\WPB\Local Sites\MyPlugin-google-sdk\app\public\wp-content\plugins\wp-MyPlugin\lib\Google-GA4\vendor\google\analytics-admin\src\V1alpha\ListAccountsRequest.php",
"line": 69,
"function": "__construct",
"class": "MyPlugin\Google\Protobuf\Internal\Message",
"type": "->",
"args": [
null
]
},
{
"file": "C:\Users\WPB\Local Sites\MyPlugin-google-sdk\app\public\wp-content\plugins\wp-MyPlugin\lib\Google-GA4\vendor\google\analytics-admin\src\V1alpha\Gapic\AnalyticsAdminServiceGapicClient.php",
"line": 4964,
"function": "__construct",
"class": "MyPlugin\Google\Analytics\Admin\V1alpha\ListAccountsRequest",
"type": "->",
"args": []
},
{
"file": "C:\Users\WPB\Local Sites\MyPlugin-google-sdk\app\public\wp-content\plugins\wp-MyPlugin\MyPlugin-general.php",
"line": 589,
"function": "listAccounts",
"class": "MyPlugin\Google\Analytics\Admin\V1alpha\Gapic\AnalyticsAdminServiceGapicClient",
"type": "->",
"args": []
},
{
"file": "C:\Users\WPB\Local Sites\MyPlugin-google-sdk\app\public\wp-content\plugins\wp-MyPlugin\inc\wpa-core-functions.php",
"line": 522,
"function": "get_ga_properties",
"class": "MyPlugin_General",
"type": "->",
"args": []
},
{
"file": "C:\Users\WPB\Local Sites\MyPlugin-google-sdk\app\public\wp-content\plugins\wp-MyPlugin\classes\MyPlugin-settings.php",
"line": 195,
"function": "fetch_ga_properties",
"class": "WP_MyPlugin_FUNCTIONS",
"type": "::",
"args": []
},
{
"file": "C:\Users\WPB\Local Sites\MyPlugin-google-sdk\app\public\wp-content\plugins\wp-MyPlugin\classes\MyPlugin-settings.php",
"line": 499,
"function": "get_settings_fields",
"class": "MyPlugin",
"type": "->",
"args": []
},
{
"file": "C:\Users\WPB\Local Sites\MyPlugin-google-sdk\app\public\wp-includes\class-wp-hook.php",
"line": 324,
"function": "admin_init",
"class": "WP_MyPlugin_Settings",
"type": "->",
"args": [
""
]
},
{
"file": "C:\Users\WPB\Local Sites\MyPlugin-google-sdk\app\public\wp-includes\class-wp-hook.php",
"line": 348,
"function": "apply_filters",
"class": "WP_Hook",
"type": "->",
"args": [
null,
[
""
]
]
},
{
"file": "C:\Users\WPB\Local Sites\MyPlugin-google-sdk\app\public\wp-includes\plugin.php",
"line": 517,
"function": "do_action",
"class": "WP_Hook",
"type": "->",
"args": [
[
""
]
]
},
{
"file": "C:\Users\WPB\Local Sites\MyPlugin-google-sdk\app\public\wp-admin\admin.php",
"line": 175,
"function": "do_action",
"args": [
"admin_init"
]
}
]

@bilal-ahmed-wpb bilal-ahmed-wpb changed the title Google Libraries not working after I namespace entire library Issue with Namespacing Google Libraries in WordPress Plugin Mar 2, 2024
@saranshdhingra
Copy link
Contributor

Hi @bilal-ahmed-wpb
Thanks for filling the issue.

Although, we don't provide support for wordpress and the interaction with php-scoper definitely makes it tough to crack.

To answer one of your questions, yes the namespacing is important(just like any other composer package).
But from what I can see in the docs for php-scoper, it should handle those changes for you.

Could you provide a docker image or a minimal reproducible code where we can probably provide you with more help.

Apart from this I can recommend you to try the same with minimal setup, example only one package in your plugin so you can zero down on the bug.

Thanks.

@saranshdhingra saranshdhingra self-assigned this Mar 7, 2024
@saranshdhingra saranshdhingra added the priority: p3 Desirable enhancement or fix. May not be included in next release. label Mar 7, 2024
@bilal-ahmed-wpb
Copy link
Author

A question raised in my mind. The files in which there is the following comment:

Generated by the protocol buffer compiler. DO NOT EDIT!

In google/analytics-admin and google/analytics-data can I add my custom plugin namespace on them and will they work then?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p3 Desirable enhancement or fix. May not be included in next release.
Projects
None yet
Development

No branches or pull requests

2 participants