| 1 |
<?php |
| 2 |
/** |
| 3 |
* Activation handler for Charitable extensions. |
| 4 |
* |
| 5 |
* @package Charitable\Activation Handler |
| 6 |
* @since 1.0.0 |
| 7 |
*/ |
| 8 |
|
| 9 |
// Exit if accessed directly. |
| 10 |
if ( ! defined( 'ABSPATH' ) ) { |
| 11 |
exit; } |
| 12 |
|
| 13 |
/** |
| 14 |
* Charitable_Extension_Activation |
| 15 |
* |
| 16 |
* @since 1.0.0 |
| 17 |
*/ |
| 18 |
class Charitable_Extension_Activation { |
| 19 |
|
| 20 |
public $plugin_name, $plugin_path, $plugin_file, $has_charitable, $charitable_base; |
| 21 |
|
| 22 |
/** |
| 23 |
* Setup the activation class |
| 24 |
* |
| 25 |
* @param string $plugin_path Path to this plugin's directory. |
| 26 |
* @param string $plugin_file Core plugin file. |
| 27 |
* @return void |
| 28 |
* @access public |
| 29 |
* @since 1.0.0 |
| 30 |
*/ |
| 31 |
public function __construct( $plugin_path, $plugin_file ) { |
| 32 |
// We need plugin.php! |
| 33 |
require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); // @codingStandardsIgnoreLine |
| 34 |
|
| 35 |
$plugins = get_plugins(); |
| 36 |
|
| 37 |
// Set plugin directory. |
| 38 |
$plugin_path = array_filter( explode( '/', $plugin_path ) ); |
| 39 |
$this->plugin_path = end( $plugin_path ); |
| 40 |
|
| 41 |
// Set plugin file. |
| 42 |
$this->plugin_file = $plugin_file; |
| 43 |
|
| 44 |
// Set plugin name. |
| 45 |
if ( isset( $plugins[ $this->plugin_path . '/' . $this->plugin_file ]['Name'] ) ) { |
| 46 |
$this->plugin_name = str_replace( 'Charitable - ', '', $plugins[ $this->plugin_path . '/' . $this->plugin_file ]['Name'] ); |
| 47 |
} else { |
| 48 |
$this->plugin_name = __( 'This plugin', 'charitable' ); |
| 49 |
} |
| 50 |
|
| 51 |
// Is EDD installed? |
| 52 |
foreach ( $plugins as $plugin_path => $plugin ) { |
| 53 |
if ( $plugin['Name'] == 'Charitable' ) { |
| 54 |
$this->has_charitable = true; |
| 55 |
$this->charitable_base = $plugin_path; |
| 56 |
break; |
| 57 |
} |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
|
| 62 |
/** |
| 63 |
* Process plugin deactivation |
| 64 |
* |
| 65 |
* @return void |
| 66 |
* @access public |
| 67 |
* @since 1.0.0 |
| 68 |
*/ |
| 69 |
public function run() { |
| 70 |
add_action( 'admin_notices', [ $this, 'missing_charitable_notice' ] ); |
| 71 |
} |
| 72 |
|
| 73 |
|
| 74 |
/** |
| 75 |
* Display notice if Charitable isn't installed |
| 76 |
* |
| 77 |
* @return void |
| 78 |
* @access public |
| 79 |
* @since 1.0.0 |
| 80 |
*/ |
| 81 |
public function missing_charitable_notice() { |
| 82 |
if ( $this->has_charitable ) { |
| 83 |
$url = esc_url( wp_nonce_url( admin_url( 'plugins.php?action=activate&plugin=' . $this->charitable_base ), 'activate-plugin_' . $this->charitable_base ) ); |
| 84 |
$link = '<a href="' . $url . '">' . __( 'activate it', 'charitable' ) . '</a>'; |
| 85 |
} else { |
| 86 |
$url = esc_url( wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=charitable' ), 'install-plugin_charitable' ) ); |
| 87 |
$link = '<a href="' . $url . '">' . __( 'install it', 'charitable' ) . '</a>'; |
| 88 |
} |
| 89 |
|
| 90 |
// translators: %s is a link to the Charitable plugin. |
| 91 |
echo '<div class="error"><p>' . esc_html( $this->plugin_name ) . wp_kses_post( sprintf( __( ' requires Charitable! Please %s to continue!', 'charitable' ), $link ) ) . '</p></div>'; |
| 92 |
} |
| 93 |
} |
| 94 |
|