Tag Info

Hot answers tagged

6

Check out download_url() - it's only loaded in the admin, so you'll have to include it (or write your own) if needed on the front-end. From download_url() you can use: $response = wp_remote_get( TCS_CPDF_REMOTE_ZIP, array( 'timeout' => 300, 'stream' => true, 'filename' => TCS_CPDF_LOCAL_ZIP ) );


5

wp-content/uploads/ should be writable for the server (otherwise it would be impossible to upload a file, no?). If you are going to create something under this directory, it is safe to use wp_mkdir_p(). I would only use WP_Filesystem if there is a chance the server does not have permissions to write to the location, like in wp-content/plugins/, which does ...


5

I would highly recommend that you NOT move wp-content outside of the docroot. WordPress utilizes wp-content for more than uploads. This would have a huge impact on the accessibility of themes and plugins. WordPress uploader will not play well with this scenario, and you're only allowed to add an alternate relative relative path to the WordPress URI as well ...


5

i guess you are looking for this add_attachment and delete_attachment example: add_action('add_attachment', 'attachment_manipulation'); function attachment_manipulation($id) { if(wp_attachment_is_image($id)){ //do your own tasks } }


4

No, there is not a more convenient way. The thing is, your first example is insecure on the most common hosting systems because the directory will be "owned" by whatever user the webserver itself is running as. Thus, anybody else able to execute code on that same webserver will be able to access it, write to it, changes files in it, and so on. Credentials ...


4

Files named "core" are created when some OS process crashes. In your case it was likely a crash of the php interpreter. These files being memory dumps are used to debug the process "postmortem" - e.g. to check in which function did it fail, so it is perfectly safe to delete them if you are not going to debug the issue. In fact, on many systems there is a ...


3

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 directory, and ...


3

I'd try something simple, before messing around with an endless sea of possibilites/hosting setups: $target = 'wherever'; wp_mkdir_p( $target ); if ( wp_mkdir_p( $target ) === TRUE ) { echo "Folder $target successfully created"; } else { new WP_Error; #... etc. Just tell where the user has to make a new folder with the name xy // or if you're ...


2

$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 ...


2

Just a heads up on having your plugin create files/folders: my plugin did that as well, and I ran into a slew of issues with file permissions for different users. Some are windows, some are unix, some are hosted, and some home grown. It was my #1 support email once I shared the plugin. I have refactored my code to minimize the need to touch the file ...


2

Some handy links for you: http://codex.wordpress.org/Post_Thumbnails http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail http://codex.wordpress.org/Function_Reference/the_post_thumbnail http://codex.wordpress.org/Function_Reference/has_post_thumbnail Those are useful if you're wanting to display or act differently in the theme, based on ...


2

The get_contents function returns the contents of the file, not a file handle. Using put_contents with $f after that is incorrect. Try $wp_filesystem->put_contents( $htaccess_file, $htaccessnew, FS_CHMOD_FILE ) instead. Also, it's not necessarily safe to use things like "get_home_path" and such with the WP_Filesystem. The remote path may not match the ...


1

update The session option describe below seems very insecure! Further investigation make clear the array returned by request_filesystem_credentials contains your credentials in plain text. So store this in a session seems a bad idea. Note sending the credentials over an non-secure connection (http) when posting the form also seems a bad idea. The latest ...


1

What you are trying to do is wrong if it is for general purpose use and is not tailored for the needs of a specific client. Dynamically modifying your theme's code, and css is code like JS, is usually a bad idea that bring only maintenance problems - are you validating all values to be able to compile? How will you handle upgrades? How will you handle ...


1

Reading a file to send to the user is perfectly safe and does not necessarily need to be converted to the WP_Filesystem methods. Only writing is potentially an issue. However, if you wanted to do so, this would be the equivalent: echo $wp_filesystem->get_contents( filename variable here ); Also, note that your filename for "put_contents" is incorrect. ...


1

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 ...


1

To cache something you can use the Transients API (thanks @Otto), get_transient() to see if it exists already exists, if not then fetch the data and store it in a transient with set_transient(). if (get_transient('mytheme_webfonts')) { $content = get_transient('mytheme_webfonts'); } else{ $googleApi = ...


1

Yes, this can be done in WordPress. Check out http://wp.tutsplus.com/tutorials/allow-users-to-submit-images-your-site/ for some code examples. You will have to modify the logic to suit your needs of course, but the above link should get you pointed in the right direction.


1

Dear you don't need to worry about much - if its a fresh installation and you don't have any data on your website - eg post, article, images or anything then I prefer you t install a clean fresh wordpress again from the sketches after a complete scan of your hosting. and if you have data in your hosting I am sure you can access your data base from cpanel or ...


1

There is a bit of practical split about where WP can write files and if Filesystem API is invoked. It might be easier to see this divide not as technical, but as administrative. There is user space. Users must be able to do things like create attachments and must not need to have admin access credentials. For these requirements uploads directory typically ...


1

I expect that the problem is with the login credentials. Your code assumes that the credentials are set but you have done nothing to ensure that. var_dump($f) and see if you have an error object at $f->errors. That is, do this: $f = $wp_filesystem->get_contents($htaccess_file); var_dump($wp_filesystem); If you do have an error object you will need ...


1

You are trying to check it by URL, which makes no sense to is_file() which expects local path. By the way I'd use file_exists() instead. Try: $fileName1 = TEMPLATEPATH . '/txtfolder/file1.txt';


1

Line 756 is $dirlist = $wp_filesystem->dirlist($from);. The argument is ok. I think that the object $wp_filesystem is not globally available for your plugin.


1

The method rmdir() - source - : /** * Delete a directory. * * @since 2.5.0 * * @param string $path Path to directory. * @param bool $recursive Optional. Whether to recursively remove files/directories. * Default false. * @return bool Whether directory is deleted successfully or not. */ public function rmdir( $path, $recursive = false ) { return ...


1

It is not necessary to use the WP_Filesystem for every little thing, and in this case, the correct solution is to use the normal file_get_contents. The WP_Filesystem is a wrapper around various ways to interact with the filesystem in a safe manner... but it's not meant for everything. Fundamentally, the WP_Filesystem code was created to allow WordPress to ...


1

@codecowboy, what version of Redux are you using? In the newer versions we don't even use the googlefonts.json like this. I suggest you simply install Redux Framework from the WordPress plugin repository (http://wordpress.org/plugins/redux-framework/), and this problem will be resolved for you as plugin will override the Redux version embedded within your ...


1

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 false. if( ! ...



Only top voted, non community-wiki answers of a minimum length are eligible