• Resolved Beef Supreme

    (@polymathy)


    I have a custom post type on my site called “recipe”. It’s note very different from a normal post. When I enable the subtitle support for recipes and try to open one of my recipes,

    2020-11-19-13h20-37

    I get the following error:

    “The editor has encountered an unexpected error.”

    2020-11-19-13h18-52

    This is the code for my custom post type, if it helps:

    function si_recipe_post_type()
    {
        $labels = array(
            'name' => _x('Recipes', 'Post type general name', 'si-extend'),
            'singular_name' => _x('Recipe', 'Post type singular name', 'si-extend'),
            'menu_name' => _x('Recipes', 'Admin Menu text', 'si-extend'),
        );
    
        $args = array(
            'labels' => $labels,
            'public' => true,
            'publicly_queryable' => true,
            'menu_position' => 6,
            'menu_icon' => 'dashicons-list-view',
            'show_in_rest' => true,
            'supports' => array('title', 'editor', 'thumbnail', 'comments', 'excerpts', 'revisions'),
            'show_ui' => true,
            'show_in_menu' => true,
        );
    
        register_post_type('recipe', $args);
    }
    
    add_action('init', 'si_recipe_post_type');
    • This topic was modified 4 years, 4 months ago by Beef Supreme.
    • This topic was modified 4 years, 4 months ago by Beef Supreme.
    • This topic was modified 4 years, 4 months ago by Beef Supreme.
    • This topic was modified 4 years, 4 months ago by Beef Supreme.
Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author HelgaTheViking

    (@helgatheviking)

    I’m not able to reproduce this locally when testing your code. Of course, thanks WordPress for that completely useless error message. ?? I am going to suggest my typical debugging process…. disable other plugins one at a time… switch to a default theme. This way you can isolate the problem.

    Thread Starter Beef Supreme

    (@polymathy)

    I disabled every plugin as you suggested and also changed the theme to twentytwenty. First this didn’t do anything about the error. But then I used the Chrome incognito mode to edit a recipe. The error was gone. Also when I used Firefox instead of Chrome.

    I then disabled all plugins in Chrome and deleted all the browser data. Now the error was also gone in Chrome without incognito. Then I reenabled all Chrome plugins, WP plugins and switched back to my theme. Still the error is gone.

    Don’t know what happened there, something must have been saved in the browser cache that broke everything. Before I did all this, I clicked on “copy error” from the error message and this is what it reads:

    Error: An error occurred while running 'mapSelect': Cannot read property 'kia_subtitle' of undefined
    The error may be correlated with this previous error:
    TypeError: Cannot read property 'kia_subtitle' of undefined
        at https://mywebsite.de/wp-content/plugins/kia-subtitle/js/dist/index.js?ver=3.0.0:1:1618
        at Object.current (https://mywebsite.de/wp-includes/js/dist/data.min.js?ver=75f90354ddff4acd5b0b4026454037ca:2:28125)
        at e (https://mywebsite.de/wp-includes/js/dist/data.min.js?ver=75f90354ddff4acd5b0b4026454037ca:2:27752)
        at https://mywebsite.de/wp-includes/js/dist/data.min.js?ver=75f90354ddff4acd5b0b4026454037ca:2:27861
        at Vb (https://mywebsite.de/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.9.0:104:431)
        at Ti (https://mywebsite.de/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.9.0:148:85)
        at unstable_runWithPriority (https://mywebsite.de/wp-includes/js/dist/vendor/react.min.js?ver=16.9.0:26:340)
        at Ma (https://mywebsite.de/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.9.0:52:280)
        at Ia (https://mywebsite.de/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.9.0:140:407)
        at ze (https://mywebsite.de/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.9.0:118:14)
    
    Original stack trace:
        at Fe (https://mywebsite.de/wp-includes/js/dist/data.min.js?ver=75f90354ddff4acd5b0b4026454037ca:2:27544)
        at https://mywebsite.de/wp-includes/js/dist/data.min.js?ver=75f90354ddff4acd5b0b4026454037ca:2:28100
        at je (https://mywebsite.de/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.9.0:78:476)
        at qe (https://mywebsite.de/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.9.0:89:115)
        at ph (https://mywebsite.de/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.9.0:216:489)
        at lh (https://mywebsite.de/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.9.0:126:409)
        at O (https://mywebsite.de/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.9.0:121:71)
        at ze (https://mywebsite.de/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.9.0:118:14)
        at https://mywebsite.de/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.9.0:53:49
        at unstable_runWithPriority (https://mywebsite.de/wp-includes/js/dist/vendor/react.min.js?ver=16.9.0:26:340)
    • This reply was modified 4 years, 4 months ago by Beef Supreme.
    Thread Starter Beef Supreme

    (@polymathy)

    Actually the error still persists. After doing all the above and then trying to add a subtitle, I still get the error.

    This happens even with all other plugins disabled and switching to the twentytwenty theme (with my custom post type code in the functions.php of that theme). It happens with any browser.

    I even created a completely new WordPress installation with nothing else installed, just the KIA subtitle plugin and the twentytwenty theme and get the error.

    So actually I think you should be able to reproduce this, if you use my code for the custom post type and use it in the twentytwenty theme.

    I can give you access to that said installation, if you want to investigate it.

    • This reply was modified 4 years, 4 months ago by Beef Supreme.
    Plugin Author HelgaTheViking

    (@helgatheviking)

    I see the issue now. You need to add ‘custom-fields’ to the ‘supports’ array when registering your post type if you want to access post meta in Gutenberg.

    So that should resolve your problem immediately and I’ll tinker with how to prevent this in a future version.

    
    
    function si_recipe_post_type()
    {
        $labels = array(
            'name' => _x('Recipes', 'Post type general name', 'si-extend'),
            'singular_name' => _x('Recipe', 'Post type singular name', 'si-extend'),
            'menu_name' => _x('Recipes', 'Admin Menu text', 'si-extend'),
        );
    
        $args = array(
            'labels' => $labels,
            'public' => true,
            'publicly_queryable' => true,
            'menu_position' => 6,
            'menu_icon' => 'dashicons-list-view',
            'show_in_rest' => true,
            'supports' => array('title', 'editor', 'thumbnail', 'comments', 'excerpts', 'revisions', 'custom-fields' ), // Add 'custom-fields' here
            'show_ui' => true,
            'show_in_menu' => true,
        );
    
        register_post_type('recipe', $args);
    }
    
    add_action('init', 'si_recipe_post_type');
    
    Plugin Author HelgaTheViking

    (@helgatheviking)

    version 3.0.2 should provide a more graceful fallback. If your CPT does not support custom-fields then you will see a back-compatible metabox at the bottom of the Gutenberg screen. To use the sidebar, you would still need to enable support when registering your CPT as described above.

    Thanks for reporting!

    Thread Starter Beef Supreme

    (@polymathy)

    Thank you, adding “custom-fields” worked for me. With your new update it seems the subtitle is not shown, when you don’t have custom-fields in your custom post, which I guess is fine.

    Plugin Author HelgaTheViking

    (@helgatheviking)

    Well it cannot be added to the sidebar if your CPT doesn’t support custom fields. You get the error you reported. There’s no way around that.

    If CPTs aren’t supported, you should (famous last words) get a fallback metabox at the bottom, see this screenshot:
    https://share.getcloudapp.com/rRu0qjvL

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Unexpected error when activated for custom post type’ is closed to new replies.