Skip to content

Instantly share code, notes, and snippets.

@harisrozak
Last active October 26, 2018 04:23
Show Gist options
  • Save harisrozak/b371fa5adfd7767c6654f36da9999696 to your computer and use it in GitHub Desktop.
Save harisrozak/b371fa5adfd7767c6654f36da9999696 to your computer and use it in GitHub Desktop.
WordPress::Create custom static page on custom url
<?php
add_action('init', 'create_download_page');
public function create_download_page() {
global $wp;
$home_url = network_home_url();
$download_url = trailingslashit(network_home_url('download'));
// current url path
$current_path = parse_url(add_query_arg(array()), PHP_URL_PATH);
$current_path = trailingslashit($current_path);
// get the strpos & substr
$pos = strripos($download_url, $current_path);
$substr = substr($download_url, 0, $pos);
// is all true?
$is_pos = ($pos !== false);
$is_last_segment = ($is_pos && ($substr . $current_path) == $download_url);
$is_include_home_url = ($is_pos && strlen($home_url) > $pos);
// load the download file if true
if($is_pos && $is_last_segment && $is_include_home_url) {
require_once(plugin_dir_path( __FILE__ ) . 'download-page.php');
exit();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment