Download the PHP package waughj/wp-theme-image without Composer
On this page you can find all versions of the php package waughj/wp-theme-image. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package wp-theme-image
WP Theme Image
Class for autogenerating HTML for WordPress theme image.
Works just like HTMLImage class, but autogenerates the FileLoader to fit WordPress’s theme directory.
Local directory within theme directory can be set on an image-by-image basis by setting the “directory” key in the $attributes hash map to the desired local directory string.
For example, in a theme named “blue” setup on localhost:
use WaughJ\WPThemeImage\WPThemeImage;
$image = new WPThemeImage( 'demo.png', [ 'directory' => 'img' ] );
$image->print(); // Will print <img src="http://localhost.com/wp-content/themes/blue/img/demo.png?m=4389109" alt=""> ( #s after m= will vary ).
Or you can globally set the default local directory with the static method setDefaultSharedDirectory():
use WaughJ\WPThemeImage\WPThemeImage;
$image = new WPThemeImage( 'demo.png' );
$image->print(); // Will print <img src="http://localhost.com/wp-content/themes/blue/demo.png?m=4389109" alt=""> ( #s after m= will vary ).
WPThemeImage::setDefaultSharedDirectory( 'pictures' );
$image = new WPThemeImage( 'demo.png' );
$image->print(); // Will now print <img src="http://localhost.com/wp-content/themes/blue/pictures/demo.png?m=4389109" alt=""> ( #s after m= will vary ).
Error Handling
As a child o’ HTMLImage, WPThemeImage will throw an exception if it’s set to show versioning ( default ) & can’t find the file on the server. Read the HTMLImage documentation to learn mo’ ’bout this. WPThemeImage works the same way:
try
{
$image = new WPThemeImage( 'missing.jpg' );
}
catch ( MissingFileException $e )
{
$image = $e->getFallbackContent();
}
$image->print() // Will print <img src="http://localhost.com/wp-content/themes/blue/missing.jpg" alt=""> without throwing an error.
Changelog
0.4.0
- Add function for getting URL directory.
0.3.0
- Integrate HTMLImage Autogeneration o’ Sizes Attribute & Shorthand Srcset Format
0.2.0
- Apply HTMLImage HTML Cache Optimization
0.1.0
- Initial Release
All versions of wp-theme-image with dependencies
waughj/directory Version >=0.3.1
waughj/file-loader Version >=0.5.4
waughj/html-image Version >=0.9.2