AyeCode / invoicing

GetPaid (Formerly the Invoicing plugin) is a lightweight Payments and Invoicing system for WordPress. It can be used to sell anything online via payment forms or buy now buttons that can be added to any landing page. It can also be used by freelancers to manage their Invoices or by 3rd party Themes and Plugins as their payment system. GeoDirectory currently uses GetPaid as its payment system
https://wpgetpaid.com/
Other
39 stars 22 forks source link

“Deprecated: ltrim()…” warnings on manage subscription user page #806

Open pol76 opened 1 week ago

pol76 commented 1 week ago

Testing on new WordPress 6.6.2 install with PHP 8.2. No other plugins activated. When I purchase a subscription from a test user with no administrative privileges and then go to the Manage Subscription page, e.g. /gp-subscriptions/?subscription=2 , there are multiple PHP deprecated warnings regarding passing null to ltrim or preg_replace:

It seems to be coming from WPInv_Subscriptions_List_Table::generate_item_markup on line 394 in admin/class-wpinv-subscriptions-list-table.php which tries to get the link to the edit page for an item or invoice and then passes that to esc_url without checking if it’s null.

see https://wordpress.org/support/topic/deprecated-ltrim-warnings-on-manage-subscription-user-page/

kprajapatii commented 1 week ago

This has been fixed and pushed already.

aayla-secura commented 1 week ago

As per my comment in the Wordpress support topic (apologies for doubling up, I'll be using Github only for bug reports from now on):

I applied the patch and it did not fix the issue for me. I even wiped my test installation and started clean, installed the plugin, applied the patch, verified the file change. It's still showing those same warnings.

kprajapatii commented 1 week ago

@aayla-secura Are you using only GetPaid plugin or using GeoDirectory Pricing Manager plugin? Please update the plugin Pricing Manager if you are using it.

If you still see issue then open a topic at https://wpgeodirectory.com/support/ so we can follow up quickly.

Thanks, Kiran

aayla-secura commented 1 week ago

@kprajapatii No, I'm not using this plugin. The warnings are coming from passing the result of get_edit_post_link to esc_url without checking if it's null (which it would be null if the user is not an administrator). It happens in two separate places (possibly more, but what I'm seeing on the Subscriptions page is coming from two places).

Here's a patch that fixes it. I tested it now:

diff -U0 -r invoicing/includes/admin/class-wpinv-subscriptions-list-table.php invoicing.edit/includes/admin/class-wpinv-subscriptions-list-table.php
--- invoicing/includes/admin/class-wpinv-subscriptions-list-table.php   2024-08-08 15:00:40.000000000 +0300
+++ invoicing.edit/includes/admin/class-wpinv-subscriptions-list-table.php      2024-10-10 16:04:10.528597776 +0300
@@ -394 +394 @@
-                       $link = esc_url( $link );
+                       $link = $link === null ? '' : esc_url( $link );
diff -U0 -r invoicing/includes/admin/subscriptions.php invoicing.edit/includes/admin/subscriptions.php
--- invoicing/includes/admin/subscriptions.php  2024-06-11 12:17:00.000000000 +0300
+++ invoicing.edit/includes/admin/subscriptions.php     2024-10-10 16:13:07.441204004 +0300
@@ -604 +603,0 @@
-                                                                               $link    = esc_url( get_edit_post_link( $payment->get_id() ) );
@@ -608 +607,3 @@
-                                                                               }
+                                        } else {
+                                                                               $link    = esc_url( get_edit_post_link( $payment->get_id() ) );
+                                        }

I can create a pull request if you prefer.

kprajapatii commented 1 week ago

@aayla-secura On my test site no longer getting this error, so wanted to know in which causes the error occurred.

I can update patch from my side.

Thanks,

aayla-secura commented 1 week ago

@kprajapatii Strange, though it's possible I'm seeing it because I've enabled displaying of warnings and errors in the test install. 🤷

kprajapatii commented 1 week ago

Pushed https://github.com/AyeCode/invoicing/pull/807/commits/f5fd14c1786a79bc2e7f3a87a7541801b8d2ac14