getAlby/lightning-publisher-wordpress

is_singular was called incorrectly.

Closed this issue · 4 comments

bumi commented

I get this error in the admin panel with the latest version from the master branch.
the is_singular check was recently introduced. Are we missing a special check for the admin panel? @Bobz-zg do you have an idea here?

Notice: Function is_singular was called incorrectly. Conditional query tags do not work before the query is run. Before then, they always return false. Please see [Debugging in WordPress](https://wordpress.org/documentation/article/debugging-in-wordpress/) for more information. (This message was added in version 3.1.0.) in /var/www/html/wp-includes/functions.php on line 5865
image
bumi commented

So I think we're doing some things too early?

@bumi yes, that is correct. My bad, I haven't checked the log for errors.
It's always safest to use WP hooks to run code after everything is loaded.
Fixed now in issue/12 where the code is originally from

bumi commented

I am actually also wondering if this works, because we use the lightning client in that rest api to generate the invoice: https://github.com/getAlby/lightning-publisher-wordpress/blob/master/includes/rest-api/controllers/class-rest-paywall.php#L94

so I can be on an index page but pay an individual post I guess? the JS is requesting an invoice for a post defined in a query param.

Oh. Good point.
This would not work from Index page in this case you are describing, because conditional functions are fired only when you template/view is rendered and not if you are using API.

Actually, I would say it does not work at all.
In a way every API request is a new instance of WP which is not 'connected' with what you see in the browser

In case where we do an API payment as you described we should check in the request by post_id and init new client before making a payment.
I will check the code and apply required fix