| 1 |
<?php |
| 2 |
/** |
| 3 |
* WPPIZZA_MANAGE_GATEWAYS Class |
| 4 |
* |
| 5 |
* @package WPPIZZA |
| 6 |
* @subpackage Classes / Admin-Subpages / Manage 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 |
* WPPIZZA_MANAGE_GATEWAYS to GATEWAYS subpages |
| 19 |
* |
| 20 |
* |
| 21 |
************************************************************************************************************************/ |
| 22 |
class WPPIZZA_MANAGE_GATEWAYS{ |
| 23 |
|
| 24 |
/* |
| 25 |
* class ident |
| 26 |
* @var str |
| 27 |
* @since 3.0 |
| 28 |
*/ |
| 29 |
private $class_key='gateways';/*to help consistency throughout class in various places*/ |
| 30 |
|
| 31 |
/* |
| 32 |
* class gatyeways registered |
| 33 |
* @var str |
| 34 |
* @since 3.0 |
| 35 |
*/ |
| 36 |
private $gateways; |
| 37 |
|
| 38 |
/* |
| 39 |
* titles/lables |
| 40 |
* @var str |
| 41 |
* @since 3.0 |
| 42 |
*/ |
| 43 |
private $submenu_page_header; |
| 44 |
private $submenu_page_title; |
| 45 |
private $submenu_caps_title; |
| 46 |
private $submenu_link_label; |
| 47 |
private $submenu_priority = 40; |
| 48 |
function __construct() { |
| 49 |
|
| 50 |
/*titles/labels throughout class*/ |
| 51 |
add_action('init', array( $this, 'init_admin_lables') ); |
| 52 |
|
| 53 |
/** registering submenu page -> priority 40 **/ |
| 54 |
add_action('admin_menu', array( $this, 'wppizza_register_submenu_page'), $this->submenu_priority ); |
| 55 |
|
| 56 |
/*register capabilities for this page*/ |
| 57 |
add_filter('wppizza_filter_define_caps', array( $this, 'wppizza_filter_define_caps'), $this->submenu_priority); |
| 58 |
|
| 59 |
/*execute some helper functions once to use their return multiple times */ |
| 60 |
add_action('current_screen', array( $this, 'wppizza_add_helpers') ); |
| 61 |
|
| 62 |
/**validate options**/ |
| 63 |
add_filter('wppizza_filter_options_validate', array( $this, 'options_validate'), 10, 2 ); |
| 64 |
|
| 65 |
/**load admin ajax file**/ |
| 66 |
add_action('wp_ajax_wppizza_admin_'.$this->class_key.'_ajax', array($this, 'set_admin_ajax') ); |
| 67 |
} |
| 68 |
|
| 69 |
/****************** |
| 70 |
* @since 3.0.26 |
| 71 |
* [admin ajax include file] |
| 72 |
*******************/ |
| 73 |
public function init_admin_lables(){ |
| 74 |
$this->submenu_page_header = apply_filters('wppizza_filter_admin_label_page_header_'.$this->class_key.'', __('Gateways','wppizza-admin')); |
| 75 |
$this->submenu_page_title = apply_filters('wppizza_filter_admin_label_page_title_'.$this->class_key.'', __('Manage Gateways','wppizza-admin')); |
| 76 |
$this->submenu_caps_title = apply_filters('wppizza_filter_admin_label_caps_title_'.$this->class_key.'', __('Gateways','wppizza-admin')); |
| 77 |
$this->submenu_link_label = apply_filters('wppizza_filter_admin_label_link_label_'.$this->class_key.'', __('· Gateways','wppizza-admin')); |
| 78 |
} |
| 79 |
/****************** |
| 80 |
* @since 3.0 |
| 81 |
* [admin ajax include file] |
| 82 |
*******************/ |
| 83 |
public function set_admin_ajax(){ |
| 84 |
require(WPPIZZA_PATH.'ajax/admin.ajax.wppizza.php'); |
| 85 |
die(); |
| 86 |
} |
| 87 |
|
| 88 |
/********************************************************* |
| 89 |
* |
| 90 |
* [add helpers] |
| 91 |
* @since 3.0 |
| 92 |
* |
| 93 |
* run on this page only or if saving this page |
| 94 |
($_POST[WPPIZZA_SLUG.'_'.$this->class_key]) |
| 95 |
*********************************************************/ |
| 96 |
function wppizza_add_helpers($current_screen){ |
| 97 |
|
| 98 |
if($current_screen->id == 'options' && isset($_POST[''.WPPIZZA_POST_TYPE.'_'.$this->class_key.''])){ |
| 99 |
/** return capabilities when saving options **/ |
| 100 |
add_filter( 'option_page_capability_'.WPPIZZA_SLUG.'', array($this, 'admin_option_page_capability' )); |
| 101 |
} |
| 102 |
|
| 103 |
if( !empty($_POST[WPPIZZA_SLUG.'_'.$this->class_key]) || ($current_screen->id == ''.WPPIZZA_POST_TYPE.'_page_'.$this->class_key.'' && $current_screen->post_type == WPPIZZA_POST_TYPE)){ |
| 104 |
|
| 105 |
/**add registered gateways to class object**/ |
| 106 |
$this->gateways=WPPIZZA()->register_gateways; |
| 107 |
|
| 108 |
if($current_screen->id!='options'){ |
| 109 |
/**admin settings sections**/ |
| 110 |
$this->wppizza_admin_settings_sections(); |
| 111 |
} |
| 112 |
|
| 113 |
/***enqueue scripts and styles***/ |
| 114 |
add_action('admin_enqueue_scripts', array( $this, 'wppizza_enqueue_admin_scripts_and_styles')); |
| 115 |
|
| 116 |
} |
| 117 |
} |
| 118 |
/********************************************************* |
| 119 |
* |
| 120 |
* [class helpers] |
| 121 |
* @since 3.0 |
| 122 |
* |
| 123 |
*********************************************************/ |
| 124 |
public function wppizza_enqueue_admin_scripts_and_styles($hook) { |
| 125 |
|
| 126 |
/************ |
| 127 |
css |
| 128 |
***********/ |
| 129 |
|
| 130 |
/** chosen **/ |
| 131 |
wp_register_style(WPPIZZA_SLUG.'-chosen', plugins_url( 'css/wppizza-chosen.min.css', WPPIZZA_PLUGIN_PATH ), array(), WPPIZZA_VERSION); |
| 132 |
wp_enqueue_style(WPPIZZA_SLUG.'-chosen'); |
| 133 |
|
| 134 |
/************ |
| 135 |
js |
| 136 |
***********/ |
| 137 |
|
| 138 |
/** chosen **/ |
| 139 |
wp_register_script(WPPIZZA_SLUG.'-chosen', plugins_url( 'js/chosen.jquery.min.js', WPPIZZA_PLUGIN_PATH ), array('jquery'), WPPIZZA_VERSION ,true); |
| 140 |
wp_enqueue_script(WPPIZZA_SLUG.'-chosen'); |
| 141 |
|
| 142 |
|
| 143 |
wp_register_script(WPPIZZA_SLUG.'_'.$this->class_key.'', plugins_url( 'js/scripts.admin.'.$this->class_key.'.js', WPPIZZA_PLUGIN_PATH ), array('jquery'), WPPIZZA_VERSION ,true); |
| 144 |
wp_enqueue_script(WPPIZZA_SLUG.'_'.$this->class_key.''); |
| 145 |
} |
| 146 |
/********************************************************* |
| 147 |
* |
| 148 |
* [set settings section(s)] |
| 149 |
* @parameter $sections bool -> return sections |
| 150 |
* @parameter $fields bool -> return fields |
| 151 |
* @since 3.0 |
| 152 |
* @return array |
| 153 |
* |
| 154 |
*********************************************************/ |
| 155 |
private function wppizza_get_settings($sections=true, $fields=false, $inputs=false, $help=false){ |
| 156 |
|
| 157 |
/**ini setiings array**/ |
| 158 |
$settings=array(); |
| 159 |
/**gateway count**/ |
| 160 |
$gateway_count=count((array)$this->gateways->registered_gateways); |
| 161 |
|
| 162 |
/**sort gateway display order by sort flag **/ |
| 163 |
$registered_gatewy_sort=array(); |
| 164 |
foreach($this->gateways->registered_gateways as $reg_gateway_ident=>$reg_gateway_values){ |
| 165 |
$sort=$reg_gateway_values->gatewayOptions['_gateway_sortorder']; |
| 166 |
$registered_gatewy_sort[$reg_gateway_ident]=$sort; |
| 167 |
} |
| 168 |
asort($registered_gatewy_sort); |
| 169 |
|
| 170 |
|
| 171 |
/******************************** |
| 172 |
* [include sorted gateways as sections] |
| 173 |
********************************/ |
| 174 |
foreach($registered_gatewy_sort as $ident=>$sort){ |
| 175 |
|
| 176 |
/**get whole gateway object*/ |
| 177 |
$gateway_object=$this->gateways->registered_gateways->$ident; |
| 178 |
|
| 179 |
/*sections*/ |
| 180 |
if($sections){ |
| 181 |
$args=array(); |
| 182 |
$args['ident']=$gateway_object->gatewayIdent; |
| 183 |
$args['option_name']=$gateway_object->gatewayOptionName; |
| 184 |
$args['addinfo']=$gateway_object->gatewayAdditionalInfo; |
| 185 |
$args['admininfo']=!empty($gateway_object->gatewayDescription) ? $gateway_object->gatewayDescription : '' ; |
| 186 |
|
| 187 |
/* |
| 188 |
section(gateway) parameters |
| 189 |
gateway label - concat |
| 190 |
*/ |
| 191 |
$gatewayName = ''; |
| 192 |
$gatewayName .= !empty($gateway_object->gatewayPrefix) ? $gateway_object->gatewayPrefix.' ' : '' ; |
| 193 |
$gatewayName .= $gateway_object->gatewayName; |
| 194 |
$gatewayName .= !empty($gateway_object->gatewaySuffix) ? ' '.$gateway_object->gatewaySuffix : '' ; |
| 195 |
|
| 196 |
|
| 197 |
$settings['sections'][$gateway_object->gatewayIdent] = array( |
| 198 |
'ident'=>$gateway_object->gatewayIdent, |
| 199 |
'name'=>$gatewayName, |
| 200 |
'arg'=>$args |
| 201 |
); |
| 202 |
|
| 203 |
} |
| 204 |
/*fields*/ |
| 205 |
if($fields){ |
| 206 |
foreach($gateway_object->gatewaySettings as $options_key=>$options_value){ |
| 207 |
/**if settings section, add to args**/ |
| 208 |
$args['gateway_name']=$gateway_object->gatewayName; |
| 209 |
$args['gateway_options_name']=$gateway_object->gatewayOptionName; |
| 210 |
$args['option_key']=$options_key; |
| 211 |
$args['settings']=!empty($gateway_object->gatewaySettings[$options_key]) ? $gateway_object->gatewaySettings[$options_key] : array(); |
| 212 |
$args['value']=$options_value; |
| 213 |
$args['gateway_count']=$gateway_count; |
| 214 |
/**settings**/ |
| 215 |
$settings['fields'][$gateway_object->gatewayIdent][$options_key] = array('options_key'=>$options_key, 'label'=>'', 'section'=>$gateway_object->gatewayIdent, 'args'=>$args); |
| 216 |
} |
| 217 |
} |
| 218 |
} |
| 219 |
|
| 220 |
|
| 221 |
/** |
| 222 |
allow filtering of settings sections |
| 223 |
do add additional if required |
| 224 |
**/ |
| 225 |
//$settings=apply_filters('wppizza_filter_settings_sections_'.$this->class_key.'', $settings, $sections, $fields, $inputs, $help); |
| 226 |
|
| 227 |
return $settings; |
| 228 |
} |
| 229 |
|
| 230 |
|
| 231 |
/**************************************************************** |
| 232 |
* |
| 233 |
* [validate options on save/update] |
| 234 |
* @since 3.0 |
| 235 |
* @return array() |
| 236 |
* |
| 237 |
****************************************************************/ |
| 238 |
function options_validate($options, $input){ |
| 239 |
|
| 240 |
/**just get the full array on install/update**/ |
| 241 |
if ( empty( $_POST['_wp_http_referer'] ) ) { |
| 242 |
return $input; |
| 243 |
} |
| 244 |
|
| 245 |
if(isset($_POST[''.WPPIZZA_SLUG.'_'.$this->class_key.''])){ |
| 246 |
|
| 247 |
|
| 248 |
/*ini array*/ |
| 249 |
$gateway_options=array(); |
| 250 |
|
| 251 |
/**ini array for main wppizza options value**/ |
| 252 |
$wppizza_options_gateways=array(); |
| 253 |
|
| 254 |
/*** |
| 255 |
loop through gateways and validate options |
| 256 |
***/ |
| 257 |
foreach($this->gateways->registered_gateways as $gateway_ident=>$gateway_values){ |
| 258 |
|
| 259 |
/**db option name**/ |
| 260 |
$gateway_db_option_name=$gateway_values->gatewayOptionName; |
| 261 |
/*get currently set options*/ |
| 262 |
$gateway_options[$gateway_db_option_name]=array();//=get_option($gateway_db_option_name,0); |
| 263 |
|
| 264 |
/**distinctly save version no*/ |
| 265 |
$gateway_options[$gateway_db_option_name]['_gateway_version'] = $gateway_values->gatewayVersion; |
| 266 |
/**distinctly save enabled*/ |
| 267 |
$gateway_options[$gateway_db_option_name]['_gateway_enabled'] = !empty($input['gateways'][$gateway_db_option_name]['_gateway_enabled']) ? true : false; |
| 268 |
|
| 269 |
/** |
| 270 |
[validate individual settings for this gateway] |
| 271 |
**/ |
| 272 |
$gateway_settings=$gateway_values->gatewaySettings; |
| 273 |
|
| 274 |
foreach($gateway_settings as $option_key=>$option_settings_values){ |
| 275 |
|
| 276 |
|
| 277 |
$to_validate=!empty($input['gateways'][$gateway_db_option_name][$option_key]) ? $input['gateways'][$gateway_db_option_name][$option_key] : '' ; |
| 278 |
|
| 279 |
/** |
| 280 |
callback defined |
| 281 |
**/ |
| 282 |
if(!empty($option_settings_values['validateCallback'])){ |
| 283 |
|
| 284 |
/** |
| 285 |
callback is a simple function name, |
| 286 |
not an array |
| 287 |
**/ |
| 288 |
if(!is_array($option_settings_values['validateCallback'])){ |
| 289 |
$val=$option_settings_values['validateCallback']($to_validate); |
| 290 |
} |
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
/** |
| 295 |
callback is an array using inbuilt |
| 296 |
wppizza validation function (first parameter being a string / the function name) |
| 297 |
**/ |
| 298 |
if(is_array($option_settings_values['validateCallback']) && is_string($option_settings_values['validateCallback'][0])){ |
| 299 |
/**the number of parameters passed could be done more intelligently, but up to 3 will do for now**/ |
| 300 |
if(count($option_settings_values['validateCallback'])==2){ |
| 301 |
$val=$option_settings_values['validateCallback'][0]($to_validate, $option_settings_values['validateCallback'][1]); |
| 302 |
} |
| 303 |
if(count($option_settings_values['validateCallback'])==3){ |
| 304 |
$val=$option_settings_values['validateCallback'][0]($to_validate, $option_settings_values['validateCallback'][1], $option_settings_values['validateCallback'][2]); |
| 305 |
} |
| 306 |
if(count($option_settings_values['validateCallback'])==4){ |
| 307 |
$val=$option_settings_values['validateCallback'][0]($to_validate, $option_settings_values['validateCallback'][1], $option_settings_values['validateCallback'][2], $option_settings_values['validateCallback'][3]); |
| 308 |
} |
| 309 |
|
| 310 |
} |
| 311 |
|
| 312 |
/** |
| 313 |
callback is an array using classes own validation function |
| 314 |
(first parameter being an array like array(__CLASS__,'function_name'), second being an array of passed parameters) |
| 315 |
**/ |
| 316 |
if(is_array($option_settings_values['validateCallback']) && is_array($option_settings_values['validateCallback'][0])){ |
| 317 |
$parameters=!empty($option_settings_values['validateCallback'][1]) ? $option_settings_values['validateCallback'][1] : null; |
| 318 |
$class = new $option_settings_values['validateCallback'][0][0]; |
| 319 |
$method = $option_settings_values['validateCallback'][0][1]; |
| 320 |
$val = $class -> $method($parameters); |
| 321 |
} |
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
} |
| 326 |
/** |
| 327 |
no callback defined, just insert input or false if not set |
| 328 |
**/ |
| 329 |
if(empty($option_settings_values['validateCallback'])){ |
| 330 |
$val=!empty($to_validate) ? esc_sql($to_validate) : false; |
| 331 |
} |
| 332 |
|
| 333 |
/** |
| 334 |
do not allow empty label, but use gatewayName if empty |
| 335 |
**/ |
| 336 |
if($option_key == '_gateway_label' && trim($val)==''){ |
| 337 |
$val = $gateway_values->gatewayName; |
| 338 |
} |
| 339 |
|
| 340 |
/***add to array**/ |
| 341 |
$gateway_options[$gateway_db_option_name][$option_key] = $val;//$val; |
| 342 |
} |
| 343 |
|
| 344 |
|
| 345 |
/*filter*/ |
| 346 |
$gateway_options[$gateway_db_option_name]=apply_filters('wppizza_filter_gateway_options_validate_'.strtolower($gateway_ident).'', $gateway_options[$gateway_db_option_name]); |
| 347 |
|
| 348 |
/********* |
| 349 |
[add/set options for main wppizza option value if enabled] |
| 350 |
*********/ |
| 351 |
if($gateway_options[$gateway_db_option_name]['_gateway_enabled']){ |
| 352 |
$wppizza_options_gateways[$gateway_ident]=array('sort'=>$gateway_options[$gateway_db_option_name]['_gateway_sortorder'], 'ident'=>$gateway_ident); |
| 353 |
} |
| 354 |
|
| 355 |
} |
| 356 |
/*** |
| 357 |
update options table for each gateway |
| 358 |
***/ |
| 359 |
foreach($gateway_options as $gateway_options_db_name=>$gateway_options_db_values){ |
| 360 |
/*update option table values for this gateway**/ |
| 361 |
update_option($gateway_options_db_name, $gateway_options_db_values); |
| 362 |
} |
| 363 |
/****************************************** |
| 364 |
update main wppizza options |
| 365 |
adding enabled gateways to $options returned |
| 366 |
******************************************/ |
| 367 |
/**sort by sort order set and save**/ |
| 368 |
asort($wppizza_options_gateways); |
| 369 |
$options['gateways']=$wppizza_options_gateways; |
| 370 |
} |
| 371 |
return $options; |
| 372 |
} |
| 373 |
|
| 374 |
/********************************************************* |
| 375 |
* |
| 376 |
* [register submenu page] |
| 377 |
* @since 3.0 |
| 378 |
* |
| 379 |
*********************************************************/ |
| 380 |
public function wppizza_register_submenu_page(){ |
| 381 |
$submenu_page= array( |
| 382 |
'url' => 'edit.php?post_type='.WPPIZZA_SLUG.'', |
| 383 |
'title' => ''.WPPIZZA_NAME.' '.$this->submenu_page_title, |
| 384 |
'link_label' => $this->submenu_link_label, |
| 385 |
'caps' => 'wppizza_cap_'.$this->class_key.'', |
| 386 |
'key' => $this->class_key, |
| 387 |
'callback' => array($this, 'wppizza_admin_manage_sections') |
| 388 |
); |
| 389 |
/**add submenu page**/ |
| 390 |
$wppizza_submenu_page=add_submenu_page($submenu_page['url'], $submenu_page['title'], $submenu_page['link_label'], $submenu_page['caps'], $submenu_page['key'], $submenu_page['callback']); |
| 391 |
} |
| 392 |
/********************************************************* |
| 393 |
* |
| 394 |
* [add settings section(s) and fields] |
| 395 |
* |
| 396 |
* @since 3.0 |
| 397 |
* @return void |
| 398 |
* |
| 399 |
*********************************************************/ |
| 400 |
public function wppizza_admin_settings_sections(){ |
| 401 |
/** get settings sections and fields **/ |
| 402 |
$settings=$this->wppizza_get_settings(true, true); |
| 403 |
/**iterate through sections*/ |
| 404 |
foreach($settings['sections'] as $sections_key=>$sections_values){ |
| 405 |
|
| 406 |
/** |
| 407 |
add section |
| 408 |
**/ |
| 409 |
add_settings_section($sections_values['ident'], '', array( $this, 'wppizza_admin_settings_section_header'), $sections_values['ident']); |
| 410 |
|
| 411 |
/** |
| 412 |
add section fields |
| 413 |
**/ |
| 414 |
foreach($settings['fields'][$sections_key] as $fields_key=>$field_values){ |
| 415 |
add_settings_field($field_values['options_key'], $field_values['label'], array( $this, 'wppizza_admin_settings_section_fields'), $field_values['section'], $field_values['section'], $field_values['args']); |
| 416 |
} |
| 417 |
} |
| 418 |
} |
| 419 |
/********************************************************* |
| 420 |
* |
| 421 |
* [add setting section(s) headers] |
| 422 |
* |
| 423 |
* @param array |
| 424 |
* @return str |
| 425 |
* |
| 426 |
*********************************************************/ |
| 427 |
public function wppizza_admin_settings_section_header($arg){ |
| 428 |
/*might come in useful somewhere*/ |
| 429 |
static $section_count=0;$section_count++; |
| 430 |
|
| 431 |
/**add more text headers if required*/ |
| 432 |
do_action('wppizza_settings_sections_header_'.$this->class_key.'', $arg, $section_count); |
| 433 |
} |
| 434 |
/********************************************************* |
| 435 |
* |
| 436 |
* [echo manage settings] |
| 437 |
* |
| 438 |
* wrap settings sections into div->form |
| 439 |
* add uniquely identifiable id's / classes |
| 440 |
* add h2 text |
| 441 |
* add uniquely identifiable hidden input |
| 442 |
* add submit button |
| 443 |
* |
| 444 |
* @since 3.0 |
| 445 |
* @return str |
| 446 |
* |
| 447 |
*********************************************************/ |
| 448 |
public function wppizza_admin_manage_sections(){ |
| 449 |
global $wppizza_options; |
| 450 |
|
| 451 |
/* |
| 452 |
wppizza post type only |
| 453 |
*/ |
| 454 |
$screen = get_current_screen(); |
| 455 |
if($screen->post_type != WPPIZZA_POST_TYPE){return;} |
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
/** get sections settings**/ |
| 460 |
$settings=$this->wppizza_get_settings(true); |
| 461 |
|
| 462 |
/**wrap settings sections into div->form */ |
| 463 |
echo'<div id="'.WPPIZZA_SLUG.'-'.$this->class_key.'" class="'.WPPIZZA_SLUG.'-wrap '.WPPIZZA_SLUG.'-'.$this->class_key.'-wrap">'; |
| 464 |
|
| 465 |
|
| 466 |
echo"<div class='".WPPIZZA_SLUG."-admin-pageheader'>"; |
| 467 |
|
| 468 |
echo"<h2>"; |
| 469 |
echo"<span id='".WPPIZZA_SLUG."-header'>".WPPIZZA_NAME." ".$this->submenu_page_header."</span>"; |
| 470 |
echo"</h2>"; |
| 471 |
|
| 472 |
echo"</div>"; |
| 473 |
|
| 474 |
/**update info / errors etc*/ |
| 475 |
settings_errors(); |
| 476 |
|
| 477 |
|
| 478 |
echo'<form action="options.php" method="post">'; |
| 479 |
echo'<input type="hidden" name="'.WPPIZZA_SLUG.'_'.$this->class_key.'" value="1" />'; |
| 480 |
|
| 481 |
/**echo wppizza settings field*/ |
| 482 |
settings_fields(WPPIZZA_SLUG); |
| 483 |
|
| 484 |
|
| 485 |
/**echo settings sections**/ |
| 486 |
foreach($settings['sections'] as $sections_key => $sections_values){ |
| 487 |
|
| 488 |
echo'<div id="wppizza-section-gateways-'.$sections_key.'" class="wppizza-section-gateways button">'; |
| 489 |
/**label (gateway name)**/ |
| 490 |
print'<span class="wppizza-gateway-label">'.$sections_values['name'].'</span>'; |
| 491 |
|
| 492 |
/*show options button */ |
| 493 |
print'<span id="wppizza-gateway-show-options-'.$sections_key.'" class="wppizza-gateway-show-options button">'.__('show options','wppizza-admin').'</span>'; |
| 494 |
|
| 495 |
/**enable button*/ // '.checked(!empty($wppizza_options['gateways'][$sections_key]),true,false).' |
| 496 |
print'<label class="wppizza-gateway-enable button"><input name="'.WPPIZZA_SLUG.'[gateways]['.$sections_values['arg']['option_name'].'][_gateway_enabled]" type="checkbox" '.checked(!empty($wppizza_options['gateways'][$sections_key]),true,false).' value="1">'.__('enabled Y/N','wppizza-admin').'</label>'; |
| 497 |
|
| 498 |
echo'</div>'; |
| 499 |
|
| 500 |
|
| 501 |
echo'<div id="wppizza-fields-gateways-'.$sections_key.'" class="wppizza-fields-gateways">'; |
| 502 |
if(!empty($sections_values['arg']['admininfo'])){ |
| 503 |
print'<div class="wppizza-fields-gateways-addinfo">'.$sections_values['arg']['admininfo'].'</div>'; |
| 504 |
} |
| 505 |
|
| 506 |
do_settings_sections($sections_key); |
| 507 |
echo'</div>'; |
| 508 |
} |
| 509 |
|
| 510 |
/**echo submit button or diabled button*/ |
| 511 |
if(WPPIZZA_DEV_ADMIN_NO_SAVE){ |
| 512 |
print '<input type="button" class="'.WPPIZZA_PREFIX.'-save-disabled" value="'.__('Saving Disabled', 'wppizza-admin').'">'; |
| 513 |
}else{ |
| 514 |
submit_button( __('Save Changes', 'wppizza-admin') ); |
| 515 |
} |
| 516 |
|
| 517 |
echo'</form>'; |
| 518 |
echo'</div>'; |
| 519 |
} |
| 520 |
/********************************************************* |
| 521 |
* |
| 522 |
* [echo setting section(s) fields] |
| 523 |
* |
| 524 |
*********************************************************/ |
| 525 |
public function wppizza_admin_settings_section_fields($args){ |
| 526 |
/** wppizza options set **/ |
| 527 |
global $wppizza_options; |
| 528 |
|
| 529 |
|
| 530 |
/**option key**/ |
| 531 |
$gateway_name=$args['gateway_name']; |
| 532 |
/**option key**/ |
| 533 |
$option_key=$args['option_key']; |
| 534 |
/*gateway_options_name***/ |
| 535 |
$gateway_options_name=$args['gateway_options_name']; |
| 536 |
/**number of gateways **/ |
| 537 |
$gateway_count=$args['gateway_count']; |
| 538 |
/**settings**/ |
| 539 |
$settings=$args['settings']; |
| 540 |
/**value**/ |
| 541 |
$value=$args['value']; |
| 542 |
|
| 543 |
/** |
| 544 |
gateway specific variables |
| 545 |
**/ |
| 546 |
if(count($settings)>0){ |
| 547 |
|
| 548 |
echo"<label style='float:left;width:17%'>"; |
| 549 |
echo"".$settings['label']." "; |
| 550 |
echo"</label>"; |
| 551 |
|
| 552 |
echo"<div style='float:right;width:82%;'>"; |
| 553 |
/* |
| 554 |
normal selects ? |
| 555 |
*/ |
| 556 |
//$selected=!empty($settings['selected']) ? $settings['selected'] : '' ; |
| 557 |
/* |
| 558 |
checkboxes / radio |
| 559 |
*/ |
| 560 |
$selected = '' ;/* ini for non check/radio */ |
| 561 |
if($settings['type'] == 'checkbox' || $settings['type'] == 'radio'){ |
| 562 |
$selected=!empty($settings['selected']) ? 'checked="checked"' : '' ; |
| 563 |
} |
| 564 |
//if($settings['type'] == 'select'){ |
| 565 |
// $selected=!empty($settings['selected']) ? 'selected="selected"' : '' ; |
| 566 |
//} |
| 567 |
|
| 568 |
|
| 569 |
$this->wppizza_echo_gateway_formfield($settings['type'], $settings['key'], WPPIZZA_SLUG."[gateways][".$gateway_options_name."][".$settings['key']."]",$settings['value'], $settings['placeholder'], $settings['options'], $selected); |
| 570 |
|
| 571 |
/*description if set**/ |
| 572 |
if(!empty($settings['descr'])){ |
| 573 |
echo"<span class='description'>"; |
| 574 |
echo"".$settings['descr'].""; |
| 575 |
echo"</span>"; |
| 576 |
} |
| 577 |
echo"</div>"; |
| 578 |
|
| 579 |
} |
| 580 |
} |
| 581 |
/********************************************************* |
| 582 |
* |
| 583 |
* [define caps] |
| 584 |
* @since 3.0 |
| 585 |
* |
| 586 |
*********************************************************/ |
| 587 |
function wppizza_filter_define_caps($caps){ |
| 588 |
/**add editing capability for this page**/ |
| 589 |
$caps[$this->class_key]=array('name'=>$this->submenu_caps_title ,'cap'=>'wppizza_cap_'.$this->class_key.''); |
| 590 |
return $caps; |
| 591 |
} |
| 592 |
/********************************************************* |
| 593 |
* |
| 594 |
* [set required capability for this page] |
| 595 |
* @since 3.0 |
| 596 |
* |
| 597 |
*********************************************************/ |
| 598 |
function admin_option_page_capability($capability) { |
| 599 |
$capability = 'wppizza_cap_'.$this->class_key.''; |
| 600 |
return $capability; |
| 601 |
} |
| 602 |
/********************************************************* |
| 603 |
* |
| 604 |
* [helpers] |
| 605 |
* |
| 606 |
*********************************************************/ |
| 607 |
/**************************************************************************** |
| 608 |
[output gateway formfields depending on type] |
| 609 |
* @since 3.0 |
| 610 |
****************************************************************************/ |
| 611 |
function wppizza_echo_gateway_formfield($type='text', $id='', $name='', $value='', $placeholder='' , $options='', $selected=''){ |
| 612 |
|
| 613 |
/* |
| 614 |
output text / email / password / text with set size / encrypted |
| 615 |
*/ |
| 616 |
if($type=='text' || $type=='email' || $type=='password' || $type=='encrypted' || substr($type,0,10)=='text_size_'){ |
| 617 |
|
| 618 |
$input_field_type = ($type == 'email') ? 'email' : 'text'; |
| 619 |
$input_field_type = (in_array($type, array('password', 'encrypted')) ? 'password' : $input_field_type ); |
| 620 |
$set_size = !empty($type) ? (int)substr($type, 10) : 0 ; |
| 621 |
$input_field_size=!empty($set_size) ? (int)substr($type, 10) : 40; |
| 622 |
/* decrypt value if stored encrypted */ |
| 623 |
$value = $type=='encrypted' && !empty($value) ? wppizza_decrypt($value): $value ;//wppizza_decrypt($value) |
| 624 |
/* add visibility toggle for passwords / encrypted fields */ |
| 625 |
$onclickevent = in_array($type, array('password', 'encrypted')) ? 'onfocus="wppizza_toggle_password(\''.$id.'\', 1);" onblur="wppizza_toggle_password(\''.$id.'\');"' : '' ; |
| 626 |
|
| 627 |
echo'<input type="'.$input_field_type.'" id="'.$id.'" class="'.$id.'" name="'.$name.'" value="'.$value.'" size="'.$input_field_size.'" placeholder="'.$placeholder.'" '.$onclickevent.' />'; |
| 628 |
} |
| 629 |
|
| 630 |
/* |
| 631 |
output checkbox |
| 632 |
*/ |
| 633 |
if($type=='checkbox'){ |
| 634 |
echo'<input type="checkbox" class="'.$id.'" name="'.$name.'" value="'.$value.'" '.$selected.' />'; |
| 635 |
} |
| 636 |
|
| 637 |
/* |
| 638 |
output radio button(s) |
| 639 |
*/ |
| 640 |
if($type=='radio'){ |
| 641 |
if(is_array($options)){ |
| 642 |
$i=0; |
| 643 |
foreach($options as $key=>$val){ |
| 644 |
//add labels |
| 645 |
if(!empty($placeholder) && is_array($placeholder) && !empty($placeholder[$key])){ |
| 646 |
echo'<label>'; |
| 647 |
} |
| 648 |
|
| 649 |
echo'<input type="radio" id="'.$key.'_'.$i.'" class="'.$key.'" name="'.$key.'" value="'.$val.'" '.checked(is_array($selected) && in_array($val,$selected),true,false).'/>'; |
| 650 |
|
| 651 |
//add labels |
| 652 |
if(!empty($placeholder) && is_array($placeholder) && !empty($placeholder[$key])){ |
| 653 |
echo' '.$placeholder[$key].'</label>'; |
| 654 |
} |
| 655 |
$i++; |
| 656 |
} |
| 657 |
}else{ |
| 658 |
//add labels |
| 659 |
if(!empty($placeholder) && is_string($placeholder) ){ |
| 660 |
echo'<label>'; |
| 661 |
} |
| 662 |
echo'<input type="rdo" id="'.$id.'" class="'.$id.'" name="'.$name.'" value="'.$value.'" '.$selected.'/>'; |
| 663 |
//add labels |
| 664 |
if(!empty($placeholder) && is_string($placeholder) ){ |
| 665 |
echo' '.$placeholder.'</label>'; |
| 666 |
} |
| 667 |
} |
| 668 |
} |
| 669 |
|
| 670 |
/* |
| 671 |
output multiple checkboxes |
| 672 |
*/ |
| 673 |
if($type=='checkboxmulti'){ |
| 674 |
if(isset($options) && is_array($options)){ |
| 675 |
foreach($options as $k=>$v){ |
| 676 |
echo'<span style="padding-right:10px;"><input type="checkbox" id="'.$id.'_'.$k.'" class="'.$id.'" name="'.$name.'['.$k.']" value="'.$k.'" '.checked(in_array($k,$value),true,false).'/>'; |
| 677 |
echo''.$v.''; |
| 678 |
echo'</span>'; |
| 679 |
}} |
| 680 |
} |
| 681 |
|
| 682 |
/* |
| 683 |
output textarea |
| 684 |
*/ |
| 685 |
if($type=='textarea'){ |
| 686 |
echo'<textarea id="'.$id.'" class="'.$id.'" name="'.$name.'">'.$value.'</textarea>'; |
| 687 |
} |
| 688 |
|
| 689 |
/* |
| 690 |
output textarea html editor |
| 691 |
*/ |
| 692 |
if($type=='texteditor'){ |
| 693 |
$id=strtolower(str_replace(array('[',']'),'_',$name));/* WP 3.9 doesnt like brackets in id's*/ |
| 694 |
echo'<div class="'.WPPIZZA_SLUG.'-texteditor">'; |
| 695 |
wp_editor( $value, $id , array('teeny'=>1,'wpautop'=>false,'media_buttons'=>false,'textarea_name'=>$name) ); |
| 696 |
echo'</div>'; |
| 697 |
} |
| 698 |
|
| 699 |
/* |
| 700 |
output select/dropdown |
| 701 |
*/ |
| 702 |
if($type=='select'){ |
| 703 |
echo'<select id="'.$id.'" class="'.$id.'" name="'.$name.'" >'; |
| 704 |
foreach($options as $selValue=>$selLabel){ |
| 705 |
echo'<option value="'.$selValue.'" '.selected((!empty($value) && $value == $selValue), true ,false).' >'.$selLabel.'</option>'; |
| 706 |
} |
| 707 |
echo'</select>'; |
| 708 |
} |
| 709 |
|
| 710 |
/* |
| 711 |
output multi select/dropdown |
| 712 |
*/ |
| 713 |
if($type=='selectmulti'){ |
| 714 |
echo ( !empty($placeholder) ? '<select id="'.$id.'" class="'.$id.'" name="'.$name.'[]" multiple="multiple" data-placeholder="'.$placeholder.'">' : '<select id="'.$id.'" class="'.$id.'" name="'.$name.'[]" multiple="multiple">'); |
| 715 |
asort($options); |
| 716 |
foreach($options as $selValue=>$selLabel){ |
| 717 |
echo'<option value="'.$selValue.'" '.selected((!empty($value) && in_array($selValue, $value) ), true ,false).' >'.$selLabel.'</option>'; |
| 718 |
} |
| 719 |
echo'</select>'; |
| 720 |
} |
| 721 |
|
| 722 |
|
| 723 |
/* |
| 724 |
output formfields dropdown |
| 725 |
*/ |
| 726 |
if($type=='formfields' && !empty($options) && is_array($options)){ |
| 727 |
|
| 728 |
/** get enabled order form fields **/ |
| 729 |
$enabled_formfields = WPPIZZA() -> admin_helper -> admin_orderform_enabled_formfields('gateways'); |
| 730 |
|
| 731 |
/* |
| 732 |
echo dropdown |
| 733 |
*/ |
| 734 |
echo'<span class="'.WPPIZZA_SLUG.'-formfields-table-span"><table class="'.WPPIZZA_SLUG.'-formfields-table">'; |
| 735 |
|
| 736 |
foreach($enabled_formfields as $effKey => $effArr){ |
| 737 |
|
| 738 |
echo'<tr>'; |
| 739 |
|
| 740 |
echo'<td>'.$effArr['lbl'].'</td>'; |
| 741 |
|
| 742 |
echo'<td>'; |
| 743 |
|
| 744 |
echo'<select id="'.$effKey.'" class="'.$effKey.'" name="'.$name.'['.$effKey.']">'; |
| 745 |
|
| 746 |
foreach($options as $oValue => $oLabel){ |
| 747 |
echo'<option value="'.$oValue.'" '.selected((!empty($value[$effKey]) && $value[$effKey] == $oValue), true ,false).' >'.$oLabel.'</option>'; |
| 748 |
} |
| 749 |
|
| 750 |
echo'</select>'; |
| 751 |
|
| 752 |
echo'</td>'; |
| 753 |
|
| 754 |
echo'</tr>'; |
| 755 |
|
| 756 |
} |
| 757 |
echo'</table></span>'; |
| 758 |
} |
| 759 |
|
| 760 |
/* |
| 761 |
set to custom, just output |
| 762 |
what's set in options |
| 763 |
*/ |
| 764 |
if($type=='custom'){ |
| 765 |
echo''.$options; |
| 766 |
} |
| 767 |
} |
| 768 |
|
| 769 |
} |
| 770 |
/*************************************************************** |
| 771 |
* |
| 772 |
* [ini] |
| 773 |
* |
| 774 |
***************************************************************/ |
| 775 |
$WPPIZZA_MANAGE_GATEWAYS = new WPPIZZA_MANAGE_GATEWAYS(); |
| 776 |
?> |