Make WordPress Core

Opened 6 years ago

Closed 4 years ago

Last modified 4 years ago

#43848 closed enhancement (fixed)

Function "user_can_access_admin_page" refactor.

Reported by: rnaby's profile rnaby Owned by: valentinbora's profile 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 6 years ago.
The patch for the enhancement.
43848.2.diff (3.3 KB) - added by rnaby 6 years ago.
Another improved patch. Merged some if statement and refactored.

Download all attachments as: .zip

Change History (9)

@rnaby
6 years ago

The patch for the enhancement.

@rnaby
6 years ago

Another improved patch. Merged some if statement and refactored.

#1 @pento
5 years ago

  • Version trunk deleted

#2 @valentinbora
4 years 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
4 years 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
4 years ago

  • Milestone Future Release deleted

#5 @SergeyBiryukov
4 years 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
4 years 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
4 years 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.