/admin/admin.php

  1. <?php 
  2. /** 
  3. * Plugin's admin options 
  4. * 
  5. * @package Gravity Forms Toolbar 
  6. * @subpackage Admin Options 
  7. * @author Milan Petrovic - Dev4Press 
  8. * @copyright Copyright (c) 2012-2014, Milan Petrovic - Dev4Press 
  9. * @license http://www.opensource.org/licenses/gpl-license.php GPL-2.0+ 
  10. * @link http://twitter.com/milangd 
  11. * 
  12. * @since 1.2.0 
  13. */ 
  14.  
  15. /** 
  16. * Exit if accessed directly. 
  17. * 
  18. * @since 1.6.0 
  19. */ 
  20. if ( ! defined( 'WPINC' ) ) { 
  21. exit( 'Sorry, you are not allowed to access this file directly.' ); 
  22.  
  23.  
  24. add_action( 'admin_menu', 'ddw_gftb_admin_menu' ); 
  25. /** 
  26. * Registrer plugin menu panel. 
  27. * 
  28. * @since 1.2.0 
  29. * 
  30. * @uses current_user_can() 
  31. * @uses add_options_page() 
  32. */ 
  33. function ddw_gftb_admin_menu() { 
  34.  
  35. /** Check for available Gravity Forms capabilities */ 
  36. $gftb_options_cap_check = current_user_can( 'gravityforms_edit_forms' ) ? 'gravityforms_edit_forms' : 'gform_full_access'; 
  37.  
  38. /** Set filter for options page capability */ 
  39. $gftb_options_capability = apply_filters( 'gftb_filter_options_capability', $gftb_options_cap_check ); 
  40.  
  41. /** Add the menu panel & options page */ 
  42. add_options_page( 
  43. __( 'Gravity Forms Toolbar', 'gravity-forms-toolbar' ),  
  44. __( 'Gravity Forms Toolbar', 'gravity-forms-toolbar' ),  
  45. esc_attr( $gftb_options_capability ),  
  46. 'ddw_gftb_options_page',  
  47. 'ddw_gftb_options_page' 
  48. ); 
  49.  
  50. } // end of function ddw_gftb_admin_menu 
  51.  
  52.  
  53. add_action( 'admin_init', 'ddw_gftb_admin_init' ); 
  54. /** 
  55. * Registrer settings for the plugin. 
  56. * 
  57. * @since 1.2.0 
  58. * 
  59. * @uses register_setting() 
  60. */ 
  61. function ddw_gftb_admin_init() { 
  62.  
  63. register_setting( 'ddw_gftb_options', 'ddw_gftb', 'ddw_gftb_options_validate' ); 
  64.  
  65. } // end of function ddw_gftb_admin_init 
  66.  
  67.  
  68. /** 
  69. * Validation of the options to save. 
  70. * 
  71. * @since 1.2.0 
  72. * 
  73. * @param array $input raw options data 
  74. * 
  75. * @return array valid options data 
  76. */ 
  77. function ddw_gftb_options_validate( $input ) { 
  78.  
  79. $default = ddw_gftb_default_options(); 
  80.  
  81. if ( ! isset( $input['toolbar_admin'] ) ) { 
  82. $default['toolbar_admin'] = false; 
  83.  
  84. if ( ! isset( $input['toolbar_frontend'] ) ) { 
  85. $default['toolbar_frontend'] = false; 
  86.  
  87. if ( ! isset( $input['help_and_support'] ) ) { 
  88. $default['help_and_support'] = false; 
  89.  
  90. if ( ! isset( $input['extensions'] ) ) { 
  91. $default['extensions'] = false; 
  92.  
  93. if ( ! isset( $input['forms_details'] ) ) { 
  94. $default['forms_details'] = false; 
  95.  
  96. if ( ! isset( $input['add_ons'] ) ) { 
  97. $default['add_ons'] = false; 
  98.  
  99. if ( ! isset( $input['update_notification'] ) ) { 
  100. $default['update_notification'] = false; 
  101.  
  102. if ( ! isset( $input['unread_notification'] ) ) { 
  103. $default['unread_notification'] = false; 
  104.  
  105. return $default; 
  106.  
  107. } // end of function ddw_gftb_options_validate 
  108.  
  109.  
  110. /** 
  111. * Include form 
  112. * 
  113. * @since 1.2.0 
  114. */ 
  115. function ddw_gftb_options_page() { 
  116.  
  117. include( GFTB_PLUGIN_DIR . '/admin/form.php' ); 
  118.  
  119. } // end of function ddw_gftb_options_page 
  120.  
  121.  
  122. /** 
  123. * Register & display "Settings updated" message when saving options. 
  124. * 
  125. * @since 1.0.0 
  126. * 
  127. * @uses add_settings_error() 
  128. * @uses settings_errors() 
  129. */ 
  130. function ddw_gftb_settings_message() { 
  131.  
  132. /** Register "Update" message */ 
  133. add_settings_error( 'gftb-notices', '', __( 'Toolbar Settings updated.', 'gravity-forms-toolbar' ), 'updated' ); 
  134.  
  135. /** Display message */ 
  136. settings_errors( 'gftb-notices' ); 
  137.  
  138. } // end of function ddw_gftb_settings_message 
.