/includes/eoi-powerups.php

  1. <?php 
  2. // 
  3. // Handle Powerups / Settings page  
  4. // 
  5.  
  6. // Load all powerups 
  7. foreach ( glob( FCA_EOI_PLUGIN_DIR . 'powerups/*', GLOB_ONLYDIR ) as $powerup_path ) {  
  8. require_once "$powerup_path/powerup.php"; 
  9. } 
  10.   
  11. function fca_eoi_register_setting_page() { 
  12. add_submenu_page( 
  13. 'edit.php?post_type=easy-opt-ins',  
  14. __('Settings', 'easy-opt-ins'),  
  15. __('Settings', 'easy-opt-ins'),  
  16. 'manage_options',  
  17. 'fca_eoi_settings_page',  
  18. 'fca_eoi_settings_page' 
  19. ); 
  20.  
  21. } 
  22. add_action('admin_menu', 'fca_eoi_register_setting_page'); 
  23.   
  24. function fca_eoi_register_settings() { 
  25. global $dh_easy_opt_ins_plugin; 
  26. $fca_eoi_options = get_option( 'fca_eoi_settings' ); 
  27. if( !$fca_eoi_options ) {  
  28. add_option( 'fca_eoi_settings' ); 
  29. } 
  30.  
  31. if ( $dh_easy_opt_ins_plugin->distro != 'free' ) { 
  32.  
  33. add_settings_section( 'fca_eoi_license_settings_section', __('License', 'easy-opt-ins'), false, 'fca_eoi_settings_page' );  
  34.  
  35. } 
  36.   
  37. add_settings_section( 'fca_eoi_powerup_settings_section', __('Powerups', 'easy-opt-ins'), false, 'fca_eoi_settings_page' ); 
  38.  
  39. $option_fields = apply_filters( 'fca_eoi_setting_filter', array() ); 
  40.  
  41. foreach( $option_fields as $option ) { 
  42. $id = empty ( $option[0] ) ? '' : $option[0]; 
  43. $friendly_text = empty ( $option[1] ) ? '' : $option[1]; 
  44. $callback_function = empty ( $option[2] ) ? '' : $option[2]; 
  45. $setting_heading = empty ( $option[3] ) ? '' : $option[3]; 
  46.  
  47.  
  48. add_settings_field( "fca_eoi_settings[$id]", $friendly_text, $callback_function, 'fca_eoi_settings_page', $setting_heading, $option); 
  49. } 
  50.  
  51. register_setting( 'fca_eoi_main_settings', 'fca_eoi_settings', 'fca_eoi_settings_sanitize_callback' );  
  52.  
  53. } 
  54. add_action('admin_init', 'fca_eoi_register_settings'); 
  55.   
  56. function fca_eoi_settings_sanitize_callback( $data ) { 
  57.  
  58. $status = get_option( 'fca_eoi_license_status' ); 
  59. $settings = get_option( 'fca_eoi_settings' ); 
  60.  
  61. $deactivate = empty( $data['fca_eoi_license_deactivate'] ) ? false : true; 
  62. $data['license_key'] = empty( $data['license_key'] ) ? '' : trim( esc_textarea ( $data['license_key'] ) ); 
  63. if ( $deactivate ) { 
  64. $key = !empty($settings['license_key']) ? $settings['license_key'] : $data['license_key']; 
  65. fca_eoi_deactivate_license( $key ); 
  66. $data['license_key'] = ''; 
  67. } else if ( $status != 'valid' && !empty( $data['license_key'] ) ) { 
  68. fca_eoi_activate_license( $data['license_key'] ); 
  69. } 
  70. return $data; 
  71. } 
  72.   
  73. function fca_eoi_checkbox_callback( $args ) { 
  74. $option_name = $args[0]; 
  75.   
  76. $options = get_option( 'fca_eoi_settings' ); 
  77.  
  78. $help_text = empty( $args[4] ) ? '' : $args[4]; 
  79.  
  80. /***** SET TO DEFAULT IF THIS OPTION HAS NEVER BEEN SET *****/ 
  81.  
  82. if ( !isset ( $options[ $option_name ] ) ) { 
  83. $options[ $option_name ] = 0; 
  84.  
  85. $html = "<div class='onoffswitch'>"; 
  86. $html .= "<input type='checkbox' class='onoffswitch-checkbox' id='fca_eoi_settings[$option_name]' style='display:none;' name='fca_eoi_settings[$option_name]' value='1' " . checked( 1, $options[ $option_name ], false ) . '/>'; 
  87. $html .= "<label class='onoffswitch-label' for='fca_eoi_settings[$option_name]'><span class='onoffswitch-inner' data-content-on='".__('ON', 'easy-opt-ins')."' data-content-off='".__('OFF', 'easy-opt-ins')."'><span class='onoffswitch-switch'></span></span></label>"; 
  88. $html .= "</div>"; 
  89. $html .= "<p class='fca_eoi_help_text'>$help_text</p>"; 
  90.  
  91. echo $html; 
  92.  
  93. function fca_eoi_text_box_callback( $args ) { 
  94.  
  95. $option_name = $args[0]; 
  96.  
  97. $placeholder = empty( $args[1] ) ? '' : $args[1]; 
  98.  
  99. $help_text = empty( $args[2] ) ? '' : $args[2]; 
  100.  
  101. $options = get_option( 'fca_eoi_settings' ); 
  102.  
  103. /***** SET TO DEFAULT IF THIS OPTION HAS NEVER BEEN SET *****/ 
  104.  
  105. if ( !isset ( $options[ $option_name ] ) ) { 
  106. $value = $options[ $option_name ] = ''; 
  107. }else { 
  108. $value = esc_textarea( $options[ $option_name ] ); 
  109.  
  110. $html = "<input type='text' class='fca_eoi_settings_text_input' id='fca_eoi_settings[$option_name]' name='fca_eoi_settings[$option_name]' value='$value' placeholder='$placeholder' />";  
  111.  
  112. $html .= "<p class='fca_eoi_help_text'>$help_text</p>"; 
  113.  
  114. echo $html; 
  115.  
  116. function fca_eoi_settings_page() { 
  117.  
  118. wp_enqueue_style( 'fca_eoi_settings_page_css', FCA_EOI_PLUGIN_URL . '/assets/powerups/powerup-page.min.css', array(), FCA_EOI_VER ); 
  119. wp_enqueue_script( 'fca_eoi_settings_page_js', FCA_EOI_PLUGIN_URL . '/assets/powerups/powerup-page.min.js', array(), FCA_EOI_VER, true ); 
  120. do_action('fca_eoi_setting_page_enqueue'); 
  121.  
  122. ob_start(); ?> 
  123. <form method='post' action='options.php' id='fca_eoi_save_settings_form'> 
  124.  
  125. <?php  
  126. settings_fields( 'fca_eoi_main_settings' ); 
  127. do_settings_sections( 'fca_eoi_settings_page' ); 
  128. ?> 
  129.  
  130. <input type="submit" name="submit" id="submit" class="button button-primary" value="<?php _e('Save', 'easy-opt-ins')?>" /> 
  131.  
  132. </form> 
  133. <?php  
  134. echo ob_get_clean(); 
  135.  
.