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