PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.4
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.4
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/FrmApplicationTemplate.php +25 -121 6.295.4 View file →
@@ -8,29 +8,30 @@
8 8 */
9 9 class FrmApplicationTemplate {
10 10
11 11 /**
12 - * @var array<string>|null
12 + * @var array<string>|null $keys
13 13 */
14 14 private static $keys;
15 15
16 16 /**
17 - * @var array<string>|null
17 + * @var array<string>|null $keys_with_images
18 18 */
19 19 private static $keys_with_images;
20 20
21 21 /**
22 - * @var array<string>|null
22 + * @var array<string>|null $categories
23 23 */
24 24 private static $categories;
25 25
26 26 /**
27 - * @var array
27 + * @var array $api_data
28 28 */
29 29 private $api_data;
30 30
31 31 /**
32 - * @return void
32 + * @param array<string> $keys
33 + * @param array<string> $keys_with_images
33 34 */
34 35 public static function init() {
35 36 /**
36 37 * @since 5.3
@@ -38,44 +39,20 @@
38 39 * @param array $keys
39 40 */
40 41 self::$keys = apply_filters(
41 42 'frm_application_data_keys',
42 - array( 'key', 'name', 'description', 'link', 'categories', 'views', 'forms', 'used_addons' )
43 + array( 'key', 'name', 'description', 'link', 'categories', 'views', 'forms' )
43 44 );
44 - self::$keys_with_images = array_merge(
45 - self::get_template_keys_with_local_png_images(),
46 - self::get_template_keys_with_local_webp_images()
47 - );
45 + self::$keys_with_images = self::get_template_keys_with_local_images();
48 46 self::$categories = array();
49 47 }
50 48
51 49 /**
52 - * Newer templates now use .webp files instead of .png.
53 - *
54 - * @since 6.16
55 - *
56 - * @return array<string>
57 - */
58 - private static function get_template_keys_with_local_webp_images() {
59 - return array(
60 - 'member-directory',
61 - 'link-in-bio-instagram',
62 - 'letter-of-recommendation',
63 - 'invoice-pdf',
64 - 'freelance-invoice-generator',
65 - 'contract-agreement',
66 - 'charity-tracker',
67 - 'certificate',
68 - 'testimonials',
69 - );
70 - }
71 -
72 - /**
73 50 * Return the template keys that have embedded images. Otherwise, we want to avoid trying to load the URL and use the placeholder instead.
74 51 *
75 52 * @return array<string>
76 53 */
77 - private static function get_template_keys_with_local_png_images() {
54 + private static function get_template_keys_with_local_images() {
78 55 return array(
79 56 'business-hours',
80 57 'faq-template-wordpress',
81 58 'restaurant-menu',
@@ -81,36 +58,13 @@
81 58 'restaurant-menu',
82 59 'team-directory',
83 60 'product-review',
84 61 'real-estate-listings',
85 - 'business-directory',
86 - 'artist-gallery',
87 - 'classifieds',
88 - 'community-event-calendar',
89 - 'company-timeline',
90 - 'crowdfunding',
91 - 'job-board',
92 - 'logo-cloud',
93 - 'multi-property-booking-system',
94 - 'wedding-venue-booking',
95 - 'permission-slip',
96 - 'property-directory',
97 - 'radio-station',
98 - 'recipe',
99 - 'rsvp-invite',
100 - 'searchable-directory',
101 - 'shopping-cart',
102 - 'sports-league-calendar',
103 - 'staff-directory',
104 - 'tiered-pricing',
105 - 'trip-itinerary',
106 - 'twitterx',
107 62 );
108 63 }
109 64
110 65 /**
111 66 * @param array $api_data
112 - *
113 67 * @return void
114 68 */
115 69 public function __construct( $api_data ) {
116 70 $this->api_data = $api_data;
@@ -121,43 +75,24 @@
121 75 }
122 76
123 77 /**
124 78 * @param array<string> $categories
125 - *
126 79 * @return void
127 80 */
128 81 private static function populate_category_information( $categories ) {
129 82 foreach ( $categories as $category ) {
130 - if ( self::category_matches_a_license_type( $category ) ) {
83 + if ( false !== strpos( $category, '+Views' ) || in_array( $category, self::$categories, true ) ) {
131 84 continue;
132 85 }
133 -
134 - if ( in_array( $category, self::$categories, true ) ) {
135 - continue;
136 - }
137 86 self::$categories[] = $category;
138 87 }
139 88 }
140 89
141 90 /**
142 - * @since 5.5.2
143 - *
144 - * @param string $category
145 - *
146 - * @return bool
147 - */
148 - private static function category_matches_a_license_type( $category ) {
149 - if ( str_contains( $category, '+Views' ) ) {
150 - return true;
151 - }
152 - return in_array( $category, FrmFormsHelper::get_license_types(), true );
153 - }
154 -
155 - /**
156 91 * @return array<string>
157 92 */
158 93 public static function get_categories() {
159 - return self::$categories ?? array();
94 + return isset( self::$categories ) ? self::$categories : array();
160 95 }
161 96
162 97 /**
163 98 * @return array
@@ -162,14 +97,9 @@
162 97 /**
163 98 * @return array
164 99 */
165 100 public function as_js_object() {
166 - if ( ! is_array( self::$keys ) ) {
167 - return array();
168 - }
169 -
170 101 $application = array();
171 -
172 102 foreach ( self::$keys as $key ) {
173 103 if ( ! isset( $this->api_data[ $key ] ) ) {
174 104 continue;
175 105 }
@@ -182,10 +112,10 @@
182 112 } elseif ( 'categories' === $key ) {
183 113 $application[ $key ] = array_values(
184 114 array_filter(
185 115 $value,
186 - function ( $category ) {
187 - return ! str_contains( $category, '+Views' );
116 + function( $category ) {
117 + return false === strpos( $category, '+Views' );
188 118 }
189 119 )
190 120 );
191 121 } else {
@@ -194,48 +124,27 @@
194 124 } elseif ( 'forms' === $key ) {
195 125 $key = 'formCount';
196 126 }
197 127
198 - if ( 'name' === $key && str_ends_with( $value, ' Template' ) ) {
128 + if ( 'name' === $key && ' Template' === substr( $value, -9 ) ) {
199 129 // Strip off the " Template" text at the end of the name as it takes up space.
200 130 $value = substr( $value, 0, -9 );
201 131 }
202 -
203 132 $application[ $key ] = $value;
204 - }//end if
205 - }//end foreach
133 + }
134 + }
206 135
207 136 $application['hasLiteThumbnail'] = in_array( $application['key'], self::$keys_with_images, true );
208 - $application['isWebp'] = in_array( $application['key'], self::get_template_keys_with_local_webp_images(), true );
209 137
210 138 if ( ! array_key_exists( 'url', $application ) ) {
211 - $application['requires'] = FrmFormsHelper::get_plan_required( $application );
212 -
213 - if ( false === $application['requires'] ) {
214 - // Application is invalid if the URL is unavailable and there is no plan required.
215 - return array();
216 - }
217 -
218 139 $purchase_url = $this->is_available_for_purchase();
219 -
220 140 if ( false !== $purchase_url ) {
221 141 $application['forPurchase'] = true;
222 142 }
223 -
224 143 $application['upgradeUrl'] = $this->get_admin_upgrade_link();
225 144 $application['link'] = $application['upgradeUrl'];
226 145 }
227 146
228 - $application['isNew'] = $this->is_new();
229 -
230 - $application['usedAddons'] = array();
231 -
232 - if ( isset( $application['used_addons'] ) ) {
233 - // Change key to camel case.
234 - $application['usedAddons'] = $application['used_addons'];
235 - unset( $application['used_addons'] );
236 - }
237 -
238 147 return $application;
239 148 }
240 149
241 150 /**
@@ -254,9 +163,8 @@
254 163 return false;
255 164 }
256 165
257 166 $pro = $addons[93790];
258 -
259 167 if ( ! array_key_exists( 'type', $pro ) ) {
260 168 return false;
261 169 }
262 170
@@ -264,20 +172,13 @@
264 172 $args = array(
265 173 'license_type' => $license_type,
266 174 'plan_required' => $this->get_required_license(),
267 175 );
268 - return FrmFormsHelper::plan_is_allowed( $args );
269 - }
176 + if ( ! FrmFormsHelper::plan_is_allowed( $args ) ) {
177 + return false;
178 + }
270 179
271 - /**
272 - * Check if an application template is new. If it is, we include a "NEW" pill beside the title.
273 - *
274 - * @since 6.0
275 - *
276 - * @return bool
277 - */
278 - private function is_new() {
279 - return ! empty( $this->api_data['is_new'] );
180 + return true;
280 181 }
281 182
282 183 /**
283 184 * @return string
@@ -283,9 +184,12 @@
283 184 * @return string
284 185 */
285 186 private function get_required_license() {
286 187 $required_license = strtolower( $this->api_data['min_plan'] );
287 - return 'plus' === $required_license ? 'personal' : $required_license;
188 + if ( 'plus' === $required_license ) {
189 + $required_license = 'personal';
190 + }
191 + return $required_license;
288 192 }
289 193
290 194 /**
291 195 * @return string
@@ -295,8 +199,8 @@
295 199 array(
296 200 'content' => 'upgrade',
297 201 'medium' => 'applications',
298 202 ),
299 - 'view-templates/' . $this->api_data['slug']
203 + '/view-templates/' . $this->api_data['slug']
300 204 );
301 205 }
302 206 }