diff --git a/src/includes/class-boldgrid-framework-404.php b/src/includes/class-boldgrid-framework-404.php index 321397d9..1c4d857b 100644 --- a/src/includes/class-boldgrid-framework-404.php +++ b/src/includes/class-boldgrid-framework-404.php @@ -65,7 +65,6 @@ public function boldgrid_404_template() { -
- false ) ); + + foreach ( $categories as $category ) { + $category_nicename = $category->slug; + if ( $category->parent === $category->cat_ID ) { + $category->parent = 0; + } elseif ( 0 !== $category->parent ) { + $category_nicename = get_category_parents( $category->parent, false, '/', true ) . $category_nicename; + } + + $category_rewrite[ '(' . $category_nicename . ')/(?:feed/)?(feed|rdf|rss|rss2|atom)/?$' ] = 'index.php?category_name=$matches[1]&feed=$matches[2]'; + + $category_rewrite[ '(' . $category_nicename . ')/page/?([0-9]{1,})/?$' ] = 'index.php?category_name=$matches[1]&paged=$matches[2]'; + + $category_rewrite[ '(' . $category_nicename . ')/?$' ] = 'index.php?category_name=$matches[1]'; + } + + global $wp_rewrite; + + $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?category_redirect=$matches[1]'; + + return $category_rewrite; + } + + /** + * Schedule Flush + * + * Flush rewrite rules on category additions, + * changes, or deletions. + * + * @since 2.19.1 + */ + public function schedule_flush() { + add_action( 'shutdown', 'flush_rewrite_rules' ); + } } diff --git a/src/includes/class-boldgrid-framework-comments.php b/src/includes/class-boldgrid-framework-comments.php index 51c388a9..e2aa3869 100644 --- a/src/includes/class-boldgrid-framework-comments.php +++ b/src/includes/class-boldgrid-framework-comments.php @@ -272,8 +272,6 @@ public function boldgrid_bootstrap_comment( $comment, $args, $depth ) { $button_class = get_theme_mod( 'bgtfw_comment_reply_button_class', 'button-primary' ); $classes = apply_filters( 'bgtfw_button_classes', array() ); - error_log( 'button_class: ' . $button_class ); - error_log( 'isset button_class: ' . isset( $classes[ $button_class ] ) ); if ( isset( $classes[ $button_class ] ) ) { $comment_reply_link = preg_replace( '/comment-reply-link/', diff --git a/src/includes/class-boldgrid-framework.php b/src/includes/class-boldgrid-framework.php index 242861a0..3d70b07d 100644 --- a/src/includes/class-boldgrid-framework.php +++ b/src/includes/class-boldgrid-framework.php @@ -656,6 +656,12 @@ private function define_admin_hooks() { $this->loader->add_action( 'init', $admin, 'remove_hooks' ); $this->loader->add_action( 'bgtfw_pro_feature_cards', $pro_feature_cards, 'print_cards' ); + + // Filter category rewrite rules. + $this->loader->add_filter( 'category_rewrite_rules', $admin, 'category_rewrite_rules' ); + $this->loader->add_action( 'created_category', $admin, 'schedule_flush' ); + $this->loader->add_action( 'edited_category', $admin, 'schedule_flush' ); + $this->loader->add_action( 'delete_category', $admin, 'schedule_flush' ); } /** diff --git a/src/includes/partials/template-tags.php b/src/includes/partials/template-tags.php index 6b38ed5a..6f0ef1df 100644 --- a/src/includes/partials/template-tags.php +++ b/src/includes/partials/template-tags.php @@ -169,7 +169,7 @@ function boldgrid_entry_footer() { $categories_list = get_the_category_list( esc_html__( ', ', 'crio' ) ); $categories_count = count( explode( ', ', $categories_list ) ); - if ( $categories_list && boldgrid_categorized_blog() ) { + if ( $categories_list ) { $class = 'singular'; $icon = is_single() ? get_theme_mod( 'bgtfw_posts_cat_icon' ) : get_theme_mod( 'bgtfw_blog_post_cat_icon' ); @@ -236,36 +236,6 @@ function boldgrid_entry_footer() { } endif; -/** - * Returns true if a blog has more than 1 category. - * - * @return bool - */ -function boldgrid_categorized_blog() { - if ( false === ( $all_the_cool_cats = get_transient( 'boldgrid_categories' ) ) ) { - // Create an array of all the categories that are attached to posts. - $all_the_cool_cats = get_categories( array( - 'fields' => 'ids', - 'hide_empty' => 1, - // We only need to know if there is more than one category. - 'number' => 2, - ) ); - - // Count the number of categories that are attached to the posts. - $all_the_cool_cats = count( $all_the_cool_cats ); - - set_transient( 'boldgrid_categories', $all_the_cool_cats ); - } - - if ( $all_the_cool_cats > 1 ) { - // This blog has more than 1 category so boldgrid_categorized_blog should return true. - return true; - } else { - // This blog has only 1 category so boldgrid_categorized_blog should return false. - return false; - } -} - /** * Flush out the transients used in boldgrid_categorized_blog. */