codesnippetspro/code-snippets

Testing out multiple similar Featured image snippets

Closed this issue · 2 comments

I have been testing out multiple featured image snippets.
https://new.easywebdesigntutorials.com/automatically-set-fallback-featured-image/

I have also downloaded a code snippet placed into a plugin:
https://gitlab.com/WPezPlugins/wpez-force-thumbnail/-/blob/main/wpez-force-thumbnail.php

The plugin was activated and I happen to activate the same code through Code Snippets (free version).

I received this message:
Screenshot 2022-09-04 at 13 18 41

I logged into the web host. Went to the File Manager. Renamed the Code Snippets plugin. Refreshed the page and had access to the web site. Refreshed the Installed Plugins screen and then went back to the File Manager and renamed the Code Snippets plugin back to its original name. Critical error came back again. Because the code snippets did not deactivate causing the error to come back again.

Renamed plugin folder again. This time I deactivated the featured image plugin. Renamed the Code Snippets plugin back to its original name. Site works again. I deactivated the featured image code snippet.

Conclusion: Having a plugin with a code snippet and having the same code in the Code Snippet plugin seems to cause a critical error. Manually deactivating the Code snippet plugin does not deactivate snippets added to the Code Snippets plugin..

In this case, the critical error was caused from using the same namespace and function names between multiple pieces of code. This isn't something that works in PHP, and is the primary reason why I recommend using anonymous functions in snippets where possible.

Deactivating the plugin won't deactivate any snippets. We want people to be able to switch off the plugin if the need to for whatever reason (upgrades, transferring sites, etc), and not lose their snippet active statuses.

Instead, we include a built-in safe mode feature for recovering from these sorts of errors. You can read more about it in our help docs: https://help.codesnippets.pro/12-safe-mode

Thanks Shea!

Here is the correct link when others come across this issue: https://help.codesnippets.pro/article/12-safe-mode