PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.0
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.0
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 -54 6.265.0 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,18 +53,12 @@
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 61 if ( empty( $normalized_term ) ) {
72 62 // Don't add anything extra.
73 63 return $result;
74 64 }
@@ -80,25 +70,20 @@
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,17 +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'] );
120 + $addon_terms = $this->search_to_array( $addon_opts['search_terms'] . ', ' . $addon_opts['name'] );
134 121
135 - $matched_terms = array_intersect( $addon_terms, $normalized_term );
122 + $matches = ! empty( array_intersect( $addon_terms, $normalized_term ) );
136 123
137 - if ( count( $matched_terms ) === count( $normalized_term ) ) {
124 + if ( $matches && $is_supported_by_plan ) {
138 125 $matching_addon = $addon_id;
139 126 break;
140 127 }
141 128 }
@@ -149,10 +136,9 @@
149 136 * @return array
150 137 */
151 138 private function get_addons() {
152 139 $api = new FrmFormApi();
153 - $addons = $api->get_api_info();
154 - return apply_filters( 'frm_plugin_search', $addons );
140 + return $api->get_api_info();
155 141 }
156 142
157 143 /**
158 144 * Get the plugin repo's data to populate the fields with.
@@ -188,12 +174,12 @@
188 174
189 175 /**
190 176 * Modify URL used to fetch to plugin information so it pulls Formidable plugin page.
191 177 *
178 + * @param string $url URL to load in dialog pulling the plugin page from wporg.
179 + *
192 180 * @since 4.12
193 181 *
194 - * @param string $url URL to load in dialog pulling the plugin page from wporg.
195 - *
196 182 * @return string The URL with 'formidable' instead of 'frm-plugin-search'.
197 183 */
198 184 public function plugin_details( $url ) {
199 185 return false !== stripos( $url, 'tab=plugin-information&plugin=' . self::$slug )
@@ -202,14 +188,11 @@
202 188 }
203 189
204 190 /**
205 191 * @since 4.12
206 - *
207 - * @return void
208 192 */
209 193 private function maybe_dismiss() {
210 194 $addon = FrmAppHelper::get_param( 'frm-dismiss', '', 'get', 'absint' );
211 -
212 195 if ( ! empty( $addon ) ) {
213 196 $this->add_to_dismissed_hints( $addon );
214 197 }
215 198 }
@@ -266,9 +249,8 @@
266 249 * Take a raw search query and return something a bit more standardized and
267 250 * easy to work with.
268 251 *
269 252 * @param string $term The raw search term.
270 - *
271 253 * @return string A simplified/sanitized version.
272 254 */
273 255 private function sanitize_search_term( $term ) {
274 256 $term = strtolower( urldecode( $term ) );
@@ -284,15 +266,13 @@
284 266
285 267 /**
286 268 * @since 4.12
287 269 *
288 - * @param string $terms
289 - *
290 270 * @return array
291 271 */
292 272 private function search_to_array( $terms ) {
293 273 $terms = $this->sanitize_search_term( $terms );
294 - return array_filter( explode( ' ', $terms ) );
274 + return array_filter( explode( ',', $terms ) );
295 275 }
296 276
297 277 /**
298 278 * Put some more appropriate links on our custom result cards.
@@ -298,10 +278,8 @@
298 278 * Put some more appropriate links on our custom result cards.
299 279 *
300 280 * @param array $links Related links.
301 281 * @param array $plugin Plugin result information.
302 - *
303 - * @return array
304 282 */
305 283 public function insert_related_links( $links, $plugin ) {
306 284 if ( self::$slug !== $plugin['slug'] ) {
307 285 return $links;
@@ -309,18 +287,19 @@
309 287
310 288 // By the time this filter is applied, self_admin_url was already applied and we don't need it anymore.
311 289 remove_filter( 'self_admin_url', array( $this, 'plugin_details' ) );
312 290
313 - $links = array();
291 + $links = array();
314 292 $is_installed = $this->is_installed( $plugin['plugin'] );
315 293 $is_active = is_plugin_active( $plugin['plugin'] );
294 + $has_access = ! empty( $plugin['url'] );
316 295
317 296 // Plugin installed, active, feature not enabled; prompt to enable.
318 297 if ( ! $is_active && $is_installed ) {
319 298 if ( current_user_can( 'activate_plugins' ) ) {
320 - $activate_url = add_query_arg(
299 + $activate_url = add_query_arg(
321 300 array(
322 - 'action' => 'activate',
301 + 'action' => 'activate',
323 302 '_wpnonce' => wp_create_nonce( 'activate-plugin_' . $plugin['plugin'] ),
324 303 'plugin' => $plugin['plugin'],
325 304 ),
326 305 admin_url( 'plugins.php' )
@@ -341,9 +320,9 @@
341 320 href="' . esc_url( FrmAppHelper::admin_upgrade_link( 'plugin-learn-more', $plugin['link'] ) ) . '"
342 321 target="_blank"
343 322 data-addon="' . esc_attr( $plugin['addon'] ) . '"
344 323 >' . esc_html__( 'Learn more', 'formidable' ) . '</a>';
345 - }//end if
324 + }
346 325
347 326 // Dismiss link.
348 327 $dismiss = add_query_arg( array( 'frm-dismiss' => $plugin['id'] ) );
349 328 $links[] = '<a
@@ -354,22 +333,20 @@
354 333
355 334 return $links;
356 335 }
357 336
358 - /**
359 - * @param string $plugin
360 - *
361 - * @return bool
362 - */
363 337 protected function is_installed( $plugin ) {
364 - $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 +
365 344 return isset( $all_plugins[ $plugin ] );
366 345 }
367 346
368 347 /**
369 348 * Load the search scripts and CSS for PSH.
370 - *
371 - * @return void
372 349 */
373 350 public function load_plugins_search_script() {
374 351 wp_enqueue_script( self::$slug, FrmAppHelper::plugin_url() . '/js/plugin-search.js', array(), FrmAppHelper::plugin_version(), true );
375 352 wp_localize_script(