PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.8
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.8
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 +24 -91 6.296.8 View file →
@@ -8,24 +8,24 @@
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 /**
@@ -38,44 +38,20 @@
38 38 * @param array $keys
39 39 */
40 40 self::$keys = apply_filters(
41 41 'frm_application_data_keys',
42 - array( 'key', 'name', 'description', 'link', 'categories', 'views', 'forms', 'used_addons' )
42 + array( 'key', 'name', 'description', 'link', 'categories', 'views', 'forms' )
43 43 );
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 - );
44 + self::$keys_with_images = self::get_template_keys_with_local_images();
48 45 self::$categories = array();
49 46 }
50 47
51 48 /**
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 49 * Return the template keys that have embedded images. Otherwise, we want to avoid trying to load the URL and use the placeholder instead.
74 50 *
75 51 * @return array<string>
76 52 */
77 - private static function get_template_keys_with_local_png_images() {
53 + private static function get_template_keys_with_local_images() {
78 54 return array(
79 55 'business-hours',
80 56 'faq-template-wordpress',
81 57 'restaurant-menu',
@@ -81,36 +57,13 @@
81 57 'restaurant-menu',
82 58 'team-directory',
83 59 'product-review',
84 60 '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 61 );
108 62 }
109 63
110 64 /**
111 65 * @param array $api_data
112 - *
113 66 * @return void
114 67 */
115 68 public function __construct( $api_data ) {
116 69 $this->api_data = $api_data;
@@ -121,9 +74,8 @@
121 74 }
122 75
123 76 /**
124 77 * @param array<string> $categories
125 - *
126 78 * @return void
127 79 */
128 80 private static function populate_category_information( $categories ) {
129 81 foreach ( $categories as $category ) {
@@ -129,9 +81,8 @@
129 81 foreach ( $categories as $category ) {
130 82 if ( self::category_matches_a_license_type( $category ) ) {
131 83 continue;
132 84 }
133 -
134 85 if ( in_array( $category, self::$categories, true ) ) {
135 86 continue;
136 87 }
137 88 self::$categories[] = $category;
@@ -141,16 +92,15 @@
141 92 /**
142 93 * @since 5.5.2
143 94 *
144 95 * @param string $category
145 - *
146 96 * @return bool
147 97 */
148 98 private static function category_matches_a_license_type( $category ) {
149 - if ( str_contains( $category, '+Views' ) ) {
99 + if ( false !== strpos( $category, '+Views' ) ) {
150 100 return true;
151 101 }
152 - return in_array( $category, FrmFormsHelper::get_license_types(), true );
102 + return in_array( $category, FrmFormsHelper::ignore_template_categories(), true );
153 103 }
154 104
155 105 /**
156 106 * @return array<string>
@@ -155,9 +105,9 @@
155 105 /**
156 106 * @return array<string>
157 107 */
158 108 public static function get_categories() {
159 - return self::$categories ?? array();
109 + return isset( self::$categories ) ? self::$categories : array();
160 110 }
161 111
162 112 /**
163 113 * @return array
@@ -162,14 +112,9 @@
162 112 /**
163 113 * @return array
164 114 */
165 115 public function as_js_object() {
166 - if ( ! is_array( self::$keys ) ) {
167 - return array();
168 - }
169 -
170 116 $application = array();
171 -
172 117 foreach ( self::$keys as $key ) {
173 118 if ( ! isset( $this->api_data[ $key ] ) ) {
174 119 continue;
175 120 }
@@ -182,10 +127,10 @@
182 127 } elseif ( 'categories' === $key ) {
183 128 $application[ $key ] = array_values(
184 129 array_filter(
185 130 $value,
186 - function ( $category ) {
187 - return ! str_contains( $category, '+Views' );
131 + function( $category ) {
132 + return false === strpos( $category, '+Views' );
188 133 }
189 134 )
190 135 );
191 136 } else {
@@ -194,48 +139,30 @@
194 139 } elseif ( 'forms' === $key ) {
195 140 $key = 'formCount';
196 141 }
197 142
198 - if ( 'name' === $key && str_ends_with( $value, ' Template' ) ) {
143 + if ( 'name' === $key && ' Template' === substr( $value, -9 ) ) {
199 144 // Strip off the " Template" text at the end of the name as it takes up space.
200 145 $value = substr( $value, 0, -9 );
201 146 }
202 -
203 147 $application[ $key ] = $value;
204 148 }//end if
205 149 }//end foreach
206 150
207 151 $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 152
210 153 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 154 $purchase_url = $this->is_available_for_purchase();
219 -
220 155 if ( false !== $purchase_url ) {
221 156 $application['forPurchase'] = true;
222 157 }
223 -
224 158 $application['upgradeUrl'] = $this->get_admin_upgrade_link();
159 + $application['requires'] = FrmFormsHelper::get_plan_required( $application );
225 160 $application['link'] = $application['upgradeUrl'];
226 161 }
227 162
228 163 $application['isNew'] = $this->is_new();
229 164
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 165 return $application;
239 166 }
240 167
241 168 /**
@@ -254,9 +181,8 @@
254 181 return false;
255 182 }
256 183
257 184 $pro = $addons[93790];
258 -
259 185 if ( ! array_key_exists( 'type', $pro ) ) {
260 186 return false;
261 187 }
262 188
@@ -264,9 +190,13 @@
264 190 $args = array(
265 191 'license_type' => $license_type,
266 192 'plan_required' => $this->get_required_license(),
267 193 );
268 - return FrmFormsHelper::plan_is_allowed( $args );
194 + if ( ! FrmFormsHelper::plan_is_allowed( $args ) ) {
195 + return false;
196 + }
197 +
198 + return true;
269 199 }
270 200
271 201 /**
272 202 * Check if an application template is new. If it is, we include a "NEW" pill beside the title.
@@ -283,9 +213,12 @@
283 213 * @return string
284 214 */
285 215 private function get_required_license() {
286 216 $required_license = strtolower( $this->api_data['min_plan'] );
287 - return 'plus' === $required_license ? 'personal' : $required_license;
217 + if ( 'plus' === $required_license ) {
218 + $required_license = 'personal';
219 + }
220 + return $required_license;
288 221 }
289 222
290 223 /**
291 224 * @return string
@@ -295,8 +228,8 @@
295 228 array(
296 229 'content' => 'upgrade',
297 230 'medium' => 'applications',
298 231 ),
299 - 'view-templates/' . $this->api_data['slug']
232 + '/view-templates/' . $this->api_data['slug']
300 233 );
301 234 }
302 235 }