Adventskalender Day 10 – Prevent Recursion in Hooks

marketpress-adventskalender-10

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

slack-blog

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
vip

Inpsyde is the first WordPress.com VIP partner in Germany

by Michael Firnkes

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

Read more
wooexperts

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

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

Comments

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="">