[wp-hackers] How do I remove rewrite rules?

Abdussamad Abdurrazzaq abdussamad at abdussamad.com
Sat Oct 13 16:19:52 UTC 2012


Try the plugin code below:

<?php
/*
Plugin NAme: REwrite Rule remover
*/

class rewrite_rule_remove {
        function __construct() {
         register_activation_hook( __FILE__, array( $this, 'install' ) );
           add_action( 'generate_rewrite_rules', array( $this, 'remover' 
) );
        }

     public function install() {
           flush_rewrite_rules();
     }

     public function remover( $wp_rewrite ){
           unset( $wp_rewrite->rules [ 
'[0-9]{4}/[0-9]{1,2}/[^/]+/attachment/([^/]+)/?$' ] );
     }
}

new rewrite_rule_remove();
?>

Unset is needed instead of array_splice because its an associative array.

On 10/13/2012 08:28 PM, Chris McCoy wrote:
> Yes we already do this, we want to remove a default rule
>
> -----Original Message-----
> From: wp-hackers-bounces at lists.automattic.com
> [mailto:wp-hackers-bounces at lists.automattic.com] On Behalf Of Abdussamad
> Abdurrazzaq
> Sent: Saturday, October 13, 2012 1:33 AM
> To: wp-hackers at lists.automattic.com
> Subject: Re: [wp-hackers] How do I remove rewrite rules?
>
> You'll need to plug into an action called  "generate_rewrite_rules". The
> call back function will take one argument $wp_rewrite which is the rewrite
> object. $wp_rewrite->rules will allow you to get/set the current rules.
>
> On 10/12/2012 09:01 PM, Tom Barrett wrote:
>> Specifically, I would like to remove attachment rewrite rules and
>> replace them with a leading slug (e.g. /media/).
>>
>> My Google-fu has abandoned me - all I can find is related to flushing
>> and apache rewrite. I want to delete the rule.
>>
>> My main reason for this is slug collisions with media items.
>> Especially that they take precedence over pages.
>>
>
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>




More information about the wp-hackers mailing list