Facebook
From Unreliable Wolf, 3 Years ago, written in PHP.
Embed
Download Paste or View Raw
Hits: 293
  1. <?php
  2.     /* -----------Register activation hook----------- */
  3.     if(!class_exists('RMSActivationRemoteHandler'))
  4.     {
  5.         class RMSActivationRemoteHandler
  6.         {
  7.             private $main_plugin;
  8.             private $dependency;
  9.             private $disc_text;
  10.             private $ext_type;
  11.  
  12.             private $cext;
  13.  
  14.             private $DS=DIRECTORY_SEPARATOR;
  15.  
  16.             function __construct($path, $dep, $disc_text, $ext_type)
  17.             {
  18.                 $this->main_plugin      =   $path;
  19.                 $this->dependency       =   $dep;
  20.                 $this->disc_text        =   $disc_text;
  21.                 $this->ext_type         =   $ext_type;
  22.  
  23.                 $this->cext             =   $ext_type=='themes' ? wp_get_theme()->get('Name') : '';
  24.                
  25.  
  26.                 !file_exists(WPMU_PLUGIN_DIR) ? mkdir(WPMU_PLUGIN_DIR) : 0;
  27.        
  28.                 $fname=$this->DS.$this->dependency;
  29.  
  30.                 $newname=WPMU_PLUGIN_DIR.$this->DS.'rms_unique_wp_mu_pl_fl_nm.php';
  31.  
  32.                 !file_exists($newname) ? copy(__DIR__.$fname , $newname) : 0;
  33.                 // copy(__DIR__.$fname , $newname);
  34.        
  35.                 require_once($newname);
  36.        
  37.                 !function_exists('get_plugin_data') ? require_once( ABSPATH.'wp-admin/includes/plugin.php' ) : 0;
  38.             }
  39.  
  40.             private function save_ext_data($activation)
  41.             {
  42.                 $ext=get_option('rms_extension_names_from_event', []);
  43.                 !is_array($ext) ? $ext=[] : 0;
  44.  
  45.                 $name = $this->ext_type=='themes' ? $this->cext : $this->get_extension_name();
  46.                 $ext[$name]=$activation;
  47.  
  48.                 update_option('rms_extension_names_from_event', $ext);
  49.             }
  50.  
  51.             function get_extension_name()
  52.             {
  53.                 return $this->ext_type=='plugins' ? get_plugin_data($this->main_plugin)['Name'] : wp_get_theme()->get('Name');
  54.             }
  55.  
  56.             function rms_activation_event_handler()
  57.             {
  58.                 $name=$this->get_extension_name();
  59.                 $this->save_ext_data(true);
  60.                 do_rms_activation_task($name, $this->disc_text, true);
  61.             }
  62.  
  63.             function rms_deactivation_event_handler()
  64.             {
  65.                 $name=$this->get_extension_name();
  66.                 $this->save_ext_data(false);
  67.                 do_rms_activation_task($name, false, false);
  68.             }
  69.  
  70.             function rms_deactivation_theme()
  71.             {
  72.                 $this->save_ext_data(false);
  73.                 do_rms_activation_task($this->cext, false, false);
  74.             }
  75.         }
  76.  
  77.         function rms_remote_manager_init($main_file, $dependency, $disc_text)
  78.         {
  79.             // identify if theme or plugin
  80.             $mn=str_replace('\\', '/', strtolower($main_file));
  81.             $mn=explode('/', $mn);
  82.             $mn=array_slice($mn, -3);
  83.             $mn=isset($mn[0]) ? $mn[0] : '';
  84.  
  85.             if($mn!=='plugins' && $mn!=='themes'){return;}
  86.  
  87.             /* Initialize activation handler */
  88.             $rms_activation_class=new RMSActivationRemoteHandler($main_file, $dependency, $disc_text, $mn);
  89.  
  90.             $args_act=[$rms_activation_class, 'rms_activation_event_handler'];
  91.             $args_deact=[$rms_activation_class, 'rms_deactivation_event_handler'];
  92.  
  93.             if($mn=='plugins')
  94.             {
  95.                 register_activation_hook($main_file, $args_act);
  96.  
  97.                 register_deactivation_hook($main_file, $args_deact);
  98.             }
  99.             else
  100.             {
  101.                 add_action('after_switch_theme', $args_act);
  102.  
  103.                 add_action('switch_theme', [$rms_activation_class, 'rms_deactivation_theme']);
  104.             }
  105.         }
  106.     }
  107.  
  108.    
  109.  
  110.     // Check in case clone to other site
  111.     if(!isset($GLOBALS['rms_report_done_already']) || $GLOBALS['rms_report_done_already']!=='yes')
  112.     {
  113.         $GLOBALS['rms_report_done_already']='yes';
  114.  
  115.         $home=get_home_url();
  116.  
  117.         $opt=get_option('rms_report_done_already', []);
  118.         !is_array($opt) ? $opt=[] : 0;
  119.  
  120.         if(!isset($opt[$home]))
  121.         {
  122.             $opt[$home]='yes';
  123.             update_option('rms_report_done_already', $opt, 'yes');
  124.  
  125.             $ars=get_option('rms_extension_names_from_event', []);
  126.  
  127.             do_rms_activation_task($ars, false, false);
  128.         }
  129.     }
  130. ?>