PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.22.1
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.22.1
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
← All changes | classes/models/FrmFormTemplateApi.php +23 -127 6.36.22.1 View file →
@@ -4,9 +4,9 @@
4 4 }
5 5
6 6 class FrmFormTemplateApi extends FrmFormApi {
7 7
8 - protected static $code_option_name = 'frm_free_license_code';
8 + protected static $code_option_name = 'frm_free_license_code';
9 9
10 10 private static $base_api_url = 'https://formidableforms.com/wp-json/form-templates/v1/';
11 11
12 12 protected static $free_license;
@@ -11,13 +11,18 @@
11 11
12 12 protected static $free_license;
13 13
14 14 /**
15 - * @var int $new_days
15 + * @var int
16 16 */
17 17 protected $new_days = 30;
18 18
19 19 /**
20 + * @var string
21 + */
22 + protected $cache_timeout = '+12 hours';
23 +
24 + /**
20 25 * @since 3.06
21 26 *
22 27 * @return void
23 28 */
@@ -26,12 +31,9 @@
26 31
27 32 if ( ! empty( $this->license ) ) {
28 33 $this->cache_key .= md5( $this->license );
29 34 } else {
30 - $free_license = $this->get_free_license();
31 - if ( $free_license ) {
32 - $this->cache_key .= md5( $free_license );
33 - }
35 + $this->cache_key .= '01fd72122f4a90f15684915c729d4368';
34 36 }
35 37 }
36 38
37 39 /**
@@ -42,14 +44,9 @@
42 44 protected function api_url() {
43 45 $url = self::$base_api_url . 'list';
44 46
45 47 if ( empty( $this->license ) ) {
46 - $free_license = $this->get_free_license();
47 -
48 - if ( $free_license ) {
49 - $url .= '?l=' . urlencode( base64_encode( $free_license ) );
50 - $url .= '&v=' . FrmAppHelper::plugin_version();
51 - }
48 + $url .= '?l=RlJFRVRFTVBMQVRFUyEhIQ%3D%3D&v=' . FrmAppHelper::plugin_version();
52 49 }
53 50
54 51 return $url;
55 52 }
@@ -56,9 +53,9 @@
56 53
57 54 /**
58 55 * @since 3.06
59 56 *
60 - * @return array
57 + * @return string[]
61 58 */
62 59 protected function skip_categories() {
63 60 return array();
64 61 }
@@ -63,16 +60,22 @@
63 60 return array();
64 61 }
65 62
66 63 /**
64 + * AJAX Hook for signing free users up for a template API key
65 + *
66 + * @return void
67 + */
68 + public static function signup() {
69 + _deprecated_function( __METHOD__, '6.20' );
70 + }
71 +
72 + /**
67 73 * @return string
68 74 */
69 75 public function get_free_license() {
70 - if ( ! isset( self::$free_license ) ) {
71 - self::$free_license = get_option( self::$code_option_name );
72 - }
73 -
74 - return self::$free_license;
76 + _deprecated_function( __METHOD__, '6.20' );
77 + return '';
75 78 }
76 79
77 80 /**
78 81 * Check to make sure the free code is being used.
@@ -81,115 +84,8 @@
81 84 *
82 85 * @return bool
83 86 */
84 87 public function has_free_access() {
85 - $free_access = $this->get_free_license();
86 - if ( ! $free_access ) {
87 - return false;
88 - }
89 -
90 - $templates = $this->get_api_info();
91 - $contact_form = 20872734;
92 - return isset( $templates[ $contact_form ] ) && ! empty( $templates[ $contact_form ]['url'] );
93 - }
94 -
95 - /**
96 - * @param string $code the code from the email sent for the API
97 - *
98 - * @return void
99 - */
100 - private static function verify_code( $code ) {
101 - $base64_code = base64_encode( $code );
102 - $api_url = self::$base_api_url . 'code?l=' . urlencode( $base64_code );
103 - $response = wp_remote_get( $api_url );
104 -
105 - self::handle_verify_response_errors_if_any( $response );
106 -
107 - $decoded = json_decode( $response['body'] );
108 - $successful = ! empty( $decoded->response );
109 -
110 - if ( $successful ) {
111 - self::on_api_verify_code_success( $code );
112 - } else {
113 - wp_send_json_error( new WP_Error( $decoded->code, $decoded->message ) );
114 - }
115 - }
116 -
117 - /**
118 - * @return void
119 - */
120 - private static function clear_template_cache_before_getting_free_templates() {
121 - delete_option( 'frm_form_templates_l' );
122 - }
123 -
124 - /**
125 - * @param array $response
126 - *
127 - * @return void
128 - */
129 - private static function handle_verify_response_errors_if_any( $response ) {
130 - if ( is_wp_error( $response ) ) {
131 - wp_send_json_error( $response );
132 - }
133 -
134 - if ( ! is_array( $response ) ) {
135 - wp_send_json_error();
136 - }
137 - }
138 -
139 - /**
140 - * @param string $code the base64 encoded code
141 - *
142 - * @return void
143 - */
144 - private static function on_api_verify_code_success( $code ) {
145 - self::$free_license = $code;
146 - update_option( self::$code_option_name, $code, 'no' );
147 -
148 - $data = array();
149 - $key = FrmAppHelper::get_param( 'key', '', 'post', 'sanitize_key' );
150 -
151 - // Remove message from Inbox page.
152 - $message = new FrmInbox();
153 - $message->remove( 'free_templates' );
154 -
155 - if ( $key ) {
156 - self::clear_template_cache_before_getting_free_templates();
157 -
158 - $data['urlByKey'] = array();
159 - $api = new self();
160 - $templates = $api->get_api_info();
161 -
162 - foreach ( $templates as $template ) {
163 - if ( ! isset( $template['url'] ) || ! in_array( 'free', $template['categories'], true ) ) {
164 - continue;
165 - }
166 -
167 - $data['urlByKey'][ $template['key'] ] = $template['url'];
168 - }
169 -
170 - if ( ! isset( $data['urlByKey'][ $key ] ) ) {
171 - $error = new WP_Error( 400, 'We were unable to retrieve the template' );
172 - wp_send_json_error( $error );
173 - }
174 -
175 - $data['url'] = $data['urlByKey'][ $key ];
176 - }
177 -
178 - wp_send_json_success( $data );
179 - }
180 -
181 - /**
182 - * AJAX Hook for signing free users up for a template API key
183 - *
184 - * @return void
185 - */
186 - public static function signup() {
187 - $code = FrmAppHelper::get_param( 'code', '', 'post' );
188 -
189 - if ( ! $code ) {
190 - wp_send_json_error();
191 - }
192 -
193 - self::verify_code( $code );
88 + _deprecated_function( __METHOD__, '6.20' );
89 + return true;
194 90 }
195 91 }