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