Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load plugin only when EDD is active #30

Merged
merged 2 commits into from
Aug 1, 2024
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
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