FS_Plugin_Manager

The NextGEN Gallery FS Plugin Manager class.

Defined (1)

The class is defined in the following location(s).

/freemius/includes/managers/class-fs-plugin-manager.php  
  1. class FS_Plugin_Manager { 
  2. /** 
  3. * @var string 
  4. */ 
  5. protected $_slug; 
  6. /** 
  7. * @var FS_Plugin 
  8. */ 
  9. protected $_plugin; 
  10.  
  11. /** 
  12. * @var FS_Plugin_Manager[] 
  13. */ 
  14. private static $_instances = array(); 
  15. /** 
  16. * @var FS_Logger 
  17. */ 
  18. protected $_logger; 
  19.  
  20. /** 
  21. * @param string $slug 
  22. * @return FS_Plugin_Manager 
  23. */ 
  24. static function instance( $slug ) { 
  25. if ( ! isset( self::$_instances[ $slug ] ) ) { 
  26. self::$_instances[ $slug ] = new FS_Plugin_Manager( $slug ); 
  27.  
  28. return self::$_instances[ $slug ]; 
  29.  
  30. protected function __construct( $slug ) { 
  31. $this->_logger = FS_Logger::get_logger( WP_FS__SLUG . '_' . $slug . '_' . 'plugins', WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK ); 
  32.  
  33. $this->_slug = $slug; 
  34. $this->load(); 
  35.  
  36. protected function get_option_manager() { 
  37. return FS_Option_Manager::get_manager( WP_FS__ACCOUNTS_OPTION_NAME, true ); 
  38.  
  39. protected function get_all_plugins() { 
  40. return $this->get_option_manager()->get_option( 'plugins', array() ); 
  41.  
  42. /** 
  43. * Load plugin data from local DB. 
  44. * @author Vova Feldman (@svovaf) 
  45. * @since 1.0.6 
  46. */ 
  47. function load() { 
  48. $all_plugins = $this->get_all_plugins(); 
  49. $this->_plugin = isset( $all_plugins[ $this->_slug ] ) ? 
  50. $all_plugins[ $this->_slug ] : 
  51. null; 
  52.  
  53. /** 
  54. * Store plugin on local DB. 
  55. * @author Vova Feldman (@svovaf) 
  56. * @since 1.0.6 
  57. * @param bool|FS_Plugin $plugin 
  58. * @param bool $flush 
  59. * @return bool|\FS_Plugin 
  60. */ 
  61. function store( $plugin = false, $flush = true ) { 
  62. $all_plugins = $this->get_all_plugins(); 
  63.  
  64. if ( false !== $plugin ) { 
  65. $this->_plugin = $plugin; 
  66.  
  67. $all_plugins[ $this->_slug ] = $this->_plugin; 
  68.  
  69. $options_manager = $this->get_option_manager(); 
  70. $options_manager->set_option( 'plugins', $all_plugins, $flush ); 
  71.  
  72. return $this->_plugin; 
  73.  
  74. /** 
  75. * Update local plugin data if different. 
  76. * @author Vova Feldman (@svovaf) 
  77. * @since 1.0.6 
  78. * @param \FS_Plugin $plugin 
  79. * @param bool $store 
  80. * @return bool True if plugin was updated. 
  81. */ 
  82. function update( FS_Plugin $plugin, $store = true ) { 
  83. if ( ! ( $this->_plugin instanceof FS_Plugin ) || 
  84. $this->_plugin->slug != $plugin->slug || 
  85. $this->_plugin->public_key != $plugin->public_key || 
  86. $this->_plugin->secret_key != $plugin->secret_key || 
  87. $this->_plugin->parent_plugin_id != $plugin->parent_plugin_id || 
  88. $this->_plugin->title != $plugin->title 
  89. ) { 
  90. $this->store( $plugin, $store ); 
  91.  
  92. return true; 
  93.  
  94. return false; 
  95.  
  96. /** 
  97. * @author Vova Feldman (@svovaf) 
  98. * @since 1.0.6 
  99. * @param FS_Plugin $plugin 
  100. * @param bool $store 
  101. */ 
  102. function set( FS_Plugin $plugin, $store = false ) { 
  103. $this->_plugin = $plugin; 
  104.  
  105. if ( $store ) { 
  106. $this->store(); 
  107.  
  108. /** 
  109. * @author Vova Feldman (@svovaf) 
  110. * @since 1.0.6 
  111. * @return bool|\FS_Plugin 
  112. */ 
  113. function get() { 
  114. return isset( $this->_plugin ) ? 
  115. $this->_plugin : 
  116. false; 
  117.  
  118.