From dfd29dc9dcec4d814bf19ff9365246b77016908f Mon Sep 17 00:00:00 2001 From: Chauncey McAskill Date: Wed, 18 Jan 2023 12:29:56 -0500 Subject: [PATCH 1/3] Add support for PublishPress Pro --- Installer.php | 2 + README.md | 146 +++++++++++++++++++++++++++++++++++- plugins/PublishPressPro.php | 77 +++++++++++++++++++ 3 files changed, 224 insertions(+), 1 deletion(-) create mode 100644 plugins/PublishPressPro.php diff --git a/Installer.php b/Installer.php index 364de18..c19a781 100644 --- a/Installer.php +++ b/Installer.php @@ -256,6 +256,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 ) ); } diff --git a/README.md b/README.md index 200088e..651344d 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,8 @@ Sensitive credentials (license keys, tokens) are read from environment variables 1. Advanced Custom Fields Pro 2. Gravity Forms / Add-Ons 3. Polylang Pro -4. WP All Import / Export Pro / Add-Ons +4. PublishPress Pro +5. WP All Import / Export Pro / Add-Ons ## Overview @@ -38,6 +39,8 @@ ACF_PRO_KEY="" GRAVITY_FORMS_KEY="" POLYLANG_PRO_KEY="" POLYLANG_PRO_URL="" +PUBLISHPRESS_PRO_KEY="" +PUBLISHPRESS_PRO_URL="" WP_ALL_IMPORT_PRO_KEY="" WP_ALL_IMPORT_PRO_URL="" WP_ALL_EXPORT_PRO_KEY="" @@ -108,6 +111,126 @@ Add the following to your composer.json file: } } }, + { + "type": "package", + "package": { + "name": "junaidbhura/publishpress-authors-pro", + "version": "", + "type": "wordpress-plugin", + "dist": { + "type": "zip", + "url": "https://publishpress.com/" + }, + "require": { + "junaidbhura/composer-wp-pro-plugins": "*" + } + } + }, + { + "type": "package", + "package": { + "name": "junaidbhura/publishpress-blocks-pro", + "version": "", + "type": "wordpress-plugin", + "dist": { + "type": "zip", + "url": "https://publishpress.com/" + }, + "require": { + "junaidbhura/composer-wp-pro-plugins": "*" + } + } + }, + { + "type": "package", + "package": { + "name": "junaidbhura/publishpress-capabilities-pro", + "version": "", + "type": "wordpress-plugin", + "dist": { + "type": "zip", + "url": "https://publishpress.com/" + }, + "require": { + "junaidbhura/composer-wp-pro-plugins": "*" + } + } + }, + { + "type": "package", + "package": { + "name": "junaidbhura/publishpress-checklists-pro", + "version": "", + "type": "wordpress-plugin", + "dist": { + "type": "zip", + "url": "https://publishpress.com/" + }, + "require": { + "junaidbhura/composer-wp-pro-plugins": "*" + } + } + }, + { + "type": "package", + "package": { + "name": "junaidbhura/publishpress-permissions-pro", + "version": "", + "type": "wordpress-plugin", + "dist": { + "type": "zip", + "url": "https://publishpress.com/" + }, + "require": { + "junaidbhura/composer-wp-pro-plugins": "*" + } + } + }, + { + "type": "package", + "package": { + "name": "junaidbhura/publishpress-planner-pro", + "version": "", + "type": "wordpress-plugin", + "dist": { + "type": "zip", + "url": "https://publishpress.com/" + }, + "require": { + "junaidbhura/composer-wp-pro-plugins": "*" + } + } + }, + { + "type": "package", + "package": { + "name": "junaidbhura/publishpress-revisions-pro", + "version": "", + "type": "wordpress-plugin", + "dist": { + "type": "zip", + "url": "https://publishpress.com/" + }, + "require": { + "junaidbhura/composer-wp-pro-plugins": "*" + } + } + }, + { + "type": "package", + "package": { + "name": "junaidbhura/publishpress-series-pro", + "version": "", + "type": "wordpress-plugin", + "dist": { + "type": "zip", + "url": "https://publishpress.com/" + }, + "require": { + "junaidbhura/composer-wp-pro-plugins": "*" + } + } + }, { "type": "package", "package": { @@ -189,6 +312,14 @@ Add the following to your composer.json file: "junaidbhura/gravityforms": "*", "junaidbhura/gravityformspolls": "*", "junaidbhura/polylang-pro": "*", + "junaidbhura/publishpress-authors-pro": "*", + "junaidbhura/publishpress-blocks-pro": "*", + "junaidbhura/publishpress-capabilities-pro": "*", + "junaidbhura/publishpress-checklists-pro": "*", + "junaidbhura/publishpress-permissions-pro": "*", + "junaidbhura/publishpress-planner-pro": "*", + "junaidbhura/publishpress-revisions-pro": "*", + "junaidbhura/publishpress-series-pro": "*", "junaidbhura/wp-all-import-pro": "*", "junaidbhura/wp-all-export-pro": "*", "junaidbhura/wpai-acf-add-on": "*", @@ -209,6 +340,19 @@ 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 + +The following PublishPress Pro plugins are supported: + +* `junaidbhura/publishpress-authors-pro` +* `junaidbhura/publishpress-blocks-pro` +* `junaidbhura/publishpress-capabilities-pro` +* `junaidbhura/publishpress-checklists-pro` +* `junaidbhura/publishpress-permissions-pro` +* `junaidbhura/publishpress-planner-pro` +* `junaidbhura/publishpress-revisions-pro` +* `junaidbhura/publishpress-series-pro` + ### WP All Import Pro Add-Ons You can use any WP All Import Pro add-on by simply adding it's slug like so: diff --git a/plugins/PublishPressPro.php b/plugins/PublishPressPro.php new file mode 100644 index 0000000..277653b --- /dev/null +++ b/plugins/PublishPressPro.php @@ -0,0 +1,77 @@ +version = $version; + $this->slug = $slug; + } + + /** + * Get the download URL for this plugin. + * + * @return string + */ + public function getDownloadUrl() { + $packages = array( + 'publishpress-authors-pro' => 7203, + 'publishpress-blocks-pro' => 98972, + 'publishpress-capabilities-pro' => 44811, + 'publishpress-checklists-pro' => 6465, + 'publishpress-permissions-pro' => 34506, + 'publishpress-planner-pro' => 49742, + 'publishpress-revisions-pro' => 40280, + 'publishpress-series-pro' => 110550, + ); + + if ( array_key_exists( $this->slug, $packages ) ) { + $http = new Http(); + $response = json_decode( $http->get( 'https://publishpress.com', array( + 'edd_action' => 'get_version', + 'license' => getenv( 'PUBLISHPRESS_PRO_KEY' ), + 'item_id' => $packages[ $this->slug ], + 'url' => getenv( 'PUBLISHPRESS_PRO_URL' ), + 'version' => $this->version, + ) ), true ); + + if ( ! empty( $response['download_link'] ) ) { + return $response['download_link']; + } + } + + return ''; + } + +} From f736b906f4cf4210e42bc8855142561e4fe54011 Mon Sep 17 00:00:00 2001 From: Chauncey McAskill Date: Fri, 20 Jan 2023 13:12:40 -0500 Subject: [PATCH 2/3] Improve PublishPress Pro integration Changed: - Added support for per-plugin licensing. - Added support for bailing on version mismatch. - Reduced list of plugins featured in 'composer.json'. - Changed list of plugins into table. --- README.md | 142 +++++------------------------------- plugins/PublishPressPro.php | 107 +++++++++++++++++++++------ 2 files changed, 102 insertions(+), 147 deletions(-) diff --git a/README.md b/README.md index 651344d..251c6c6 100644 --- a/README.md +++ b/README.md @@ -39,8 +39,10 @@ ACF_PRO_KEY="" GRAVITY_FORMS_KEY="" POLYLANG_PRO_KEY="" POLYLANG_PRO_URL="" -PUBLISHPRESS_PRO_KEY="" -PUBLISHPRESS_PRO_URL="" +PUBLISHPRESS_PRO_KEY="" +PUBLISHPRESS_PRO_URL="" +PUBLISHPRESS__PRO_KEY="" +PUBLISHPRESS__PRO_URL="" WP_ALL_IMPORT_PRO_KEY="" WP_ALL_IMPORT_PRO_URL="" WP_ALL_EXPORT_PRO_KEY="" @@ -111,81 +113,6 @@ Add the following to your composer.json file: } } }, - { - "type": "package", - "package": { - "name": "junaidbhura/publishpress-authors-pro", - "version": "", - "type": "wordpress-plugin", - "dist": { - "type": "zip", - "url": "https://publishpress.com/" - }, - "require": { - "junaidbhura/composer-wp-pro-plugins": "*" - } - } - }, - { - "type": "package", - "package": { - "name": "junaidbhura/publishpress-blocks-pro", - "version": "", - "type": "wordpress-plugin", - "dist": { - "type": "zip", - "url": "https://publishpress.com/" - }, - "require": { - "junaidbhura/composer-wp-pro-plugins": "*" - } - } - }, - { - "type": "package", - "package": { - "name": "junaidbhura/publishpress-capabilities-pro", - "version": "", - "type": "wordpress-plugin", - "dist": { - "type": "zip", - "url": "https://publishpress.com/" - }, - "require": { - "junaidbhura/composer-wp-pro-plugins": "*" - } - } - }, - { - "type": "package", - "package": { - "name": "junaidbhura/publishpress-checklists-pro", - "version": "", - "type": "wordpress-plugin", - "dist": { - "type": "zip", - "url": "https://publishpress.com/" - }, - "require": { - "junaidbhura/composer-wp-pro-plugins": "*" - } - } - }, - { - "type": "package", - "package": { - "name": "junaidbhura/publishpress-permissions-pro", - "version": "", - "type": "wordpress-plugin", - "dist": { - "type": "zip", - "url": "https://publishpress.com/" - }, - "require": { - "junaidbhura/composer-wp-pro-plugins": "*" - } - } - }, { "type": "package", "package": { @@ -201,36 +128,6 @@ Add the following to your composer.json file: } } }, - { - "type": "package", - "package": { - "name": "junaidbhura/publishpress-revisions-pro", - "version": "", - "type": "wordpress-plugin", - "dist": { - "type": "zip", - "url": "https://publishpress.com/" - }, - "require": { - "junaidbhura/composer-wp-pro-plugins": "*" - } - } - }, - { - "type": "package", - "package": { - "name": "junaidbhura/publishpress-series-pro", - "version": "", - "type": "wordpress-plugin", - "dist": { - "type": "zip", - "url": "https://publishpress.com/" - }, - "require": { - "junaidbhura/composer-wp-pro-plugins": "*" - } - } - }, { "type": "package", "package": { @@ -312,14 +209,7 @@ Add the following to your composer.json file: "junaidbhura/gravityforms": "*", "junaidbhura/gravityformspolls": "*", "junaidbhura/polylang-pro": "*", - "junaidbhura/publishpress-authors-pro": "*", - "junaidbhura/publishpress-blocks-pro": "*", - "junaidbhura/publishpress-capabilities-pro": "*", - "junaidbhura/publishpress-checklists-pro": "*", - "junaidbhura/publishpress-permissions-pro": "*", "junaidbhura/publishpress-planner-pro": "*", - "junaidbhura/publishpress-revisions-pro": "*", - "junaidbhura/publishpress-series-pro": "*", "junaidbhura/wp-all-import-pro": "*", "junaidbhura/wp-all-export-pro": "*", "junaidbhura/wpai-acf-add-on": "*", @@ -342,16 +232,22 @@ Here's a list of all Gravity Forms add-on slugs: [https://docs.gravityforms.com/ ### PublishPress Pro Plugins -The following PublishPress Pro plugins are supported: +You can use any PublishPress Pro plugins by simply adding it's slug like so: + +`junaidbhura/` -* `junaidbhura/publishpress-authors-pro` -* `junaidbhura/publishpress-blocks-pro` -* `junaidbhura/publishpress-capabilities-pro` -* `junaidbhura/publishpress-checklists-pro` -* `junaidbhura/publishpress-permissions-pro` -* `junaidbhura/publishpress-planner-pro` -* `junaidbhura/publishpress-revisions-pro` -* `junaidbhura/publishpress-series-pro` +The following plugins are supported: + +| Package name | Environment variables | +|:------------------------------------------- |:-------------------------------------------- | +| `junaidbhura/publishpress-authors-pro` | `PUBLISHPRESS_AUTHORS_PRO_` | +| `junaidbhura/publishpress-blocks-pro` | `PUBLISHPRESS_BLOCKS_PRO_` | +| `junaidbhura/publishpress-capabilities-pro` | `PUBLISHPRESS_CAPABILITIES_PRO_` | +| `junaidbhura/publishpress-checklists-pro` | `PUBLISHPRESS_CHECKLISTS_PRO_` | +| `junaidbhura/publishpress-permissions-pro` | `PUBLISHPRESS_PERMISSIONS_PRO_` | +| `junaidbhura/publishpress-planner-pro` | `PUBLISHPRESS_PLANNER_PRO_` | +| `junaidbhura/publishpress-revisions-pro` | `PUBLISHPRESS_REVISIONS_PRO_` | +| `junaidbhura/publishpress-series-pro` | `PUBLISHPRESS_SERIES_PRO_` | ### WP All Import Pro Add-Ons diff --git a/plugins/PublishPressPro.php b/plugins/PublishPressPro.php index 277653b..1ec5889 100644 --- a/plugins/PublishPressPro.php +++ b/plugins/PublishPressPro.php @@ -45,30 +45,89 @@ public function __construct( $version = '', $slug = 'publishpress-planner-pro' ) * @return string */ public function getDownloadUrl() { - $packages = array( - 'publishpress-authors-pro' => 7203, - 'publishpress-blocks-pro' => 98972, - 'publishpress-capabilities-pro' => 44811, - 'publishpress-checklists-pro' => 6465, - 'publishpress-permissions-pro' => 34506, - 'publishpress-planner-pro' => 49742, - 'publishpress-revisions-pro' => 40280, - 'publishpress-series-pro' => 110550, - ); - - if ( array_key_exists( $this->slug, $packages ) ) { - $http = new Http(); - $response = json_decode( $http->get( 'https://publishpress.com', array( - 'edd_action' => 'get_version', - 'license' => getenv( 'PUBLISHPRESS_PRO_KEY' ), - 'item_id' => $packages[ $this->slug ], - 'url' => getenv( 'PUBLISHPRESS_PRO_URL' ), - 'version' => $this->version, - ) ), true ); - - if ( ! empty( $response['download_link'] ) ) { - return $response['download_link']; - } + $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 the response does not have a version number or the version number + * does not match the package constraint, bail. + */ + if ( empty( $response['new_version'] ) || $response['new_version'] !== $this->version ) { + return ''; + } + + if ( ! empty( $response['download_link'] ) ) { + return $response['download_link']; } return ''; From 366c175bb622fffe58a9eabbf6197c7603b440c4 Mon Sep 17 00:00:00 2001 From: Chauncey McAskill Date: Fri, 20 Jan 2023 14:23:52 -0500 Subject: [PATCH 3/3] Use Semver to check PublishPress Pro version --- plugins/PublishPressPro.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/plugins/PublishPressPro.php b/plugins/PublishPressPro.php index 1ec5889..827f855 100644 --- a/plugins/PublishPressPro.php +++ b/plugins/PublishPressPro.php @@ -7,6 +7,7 @@ namespace Junaidbhura\Composer\WPProPlugins\Plugins; +use Composer\Semver\Semver; use Junaidbhura\Composer\WPProPlugins\Http; /** @@ -118,19 +119,19 @@ public function getDownloadUrl() { 'version' => $this->version, ) ), true ); - /** - * If the response does not have a version number or the version number - * does not match the package constraint, bail. - */ - if ( empty( $response['new_version'] ) || $response['new_version'] !== $this->version ) { + if ( empty( $response['download_link'] ) ) { + return ''; + } + + if ( empty( $response['new_version'] ) ) { return ''; } - if ( ! empty( $response['download_link'] ) ) { - return $response['download_link']; + if ( ! Semver::satisfies( $response['new_version'], $this->version ) ) { + return ''; } - return ''; + return $response['download_link']; } }