6
votes
Accepted
What dependencies should I load and to use the WP_Filesystem?
What is the best way to load the dependencies for the WP_Filesystem?
The first or the second code part?
WP_Filesystem() is used in conjunction with the global $wp_filesystem variable, so if you use ...
4
votes
Accepted
How to replace file_get_contents() with a Wordpress Filesystem call
Firstly add this two line to your functions.php file. Sorry I forgot to mention about this earlier.
require_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php';
require_once ABSPATH . 'wp-...
4
votes
How to replace file_get_contents() with a Wordpress Filesystem call
Solution 01
$wp_filesystem = new \WP_Filesystem_Direct(null);
$svg= $wp_filesystem->get_contents(get_stylesheet_directory_uri() . '/assets/images/Search_Glyph.svg');
Solution 02
$remote_svg_file = ...
3
votes
Accepted
Register visits of my pages in wordpresss
It's not a good idea to store user's data on a file that is publicly accessible. A better way would be to create a folder, and store your file under it. Also, it's better to use WordPress's filesytem ...
3
votes
Accepted
Can I delete `wp-config-sample.php` after installing and configuring Wordpress?
Yes, you can safely delete that file. It's a template of what a minimal wp-config.php looks like, so as soon as you have a working wp-config, you don't need it.
It will never be restored unless you ...
3
votes
Accepted
How do I edit the php/html for a particular post?
It's useful to understand how things work in WP. Content (pages, posts) are stored in the WP database. The 'style' of the site - how it works, how pages are built, how it looks - are in the theme of ...
3
votes
Why my wordpress blog files are getting changed?
It's really hard to give you a 100% solid answer, because there is not much info in your question, but... Let me do some educated guesses...
The files that are mentioned in your question are very ...
3
votes
Relative file paths in CSS when linking directly (not enqueuing)
Relative paths in CSS are relative to the stylesheet file. So if you have this structure:
- style.css
- images/
-- logo.png
-- background.jpg
Then the paths in CSS for the images would be url(images/...
3
votes
Is file_get_contents() the only way for plugins reading local files OR does WP_Filesystem_Direct::get_contents() even work?
The alternate of using file_get_contents() is to initiate WP_Filesystem and use its $wp_filesystem->get_contents method.
Here is a clean example method on how to use it
Example
<?php
/**
...
3
votes
Accepted
How to append_contents using WP_Filesystem?
WP_Filesystem abstraction is primarily meant for performing plugin/theme/core updates, especially in environments with restricted writes.
As such it doesn’t really implement full range of possible ...
3
votes
Accepted
How to fix the error "file_get_contents was found in the file functions.php"?
To Add External Atylesheet:
Generally speaking, you should use the wp_enqueue_style() function to add external stylesheet to your theme.
function wpse259600_add_style() {
wp_enqueue_style( '...
2
votes
Downloading File from Outside Web Root
What you have there is production ready. However, there is room for some minor improvements, so I will point those out for you. Also see my notes below regarding X-Sendfile and X-Accel-Redirect.
...
2
votes
How to use WordPress HTTP API to download file from remote location
$your_pdf_path = 'https://example.com/Fortrydelsesformular.pdf';
if (!class_exists('WP_Http'))
include_once( ABSPATH . WPINC . '/class-http.php' );
$http = new WP_Http();
$response = $http->...
2
votes
Accepted
Do I need to use WP_Filesystem when creating a downloadable file on the fly?
No.
Keep in mind that the code sniffer is a limited utility operating on very simplistic parsing of the PHP code and has very little contextual knowledge. Therefor, you should use it as an advisory, ...
2
votes
Accepted
Allowing all/different file type uploads
I had the same issue, it looks like WordPress isn't able to determine the correct MIME type for RFA files, so it defaults to:
'application/CDFV2-unknown'
Changing the MIME type to this fixed it for ...
2
votes
Is file_get_contents() the only way for plugins reading local files OR does WP_Filesystem_Direct::get_contents() even work?
$wp_filesystem->get_contents is wrong for this purpose, since you can't know what filesystem path the file is going to be accessible at using WP_Filesystem . If the user has WP_Filesystem using ...
2
votes
Accepted
What to use , set_transient, set_option or file system?
I would go with transient. The reason I would choose transient it is they are created exactly for your case. I know that you have your own removal functionality but why to repeat yourself? Another ...
1
vote
Accepted
PHP File_exist() not working - Checking if File Exist in WordPress Theme Directory
Most of this code is unnecessary. You're attempting to convert a URL to a path when you could just use the function that returns a path.
$path = get_theme_file_path( 'archive.php' );
if ( file_exists(...
1
vote
Accepted
Finding the path of a specific WordPress install
If you haven't already figured this out, as you have admin access to the dashboard, just go into Appearance->Theme Editor then add some PHP into the theme's footer.php or functions.php to echo out the ...
1
vote
how to change max file upload size WordPress 4.9.8
php.ini should be in the /wp-admin/ folder, not the root. Also, I've had success using a combination of the following in my /wp-admin/php.ini file AND a directive to increase the memory in my wp-...
1
vote
What functions of WP_Filesystem allow me to create a file with code-generated contents in a directory?
Seems like you have several misconceptions/misunderstanding about when/why and how you should write to files.
In general never write to any directory in which code resides, either core code or themes ...
1
vote
Relative file paths in CSS when linking directly (not enqueuing)
You should be using get_stylesheet_directory_uri(). This is the same function as get_template_directory_uri() but it uses the directory of the child theme.
as an example:
get_template_directory_uri(...
1
vote
Accepted
Is there a name for trivial WP PHP files like functions.php, archive php entry.php, page.php and so forth?
They don't have a special name, they are just theme / template files. If you want to read more about them in general, see template files in the codex. The template hierarchy is also something you'll ...
1
vote
Right way to download file from source to destination
There is no need to use the WP filesystem API if you are trying to access directories to which the web server has full access. It is needed mainly only when you want to write to directories which have ...
1
vote
What's a simple but secure method to get file contents into WordPress?
I had to dig pretty deep for this too, and eventually figured out some way to do this.
in my solution I used the following:
WP_Filesystem();
global $wp_filesystem;
$wp_filesystem->exists( '/path/...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
wp-filesystem × 96filesystem × 22
plugin-development × 16
uploads × 16
plugins × 9
php × 8
theme-development × 6
directory × 6
media-library × 4
ziparchive × 4
filesystem-api × 4
htaccess × 3
wp-config × 3
functions × 2
images × 2
hooks × 2
urls × 2
forms × 2
media × 2
security × 2
upgrade × 2
file-manager × 2
virus × 2
custom-post-types × 1
customization × 1