-
Notifications
You must be signed in to change notification settings - Fork 2
Fix Notices Class Static Method Error and Improve Documentation #23 #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- Remove static keyword from add() method to allow $this usage - Resolves "Cannot use '$this' in non-object context" error - Method now requires instantiation to call: $notices = new Notices(); $notices->add($args); Fixes #23
- Document how to use the Notices class for displaying admin notifications - Include code examples showing proper instantiation and usage - Explain available notice types and configuration options - Reflects the non-static implementation of the add() method Closes #23
robincornett
requested changes
Sep 17, 2025
- Add static storage property for notices added via static method - Maintain add() method as static while preserving instance rendering - Merge static notices into instance notices during construction - Update README with proper initialization and usage examples - Reorganize documentation for better developer workflow This enables calling Notices::add() statically while maintaining WordPress admin notice rendering through instance-based approach. Fixes #23
robincornett
requested changes
Sep 17, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need to create a new static property; it should be fine to change the existing one to static. Additionally, the registry takes care of instantiating the class, so all a developer should have to do is to use the add
method before admin_notices
100
.
- Remove hybrid storage system with separate $static_notices property - Convert existing $notices property to static for cleaner implementation - Eliminate merging logic from constructor - Update add() and render() methods to use self::$notices directly - Update README with comprehensive priority examples and clearer usage - Registry instantiation makes manual initialization unnecessary Fixes #23
robincornett
requested changes
Sep 18, 2025
…nslation support - Remove outdated examples and consolidate notice usage into a single example - Update notice ID and message to include translation-ready strings - Simplify documentation for adding notices using the admin_notices hook This improves the usability of the README for developers implementing admin notifications.
robincornett
approved these changes
Sep 22, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix Notices Class Static Method Error and Improve Documentation
Overview
This PR resolves a critical PHP error in the
Notices
class and adds comprehensive documentation for the Admin Notices functionality.Changes Made
🐛 Bug Fix: Notices Class Static Method Error
src/Admin/Notices.php
add()
method was declared asstatic
but attempted to use$this->notices
, causing a "Cannot use '$this' in non-object context" errorstatic
keyword from theadd()
method to allow proper instance method behaviorBefore:
After:
📚 Documentation Enhancement: Admin Notices Usage
readme.md
success
,error
,warning
,info
)Impact
Breaking Change Notice
Notices::add()
method is no longer static. Code calling this method must be updated:Old Usage (No longer works):
New Usage (Required):
Benefits
Files Changed
src/Admin/Notices.php
(1 line changed)readme.md
(21 lines added)Testing
Notices
class instantiation works correctlyadd()
method functions without errorsCloses #23