Support

Account

Home Forums Bug Reports ACF 5.4 preview changes no longer works

Solved

ACF 5.4 preview changes no longer works

  • Hello,

    I’ve upgraded to 5.4.0 and now when I go to “preview changes” from the admin site none of my fields are pulled into the theme and instead I just get PHP errors about fields not existing.

  • Hi @leapxd

    Thanks for the bug report. Can you please attach some screenshots and copy/paste the errors?

    I’ll do some testing and get back to you shortly

  • Hi @leapxd

    Good news

    This issue has now been fixed. Please re-download the plugin files and copy across the api/api-helpers.php file or make the following code change on line ~744:

    
    function acf_verify_nonce( $value, $post_id = 0 ) {
    	
    	// vars
    	$nonce = acf_maybe_get( $_POST, '_acfnonce' );
    	
    	
    	// bail early if no nonce or if nonce does not match (post|user|comment|term)
    	if( !$nonce || !wp_verify_nonce($nonce, $value) ) {
    		
    		return false;
    		
    	}
    	
    	
    	// if saving specific post
    	if( $post_id ) {
    		
    		// vars
    		$form_post_id = (int) acf_maybe_get( $_POST, 'post_ID' );
    		$post_parent = wp_is_post_revision( $post_id );
    		
    			
    		// 1. no $_POST['post_id'] (shopp plugin)
    		if( !$form_post_id ) {
    			
    			// do nothing (don't remove this if statement!)
    			
    		// 2. direct match (this is the post we were editing)
    		} elseif( $post_id === $form_post_id ) {
    			
    			// do nothing (don't remove this if statement!)
    			
    		// 3. revision (this post is a revision of the post we were editing)
    		} elseif( $post_parent === $form_post_id ) {
    			
    			// return true early and prevent $_POST['_acfnonce'] from being reset
    			// this will allow another save_post to save the real post
    			return true;
    			
    		// 4. no match (this post is a custom created one during the save proccess via either WP or 3rd party)
    		} else {
    			
    			// return false early and prevent $_POST['_acfnonce'] from being reset
    			// this will allow another save_post to save the real post
    			return false;
    			
    		}
    		
    	}
    	
    	
    	// reset nonce (only allow 1 save)
    	$_POST['_acfnonce'] = false;
    	
    	
    	// return
    	return true;
    		
    }
    
  • Hi @elliot !

    Thanks for this. Will this updates (and the options update in another post) be rolled into a new release soon?

  • Just re-downloaded the files..
    This function doesn’t appear in api/api-template.php

    Line 744 has

    
    
    /*
    *  has_sub_field()
    *
    *  This function is used inside a while loop to return either true or false (loop again or stop).
    *  When using a repeater or flexible content field, it will loop through the rows until 
    *  there are none left or a break is detected
    *
    *  @type	function
    *  @since	1.0.3
    *  @date	29/01/13
    *
    *  @param	$field_name (string) the field name
    *  @param	$post_id (mixed) the post_id of which the value is saved against
    *  @return	(boolean)
    */
    
    function has_sub_field( $field_name, $post_id = false ) {....
    

    It does appear in api/api-helpers.php at line 767

    
    /*
    *  acf_verify_nonce
    *
    *  This function will look at the $_POST['_acfnonce'] value and return true or false
    *
    *  @type	function
    *  @date	15/10/13
    *  @since	5.0.0
    *
    *  @param	$nonce (string)
    *  @return	(boolean)
    */
    
    function acf_verify_nonce( $value, $post_id = 0 ) {....
    

    Was there a different file I should have downloaded?

  • Hi @leapxd

    Thanks for the reply. Yes, the file should be api/api-helpers.php

    Did this fix the issue?

  • Yep all fixed and working as expected. Thanks!

  • I’m having a similar issue with the ‘Preview Changes’ button not working for custom fields.

    This is with version 5.6.10 of ACF.

    The fix above does not seem to work for me.

  • @masmith Try enabling “Revisions” in your custom post type. This solved it for me

  • Thanks for the suggestion, but the problem is not on a custom post type but on pages, which I think already support revisions.

Viewing 10 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic.