| @@ -1,12 +1,8 @@ | ||
| 1 | 1 | <?php |
| 2 | + | |
| 2 | 3 | namespace WPDeveloper\BetterDocs\Core; |
| 3 | 4 | |
| 4 | -if ( ! defined( 'ABSPATH' ) ) { | |
| 5 | - exit; | |
| 6 | -} | |
| 7 | - | |
| 8 | - | |
| 9 | 5 | use WP_Post; |
| 10 | 6 | use WPDeveloper\BetterDocs\Utils\Base; |
| 11 | 7 | use WPDeveloper\BetterDocs\Utils\Database; |
| 12 | 8 | |
| @@ -145,13 +141,8 @@ | ||
| 145 | 141 | |
| 146 | 142 | return $structure; |
| 147 | 143 | } |
| 148 | 144 | |
| 149 | - public function hierarchy_based_slug_switch() { | |
| 150 | - $hierarchy_slug = $this->settings->get( 'enable_category_hierarchy_slugs', false ); | |
| 151 | - return $hierarchy_slug; | |
| 152 | - } | |
| 153 | - | |
| 154 | 145 | public function get_base_slug() { |
| 155 | 146 | $docs_slug = $this->settings->get( 'docs_slug', 'docs' ); |
| 156 | 147 | $docs_page = $this->settings->get( 'docs_page', 0 ); |
| 157 | 148 | $builtin_doc_page = $this->settings->get( 'builtin_doc_page', true ); |
| @@ -205,9 +196,9 @@ | ||
| 205 | 196 | function ( $carry, $item ) { |
| 206 | 197 | $carry .= ( strpos( $item, '%' ) !== false ? '([^/]+)' : $item ) . '/'; |
| 207 | 198 | return $carry; |
| 208 | 199 | }, |
| 209 | - '^' | |
| 200 | + '' | |
| 210 | 201 | ) . '?$'; |
| 211 | 202 | } |
| 212 | 203 | |
| 213 | 204 | public function make_query( $segments ) { |
| @@ -240,23 +231,17 @@ | ||
| 240 | 231 | * https://url/docs/(kb-slug)/(cat-slug)/(docs-slug) |
| 241 | 232 | * https://url/docs/(cat-slug)/(kb-slug)/(docs-slug) |
| 242 | 233 | */ |
| 243 | 234 | |
| 244 | - $base = $this->get_base_slug(); | |
| 245 | - $hierarchy_slug = $this->hierarchy_based_slug_switch(); | |
| 235 | + $base = $this->get_base_slug(); | |
| 246 | 236 | |
| 247 | 237 | // Add rule to handle pagination attempts |
| 248 | 238 | $this->add_rewrite_rule( |
| 249 | - '^' . $base . '/page/([0-9]+)/?$', | |
| 239 | + $base . '/page/([0-9]+)/?$', | |
| 250 | 240 | 'index.php?post_type=docs', |
| 251 | 241 | 'top' |
| 252 | 242 | ); |
| 253 | 243 | |
| 254 | - $base = $this->get_base_slug(); | |
| 255 | - $this->add_rewrite_rule( '^' . $base . '/(feed|rdf|rss|rss2|atom)/?$', 'index.php?post_type=docs&feed=$matches[1]' ); | |
| 256 | - $this->add_rewrite_rule( '^' . $base . '/authors/([0-9]+)/?$', 'index.php?post_type=docs&author=$matches[1]' ); | |
| 257 | - $this->add_rewrite_rule( '^' . $base . '/authors/([0-9]+)/page/([0-9]+)/?$', 'index.php?post_type=docs&author=$matches[1]&page=$matches[2]' ); | |
| 258 | - | |
| 259 | 244 | /** |
| 260 | 245 | * This code of blocks used to determine single docs permalink. |
| 261 | 246 | */ |
| 262 | 247 | $_docs_perma_struct = betterdocs()->settings->get( 'permalink_structure', 'docs' ); |
| @@ -261,20 +246,8 @@ | ||
| 261 | 246 | */ |
| 262 | 247 | $_docs_perma_struct = betterdocs()->settings->get( 'permalink_structure', 'docs' ); |
| 263 | 248 | $_normalized_structure = $this->normalzie_doc_perma_structure( $_docs_perma_struct ); |
| 264 | 249 | |
| 265 | - if( $hierarchy_slug ) { // register hierarchy based slug rewrite rule, for single doc permalink | |
| 266 | - // When MKB or WPML is used, the actual base for single docs might differ from the generic $base | |
| 267 | - $perma_base = isset( $_normalized_structure['raw'][0] ) && strpos( $_normalized_structure['raw'][0], '%' ) === false | |
| 268 | - ? $_normalized_structure['raw'][0] | |
| 269 | - : $base; | |
| 270 | - | |
| 271 | - $this->add_rewrite_rule( '^' . $perma_base . '/(.+?)/([^/]+)(?:/([0-9]+))?/?$', 'index.php?doc_category=$matches[1]&docs=$matches[2]&post_type=docs', 'top' ); | |
| 272 | - | |
| 273 | - // Removed flush_rewrite_rules() from here. Calling flush_rewrite_rules() on the 'init' hook causes | |
| 274 | - // infinite database updates and destroys custom rules when WPML or MKB dynamically filters keys. | |
| 275 | - } | |
| 276 | - | |
| 277 | 250 | $_feed_regex = $_normalized_structure['raw']; |
| 278 | 251 | $_feed_regex[] = '(feed|rdf|rss|rss2|atom)'; |
| 279 | 252 | $_feed_group = $_normalized_structure['group']; |
| 280 | 253 | $_feed_group[] = '%feed%'; |
| @@ -285,9 +258,9 @@ | ||
| 285 | 258 | $this->make_regex( $_normalized_structure['raw'] ), |
| 286 | 259 | $this->make_query( $_normalized_structure['group'] ) |
| 287 | 260 | ); |
| 288 | 261 | |
| 289 | - $this->add_rewrite_rule( '^' . $base . '/(feed|rdf|rss|rss2|atom)/?$', 'index.php?post_type=docs&feed=$matches[1]' ); | |
| 262 | + $this->add_rewrite_rule( $base . '/(feed|rdf|rss|rss2|atom)/?$', 'index.php?post_type=docs&feed=$matches[1]' ); | |
| 290 | 263 | } |
| 291 | 264 | |
| 292 | 265 | public function add_rewrite_rule( $regex, $query, $after = 'top' ) { |
| 293 | 266 | add_rewrite_rule( $regex, $query, $after ); |