Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3942536
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T00:40:30+00:00 2026-05-20T00:40:30+00:00

Is it possible for a file in the plugin directory to be used as

  • 0

Is it possible for a file in the plugin directory to be used as a custom Page Template?

Also, how do you make a plugin create a page?

I’m developing a plugin for a client based on a theme, he wants this plugin to make sales pages while being able to use his theme on the homepage. This is a product that I’m making for him to market so it needs to be automated all through the plugin.

Is this possible?

EDIT

I have the activation/deactivation hooks in my plugins main file, and it’s not working. Here’s the code:

$filename = __FILE__;

register_activation_hook($filename, 'superActivation');
register_deactivation_hook($filename, 'superDeactivation');

global $myFile; global $fh; global $stringData; global $filename;

$myFile = "testFile.txt";
$stringData = "Testing\n";
$fh = fopen($myFile, 'w') or die("can't open file");

function superActivation() {
    global $myFile; global $fh; global $stringData; global $filename;
    fwrite($fh, $stringData);
    fclose($fh);
}

function superDeactivation() {
    $myFile = "testFile.txt";
    unlink($myFile);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T00:40:31+00:00Added an answer on May 20, 2026 at 12:40 am

    You can do this with the template_redirect hook. Here’s my code to manually replace the template for a custom post type with one in the theme if there isn’t one in the template folder. Put this in your plugin file and then put a folder underneath your plugin called themefiles with your default theme files.

    //Template fallback
    add_action("template_redirect", 'my_theme_redirect');
    
    function my_theme_redirect() {
        global $wp;
        $plugindir = dirname( __FILE__ );
    
        //A Specific Custom Post Type
        if ($wp->query_vars["post_type"] == 'product') {
            $templatefilename = 'single-product.php';
            if (file_exists(TEMPLATEPATH . '/' . $templatefilename)) {
                $return_template = TEMPLATEPATH . '/' . $templatefilename;
            } else {
                $return_template = $plugindir . '/themefiles/' . $templatefilename;
            }
            do_theme_redirect($return_template);
    
        //A Custom Taxonomy Page
        } elseif ($wp->query_vars["taxonomy"] == 'product_categories') {
            $templatefilename = 'taxonomy-product_categories.php';
            if (file_exists(TEMPLATEPATH . '/' . $templatefilename)) {
                $return_template = TEMPLATEPATH . '/' . $templatefilename;
            } else {
                $return_template = $plugindir . '/themefiles/' . $templatefilename;
            }
            do_theme_redirect($return_template);
    
        //A Simple Page
        } elseif ($wp->query_vars["pagename"] == 'somepagename') {
            $templatefilename = 'page-somepagename.php';
            if (file_exists(TEMPLATEPATH . '/' . $templatefilename)) {
                $return_template = TEMPLATEPATH . '/' . $templatefilename;
            } else {
                $return_template = $plugindir . '/themefiles/' . $templatefilename;
            }
            do_theme_redirect($return_template);
        }
    }
    
    function do_theme_redirect($url) {
        global $post, $wp_query;
        if (have_posts()) {
            include($url);
            die();
        } else {
            $wp_query->is_404 = true;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: PHP create a file without fopen I want to create a file
Possible Duplicate: Check synchronously if file/directory exists in Node.js For example, i have a
Using the Egit plugin, is it possible to permanently remove a file from source
Possible Duplicate: Limit file format when using <input type=file>? I need to use the
Possible Duplicate: Are file descriptors shared when fork()ing? Suppose I have following code in
Possible Duplicate: Get file name from URI string in C# How to extract file
Possible Duplicate: CSV File Imports in .Net In .net, is there a standard library
I know locally it is possible to get file content line by line. just
Possible Duplicate: Problem executing bash file I have created a bash file script and
Possible Duplicate: How to check file types of uploaded files in PHP? I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.