PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.0.07
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.0.07
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/FrmPluginSearch.php +40 -60 6.275.0.07 View file →
@@ -25,13 +25,11 @@
25 25
26 26 /**
27 27 * Add actions and filters only if this is the plugin installation screen and it's the first page.
28 28 *
29 - * @since 4.12
30 - *
31 29 * @param object $screen WP Screen object.
32 30 *
33 - * @return void
31 + * @since 4.12
34 32 */
35 33 public function start( $screen ) {
36 34 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
37 35 if ( 'plugin-install' === $screen->base && ( ! isset( $_GET['paged'] ) || 1 === intval( $_GET['paged'] ) ) ) {
@@ -48,10 +46,8 @@
48 46 *
49 47 * @param object $result Plugin search results.
50 48 * @param string $action unused.
51 49 * @param object $args Search args.
52 - *
53 - * @return object
54 50 */
55 51 public function inject_suggestion( $result, $action, $args ) {
56 52 // Looks like a search query; it's matching time.
57 53 if ( empty( $args->search ) ) {
@@ -57,19 +53,13 @@
57 53 if ( empty( $args->search ) ) {
58 54 return $result;
59 55 }
60 56
61 - if ( is_wp_error( $result ) ) {
62 - // This may happen if the request failed due to an internet connection issue.
63 - return $result;
64 - }
65 -
66 57 $addon_list = $this->get_addons();
67 58
68 59 // Lowercase, trim, remove punctuation/special chars, decode url, remove 'formidable'.
69 60 $normalized_term = $this->search_to_array( $args->search );
70 -
71 - if ( ! $normalized_term ) {
61 + if ( empty( $normalized_term ) ) {
72 62 // Don't add anything extra.
73 63 return $result;
74 64 }
75 65
@@ -74,31 +64,26 @@
74 64 }
75 65
76 66 $matching_addon = $this->matching_addon( $addon_list, $normalized_term );
77 67
78 - if ( ! $matching_addon || ! $this->should_display_hint( $matching_addon ) ) {
68 + if ( empty( $matching_addon ) || ! $this->should_display_hint( $matching_addon ) ) {
79 69 return $result;
80 70 }
81 71
82 72 $inject = (array) $this->get_plugin_data();
83 73 $overrides = array(
84 - // Helps to determine if that an injected card.
85 - 'plugin-search' => true,
86 - 'name' => sprintf(
74 + 'plugin-search' => true, // Helps to determine if that an injected card.
75 + 'name' => sprintf(
87 76 /* translators: Formidable addon name */
88 77 esc_html_x( 'Formidable %s', 'Formidable Addon Name', 'formidable' ),
89 78 $addon_list[ $matching_addon ]['name']
90 79 ),
91 - 'addon' => $addon_list[ $matching_addon ]['slug'],
92 - 'short_description' => $addon_list[ $matching_addon ]['excerpt'],
93 - 'slug' => self::$slug,
94 - 'version' => $addon_list[ $matching_addon ]['version'],
80 + 'addon' => $addon_list[ $matching_addon ]['slug'],
81 + 'short_description' => $addon_list[ $matching_addon ]['excerpt'],
82 + 'slug' => self::$slug,
83 + 'version' => $addon_list[ $matching_addon ]['version'],
95 84 );
96 85
97 - if ( ! empty( $addon_list[ $matching_addon ]['external'] ) ) {
98 - unset( $overrides['name'] );
99 - }
100 -
101 86 // Splice in the base addon data.
102 87 $inject = array_merge( $inject, $addon_list[ $matching_addon ], $overrides );
103 88
104 89 // Add it to the top of the list.
@@ -111,12 +96,9 @@
111 96 * Search for any addons that match the searched terms.
112 97 *
113 98 * @since 4.12
114 99 *
115 - * @param array $addon_list
116 - * @param array $normalized_term
117 - *
118 - * @return int|null
100 + * @return int
119 101 */
120 102 private function matching_addon( $addon_list, $normalized_term ) {
121 103 $matching_addon = null;
122 104
@@ -125,16 +107,22 @@
125 107 if ( ! is_array( $addon_opts ) || empty( $addon_opts['excerpt'] ) ) {
126 108 continue;
127 109 }
128 110
111 + /*
112 + * Does the site's current plan support the feature?
113 + */
114 + $is_supported_by_plan = ! empty( $addon_opts['url'] );
115 +
129 116 if ( ! isset( $addon_opts['search_terms'] ) ) {
130 117 $addon_opts['search_terms'] = '';
131 118 }
132 119
133 - $addon_terms = $this->search_to_array( $addon_opts['search_terms'] . ' ' . $addon_opts['name'] );
134 - $matched_terms = array_intersect( $addon_terms, $normalized_term );
120 + $addon_terms = $this->search_to_array( $addon_opts['search_terms'] . ', ' . $addon_opts['name'] );
135 121
136 - if ( count( $matched_terms ) === count( $normalized_term ) ) {
122 + $matches = ! empty( array_intersect( $addon_terms, $normalized_term ) );
123 +
124 + if ( $matches && $is_supported_by_plan ) {
137 125 $matching_addon = $addon_id;
138 126 break;
139 127 }
140 128 }
@@ -148,10 +136,9 @@
148 136 * @return array
149 137 */
150 138 private function get_addons() {
151 139 $api = new FrmFormApi();
152 - $addons = $api->get_api_info();
153 - return apply_filters( 'frm_plugin_search', $addons );
140 + return $api->get_api_info();
154 141 }
155 142
156 143 /**
157 144 * Get the plugin repo's data to populate the fields with.
@@ -187,12 +174,12 @@
187 174
188 175 /**
189 176 * Modify URL used to fetch to plugin information so it pulls Formidable plugin page.
190 177 *
178 + * @param string $url URL to load in dialog pulling the plugin page from wporg.
179 + *
191 180 * @since 4.12
192 181 *
193 - * @param string $url URL to load in dialog pulling the plugin page from wporg.
194 - *
195 182 * @return string The URL with 'formidable' instead of 'frm-plugin-search'.
196 183 */
197 184 public function plugin_details( $url ) {
198 185 return false !== stripos( $url, 'tab=plugin-information&plugin=' . self::$slug )
@@ -201,15 +188,12 @@
201 188 }
202 189
203 190 /**
204 191 * @since 4.12
205 - *
206 - * @return void
207 192 */
208 193 private function maybe_dismiss() {
209 194 $addon = FrmAppHelper::get_param( 'frm-dismiss', '', 'get', 'absint' );
210 -
211 - if ( $addon ) {
195 + if ( ! empty( $addon ) ) {
212 196 $this->add_to_dismissed_hints( $addon );
213 197 }
214 198 }
215 199
@@ -221,9 +205,9 @@
221 205 * @return array List of dismissed hints.
222 206 */
223 207 protected function get_dismissed_hints() {
224 208 $dismissed_hints = get_option( self::$dismissed_opt );
225 - return $dismissed_hints && is_array( $dismissed_hints ) ? $dismissed_hints : array();
209 + return ! empty( $dismissed_hints ) && is_array( $dismissed_hints ) ? $dismissed_hints : array();
226 210 }
227 211
228 212 /**
229 213 * Save the hint in the list of dismissed hints.
@@ -265,9 +249,8 @@
265 249 * Take a raw search query and return something a bit more standardized and
266 250 * easy to work with.
267 251 *
268 252 * @param string $term The raw search term.
269 - *
270 253 * @return string A simplified/sanitized version.
271 254 */
272 255 private function sanitize_search_term( $term ) {
273 256 $term = strtolower( urldecode( $term ) );
@@ -275,21 +258,21 @@
275 258 // remove non-alpha/space chars.
276 259 $term = preg_replace( '/[^a-z ]/', '', $term );
277 260
278 261 // remove strings that don't help matches.
279 - return trim( str_replace( array( 'formidable', 'free', 'wordpress', 'wp ', 'plugin' ), '', $term ) );
262 + $term = trim( str_replace( array( 'formidable', 'free', 'wordpress', 'wp ', 'plugin' ), '', $term ) );
263 +
264 + return $term;
280 265 }
281 266
282 267 /**
283 268 * @since 4.12
284 269 *
285 - * @param string $terms
286 - *
287 270 * @return array
288 271 */
289 272 private function search_to_array( $terms ) {
290 273 $terms = $this->sanitize_search_term( $terms );
291 - return array_filter( explode( ' ', $terms ) );
274 + return array_filter( explode( ',', $terms ) );
292 275 }
293 276
294 277 /**
295 278 * Put some more appropriate links on our custom result cards.
@@ -295,10 +278,8 @@
295 278 * Put some more appropriate links on our custom result cards.
296 279 *
297 280 * @param array $links Related links.
298 281 * @param array $plugin Plugin result information.
299 - *
300 - * @return array
301 282 */
302 283 public function insert_related_links( $links, $plugin ) {
303 284 if ( self::$slug !== $plugin['slug'] ) {
304 285 return $links;
@@ -306,24 +287,25 @@
306 287
307 288 // By the time this filter is applied, self_admin_url was already applied and we don't need it anymore.
308 289 remove_filter( 'self_admin_url', array( $this, 'plugin_details' ) );
309 290
310 - $links = array();
291 + $links = array();
311 292 $is_installed = $this->is_installed( $plugin['plugin'] );
312 293 $is_active = is_plugin_active( $plugin['plugin'] );
294 + $has_access = ! empty( $plugin['url'] );
313 295
314 296 // Plugin installed, active, feature not enabled; prompt to enable.
315 297 if ( ! $is_active && $is_installed ) {
316 298 if ( current_user_can( 'activate_plugins' ) ) {
317 - $activate_url = add_query_arg(
299 + $activate_url = add_query_arg(
318 300 array(
319 - 'action' => 'activate',
301 + 'action' => 'activate',
320 302 '_wpnonce' => wp_create_nonce( 'activate-plugin_' . $plugin['plugin'] ),
321 303 'plugin' => $plugin['plugin'],
322 304 ),
323 305 admin_url( 'plugins.php' )
324 306 );
325 - $links['frm_get_started'] = '<a href="' . esc_url( $activate_url ) . '" class="button activate-now" aria-label="Activate ' . esc_attr( $plugin['name'] ) . '">' . __( 'Activate', 'formidable' ) . '</a>'; // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
307 + $links['frm_get_started'] = '<a href="' . esc_url( $activate_url ) . '" class="button activate-now" aria-label="Activate ' . esc_attr( $plugin['name'] ) . '">' . __( 'Activate', 'formidable' ) . '</a>';
326 308 }
327 309 } elseif ( ! $is_active && isset( $plugin['url'] ) ) {
328 310 // Go to the add-ons page to install.
329 311 $links[] = '<a
@@ -338,9 +320,9 @@
338 320 href="' . esc_url( FrmAppHelper::admin_upgrade_link( 'plugin-learn-more', $plugin['link'] ) ) . '"
339 321 target="_blank"
340 322 data-addon="' . esc_attr( $plugin['addon'] ) . '"
341 323 >' . esc_html__( 'Learn more', 'formidable' ) . '</a>';
342 - }//end if
324 + }
343 325
344 326 // Dismiss link.
345 327 $dismiss = add_query_arg( array( 'frm-dismiss' => $plugin['id'] ) );
346 328 $links[] = '<a
@@ -351,22 +333,20 @@
351 333
352 334 return $links;
353 335 }
354 336
355 - /**
356 - * @param string $plugin
357 - *
358 - * @return bool
359 - */
360 337 protected function is_installed( $plugin ) {
361 - $all_plugins = FrmAppHelper::get_plugins();
338 + if ( ! function_exists( 'get_plugins' ) ) {
339 + require_once ABSPATH . 'wp-admin/includes/plugin.php';
340 + }
341 +
342 + $all_plugins = get_plugins();
343 +
362 344 return isset( $all_plugins[ $plugin ] );
363 345 }
364 346
365 347 /**
366 348 * Load the search scripts and CSS for PSH.
367 - *
368 - * @return void
369 349 */
370 350 public function load_plugins_search_script() {
371 351 wp_enqueue_script( self::$slug, FrmAppHelper::plugin_url() . '/js/plugin-search.js', array(), FrmAppHelper::plugin_version(), true );
372 352 wp_localize_script(