If what you want is to actually generate a page template when the plugin is activated, you can use something like this:
<?php
/**
* Plugin Name: Testtest
* Description: Ignore
* Version: 0.1
* Author: windyjonas
*/
function myplugin_activate() {
$buf = "<?php\n"
. "/*\n"
. " * Template Name: generated template\n"
. " */\n"
. "?>\n"
. "Hello world\n";
$handle = fopen( get_stylesheet_directory() . '/tpl-plugin.php', 'w' );
fwrite( $handle, $buf );
fclose( $handle );
}
register_activation_hook( __FILE__, 'myplugin_activate' );
This only works if the web server user has enough privileges to write to theme directory.
Related Posts:
- Is it possible to upload a template file to a directory that can be used by all themes?
- Is there any way to get all the name or slug of template parts used in a page?
- Create a custom page template inside my wordpress plugin
- Register Page Template from Plugin
- Plugin-generated pages use Not Found or Pages Archive templates?
- Plugin create pages and use templates
- How do I show content from a plugin using the template the site is currently working with?
- WordPress Product Detail and catalog
- Plugin json page
- How to use custom footer template in a site-plugin?
- Custom Page Templates for a complex application – code must sit in a plugin and not the Theme
- How to provide page_template path in custom plugin using WordPress
- Get plugin directory from a theme
- How to call a plugin function from index.php
- Rewriting every url
- How can I make my custom shortcode work in a Custom HTML Widget?
- How Does WordPress Uninclude/Deactivate A Plugin?
- Custom admin column disappearing when using Quick Edit [duplicate]
- Create page when plugin is activated
- How to un-attach rich text editor from named textarea elements
- How can I translate the name of my Plugin for other languages?
- how to not show plugin in admin area
- Memory Leak in plugin action
- Getting User email on logout. wp_logout
- Ajax call doesn’t work in frontend but it’s working in backend (when I’m logged in)
- How can I add a custom meta value on file upload?
- Logs to check when the plugin was first installed for the first time
- Can a plugin add to header/footer/body content?
- Add a Custom Permalink option in the Permalink Admin Screen?
- How Can A Plugin Hook Itself To the End of Every Excerpt?
- Allow Facebook to preview posts before published
- publish_post plugin hook doesn’t always pass $post->post_content
- Let user subscribe to specific categories
- add action for displaying posts using a shortcode
- Best way to hook a custom url?
- How to cancel WordPress’ action/filter when using OOP with anonymous callback
- What is the best way to mimic a search query within a plugin
- How do I add a custom sub menu menu under Woo-commerce marketing?
- How to load plugin after page is loaded – pagespeed issues
- Programatically download a plugin
- Do action only on certain front end pages?
- Archive – same title for the first two posts
- Creating plugin using simple_html_dom parser?
- User Session and Stored Cookies not get removed
- Create a navbar filter that filters by a custom field
- wp.media javascript issue with on select
- add tabs in rdp-plugin/includes/settings.php and get settings saved
- Creating shortcodes in plugin
- Plugin Development Form Self Submission
- Change plugin name on WordPress repo
- How To Extend A WordPress Plugin Without Losing Your Changes [duplicate]
- Does a blank plugin come with any overhead?
- Admin AJAX doesn’t work in plugin admin page – Even though code is copied verbatim from WordPress Codex
- Are plugins instantiated on every request to WordPress?
- Why is my custom post type not being activated on plug-in activation?
- URLs Added to ACF Repeater Field are not working
- adding a button to the media uploader
- How to generate an all in one WordPress New content, plugin and theme update report on a website? [closed]
- Why WP_Screeen doesn’t show all options with admin_body_class
- How do I add $_SESSION[”] to my wordpress page?
- Built a second plugin but it overwrote the first one
- Search users with custom meta data
- Calling a class method instantiated by ajax call in wordpress [closed]
- Woocommerce plugin – How to create two versions of the same plugin with slightly different implementation for different users
- Error using wordpress functions inside a plugin class
- How to Join wp_posts & wp_postmeta table using custom query
- Use localized plugin name and description even when the plugin is disabled
- Give custom page template a custom post ID
- How to resolve warning for `unstableOnSplit` prop on a DOM element in block editor
- Rename a folder via HTML POST request
- Cron task gets removed from the schedule
- path of wp-content directory when we are on some plugin
- “Enable Media Replace” plugin does not update serialized object in WPMeta
- One time call to external API in widget
- Add Custom Field to Post Pages via Plugin
- Timing issue with is_amp_endpoint()
- Is it possible to change plugin’s Admin Panel Url?
- Can I add content before post content without using the_content filter
- WordPress scheduled event not working
- plugin_dir_url(__FILE__) searches parent theme in ACF extension
- hide load more button if there are no posts left to display
- My plugin can’t see my files
- Confusing problem with displaying message recipient metadata
- Use functionality in third-party plugin in my own plugin
- Input gets deleted/overwritten after changing to different Admin Menu
- Force Network Activated Plugin to Run After Site Level Plugins
- I want to add facility to add country, State, City in my custom plugin
- The plugin generated XXX characters of unexpected output…help?
- Cannot Search | Featured | Popular | Newest | Favorites in wordpress working
- Display WP Start bar on front page only
- WP-Snap too slow (caused by WP_Query?)
- WordPress Meta Query: Relation is not working correctly
- What is the source outline for a basic word press plugin?
- Submit posts in two different post types with the same form
- How do I set register_meta for a specific CPT?
- How to Enfroce Domain Licensing Limits? [closed]
- How can I save the selected page in the dropdown after anyone clicks on Save Changes?
- Update Content for a Custom Block Toolbar Button
- Submitting form to admin-post.php WordPress
- WordPress Throwing Deprecated Errors on its own Files