Adventskalender Day 10 – Prevent Recursion in Hooks

Today the Adventskalender is for all the developers out there, who have to fight recursion. Let’s say, we are within the context of a save_post hook and we want to, whatever reason, wp_update_post(), the function would look like this:

The problem: wp_update_post() triggers the 'save_post' hook. The result? An infinite loop. Let’s prevent this with a temporarely defined constant:

This example can be used for any kind of recursion like at wp_update_user().

Post Sharing

Author Avatar

Thomas is a WordPress-Developer, who always thinks beyond the tellerrand. Born 1985 and living in Düsseldorf, Thomas loves to play games, enjoys cooking and creating music.

Also Interesting

New Plugin: Slack Connector - Connect WordPress, WooCommerce and Slack

by Michael Firnkes

Initially we merely wanted to optimize our own Slack-processes. With automated notifications from our MarkettPress shop, the blog and our forums. The resul ...

Read more

Inpsyde is the first VIP partner in Germany

by Michael Firnkes

Automattic has given us the title of VIP Service Partner, the first in Germany, Austria and Switzerland. Worldwide, there are only eleven com ...

Read more

Inpsyde is a WooExperts Gold Partner of WooCommerce

by Michael Firnkes

A few weeks ago, Inpsyde GmbH with MarketPress became a certified WooExperts Gold Partner. This is confirmation from WooThemes of our agency’s know-h ...

Read more

BackWPup Pro: Secure WordPress Backup with Google Drive

by Michael Firnkes

The Pro version of our BackWPup plugin supports the backup of WordPress databases and files to Google Drive. But how do you set something like that up? And ...

Read more


Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">