$wp_filesystem returns NULL. What are the dependencies?

$wp_filesystem is a global variable containing the instance of the (auto-)configured filesystem object after the filesystem “factory” has been run. To run the factory “over” the global variable (so to set it), just call the WP_Filesystem() function which is, guess what, undocumented in codex. At least the docblock contains some information and you can read … Read more

Moving wp-content outside of web root?

See Ben Word – How to Hide WordPress Summary: In the Roots Theme we’re taking several steps to help make it not so obvious that you’re using WordPress: Cleaning up the output of wp_head and removing the generator from RSS feeds Hiding /wp-content/ by rewriting static theme assets (CSS, JS, and images), rewriting the plugins … Read more

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 me. So it would be: add_filter( ‘upload_mimes’, function ( $mime_types ) { $mime_types[‘rfa’] = ‘application/CDFV2-unknown’; return $mime_types; } );

What is the correct way to check if WP_Filesystem can write to a directory without aking for username / password?

This is what i ended up using /** * check if the path is writable. To make the check . * * @param string $path * @return boolean */ public static function is_writable( $path ) { global $wp_filesystem; include_once ABSPATH . ‘wp-admin/includes/file.php’; // If for some reason the include doesn’t work as expected just return … Read more

How do you use unzip_file()?

require_once(ABSPATH .’/wp-admin/includes/file.php’); global $wp_filesystem; if ( ! $filesystem ) { WP_Filesystem(); if ( ! $wp_filesystem ) nuke_the_world_because_wpfs_cannot_be_initialized_in_case_of_missing_arguments(‘!’); } $result = unzip_file( $zip, $dest ); if ( is_wp_error( $result ) ) nuke_the_world(); Maybe some error handling make it easier.

What exactly does $wp_filesystem->abspath() return?

If you check out the source of abspath(): public function abspath() { $folder = $this->find_folder(ABSPATH); // Perhaps the FTP folder is rooted at the WordPress install, Check for wp-includes folder in root, Could have some false positives, but rare. if ( ! $folder && $this->is_dir( “https://wordpress.stackexchange.com/” . WPINC ) ) $folder=”https://wordpress.stackexchange.com/”; return $folder; } .. … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)