Opened 4 weeks ago
Last modified 3 weeks ago
#63216 new defect (bug)
simplify get_role() method in WP_Roles class
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | |
Component: | Role/Capability | Keywords: | has-patch |
Focuses: | coding-standards | Cc: |
Description
This update simplifies the get_role()
method in the WP_Roles
class by removing an unnecessary else
block. The method now directly returns null
when the role is not found, improving readability and maintaining consistency with WordPress coding standards.
Change History (4)
This ticket was mentioned in PR #8637 on WordPress/wordpress-develop by @dilipbheda.
4 weeks ago
#1
#3
@
4 weeks ago
Hello @spacedmonkey,
Thank you for the sharing the document.
Reason for this changes
1) When reviewing the get_role()
function, I noticed an unnecessary else
block. Since the if
statement already returns a value, the else
can be removed for cleaner code.
2) The get_role()
function is used daily and has minimal code, minimizing the risk of regression. So, I created a ticket and a patch for it.
For shorter condition
Initially, I only removed the else
block and returned the value directly. However, based on reviewer feedback, I simplified it with a shorter condition.
Here: https://github.com/WordPress/wordpress-develop/pull/8637/commits/7b08649a6402c924fc28c2640e0330d82dba8075
There’s no other reason for this ticket. Feel free to close it if the changes aren’t needed.
Thanks
Thanks for your ticket @dilipbheda .
There is a rule with WordPress core, that we do not commit refactors for the sake of refactors. There is lots of code and if we refactored for the sake of it, it would be never ending task.
Can you provide more context why this change is needed, other than the code is cleaner. Is there a performance benefit?
Please read this docs for more information.
https://make.wordpress.org/core/handbook/contribute/code-refactoring/