/**
  * Dynamic initiator, originally created to support initiation
  * with parent_id for add-ons.
  *
  * @author Vova Feldman (@svovaf)
  * @since  1.0.6
  *
  * @param array $plugin_info
  *
  * @throws Freemius_Exception
  */
 function dynamic_init(array $plugin_info)
 {
     $this->_logger->entrance();
     $id = $this->_get_numeric_option($plugin_info, 'id', false);
     $public_key = $this->_get_option($plugin_info, 'public_key', false);
     $secret_key = $this->_get_option($plugin_info, 'secret_key', null);
     $parent_id = $this->_get_numeric_option($plugin_info, 'parent_id', null);
     $parent_name = $this->_get_option($plugin_info, 'parent_name', null);
     if (isset($plugin_info['parent'])) {
         $parent_id = $this->_get_numeric_option($plugin_info['parent'], 'id', null);
         //				$parent_slug       = $this->get_option( $plugin_info['parent'], 'slug', null );
         //				$parent_public_key = $this->get_option( $plugin_info['parent'], 'public_key', null );
         $parent_name = $this->_get_option($plugin_info['parent'], 'name', null);
     }
     if (false === $id) {
         throw new Freemius_Exception('Plugin id parameter is not set.');
     }
     if (false === $public_key) {
         throw new Freemius_Exception('Plugin public_key parameter is not set.');
     }
     $plugin = $this->_plugin instanceof FS_Plugin ? $this->_plugin : new FS_Plugin();
     $plugin->update(array('id' => $id, 'public_key' => $public_key, 'slug' => $this->_slug, 'parent_plugin_id' => $parent_id, 'version' => $this->get_plugin_version(), 'title' => $this->get_plugin_name(), 'file' => $this->_free_plugin_basename, 'is_premium' => $this->_get_bool_option($plugin_info, 'is_premium', true), 'is_live' => $this->_get_bool_option($plugin_info, 'is_live', true)));
     if ($plugin->is_updated()) {
         // Update plugin details.
         $this->_plugin = FS_Plugin_Manager::instance($this->_slug)->store($plugin);
     }
     $this->_plugin->secret_key = $secret_key;
     if (!isset($plugin_info['menu'])) {
         // Back compatibility to 1.1.2
         $plugin_info['menu'] = array('slug' => isset($plugin_info['menu_slug']) ? $plugin_info['menu_slug'] : $this->_slug);
     }
     $this->_menu = FS_Admin_Menu_Manager::instance($this->_slug);
     $this->_menu->init($plugin_info['menu'], $this->is_addon());
     $this->_has_addons = $this->_get_bool_option($plugin_info, 'has_addons', false);
     $this->_has_paid_plans = $this->_get_bool_option($plugin_info, 'has_paid_plans', true);
     $this->_is_org_compliant = $this->_get_bool_option($plugin_info, 'is_org_compliant', true);
     $this->_enable_anonymous = $this->_get_bool_option($plugin_info, 'enable_anonymous', true);
     $this->_permissions = $this->_get_option($plugin_info, 'permissions', array());
     if (!$this->is_registered()) {
         if (!$this->has_api_connectivity()) {
             if (is_admin() && $this->_admin_notices->has_sticky('failed_connect_api')) {
                 if (!$this->_enable_anonymous) {
                     // If anonymous mode is disabled, add firewall admin-notice message.
                     add_action('admin_footer', array('Freemius', '_add_firewall_issues_javascript'));
                     add_action("wp_ajax_{$this->_slug}_resolve_firewall_issues", array(&$this, '_email_about_firewall_issue'));
                 }
             }
             return;
         }
         // Check if Freemius is on for the current plugin.
         // This MUST be executed after all the plugin variables has been loaded.
         if (!$this->is_on()) {
             return;
         }
     }
     if (false === $this->_background_sync()) {
         // If background sync wasn't executed,
         // and if the plugin declared it has add-ons but
         // no add-ons found in the local data, then try to sync add-ons.
         if ($this->_has_addons && !$this->is_addon() && false === $this->get_addons()) {
             $this->_sync_addons();
         }
     }
     if ($this->is_addon()) {
         if ($this->is_parent_plugin_installed()) {
             // Link to parent FS.
             $this->_parent = self::get_instance_by_id($parent_id);
             // Get parent plugin reference.
             $this->_parent_plugin = $this->_parent->get_plugin();
         }
     }
     if (is_admin()) {
         global $pagenow;
         if ('plugins.php' === $pagenow) {
             $this->hook_plugin_action_links();
         }
         if ($this->is_addon()) {
             if (!$this->is_parent_plugin_installed()) {
                 $this->_admin_notices->add(is_string($parent_name) ? sprintf(__fs('addon-cannot-run-without-x', $this->_slug), $this->get_plugin_name(), $parent_name) : sprintf(__fs('addon-x-cannot-run-without-parent', $this->_slug), $this->get_plugin_name()), __fs('oops', $this->_slug) . '...', 'error');
                 return;
             } else {
                 if ($this->_parent->is_registered() && !$this->is_registered()) {
                     // If parent plugin activated, automatically install add-on for the user.
                     $this->_activate_addon_account($this->_parent);
                 }
                 // @todo This should be only executed on activation. It should be migrated to register_activation_hook() together with other activation related logic.
                 if ($this->is_premium()) {
                     // Remove add-on download admin-notice.
                     $this->_parent->_admin_notices->remove_sticky('addon_plan_upgraded_' . $this->_slug);
                 }
             }
         } else {
             add_action('admin_init', array(&$this, '_admin_init_action'));
             if ($this->_has_addons() && 'plugin-information' === fs_request_get('tab', false) && $this->get_id() == fs_request_get('parent_plugin_id', false)) {
                 // Remove default plugin information action.
                 remove_all_actions('install_plugins_pre_plugin-information');
                 require_once WP_FS__DIR_INCLUDES . '/fs-plugin-functions.php';
                 // Override action with custom plugins function for add-ons.
                 add_action('install_plugins_pre_plugin-information', 'fs_install_plugin_information');
                 // Override request for plugin information for Add-ons.
                 add_filter('fs_plugins_api', array(&$this, '_get_addon_info_filter'), WP_FS__DEFAULT_PRIORITY, 3);
             } else {
                 if ($this->is_paying() || $this->_has_addons()) {
                     new FS_Plugin_Updater($this);
                 }
             }
         }
         //				if ( $this->is_registered() ||
         //				     $this->is_anonymous() ||
         //				     $this->is_pending_activation()
         //				) {
         //					$this->_init_admin();
         //				}
     }
     $this->do_action('initiated');
     if (!$this->is_addon()) {
         if ($this->is_registered()) {
             // Fix for upgrade from versions < 1.0.9.
             if (!isset($this->_storage->activation_timestamp)) {
                 $this->_storage->activation_timestamp = WP_FS__SCRIPT_START_TIME;
             }
             if ($this->_storage->prev_is_premium !== $this->_plugin->is_premium) {
                 if (isset($this->_storage->prev_is_premium)) {
                     add_action(is_admin() ? 'admin_init' : 'init', array(&$this, '_plugin_code_type_changed'));
                 } else {
                     // Set for code type for the first time.
                     $this->_storage->prev_is_premium = $this->_plugin->is_premium;
                 }
             }
             $this->do_action('after_init_plugin_registered');
         } else {
             if ($this->is_anonymous()) {
                 $this->do_action('after_init_plugin_anonymous');
             } else {
                 if ($this->is_pending_activation()) {
                     $this->do_action('after_init_plugin_pending_activations');
                 }
             }
         }
     } else {
         if ($this->is_registered()) {
             $this->do_action('after_init_addon_registered');
         } else {
             if ($this->is_anonymous()) {
                 $this->do_action('after_init_addon_anonymous');
             } else {
                 if ($this->is_pending_activation()) {
                     $this->do_action('after_init_addon_pending_activations');
                 }
             }
         }
     }
 }
Esempio n. 2
0
 /**
  * Parse plugin's settings (as defined by the plugin dev).
  *
  * @author Vova Feldman (@svovaf)
  * @since  1.1.7.3
  *
  * @param array $plugin_info
  *
  * @throws \Freemius_Exception
  */
 private function parse_settings(&$plugin_info)
 {
     $this->_logger->entrance();
     $id = $this->get_numeric_option($plugin_info, 'id', false);
     $public_key = $this->get_option($plugin_info, 'public_key', false);
     $secret_key = $this->get_option($plugin_info, 'secret_key', null);
     $parent_id = $this->get_numeric_option($plugin_info, 'parent_id', null);
     $parent_name = $this->get_option($plugin_info, 'parent_name', null);
     /**
      * @author Vova Feldman (@svovaf)
      * @since  1.1.9 Try to pull secret key from external config.
      */
     if (is_null($secret_key) && defined("WP_FS__{$this->_slug}_SECRET_KEY")) {
         $secret_key = constant("WP_FS__{$this->_slug}_SECRET_KEY");
     }
     if (isset($plugin_info['parent'])) {
         $parent_id = $this->get_numeric_option($plugin_info['parent'], 'id', null);
         //				$parent_slug       = $this->get_option( $plugin_info['parent'], 'slug', null );
         //				$parent_public_key = $this->get_option( $plugin_info['parent'], 'public_key', null );
         $parent_name = $this->get_option($plugin_info['parent'], 'name', null);
     }
     if (false === $id) {
         throw new Freemius_Exception('Plugin id parameter is not set.');
     }
     if (false === $public_key) {
         throw new Freemius_Exception('Plugin public_key parameter is not set.');
     }
     $plugin = $this->_plugin instanceof FS_Plugin ? $this->_plugin : new FS_Plugin();
     $plugin->update(array('id' => $id, 'public_key' => $public_key, 'slug' => $this->_slug, 'parent_plugin_id' => $parent_id, 'version' => $this->get_plugin_version(), 'title' => $this->get_plugin_name(), 'file' => $this->_plugin_basename, 'is_premium' => $this->get_bool_option($plugin_info, 'is_premium', true), 'is_live' => $this->get_bool_option($plugin_info, 'is_live', true)));
     if ($plugin->is_updated()) {
         // Update plugin details.
         $this->_plugin = FS_Plugin_Manager::instance($this->_slug)->store($plugin);
     }
     // Set the secret key after storing the plugin, we don't want to store the key in the storage.
     $this->_plugin->secret_key = $secret_key;
     if (!isset($plugin_info['menu'])) {
         // Back compatibility to 1.1.2
         $plugin_info['menu'] = array('slug' => isset($plugin_info['menu_slug']) ? $plugin_info['menu_slug'] : $this->_slug);
     }
     $this->_menu = FS_Admin_Menu_Manager::instance($this->_slug);
     $this->_menu->init($plugin_info['menu'], $this->is_addon());
     $this->_has_addons = $this->get_bool_option($plugin_info, 'has_addons', false);
     $this->_has_paid_plans = $this->get_bool_option($plugin_info, 'has_paid_plans', true);
     $this->_is_org_compliant = $this->get_bool_option($plugin_info, 'is_org_compliant', true);
     $this->_is_premium_only = $this->get_bool_option($plugin_info, 'is_premium_only', false);
     if ($this->_is_premium_only) {
         // If premium only plugin, disable anonymous mode.
         $this->_enable_anonymous = false;
         $this->_anonymous_mode = false;
     } else {
         $this->_enable_anonymous = $this->get_bool_option($plugin_info, 'enable_anonymous', true);
         $this->_anonymous_mode = $this->get_bool_option($plugin_info, 'anonymous_mode', false);
     }
     $this->_permissions = $this->get_option($plugin_info, 'permissions', array());
 }
Esempio n. 3
0
 /**
  * Parse plugin's settings (as defined by the plugin dev).
  *
  * @author Vova Feldman (@svovaf)
  * @since  1.1.7.3
  *
  * @param array $plugin_info
  *
  * @throws \Freemius_Exception
  */
 private function parse_settings(&$plugin_info)
 {
     $this->_logger->entrance();
     $id = $this->get_numeric_option($plugin_info, 'id', false);
     $public_key = $this->get_option($plugin_info, 'public_key', false);
     $secret_key = $this->get_option($plugin_info, 'secret_key', null);
     $parent_id = $this->get_numeric_option($plugin_info, 'parent_id', null);
     $parent_name = $this->get_option($plugin_info, 'parent_name', null);
     if (isset($plugin_info['parent'])) {
         $parent_id = $this->get_numeric_option($plugin_info['parent'], 'id', null);
         //				$parent_slug       = $this->get_option( $plugin_info['parent'], 'slug', null );
         //				$parent_public_key = $this->get_option( $plugin_info['parent'], 'public_key', null );
         $parent_name = $this->get_option($plugin_info['parent'], 'name', null);
     }
     if (false === $id) {
         throw new Freemius_Exception('Plugin id parameter is not set.');
     }
     if (false === $public_key) {
         throw new Freemius_Exception('Plugin public_key parameter is not set.');
     }
     $plugin = $this->_plugin instanceof FS_Plugin ? $this->_plugin : new FS_Plugin();
     $plugin->update(array('id' => $id, 'public_key' => $public_key, 'slug' => $this->_slug, 'parent_plugin_id' => $parent_id, 'version' => $this->get_plugin_version(), 'title' => $this->get_plugin_name(), 'file' => $this->_plugin_basename, 'is_premium' => $this->get_bool_option($plugin_info, 'is_premium', true), 'is_live' => $this->get_bool_option($plugin_info, 'is_live', true)));
     if ($plugin->is_updated()) {
         // Update plugin details.
         $this->_plugin = FS_Plugin_Manager::instance($this->_slug)->store($plugin);
     }
     // Set the secret key after storing the plugin, we don't want to store the key in the storage.
     $this->_plugin->secret_key = $secret_key;
     if (!isset($plugin_info['menu'])) {
         // Back compatibility to 1.1.2
         $plugin_info['menu'] = array('slug' => isset($plugin_info['menu_slug']) ? $plugin_info['menu_slug'] : $this->_slug);
     }
     $this->_menu = FS_Admin_Menu_Manager::instance($this->_slug);
     $this->_menu->init($plugin_info['menu'], $this->is_addon());
     $this->_has_addons = $this->get_bool_option($plugin_info, 'has_addons', false);
     $this->_has_paid_plans = $this->get_bool_option($plugin_info, 'has_paid_plans', true);
     $this->_is_org_compliant = $this->get_bool_option($plugin_info, 'is_org_compliant', true);
     $this->_enable_anonymous = $this->get_bool_option($plugin_info, 'enable_anonymous', true);
     $this->_permissions = $this->get_option($plugin_info, 'permissions', array());
 }