1

I'm building a plugin that will be used for a single site and relies on add_rewrite_rule to work, which requires permalinks to be turned on. It's no trouble to turn them on since it's only a single site, but I'm concerned that one of the admins may turn it off not realizing what they're doing and break the site.

How can I programmatically force pretty permalinks to remain on?

1

Not exactly the solution you're asking for, but here's how I would deal with such problem...

If your plugin needs permalinks to be turned on, then I would put some checks and display a notice, if they're not turned on.

I don't think that plugin should force anything. There can be a lot of reasons that somebody turned permalinks off (for example they were breaking the site).So if your plugin will force them, then dealing with such problem would be very hard. And to be honest - it will be really hard to find why permalinks aren't turning off.

On the other hand... If I turn permalinks off and there will be notice, that your plugin may not work properly, everything will be clear and everyone will remember, why this plugin isn't working.

It's much nicer approach, I guess.

So the last part is the check itself. So how to check if permalinks are enabled? Codex tells you how:

if ( get_option('permalink_structure') ) {
    echo 'permalinks enabled';
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.