Make WordPress Core

Opened 3 years ago

Closed 5 months ago

#56479 closed defect (bug) (worksforme)

Missing capability shows blank page in WP-Admin

Reported by: vincenz17's profile vincenz17 Owned by:
Milestone: Priority: normal
Severity: normal Version: 6.0.2
Component: Posts, Post Types Keywords:
Focuses: ui, administration Cc:

Description

Hello,

I have created a custom post type with the following code.

<?php
function customPostTypeIBF()
{
        $labels = array
        (
                'name'                  => _x('Fortbildungen', 'Post Type General Name', 'ibf'),
                'singular_name'         => _x('Fortbildung', 'Post Type Singular Name', 'ibf'),
                'menu_name'             => __('IBF', 'ibf'),
                'name_admin_bar'        => __('IBF-Fortbildung', 'ibf'),
                'archives'              => __('IBF-Archiv', 'ibf'),
                'all_items'             => __('Alle Fortbildungen', 'ibf'),
                'add_new_item'          => __('Neue Fortbildung', 'ibf'),
                'add_new'               => __('Neue Fortbildung', 'ibf'),
                'new_item'              => __('Neue Fortbildung', 'ibf'),
                'edit_item'             => __('Fortbildung bearbeiten', 'ibf'),
                'update_item'           => __('Fortbildung speichern', 'ibf'),
                'view_item'             => __('Fortbildung anzeigen', 'ibf'),
                'view_items'            => __('Fortbildungen anzeigen', 'ibf'),
                'search_items'          => __('Fortbildung suchen', 'ibf'),
        );

        $args = array
        (
                'label'                 => __('IBF', 'ibf'),
                'description'           => __('Fortbildungen verwalten', 'ibf'),
                'labels'                => $labels,
                'supports'              => array('title', 'editor', 'author', 'thumbnail', 'revisions', 'custom-fields'),
                'show_in_rest'          => true,
                'hierarchical'          => false,
                'public'                => true,
                'show_in_menu'          => true,
                'menu_position'         => 5,
                'menu_icon'             => 'dashicons-welcome-learn-more',
                'has_archive'           => true,
                'rewrite'               => array('slug' => 'ibf'),
                'capability_type'       => 'post',
                'capabilities'          => array
                (
                        'edit_post'             => 'edit_ibf',
                        'edit_posts'            => 'edit_ibfs',
                        'edit_others_posts'     => 'edit_others_ibf',
                        'publish_posts'         => 'publish_ibf',
                        'read_post'             => 'read_ibf',
                        'read_private_posts'    => 'read_private_ibf',
                        'delete_post'           => 'delete_ibf',
                        'create_posts'          => 'create_ibfs', 
                ),
        );

        register_post_type('ibf', $args);
}
add_action('init', 'customPostTypeIBF', 0);

Then I adjusted the wp_user_roles field in the database so that the permissions are also set appropriately based on the role.

Now when I don't have the create_ibf permission I get the following message in the admin panel:

https://i.ibb.co/2dPcrWh/error-ok.png

Thats right and it works!

Now the problem: When I don't have the edit_ibf (without S at the end) permission I just get a white page (blank page) in the admin panel. Now error message or so. Only a white page. The source code shows the page but in the browser I cant see anything.
If I use the developer tools I get the following error message:

https://i.ibb.co/gjjyhkZ/error-white.png

If I follow the link in the error message I can see that:

https://i.ibb.co/3dFQ8Sh/wp-rest-error.png

So I think here is a error message missing.

And now another funny thing: When I havent the permission edit_ibf and disable the block editor with the parameter:

<?php
'show_in_rest' => false,

the page is loading:

https://i.ibb.co/dGJPdj3/ibf-ohne-blockeditor.png

I think something is wrong here. Maybe someone can take a look and fix this. At least the error message that you don't have enough rights would make sense, since you're looking for the error for a long time.

Thanks in advance!

My Live-Server: Ubuntu 20.04.3 with PHP 8.0.22 and MariaDB 10.5
My Test-Server (used here for reporting): Windows 11 with XAMPP and PHP 8.0.19 and a fresh install from 18:00 Uhr

Change History (2)

#1 @vincenz17
3 years ago

Hello,

is someone working in this system?!
Sorry, but I report no bugs anymore because all my tickets will be ignored. No answer, no comment, no status about anything…
That’s not fun. 😒

#2 @SirLouen
5 months ago

  • Milestone Awaiting Review deleted
  • Resolution set to worksforme
  • Status changed from new to closed

Reproduction Report

Description

❌ This report can't validate that the issue can be reproduced.

Environment

  • WordPress: 6.9-alpha-60093-src
  • PHP: 8.2.29
  • Server: nginx/1.29.1
  • Database: mysqli (Server: 8.4.6 / Client: mysqlnd 8.2.29)
  • Browser: Chrome 139.0.0.0
  • OS: Windows 10/11
  • Theme: Twenty Twenty-Three 1.6
  • MU Plugins: None activated
  • Plugins:
    • BBB Testing Dolly
    • Test Reports 1.2.0

Testing Instructions

  1. Add the code in Supp Artifacts to somewhere it could be executed
  2. Add a user with Author level
  3. Login with that user
  4. Try to create a new post, then edit it
  5. 👌 Both block and classic editor are working as expected, no errors

Actual Results

  1. ❌ Error condition not occurring

Additional Notes

  • @vincenz17 ideally try to add all the info in your reports in full English, not in German
  • I could not reproduce this. I removed one and all the edit capabilities you set in the CPT and the problem is not happening. Please review better your instructions and my code because this is not reproducible.
  • Closing for now as worksforme feel free to reopen if you can provide more reproducible information.
  • Remember that I'm using a 100% clean brand new WP installation.

Supplemental Artifacts

Testing code:

function customPostTypeIBF()
{
        $labels = array
        (
                'name'                  => _x('Fortbildungen', 'Post Type General Name', 'ibf'),
                'singular_name'         => _x('Fortbildung', 'Post Type Singular Name', 'ibf'),
                'menu_name'             => __('IBF', 'ibf'),
                'name_admin_bar'        => __('IBF-Fortbildung', 'ibf'),
                'archives'              => __('IBF-Archiv', 'ibf'),
                'all_items'             => __('Alle Fortbildungen', 'ibf'),
                'add_new_item'          => __('Neue Fortbildung', 'ibf'),
                'add_new'               => __('Neue Fortbildung', 'ibf'),
                'new_item'              => __('Neue Fortbildung', 'ibf'),
                'edit_item'             => __('Fortbildung bearbeiten', 'ibf'),
                'update_item'           => __('Fortbildung speichern', 'ibf'),
                'view_item'             => __('Fortbildung anzeigen', 'ibf'),
                'view_items'            => __('Fortbildungen anzeigen', 'ibf'),
                'search_items'          => __('Fortbildung suchen', 'ibf'),
        );

        $args = array
        (
                'label'                 => __('IBF', 'ibf'),
                'description'           => __('Fortbildungen verwalten', 'ibf'),
                'labels'                => $labels,
                'supports'              => array('title', 'editor', 'author', 'thumbnail', 'revisions', 'custom-fields'),
                'show_in_rest'          => true,
                'hierarchical'          => false,
                'public'                => true,
                'show_in_menu'          => true,
                'menu_position'         => 5,
                'menu_icon'             => 'dashicons-welcome-learn-more',
                'has_archive'           => true,
                'rewrite'               => array('slug' => 'ibf'),
                'capability_type'       => 'post',
                'capabilities'          => array
                (
                       'edit_post'             => 'edit_ibf',
                       'edit_posts'            => 'edit_ibfs',
                       'edit_others_posts'     => 'edit_others_ibf',
                       'publish_posts'         => 'publish_ibf',
                       'read_post'             => 'read_ibf',
                       'read_private_posts'    => 'read_private_ibf',
                       'delete_post'           => 'delete_ibf',
                       'create_posts'          => 'create_ibfs', 
                ),
        );

        register_post_type('ibf', $args);
}
add_action('init', 'customPostTypeIBF');

function ibf_add_caps()
{
	$role = get_role('author');
	if ( $role ) {
		$caps = array(
			'read_ibf',
			'delete_ibf',
			'edit_others_ibf',
			'publish_ibf',
			'read_private_ibf',
            'create_ibfs',
		);

		foreach ( $caps as $cap ) {
			$role->add_cap( $cap );
		}
	}
}
add_action( 'admin_init', 'ibf_add_caps' );
Note: See TracTickets for help on using tickets.