Working with Files
All images and files throughout the MasterPress API are represented by the WOOF_Image and WOOF_File classes respectively. The classes offers a lot of utility methods which will often save you from needing to call on lower level PHP file functions. The examples presented in this section assume you already know how to access files and images via the API, please read through Accessing Files and Images if you’re not familiar.
File links and enclosures
The method WOOF_File::link can be used to easily build an HTML anchor (a) tag linking to the file. This method accepts an arguments string or array to override both the attributes used, and the link text via the “text” argument:
Example 1: Linking to a file
Building an enclosure tag for an RSS feed is made easy via the WOOF_File::enclosure method:
Example 2: Building an enclosure tag
The WOOF_File class contains a host of utility methods for accessing properties on the file, many of which have more concise method names than their counterpart functions in PHP.
Path and file name methods
Example 3: File path and file name methods
All of these should be explained well enough in the comments in Example 1, and the class reference for WOOF_File explains them in detail.
Example 4: URL methods
Again, these should be straightforward.
WOOF_File has a number of methods for dealing with the size of the file, which can be really useful to output nicely formatted file sizes for linking to file downloads. Let’s look at how to use WOOF_File::size and WOOF_File::bytes:
Example 5: File size methods
Now let’s look at how to access information about the kind of file we’re dealing with. In addition to a the WOOF_File::mime method to retrieve the mime-type, WOOF_File also contains a number of static arrays which store both short and long descriptions of known file extensions, accessable through the WOOF_File::filetype and methods:
Example 6: Getting file type info
Finally you can access the modification date of a file with the WOOF_File::modified function, which can take also take a formatter string: