Skip to content

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

@acf-extended

Description

@acf-extended
  • I've read and understood the contribution guidelines.
  • I've searched for any related issues and avoided creating a duplicate issue.

Please give us a description of what happened.

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.
Elementor bugreport is available here.

How can we reproduce this behavior?

  • 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.

Technical info

  • If relevant, which editor is affected (or editors):
  • Classic Editor
  • Gutenberg
  • Classic Editor plugin
  • Which browser is affected (or browsers):
  • Chrome
  • Firefox
  • Safari
  • Other

Used versions

  • WordPress version: 5.3.2
  • Yoast SEO version: 13.3
  • Relevant plugins in case of a bug:
  • ACF Pro 5.8.9 (latest)
  • Elementor 2.9.7 (latest)
  • Tested with theme: Twenty Twenty

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions