Advertisement
Guest User

Untitled

a guest
Dec 13th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.85 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Plugin Name: DBRR - Tests
  4.  * Plugin URI:
  5.  * Description: Test Cases for rules testing.
  6.  * Version:     0.0.1
  7.  */
  8.  
  9.  
  10. register_activation_hook( __FILE__, function() {
  11.     add_filter( 'rewrite_rules_array', 'rewrite_rules_array_defaults_reset' );
  12.  
  13.     flush_rewrite_rules();
  14. });
  15.  
  16. register_deactivation_hook( __FILE__, function() {
  17.  
  18.     // Resets for Some general unused by me rules.
  19.     remove_filter( 'rewrite_rules_array', 'rewrite_rules_array_defaults_reset', 12 );
  20.     flush_rewrite_rules();
  21. });
  22.  
  23. add_action( 'init', function() {
  24.     add_filter( 'rewrite_rules_array', 'rewrite_rules_array_defaults_reset', 12 );
  25. });
  26.  
  27. /**
  28.  * Reset filters
  29.  *
  30.  * ... so we can see and test a smaller amount of information.
  31.  *
  32.  * @param  array $rules    WP_Rewrite Rules.
  33.  * @return array
  34.  */
  35. function rewrite_rules_array_defaults_reset( array $rewrite_rules ) : array {
  36.     $rewrite_rules = [];
  37.     $rewrite_rules['^wc-auth/v([1]{1})/(.*)?'] = 'index.php?wc-auth-version=$matches[1]&wc-auth-route=$matches[2]';
  38.     $rewrite_rules['^wc-api/v([1-3]{1})/?$'] = 'index.php?wc-api-version=$matches[1]&wc-api-route=/';
  39.     $rewrite_rules['^wc-api/v([1-3]{1})(.*)?'] = 'index.php?wc-api-version=$matches[1]&wc-api-route=$matches[2]';
  40.     $rewrite_rules['sitemap_index\.xml$'] = 'index.php?sitemap=1';
  41.     $rewrite_rules['([^/]+?)-sitemap([0-9]+)?\.xml$'] = 'index.php?sitemap=$matches[1]&sitemap_n=$matches[2]';
  42.     $rewrite_rules['([a-z]+)?-?sitemap\.xsl$'] = 'index.php?yoast-sitemap-xsl=$matches[1]';
  43.     $rewrite_rules['shop/?$'] = 'index.php?post_type=product';
  44.     $rewrite_rules['shop/feed/(feed|rdf|rss|rss2|atom)/?$'] = 'index.php?post_type=product&feed=$matches[1]';
  45.     $rewrite_rules['shop/(feed|rdf|rss|rss2|atom)/?$'] = 'index.php?post_type=product&feed=$matches[1]';
  46.     $rewrite_rules['shop/page/([0-9]{1,})/?$'] = 'index.php?post_type=product&paged=$matches[1]';
  47.  
  48.     return $rewrite_rules;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement