[wp-hackers] $wp_rewrite->flush_rules() on plugin activation
if.website at gmail.com
Tue Dec 8 23:28:36 UTC 2009
On Tue, Dec 8, 2009 at 5:17 PM, Matt Jacob <matt at mattjacob.com> wrote:
> On Tue, Dec 8, 2009 at 4:03 PM, Austin Matzko <if.website at gmail.com> wrote:
>> Yes, and you'll also need to attach to "init" the callback that sets
>> up the rules.
> Is that the 'init' action, or my plugin's init function (the constructor)?
Yes, the "init" action.
> Does that mean that the Codex is wrong, then? It lists plugins_loaded
> as coming before init
"plugins_loaded" is not the same as "activate_[plugin filename]".
"plugins_loaded" happens on every load of WP files, when all the
active plugin files are included.
> To further complicate things, the docs for register_activation_hook()
> say that the callback passed to that function doesn't have access to
> global variables at the point when it's called. Does that include WP
> globals like $wp_rewrite?
Yes, you can use WP globals like $wp_rewrite.
Whoever wrote that is saying that normally plugin files are included
in global scope, so if you declare a variable in your plugin file
without explicitly making it a global variable, for all other times
but activation that variable will automatically have global scope. And
declaring variables like that with the hope they're global by default
is not a good idea, anyways.
More information about the wp-hackers