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 / stripe / models / FrmStrpLiteSettings.php

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

139 lines 3.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 #[\AllowDynamicProperties]
7 class FrmStrpLiteSettings {
8
9 /**
10 * @var stdClass|null
11 */
12 public $settings;
13
14 public function __construct() {
15 $this->set_default_options();
16 }
17
18 /**
19 * @return string
20 */
21 public function param() {
22 return 'strp';
23 }
24
25 /**
26 * @return array
27 */
28 public function default_options() {
29 return array(
30 'test_mode' => 1,
31 'processing_message' => __( 'This payment may take several days to finish processing.', 'formidable' ),
32 );
33 }
34
35 /**
36 * @param mixed $settings
37 *
38 * @return void
39 */
40 public function set_default_options( $settings = false ) {
41 $default_settings = $this->default_options();
42
43 if ( ! $settings ) {
44 $settings = $this->get_options();
45 } elseif ( $settings === true ) {
46 $settings = new stdClass();
47 }
48
49 if ( ! isset( $this->settings ) ) {
50 $this->settings = new stdClass();
51 }
52
53 foreach ( $default_settings as $setting => $default ) {
54 if ( is_object( $settings ) && isset( $settings->{$setting} ) ) {
55 $this->settings->{$setting} = $settings->{$setting};
56 }
57
58 if ( ! isset( $this->settings->{$setting} ) ) {
59 $this->settings->{$setting} = $default;
60 }
61 }
62 }
63
64 /**
65 * @return object
66 */
67 public function get_options() {
68 $settings = get_option( 'frm_' . $this->param() . '_options' );
69
70 if ( is_object( $settings ) ) {
71 $this->set_default_options( $settings );
72 } elseif ( $settings ) {
73 // Workaround for W3 total cache conflict.
74 $this->settings = unserialize( serialize( $settings ) );
75 } else {
76 $this->set_default_options( true );
77 $this->store();
78 }
79
80 return $this->settings;
81 }
82
83 /**
84 * @param array $params
85 *
86 * @return void
87 */
88 public function update( $params ) {
89 $settings = $this->default_options();
90
91 foreach ( $settings as $setting => $default ) {
92 if ( ! isset( $params[ 'frm_' . $this->param() . '_' . $setting ] ) ) {
93 continue;
94 }
95
96 $value = $params[ 'frm_' . $this->param() . '_' . $setting ];
97
98 // Clean up any accumulated backslashes from previous bug.
99 // @see https://github.com/Strategy11/formidable-pro/issues/6294
100 if ( 'processing_message' === $setting ) {
101 $value = str_replace( '\\', '', $value );
102 }
103
104 $this->settings->{$setting} = sanitize_text_field( $value );
105 }
106
107 $this->settings->test_mode = isset( $params['frm_strp_test_mode'] ) ? absint( $params['frm_strp_test_mode'] ) : 0;
108 }
109
110 /**
111 * @return void
112 */
113 public function store() {
114 // Save the posted value in the database.
115 update_option( 'frm_' . $this->param() . '_options', $this->settings );
116 }
117
118 /**
119 * @return string
120 */
121 public function get_active_publishable_key() {
122 return $this->settings->test_mode ? $this->get_frm_publishable_test_key() : $this->get_frm_publishable_live_key();
123 }
124
125 /**
126 * @return string
127 */
128 private function get_frm_publishable_test_key() {
129 return 'pk_test_51I8ZwGAifsV2HHSa8NKsdEEVTa8o69bZykSf1zM3OsonXFblw7mEuNkyYUjLgGwYrgF95CmpkJSJtaWyrQNKaMMJ00y2Q7Y0jz';
130 }
131
132 /**
133 * @return string
134 */
135 private function get_frm_publishable_live_key() {
136 return 'pk_live_51I8ZwGAifsV2HHSa0jgLD6S16izScuihE2WtExBWzbyBsawOazS9cjt1aFyBsdSuK9nYwDD7Vh7LUOoa0Evb7Evb00yVEpTIJL';
137 }
138 }
139