Custom-Meta-Boxes icon indicating copy to clipboard operation
Custom-Meta-Boxes copied to clipboard

Check for switched site context in CMB_Meta_Box::save()

Open dnaber-de opened this issue 8 years ago • 1 comments

The method CMB_Meta_Box::save() assumes it runs in a site context it was initialized in. That means if any other component runs a switch_to_blog() and triggers the save_post action, your plugin writes data to a wrong object (in a wrong site). This already leads to concrete issues.

However, this is easy to solve by just adding the following guard to your save_post handler:

if ( is_multisite() && ms_is_switched() )
    return;

If appreciated I would provide a pull request.

dnaber-de avatar Jul 27 '16 11:07 dnaber-de

This sounds reasonable to me, any thoughts @mattheu?

mikeselander avatar Nov 12 '16 12:11 mikeselander