PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.5.3
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.5.3
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 +26 -106 6.355.5.3 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,9 +75,8 @@
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 ) {
@@ -129,9 +82,8 @@
129 82 foreach ( $categories as $category ) {
130 83 if ( self::category_matches_a_license_type( $category ) ) {
131 84 continue;
132 85 }
133 -
134 86 if ( in_array( $category, self::$categories, true ) ) {
135 87 continue;
136 88 }
137 89 self::$categories[] = $category;
@@ -141,16 +93,15 @@
141 93 /**
142 94 * @since 5.5.2
143 95 *
144 96 * @param string $category
145 - *
146 97 * @return bool
147 98 */
148 99 private static function category_matches_a_license_type( $category ) {
149 - if ( str_contains( $category, '+Views' ) ) {
100 + if ( false !== strpos( $category, '+Views' ) ) {
150 101 return true;
151 102 }
152 - return in_array( $category, FrmFormsHelper::get_license_types(), true );
103 + return in_array( $category, FrmFormsHelper::ignore_template_categories(), true );
153 104 }
154 105
155 106 /**
156 107 * @return array<string>
@@ -155,9 +106,9 @@
155 106 /**
156 107 * @return array<string>
157 108 */
158 109 public static function get_categories() {
159 - return self::$categories ?? array();
110 + return isset( self::$categories ) ? self::$categories : array();
160 111 }
161 112
162 113 /**
163 114 * @return array
@@ -162,14 +113,9 @@
162 113 /**
163 114 * @return array
164 115 */
165 116 public function as_js_object() {
166 - if ( ! is_array( self::$keys ) ) {
167 - return array();
168 - }
169 -
170 117 $application = array();
171 -
172 118 foreach ( self::$keys as $key ) {
173 119 if ( ! isset( $this->api_data[ $key ] ) ) {
174 120 continue;
175 121 }
@@ -182,10 +128,10 @@
182 128 } elseif ( 'categories' === $key ) {
183 129 $application[ $key ] = array_values(
184 130 array_filter(
185 131 $value,
186 - function ( $category ) {
187 - return ! str_contains( $category, '+Views' );
132 + function( $category ) {
133 + return false === strpos( $category, '+Views' );
188 134 }
189 135 )
190 136 );
191 137 } else {
@@ -194,48 +140,27 @@
194 140 } elseif ( 'forms' === $key ) {
195 141 $key = 'formCount';
196 142 }
197 143
198 - if ( 'name' === $key && str_ends_with( $value, ' Template' ) ) {
144 + if ( 'name' === $key && ' Template' === substr( $value, -9 ) ) {
199 145 // Strip off the " Template" text at the end of the name as it takes up space.
200 146 $value = substr( $value, 0, -9 );
201 147 }
202 -
203 148 $application[ $key ] = $value;
204 - }//end if
205 - }//end foreach
149 + }
150 + }
206 151
207 152 $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 153
210 154 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 155 $purchase_url = $this->is_available_for_purchase();
219 -
220 156 if ( false !== $purchase_url ) {
221 157 $application['forPurchase'] = true;
222 158 }
223 -
224 159 $application['upgradeUrl'] = $this->get_admin_upgrade_link();
225 160 $application['link'] = $application['upgradeUrl'];
226 161 }
227 162
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 163 return $application;
239 164 }
240 165
241 166 /**
@@ -254,9 +179,8 @@
254 179 return false;
255 180 }
256 181
257 182 $pro = $addons[93790];
258 -
259 183 if ( ! array_key_exists( 'type', $pro ) ) {
260 184 return false;
261 185 }
262 186
@@ -264,20 +188,13 @@
264 188 $args = array(
265 189 'license_type' => $license_type,
266 190 'plan_required' => $this->get_required_license(),
267 191 );
268 - return FrmFormsHelper::plan_is_allowed( $args );
269 - }
192 + if ( ! FrmFormsHelper::plan_is_allowed( $args ) ) {
193 + return false;
194 + }
270 195
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'] );
196 + return true;
280 197 }
281 198
282 199 /**
283 200 * @return string
@@ -283,9 +200,12 @@
283 200 * @return string
284 201 */
285 202 private function get_required_license() {
286 203 $required_license = strtolower( $this->api_data['min_plan'] );
287 - return 'plus' === $required_license ? 'personal' : $required_license;
204 + if ( 'plus' === $required_license ) {
205 + $required_license = 'personal';
206 + }
207 + return $required_license;
288 208 }
289 209
290 210 /**
291 211 * @return string
@@ -295,8 +215,8 @@
295 215 array(
296 216 'content' => 'upgrade',
297 217 'medium' => 'applications',
298 218 ),
299 - 'view-templates/' . $this->api_data['slug']
219 + '/view-templates/' . $this->api_data['slug']
300 220 );
301 221 }
302 222 }