[wp-hackers] update_option problem
Peter Westwood
peter.westwood at ftwr.co.uk
Thu May 14 06:39:35 GMT 2009
On 14 May 2009, at 00:59, aesqe wrote:
> Hi all :)
>
> I've been trying to figure out why the following doesn't work:
>
> <?php
> /*
> Plugin Name: permalink check
> Plugin URI: ...
> Description: ...
> Author: ...
> Version: 1.0
> Author URI: ...
> */
>
> function permalinkage()
> {
> global $wp_rewrite;
> echo $wp_rewrite->get_category_permastruct();
> }
> add_action('update_option_permalink_structure', 'permalinkage');
> ?>
>
> Permalink structure gets updated, but get_category_permastruct()
> returns previous value each time.
>
> Is this related to option caching, maybe?
>
No.
The reason here is that your are asking for the information before it
has been updated.
The process goes as follows in WP_Rewrite:
function set_permalink_structure($permalink_structure) {
if ($permalink_structure != $this->permalink_structure) {
update_option('permalink_structure', $permalink_structure);
$this->init();
}
}
The WP_Rewrite::init function is what reconfigures the rewrite engine
with the new permalink structure and so until that has been called you
will get the old configuration from the $wp_rewrite object.
At the moment there is not a hook that I can see that will let you act
on this option change after it has been completed.
From WordPress 2.8 you will be able to use the new
'permalink_structure_changed' action which I have added to
set_permalink_structure in [11325].
Cheers
westi
--
Peter Westwood
http://blog.ftwr.co.uk | http://westi.wordpress.com
C53C F8FC 8796 8508 88D6 C950 54F4 5DCD A834 01C5
More information about the wp-hackers
mailing list