From c22175d34f244ef2925c799a98ebcaac0d39e560 Mon Sep 17 00:00:00 2001 From: Chauncey McAskill Date: Wed, 18 Jan 2023 17:24:28 -0500 Subject: [PATCH 1/3] Add support for Ninja Forms Add-Ons --- Installer.php | 2 + README.md | 35 +++- plugins/NinjaForms.php | 358 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 393 insertions(+), 2 deletions(-) create mode 100644 plugins/NinjaForms.php diff --git a/Installer.php b/Installer.php index 364de18..ef82fb3 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/ninja-forms-' ) ) { + $plugin = new Plugins\NinjaForms( $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..cc5e6fc 100644 --- a/README.md +++ b/README.md @@ -8,8 +8,9 @@ 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 +3. Ninja Forms Add-Ons +4. Polylang Pro +5. WP All Import / Export Pro / Add-Ons ## Overview @@ -36,6 +37,10 @@ Create a `.env` file in the root of your WordPress site, where the `composer.jso ``` ACF_PRO_KEY="" GRAVITY_FORMS_KEY="" +NINJA_FORMS_KEY="" +NINJA_FORMS_URL="" +NINJA_FORMS__KEY="" +NINJA_FORMS__URL="" POLYLANG_PRO_KEY="" POLYLANG_PRO_URL="" WP_ALL_IMPORT_PRO_KEY="" @@ -93,6 +98,21 @@ Add the following to your composer.json file: } } }, + { + "type": "package", + "package": { + "name": "junaidbhura/ninja-forms-uploads", + "version": "", + "type": "wordpress-plugin", + "dist": { + "type": "zip", + "url": "https://ninjaforms.com/" + }, + "require": { + "junaidbhura/composer-wp-pro-plugins": "*" + } + } + }, { "type": "package", "package": { @@ -188,6 +208,7 @@ Add the following to your composer.json file: "junaidbhura/advanced-custom-fields-pro": "*", "junaidbhura/gravityforms": "*", "junaidbhura/gravityformspolls": "*", + "junaidbhura/ninja-forms-uploads": "*", "junaidbhura/polylang-pro": "*", "junaidbhura/wp-all-import-pro": "*", "junaidbhura/wp-all-export-pro": "*", @@ -209,6 +230,16 @@ 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/) +### Ninja Forms Add-Ons + +You can use any Ninja Forms add-on by simply adding it's slug like so: + +`junaidbhura/ninja-forms-` + +For example: + +`junaidbhura/ninja-forms-uploads` + ### 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/NinjaForms.php b/plugins/NinjaForms.php new file mode 100644 index 0000000..3986d40 --- /dev/null +++ b/plugins/NinjaForms.php @@ -0,0 +1,358 @@ +version = $version; + $this->slug = $slug; + } + + /** + * Get the download URL for this plugin. + * + * @return string + */ + public function getDownloadUrl() { + $name = ''; + $env = null; + /** + * Membership licensing. + */ + $license = ( getenv( 'NINJA_FORMS_KEY' ) ?: null ); + $url = ( getenv( 'NINJA_FORMS_URL' ) ?: null ); + + /** + * List of official add-ons as of 2023-01-20. + * + * Packages are named according to their extension page slug or brand name + * rather than their WordPress plugin directory name which often is misspelled + * or changes between versions of Ninja Forms. + * + * If the installed package must match it's official plugin basename, + * use composer/installers {@link https://github.com/composer/installers#custom-install-names custom install name} + * `installer-name`. + */ + switch ( $this->slug ) { + case 'ninja-forms-activecampaign': + // NF plugin basename: ninja-forms-active-campaign + $name = 'ActiveCampaign'; + $env = 'ACTIVECAMPAIGN'; + break; + + case 'ninja-forms-advanced-datepicker': + // NF plugin basename: ninja-forms-advanced-datepicker + $name = 'Advanced Datepicker'; + $env = 'ADVANCED_DATEPICKER'; + break; + + case 'ninja-forms-authorize-net': + // NF plugin basename: ninja-forms-authorize-net + $name = 'Authorize.net'; + $env = 'AUTHORIZE_NET'; + break; + + case 'ninja-forms-aweber': + // NF plugin basename: ninja-forms-aweber + $name = 'AWeber'; + $env = 'AWEBER'; + break; + + case 'ninja-forms-campaign-monitor': + // NF plugin basename: ninja-forms-campaign-monitor + $name = 'Campaign Monitor'; + $env = 'CAMPAIGN_MONITOR'; + break; + + case 'ninja-forms-capsule-crm': + // NF plugin basename: ninja-forms-capsule-crm + $name = 'Capsule CRM'; + $env = 'CAPSULE_CRM'; + break; + + case 'ninja-forms-civicrm': + // NF plugin basename: ninja-forms-civicrm + $name = 'CiviCRM'; + $env = 'CIVICRM'; + break; + + case 'ninja-forms-cleverreach': + // NF plugin basename: ninja-forms-cleverreach + $name = 'CleverReach'; + $env = 'CLEVERREACH'; + break; + + case 'ninja-forms-clicksend': + // NF plugin basename: ninja-forms-clicksend + $name = 'ClickSend SMS'; + $env = 'CLICKSEND'; + break; + + case 'ninja-forms-conditional-logic': + // NF plugin basename: ninja-forms-conditionals, ninja-forms-conditional-logic + $name = 'Conditional Logic'; + $env = 'CONDITIONAL_LOGIC'; + break; + + case 'ninja-forms-constant-contact': + // NF plugin basename: ninja-forms-constant-contact + $name = 'Constant Contact'; + $env = 'CONSTANT_CONTACT'; + break; + + case 'ninja-forms-convertkit': + // NF plugin basename: ninja-forms-convertkit + $name = 'ConvertKit'; + $env = 'CONVERTKIT'; + break; + + case 'ninja-forms-elavon': + // NF plugin basename: ninja-forms-elavon-payment-gateway + $name = 'Elavon'; + $env = 'ELAVON'; + break; + + case 'ninja-forms-emailoctopus': + // NF plugin basename: ninja-forms-emailoctopus + $name = 'EmailOctopus'; + $env = 'EMAILOCTOPUS'; + break; + + case 'ninja-forms-emma': + // NF plugin basename: ninja-forms-emma + $name = 'Emma'; + $env = 'EMMA'; + break; + + case 'ninja-forms-excel-export': + // NF plugin basename: ninja-forms-excel-export + $name = 'Excel Export'; + $env = 'EXCEL_EXPORT'; + break; + + case 'ninja-forms-help-scout': + // NF plugin basename: ninja-forms-helpscout + $name = 'Help Scout'; + $env = 'HELP_SCOUT'; + break; + + case 'ninja-forms-hubspot': + // NF plugin basename: ninja-forms-hubspot + $name = 'HubSpot'; + $env = 'HUBSPOT'; + break; + + case 'ninja-forms-insightly': + // NF plugin basename: ninja-forms-insightly-crm + $name = 'Insightly CRM'; + $env = 'INSIGHTLY'; + break; + + case 'ninja-forms-layout-styles': + // NF plugin basename: ninja-forms-style, ninja-forms-layout-styles + $name = 'Layout and Styles'; + $env = 'LAYOUT_STYLES'; + break; + + case 'ninja-forms-mailchimp': + // NF plugin basename: ninja-forms-mail-chimp, ninja-forms-mailchimp + $name = 'Mailchimp'; + $env = 'MAILCHIMP'; + break; + + case 'ninja-forms-mailpoet': + // NF plugin basename: ninja-forms-mailpoet + // Formerly Wysija + $name = 'MailPoet'; + $env = 'MAILPOET'; + break; + + case 'ninja-forms-multi-step': + // NF plugin basename: ninja-forms-multi-part + $name = 'Multi Step Forms'; + $env = 'MULTI_STEP'; + break; + + case 'ninja-forms-onepagecrm': + // NF plugin basename: ninja-forms-onepage-crm, ninja-forms-onepagecrm + $name = 'OnePageCRM'; + $env = 'ONEPAGECRM'; + break; + + case 'ninja-forms-paypal-express': + // NF plugin basename: ninja-forms-paypal-express + $name = 'PayPal Express'; + $env = 'PAYPAL_EXPRESS'; + break; + + case 'ninja-forms-pdf-submissions': + // NF plugin basename: ninja-forms-pdf-submissions + $name = 'PDF Form Submission'; + $env = 'PDF_SUBMISSIONS'; + break; + + case 'ninja-forms-pipeline-crm': + // NF plugin basename: ninja-forms-pipeline-deals-crm + // Formerly PipelineDeals + $name = 'Pipeline CRM'; + $env = 'PIPELINE_CRM'; + break; + + case 'ninja-forms-post-creation': + // NF plugin basename: ninja-forms-post-creation + $name = 'Front-End Posting'; + $env = 'POST_CREATION'; + break; + + case 'ninja-forms-recurly': + // NF plugin basename: ninja-forms-recurly + $name = 'Recurly'; + $env = 'RECURLY'; + break; + + case 'ninja-forms-salesforce': + // NF plugin basename: ninja-forms-salesforce-crm + $name = 'Salesforce CRM'; + $env = 'SALESFORCE'; + break; + + case 'ninja-forms-save-progress': + // NF plugin basename: ninja-forms-save-progress + $name = 'Save Progress'; + $env = 'SAVE_PROGRESS'; + break; + + case 'ninja-forms-scheduled-exports': + // NF plugin basename: ninja-forms-scheduled-exports + $name = 'Scheduled Submissions Export'; + $env = 'SCHEDULED_EXPORTS'; + break; + + case 'ninja-forms-slack': + // NF plugin basename: ninja-forms-slack + $name = 'Slack'; + $env = 'SLACK'; + break; + + case 'ninja-forms-stripe': + // NF plugin basename: ninja-forms-stripe + $name = 'Stripe'; + $env = 'STRIPE'; + break; + + case 'ninja-forms-trello': + // NF plugin basename: ninja-forms-trello + $name = 'Trello'; + $env = 'TRELLO'; + break; + + case 'ninja-forms-twilio': + // NF plugin basename: ninja-forms-twilio + $name = 'Twilio SMS'; + $env = 'TWILIO'; + break; + + case 'ninja-forms-uploads': + // NF plugin basename: ninja-forms-uploads + $name = 'File Uploads'; + $env = 'UPLOADS'; + break; + + case 'ninja-forms-user-analytics': + // NF plugin basename: ninja-forms-user-analytics + $name = 'User Analytics'; + $env = 'USER_ANALYTICS'; + break; + + case 'ninja-forms-user-management': + // NF plugin basename: ninja-forms-user-management + $name = 'User Management'; + $env = 'USER_MANAGEMENT'; + break; + + case 'ninja-forms-webhooks': + // NF plugin basename: ninja-forms-webhooks + $name = 'Webhooks'; + $env = 'WEBHOOKS'; + break; + + case 'ninja-forms-zapier': + // NF plugin basename: ninja-forms-zapier + $name = 'Zapier'; + $env = 'ZAPIER'; + break; + + case 'ninja-forms-zoho': + // NF plugin basename: ninja-forms-zoho-crm + $name = 'Zoho CRM'; + $env = 'ZOHO'; + break; + + default: + return ''; + } + + if ( $env ) { + /** + * Use add-on licensing if available, otherwise use membership licensing. + */ + $license = ( getenv( "NINJA_FORMS_{$env}_KEY" ) ?: $license ); + $url = ( getenv( "NINJA_FORMS_{$env}_URL" ) ?: $url ); + } + + $http = new Http(); + $response = json_decode( $http->get( 'https://ninjaforms.com', array( + 'edd_action' => 'get_version', + 'license' => $license, + 'item_name' => $name, + '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 86a5ba93f681c1e47eb6540f0896891a0d5803cd Mon Sep 17 00:00:00 2001 From: Chauncey McAskill Date: Fri, 20 Jan 2023 12:55:58 -0500 Subject: [PATCH 2/3] Update Ninja Forms section in README Include list of supported add-ons by package name and corresponding environment variable. --- README.md | 49 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index cc5e6fc..51b639b 100644 --- a/README.md +++ b/README.md @@ -236,9 +236,52 @@ You can use any Ninja Forms add-on by simply adding it's slug like so: `junaidbhura/ninja-forms-` -For example: - -`junaidbhura/ninja-forms-uploads` +The following add-ons are supported: + +| Package name | Environment variables | +|:--------------------------------------------- |:---------------------------------------------- | +| `junaidbhura/ninja-forms-activecampaign` | `NINJA_FORMS_ACTIVECAMPAIGN_` | +| `junaidbhura/ninja-forms-advanced-datepicker` | `NINJA_FORMS_ADVANCED_DATEPICKER_` | +| `junaidbhura/ninja-forms-authorize-net` | `NINJA_FORMS_AUTHORIZE_NET_` | +| `junaidbhura/ninja-forms-aweber` | `NINJA_FORMS_AWEBER_` | +| `junaidbhura/ninja-forms-campaign-monitor` | `NINJA_FORMS_CAMPAIGN_MONITOR_` | +| `junaidbhura/ninja-forms-capsule-crm` | `NINJA_FORMS_CAPSULE_CRM_` | +| `junaidbhura/ninja-forms-civicrm` | `NINJA_FORMS_CIVICRM_` | +| `junaidbhura/ninja-forms-cleverreach` | `NINJA_FORMS_CLEVERREACH_` | +| `junaidbhura/ninja-forms-clicksend` | `NINJA_FORMS_CLICKSEND_` | +| `junaidbhura/ninja-forms-conditional-logic` | `NINJA_FORMS_CONDITIONAL_LOGIC_` | +| `junaidbhura/ninja-forms-constant-contact` | `NINJA_FORMS_CONSTANT_CONTACT_` | +| `junaidbhura/ninja-forms-convertkit` | `NINJA_FORMS_CONVERTKIT_` | +| `junaidbhura/ninja-forms-elavon` | `NINJA_FORMS_ELAVON_` | +| `junaidbhura/ninja-forms-emailoctopus` | `NINJA_FORMS_EMAILOCTOPUS_` | +| `junaidbhura/ninja-forms-emma` | `NINJA_FORMS_EMMA_` | +| `junaidbhura/ninja-forms-excel-export` | `NINJA_FORMS_EXCEL_EXPORT_` | +| `junaidbhura/ninja-forms-help-scout` | `NINJA_FORMS_HELP_SCOUT_` | +| `junaidbhura/ninja-forms-hubspot` | `NINJA_FORMS_HUBSPOT_` | +| `junaidbhura/ninja-forms-insightly` | `NINJA_FORMS_INSIGHTLY_` | +| `junaidbhura/ninja-forms-layout-styles` | `NINJA_FORMS_LAYOUT_STYLES_` | +| `junaidbhura/ninja-forms-mailchimp` | `NINJA_FORMS_MAILCHIMP_` | +| `junaidbhura/ninja-forms-mailpoet` | `NINJA_FORMS_MAILPOET_` | +| `junaidbhura/ninja-forms-multi-step` | `NINJA_FORMS_MULTI_STEP_` | +| `junaidbhura/ninja-forms-onepagecrm` | `NINJA_FORMS_ONEPAGECRM_` | +| `junaidbhura/ninja-forms-paypal-express` | `NINJA_FORMS_PAYPAL_EXPRESS_` | +| `junaidbhura/ninja-forms-pdf-submissions` | `NINJA_FORMS_PDF_SUBMISSIONS_` | +| `junaidbhura/ninja-forms-pipeline-crm` | `NINJA_FORMS_PIPELINE_CRM_` | +| `junaidbhura/ninja-forms-post-creation` | `NINJA_FORMS_POST_CREATION_` | +| `junaidbhura/ninja-forms-recurly` | `NINJA_FORMS_RECURLY_` | +| `junaidbhura/ninja-forms-salesforce` | `NINJA_FORMS_SALESFORCE_` | +| `junaidbhura/ninja-forms-save-progress` | `NINJA_FORMS_SAVE_PROGRESS_` | +| `junaidbhura/ninja-forms-scheduled-exports` | `NINJA_FORMS_SCHEDULED_EXPORTS_` | +| `junaidbhura/ninja-forms-slack` | `NINJA_FORMS_SLACK_` | +| `junaidbhura/ninja-forms-stripe` | `NINJA_FORMS_STRIPE_` | +| `junaidbhura/ninja-forms-trello` | `NINJA_FORMS_TRELLO_` | +| `junaidbhura/ninja-forms-twilio` | `NINJA_FORMS_TWILIO_` | +| `junaidbhura/ninja-forms-uploads` | `NINJA_FORMS_UPLOADS_` | +| `junaidbhura/ninja-forms-user-analytics` | `NINJA_FORMS_USER_ANALYTICS_` | +| `junaidbhura/ninja-forms-user-management` | `NINJA_FORMS_USER_MANAGEMENT_` | +| `junaidbhura/ninja-forms-webhooks` | `NINJA_FORMS_WEBHOOKS_` | +| `junaidbhura/ninja-forms-zapier` | `NINJA_FORMS_ZAPIER_` | +| `junaidbhura/ninja-forms-zoho` | `NINJA_FORMS_ZOHO_` | ### WP All Import Pro Add-Ons From 9ad2d4d458d5319250a8cbe8dbc4eb1c6cf8d73c Mon Sep 17 00:00:00 2001 From: Chauncey McAskill Date: Fri, 20 Jan 2023 14:23:31 -0500 Subject: [PATCH 3/3] Use Semver to check Ninja Forms add-on version --- plugins/NinjaForms.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/plugins/NinjaForms.php b/plugins/NinjaForms.php index 3986d40..86c29b0 100644 --- a/plugins/NinjaForms.php +++ b/plugins/NinjaForms.php @@ -7,6 +7,7 @@ namespace Junaidbhura\Composer\WPProPlugins\Plugins; +use Composer\Semver\Semver; use Junaidbhura\Composer\WPProPlugins\Http; /** @@ -340,19 +341,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']; } }