| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
die( 'You are not allowed to call this page directly.' ); |
| 4 |
} |
| 5 |
|
| 6 |
/** |
| 7 |
* @since 4.04.04 |
| 8 |
*/ |
| 9 |
class FrmInstallPlugin { |
| 10 |
|
| 11 |
protected $plugin_file; // format: folder/filename.php |
| 12 |
protected $plugin_slug; |
| 13 |
|
| 14 |
public function __construct( $atts ) { |
| 15 |
$this->plugin_file = $atts['plugin_file']; |
| 16 |
list( $slug, $file ) = explode( '/', $this->plugin_file ); |
| 17 |
$this->plugin_slug = $slug; |
| 18 |
} |
| 19 |
|
| 20 |
public function get_activate_link() { |
| 21 |
if ( $this->is_installed() && $this->is_active() ) { |
| 22 |
return ''; |
| 23 |
} |
| 24 |
|
| 25 |
if ( $this->is_installed() ) { |
| 26 |
$url = $this->activate_url(); |
| 27 |
} else { |
| 28 |
$url = $this->install_url(); |
| 29 |
} |
| 30 |
return $url; |
| 31 |
} |
| 32 |
|
| 33 |
public function is_installed() { |
| 34 |
return is_dir( WP_PLUGIN_DIR . '/' . $this->plugin_slug ); |
| 35 |
} |
| 36 |
|
| 37 |
public function is_active() { |
| 38 |
return is_plugin_active( $this->plugin_file ); |
| 39 |
} |
| 40 |
|
| 41 |
protected function install_url() { |
| 42 |
return wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=' . $this->plugin_slug ), 'install-plugin_' . $this->plugin_slug ); |
| 43 |
} |
| 44 |
|
| 45 |
protected function activate_url() { |
| 46 |
return wp_nonce_url( self_admin_url( 'plugins.php?action=activate&plugin=' . $this->plugin_file ), 'activate-plugin_' . $this->plugin_file ); |
| 47 |
} |
| 48 |
} |
| 49 |
|