Skip to content

Commit

Permalink
Merge pull request #45 from mcaskill/feature/publishpress-pro
Browse files Browse the repository at this point in the history
Add support for PublishPress Pro
  • Loading branch information
junaidbhura authored Jan 23, 2023
2 parents 441bdc5 + 182c695 commit 583ff37
Show file tree
Hide file tree
Showing 3 changed files with 183 additions and 4 deletions.
2 changes: 2 additions & 0 deletions Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@ protected function getDownloadUrl( PackageInterface $package ) {
default:
if ( 0 === strpos( $package_name, 'junaidbhura/gravityforms' ) ) {
$plugin = new Plugins\GravityForms( $package->getPrettyVersion(), str_replace( 'junaidbhura/', '', $package_name ) );
} elseif ( 0 === strpos( $package_name, 'junaidbhura/publishpress-' ) ) {
$plugin = new Plugins\PublishPressPro( $package->getPrettyVersion(), str_replace( 'junaidbhura/', '', $package_name ) );
} elseif ( 0 === strpos( $package_name, 'junaidbhura/wpai-' ) || 0 === strpos( $package_name, 'junaidbhura/wpae-' ) ) {
$plugin = new Plugins\WpAiPro( $package->getPrettyVersion(), str_replace( 'junaidbhura/', '', $package_name ) );
}
Expand Down
48 changes: 44 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ Sensitive credentials (license keys, tokens) are read from environment variables
## Supported Plugins

1. Advanced Custom Fields Pro
2. Advanced Custom Fields Extended Pro
3. Gravity Forms / Add-Ons
4. Polylang Pro
5. WP All Import / Export Pro / Add-Ons
1. Gravity Forms / Add-Ons
1. Polylang Pro
1. PublishPress Pro
1. Advanced Custom Fields Extended Pro
1. WP All Import / Export Pro / Add-Ons

## Overview

Expand Down Expand Up @@ -41,6 +42,10 @@ ACFE_PRO_URL="<registered_url_for_acf_extended_pro>"
GRAVITY_FORMS_KEY="<gravity_forms_license_key>"
POLYLANG_PRO_KEY="<polylang_pro_license_key>"
POLYLANG_PRO_URL="<registered_url_for_polylang_pro>"
PUBLISHPRESS_PRO_KEY="<publishpress_pro_membership_license_key>"
PUBLISHPRESS_PRO_URL="<registered_url_for_publishpress_pro_membership>"
PUBLISHPRESS_<plugin_slug>_PRO_KEY="<publishpress_pro_license_key>"
PUBLISHPRESS_<plugin_slug>_PRO_URL="<registered_url_for_publishpress_pro>"
WP_ALL_IMPORT_PRO_KEY="<wp_all_import_license_key>"
WP_ALL_IMPORT_PRO_URL="<registered_url_for_wpai_pro>"
WP_ALL_EXPORT_PRO_KEY="<wp_all_export_license_key>"
Expand Down Expand Up @@ -126,6 +131,21 @@ Add the following to your composer.json file:
}
}
},
{
"type": "package",
"package": {
"name": "junaidbhura/publishpress-planner-pro",
"version": "<version_number>",
"type": "wordpress-plugin",
"dist": {
"type": "zip",
"url": "https://publishpress.com/"
},
"require": {
"junaidbhura/composer-wp-pro-plugins": "*"
}
}
},
{
"type": "package",
"package": {
Expand Down Expand Up @@ -208,6 +228,7 @@ Add the following to your composer.json file:
"junaidbhura/gravityforms": "*",
"junaidbhura/gravityformspolls": "*",
"junaidbhura/polylang-pro": "*",
"junaidbhura/publishpress-planner-pro": "*",
"junaidbhura/wp-all-import-pro": "*",
"junaidbhura/wp-all-export-pro": "*",
"junaidbhura/wpai-acf-add-on": "*",
Expand All @@ -228,6 +249,25 @@ For example:

Here's a list of all Gravity Forms add-on slugs: [https://docs.gravityforms.com/gravity-forms-add-on-slugs/](https://docs.gravityforms.com/gravity-forms-add-on-slugs/)

### PublishPress Pro Plugins

You can use any PublishPress Pro plugins by simply adding it's slug like so:

`junaidbhura/<plugin-slug>`

The following plugins are supported:

| Package name | Environment variables |
|:------------------------------------------- |:-------------------------------------------- |
| `junaidbhura/publishpress-authors-pro` | `PUBLISHPRESS_AUTHORS_PRO_<key_or_url>` |
| `junaidbhura/publishpress-blocks-pro` | `PUBLISHPRESS_BLOCKS_PRO_<key_or_url>` |
| `junaidbhura/publishpress-capabilities-pro` | `PUBLISHPRESS_CAPABILITIES_PRO_<key_or_url>` |
| `junaidbhura/publishpress-checklists-pro` | `PUBLISHPRESS_CHECKLISTS_PRO_<key_or_url>` |
| `junaidbhura/publishpress-permissions-pro` | `PUBLISHPRESS_PERMISSIONS_PRO_<key_or_url>` |
| `junaidbhura/publishpress-planner-pro` | `PUBLISHPRESS_PLANNER_PRO_<key_or_url>` |
| `junaidbhura/publishpress-revisions-pro` | `PUBLISHPRESS_REVISIONS_PRO_<key_or_url>` |
| `junaidbhura/publishpress-series-pro` | `PUBLISHPRESS_SERIES_PRO_<key_or_url>` |

### WP All Import Pro Add-Ons

You can use any WP All Import Pro add-on by simply adding it's slug like so:
Expand Down
137 changes: 137 additions & 0 deletions plugins/PublishPressPro.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
<?php
/**
* PublishPress Pro Plugin.
*
* @package Junaidbhura\Composer\WPProPlugins\Plugins
*/

namespace Junaidbhura\Composer\WPProPlugins\Plugins;

use Composer\Semver\Semver;
use Junaidbhura\Composer\WPProPlugins\Http;

/**
* PublishPressPro class.
*/
class PublishPressPro {

/**
* The version number of the plugin to download.
*
* @var string Version number.
*/
protected $version = '';

/**
* The slug of which plugin to download.
*
* @var string Plugin slug.
*/
protected $slug = '';

/**
* WpAiPro constructor.
*
* @param string $version
* @param string $slug
*/
public function __construct( $version = '', $slug = 'publishpress-planner-pro' ) {
$this->version = $version;
$this->slug = $slug;
}

/**
* Get the download URL for this plugin.
*
* @return string
*/
public function getDownloadUrl() {
$id = 0;
$env = null;
/**
* Membership licensing.
*/
$license = ( getenv( 'PUBLISHPRESS_PRO_KEY' ) ?: null );
$url = ( getenv( 'PUBLISHPRESS_PRO_URL' ) ?: null );

/**
* List of official plugins as of 2023-01-20.
*/
switch ( $this->slug ) {
case 'publishpress-authors-pro':
$id = 7203;
$env = 'AUTHORS';
break;

case 'publishpress-blocks-pro':
$id = 98972;
$env = 'BLOCKS';
break;

case 'publishpress-capabilities-pro':
$id = 44811;
$env = 'CAPABILITIES';
break;

case 'publishpress-checklists-pro':
$id = 6465;
$env = 'CHECKLISTS';
break;

case 'publishpress-permissions-pro':
$id = 34506;
$env = 'PERMISSIONS';
break;

case 'publishpress-planner-pro':
$id = 49742;
$env = 'PLANNER';
break;

case 'publishpress-revisions-pro':
$id = 40280;
$env = 'REVISIONS';
break;

case 'publishpress-series-pro':
$id = 110550;
$env = 'SERIES';
break;

default:
return '';
}

if ( $env ) {
/**
* Use add-on licensing if available, otherwise use membership licensing.
*/
$license = ( getenv( "PUBLISHPRESS_{$env}_PRO_KEY" ) ?: $license );
$url = ( getenv( "PUBLISHPRESS_{$env}_PRO_URL" ) ?: $url );
}

$http = new Http();
$response = json_decode( $http->get( 'https://publishpress.com', array(
'edd_action' => 'get_version',
'license' => $license,
'item_id' => $id,
'url' => $url,
'version' => $this->version,
) ), true );

if ( empty( $response['download_link'] ) ) {
return '';
}

if ( empty( $response['new_version'] ) ) {
return '';
}

if ( ! Semver::satisfies( $response['new_version'], $this->version ) ) {
return '';
}

return $response['download_link'];
}

}

0 comments on commit 583ff37

Please sign in to comment.