verygoodplugins / wp-fusion-lite

WP Fusion connects your WordPress website to your CRM or marketing automation system.
GNU General Public License v3.0
10 stars 10 forks source link

Undefined constant WPF_TAGS_META_KEY #19

Closed bsmolyanov closed 6 months ago

bsmolyanov commented 2 years ago

I get my logs full of the following warning:

PHP warning: Use of undefined constant WPF_TAGS_META_KEY - assumed 'WPF_TAGS_META_KEY' (this will throw an Error in a future version of PHP)

/.../wp-content/plugins/wp-fusion-lite/includes/class-user.php:1066

Can this be easily fixed?

verygoodplugins commented 2 years ago

@bsmolyanov Interesting. I haven't seen that before.

Are you sure the plugin is up to date? In the latest Lite v 3.38.44 there is nothing at that line: https://github.com/verygoodplugins/wp-fusion-lite/blob/master/includes/class-user.php#L1066

And then do you know the context for when the warning is thrown? Can you provide a backtrace?

The WPF_TAGS_META_KEY constant is defined once the CRM is initialized: https://github.com/verygoodplugins/wp-fusion-lite/blob/master/includes/class-user.php#L78, which happens on the plugins_loaded hook. So even if your custom code is in functions.php, it shouldn't be able to trigger that warning.

However, if you had a custom plugin that ran code before plugins_loaded, and that made a call to wp_fusion()->user->get_tags(), then yes, it could throw a warning like that.

We can probably fix that, or at least cause it to return a WP_Error, but I'd need to know how to reproduce it. If you could let me know that'd be great.

bsmolyanov commented 2 years ago

I am trying to look into more details. My rinnung version is 3.40.12 - the latest from wordpress.org - https://wordpress.org/plugins/wp-fusion-lite/

In version 3.38.44 the same code in question is located on line 1083 -

// Compare new tags to current tags to see what's changed.
        $user_tags = get_user_meta( $user_id, WPF_TAGS_META_KEY, true );
verygoodplugins commented 2 years ago

Gotcha, thanks for clarifying.

Right, so that error would happen if you tried to set a user's tags before the CRM had loaded, or before the init hook.

Because the constant isn't defined, it would cause the tags not to be saved to the database.

Do you know when it happens? Like, on a specific page, or when a user does something specific? And does it happen often, or just occasionally?

Do you have any custom code running that makes use of WP Fusion, or any other plugins that have a WP Fusion integration? (i.e. AutomatorWP, Uncanny Automator, Block Visibility, etc)?

We should be able to fix it, just need to figure out exactly what's causing it 🙂