Not sure if this is necessary, the lines above the code submitted mention a check of moderation state but it looks like that's the content's current moderation state instead. Should this replace that instead?
This does however solve the issue as explained here.