Bird
0
0

Given this code snippet in a WordPress plugin:

medium📝 component behavior Q13 of 15
Wordpress - Plugins and Extensibility
Given this code snippet in a WordPress plugin:
add_action('init', function() {
  if (function_exists('some_plugin_function')) {
    some_plugin_function();
  } else {
    error_log('Function missing');
  }
});

What will happen if some_plugin_function is removed by another plugin?
AAn error will be logged saying 'Function missing'
BWordPress will crash with a fatal error
CThe function will run normally without errors
DThe plugin will deactivate automatically
Step-by-Step Solution
Solution:
  1. Step 1: Understand the code logic

    The code checks if some_plugin_function exists before calling it. If it does not exist, it logs 'Function missing'.
  2. Step 2: Analyze the effect of removal

    If another plugin removes or disables some_plugin_function, the condition fails and error_log is called.
  3. Final Answer:

    An error will be logged saying 'Function missing' -> Option A
  4. Quick Check:

    Missing function triggers error_log [OK]
Quick Trick: Check function_exists before calling to avoid fatal errors [OK]
Common Mistakes:
  • Assuming WordPress crashes without check
  • Thinking function runs even if missing
  • Believing plugin auto-deactivates on error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Wordpress Quizzes