Code Snippet doesn't work when run from MainWP, but works fine in WPCodeBox or functions.php

I have a recent issue for a particular code snippet I am trying to use in MainWP Code Snippets extension for one website, and it works fine when using it in WPCodeBox or in the functions.php file, but for some reason is not working properly when set via MainWP.

Here’s the snippet I’m trying to run:

https://gist.github.com/bkatusic/a877cb9f02bde51acaf8e9ebabca7972

And when I run it in MainWP, when trying to use the form to login, I get the following PHP error:


Apr 09 23:38:33 [Mon Apr 10 06:38:33.639727 2023] [php:error] [pid 2300] [client 207.216.93.172:60434] PHP Fatal error: Uncaught Error: Class "FluentFormFrameworkHelpersArrayHelper" not found in /app/data/public/wp-content/plugins/mainwp-child/class/class-mainwp-utility.php(87) : eval()'d code:74\nStack trace:\n#0 /app/data/public/wp-includes/class-wp-hook.php(308): MainWP\\Child\\MainWP_Utility::{closure}()\n#1 /app/data/public/wp-includes/class-wp-hook.php(332): WP_Hook->apply_filters()\n#2 /app/data/public/wp-includes/plugin.php(517): WP_Hook->do_action()\n#3 /app/data/public/wp-content/plugins/fluentform/app/Modules/Form/FormHandler.php(113): do_action()\n#4 /app/data/public/wp-content/plugins/fluentform/app/Hooks/Ajax.php(16): FluentForm\\App\\Modules\\Form\\FormHandler->onSubmit()\n#5 /app/data/public/wp-includes/class-wp-hook.php(308): FluentForm\\Framework\\Foundation\\Application->{closure}()\n#6 /app/data/public/wp-includes/class-wp-hook.php(332): WP_Hook->apply_filters()\n#7 /app/data/public/wp-includes/plugin.php(517): WP_Hook->do_action()\n#8 /app/data/public/wp-admin/admin-ajax.php(203): do_action()\n#9 {main}\n thrown in /app/data/public/wp-content/plugins/mainwp-child/class/class-mainwp-utility.php(87) : eval()'d code on line 74, referer: https://www.staging.example.com/account/

Again, this works fine when the code snippet runs from WPCodeBox or in the theme’s functions.php file, so I imagine there’s a processing issue when placed into the database from MainWP. Please help. Thank you. :slight_smile:

I’m using both MainWP Dashboard and MainWP Child plugins at version 4.4.0.4.

It seems like this part didn’t paste correctly, the forum software here seems to be rewriting it a bit. It’s mean too be without the brackets like this:

Hi @d19dotca

When you apply the snippet through the MainWP Code Snippets extension, did you choose the “Execute on Child Sites option”?

Please send us the full snippet via a service such as pastebin.com so we’re sure the forum software doesn’t interfere with formatting.

And as always, please make sure you’re running the latest version of the Dashboard (4.4.0.4), Code Snippets extension (4.0.3), and MainWP Child plugin (4.4.0.4).

Hi @bojan,

Yes the versions are all up-to-date for all plugins and extensions, and the snippet is set to “Execute on Child Sites”.

I’ve pasted the whole code snippet here, it includes two snippets in one, you only need to concern with the first one for Fluent Forms as the other works fine. Snippet is good for two weeks at https://pastebin.com/raw/rpXXEiZs

Your help would be greatly appreciated. Thank you in advance. :slight_smile:

I just had the idea to go digging into my database to see how it was entered, and sure enough the part where it doesn’t work in the forum software here is also the part that doesn’t work in MainWP’s database entry.

It looks like this in the database when you can see from the pastebin and the screenshot earlier how it should really look, but unfortunately looks like this instead which explains the PHP error:

$email = FluentFormFrameworkHelpersArrayHelper::get($data, "email"); // your form should have email field
$password = FluentFormFrameworkHelpersArrayHelper::get($data, "password"); // your form should have password field

Notice the absence of the back-slashes. This seems like a defect.

I tried to duplicate the back-slashes so that it looked like \\ and that worked for now as a workaround, but obviously this is incorrect and needs to be fixed please.

1 Like

Thanks for the additional details @d19dotca .

We’ve managed to reproduce the issue. The code in question, in our database, ends up being stripped of the backslashes as well.

The development team will investigate this further and it will be addressed in the next release of the Code Snippets extension.

1 Like

@d19dotca

We’ve included a fix for this in the MainWP Dashboard 4.4.1 Beta. You can read more about the beta and find download links for the Dashboard and Child plugins here: MainWP 4.4.1 Beta

Make sure to install both the Dashboard and the Child plugin.

In our testing, the backslashes are no longer getting stripped.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.