• Hello! I activated file-based execution mode and immediately got a fatal error:

    PHP Fatal error: Cannot redeclare do_wp_mail_forced_to() (previously declared in wp-content/code-snippets/dafeda30b2607c356aa4a8d750591e94/php/52.php:15) in wp-content/plugins/code-snippets/php/snippet-ops.php(599) : eval()’d code on line 10

    Looks like there’s 2 matches for our custom function definition somehow:

    [php]$ fgrep do_wp_mail_forced_to ./*
    ./52.php: add_filter(‘wp_mail’, ‘do_wp_mail_forced_to’, 1, 1);
    ./52.php: function do_wp_mail_forced_to($args)
    ./index.php: add_filter(\’wp_mail\’, \’do_wp_mail_forced_to\’, 1, 1);
    ./index.php: function do_wp_mail_forced_to($args)

    (1) You might want to figure out some way to handle fatals in the script file execution.
    (2) How can I disable file-based execution mode now that the code-snippets plugin UI fails (actually, the whole https://mysite.com/wp-admin/network/ fails)?

Viewing 14 replies - 1 through 14 (of 14 total)
  • Plugin Contributor ImageLouis Wolmarans

    (@louiswol94)

    Hi @vhmarkgmailcom , thanks for reaching out!

    The error you are receiving is really strange. It seems that on your environment it tries to fetch and execute the database snippet as well as the file snippet, where it should just be either/or.

    I was unable to reproduce this on my side, so maybe a bit of system information might be helpful. It might also be cache related.

    1) We will look into this further, thank you.
    2) Under the hood, you can delete this file: wp-content/code-snippets/flat-files-enabled.flag, which will emulate the feature as off. Then you should disable it from the plugin UI as well. Otherwise, you can try safe mode: https://codesnippets.pro/doc/help-my-site-broke-how-can-i-fix-it/

    Plugin Contributor ImageLouis Wolmarans

    (@louiswol94)

    Regarding the two matches, it is finding the code in the wp-content/code-snippets/*/php/index.php file, which is just the config file which mirrors the database, and then the actual code file in */php/52.php. In the config file it is just a string and not an actual PHP function.

    I have the same issue. It seems the plugin tries to load the snippets twice.
    In my case, I get the fatal error on a WordPress Multisite. All my snippets are enabled globally, at the Network level. (I do not have this issue on normal WordPress installs)

    Thread Starter Imagebuddywhatshisname

    (@vhmarkgmailcom)

    I should have mentioned we run a multisite.
    I fixed the fatal by deleting the folder wp-content/code-snippets/, and once back in the UI found the file-based execution mode checkbox was now disabled.
    I’ll add some function_exists() checks for future robustness.

    Plugin Contributor ImageLouis Wolmarans

    (@louiswol94)

    Thank you @vhmarkgmailcom and @eusebiuoprinoiu , multisite was the clue we needed. We were able to reproduce and working on a fix. Thanks!

    Hello, Louis!
    I just tested the new update with the fix for Multisite installs, and I still get a fatal error.
    If it helps for debugging, I have the plugin network-activated.

    Plugin Contributor ImageLouis Wolmarans

    (@louiswol94)

    Hi @eusebiuoprinoiu , thanks for testing. I also had the plugin network activated. Could you share the error detail please. Sorry that you are still having trouble.

    @vhmarkgmailcom Can you verify if the fix worked on your side?

    Thanks!

    Hello, Louis!

    I get the same error: PHP Fatal error: Cannot redeclare function_name().

    I also noticed other issues. For context, I have a Multisite network on localhost for local development and another one on a live server. On both, the plugin is network-activated.

    On the live server, the Settings menu appears under the Network settings, but on localhost, it appears under each website, like on standard WordPress installs, which is weird. Is this a bug?

    When I enable file-based execution on the live server (in the Network settings), I get the fatal error. On localhost, where the Settings menu is shown for each website, I do not. And because in this case, this setting can be enabled or disabled for each website, the settings do not reflect the expected behaviour. Enabling file-based execution on one website enables it on all websites (via the file flag), but the checkbox remains unchecked on the other websites. The same happens when the option is disabled. (the file flag is removed, affecting all websites, but the checkbox remains enabled on all other websites)

    In addition, on both Multisite installs, removing the file flag from the server does not clear the checkbox under Settings, as it does in standard WordPress installs, even though it disables file-based execution.

    Plugin Contributor ImageLouis Wolmarans

    (@louiswol94)

    @eusebiuoprinoiu quick question, do you have namespaced OOP snippets by any chance?

    @eusebiuoprinoiu for me to disable I removed the file, edited the corresponding database setting in the options table, and cleared Redis cache (maybe also OPcache – I can’t remember). I don’t know if it was the database edit or clearing cache that made the difference, but those were all the steps I took.

    This was on a local single-site install – I’ve not yet tested on multisite. I’m waiting for a separate fix before I test that.

    If the database edit is necessary, it’s possible the setting exists at both a ‘blog’ and ‘site’ level – again, I’ve not tested that yet.

    @louiswol94 I don’t have any OOP snippets. For simple things I use anonymous functions, and for more complex things I use named functions namespaced by a prefix. I only use OOP in plugins.

    @amibe Normal WordPress installs are not affected by this. Only Multisite.

    Plugin Contributor ImageLouis Wolmarans

    (@louiswol94)

    Hi @eusebiuoprinoiu and @amibe , we’ve released a few versions with fixes related to file based execution among other things. I would appreciate it if you can update the plugin and let me know if your issues have been resolved.

    To answer a few of your other questions:

    On the live server, the Settings menu appears under the Network settings, but on localhost, it appears under each website, like on standard WordPress installs, which is weird. Is this a bug?

    From what I can see the Snippet Settings page is only available on the Network admin under wp-admin/network/admin.php?page=snippets-settings. I don’t have the “Settings” menu option under any of the sub sites. Also on localhost.

    In addition, on both Multisite installs, removing the file flag from the server does not clear the checkbox under Settings, as it does in standard WordPress installs, even though it disables file-based execution.

    Removing the flag was only mentioned as a workaround to get the site back up and running again. In general it should be managed via the settings page. When the setting is enabled it creates the flag file and if the setting is disabled it deletes the flag file. If you manually deleted the file, the setting won’t automatically reflect the same. We check the flag file to decide if we should execute using files, in order to totally avoid any database calls, even to the settings/options table, during run time.

    Thank you so much,
    Louis

    Hello, Louis!

    I still get a fatal error on WordPress Multisite installs, even with the latest version.

    Regarding the Settings menu being displayed for each network site, even when the plugin is network-activated, this is definitely a bug. Luckily, it only occurs on my localhost, so I’m not too bothered by it.
    I tried to fix it by manually removing all options and tables from the database and re-installing the plugin, but I get the same behavior.

    As for the file flag, a possible improvement would be to check if both the option for the file-based execution is enabled and if the file exists on the server. If the checkbox is checked but the file no longer exists, automatically update the option for file-based execution to disabled. This would automatically sync the value of the checkbox with the existence of the file flag. You could do this only when accessing the Settings page, to prevent checking the file on every page load.

    Plugin Contributor ImageLouis Wolmarans

    (@louiswol94)

    Hi everyone, we added an improvement for file based execution to handle fatal errors, similar to the database snippets. I hope this helps. Please let me know if there is any further feedback.

    Kind regards

    Louis

Viewing 14 replies - 1 through 14 (of 14 total)

You must be logged in to reply to this topic.