Support

Account

Home Forums Backend Issues (wp-admin) Revisions dont’t work, get php errors…

Solved

Revisions dont’t work, get php errors…

  • When I restore a WP revision of a page I got always this error:

    Warning: trim() expects parameter 1 to be string, array given in /xxx/wp-includes/formatting.php on line 4628
    
    Warning: trim() expects parameter 1 to be string, array given in /xxx/wp-includes/formatting.php on line 4628
    
    Warning: Cannot modify header information - headers already sent by (output started at /xxx/wp-includes/formatting.php:4628) in /xxx/htdocs/xxx/wp-includes/pluggable.php on line 1210

    When I deactivate the ACF Pro (current version) the revisions work normally.

    My theme is a custom theme but I can’t see any problem here. I have removed all from functions.php but the problem is still there.

    I also cleaned up all old revision. And tried to restore a new added revision, but no change.

  • I’ve just done some digging around in WP and ACF and it does not look to me that ACF (even though the problem goes away when you deactivate ACF) should be causing this, but I could be wrong.

    Have you tried deactivating all of your other plugins to except ACF to see if you still get the errors? If you continue to get the error with only ACF active then submit a new ticket here https://support.advancedcustomfields.com/new-ticket/

  • I think figured out, with a lot oft testing, where it came form.
    It is defiantly ACF Pro (no other Plugin, not from the templates, wp-config, functions.php)

    On the most templates the wp default content-editor is deactivated and hidden by ACF.

    Page-templates has the problem with revisions without the editor. When I activate the editor and add some content the revisions work normally.
    CPT post don’t have this problem…

    Is the any way to fix this problem?

  • From what I can see it isn’t a problem with ACF, not sure if the developer can do anything about it or not. The only way to find out is to open a new support ticket and explain the problem https://support.advancedcustomfields.com/new-ticket/

  • The support can’t help and want’ that I ask here…

    …and it is NOT SOLVED this was a wrong click, how can I remove this from the thread?

  • I don’t think there is an option to unmark a solution.

    What do you mean by “wp default content-editor is deactivated”?

    Do you mean that you have ACF set to hide the default content editor? I tried this and I’m still not getting the errors that you’re getting when I restore a revision.

    What other types of fields do you have? Can you provide and export of the field group that is causing this error?

  • Yes deactivated = hidden

    here is the json:

    
    [
        {
            "key": "group_58fdac3805d6e",
            "title": "Standard Seite",
            "fields": [
                {
                    "key": "field_58fdacd119084",
                    "label": "Inhalt",
                    "name": "",
                    "type": "tab",
                    "instructions": "",
                    "required": 0,
                    "conditional_logic": 0,
                    "wrapper": {
                        "width": "",
                        "class": "",
                        "id": ""
                    },
                    "placement": "top",
                    "endpoint": 0
                },
                {
                    "key": "field_58fdad1266b76",
                    "label": "Überschrift",
                    "name": "headline",
                    "type": "textarea",
                    "instructions": "",
                    "required": 0,
                    "conditional_logic": 0,
                    "wrapper": {
                        "width": "50",
                        "class": "",
                        "id": ""
                    },
                    "default_value": "",
                    "placeholder": "",
                    "maxlength": "",
                    "rows": 2,
                    "new_lines": "br"
                },
                {
                    "key": "field_58fdad59a6080",
                    "label": "Teasertext",
                    "name": "teasertext",
                    "type": "textarea",
                    "instructions": "",
                    "required": 0,
                    "conditional_logic": 0,
                    "wrapper": {
                        "width": "",
                        "class": "",
                        "id": ""
                    },
                    "default_value": "",
                    "placeholder": "",
                    "maxlength": 200,
                    "rows": 4,
                    "new_lines": "br"
                },
                {
                    "key": "field_58fdac6456f92",
                    "label": "Teaser Bild",
                    "name": "teaser_image",
                    "type": "image_crop",
                    "instructions": "",
                    "required": 0,
                    "conditional_logic": 0,
                    "wrapper": {
                        "width": "",
                        "class": "",
                        "id": ""
                    },
                    "crop_type": "hard",
                    "target_size": "custom",
                    "width": 800,
                    "height": 566,
                    "preview_size": "medium",
                    "force_crop": "yes",
                    "save_in_media_library": "yes",
                    "save_format": "object",
                    "library": "all",
                    "retina_mode": "no"
                },
                {
                    "key": "field_5900981454641",
                    "label": "Text Layout",
                    "name": "copy_layout",
                    "type": "radio",
                    "instructions": "",
                    "required": 0,
                    "conditional_logic": 0,
                    "wrapper": {
                        "width": "",
                        "class": "",
                        "id": ""
                    },
                    "choices": {
                        "center": "zentriert",
                        "left": "linksbündig"
                    },
                    "allow_null": 0,
                    "other_choice": 0,
                    "save_other_choice": 0,
                    "default_value": "",
                    "layout": "horizontal",
                    "return_format": "value"
                },
                {
                    "key": "field_58fdac6e56f93",
                    "label": "Text",
                    "name": "copy",
                    "type": "wysiwyg",
                    "instructions": "",
                    "required": 0,
                    "conditional_logic": 0,
                    "wrapper": {
                        "width": "",
                        "class": "",
                        "id": ""
                    },
                    "default_value": "",
                    "tabs": "all",
                    "toolbar": "full",
                    "media_upload": 0,
                    "delay": 0
                },
                {
                    "key": "field_58fdacb74ea04",
                    "label": "Flexible Inhalte",
                    "name": "flexible_content_page_clone",
                    "type": "clone",
                    "instructions": "",
                    "required": 0,
                    "conditional_logic": 0,
                    "wrapper": {
                        "width": "",
                        "class": "",
                        "id": ""
                    },
                    "clone": [
                        "field_58e26f566db37"
                    ],
                    "display": "seamless",
                    "layout": "block",
                    "prefix_label": 0,
                    "prefix_name": 0
                },
                {
                    "key": "field_5900a215b7182",
                    "label": "Links & Verwandte Inhalte",
                    "name": "",
                    "type": "tab",
                    "instructions": "",
                    "required": 0,
                    "conditional_logic": 0,
                    "wrapper": {
                        "width": "",
                        "class": "",
                        "id": ""
                    },
                    "placement": "top",
                    "endpoint": 0
                },
                {
                    "key": "field_5900a1d1cca47",
                    "label": "Links",
                    "name": "related_links_clone",
                    "type": "clone",
                    "instructions": "",
                    "required": 0,
                    "conditional_logic": 0,
                    "wrapper": {
                        "width": "",
                        "class": "",
                        "id": ""
                    },
                    "clone": [
                        "group_58f9cbb37d94d"
                    ],
                    "display": "seamless",
                    "layout": "block",
                    "prefix_label": 0,
                    "prefix_name": 0
                },
                {
                    "key": "field_593a7f9f6a653",
                    "label": "",
                    "name": "",
                    "type": "message",
                    "instructions": "",
                    "required": 0,
                    "conditional_logic": 0,
                    "wrapper": {
                        "width": "100",
                        "class": "acf-separator",
                        "id": ""
                    },
                    "message": "",
                    "new_lines": "wpautop",
                    "esc_html": 0
                },
                {
                    "key": "field_5900a45388b68",
                    "label": "Verwandte Inhalte",
                    "name": "relationships_clone",
                    "type": "clone",
                    "instructions": "",
                    "required": 0,
                    "conditional_logic": 0,
                    "wrapper": {
                        "width": "",
                        "class": "",
                        "id": ""
                    },
                    "clone": [
                        "group_58f9f302af202"
                    ],
                    "display": "seamless",
                    "layout": "block",
                    "prefix_label": 0,
                    "prefix_name": 0
                },
                {
                    "key": "field_593a7fbf586d1",
                    "label": "",
                    "name": "",
                    "type": "message",
                    "instructions": "",
                    "required": 0,
                    "conditional_logic": 0,
                    "wrapper": {
                        "width": "100",
                        "class": "acf-separator",
                        "id": ""
                    },
                    "message": "",
                    "new_lines": "wpautop",
                    "esc_html": 0
                },
                {
                    "key": "field_58fdacbb4ea05",
                    "label": "Slider",
                    "name": "",
                    "type": "tab",
                    "instructions": "",
                    "required": 0,
                    "conditional_logic": 0,
                    "wrapper": {
                        "width": "",
                        "class": "",
                        "id": ""
                    },
                    "placement": "top",
                    "endpoint": 0
                },
                {
                    "key": "field_58fdacbd4ea06",
                    "label": "Slider",
                    "name": "slider_clone",
                    "type": "clone",
                    "instructions": "",
                    "required": 0,
                    "conditional_logic": 0,
                    "wrapper": {
                        "width": "",
                        "class": "",
                        "id": ""
                    },
                    "clone": [
                        "field_58f87ffd86644",
                        "field_58f8825ba35f4",
                        "field_58f8bb5b31957",
                        "field_58f8bc9b31958"
                    ],
                    "display": "seamless",
                    "layout": "block",
                    "prefix_label": 0,
                    "prefix_name": 0
                }
            ],
            "location": [
                [
                    {
                        "param": "page_template",
                        "operator": "==",
                        "value": "page.php"
                    }
                ]
            ],
            "menu_order": 0,
            "position": "normal",
            "style": "default",
            "label_placement": "top",
            "instruction_placement": "label",
            "hide_on_screen": [
                "excerpt",
                "custom_fields",
                "discussion",
                "comments",
                "categories",
                "tags",
                "send-trackbacks"
            ],
            "active": 1,
            "description": ""
        }
    ]
    
  • "type": "image_crop", is not a built in ACF field type and is an add on. Have you tried without this field type plugin active? Do you have any other ACF addons installed? I cannot recreate your problem using only built in ACF field types.

  • I’m also getting these warnings when trying to restore revisions on a custom post type (also with the main editor hidden via ACF). Two versions I can verify display this problem: 5.5.10 and 5.5.14.

    This is all because of a more primary bug I’m trying to troubleshoot: restoring revisions on custom post types seems to succeed, but all values in ACF fields stay the same instead of reverting.

    I’ll keep at it and post if I have any further info on either of these (what appear to be) bugs…

  • Some further information after looking through stack traces: the warning is because WP, as part of restoring a revision, is calling normalize_whitespace() (which then calls trim()) on the values of ACF fields that are arrays, not strings.

    Two instances of ACF fields that triggered this:
    – A flex content’s base field
    – A list of categories selected from a taxonomy field

  • @adjteam I am also troubleshooting a seemingly unrelated issue and ran into this problem. I came to the same conclusion as you — the error occurs when the value of an ACF field is an array, not a string as WordPress is expecting.

  • I’ve looked at this further and did some more testing and these are the conditions that are needed to cause this error.

    1) restoring a page revision, no other post type causes this
    2) the WP main content area hidden by the use of “Hide on screen” for a field group
    3) The value of an ACF field that is being restored is an array

    I have tried debugging why this might be happening, but I can’t figure out what could be causing it.

    My only suggestion for anyone seeing this is to contact support https://support.advancedcustomfields.com/new-ticket/

  • @hube2 I just submitted a ticket. Thanks for your debugging efforts on this 🙂

  • @bluesky @adjteam @jenwachter — Did anyone get anywhere with this? I have discovered the exact same problem on a huge site I’m building that I need to launch soon. 🙁

  • Yep! Elliot said it will be in the 5.6.0 release.

  • If it helps, this was the fix, but it requires you to edit ACF core. From Elliot:

    I’ve just done some testing and believe to have found a solution.
    Would you mind editing the ‘core/revisions.php’ file on line ~120 (wp_post_revision_fields function) and change it to:

    function wp_post_revision_fields( $fields, $post = null ) {
    		
    		// validate page
    		if( acf_is_screen('revision') || acf_is_ajax('get-revision-diffs') ) {
    			
    			// bail early if is restoring
    			if( acf_maybe_get($_GET, 'action') === 'restore' ) return $fields;
    			
    			
    			// allow
    			
    		} else {

    You will notice there is a new condition that checks if the post is restoring.
    This extra line should fix the issue.

  • Whew! Works! THANK YOU @jenwachter!! I’m including ACF on the site I’m working on, so that change should be safe enough. Just have to remember to re-fix if I update later and it isn’t patched yet…

  • Thanks for the info @jenwachter .

    FWIW, I’ll post here the fix to somewhat unrelated bugs I was experiencing with revisions that arose from trying to set the title of posts dynamically (based on ACF fields) on save.

    If you try to set native WP fields in a save_post hook (or even acf_save_post), you’ll end up with “extra” bogus revisions, often which don’t restore properly, or restore but ignore ACF changed fields.

    My fix was to listen for the wp_insert_post_data event, which I think ACF itself rides on, and make my change there, only referring to ACF fields by their ID since they wouldn’t be accessible via get_field at this point.

    
    // Update dynamic title on save.
    function bio_dynamic_title( $data, $postarr ) {
        // Bail if this isn't the right post type or if ACF wasn't submitted.
        if ( $data['post_type'] !== 'bio' || !array_key_exists( 'acf', $postarr ) ) {
          return $data;
        }
    
        $title = sanitize_text_field( full_name(
          $postarr['acf']['field_587e607692f49'], // first_name
          $postarr['acf']['field_589a17cb1cdd3'], // middle_initial
          $postarr['acf']['field_587e609192f4a'], // last_name
          $postarr['acf']['field_587e6ee94602b'] // suffix
        ));
    
        $data['post_title'] = $title;
        $data['post_name'] = sanitize_title( $title );
    
        return $data;
      }
      add_filter( 'wp_insert_post_data', 'bio_dynamic_title', 10, 2 );
    
Viewing 18 posts - 1 through 18 (of 18 total)

The topic ‘Revisions dont’t work, get php errors…’ is closed to new replies.