To answer your question, you have specified the paths incorrectly: plugin_dir_path( __FILE__ )
already has a trailing slash at the end (having two trailing slashes should not be a problem, but safer is to have one) and get_stylesheet_directory()
comes with no trailing slash at the end, so you have to add one before adding the filename. Your final code should be like this:
<?php
function file_replace() {
$plugin_dir = plugin_dir_path( __FILE__ ) . 'library/front-page.php';
$theme_dir = get_stylesheet_directory() . '/front-page.php';
if (!copy($plugin_dir, $theme_dir)) {
echo "failed to copy $plugin_dir to $theme_dir...\n";
}
}
add_action( 'wp_head', 'file_replace' );
Related Posts:
- Call to a member function put_contents() on a non-object
- How do you use unzip_file()?
- What’s a simple but secure method to get file contents into WordPress?
- How to append_contents using WP_Filesystem?
- When to use the Filesystem API? Should I use it at all?
- Why my wordpress blog files are getting changed?
- Finding the path of a specific WordPress install
- How to include form for WP_Filesystem()?
- How does WordPress access theme and plugin files through its editor?
- Is there a way to use WP filesystem without credentials when FS_METHOD is NOT set to direct?
- unzip_file not working with the remote file
- How can I add a method to create files when in theme-editor.php
- How to Copy Upload Image using WP_Filesystem_Direct
- Add `manifest.json` file to a Custom WordPress Theme
- How to display dialog box to save file from wp_filesystem->put_contents function?
- Creating directory in uploads – wp_mkdir_p() or WP_Filesystem?
- Standard location for plugin to save/cache files?
- How to use WordPress HTTP API to download file from remote location
- Which filters or actions to use after a media upload and delete?
- Do I need to use WP_Filesystem when creating a downloadable file on the fly?
- Convenient way to use wp_filesystem
- Copy and delete a directory with WordPress functions
- How to fix the error “file_get_contents was found in the file functions.php”?
- Can’t access wp_filesystem in cron function
- What exactly does $wp_filesystem->abspath() return?
- What is the correct way to check if WP_Filesystem can write to a directory without aking for username / password?
- Allowing all/different file type uploads
- Moving wp-content outside of web root?
- $wp_filesystem returns NULL. What are the dependencies?
- How do I edit the php/html for a particular post?
- Setting wp_temp_dir and permissions not working for “Missing A Temporary Folder” error
- Unable to access WP admin
- Use WP_Filesystem to list files in directory
- What to use , set_transient, set_option or file system? [closed]
- Why cant the WP Filesystem API read googlefonts.json?
- Convert PHP readfile to WP_Filesystem
- Using wp_filesystem in Plugins to store customizer settings
- Where is Featured Image code stored in WP?
- how to change max file upload size WordPress 4.9.8 [closed]
- Downloading File from Outside Web Root
- What is the best way to move a plugin´s subdirectory+files to wp-content/uploads-directory?
- Creating directory and file using native wordpress file system
- Relative file paths in CSS when linking directly (not enqueuing)
- Register visits of my pages in wordpresss
- Converting fopen/fwrite operations to WP_filesystem
- How to check if txt file exists inside template folder?
- Can I delete `wp-config-sample.php` after installing and configuring WordPress?
- Using wp_handle_upload() to Direct Specific Path by Using $overrides
- Unable to check if image uploaded by wp_image_editor exists using file_exists function
- Why WordPress plugin url ajax doesn’t work?
- Is file_get_contents() the only way for plugins reading local files OR does WP_Filesystem_Direct::get_contents() even work?
- Where to write custom logs in WordPress
- wp_filesystem put_contents issue with owner/group
- Copy Folder to another Folder using WP Filesystem
- why there is a large file named core in wpmu’s directory?
- What dependencies should I load and to use the WP_Filesystem?
- How to replace file_get_contents() with a WordPress Filesystem call
- Running rmdir function on post save
- How to move core js files into the footer
- WordPress Creates Unused (Unregistered) Image Sizes
- PHP File_exist() not working – Checking if File Exist in WordPress Theme Directory
- What functions of WP_Filesystem allow me to create a file with code-generated contents in a directory?
- Is there a name for trivial WP PHP files like functions.php, archive php entry.php, page.php and so forth?
- Right way to download file from source to destination
- Why WordPress not using WP_Filesystem
- WP_Filesystem in custom customize control
- Upload PDF and other files from the Front-End
- How to prevent users to view server files using WP File Manager plugin?
- Submitting form from input[type=file] dialog box
- How can I create a WordPress dynamic download counter
- Admin Custom Plugin List Files in admin Table
- How do you find a file in the media library using the file URL?
- temphangle variable missing when using wp_filesystem copy
- how to get json file in wordpress template
- Why is that only the first row getting inserted into Mysql table when i import csv file on backend custom plugin?
- WordPress Filesystem create CSS-File – get Shortcode ID for Name
- Unzip_file causing Media file upload error
- How to upload .tex files in wordpress?
- Need folder for CPT templates for eg: single-{post_type}.php
- Change default wordpress FS owner
- Downloadable content file structure
- Media Upload to custom database and Custom Directory
- trying to locate the correct file to edit my internal linking anchor tags
- Why does unzip_file always return true but nothing happens?
- Error Copying Directory On Plugin Activation
- Should I use Filesystem API for reading files or listing directories?
- WP_Filesystem usage within a block of code
- version control for wordpress? (wordpress folder and database at same time)
- how to create or rewrite files in wordpress plugin folder
- Enabling XSendFile causes 404 for images on WordPress Multisite / Network
- Upgrading WordPress (File permission group owner)
- Download a zip folder of selected files
- How do I upload my WordPress code files from previous website onto local host WordPress website?
- WordPress upload path decalration
- Does unzip_file() over-write by default?
- WordPress – tracking options