managed_page_url

📅 Published on

📝 Last updated

Documentation

»

Functions

»

managed_page_url

Returns the URL to a path within Groundhogg’s managed page — the special page that handles the preferences centre, email confirmations, unsubscribes, and other Groundhogg-specific front-end endpoints. Pass a relative path to get the full URL for that endpoint, or call with no arguments to get the base managed page URL.

Parameters

ParameterTypeDescription
$urlstringA relative path within the managed page (e.g. 'preferences/manage/'). Default empty string returns the base URL.

Return value

string — The full URL to the specified managed page path.

Usage

$base    = \Groundhogg\managed_page_url();
$prefs   = \Groundhogg\managed_page_url( 'preferences/manage/' );
$confirm = \Groundhogg\managed_page_url( 'preferences/confirm/' );
$unsub   = \Groundhogg\managed_page_url( 'preferences/unsubscribe/' );

Example

Here’s a pseudo code example for a hypothetical custom managed page endpoint.

add_action( 'groundhogg/install_custom_rewrites', 'my_plugin_add_managed_rewrite' );

/**
 * Register a custom endpoint under Groundhogg's managed page.
 *
 * @return void
 */
function my_plugin_add_managed_rewrite() {
    \Groundhogg\add_managed_rewrite_rule(
        'my-plugin/([^/]+)',
        'subpage=my-plugin&token=$matches[1]'
    );
}

add_action( 'template_redirect', 'my_plugin_handle_managed_request' );

/**
 * Handle requests to the custom endpoint.
 *
 * @return void
 */
function my_plugin_handle_managed_request() {

    if ( ! \Groundhogg\is_managed_page() ) {
        return;
    }

    $token = get_query_var( 'token' );

    if ( $token ) {
        my_plugin_process_token( $token );
        exit;
    }
}

Was this helpful?

Let us know if this document answered your question. That’s the only way we can improve.