PHP code example of alleyinteractive / wp-path-dispatch
1. Go to this page and download the library: Download alleyinteractive/wp-path-dispatch library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
alleyinteractive / wp-path-dispatch example snippets
\WP_Path_Dispatch\Path_Dispatch()->add_path(
[
'path' => 'some-path',
'callback' => 'some_function'
]
);
\WP_Path_Dispatch\Path_Dispatch()->add_paths(
[
[
'path' => 'some-path',
'callback' => 'some_function',
],
[
'path' => 'custom-feed.json',
'callback' => 'custom_feed',
],
[
'path' => 'custom-feed.xml',
'callback' => 'custom_feed',
],
]
);
\WP_Path_Dispatch\Path_Dispatch()->add_path(
[
'path' => 'some-path', // re this action instead of dispatch_path_{$path}
'template' => '', // optional
'rewrite' => [ // optional
'query_vars' => [], // optional
'rule' => '', //
\WP_Path_Dispatch\Path_Dispatch()->add_path(
[
'path' => 'my-path',
]
);
\WP_Path_Dispatch\Path_Dispatch()->add_path( 'my-path' );
\WP_Path_Dispatch\Path_Dispatch()->add_path(
[
'path' => 'my-path',
'callback' => 'my_function',
]
);
\WP_Path_Dispatch\Path_Dispatch()->add_path(
[
'path' => 'my-path',
'template' => 'custom-page'
]
);
\WP_Path_Dispatch\Path_Dispatch()->add_path(
[
'path' => 'my-rewrite',
'rewrite' => [
'rule' => 'my-path/(.*)/?',
'redirect' => 'index.php?dispatch=my-rewrite&my_path=$matches[1]'
],
]
);
\WP_Path_Dispatch\Path_Dispatch()->add_path(
[
'path' => 'my-rewrite',
'rewrite' => [
'rule' => 'my-path/(.+)/?',
'redirect' => 'index.php?dispatch=my-rewrite&my_path=$matches[1]',
'query_vars' => 'my_path',
],
'template' => 'my-page',
]
);
\WP_Path_Dispatch\Path_Dispatch()->add_path(
[
'path' => 'my-rewrite',
'rewrite' => [
'rule' => 'my-path/([^/]+)/(.+)/?',
'redirect' => 'index.php?dispatch=my-rewrite&my_path=$matches[1]&my_section=$matches[2]',
'query_vars' => [ 'my_path', 'my_section' ],
],
'callback' => [ My_Singleton(), 'my_method' ],
]
);