apsislabs / cf7-gated-content

Contact Form 7 Gated Content
2 stars 1 forks source link

Fix #1: Warning when using extract #2

Closed ncallaway closed 5 years ago

ncallaway commented 5 years ago

This resolves #1.

Repro Steps The issue reproduces if you put an empty short-code on a page while the gated content plugin is active.

For example, active the plugin, the add the shortcode [gallery] to any page.

Explanation $atts ends up not being set by WP, which means extract() fails because it is not an array. I've opted to replace the use of extract() entirely, as a couple other sources suggested it's not recommended by WP core. Since we're only using it to get one parameter, I'm simply setting $id by accessing it from $atts if $atts exists.

There are a couple other small fixes for other warnings and notices that shows up. The one I'm most suspicious of are the changes to the 'revision' === $post->post_type guard. I have no idea what that guard is doing, but $post both wasn't defined and wasn't set, which was blowing up.