Skip to content

Commit

Permalink
Merge pull request #30 from brainstormforce/handle-edd-active-condition
Browse files Browse the repository at this point in the history
Load plugin only when EDD is active
  • Loading branch information
patilvikasj authored Aug 1, 2024
2 parents 8e43015 + 1765fe7 commit 0c18366
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 12 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
**Donate link:** https://www.paypal.me/BrainstormForce
**Tags:** edd, payment, redirect
**Requires at least:** 4.4
**Tested up to:** 6.2
**Stable tag:** 1.0.4
**Tested up to:** 6.6
**Stable tag:** 1.0.5
**License:** GPLv2 or later
**License URI:** http://www.gnu.org/licenses/gpl-2.0.html

Expand All @@ -27,6 +27,9 @@ e.g.

## Changelog ##

## 1.0.5 ###
- Fix: Fatal error on front end when Easy digital downloads plugin is not active.

### 1.0.4 ###
- Improvement: Added compatibility to WordPress 6.1

Expand Down
37 changes: 30 additions & 7 deletions class-edd-simple-after-payment-redirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* Author URI: https://pratikchaskar.com/
* Text Domain: edd-simple-after-payment-redirect
* Domain Path: /languages
* Version: 1.0.4
* Version: 1.0.5
*
* PHP version 7
*
Expand Down Expand Up @@ -69,12 +69,35 @@ public static function instance() {
* @return void
*/
private function __construct() {
add_action( 'edd_complete_purchase', array( $this, 'process_standard_payment' ) );
add_filter( 'edd_payment_confirm_paypal', array( $this, 'process_paypal_standard' ) );
add_action( 'template_redirect', array( $this, 'process_offsite_payment' ) );
add_action( 'edd_meta_box_fields', array( $this, 'edd_external_product_render_field' ), 90 );
add_filter( 'edd_metabox_fields_save', array( $this, 'edd_external_product_save' ) );
add_filter( 'edd_metabox_save__edd_after_payment_redirect', array( $this, 'edd_external_product_metabox_save' ) );
add_action( 'plugins_loaded', array( $this, 'maybe_load_plugin' ), 9999, 0 );
}

/**
* Load plugin only when EDD is active.
*
* @return void
*/
public function maybe_load_plugin() {
if ( ! class_exists( 'Easy_Digital_Downloads' ) ) {
add_action(
'admin_notices',
function() {
?>
<div class="notice notice-error is-dismissible">
<p><?php esc_html_e( 'EDD Redirect after payment requires Easy Digital Downloads to be installed and activated.', 'edd-simple-after-payment-redirect' ); ?></p>
</div>
<?php
}
);
} else {

add_action( 'edd_complete_purchase', array( $this, 'process_standard_payment' ) );
add_filter( 'edd_payment_confirm_paypal', array( $this, 'process_paypal_standard' ) );
add_action( 'template_redirect', array( $this, 'process_offsite_payment' ) );
add_action( 'edd_meta_box_fields', array( $this, 'edd_external_product_render_field' ), 90 );
add_filter( 'edd_metabox_fields_save', array( $this, 'edd_external_product_save' ) );
add_filter( 'edd_metabox_save__edd_after_payment_redirect', array( $this, 'edd_external_product_metabox_save' ) );
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "edd-simple-after-payment-redirect",
"version": "1.0.4",
"version": "1.0.5",
"main": "Gruntfile.js",
"author": "Brainstorm Force",
"devDependencies": {
Expand Down
7 changes: 5 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ Contributors: pratikchaskar
Donate link: https://www.paypal.me/BrainstormForce
Tags: edd, payment, redirect
Requires at least: 4.4
Tested up to: 6.2
Stable tag: 1.0.4
Tested up to: 6.6
Stable tag: 1.0.5
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand All @@ -27,6 +27,9 @@ e.g.

== Changelog ==

= 1.0.5 =
- Fix: Fatal error on front end when Easy digital downloads plugin is not active.

= 1.0.4 =
- Improvement: Added compatibility to WordPress 6.1

Expand Down

0 comments on commit 0c18366

Please sign in to comment.