Skip to content

Elementor + YOAST + ACF Pro: Infinite Loop with wp_insert_post() - [Edge Case] #10998

@acf-extended

Description

@acf-extended

Prerequisites

  • I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
  • The issue still exists against the latest stable version of Elementor.

Description

I found a compatibility problem between Elementor, YOAST and ACF Pro. While this is an edge case, I think it should be looked at because it could cause some problems with others plugins.

Note: This is a cross-bugreport on both Elementor & YOAST github repo.
YOAST bugreport is available here.

Steps to reproduce

  • Add the following code in the theme functions.php file:
add_action('wp', function(){
	
	if(isset($_POST['test']) && !empty($_POST['test'])){
		
		if(have_rows('repeater', 32)):
			while(have_rows('repeater', 32)): the_row();
			
				// Log
				error_log('wp_insert_post');
				
				// wp_insert_post
				wp_insert_post(array(
					'post_title' => 'Page',
					'post_type' => 'page',
				));
				
				// Inifinite loop...
			
			endwhile;
		endif;
		
	}
	
	
});

add_shortcode('test', function(){
	
	if(have_rows('repeater', 32)):
		while(have_rows('repeater', 32)): the_row();
	
			// Do something with the repeater ...
		
		endwhile;
	endif;
	
	ob_start();
	
	?>
	<form action="" method="post">
		
		<input type="hidden" name="test" value="1" />
		<button>Submit</button>
		
	</form>
	<?php
	
	return ob_get_clean();

});
  • In ACF: Create a new field group Test with the conditional logic: Post Type = Page
  • In the field group add a repeater/flexible content field called repeater
  • Add a row with a single sub field called Test
  • Create a new page & add a new row in the ACF repeater field
  • Save the page and edit with Elementor
  • Add a shortcode widget, with the following code: [test]
  • Save the page
  • Retrieve the post_id and replace it in the code above (in all have_rows('repeater', 32) parts)
  • Display the page and click on the "Submit" button
  • The form is processed, and an infinite loop of post creation is triggered

The fundamental problem:

On each post creation, YOAST check the new post content for their "Link Checker" feature using the save_post hook (which is triggered inside wp_insert_post()).

When YOAST do that check, it retrieve the post content using apply_filters('the_content'). But Elementor add specific filters to the_content, and load all components and shortcodes. In our case, applying the shortcodes will print the form which trigger an infinite loop.

Potential bugfix

I found a workaround by disabling the YOAST "Link Checker" using the following hook, right before the wp_insert_post():

add_filter('wpseo_should_index_links', '__return_false');

However, this can also be fixed if we remove the filter applied on the_content in the file: /elementor/includes/frontend.php:273. The way it is implemented right now means that Elementor load all components & shortcodes when using wp_insert_post() in conjunction with YOAST, which seems problematic.

Isolating the problem

  • This bug happens with only Elementor plugin active (and Elementor Pro).
  • This bug happens with a default WordPress theme active.
  • I can reproduce this bug consistently using the steps above.

Environment

https://pastebin.com/raw/1K4rWaeE

Metadata

Metadata

Assignees

No one assigned

    Labels

    compatibility/3rd-partyIndicates a compatibility problem with a 3rd-party plugin or theme.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions