Make WordPress Core

Opened 8 years ago

Closed 6 years ago

Last modified 6 years ago

#43848 closed enhancement (fixed)

Function "user_can_access_admin_page" refactor.

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

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 8 years ago.
The patch for the enhancement.
43848.2.diff (3.3 KB ) - added by rnaby 8 years ago.
Another improved patch. Merged some if statement and refactored.

Download all attachments as: .zip

Change History (9)

@rnaby
8 years ago

The patch for the enhancement.

@rnaby
8 years ago

Another improved patch. Merged some if statement and refactored.

#1 @pento
8 years ago

  • Version trunk

#2 @valentinbora
7 years ago

  • Keywords needs-refresh added; needs-testing removed
  • Milestone Awaiting ReviewFuture Release
  • Owner set to valentinbora
  • Priority normallowest
  • Status newaccepted

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
6 years ago

  • Keywords close added
  • Resolutionwontfix
  • Status acceptedclosed

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
6 years ago

  • Milestone Future Release

#5 @SergeyBiryukov
6 years ago

  • Focuses coding-standards added
  • Keywords close removed
  • Milestone5.6
  • Resolution wontfix
  • Status closedreopened

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
6 years ago

  • Resolutionfixed
  • Status reopenedclosed

In 48762:

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

Props rnaby, valentinbora, khag7.
Fixes #43848.

#7 @SergeyBiryukov
6 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.