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 +15 -118 6.265.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 ( false !== strpos( $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,9 +112,9 @@
182 112 } elseif ( 'categories' === $key ) {
183 113 $application[ $key ] = array_values(
184 114 array_filter(
185 115 $value,
186 - function ( $category ) {
116 + function( $category ) {
187 117 return false === strpos( $category, '+Views' );
188 118 }
189 119 )
190 120 );
@@ -199,24 +129,15 @@
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 132 $application[ $key ] = $value;
203 - }//end if
204 - }//end foreach
133 + }
134 + }
205 135
206 136 $application['hasLiteThumbnail'] = in_array( $application['key'], self::$keys_with_images, true );
207 - $application['isWebp'] = in_array( $application['key'], self::get_template_keys_with_local_webp_images(), true );
208 137
209 138 if ( ! array_key_exists( 'url', $application ) ) {
210 - $application['requires'] = FrmFormsHelper::get_plan_required( $application );
211 -
212 - if ( false === $application['requires'] ) {
213 - // Application is invalid if the URL is unavailable and there is no plan required.
214 - return array();
215 - }
216 -
217 139 $purchase_url = $this->is_available_for_purchase();
218 -
219 140 if ( false !== $purchase_url ) {
220 141 $application['forPurchase'] = true;
221 142 }
222 143 $application['upgradeUrl'] = $this->get_admin_upgrade_link();
@@ -222,18 +143,8 @@
222 143 $application['upgradeUrl'] = $this->get_admin_upgrade_link();
223 144 $application['link'] = $application['upgradeUrl'];
224 145 }
225 146
226 - $application['isNew'] = $this->is_new();
227 -
228 - $application['usedAddons'] = array();
229 -
230 - if ( isset( $application['used_addons'] ) ) {
231 - // Change key to camel case.
232 - $application['usedAddons'] = $application['used_addons'];
233 - unset( $application['used_addons'] );
234 - }
235 -
236 147 return $application;
237 148 }
238 149
239 150 /**
@@ -252,9 +163,8 @@
252 163 return false;
253 164 }
254 165
255 166 $pro = $addons[93790];
256 -
257 167 if ( ! array_key_exists( 'type', $pro ) ) {
258 168 return false;
259 169 }
260 170
@@ -262,9 +172,8 @@
262 172 $args = array(
263 173 'license_type' => $license_type,
264 174 'plan_required' => $this->get_required_license(),
265 175 );
266 -
267 176 if ( ! FrmFormsHelper::plan_is_allowed( $args ) ) {
268 177 return false;
269 178 }
270 179
@@ -271,24 +180,12 @@
271 180 return true;
272 181 }
273 182
274 183 /**
275 - * Check if an application template is new. If it is, we include a "NEW" pill beside the title.
276 - *
277 - * @since 6.0
278 - *
279 - * @return bool
280 - */
281 - private function is_new() {
282 - return ! empty( $this->api_data['is_new'] );
283 - }
284 -
285 - /**
286 184 * @return string
287 185 */
288 186 private function get_required_license() {
289 187 $required_license = strtolower( $this->api_data['min_plan'] );
290 -
291 188 if ( 'plus' === $required_license ) {
292 189 $required_license = 'personal';
293 190 }
294 191 return $required_license;
@@ -302,8 +199,8 @@
302 199 array(
303 200 'content' => 'upgrade',
304 201 'medium' => 'applications',
305 202 ),
306 - 'view-templates/' . $this->api_data['slug']
203 + '/view-templates/' . $this->api_data['slug']
307 204 );
308 205 }
309 206 }