PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.5.5
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.5.5
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 +26 -48 6.275.5.5 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,25 +64,24 @@
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 86 if ( ! empty( $addon_list[ $matching_addon ]['external'] ) ) {
98 87 unset( $overrides['name'] );
@@ -111,12 +100,9 @@
111 100 * Search for any addons that match the searched terms.
112 101 *
113 102 * @since 4.12
114 103 *
115 - * @param array $addon_list
116 - * @param array $normalized_term
117 - *
118 - * @return int|null
104 + * @return int
119 105 */
120 106 private function matching_addon( $addon_list, $normalized_term ) {
121 107 $matching_addon = null;
122 108
@@ -129,12 +115,13 @@
129 115 if ( ! isset( $addon_opts['search_terms'] ) ) {
130 116 $addon_opts['search_terms'] = '';
131 117 }
132 118
133 - $addon_terms = $this->search_to_array( $addon_opts['search_terms'] . ' ' . $addon_opts['name'] );
134 - $matched_terms = array_intersect( $addon_terms, $normalized_term );
119 + $addon_terms = $this->search_to_array( $addon_opts['search_terms'] . ' ' . $addon_opts['name'] );
135 120
136 - if ( count( $matched_terms ) === count( $normalized_term ) ) {
121 + $matches = ! empty( array_intersect( $addon_terms, $normalized_term ) );
122 +
123 + if ( $matches ) {
137 124 $matching_addon = $addon_id;
138 125 break;
139 126 }
140 127 }
@@ -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,16 +258,16 @@
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 );
@@ -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,9 +287,9 @@
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'] );
313 294
314 295 // Plugin installed, active, feature not enabled; prompt to enable.
@@ -313,17 +294,17 @@
313 294
314 295 // Plugin installed, active, feature not enabled; prompt to enable.
315 296 if ( ! $is_active && $is_installed ) {
316 297 if ( current_user_can( 'activate_plugins' ) ) {
317 - $activate_url = add_query_arg(
298 + $activate_url = add_query_arg(
318 299 array(
319 - 'action' => 'activate',
300 + 'action' => 'activate',
320 301 '_wpnonce' => wp_create_nonce( 'activate-plugin_' . $plugin['plugin'] ),
321 302 'plugin' => $plugin['plugin'],
322 303 ),
323 304 admin_url( 'plugins.php' )
324 305 );
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
306 + $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 307 }
327 308 } elseif ( ! $is_active && isset( $plugin['url'] ) ) {
328 309 // Go to the add-ons page to install.
329 310 $links[] = '<a
@@ -338,9 +319,9 @@
338 319 href="' . esc_url( FrmAppHelper::admin_upgrade_link( 'plugin-learn-more', $plugin['link'] ) ) . '"
339 320 target="_blank"
340 321 data-addon="' . esc_attr( $plugin['addon'] ) . '"
341 322 >' . esc_html__( 'Learn more', 'formidable' ) . '</a>';
342 - }//end if
323 + }
343 324
344 325 // Dismiss link.
345 326 $dismiss = add_query_arg( array( 'frm-dismiss' => $plugin['id'] ) );
346 327 $links[] = '<a
@@ -353,9 +334,8 @@
353 334 }
354 335
355 336 /**
356 337 * @param string $plugin
357 - *
358 338 * @return bool
359 339 */
360 340 protected function is_installed( $plugin ) {
361 341 $all_plugins = FrmAppHelper::get_plugins();
@@ -363,10 +343,8 @@
363 343 }
364 344
365 345 /**
366 346 * Load the search scripts and CSS for PSH.
367 - *
368 - * @return void
369 347 */
370 348 public function load_plugins_search_script() {
371 349 wp_enqueue_script( self::$slug, FrmAppHelper::plugin_url() . '/js/plugin-search.js', array(), FrmAppHelper::plugin_version(), true );
372 350 wp_localize_script(