Remember a full record of a wordpress 500 fatal error checking caused by wpcode shortcode

我重新审视了这篇文章的内容,发现文章中直接包含了 WPCode 的简码调用:wpcode。如图4

作者:

Background
Recently, I encountered a difficult problem when maintaining a blog: a specific article details page directly displays ‘500 internal server errors’, and other article details pages are completely normal to open.
A single page crash, usually a page-specific element (such as a specific shortcode, block or content) triggers a PHP fatal error.

1. View the error log and lock the ‘weapon of the crime’

The first reaction is to check the server debug.log, found the following fatal error records:

Plaintext
[23-Jun-2026 13:13:47 UTC] PHP Fatal error:  Cannot redeclare custom_desc_and_ads_inserter() (previously declared in /data/wwwroot/www.shuijingwanwq.com/wp-content/plugins/insert-headers-and-footers/includes/class-wpcode-snippet-execute.php(419) : eval()'d code:6) in /data/wwwroot/www.shuijingwanwq.com/wp-content/plugins/insert-headers-and-footers/includes/class-wpcode-snippet-execute.php(419) : eval()'d code on line 451
Figure 1: A blog details page that reports 500 errors
Figure 1: A blog details page that reports 500 errors

Figure 2: Viewing the debug.log log shows the cannot redoclare error
Figure 2: Viewing the debug.log log shows the cannot redoclare error


Log analysis:

  • Cannot Redeclare CUSTOM_DESC_ANDS_INSERTER(): This is a classic PHP error, which means the same function name has been declared twice.
  • path pointing insert-headers-and-footers(i.e. wpcode plugin) internal class-wpcode-snippet-execute.php file.
  • The key is eval()D code: This code that causes the error is not written to die in the file, but the code snippet that is executed dynamically through the wpcode plugin.

2. Emergency handling and error clue investigation (this road does not work)

In order to restore the page access first, I decided to disable the corresponding code snippet in wpcode in the background first.

Figure 3: The page returns to normal after disabling wpcode corresponding code snippet
Figure 3: The page returns to normal after disabling wpcode corresponding code snippet


After it is disabled, the page does not report a 500 error, but this is only a cure for the symptoms. Next, start looking for the root cause:

  • Suspect 1: Code Pro code block
    I remembered that in this error-reporting article, I used the Code Pro plugin to show a php code, which happened to contain CUSTOM_DESC_AND_ADS_INSERTER function definition.
    Action: I renamed the function name in the code block, refreshed the page after saving,Still reporting an error 500.
    further action: I even directly delete the entire Code Pro code block from the article, save the page after saving,It’s still an error 500!
    Reflect: Since the pure display code in the article is deleted, it still reports an error, indicating that the culprit that causes the function to repeat the declaration is not in the pure display code block. Need to re-examine.

3. Locate the shortcode and step on the pit again

Now that the suspected code Pro block is ruled out, the eyes are back to the WPCode plugin itself. I re-examined the content of this article and found that the shortcode call for wpcode directly contains:wpcode. as shown in Figure 4

I re-examined the content of this article and found that the article directly contains the shortcode call of wpcode: wpcode. as shown in Figure 4


Before wpcode When it is not in the ‘Shortcode Block’ dedicated to the Gutenberg editor, both the foreground page and the background editor report an error.
Action: I wrote directly in the text wpcode Extracted and put it in the ‘Shortcode Block’ dedicated to the Gutenberg editor.
Result: The front page is normal! However, the background editor still reports an error!
This shows that the problem is not at the block resolution level, but the execution logic of the shortcode itself has a conflict. When processing the shortcode, the WPCode plugin may cause internal conflicts with the current environment due to the content of the code snippet. eval() The logic executes the code twice.

4. Final solution

After trying multiple block combinations to be invalid, in order to completely block WPCode’s exception execution of this code, I took the most direct and effective solution. Since re-enabling the WPCode code snippet makes the background editor inaccessible, you must operate in the following specific order:

  1. Keep the corresponding code snippet in WPCode asdisabled state(This way the background editor can be loaded normally).
  2. Enter the editor of the error article.
  3. Put the shortcode in the content of the article wpcode Modify directly to plain text wpcode.
  4. Update articles.
  5. Back to WPCode plugin settings,reactivateThe code snippet that was previously disabled (restore the global function is available).

By removing the square bracket syntax of the shortcode, WordPress no longer recognizes it as executable shortcode, thereby preventing WPCode’s eval() execution behavior. Refresh the foreground page, the article is loaded perfectly, the background editor is also back to normal, and the 500 error disappears completely!

Figure 5: The problem is solved after modifying the text content to wpcode
Figure 5: The problem is solved after modifying the text content to wpcode

Summary and Pits Guide

This investigation process can be described as twists and turns, from the wrong direction at the beginning to the final positioning, the following profound lessons are summarized:

  1. Cannot Redeclare The nature of the error: It must be that the same piece of code has been executed multiple times. In dynamic execution plugins such as WPCode, this usually means eval() The logic is repeatedly triggered.
  2. Highlighting plugins such as Code Pro are safe: They just highlight the code as plain text and don’t go through the server side eval() execute. Deleting them doesn’t work, it can prove that the problem is elsewhere.
  3. Potential risks of WPCode shortcodes: In some specific cases, the shortcode execution of WPCode may cause the code snippet to be multiple times eval(). If you encounter a duplicate declaration error that cannot be solved, it is the most effective downgrade stop loss scheme to cancel the execution of the shortcode directly in the content (remove square brackets).
  4. Defensive programming is the bottom line: Regardless of the plugin execution mechanism, when writing code snippets with function definitions in WPCode,Be sureUse if ( ! function_exists(function_name) ) { ... } Package. Even if it is accidentally executed multiple times, it will be safely skipped, thereby avoiding a fatal crash.

评论

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.