AOMC
AOMC

Reputation: 11

Updating failed. The response is not a valid JSON response when adding a style property to a block in wordpress on hostinger

I am using wordpress on hostinger. I have registered new custom post types. I am using the twentytwentyfive theme and gutenburg editor. I get this error when I add a style property to a element:
Updating failed. The response is not a valid JSON response.

NOTE: THIS ERROR ONLY HAPPENS ON CUSTOM POST TYPES. ON normal WP PAGES AND POSTS, IT'S FINE

This happens when any block has a style property

e.g.

when I have

<!-- wp:paragraph -->
    <p style="background-color: #000000">Prepare for 2025</p>
<!-- /wp:paragraph -->

It throws the error but when I have

<!-- wp:paragraph -->
    <p>Prepare for 2025</p>
<!-- /wp:paragraph -->

It's fine.

In the network tab I see:
https://{website}.com/wp-json/wp/v2/myupdates/60?_locale=user getting a 403 after I post
{"id":60,"content":"<!-- wp:paragraph -->\n<p style="background-color: #000000">Prepare for 2025</p>\n<!-- /wp:paragraph -->"}

My custom post types are defined in a post-types.php file in mu-plugins folder

This is the file

<?php
function include_myupdates_in_category_archives($query)
{
    if (!is_admin() && $query->is_main_query() && (is_category() || is_tag())) {
        $query->set('post_type', array('post', 'myupdates', 'myfundraisers', 'mycampaigns'));
    }
}
add_action('pre_get_posts', 'include_myupdates_in_category_archives');

function custom_post_types()
{
    // Event post type
    // wordpress register_post_type function
    register_post_type('myupdates', array(
        'supports' => array('title', 'thumbnail', 'editor', 'excerpt', 'custom-fields'),
        'has_archive' => true,
        'rewrite' => array('slug' => 'updates'),
        'taxonomies' => array('category'),
        'description' => 'Council Updates',
        'public' => true,
        'show_in_rest' => true,
        'label' => 'Updates',
        'labels' => array(
            'name' => 'Updates',
            'add_new_item' => 'Add New Update',
            'edit_item' => 'Edit Update',
            'all_items' => 'All Updates',
            'singular_name' => 'Update'
        ),
        'menu_icon' => 'dashicons-info-outline' // https://developer.wordpress.org/resource/dashicons/
    ));

    register_post_type('myfundraisers', array(
        'supports' => array('title', 'thumbnail', 'editor', 'excerpt'),
        'has_archive' => true,
        'rewrite' => array('slug' => 'fundraisers'),
        'taxonomies' => array('category'),
        'description' => 'Council Fundraisers',
        'public' => true,
        'show_in_rest' => true,
        'label' => 'Fundraisers',
        'labels' => array(
            'name' => 'Fundraisers',
            'add_new_item' => 'Add New Fundraiser',
            'edit_item' => 'Edit Fundraiser',
            'all_items' => 'All Fundraisers',
            'singular_name' => 'Fundraiser'
        ),
        'menu_icon' => 'dashicons-awards' // https://developer.wordpress.org/resource/dashicons/
    ));

    register_post_type('mycampaigns', array(
        'supports' => array('title', 'thumbnail', 'editor', 'excerpt'),
        'has_archive' => true,
        'rewrite' => array('slug' => 'campaigns'),
        'taxonomies' => array('category'),
        'description' => 'Council Campaigns',
        'public' => true,
        'show_in_rest' => true,
        'label' => 'Campaigns',
        'labels' => array(
            'name' => 'Campaigns',
            'add_new_item' => 'Add New Campaign',
            'edit_item' => 'Edit Campaign',
            'all_items' => 'All Campaigns',
            'singular_name' => 'Campaign'
        ),
        'menu_icon' => 'dashicons-groups' // https://developer.wordpress.org/resource/dashicons/
    ));
}

add_action('init', 'custom_post_types')



    ?>

Upvotes: 1

Views: 13

Answers (0)

Related Questions