403, 'back_link' => true ] ); } } } } /** * Top level menu slugs hidden for the current user. Administrators always * see everything. * * @return string[] */ private static function hidden_for_current_user(): array { $user = wp_get_current_user(); if ( ! $user->exists() || in_array( 'administrator', $user->roles, true ) ) { return []; } $hidden_menus = (array) self::$settings['hidden_menus']; $hidden = []; foreach ( $user->roles as $role ) { if ( ! empty( $hidden_menus[ $role ] ) && is_array( $hidden_menus[ $role ] ) ) { $hidden = array_merge( $hidden, $hidden_menus[ $role ] ); } } return array_values( array_unique( $hidden ) ); } /** * Whether the request is the screen a menu item points to: a plugin page * by its page argument, a core screen by its file and query arguments. */ private static function is_current_screen( string $screen ): bool { // Read only to compare the request with the menu; nothing is changed. // phpcs:ignore WordPress.Security.NonceVerification.Recommended $query = array_map( 'sanitize_text_field', wp_unslash( array_filter( $_GET, 'is_string' ) ) ); $page = $query['page'] ?? ''; if ( ! str_contains( $screen, '.php' ) ) { return '' !== $page && $page === $screen; } $parts = wp_parse_url( $screen ); if ( ( $GLOBALS['pagenow'] ?? '' ) !== ( $parts['path'] ?? '' ) || '' !== $page ) { return false; } parse_str( $parts['query'] ?? '', $args ); if ( ( $args['post_type'] ?? 'post' ) !== ( $query['post_type'] ?? 'post' ) ) { return false; } foreach ( $args as $key => $value ) { if ( ( $query[ $key ] ?? null ) !== $value ) { return false; } } return true; } }