Answers for "category_rewrite_rules wordpress.org"

PHP
0

category_rewrite_rules wordpress.org

public function category_rewrite_rules() {
    global $wp_rewrite;

    $category_rewrite = [];

    $taxonomy            = get_taxonomy( 'category' );
    $permalink_structure = get_option( 'permalink_structure' );

    $blog_prefix = '';
    if ( is_multisite() && ! is_subdomain_install() && is_main_site() && strpos( $permalink_structure, '/blog/' ) === 0 ) {
      $blog_prefix = 'blog/';
    }

    $categories = get_categories( [ 'hide_empty' => false ] );
    if ( is_array( $categories ) && $categories !== [] ) {
      foreach ( $categories as $category ) {
        $category_nicename = $category->slug;
        if ( $category->parent === $category->cat_ID ) {
          // Recursive recursion.
          $category->parent = 0;
        }
        elseif ( $taxonomy->rewrite['hierarchical'] !== false && $category->parent !== 0 ) {
            $parents = get_category_parents( $category->parent, false, '/', true );
          if ( ! is_wp_error( $parents ) ) {
            $category_nicename = $parents . $category_nicename;
          }
          unset( $parents );
        }

        $category_rewrite = $this->add_category_rewrites( $category_rewrite, $category_nicename, $blog_prefix, $wp_rewrite->pagination_base );

        // Adds rules for the uppercase encoded URIs.
        $category_nicename_filtered = $this->convert_encoded_to_upper( $category_nicename );

        if ( $category_nicename_filtered !== $category_nicename ) {
          $category_rewrite = $this->add_category_rewrites( $category_rewrite, $category_nicename_filtered, $blog_prefix, $wp_rewrite->pagination_base );
        }
      }
      unset( $categories, $category, $category_nicename, $category_nicename_filtered );
    }

    // Redirect support from Old Category Base.
    $old_base                            = $wp_rewrite->get_category_permastruct();
    $old_base                            = str_replace( '%category%', '(.+)', $old_base );
    $old_base                            = trim( $old_base, '/' );
    $category_rewrite[ $old_base . '$' ] = 'index.php?wpseo_category_redirect=$matches[1]';

    return $category_rewrite;
  }
 
Posted by: Guest on April-15-2020

Browse Popular Code Answers by Language