PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.24
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.24
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 / square / models / FrmSquareLiteSettings.php

FrmSquareLiteSettings.php in Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More 6.24, at square/models/FrmSquareLiteSettings.php

101 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 FrmSquareLiteSettings {
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 'square';
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 * @return void
36 */
37 public function set_default_options( $settings = false ) {
38 $default_settings = $this->default_options();
39
40 if ( ! $settings ) {
41 $settings = $this->get_options();
42 } elseif ( $settings === true ) {
43 $settings = new stdClass();
44 }
45
46 if ( ! isset( $this->settings ) ) {
47 $this->settings = new stdClass();
48 }
49
50 foreach ( $default_settings as $setting => $default ) {
51 if ( is_object( $settings ) && isset( $settings->{$setting} ) ) {
52 $this->settings->{$setting} = $settings->{$setting};
53 }
54
55 if ( ! isset( $this->settings->{$setting} ) ) {
56 $this->settings->{$setting} = $default;
57 }
58 }
59 }
60
61 public function get_options() {
62 $settings = get_option( 'frm_' . $this->param() . '_options' );
63
64 if ( is_object( $settings ) ) {
65 $this->set_default_options( $settings );
66 } elseif ( $settings ) {
67 // Workaround for W3 total cache conflict.
68 $this->settings = unserialize( serialize( $settings ) );
69 } else {
70 $this->set_default_options( true );
71 $this->store();
72 }
73
74 return $this->settings;
75 }
76
77 /**
78 * @param array $params
79 * @return void
80 */
81 public function update( $params ) {
82 $settings = $this->default_options();
83
84 foreach ( $settings as $setting => $default ) {
85 if ( isset( $params[ 'frm_' . $this->param() . '_' . $setting ] ) ) {
86 $this->settings->{$setting} = trim( sanitize_text_field( $params[ 'frm_' . $this->param() . '_' . $setting ] ) );
87 }
88 }
89
90 $this->settings->test_mode = isset( $params[ 'frm_' . $this->param() . '_test_mode' ] ) ? absint( $params[ 'frm_' . $this->param() . '_test_mode' ] ) : 0;
91 }
92
93 /**
94 * @return void
95 */
96 public function store() {
97 // Save the posted value in the database.
98 update_option( 'frm_' . $this->param() . '_options', $this->settings );
99 }
100 }
101