| 1 |
<?php |
| 2 |
/** |
| 3 |
* WPPIZZA_MODULE_SETTINGS_LOGGING Class |
| 4 |
* |
| 5 |
* @package WPPIZZA |
| 6 |
* @subpackage WPPIZZA_MODULE_SETTINGS_LOGGING |
| 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_SETTINGS_LOGGING{ |
| 24 |
|
| 25 |
private $settings_page = 'settings';/* which admin subpage (identified there by this->class_key) are we adding this to */ |
| 26 |
|
| 27 |
|
| 28 |
private $section_key = 'logging';/* must be unique */ |
| 29 |
|
| 30 |
|
| 31 |
function __construct() { |
| 32 |
/********************************************************** |
| 33 |
[add settings to admin] |
| 34 |
***********************************************************/ |
| 35 |
if(is_admin()){ |
| 36 |
/* add admin options settings page*/ |
| 37 |
add_filter('wppizza_filter_settings_sections_'.$this->settings_page.'', array($this, 'admin_options_settings'), 90, 5); |
| 38 |
/* add admin options settings page fields */ |
| 39 |
add_action('wppizza_admin_settings_section_fields_'.$this->settings_page.'', array($this, 'admin_options_fields_settings'), 10, 5); |
| 40 |
/**add default options **/ |
| 41 |
add_filter('wppizza_filter_setup_default_options', array( $this, 'options_default')); |
| 42 |
/**validate options**/ |
| 43 |
add_filter('wppizza_filter_options_validate', array( $this, 'options_validate'), 10, 2 ); |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
/******************************************************************************************************************************************************* |
| 49 |
* |
| 50 |
* |
| 51 |
* |
| 52 |
* [add admin page options] |
| 53 |
* |
| 54 |
* |
| 55 |
* |
| 56 |
********************************************************************************************************************************************************/ |
| 57 |
|
| 58 |
/*------------------------------------------------------------------------------ |
| 59 |
# |
| 60 |
# |
| 61 |
# [settings page] |
| 62 |
# |
| 63 |
# |
| 64 |
------------------------------------------------------------------------------*/ |
| 65 |
|
| 66 |
/*------------------------------------------------------------------------------ |
| 67 |
# [settings section - setting page] |
| 68 |
# @since 3.0 |
| 69 |
# @return array() |
| 70 |
------------------------------------------------------------------------------*/ |
| 71 |
function admin_options_settings($settings, $sections, $fields, $inputs, $help){ |
| 72 |
|
| 73 |
/*section*/ |
| 74 |
if($sections){ |
| 75 |
$settings['sections'][$this->section_key] = __('Logging', 'wppizza-admin'); |
| 76 |
} |
| 77 |
/*help*/ |
| 78 |
if($help){ |
| 79 |
$settings['help'][$this->section_key][] = array( |
| 80 |
'label'=>__('Logging Options', 'wppizza-admin'), |
| 81 |
'description'=>array( |
| 82 |
__('Please adjust settings as appropriate according to the information provided next to each individual option.', 'wppizza-admin') |
| 83 |
) |
| 84 |
); |
| 85 |
} |
| 86 |
/*fields*/ |
| 87 |
if($fields){ |
| 88 |
$field = 'log_failed_orders'; |
| 89 |
$settings['fields'][$this->section_key][$field] = array( __('Log failed orders', 'wppizza-admin'), array( |
| 90 |
'value_key'=>$field, |
| 91 |
'option_key'=>$this->settings_page, |
| 92 |
'label'=>__('Do you wish to enable error logging ? [logfiles will be located in the /logs/ directory]', 'wppizza-admin'), |
| 93 |
'description'=>array() |
| 94 |
)); |
| 95 |
$field = 'send_failed_orders_to_admin'; |
| 96 |
$settings['fields'][$this->section_key][$field] = array( __('Errors to admin email', 'wppizza-admin'), array( |
| 97 |
'value_key'=>$field, |
| 98 |
'option_key'=>$this->settings_page, |
| 99 |
'label'=>__('It might be a good idea to have all non-verified transactions or other transaction errors sent to your administrators email address to investigate. You can turn this off if you are happy everything works. If you enable logging, all those occurences will be logged regardless.', 'wppizza-admin').'<br/><span class="wppizza-highlight">'.__('Note: Critical errors will always be sent to admin email, regardless of the settings here', 'wppizza-admin').'</span>', |
| 100 |
'description'=>array() |
| 101 |
)); |
| 102 |
$field = 'log_successful_orders'; |
| 103 |
$settings['fields'][$this->section_key][$field] = array( __('Log successful orders', 'wppizza-admin'), array( |
| 104 |
'value_key'=>$field, |
| 105 |
'option_key'=>$this->settings_page, |
| 106 |
'label'=>__('If you wish, enable this to log all successful orders too. [logfiles will be located in the /logs/ directory]', 'wppizza-admin'), |
| 107 |
'description'=>array() |
| 108 |
)); |
| 109 |
|
| 110 |
} |
| 111 |
|
| 112 |
return $settings; |
| 113 |
} |
| 114 |
/*------------------------------------------------------------------------------ |
| 115 |
# [output option fields - setting page] |
| 116 |
# @since 3.0 |
| 117 |
# @return array() |
| 118 |
------------------------------------------------------------------------------*/ |
| 119 |
function admin_options_fields_settings($wppizza_options, $options_key, $field, $label, $description){ |
| 120 |
|
| 121 |
if($field=='log_failed_orders'){ |
| 122 |
echo "<label>"; |
| 123 |
echo "<input id='".$field."' name='".WPPIZZA_SLUG."[".$options_key."][".$field."]' type='checkbox' ". checked($wppizza_options[$options_key][$field],true,false)." value='1' />"; |
| 124 |
echo "" . $label . ""; |
| 125 |
echo "</label>"; |
| 126 |
echo"".$description.""; |
| 127 |
} |
| 128 |
|
| 129 |
if($field=='send_failed_orders_to_admin'){ |
| 130 |
echo "<label>"; |
| 131 |
echo "<input id='".$field."' name='".WPPIZZA_SLUG."[".$options_key."][".$field."]' type='checkbox' ". checked($wppizza_options[$options_key][$field],true,false)." value='1' />"; |
| 132 |
echo "" . $label . ""; |
| 133 |
echo "</label>"; |
| 134 |
echo"".$description.""; |
| 135 |
} |
| 136 |
|
| 137 |
if($field=='log_successful_orders'){ |
| 138 |
echo "<label>"; |
| 139 |
echo "<input id='".$field."' name='".WPPIZZA_SLUG."[".$options_key."][".$field."]' type='checkbox' ". checked($wppizza_options[$options_key][$field],true,false)." value='1' />"; |
| 140 |
echo "" . $label . ""; |
| 141 |
echo "</label>"; |
| 142 |
echo"".$description.""; |
| 143 |
} |
| 144 |
|
| 145 |
} |
| 146 |
/*------------------------------------------------------------------------------ |
| 147 |
# [insert default option on install] |
| 148 |
# $parameter $options array() | filter passing on filtered options |
| 149 |
# @since 3.0 |
| 150 |
# @return array() |
| 151 |
------------------------------------------------------------------------------*/ |
| 152 |
function options_default($options){ |
| 153 |
|
| 154 |
$options[$this->settings_page]['log_failed_orders'] = true; |
| 155 |
$options[$this->settings_page]['send_failed_orders_to_admin'] = true; |
| 156 |
$options[$this->settings_page]['log_successful_orders'] = false; |
| 157 |
|
| 158 |
return $options; |
| 159 |
} |
| 160 |
|
| 161 |
/*------------------------------------------------------------------------------ |
| 162 |
# [validate options on save/update] |
| 163 |
# |
| 164 |
# @since 3.0 |
| 165 |
# @return array() |
| 166 |
------------------------------------------------------------------------------*/ |
| 167 |
function options_validate($options, $input){ |
| 168 |
/**make sure we get the full array on install/update**/ |
| 169 |
if ( empty( $_POST['_wp_http_referer'] ) ) { |
| 170 |
return $input; |
| 171 |
} |
| 172 |
/******************************** |
| 173 |
* [validate] |
| 174 |
********************************/ |
| 175 |
if(isset($_POST[''.WPPIZZA_SLUG.'_'.$this->settings_page.''])){ |
| 176 |
$options[$this->settings_page]['log_failed_orders'] = !empty($input[$this->settings_page]['log_failed_orders']) ? true : false; |
| 177 |
$options[$this->settings_page]['send_failed_orders_to_admin'] = !empty($input[$this->settings_page]['send_failed_orders_to_admin']) ? true : false; |
| 178 |
$options[$this->settings_page]['log_successful_orders'] = !empty($input[$this->settings_page]['log_successful_orders']) ? true : false; |
| 179 |
} |
| 180 |
return $options; |
| 181 |
} |
| 182 |
} |
| 183 |
/*************************************************************** |
| 184 |
* |
| 185 |
* [ini] |
| 186 |
* |
| 187 |
***************************************************************/ |
| 188 |
$WPPIZZA_MODULE_SETTINGS_LOGGING = new WPPIZZA_MODULE_SETTINGS_LOGGING(); |
| 189 |
?> |