PHP Classes
elePHPant
Icontem

WP_Image: Store given images in a WordPress installation

Recommend this page to a friend!
  Info   View files Documentation   View files View files (28)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2017-12-06 (4 days ago) RSS 2.0 feedNot yet rated by the usersTotal: 43 This week: 28All time: 9,056 This week: 32Up
Version License PHP version Categories
wp_image 1.0.1Custom (specified...5PHP 5, Graphics, Blogs
Description Author

This class can store given images in a WordPress installation.

It can perform several types of operations with images to be stored for use in WordPress posts.

Currently it can retrieve an image from a remote URL and save it to associate with a post, process an uploaded image, delete images of a given post.

  Performance   Level  
Name: Josantonius is available for providing paid consulting. Contact Josantonius .
Classes: 19 packages by
Country: Spain Spain
Age: ???
All time rank: 232557 in Spain Spain
Week rank: 2 Up1 in Spain Spain Up
Innovation award
Innovation award
Nominee: 8x

Details

PHP WordPress Image

Latest Stable Version Total Downloads Latest Unstable Version License Travis

Versión en español

Save images to WordPress.

Installation

The preferred way to install this extension is through composer.

To install PHP Wordpress Image library, simply:

$ composer require Josantonius/WP_Image

The previous command will only install the necessary files, if you prefer to download the entire source code (including tests, vendor folder, exceptions not used, docs...) you can use:

$ composer require Josantonius/WP_Image --prefer-source

Or you can also clone the complete repository with Git:

$ git clone https://github.com/Josantonius/WP_Image.git

Requirements

This library is supported by PHP versions 5.6 or higher and is compatible with HHVM versions 3.0 or higher.

Quick Start and Examples

To use this class, simply:

<?php
require __DIR__ . '/vendor/autoload.php';

use Josantonius\WP_Image\WP_Image;

Available Methods

Available methods in this library:

save($url, $postID, $featured)

Save image and associate it with a specific post.

| Atttribute | Description | Type | Required | Default | --- | --- | --- | --- | --- | | $url | External url image | string | Yes | | | $postID | Post ID | int | Yes | | | $featured | Set image as featured | boolean | No | false |

@return ? string | false ? URI for an attachment file or false on failure

upload($url, $filename)

Upload image to WordPress upload directory.

| Atttribute | Description | Type | Required | --- | --- | --- | --- | | $url | External url image | string | Yes | | $filename| Filename | string | Yes |

@return ? string | false ? Path to upload image or false on failure

deleteAttachedImages($postID, $force)

Deletes an attachment and all of its derivatives.

| Atttribute | Description | Type | Required | --- | --- | --- | --- | | $postID | Post ID | int | Yes | | $force| Force deletion | boolean | Yes |

@return ? int | false ? Atachments deleted

Usage

Upload image

WP_Image::upload('https://site.com/image.png', 'image.png');

Save image

WP_Image::upload('https://site.com/image.png', '18');

Save featured image

WP_Image::upload('https://site.com/image.png', '18', true);

Delete attachments

WP_Image::deleteAttachedImages(18);

Force delete attachments

WP_Image::deleteAttachedImages('18', true);

Tests

To run tests simply:

$ git clone https://github.com/Josantonius/WP_Image.git

$ cd WP_Image

$ bash bin/install-wp-tests.sh wordpress_test root '' localhost latest

$ phpunit

? TODO

  • [x] Create tests
  • [x] Improve documentation

Contribute

  1. Check for open issues or open a new issue to start a discussion around a bug or feature.
  2. Fork the repository on GitHub to start making your changes.
  3. Write one or more tests for the new feature or that expose the bug.
  4. Make code changes to implement the feature or fix the bug.
  5. Send a pull request to get your changes merged and published.

This is intended for large and long-lived objects.

Repository

All files in this repository were created and uploaded automatically with Reposgit Creator.

License

This project is licensed under MIT license. See the LICENSE file for more info.

Copyright

2017 Josantonius, josantonius.com

If you find it useful, let me know :wink:

You can contact me on Twitter or through my email.

  Files folder image Files  
File Role Description
Files folder imagebin (1 file)
Files folder imagesrc (1 file, 1 directory)
Files folder imagetests (1 file, 2 directories)
Files folder imagevendor (1 file, 1 directory)
Accessible without login Plain text file .editorconfig Data Auxiliary data
Accessible without login Plain text file .travis.yml Data Auxiliary data
Accessible without login Plain text file CHANGELOG.md Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file CONDUCT.md Data Auxiliary data
Accessible without login Plain text file contributors.txt Doc. Documentation
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file phpunit.xml.dist Data Auxiliary data
Accessible without login Plain text file README-ES.md Doc. Documentation
Accessible without login Plain text file README.md Doc. Documentation
Accessible without login Plain text file _config.yml Data Auxiliary data

  Files folder image Files  /  bin  
File Role Description
  Accessible without login Plain text file install-wp-tests.sh Data Auxiliary data

  Files folder image Files  /  src  
File Role Description
Files folder imageWP_Image (1 file)
  Accessible without login Plain text file bootstrap.php Aux. Auxiliary script

  Files folder image Files  /  src  /  WP_Image  
File Role Description
  Plain text file WP_Image.php Class Class source

  Files folder image Files  /  tests  
File Role Description
Files folder imagetest-images (3 files)
Files folder imageWP_Image (1 directory)
  Accessible without login Plain text file bootstrap.php Example Example script

  Files folder image Files  /  tests  /  test-images  
File Role Description
  Accessible without login Image file cat.jpg Data Auxiliary data
  Accessible without login Image file funny.gif Data Auxiliary data
  Accessible without login Image file sponge.png Data Auxiliary data

  Files folder image Files  /  tests  /  WP_Image  
File Role Description
Files folder imageTest (1 file)

  Files folder image Files  /  tests  /  WP_Image  /  Test  
File Role Description
  Plain text file ImageTest.php Class Class source

  Files folder image Files  /  vendor  
File Role Description
Files folder imagecomposer (8 files)
  Accessible without login Plain text file autoload.php Aux. Auxiliary script

  Files folder image Files  /  vendor  /  composer  
File Role Description
  Accessible without login Plain text file autoload_classmap.php Aux. Auxiliary script
  Accessible without login Plain text file autoload_namespaces.php Aux. Auxiliary script
  Accessible without login Plain text file autoload_psr4.php Aux. Auxiliary script
  Plain text file autoload_real.php Class Class source
  Plain text file autoload_static.php Class Class source
  Plain text file ClassLoader.php Class Class source
  Accessible without login Plain text file installed.json Data Auxiliary data
  Accessible without login Plain text file LICENSE Lic. License text

 Version Control Unique User Downloads Download Rankings  
 100%
Total:43
This week:28
All time:9,056
This week:32Up