private function __construct($slug) { $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(); $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')) { FS_Api::clear_cache(); } $this->_register_hooks(); $this->_load_account(); $this->_version_updates_handler(); }
/** * Load static resources. * * @author Vova Feldman (@svovaf) * @since 1.0.1 */ private static function _load_required_static() { if (self::$_statics_loaded) { return; } self::$_static_logger = FS_Logger::get_logger(WP_FS__SLUG, WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK); self::$_static_logger->entrance(); self::$_accounts = FS_Option_Manager::get_manager(WP_FS__ACCOUNTS_OPTION_NAME, true); self::$_global_admin_notices = FS_Admin_Notice_Manager::instance('global'); // Configure which Freemius powered plugins should be auto updated. // add_filter( 'auto_update_plugin', '_include_plugins_in_auto_update', 10, 2 ); add_action('admin_menu', array('Freemius', 'add_debug_page')); add_action("wp_ajax_fs_toggle_debug_mode", array('Freemius', '_toggle_debug_mode')); add_action('plugins_loaded', array('Freemius', '_load_textdomain'), 1); self::$_statics_loaded = true; }
function rw_reset_account() { global $rw_fs; $rw_account = rw_account(); $rw_api = rwapi(); // Before making any changes, make sure site credentials are good. // Preserve previous credentials. $prev_site_id = $rw_account->site_id; $prev_site_public_key = $rw_account->site_public_key; $prev_site_secret_key = $rw_account->site_secret_key; // Get install information from request. $site_id = rw_request_get('site_id'); $site_public_key = rw_request_get('site_public_key'); $site_secret_key = rw_request_get('site_secret_key'); $admin_notices = FS_Admin_Notice_Manager::instance(WP_RW__ID, 'Rating-Widget'); if (!is_numeric($site_id)) { $admin_notices->add('Invalid site ID. Please contact our support for more details.'); return false; } if (32 !== strlen($site_public_key)) { $admin_notices->add('Invalid public key. Please contact our support for more details.'); return false; } if (20 > strlen($site_secret_key)) { $admin_notices->add('Invalid secret key. Please contact our support for more details.'); return false; } // Override site details. $rw_account->set_site($site_id, $site_public_key, $site_secret_key, false); // Reload API with new account details. $rw_api->reload(); if (!$rw_api->test()) { // Fallback to previous account. $rw_account->set_site($prev_site_id, $prev_site_public_key, $prev_site_secret_key, false); // Reload API with new account details. $rw_api->reload(); $admin_notices->add('Invalid site credentials. Failed pining RatingWidget\'s API. Please contact our support for more details.'); return false; } // Save new RW credentials. $rw_account->save(); if ($rw_fs->is_registered()) { // Send uninstall event. $rw_fs->_uninstall_plugin_event(false); if ('true' === rw_request_get('delete_account')) { $rw_fs->delete_account_event(false); } } if (rw_migration_to_freemius()) { fs_redirect($rw_fs->_get_admin_page_url('account')); die; } return true; }