Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Sections will require a `changelog` property with an html string of your changel
"author_profile": "https://surecart.com",
"version": "0.9.0",
"requires": "5.6",
"tested": "6.1.0",
"tested": "6.4.3",
"requires_php": "5.3",
"sections": {
"description": "This is my plugin description.",
Expand All @@ -64,6 +64,7 @@ Sections will require a `changelog` property with an html string of your changel
}
}
```
> **Note:** Icons and banners in `release.json` take priority over asset path images. If you prefer to serve them from your plugin's asset directory instead, omit the `icons` and `banners` keys from `release.json` and set the asset path using `$client->set_asset_path( $path )`.

### ⚠️ Important
In order for updates to work, the `slug` in release.json must match the **folder name** of your plugin or theme.
Expand Down Expand Up @@ -120,6 +121,23 @@ Make sure you call this function directly, never use any action hook to call thi
```php
$client = new \SureCart\Licensing\Client( 'Twenty Twelve', 'pt_jzieNYQdE5LMAxksscgU6H4', __FILE__ );
```
## Set asset path (optional)

If you want to serve plugin icons and banners from your asset directory instead of providing URLs in `release.json`, you can set the asset path. This is only used as a fallback when `icons` and `banners` are not present in `release.json`.

```php
$client->set_asset_path( plugins_url( 'assets', __FILE__ ) );
```

Expected file structure in your asset directory:
```
assets/
├── icon-128x128.png
├── icon-256x256.png
├── icon.svg
├── banner-772x250.png
└── banner-1544x500.png
```

## Set textdomain

Expand Down
20 changes: 20 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ class Client {
*/
public $textdomain;

/**
* Asset Path
*
* @var string
*/
public $asset_path;

/**
* The Object of Updater Class
*
Expand Down Expand Up @@ -341,5 +348,18 @@ public function __( $text ) {
*/
public function set_textdomain( $textdomain ) {
$this->textdomain = $textdomain;

return $this;
}

/**
* Set project asset path for images.
*
* @param string $asset_path The asset path for images.
*/
public function set_asset_path( $asset_path ) {
$this->asset_path = $asset_path;

return $this;
}
}
33 changes: 33 additions & 0 deletions src/Updater.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace SureCart\Licensing;

/**
Expand Down Expand Up @@ -165,6 +166,17 @@ private function get_project_latest_version() {
$release->icons = (array) $release->icons;
}

// If there is asset path, then try to find the images from the asset path.
if ( ! empty( $this->client->asset_path ) ) {
if ( empty( $release->banners ) ) {
$release->banners = $this->findImagesFromAssetPath( 'banner' );
}

if ( empty( $release->icons ) ) {
$release->icons = $this->findImagesFromAssetPath( 'icon' );
}
}

if ( isset( $release->sections ) ) {
$release->sections = (array) $release->sections;
}
Expand Down Expand Up @@ -253,4 +265,25 @@ private function get_version_info() {

return $version_info;
}

/**
* Find images from the asset path.
*
* @param string $prefix The prefix of the image, eg: banner or icon.
* @return array The images.
*/
public function findImagesFromAssetPath( $prefix ) {
$images = array();

if ( 'icon' === $prefix ) {
$images['1x'] = esc_url_raw( $this->client->asset_path . '/icon-128x128.png' );
$images['2x'] = esc_url_raw( $this->client->asset_path . '/icon-256x256.png' );
$images['svg'] = esc_url_raw( $this->client->asset_path . '/icon.svg' );
} elseif ( 'banner' === $prefix ) {
$images['low'] = esc_url_raw( $this->client->asset_path . '/banner-772x250.png' );
$images['high'] = esc_url_raw( $this->client->asset_path . '/banner-1544x500.png' );
}

return $images;
}
}
Loading