Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm calling the function below after each "save changes" on my plugin's settings file via the sanitization callback.

The plugin allows the end user to change their category base, and needs to completely rewrite the permalinks in order to avoid 404 errors. However, I'm still getting 404s. The only way I can resolve them is to go to the "Settings > Permalinks" manager and clicking "Save Changes".

What am I missing in this function to get rid of the 404s?

function myplugin_refresh() {
    wp_cache_flush();
    global $wp_rewrite;
    $my_permalinks = get_option('permalink_structure');
    $wp_rewrite->set_permalink_structure($my_permalinks);
    $wp_rewrite->flush_rules();
    }
share|improve this question

2 Answers 2

up vote 0 down vote accepted

Check the code in wp-admin/options-permalink.php lines 91 to 129 (3.0.5). Compare if you do all that.

share|improve this answer
    
Thanks for the tip. Will do. –  Scott B Feb 21 '11 at 1:31
    
Looks like I'm doing everything that's there. Can you see anything that's missing? –  Scott B Feb 21 '11 at 17:52
    
@Scott B: Well what i saw in there was that it seemed to do some prep operations on the permalink structure? –  wyrfel Feb 22 '11 at 16:03

wp_rewrite is not initialized in register_activation_hook()

In your hook activation code add this line....

add_option('reset_permalink_structure',true);

In your plugin code add....

add_action('admin_init',function(){
        if( get_option('reset_permalink_structure') ) {
            global $wp_rewrite;
            $my_permalinks = get_option('permalink_structure');
            $wp_rewrite->set_permalink_structure($my_permalinks);
            $wp_rewrite->flush_rules();
            add_option('reset_permalink_structure',false);
        }
    }
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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