1. Go to this page and download the library: Download varunsridharan/wp-endpoint 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/ */
varunsridharan / wp-endpoint example snippets
$vs_wp_endpoint = new \Varunsridharan\WordPress\Endpoint('customprefix');
/**
* Adds Custom Endpoints To Endpoints Array.
*
* @param string $endpoint
* @param int $endpoint_type
* @param array|string $callback
* if callback is a string and no function with the name then it will be triggered as action
*
* @example add_endpoint('hello/',EP_PAGES,'my_page_calback')
* @example add_endpoint('world/',EP_PAGES,array(&$this,'page_callback'))
*
* @return $this
*/
// With Action Trigger
$vs_wp_endpoint->add_endpoint('myendpoint',EP_ROOT,'myendpoint_action');
// With Function Callback
$vs_wp_endpoint->add_endpoint('myendpoint2',EP_ROOT,'myendpoint_callback');
// With Class Callback
$vs_wp_endpoint->add_endpoint('myendpoint3',EP_ROOT,array('VS_CALLBACK_HANDLER','render'));
add_action('myendpoint_action','render_endpoint_page');
function render_endpoint_page($wp){
var_dump($wp->query_vars);
}
function myendpoint_callback($wp){
var_dump($wp->query_vars);
}
class VS_CALLBACK_HANDLER{
public static function render($wp){
echo 'Hi';
}
}
/**
* Adds Custom Rewrite Rules.
*
* @param string $path
* @param string $after
*
* @return $this
*/
// Below Will Be Converted into **http://example.com/mypath/22/xxx/
$vs_wp_endpoint->add_rewrite_rule('mypath/{user_id}/{user_name}','top');
// Below Will Be Converted into **http://example.com/welcome/EICAUTPPWICAASJEJNCA/
$vs_wp_endpoint->add_rewrite_rule('welcome/{verify_id}','top');
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.