Articles of filesystem

Generating and downloading files with WP API

Lately I was challenged to implement functionality that would allow users, editing specific custom post, to download json file based on meta of that post. I finally managed to complete the task (well, in some sense at least), but what now concerns me the most is the security of my solution. Here goes the code […]

Correct file permissions for in-browser updates using WP-CLI

I installed WP using WP-CLI (i.e. on the command line on the remote server). I’d like to give another person the ability to change the theme, plugins, etc. using the standard WP admin browser interface. When she (and I) try to install a new theme from an account with admin permissions, we are presented with […]

Cleaning a filename after image sideloading a url that contains `%20`

Right now I’m creating a plugin to sideload images from an external source. The UI allows me to select files on the external server then downloads them via AJAX & media_sideload_image. Everything is working great. After the images is loaded I clean up the attachment’s title by replacing the dashes and underscores with spaces in […]

WordPress HTTP Error on File upload

I have increased the max_file_upload_size from 20 MB to 100 MB in WordPress, but I’ve been facing a problem since then. Whenever I try to upload a file of any type, it says “HTTP Error” when I use the multiple file uploader. I’ve tried to upload using the single file uploader. It says “Error saving […]

get_template_directory() returns wrong address on VPS

I’m having the following problem with a WordPress installation on a VPS server. I’m trying to read from a JSON file but the returned address from get_template_directory() is wrong: $url = get_template_directory() . ‘/inc/includes/acf-fonticonpicker’; $json_file = trailingslashit($url) . ‘icons/selection.json’; if($wp_filesystem->exists($json_file)){ $json_content = $wp_filesystem->get_contents($json_file); } $json_file is empty because the JSON file is not found. The […]

Right way to download file from source to destination

I’m trying to download a file from one location to another. The code is working perfect. Here is the code snippet: Helper Function – Create directory in /uploads/{$dir_name}/ and return paths. /** * Create folder in /uploads/{$dir_name}/ * @return array() */ function get_dirpath( $dir_name = ‘test’ ) { $wp_info = wp_upload_dir(); // SSL workaround. if […]

Removing the references to the wp-content folder

I downloaded an HTML template and did the necessary conversions to create a wordpress theme. The location of the template files is in /wp-content/themes. When I look at my template and I go to my website, the URL is simple However, initially when I clicked on any of the links, the URL was […]

Uploading non-media files?

I want to add files on WordPress that are non images, embedded video and the like. However when I try this using the upload media feature I get the following error. “File type does not meet security guidelines.” Is there a way to do this using WordPress?

Why does WP load so many files in the head of source code? How do I optimize it?

I have noticed that wordpress loads a bunch of files into the head of a site. This looks really sloppy and discloses vital information about the file structure of a website. Depending how many plugins are installed a site can easily have 10+ <link> and <script> tags. I understand how these files may work together, […]

Why do I get undefined function export_wp()?

I’m trying to create a function in functions.php or a plugin to generate an export via a cronjob, similar to how Chris_O did this question. However it seems that I can’t call export_wp(), I keep getting: Fatal error: Call to undefined function export_wp() in wherever-I-call-it-from.php on line 686 Can someone tell me how to call […]