PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / trunk
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More vtrunk
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
formidable / paypal / models / FrmPayPalLiteSettings.php

FrmPayPalLiteSettings.php in Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More trunk, at paypal/models/FrmPayPalLiteSettings.php

107 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 die( 'You are not allowed to call this page directly.' );
4 }
5
6 class FrmPayPalLiteSettings {
7
8 /**
9 * @var stdClass|null
10 */
11 public $settings;
12
13 public function __construct() {
14 $this->set_default_options();
15 }
16
17 /**
18 * @return string
19 */
20 public function param() {
21 return 'paypal';
22 }
23
24 /**
25 * @return array
26 */
27 public function default_options() {
28 return array(
29 'test_mode' => 1,
30 );
31 }
32
33 /**
34 * @param mixed $settings
35 *
36 * @return void
37 */
38 public function set_default_options( $settings = false ) {
39 $default_settings = $this->default_options();
40
41 if ( ! $settings ) {
42 $settings = $this->get_options();
43 } elseif ( $settings === true ) {
44 $settings = new stdClass();
45 }
46
47 if ( ! isset( $this->settings ) ) {
48 $this->settings = new stdClass();
49 }
50
51 foreach ( $default_settings as $setting => $default ) {
52 if ( is_object( $settings ) && isset( $settings->{$setting} ) ) {
53 $this->settings->{$setting} = $settings->{$setting};
54 }
55
56 if ( ! isset( $this->settings->{$setting} ) ) {
57 $this->settings->{$setting} = $default;
58 }
59 }
60 }
61
62 /**
63 * @return object
64 */
65 public function get_options() {
66 $settings = get_option( 'frm_' . $this->param() . '_options' );
67
68 if ( is_object( $settings ) ) {
69 $this->set_default_options( $settings );
70 } elseif ( $settings ) {
71 // Workaround for W3 total cache conflict.
72 $this->settings = unserialize( serialize( $settings ) );
73 } else {
74 $this->set_default_options( true );
75 $this->store();
76 }
77
78 return $this->settings;
79 }
80
81 /**
82 * @param array $params
83 *
84 * @return void
85 */
86 public function update( $params ) {
87 $settings = $this->default_options();
88 $param = $this->param();
89
90 foreach ( $settings as $setting => $default ) {
91 if ( isset( $params[ 'frm_' . $param . '_' . $setting ] ) ) {
92 $this->settings->{$setting} = sanitize_text_field( $params[ 'frm_' . $param . '_' . $setting ] );
93 }
94 }
95
96 $this->settings->test_mode = isset( $params[ 'frm_' . $param . '_test_mode' ] ) ? absint( $params[ 'frm_' . $param . '_test_mode' ] ) : 0;
97 }
98
99 /**
100 * @return void
101 */
102 public function store() {
103 // Save the posted value in the database.
104 update_option( 'frm_' . $this->param() . '_options', $this->settings );
105 }
106 }
107