PHPackages                             josantonius/wp-image-handler - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Image &amp; Media](/categories/media)
4. /
5. josantonius/wp-image-handler

AbandonedArchivedLibrary[Image &amp; Media](/categories/media)

josantonius/wp-image-handler
============================

Adding, updating and deleting images from WordPress posts.

1.0.3(8y ago)955MITPHPPHP ^5.6 || ^7.0

Since Jul 18Pushed 3y ago2 watchersCompare

[ Source](https://github.com/josantonius/wp-image-handler)[ Packagist](https://packagist.org/packages/josantonius/wp-image-handler)[ GitHub Sponsors](https://github.com/Josantonius)[ RSS](/packages/josantonius-wp-image-handler/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (5)Versions (5)Used By (0)

PHP WordPress Image
===================

[](#php-wordpress-image)

[![Latest Stable Version](https://camo.githubusercontent.com/33d5aebd8258cc78efd334fafd82ad868781ddfc2c6999a2bd07a5f688a1d18d/68747470733a2f2f706f7365722e707567782e6f72672f6a6f73616e746f6e6975732f77702d696d6167652d68616e646c65722f762f737461626c65)](https://packagist.org/packages/josantonius/wp-image-handler)[![License](https://camo.githubusercontent.com/86802e01277bf269e5f418e6ab5a6909573a6aacaf20156eb9a63de53999a52a/68747470733a2f2f706f7365722e707567782e6f72672f6a6f73616e746f6e6975732f77702d696d6167652d68616e646c65722f6c6963656e7365)](LICENSE)

[Versión en español](README-ES.md)

Adding, updating and deleting images from WordPress posts.

---

- [Requirements](#requirements)
- [Installation](#installation)
- [Available Methods](#available-methods)
- [Quick Start](#quick-start)
- [Usage](#usage)
- [Tests](#tests)
- [Sponsor](#Sponsor)
- [License](#license)

---

Requirements
------------

[](#requirements)

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

Installation
------------

[](#installation)

The preferred way to install this extension is through [Composer](http://getcomposer.org/download/).

To install **WP\_Image library**, simply:

```
composer require josantonius/wp-image-handler

```

The previous command will only install the necessary files, if you prefer to **download the entire source code** you can use:

```
composer require josantonius/wp-image-handler --prefer-source

```

You can also **clone the complete repository** with Git:

```
git clone https://github.com/josantonius/wp-image-handler.git

```

Or **install it manually**:

[Download WP\_Image.php](https://raw.githubusercontent.com/josantonius/wp-image-handler/master/src/class-wp-image.php):

```
wget https://raw.githubusercontent.com/josantonius/wp-image-handler/master/src/class-wp-image.php

```

Available Methods
-----------------

[](#available-methods)

Available methods in this library:

### - Save image and associate it with a specific post

[](#--save-image-and-associate-it-with-a-specific-post)

```
WP_Image::save($url, $post_ID, $featured);
```

AtttributeDescriptionTypeRequiredDefault$urlExternal url image.stringYes$post\_IDPost ID.intYes$featuredSet image as featured.booleanNofalse**@return** (string|false) → URI for an attachment file or false on failure.

### - Upload image to WordPress upload directory

[](#--upload-image-to-wordpress-upload-directory)

```
WP_Image::upload($url, $filename);
```

AtttributeDescriptionTypeRequired$urlExternal url image.stringYes$filenameFilename.stringYes**@return** (string|false) → Path to upload image or false on failure.

### - Deletes an attachment and all of its derivatives

[](#--deletes-an-attachment-and-all-of-its-derivatives)

```
WP_Image::delete_all_attachment($post_ID, $force);
```

AtttributeDescriptionTypeRequired$post\_IDPost ID.intYes$forceForce deletion.booleanYes**@return** (int|false) → Atachments deleted.

Quick Start
-----------

[](#quick-start)

To use this library with **Composer**:

```
require __DIR__ . '/vendor/autoload.php';

use Josantonius\WP_Image;
```

Or If you installed it **manually**, use it:

```
require_once __DIR__ . '/class-wp-image.php';

use Josantonius\WP_Image\WP_Image;
```

Usage
-----

[](#usage)

Example of use for this library:

### - Upload image

[](#--upload-image)

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

### - Save image

[](#--save-image)

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

### - Save featured image

[](#--save-featured-image)

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

### - Delete attachments

[](#--delete-attachments)

```
WP_Image::delete_all_attachment(18);
```

### - Force delete attachments

[](#--force-delete-attachments)

```
WP_Image::delete_all_attachment('18', true);
```

Tests
-----

[](#tests)

To run [tests](tests) you just need [composer](http://getcomposer.org/download/) and to execute the following:

```
git clone https://github.com/josantonius/wp-image-handler.git

cd WP_Image

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

composer install

```

Run unit tests with [PHPUnit](https://phpunit.de/):

```
composer phpunit

```

Run [WordPress](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/) code standard tests with [PHPCS](https://github.com/squizlabs/PHP_CodeSniffer):

```
composer phpcs

```

Run [PHP Mess Detector](https://phpmd.org/) tests to detect inconsistencies in code style:

```
composer phpmd

```

Run all previous tests:

```
composer tests

```

Sponsor
-------

[](#sponsor)

If this project helps you to reduce your development time, [you can sponsor me](https://github.com/josantonius#sponsor) to support my open source work 😊

License
-------

[](#license)

This repository is licensed under the [MIT License](LICENSE).

Copyright © 2017-2022, [Josantonius](https://github.com/josantonius#contact)

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~60 days

Total

4

Last Release

3035d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4b221283501ec8a9cbaefaf27821a91ae8ddd33bddf1fccc6c6815b7ad216ff1?d=identicon)[Josantonius](/maintainers/Josantonius)

---

Top Contributors

[![josantonius](https://avatars.githubusercontent.com/u/18104336?v=4)](https://github.com/josantonius "josantonius (22 commits)")

---

Tags

composerphpwordpresswordpress-imageswp-libraryphpwordpressimagehhvmattachment

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/josantonius-wp-image-handler/health.svg)

```
[![Health](https://phpackages.com/badges/josantonius-wp-image-handler/health.svg)](https://phpackages.com/packages/josantonius-wp-image-handler)
```

###  Alternatives

[toinekamps/responsive-pics

Responsive Pics is a Wordpress tool for resizing images on the fly.

831.2k](/packages/toinekamps-responsive-pics)[lciolecki/php-image-optimizer

PHP image file optimizer (uses https://github.com/bensquire/php-image-optim)

347.4k](/packages/lciolecki-php-image-optimizer)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
