plugin_FILE = (new \ReflectionClass(__CLASS__))->getFileName(); $this->plugin_DIR = dirname($this->plugin_FILE); $this->plugin_DIR_URL= plugin_dir_url($this->plugin_FILE); include_once(ABSPATH . "wp-admin/includes/plugin.php"); //setup initial variables if(method_exists($this, 'declare_static_settings')) { $this->declare_static_settings(); } else { $this->static_settings=array('show_opts'=>false, 'required_role'=>'manage_options', 'managed_from'=>'multisite', 'allowed_on'=>'both'); $this->user_initial_options= array(); } $this->my_plugin_vars(); //setup 2nd initial variables $this->plugin_slug = sanitize_key($this->static_settings['TextDomain']); //define short slug $this->opts= $this->refresh_options(); //setup final variables $this->__construct_my(); //all other custom construction hooks $this->plugin_page_url= ( $this->opts['managed_from_primary_site'] ? network_admin_url( 'settings.php') : admin_url( 'options-general.php') ). '?page='.$this->plugin_slug; //determine which page needed //==== my other default hooks ===// // If plugin has options if($this->opts['show_opts']) { //add admin menu add_action( ( $this->opts['managed_from_primary_site'] ? 'network_' : ''). 'admin_menu', function(){ add_submenu_page($this->opts['menu_pagePHP'], $this->opts['Name'], $this->opts['Name'], $this->opts['required_role'] , $this->plugin_slug, array($this, 'opts_page_output') );} ); //redirect to settings page after activation (if not bulk activation) add_action('activated_plugin', function($plugin) { if ( $plugin == plugin_basename( $this->plugin_FILE ) && !((new WP_Plugins_List_Table())->current_action()=='activate-selected')) { exit( wp_redirect($this->plugin_page_url.'&isactivation') ); } } ); } // add Settings & Donate buttons in plugins list add_filter( (is_network_admin() ? 'network_admin_' : ''). 'plugin_action_links_'.plugin_basename($this->plugin_FILE), function($links){ $links[] = ''.$this->opts['menu_text']['donate'].''; if($this->opts['show_opts']) { $links[] = "".$this->opts['menu_text']['settings'].''; } return $links; }); //translation hook add_action('plugins_loaded', array($this, 'load_textdomain') ); //activation & deactivation (empty hooks by default. all important things migrated into `refresh_options`) register_activation_hook( $this->plugin_FILE, array($this, 'activate') ); register_deactivation_hook( $this->plugin_FILE, array($this, 'deactivate')); if(is_admin()) add_action( 'shutdown', array($this, 'my_shutdown_for_versioning')); } public function activate($network_wide){ //if activation allowed from only on multisite or singlesite or Both? $die= $this->opts['allowed_on'] == 'both' ? false : ( ($this->opts['allowed_on'] =='multisite' && !$network_wide && is_multisite()) || ( $this->opts['allowed_on'] =='singlesite' && ($network_wide || is_network_admin()) ) ) ; if($die) { $text= '
Must have free plugins for everyone', 'my_default_methods_T_Todua'), $this->opts['musthave_plugins'] ); ?>