Last active
December 18, 2023 12:37
-
-
Save AndryWJ/fe6f0a4812982b14011b3100f55f8677 to your computer and use it in GitHub Desktop.
wp:php custom routing wordpress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| add_filter( 'init', function(){ | |
| add_rewrite_rule( | |
| '^bx24app/(.*)/?$', | |
| 'index.php?bx24app=$matches[1]', | |
| 'top' | |
| ); | |
| add_filter( 'query_vars', function($vars){ | |
| $vars[] = 'bx24app'; | |
| return $vars; | |
| }); | |
| add_action( 'template_redirect', function(){ | |
| if( $bx24app = get_query_var( 'bx24app' ) ){ | |
| $path = PLUGIN_DIR . '/modules/bitrix_app/'.$bx24app.'.php'; | |
| if(file_exists($path)){ | |
| include_once $path; | |
| exit(); | |
| }else{ | |
| status_header( 404 ); nocache_headers(); include( get_query_template( '404' ) ); | |
| die(); | |
| } | |
| } | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment