PageRenderTime 45ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/src/icwp-optionshandler-wpsf.php

https://github.com/stackgrinder/wp-simple-firewall
PHP | 212 lines | 161 code | 19 blank | 32 comment | 7 complexity | 2defc40c9b5539aefae49d68de10ff5c MD5 | raw file
  1. <?php
  2. /**
  3. * Copyright (c) 2014 iControlWP <support@icontrolwp.com>
  4. * All rights reserved.
  5. *
  6. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  7. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  8. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  9. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
  10. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  11. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  12. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  13. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  14. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  15. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  16. */
  17. require_once( dirname(__FILE__).'/icwp-optionshandler-base.php' );
  18. if ( !class_exists('ICWP_OptionsHandler_Wpsf') ):
  19. class ICWP_OptionsHandler_Wpsf extends ICWP_OptionsHandler_Base_Wpsf {
  20. const StoreName = 'plugin_options';
  21. const Default_AccessKeyTimeout = 30;
  22. public function __construct( $oPluginVo ) {
  23. parent::__construct( $oPluginVo, self::StoreName );
  24. $this->sFeatureName = _wpsf__('Dashboard');
  25. $this->sFeatureSlug = 'dashboard';
  26. $this->fShowFeatureMenuItem = false;
  27. }
  28. /**
  29. * @return bool|void
  30. */
  31. public function defineOptions() {
  32. $aNonUiOptions = array(
  33. 'installation_time',
  34. 'secret_key',
  35. 'feedback_admin_notice',
  36. 'update_success_tracker',
  37. 'capability_can_disk_write',
  38. 'capability_can_remote_get',
  39. 'enable_firewall',
  40. 'enable_login_protect',
  41. 'enable_comments_filter',
  42. 'enable_lockdown',
  43. 'enable_autoupdates'
  44. );
  45. $this->mergeNonUiOptions( $aNonUiOptions );
  46. if ( $this->hasEncryptOption() ) {
  47. $aAccessKey = array(
  48. 'section_title' => _wpsf__( 'Admin Access Restriction' ),
  49. 'section_options' => array(
  50. array(
  51. 'enable_admin_access_restriction',
  52. '',
  53. 'N',
  54. 'checkbox',
  55. _wpsf__( 'Enable Access Key' ),
  56. _wpsf__( 'Enforce Admin Access Restriction' ),
  57. _wpsf__( 'Enable this with great care and consideration. When this Access Key option is enabled, you must specify a key below and use it to gain access to this plugin.' ),
  58. '<a href="http://icwp.io/40" target="_blank">'._wpsf__( 'more info' ).'</a>'
  59. .' | <a href="http://icwp.io/wpsf02" target="_blank">'._wpsf__( 'blog' ).'</a>'
  60. ),
  61. array(
  62. 'admin_access_timeout',
  63. '',
  64. self::Default_AccessKeyTimeout,
  65. 'integer',
  66. _wpsf__( 'Access Key Timeout' ),
  67. _wpsf__( 'Specify A Timeout For Plugin Admin Access' ),
  68. _wpsf__( 'This will automatically expire your WordPress Simple Firewall session. Does not apply until you enter the access key again. Default: 30 minutes.' ),
  69. '<a href="http://icwp.io/41" target="_blank">'._wpsf__( 'more info' ).'</a>'
  70. ),
  71. array(
  72. 'admin_access_key',
  73. '',
  74. '',
  75. 'password',
  76. _wpsf__( 'Admin Access Key' ),
  77. _wpsf__( 'Specify Your Plugin Access Key' ),
  78. _wpsf__( 'If you forget this, you could potentially lock yourself out from using this plugin.' )
  79. .' <strong>'._wpsf__( 'Leave it blank to not update it' ).'</strong>',
  80. '<a href="http://icwp.io/42" target="_blank">'._wpsf__( 'more info' ).'</a>'
  81. )
  82. )
  83. );
  84. }
  85. $aGeneral = array(
  86. 'section_title' => _wpsf__( 'General Plugin Options' ),
  87. 'section_options' => array(
  88. array(
  89. 'enable_upgrade_admin_notice',
  90. '',
  91. 'Y',
  92. 'checkbox',
  93. _wpsf__( 'Plugin Notices' ),
  94. _wpsf__( 'Display Notices For Updates' ),
  95. _wpsf__( 'Disable this option to hide certain plugin admin notices about available updates and post-update notices' )
  96. ),
  97. array(
  98. 'delete_on_deactivate',
  99. '',
  100. 'N',
  101. 'checkbox',
  102. _wpsf__( 'Delete Plugin Settings' ),
  103. _wpsf__( 'Delete All Plugin Settings Upon Plugin Deactivation' ),
  104. _wpsf__( 'Careful: Removes all plugin options when you deactivate the plugin' )
  105. )
  106. )
  107. );
  108. $aGlobal = array(
  109. 'section_title' => _wpsf__( 'Global Plugin Features' ),
  110. 'section_options' => array(
  111. array(
  112. 'enable_firewall',
  113. '', 'N',
  114. 'checkbox',
  115. _wpsf__( 'Enable Firewall' ),
  116. _wpsf__( 'Enable (or Disable) The WordPress Firewall Feature' ),
  117. _wpsf__( 'Regardless of any other settings, this option will turn off the Firewall feature, or enable your selected Firewall options' )
  118. ),
  119. array(
  120. 'enable_login_protect',
  121. '',
  122. 'N',
  123. 'checkbox',
  124. _wpsf__( 'Enable Login Protect' ),
  125. _wpsf__( 'Enable (or Disable) The Login Protection Feature' ),
  126. _wpsf__( 'Regardless of any other settings, this option will turn off the Login Protect feature, or enable your selected Login Protect options' )
  127. ),
  128. array(
  129. 'enable_comments_filter',
  130. '',
  131. 'N',
  132. 'checkbox',
  133. _wpsf__( 'Enable Comments Filter' ),
  134. _wpsf__( 'Enable (or Disable) The Comments Filter Feature' ),
  135. _wpsf__( 'Regardless of any other settings, this option will turn off the Comments Filter feature, or enable your selected Comments Filter options' )
  136. ),
  137. // array(
  138. // 'enable_privacy_protect',
  139. // '',
  140. // 'N',
  141. // 'checkbox',
  142. // sprintf( _wpsf__( 'Enable %s' ), _wpsf__('Privacy Protection') ),
  143. // sprintf( _wpsf__( 'Enable (or Disable) The %s Feature' ), _wpsf__('Privacy Protection') ),
  144. // _wpsf__( 'Regardless of any other settings, this option will turn off the Privacy Protection feature, or enable your selected Privacy Protection options' ),
  145. // '<a href="http://icwp.io/3y" target="_blank">'._wpsf__( 'more info' ).'</a>'
  146. // ),
  147. array(
  148. 'enable_lockdown',
  149. '',
  150. 'N',
  151. 'checkbox',
  152. _wpsf__( 'Enable Lockdown' ),
  153. _wpsf__( 'Enable (or Disable) The Lockdown Feature' ),
  154. _wpsf__( 'Regardless of any other settings, this option will turn off the Lockdown feature, or enable your selected Lockdown options' )
  155. ),
  156. array(
  157. 'enable_autoupdates',
  158. '',
  159. 'Y',
  160. 'checkbox',
  161. _wpsf__( 'Enable Auto Updates' ),
  162. _wpsf__( 'Enable (or Disable) The Auto Updates Feature' ),
  163. _wpsf__( 'Regardless of any other settings, this option will turn off the Auto Updates feature, or enable your selected Auto Updates options' )
  164. )
  165. )
  166. );
  167. $this->m_aOptions = array(
  168. $aGeneral,
  169. // $aGlobal
  170. );
  171. if ( isset( $aAccessKey ) ) {
  172. array_unshift( $this->m_aOptions, $aAccessKey );
  173. }
  174. }
  175. /**
  176. * This is the point where you would want to do any options verification
  177. */
  178. protected function doPrePluginOptionsSave() {
  179. if ( $this->getOpt( 'admin_access_key_timeout' ) <= 0 ) {
  180. $this->setOpt( 'admin_access_key_timeout', self::Default_AccessKeyTimeout );
  181. }
  182. $sAccessKey = $this->getOpt( 'admin_access_key');
  183. if ( empty( $sAccessKey ) ) {
  184. $this->setOpt( 'enable_admin_access_restriction', 'N' );
  185. }
  186. $this->setOpt( 'enable_logging', 'Y' );
  187. $nInstalledAt = $this->getOpt( 'installation_time' );
  188. if ( empty($nInstalledAt) || $nInstalledAt <= 0 ) {
  189. $this->setOpt( 'installation_time', time() );
  190. }
  191. }
  192. }
  193. endif;