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.
Built from https://develop.svn.wordpress.org/trunk@48764


git-svn-id: http://core.svn.wordpress.org/trunk@48526 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2020-08-08 21:04:04 +00:00
parent f5a4ac614e
commit 004e3f897f
2 changed files with 45 additions and 33 deletions

View File

@ -651,7 +651,9 @@ function activate_plugin( $plugin, $redirect = '', $network_wide = false, $silen
return $requirements;
}
if ( ( $network_wide && ! isset( $current[ $plugin ] ) ) || ( ! $network_wide && ! in_array( $plugin, $current, true ) ) ) {
if ( $network_wide && ! isset( $current[ $plugin ] )
|| ! $network_wide && ! in_array( $plugin, $current, true )
) {
if ( ! empty( $redirect ) ) {
// We'll override this later if the plugin can be included without fatal error.
wp_redirect( add_query_arg( '_error_nonce', wp_create_nonce( 'plugin-activation-error_' . $plugin ), $redirect ) );
@ -764,7 +766,7 @@ function deactivate_plugins( $plugins, $silent = false, $network_wide = null ) {
continue;
}
$network_deactivating = false !== $network_wide && is_plugin_active_for_network( $plugin );
$network_deactivating = ( false !== $network_wide ) && is_plugin_active_for_network( $plugin );
if ( ! $silent ) {
/**
@ -978,7 +980,7 @@ function delete_plugins( $plugins, $deprecated = '' ) {
// If plugin is in its own directory, recursively delete the directory.
// Base check on if plugin includes directory separator AND that it's not the root plugin folder.
if ( strpos( $plugin_file, '/' ) && $this_plugin_dir != $plugins_dir ) {
if ( strpos( $plugin_file, '/' ) && $this_plugin_dir !== $plugins_dir ) {
$deleted = $wp_filesystem->delete( $this_plugin_dir, true );
} else {
$deleted = $wp_filesystem->delete( $plugins_dir . $plugin_file );
@ -1150,8 +1152,8 @@ function validate_plugin_requirements( $plugin ) {
$compatible_wp = is_wp_version_compatible( $requirements['requires'] );
$compatible_php = is_php_version_compatible( $requirements['requires_php'] );
/* translators: %s: URL to Update PHP page. */
$php_update_message = '</p><p>' . sprintf(
/* translators: %s: URL to Update PHP page. */
__( '<a href="%s">Learn more about updating PHP</a>.' ),
esc_url( wp_get_update_php_url() )
);
@ -1414,9 +1416,9 @@ function add_submenu_page( $parent_slug, $page_title, $menu_title, $capability,
* parent file someone is trying to link back to the parent manually. In
* this case, don't automatically add a link back to avoid duplication.
*/
if ( ! isset( $submenu[ $parent_slug ] ) && $menu_slug != $parent_slug ) {
if ( ! isset( $submenu[ $parent_slug ] ) && $menu_slug !== $parent_slug ) {
foreach ( (array) $menu as $parent_menu ) {
if ( $parent_menu[2] == $parent_slug && current_user_can( $parent_menu[1] ) ) {
if ( $parent_menu[2] === $parent_slug && current_user_can( $parent_menu[1] ) ) {
$submenu[ $parent_slug ][] = array_slice( $parent_menu, 0, 4 );
}
}
@ -1767,7 +1769,7 @@ function remove_menu_page( $menu_slug ) {
global $menu;
foreach ( $menu as $i => $item ) {
if ( $menu_slug == $item[2] ) {
if ( $menu_slug === $item[2] ) {
unset( $menu[ $i ] );
return $item;
}
@ -1795,7 +1797,7 @@ function remove_submenu_page( $menu_slug, $submenu_slug ) {
}
foreach ( $submenu[ $menu_slug ] as $i => $item ) {
if ( $submenu_slug == $item[2] ) {
if ( $submenu_slug === $item[2] ) {
unset( $submenu[ $menu_slug ][ $i ] );
return $item;
}
@ -1822,6 +1824,7 @@ function menu_page_url( $menu_slug, $echo = true ) {
if ( isset( $_parent_pages[ $menu_slug ] ) ) {
$parent_slug = $_parent_pages[ $menu_slug ];
if ( $parent_slug && ! isset( $_parent_pages[ $parent_slug ] ) ) {
$url = admin_url( add_query_arg( 'page', $menu_slug, $parent_slug ) );
} else {
@ -1870,33 +1873,40 @@ function get_admin_page_parent( $parent = '' ) {
if ( isset( $_wp_real_parent_file[ $parent ] ) ) {
$parent = $_wp_real_parent_file[ $parent ];
}
return $parent;
}
if ( 'admin.php' === $pagenow && isset( $plugin_page ) ) {
foreach ( (array) $menu as $parent_menu ) {
if ( $parent_menu[2] == $plugin_page ) {
if ( $parent_menu[2] === $plugin_page ) {
$parent_file = $plugin_page;
if ( isset( $_wp_real_parent_file[ $parent_file ] ) ) {
$parent_file = $_wp_real_parent_file[ $parent_file ];
}
return $parent_file;
}
}
if ( isset( $_wp_menu_nopriv[ $plugin_page ] ) ) {
$parent_file = $plugin_page;
if ( isset( $_wp_real_parent_file[ $parent_file ] ) ) {
$parent_file = $_wp_real_parent_file[ $parent_file ];
}
return $parent_file;
}
}
if ( isset( $plugin_page ) && isset( $_wp_submenu_nopriv[ $pagenow ][ $plugin_page ] ) ) {
$parent_file = $pagenow;
if ( isset( $_wp_real_parent_file[ $parent_file ] ) ) {
$parent_file = $_wp_real_parent_file[ $parent_file ];
}
return $parent_file;
}
@ -1905,13 +1915,16 @@ function get_admin_page_parent( $parent = '' ) {
if ( isset( $_wp_real_parent_file[ $parent ] ) ) {
$parent = $_wp_real_parent_file[ $parent ];
}
if ( ! empty( $typenow ) && ( "$pagenow?post_type=$typenow" === $submenu_array[2] ) ) {
if ( ! empty( $typenow ) && "$pagenow?post_type=$typenow" === $submenu_array[2] ) {
$parent_file = $parent;
return $parent;
} elseif ( $submenu_array[2] == $pagenow && empty( $typenow ) && ( empty( $parent_file ) || false === strpos( $parent_file, '?' ) ) ) {
} elseif ( empty( $typenow ) && $pagenow === $submenu_array[2]
&& ( empty( $parent_file ) || false === strpos( $parent_file, '?' ) )
) {
$parent_file = $parent;
return $parent;
} elseif ( isset( $plugin_page ) && ( $plugin_page == $submenu_array[2] ) ) {
} elseif ( isset( $plugin_page ) && $plugin_page === $submenu_array[2] ) {
$parent_file = $parent;
return $parent;
}
@ -1953,10 +1966,10 @@ function get_admin_page_title() {
if ( empty( $parent ) ) {
foreach ( (array) $menu as $menu_array ) {
if ( isset( $menu_array[3] ) ) {
if ( $menu_array[2] == $pagenow ) {
if ( $menu_array[2] === $pagenow ) {
$title = $menu_array[3];
return $menu_array[3];
} elseif ( isset( $plugin_page ) && ( $plugin_page == $menu_array[2] ) && ( $hook == $menu_array[5] ) ) {
} elseif ( isset( $plugin_page ) && $plugin_page === $menu_array[2] && $hook === $menu_array[5] ) {
$title = $menu_array[3];
return $menu_array[3];
}
@ -1968,21 +1981,19 @@ function get_admin_page_title() {
} else {
foreach ( array_keys( $submenu ) as $parent ) {
foreach ( $submenu[ $parent ] as $submenu_array ) {
if ( isset( $plugin_page ) &&
( $plugin_page == $submenu_array[2] ) &&
(
( $parent == $pagenow ) ||
( $parent == $plugin_page ) ||
( $plugin_page == $hook ) ||
( 'admin.php' === $pagenow && $parent1 != $submenu_array[2] ) ||
( ! empty( $typenow ) && $parent == $pagenow . '?post_type=' . $typenow )
)
if ( isset( $plugin_page )
&& ( $plugin_page === $submenu_array[2] )
&& ( $pagenow === $parent
|| $plugin_page === $parent
|| $plugin_page === $hook
|| 'admin.php' === $pagenow && $parent1 !== $submenu_array[2]
|| ! empty( $typenow ) && "$pagenow?post_type=$typenow" === $parent )
) {
$title = $submenu_array[3];
return $submenu_array[3];
}
if ( $submenu_array[2] != $pagenow || isset( $_GET['page'] ) ) { // Not the current page.
if ( $submenu_array[2] !== $pagenow || isset( $_GET['page'] ) ) { // Not the current page.
continue;
}
@ -1997,10 +2008,11 @@ function get_admin_page_title() {
}
if ( empty( $title ) ) {
foreach ( $menu as $menu_array ) {
if ( isset( $plugin_page ) &&
( $plugin_page == $menu_array[2] ) &&
( 'admin.php' === $pagenow ) &&
( $parent1 == $menu_array[2] ) ) {
if ( isset( $plugin_page )
&& $plugin_page === $menu_array[2]
&& 'admin.php' === $pagenow
&& $parent1 === $menu_array[2]
) {
$title = $menu_array[3];
return $menu_array[3];
}
@ -2126,22 +2138,22 @@ function user_can_access_admin_page() {
return true;
}
if ( isset( $plugin_page ) && ( $plugin_page == $parent ) && isset( $_wp_menu_nopriv[ $plugin_page ] ) ) {
if ( isset( $plugin_page ) && ( $plugin_page === $parent ) && isset( $_wp_menu_nopriv[ $plugin_page ] ) ) {
return false;
}
if ( isset( $submenu[ $parent ] ) ) {
foreach ( $submenu[ $parent ] as $submenu_array ) {
if ( isset( $plugin_page ) && ( $submenu_array[2] == $plugin_page ) ) {
if ( isset( $plugin_page ) && ( $submenu_array[2] === $plugin_page ) ) {
return current_user_can( $submenu_array[1] );
} elseif ( $submenu_array[2] == $pagenow ) {
} elseif ( $submenu_array[2] === $pagenow ) {
return current_user_can( $submenu_array[1] );
}
}
}
foreach ( $menu as $menu_array ) {
if ( $menu_array[2] == $parent ) {
if ( $menu_array[2] === $parent ) {
return current_user_can( $menu_array[1] );
}
}

View File

@ -13,7 +13,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.6-alpha-48762';
$wp_version = '5.6-alpha-48764';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.