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
← All changes | classes/models/FrmFormTemplateApi.php +45 -116 6.5.3 → trunk View file →
@@ -4,20 +4,34 @@
4 4 }
5 5
6 6 class FrmFormTemplateApi extends FrmFormApi {
7 7
8 - protected static $code_option_name = 'frm_free_license_code';
8 + /**
9 + * @var string
10 + */
11 + protected static $code_option_name = 'frm_free_license_code';
9 12
13 + /**
14 + * @var string
15 + */
10 16 private static $base_api_url = 'https://formidableforms.com/wp-json/form-templates/v1/';
11 17
18 + /**
19 + * @var string|null
20 + */
12 21 protected static $free_license;
13 22
14 23 /**
15 - * @var int $new_days
24 + * @var int
16 25 */
17 26 protected $new_days = 30;
18 27
19 28 /**
29 + * @var string
30 + */
31 + protected $cache_timeout = '+12 hours';
32 +
33 + /**
20 34 * @since 3.06
21 35 *
22 36 * @return void
23 37 */
@@ -26,12 +40,9 @@
26 40
27 41 if ( ! empty( $this->license ) ) {
28 42 $this->cache_key .= md5( $this->license );
29 43 } else {
30 - $free_license = $this->get_free_license();
31 - if ( $free_license ) {
32 - $this->cache_key .= md5( $free_license );
33 - }
44 + $this->cache_key .= '01fd72122f4a90f15684915c729d4368';
34 45 }
35 46 }
36 47
37 48 /**
@@ -42,14 +53,9 @@
42 53 protected function api_url() {
43 54 $url = self::$base_api_url . 'list';
44 55
45 56 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 - }
57 + $url .= '?l=RlJFRVRFTVBMQVRFUyEhIQ%3D%3D&v=' . FrmAppHelper::plugin_version();
52 58 }
53 59
54 60 return $url;
55 61 }
@@ -56,9 +62,9 @@
56 62
57 63 /**
58 64 * @since 3.06
59 65 *
60 - * @return array
66 + * @return string[]
61 67 */
62 68 protected function skip_categories() {
63 69 return array();
64 70 }
@@ -63,133 +69,56 @@
63 69 return array();
64 70 }
65 71
66 72 /**
67 - * @return string
68 - */
69 - 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;
75 - }
76 -
77 - /**
78 - * Check to make sure the free code is being used.
73 + * Set the free license code option value.
79 74 *
80 - * @since 4.09.02
75 + * @since 6.25
81 76 *
82 - * @return bool
83 - */
84 - 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
77 + * @param string $code The license code to set.
97 78 *
98 79 * @return void
99 80 */
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 - }
81 + public static function set_free_license_code( $code ) {
82 + update_option( self::$code_option_name, $code, false );
115 83 }
116 84
117 85 /**
118 - * @return void
86 + * Get the free license code option value.
87 + *
88 + * @since 6.25
89 + *
90 + * @return false|string The license code, or false if not set.
119 91 */
120 - private static function clear_template_cache_before_getting_free_templates() {
121 - delete_option( 'frm_form_templates_l' );
92 + public static function get_free_license_code() {
93 + return get_option( self::$code_option_name );
122 94 }
123 95
124 96 /**
125 - * @param array $response
97 + * AJAX Hook for signing free users up for a template API key
126 98 *
127 99 * @return void
128 100 */
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 - }
101 + public static function signup() {
102 + _deprecated_function( __METHOD__, '6.20' );
137 103 }
138 104
139 105 /**
140 - * @param string $code the base64 encoded code
141 - *
142 - * @return void
106 + * @return string
143 107 */
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 );
108 + public function get_free_license() {
109 + _deprecated_function( __METHOD__, '6.20' );
110 + return '';
179 111 }
180 112
181 113 /**
182 - * AJAX Hook for signing free users up for a template API key
114 + * Check to make sure the free code is being used.
183 115 *
184 - * @return void
116 + * @since 4.09.02
117 + *
118 + * @return bool
185 119 */
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 );
120 + public function has_free_access() {
121 + _deprecated_function( __METHOD__, '6.20' );
122 + return true;
194 123 }
195 124 }