WordPress.org

Make WordPress Core

Opened 2 years ago

Closed 14 hours ago

Last modified 13 hours ago

#43848 closed enhancement (fixed)

Function "user_can_access_admin_page" refactor.

Reported by: rnaby Owned by: valentinbora
Milestone: 5.6 Priority: lowest
Severity: normal Version:
Component: Administration Keywords: has-patch needs-refresh
Focuses: coding-standards Cc:

Description

I think this user_can_access_admin_page function should looks more clean and better this way. Also added a description of the function.

Attachments (2)

43848.diff (1.8 KB) - added by rnaby 2 years ago.
The patch for the enhancement.
43848.2.diff (3.3 KB) - added by rnaby 2 years ago.
Another improved patch. Merged some if statement and refactored.

Download all attachments as: .zip

Change History (9)

@rnaby
2 years ago

The patch for the enhancement.

@rnaby
2 years ago

Another improved patch. Merged some if statement and refactored.

#1 @pento
19 months ago

  • Version trunk deleted

#2 @valentinbora
6 months ago

  • Keywords needs-refresh added; needs-testing removed
  • Milestone changed from Awaiting Review to Future Release
  • Owner set to valentinbora
  • Priority changed from normal to lowest
  • Status changed from new to accepted

Thanks for the patch @rnaby and sorry for the delay here. Unfortunately, the patch needs a refresh as it no longer applies cleanly onto trunk.

For reference, coding standards relevant docs:

#3 @khag7
2 days ago

  • Keywords close added
  • Resolution set to wontfix
  • Status changed from accepted to closed

I reviewed the proposed patch and compared it against the current implementation.

The proposed patch is mostly whitespace changes and merging of if statements.

For example (pseudo-code):

if( A ){
    something
}
if( B ){
    something
}

to

if( A || B ){
    something
}

The current implementation is relatively concise and correct with WordPress coding standards. There's no need for this ticket to remain open.

#4 @desrosj
42 hours ago

  • Milestone Future Release deleted

#5 @SergeyBiryukov
14 hours ago

  • Focuses coding-standards added
  • Keywords close removed
  • Milestone set to 5.6
  • Resolution wontfix deleted
  • Status changed from closed to reopened

While I mostly agree with comment:3, I think there is some benefit in replacing these parts:

if ( current_user_can( $submenu_array[1] ) ) {
	return true;
} else {
	return false;
}

with:

return current_user_can( $submenu_array[1] );

#6 @SergeyBiryukov
14 hours ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In 48762:

Coding Standards: Simplify some parts of user_can_access_admin_page() for better readability.

Props rnaby, valentinbora, khag7.
Fixes #43848.

#7 @SergeyBiryukov
13 hours ago

In 48764:

Coding Standards: Fix WPCS issues in wp-admin/includes/plugin.php.

Includes minor code layout fixes for better readability.

Props rnaby for initial patch.
See #50767, #43848.

Note: See TracTickets for help on using tickets.