strangerstudios / restrict-with-stripe

WordPress plugin to restrict access to posts and pages with Stripe products and subscriptions.
GNU General Public License v3.0
2 stars 3 forks source link

TypeError: undefined is not an object (evaluating 'e.metaValue.includes') #23

Closed kasparsd closed 2 months ago

kasparsd commented 2 months ago

On a completely new site with WP 6.6.1 and RWS 1.0.9, when visiting the post and page editor (for both new and existing posts), I'm getting the following error: "The editor has encountered an unexpected error." with the following JS error reported in the console:

TypeError: undefined is not an object (evaluating 'e.metaValue.includes')

error

which appears to be coming from this part of the editor sidebar component:

https://github.com/strangerstudios/restrict-with-stripe/blob/5024a0bb9879a2c1944ae32b2693f0f4192370a5/blocks/src/sidebar/index.js#L36

which is probably due to the generated restricted_product_ids post meta not being an array for the current post.

kasparsd commented 2 months ago

This happens when either rwstripe_stripe_environment or rwstripe_stripe_account_id options are empty due this conditional when fetching rwstripe_get_meta_key(), which skips the registration of the post meta key:

https://github.com/strangerstudios/restrict-with-stripe/blob/5024a0bb9879a2c1944ae32b2693f0f4192370a5/includes/functions.php#L90-L120

and therefore fails to format the REST response accordingly (as an array).

dparker1005 commented 2 months ago

Hi @kasparsd,

Thank you for all this information; however, I have been unable to replicate this behavior with PMPro RWS v1.0.9 and WP 6.6.1 on a new website.

When I try to edit a post without being connected to Stripe, I see the message Could not connect to Stripe. Please check your Stripe connection on the Restrict With Stripe settings page. displayed in the render() function for the sidebar: https://github.com/strangerstudios/restrict-with-stripe/blob/2b4b794157ee38ca45601963f3bbc6973b2115bb/blocks/src/sidebar/index.js#L98-L123

If a website is not connected to Stripe, this is the expected behavior. In this case, the <RestrictionSelectControl> component should never be rendered, and the checked={ props.metaValue.includes( product.id ) } line that you mentioned should never be run.

Can you please confirm whether you had any other plugins active while running? This may help us to replicate the issue.

kasparsd commented 2 months ago

@dparker1005 You're right -- I was testing the plugin locally and was adding option values required for the main functionality manually which creates this state where the issue is present but it would never happen if everything was done through the standard activation workflow.