PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.17
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.17
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 +56 -16 6.46.17 View file →
@@ -8,31 +8,28 @@
8 8 */
9 9 class FrmApplicationTemplate {
10 10
11 11 /**
12 - * @var array<string>|null $keys
12 + * @var array<string>|null
13 13 */
14 14 private static $keys;
15 15
16 16 /**
17 - * @var array<string>|null $keys_with_images
17 + * @var array<string>|null
18 18 */
19 19 private static $keys_with_images;
20 20
21 21 /**
22 - * @var array<string>|null $categories
22 + * @var array<string>|null
23 23 */
24 24 private static $categories;
25 25
26 26 /**
27 - * @var array $api_data
27 + * @var array
28 28 */
29 29 private $api_data;
30 30
31 31 /**
32 - * @param array<string> $keys
33 - * @param array<string> $keys_with_images
34 - *
35 32 * @return void
36 33 */
37 34 public static function init() {
38 35 /**
@@ -41,20 +38,44 @@
41 38 * @param array $keys
42 39 */
43 40 self::$keys = apply_filters(
44 41 'frm_application_data_keys',
45 - array( 'key', 'name', 'description', 'link', 'categories', 'views', 'forms' )
42 + array( 'key', 'name', 'description', 'link', 'categories', 'views', 'forms', 'used_addons' )
46 43 );
47 - self::$keys_with_images = self::get_template_keys_with_local_images();
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 + );
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 + /**
52 73 * Return the template keys that have embedded images. Otherwise, we want to avoid trying to load the URL and use the placeholder instead.
53 74 *
54 75 * @return array<string>
55 76 */
56 - private static function get_template_keys_with_local_images() {
77 + private static function get_template_keys_with_local_png_images() {
57 78 return array(
58 79 'business-hours',
59 80 'faq-template-wordpress',
60 81 'restaurant-menu',
@@ -60,8 +81,9 @@
60 81 'restaurant-menu',
61 82 'team-directory',
62 83 'product-review',
63 84 'real-estate-listings',
85 + 'business-directory',
64 86 );
65 87 }
66 88
67 89 /**
@@ -101,9 +123,9 @@
101 123 private static function category_matches_a_license_type( $category ) {
102 124 if ( false !== strpos( $category, '+Views' ) ) {
103 125 return true;
104 126 }
105 - return in_array( $category, FrmFormsHelper::ignore_template_categories(), true );
127 + return in_array( $category, FrmFormsHelper::get_license_types(), true );
106 128 }
107 129
108 130 /**
109 131 * @return array<string>
@@ -115,8 +137,12 @@
115 137 /**
116 138 * @return array
117 139 */
118 140 public function as_js_object() {
141 + if ( ! is_array( self::$keys ) ) {
142 + return array();
143 + }
144 +
119 145 $application = array();
120 146 foreach ( self::$keys as $key ) {
121 147 if ( ! isset( $this->api_data[ $key ] ) ) {
122 148 continue;
@@ -130,9 +156,9 @@
130 156 } elseif ( 'categories' === $key ) {
131 157 $application[ $key ] = array_values(
132 158 array_filter(
133 159 $value,
134 - function( $category ) {
160 + function ( $category ) {
135 161 return false === strpos( $category, '+Views' );
136 162 }
137 163 )
138 164 );
@@ -147,25 +173,39 @@
147 173 // Strip off the " Template" text at the end of the name as it takes up space.
148 174 $value = substr( $value, 0, -9 );
149 175 }
150 176 $application[ $key ] = $value;
151 - }
152 - }
177 + }//end if
178 + }//end foreach
153 179
154 180 $application['hasLiteThumbnail'] = in_array( $application['key'], self::$keys_with_images, true );
181 + $application['isWebp'] = in_array( $application['key'], self::get_template_keys_with_local_webp_images(), true );
155 182
156 183 if ( ! array_key_exists( 'url', $application ) ) {
184 + $application['requires'] = FrmFormsHelper::get_plan_required( $application );
185 +
186 + if ( false === $application['requires'] ) {
187 + // Application is invalid if the URL is unavailable and there is no plan required.
188 + return array();
189 + }
190 +
157 191 $purchase_url = $this->is_available_for_purchase();
158 192 if ( false !== $purchase_url ) {
159 193 $application['forPurchase'] = true;
160 194 }
161 195 $application['upgradeUrl'] = $this->get_admin_upgrade_link();
162 - $application['requires'] = FrmFormsHelper::get_plan_required( $application );
163 196 $application['link'] = $application['upgradeUrl'];
164 197 }
165 198
166 199 $application['isNew'] = $this->is_new();
167 200
201 + $application['usedAddons'] = array();
202 + if ( isset( $application['used_addons'] ) ) {
203 + // Change key to camel case.
204 + $application['usedAddons'] = $application['used_addons'];
205 + unset( $application['used_addons'] );
206 + }
207 +
168 208 return $application;
169 209 }
170 210
171 211 /**
@@ -231,8 +271,8 @@
231 271 array(
232 272 'content' => 'upgrade',
233 273 'medium' => 'applications',
234 274 ),
235 - '/view-templates/' . $this->api_data['slug']
275 + 'view-templates/' . $this->api_data['slug']
236 276 );
237 277 }
238 278 }