Skip to content

Instantly share code, notes, and snippets.

@everaldomatias
Created July 15, 2023 01:20
Show Gist options
  • Save everaldomatias/f2edbda35aeb1cd464b06ef4689d7e7f to your computer and use it in GitHub Desktop.
Save everaldomatias/f2edbda35aeb1cd464b06ef4689d7e7f to your computer and use it in GitHub Desktop.
Create virtual page on WP
<?php
namespace MeuPlugin;
$voting_page = apply_filters( 'voting_page', 'create-voting' );
define( 'MEUPLUGIN_VOTING_PAGE', $voting_page );
function add_rewrite()
{
add_rewrite_rule('^concordamos/' . CONCORDAMOS_VOTING_PAGE . '/?', 'index.php?voting_page=1', 'top');
}
// add_action( 'init', 'MeuPlugin\add_rewrite' );
function add_query_vars($vars)
{
$vars[] = 'voting_page';
return $vars;
}
// add_filter( 'query_vars', 'MeuPlugin\add_query_vars' );
function add_parse_request( $wp )
{
if ( array_key_exists( 'voting_page', $wp->query_vars ) ) {
include MEUPLUGIN_PLUGIN_PATH . 'templates/create-voting.php';
exit;
}
}
// add_action( 'parse_request', 'MeuPlugin\add_parse_request' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment