protected function __construct($slug, $title = '')
 {
     $this->_logger = FS_Logger::get_logger(WP_FS__SLUG . '_' . $slug . '_data', WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK);
     $this->_slug = $slug;
     $this->_title = !empty($title) ? $title : '';
     $this->_sticky_storage = FS_Key_Value_Storage::instance('admin_notices', $this->_slug);
     if (is_admin()) {
         if (0 < count($this->_sticky_storage)) {
             // If there are sticky notices for the current slug, add a callback
             // to the AJAX action that handles message dismiss.
             add_action("wp_ajax_{$slug}_dismiss_notice_action", array(&$this, 'dismiss_notice_ajax_callback'));
             foreach ($this->_sticky_storage as $id => $msg) {
                 // Add admin notice.
                 $this->add($msg['message'], $msg['title'], $msg['type'], true, $msg['all'], $msg['id'], false);
             }
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Main singleton instance.
  *
  * @author Vova Feldman (@svovaf)
  * @since  1.0.0
  *
  * @param string $slug
  * @param bool   $is_init Since 1.2.1 Is initiation sequence.
  */
 private function __construct($slug, $is_init = false)
 {
     $this->_slug = $slug;
     $this->_logger = FS_Logger::get_logger(WP_FS__SLUG . '_' . $slug, WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK);
     $this->_storage = FS_Key_Value_Storage::instance('plugin_data', $this->_slug);
     $this->_plugin_main_file_path = $this->_find_caller_plugin_file($is_init);
     $this->_plugin_dir_path = plugin_dir_path($this->_plugin_main_file_path);
     $this->_plugin_basename = plugin_basename($this->_plugin_main_file_path);
     $this->_free_plugin_basename = str_replace('-premium/', '/', $this->_plugin_basename);
     $base_name_split = explode('/', $this->_plugin_basename);
     $this->_plugin_dir_name = $base_name_split[0];
     if ($this->_logger->is_on()) {
         $this->_logger->info('plugin_main_file_path = ' . $this->_plugin_main_file_path);
         $this->_logger->info('plugin_dir_path = ' . $this->_plugin_dir_path);
         $this->_logger->info('plugin_basename = ' . $this->_plugin_basename);
         $this->_logger->info('free_plugin_basename = ' . $this->_free_plugin_basename);
         $this->_logger->info('plugin_dir_name = ' . $this->_plugin_dir_name);
     }
     // Remember link between file to slug.
     $this->store_file_slug_map();
     // Store plugin's initial install timestamp.
     if (!isset($this->_storage->install_timestamp)) {
         $this->_storage->install_timestamp = WP_FS__SCRIPT_START_TIME;
     }
     $this->_plugin = FS_Plugin_Manager::instance($this->_slug)->get();
     $this->_admin_notices = FS_Admin_Notice_Manager::instance($slug, is_object($this->_plugin) ? $this->_plugin->title : '');
     if ('true' === fs_request_get('fs_clear_api_cache') || 'true' === fs_request_is_action('restart_freemius')) {
         FS_Api::clear_cache();
     }
     $this->_register_hooks();
     $this->_load_account();
     $this->_version_updates_handler();
 }