« first day (2901 days earlier)      last day (2032 days later) » 

12:30 PM
@TomJNowell I'm changing the rewrite rules by adding a register_rest_route();. Which is called on the action rest_api_init which is why I was asking if I should call flush_rewrite_rules(); on late init or late rest_api_init, within register_activation_hook(); and/or register_deactivation_hook();
I'm basically looking to flush the rewrite rules on plugin activation/deactivation, but wanted to know an appropriate time to do it, so that my plugin functionality can be added BEFORE the flushing occurs, so that the rewrite rules are instantly valid on plugin activation and/or deactivation.
Does that make sense?
 
12:47 PM
@MichaelEcklund in the activation/deactivation hook
also your logic is back to front
what you're trying to do is add all your logic and rules
then erase them
the end result is none of your rules are present
eitherway it sounds like you have some misconceptions about how activation and deactivation hooks work
I'd suggest doing more research
and think of them less in the way that other hooks are
 
look at it this way
you're constructing a building
you have a add_floor function
and a construction_area_cleanslate function
do you build the floors then clear the construction site?
or do you clear the construction site then build the floors?
note that one gives you a building, the other gives you an empty construction site
and you seem intent on doing the one that adds all the stuff them erases all the work you've done
 
I thought you were supposed to flush rewrite rules after modifying them. eg. After adding a REST Route.
 
why would you do that, flushing rewrite rules literally erases them, hence the flush
 
oh, well how do I update them then?
 
12:53 PM
by adding them
After flushing
 
how do I ensure my new rules will be valid after adding a REST route?
 
when you flush permalinks
it regenerates them based on the rules added
 
I'm so confused.
isn't that what I'm doing?
 
ok nevermind
in practice, there are very, very few reasons to flush rewrite rules
 
Let me put it this way. When I register_rest_route(); on action: rest_api_init ... it doesn't work, unless I flush the rewrite rules.
calling register_rest_route() adds rewrite rules, so I flush afterwards.
 
12:57 PM
follow what the codex says
 
It's literally ONLY being flushed on plugin activation and deactivation. Once the functionality exists and when it no longer exists.
So when the plugin is being activated, doesn't WordPress still trigger all of its actions and filters as normal?
so within the activation callback, do this... on init...
 
1:10 PM
no idea, further research needed
eitherway, always register rewrite rules on init
activation and deactivation may be a special case, I couldn't possibly say
 
1:21 PM
So does rest_api_init happen on init?
I'm going to just leave it on late init
only on activation/deactivation.
anyways, thanks @TomJNowell for letting me pick your brain.
 
Again, checking where this is on topic - I used a WP plugin to activate a free SSL cert. And then added rewrite rules via .htaccess to send visitors to HTTPS:// . Now, the site loads very, very slowly. The question would be, how do I troubleshoot this?
I suppose this is a server issue, so not really WP? Any recommendation which stack would be on topic?
 
1:37 PM
Probably ServerFault or StackExchange...
I like to use xdebug/cachegrind to troubleshoot performance issues, but it may be overkill for your situation
 
@MichaelEcklund I never had to flush anything to be able to add a rest rout. If you need to flush something else is broken. Rest generally have nothing to do with rewrite rules
as for plugin activation, it happens after wordpress loaded, so adding actions on init from the activation handler will do nothing
 
@JoeTaxpayer 3rd party plugins aren't in scope, you'd have to talk to the authors
but again, SSL certificates aren't something you can do via a WP plugin
 
1:59 PM
@MarkKaplun indeed, my understanding is that there's a generic rewrite rule for wp-json that hands everything off to the rest api router
 
2:22 PM
yes, for the wp-json itself
than IIRC the url just being parsed matching the registered routes
now that I said it out loud, I can see why people might think that they need a rewrite rule
 

« first day (2901 days earlier)      last day (2032 days later) »