| 1 |
<?php |
| 2 |
/** |
| 3 |
* WPPIZZA_MODULE_LAYOUT_GATEWAYS Class |
| 4 |
* |
| 5 |
* @package WPPIZZA |
| 6 |
* @subpackage WPPIZZA_MODULE_LAYOUT_GATEWAYS |
| 7 |
* @copyright Copyright (c) 2015, Oliver Bach |
| 8 |
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
| 9 |
* @since 3.0 |
| 10 |
* |
| 11 |
*/ |
| 12 |
if ( ! defined( 'ABSPATH' ) ) exit;/*Exit if accessed directly*/ |
| 13 |
|
| 14 |
|
| 15 |
/************************************************************************************************************************ |
| 16 |
* |
| 17 |
* |
| 18 |
* |
| 19 |
* |
| 20 |
* |
| 21 |
* |
| 22 |
************************************************************************************************************************/ |
| 23 |
class WPPIZZA_MODULE_LAYOUT_GATEWAYS{ |
| 24 |
|
| 25 |
private $settings_page = 'layout'; /* which admin subpage (identified there by this->class_key) are we adding this to */ |
| 26 |
|
| 27 |
private $section_key = 'gateway';/* must be unique */ |
| 28 |
|
| 29 |
|
| 30 |
function __construct() { |
| 31 |
/********************************************************** |
| 32 |
[add settings to admin] |
| 33 |
***********************************************************/ |
| 34 |
if(is_admin()){ |
| 35 |
/* add admin options settings page*/ |
| 36 |
add_filter('wppizza_filter_settings_sections_'.$this->settings_page.'', array($this, 'admin_options_settings'), 80, 5); |
| 37 |
/* add admin options settings page fields */ |
| 38 |
add_action('wppizza_admin_settings_section_fields_'.$this->settings_page.'', array($this, 'admin_options_fields_settings'), 10, 5); |
| 39 |
/**add default options **/ |
| 40 |
add_filter('wppizza_filter_setup_default_options', array( $this, 'options_default')); |
| 41 |
/**validate options**/ |
| 42 |
add_filter('wppizza_filter_options_validate', array( $this, 'options_validate'), 10, 2 ); |
| 43 |
/**add text header*/ |
| 44 |
//add_action('wppizza_settings_sections_header_'.$this->settings_page.'', array( $this, 'sections_header'), 10, 2 ); |
| 45 |
} |
| 46 |
} |
| 47 |
|
| 48 |
/******************************************************************************************************************************************************* |
| 49 |
* |
| 50 |
* |
| 51 |
* |
| 52 |
* [frontend filters] |
| 53 |
* |
| 54 |
* |
| 55 |
* |
| 56 |
********************************************************************************************************************************************************/ |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
/******************************************************************************************************************************************************* |
| 61 |
* |
| 62 |
* |
| 63 |
* |
| 64 |
* [add admin page options] |
| 65 |
* |
| 66 |
* |
| 67 |
* |
| 68 |
********************************************************************************************************************************************************/ |
| 69 |
|
| 70 |
/*------------------------------------------------------------------------------ |
| 71 |
# |
| 72 |
# |
| 73 |
# [settings page] |
| 74 |
# |
| 75 |
# |
| 76 |
------------------------------------------------------------------------------*/ |
| 77 |
|
| 78 |
/*------------------------------------------------------------------------------ |
| 79 |
# [settings section - setting page] |
| 80 |
# @since 3.0 |
| 81 |
# @return array() |
| 82 |
------------------------------------------------------------------------------*/ |
| 83 |
function admin_options_settings($settings, $sections, $fields, $inputs, $help){ |
| 84 |
|
| 85 |
/*section*/ |
| 86 |
if($sections){ |
| 87 |
$settings['sections'][$this->section_key] = __('Gateways', 'wppizza-admin'); |
| 88 |
} |
| 89 |
|
| 90 |
/*help*/ |
| 91 |
if($help){ |
| 92 |
} |
| 93 |
|
| 94 |
/*fields*/ |
| 95 |
if($fields){ |
| 96 |
|
| 97 |
$field = 'gateway_select_as_dropdown'; |
| 98 |
$settings['fields'][$this->section_key][$field] = array( __('Gateway choices as dropdowns', 'wppizza-admin') , array( |
| 99 |
'value_key'=>$field, |
| 100 |
'option_key'=>$this->settings_page, |
| 101 |
'label'=>__('Display Gateway choices as dropdowns instead of buttons. Only applicable if more than one gateway installed, activated and enabled', 'wppizza-admin'), |
| 102 |
'description'=>array() |
| 103 |
)); |
| 104 |
} |
| 105 |
|
| 106 |
return $settings; |
| 107 |
} |
| 108 |
/*------------------------------------------------------------------------------ |
| 109 |
# [output option fields - setting page] |
| 110 |
# @since 3.0 |
| 111 |
# @return array() |
| 112 |
------------------------------------------------------------------------------*/ |
| 113 |
function admin_options_fields_settings($wppizza_options, $options_key, $field, $label, $description){ |
| 114 |
|
| 115 |
if($field=='gateway_select_as_dropdown' ){ |
| 116 |
print'<label>'; |
| 117 |
echo "<input id='".$field."' name='".WPPIZZA_SLUG."[".$options_key."][".$field."]' type='checkbox' ". checked($wppizza_options['layout'][$field],true,false)." value='1' />"; |
| 118 |
print'' . $label . ''; |
| 119 |
print'</label>'; |
| 120 |
print'' . $description . ''; |
| 121 |
} |
| 122 |
} |
| 123 |
|
| 124 |
/**************************************************************** |
| 125 |
* |
| 126 |
* [insert default option on install] |
| 127 |
* $parameter $options array() | filter passing on filtered options |
| 128 |
* @since 3.0 |
| 129 |
* @return array() |
| 130 |
* |
| 131 |
****************************************************************/ |
| 132 |
function options_default($options){ |
| 133 |
|
| 134 |
$options[$this->settings_page]['gateway_select_as_dropdown'] = false; |
| 135 |
|
| 136 |
return $options; |
| 137 |
} |
| 138 |
|
| 139 |
/*------------------------------------------------------------------------------ |
| 140 |
# [validate options on save/update] |
| 141 |
# |
| 142 |
# @since 3.0 |
| 143 |
# @return array() |
| 144 |
------------------------------------------------------------------------------*/ |
| 145 |
function options_validate($options, $input){ |
| 146 |
/**make sure we get the full array on install/update**/ |
| 147 |
if ( empty( $_POST['_wp_http_referer'] ) ) { |
| 148 |
return $input; |
| 149 |
} |
| 150 |
if(isset($_POST[''.WPPIZZA_SLUG.'_'.$this->settings_page.''])){ |
| 151 |
|
| 152 |
$options[$this->settings_page]['gateway_select_as_dropdown'] = !empty($input[$this->settings_page]['gateway_select_as_dropdown']) ? true : false; |
| 153 |
} |
| 154 |
|
| 155 |
return $options; |
| 156 |
} |
| 157 |
} |
| 158 |
/*************************************************************** |
| 159 |
* |
| 160 |
* [ini] |
| 161 |
* |
| 162 |
***************************************************************/ |
| 163 |
$WPPIZZA_MODULE_LAYOUT_GATEWAYS = new WPPIZZA_MODULE_LAYOUT_GATEWAYS(); |
| 164 |
?> |