• Hi,

    I have an “admin_post_myaction” hook that processed a request, but instead of using wp_redirect() at the end, I would like to simply load a template under the same request. I tried the following and it seems to work but it resulted some PHP Notice message in the debug.log:

    // my admin_post_myaction code …
    load_template(locate_template(‘page-mytemplate.php’));

    The debug.log output:

    [15-Nov-2021 15:50:55 UTC] PHP Notice: Trying to get property ‘base’ of non-object in /app/wordpress/wp-includes/admin-bar.php on line 765

    So my quesiton is, what’s the proper way to load template in the admin-post.php processing workflow?

    BTW: One use case of this is I want to process a form using admin-post.php and if it contains error, I want to re-display the form without a full redirect request. If you have another better suggestion to do this, please do share.

    Thanks!

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    Because admin-post.php is an admin request, I don’t think the theme is even loaded. To load the theme, include its functions.php file. You can then load the desired template.

    The theme and template is not directly related to PHP notice. The cause of that is the related supposedly admin screen wasn’t properly set up. As admin-post.php isn’t really part of the WP back end, I’m unsure of how to fix this. You could try instantiating a WP_Screen object and then call its set_current_screen() method. I think you may need to also explicitly set its $id and $base properties. You can use any unique identifier string. There may be other issues in doing this, it’s a bit of a hack.

Viewing 1 replies (of 1 total)
  • The topic ‘Proper way to load_template after admin_post.php processing?’ is closed to new replies.