• Tehseen Ahmed

    (@tehseen721)


    currently am working on a wordpress plugin called Product Designer and for design the product images i want to use a template file which contains all of functionality and working fine. So when i send my plugin for approval in wordpress they create issue and send me back the issue was they say cannot include the core file directory i use below two lines in my design template file so i pass id of product and call this template file

    require_once("../../../wp-blog-header.php");
    
    header("HTTP/1.1 200 OK");

    The question is how i can include a plugin template in my wordpress plugin without using the top two lines and my plugin work fine.

    Regards. thanks in advance

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    I don’t know if they explained that many WP installations have theme and plugin folders in a relatively different location, so relative references cannot work in all cases. Repository plugins must work in all cases. And you cannot use absolute URLs because WP is not always installed in public root. (ignoring that URLs are invalid in include statements anyway) The point being there is no way to know where the WP installation actually resides on a directly requested PHP file.

    Thus, in order to get the WP environment to load so your PHP file can use WP resources, your code can only be requested by going through WP first. There’s three ways you can get your code to execute within WP on request. One is to create page template, add a page based on that template. You can then request your code by using its permalink. The others are to go through admin-ajax.php or admin-post.php. WP Ajax methods are documented in the Plugin Handbook. admin-post.php is not very well documented, but it’s not difficult to work out if you already understand Ajax in WP. It’s very similar except you do not need jQuery to make the request. Despite “post” being part of the file name, a GET request with an “action” URL parameter will work.

Viewing 1 replies (of 1 total)

The topic ‘Proper way to include template file in wordpress plugin development.’ is closed to new replies.