Popup-Maker icon indicating copy to clipboard operation
Popup-Maker copied to clipboard

Fix fatal error in other plugins due to missing return value of filter

Open DanWin opened this issue 1 month ago • 1 comments

Description

Fixes the following error in other plugins, expecting a return value of the filter:

PHP Fatal error:  Uncaught TypeError: PersonioIntegrationLight\PersonioIntegration\Post_Type::mark_menu(): Argument #1 ($use_editor) must be of type bool, null given, called in /usr/www/users/tamajf/www/wp-includes/class-wp-hook.php on line 343 and defined in /usr/www/users/tamajf/www/wp-content/plugins/personio-integration-light/app/PersonioIntegration/Post_Type.php:71
Stack trace:
#0 /usr/www/users/tamajf/www/wp-includes/class-wp-hook.php(343): PersonioIntegrationLight\PersonioIntegration\Post_Type->mark_menu()
#1 /usr/www/users/tamajf/www/wp-includes/plugin.php(205): WP_Hook->apply_filters()
#2 /usr/www/users/tamajf/www/wp-admin/includes/class-wp-screen.php(312): apply_filters()
#3 /usr/www/users/tamajf/www/wp-admin/includes/screen.php(243): WP_Screen::get()
#4 /usr/www/users/tamajf/www/wp-admin/admin.php(217): set_current_screen()
#5 /usr/www/users/tamajf/www/wp-admin/post.php(12): require_once('/usr/www/users/...')
#6 {main}
  thrown in /usr/www/users/tamajf/www/wp-content/plugins/personio-integration-light/app/PersonioIntegration/Post_Type.php on line 71

This has been tested in the following browsers

  • [ ] Chrome
  • [X] Firefox
  • [ ] Edge
  • [ ] Safari

Merge Checklist

  • [ ] This PR passes all automated checks (will appear once pull request is submitted)
  • [X] My code has been tested in the latest version of WordPress.
  • [ ] My code does not have any warnings from ESLint.
  • [ ] My code does not have any warnings from StyleLint.
  • [ ] My code does not have any warnings from PHPCS.
  • [X] My code follows the WordPress coding standards.
  • [X] My code follows the accessibility standards.
  • [X] All new functions and classes have code documentation.

Summary by CodeRabbit

  • Bug Fixes

    • Fixed inconsistent editor replacement behavior to ensure reliable functionality across all scenarios.
  • Refactor

    • Improved control flow logic for editor replacement to guarantee consistent return values in all code paths.

✏️ Tip: You can customize this high-level summary in your review settings.

DanWin avatar Dec 16 '25 13:12 DanWin

Walkthrough

The PostTypes controller's replace_editor method was refactored to ensure consistent boolean returns. The hook registration for this method was changed from an action to a filter, and the method now guarantees a return value across all code paths instead of potentially returning void.

Changes

Cohort / File(s) Summary
Hook mechanism and return type normalization
classes/Controllers/PostTypes.php
Changed hook registration from add_action to add_filter for replace_editor. Updated method to return boolean consistently: returns incoming $replace value for unmanaged post types instead of void, and ensures final return of $replace regardless of code path. Updated docblock @return annotation to reflect boolean return type.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10–15 minutes

  • Specific areas for review:
    • Verify that changing from action to filter is intentional and doesn't alter expected filter chain behavior downstream
    • Confirm that always returning a boolean value aligns with filter expectations for replace_editor hook
    • Check that the method's boolean return semantics match the editor replacement logic intent

Poem

🐰 A filter blooms where actions once did roam,
Returns now flow like rivers heading home—
No void shall leave our editor's retreat,
Boolean truths make logic's path complete!

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: fixing a fatal error caused by a filter missing a return value, which aligns with the code changes that convert replace_editor to always return a boolean.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • [ ] 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • [ ] Create PR with unit tests
  • [ ] Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar Dec 16 '25 13:12 coderabbitai[bot]