Skip to content

2.4.0: gutenberg_register_post_types() #5617

@lkraav

Description

@lkraav

https://github.com/WordPress/gutenberg/blob/v2.4.0/lib/register.php#L433 is written with the assumption that those role names exist in the system. This is not always the case, because roles can be deleted or renamed for multiple valid reasons.

As it stands, Gutenberg currently crashes my WP, because my user has two roles administrator and editor. For some reason get_role( "editor" ) evaluates to null, thereby has no has_cap() method.

$role_name string (13) "administrator"
→$role WP_Role (2)
→ Called from <ROOT>/wp-content/plugins/gutenberg/lib/register.php:435 [gutenberg_register_post_types()]

$role_name string (6) "editor"
$role null
→ Called from <ROOT>/wp-content/plugins/gutenberg/lib/register.php:435 [gutenberg_register_post_types()]

[14-Mar-2018 18:28:11 UTC] PHP Fatal error:  Uncaught Error: Call to a member function has_cap() on null in /home/warmpress/wp-content/plugins/gutenberg/lib/register.php:436

My takeaway here is that we should check get_role() result for validity before proceeding.

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Type] BugAn existing feature does not function as intended

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions