Bez popisu

class-pum-extension-activation.php 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /**
  3. * Activation handler
  4. *
  5. * @package PUM\SDK\ActivationHandler
  6. * @since 1.0.0
  7. * @copyright Copyright (c) 2019, Code Atlantic LLC
  8. */
  9. // Exit if accessed directly
  10. if( ! defined( 'ABSPATH' ) ) exit;
  11. /**
  12. * Popup Maker Extension Activation Handler Class
  13. *
  14. * @since 1.0.0
  15. */
  16. class PUM_Extension_Activation {
  17. public $plugin_name, $plugin_path, $plugin_file, $has_popmake, $popmake_base;
  18. /**
  19. * Setup the activation class
  20. *
  21. * @access public
  22. * @since 1.0.0
  23. *
  24. * @param $plugin_path
  25. * @param $plugin_file
  26. */
  27. public function __construct( $plugin_path, $plugin_file ) {
  28. // We need plugin.php!
  29. require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
  30. $plugins = get_plugins();
  31. // Set plugin directory
  32. $plugin_path = array_filter( explode( '/', $plugin_path ) );
  33. $this->plugin_path = end( $plugin_path );
  34. // Set plugin file
  35. $this->plugin_file = $plugin_file;
  36. // Set plugin name
  37. if ( isset( $plugins[ $this->plugin_path . '/' . $this->plugin_file ]['Name'] ) ) {
  38. $this->plugin_name = str_replace( 'Popup Maker - ', '', $plugins[ $this->plugin_path . '/' . $this->plugin_file ]['Name'] );
  39. } else {
  40. $this->plugin_name = __( 'This plugin', 'popup-maker' );
  41. }
  42. // Is Popup Maker installed?
  43. foreach( $plugins as $plugin_path => $plugin ) {
  44. if( $plugin['Name'] == 'Popup Maker' ) {
  45. $this->has_popmake = true;
  46. $this->popmake_base = $plugin_path;
  47. break;
  48. }
  49. }
  50. }
  51. /**
  52. * Process plugin deactivation
  53. *
  54. * @access public
  55. * @since 1.0.0
  56. * @return void
  57. */
  58. public function run() {
  59. // Display notice
  60. add_action( 'admin_notices', array( $this, 'missing_popmake_notice' ) );
  61. }
  62. /**
  63. * Display notice if Popup Maker isn't installed
  64. */
  65. public function missing_popmake_notice() {
  66. if( $this->has_popmake ) {
  67. $url = esc_url( wp_nonce_url( admin_url( 'plugins.php?action=activate&plugin=' . $this->popmake_base ), 'activate-plugin_' . $this->popmake_base ) );
  68. $link = '<a href="' . $url . '">' . __( 'activate it', 'popmake-extension-activation' ) . '</a>';
  69. } else {
  70. $url = esc_url( wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=popup-maker' ), 'install-plugin_popup-maker' ) );
  71. $link = '<a href="' . $url . '">' . __( 'install it', 'popmake-extension-activation' ) . '</a>';
  72. }
  73. echo '<div class="error"><p>' . $this->plugin_name . sprintf( __( ' requires Popup Maker! Please %s to continue!', 'popmake-extension-activation' ), $link ) . '</p></div>';
  74. }
  75. }