admin管理员组

文章数量:1122832

I want to create a URL to an activation page in Wordpress. But I don't want to create a page for it with a shortcode. So it must be a dynamic page.

I'm currently trying to see if I can do it with a REST API. And so far activation has been successful. I have created a REST route and I get the activation code (which is part of the link) as a variable. But I cannot show a page with a message that the activation was successful, not within the chosen theme. All HTML I send to the browser is displayed on a black page, without the theme.

I'm starting to wonder if I'm on the right path, or is the REST API intended for something else?

This is what I have so far:

$this->loader->add_action( 'rest_api_init', $plugin_public, 'course_add_enpoint');

public function course_add_enpoint(){
  register_rest_route('course_manager/v1', 'activation/(?P<id>[A-Za-z0-9]+(_[A-Za-z0-9]+)+)', array(
            'methods' => 'GET',
            'callback' => array ($this, 'course_activation'),
    ));
}

public function course_activation( $data ){
        returns HTML code
}

So far the activation works, but the page with HTML code is not the same as a page with the layout of the theme. Can someone point me in the right direction, am I working with the REST API or should I look elsewhere?

I want to create a URL to an activation page in Wordpress. But I don't want to create a page for it with a shortcode. So it must be a dynamic page.

I'm currently trying to see if I can do it with a REST API. And so far activation has been successful. I have created a REST route and I get the activation code (which is part of the link) as a variable. But I cannot show a page with a message that the activation was successful, not within the chosen theme. All HTML I send to the browser is displayed on a black page, without the theme.

I'm starting to wonder if I'm on the right path, or is the REST API intended for something else?

This is what I have so far:

$this->loader->add_action( 'rest_api_init', $plugin_public, 'course_add_enpoint');

public function course_add_enpoint(){
  register_rest_route('course_manager/v1', 'activation/(?P<id>[A-Za-z0-9]+(_[A-Za-z0-9]+)+)', array(
            'methods' => 'GET',
            'callback' => array ($this, 'course_activation'),
    ));
}

public function course_activation( $data ){
        returns HTML code
}

So far the activation works, but the page with HTML code is not the same as a page with the layout of the theme. Can someone point me in the right direction, am I working with the REST API or should I look elsewhere?

Share Improve this question edited Jun 2, 2024 at 13:04 Buttered_Toast 2,8191 gold badge8 silver badges21 bronze badges asked Jun 1, 2024 at 14:18 Rene van DamRene van Dam 11 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 0

OK, I found a page how to create a fake page and it's exactly what I needed: https://geek.hellyer.kiwi/2018/creating-fake-wordpress-pages/

本文标签: rest apiDynamic activation page in Wordpress