PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.0
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.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 +38 -63 6.326.0 View file →
@@ -25,25 +25,21 @@
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 - if ( 'plugin-install' !== $screen->base || ( isset( $_GET['paged'] ) && 1 !== intval( $_GET['paged'] ) ) ) {
38 - return;
35 + if ( 'plugin-install' === $screen->base && ( ! isset( $_GET['paged'] ) || 1 === intval( $_GET['paged'] ) ) ) {
36 + add_filter( 'plugins_api_result', array( $this, 'inject_suggestion' ), 10, 3 );
37 + add_filter( 'self_admin_url', array( $this, 'plugin_details' ) );
38 + add_filter( 'plugin_install_action_links', array( $this, 'insert_related_links' ), 10, 2 );
39 + add_action( 'admin_enqueue_scripts', array( $this, 'load_plugins_search_script' ) );
40 + $this->maybe_dismiss();
39 41 }
40 -
41 - add_filter( 'plugins_api_result', array( $this, 'inject_suggestion' ), 10, 3 );
42 - add_filter( 'self_admin_url', array( $this, 'plugin_details' ) );
43 - add_filter( 'plugin_install_action_links', array( $this, 'insert_related_links' ), 10, 2 );
44 - add_action( 'admin_enqueue_scripts', array( $this, 'load_plugins_search_script' ) );
45 - $this->maybe_dismiss();
46 42 }
47 43
48 44 /**
49 45 * Intercept the plugins API response and add in an appropriate card.
@@ -50,10 +46,8 @@
50 46 *
51 47 * @param object $result Plugin search results.
52 48 * @param string $action unused.
53 49 * @param object $args Search args.
54 - *
55 - * @return object
56 50 */
57 51 public function inject_suggestion( $result, $action, $args ) {
58 52 // Looks like a search query; it's matching time.
59 53 if ( empty( $args->search ) ) {
@@ -59,19 +53,13 @@
59 53 if ( empty( $args->search ) ) {
60 54 return $result;
61 55 }
62 56
63 - if ( is_wp_error( $result ) ) {
64 - // This may happen if the request failed due to an internet connection issue.
65 - return $result;
66 - }
67 -
68 57 $addon_list = $this->get_addons();
69 58
70 59 // Lowercase, trim, remove punctuation/special chars, decode url, remove 'formidable'.
71 60 $normalized_term = $this->search_to_array( $args->search );
72 -
73 - if ( ! $normalized_term ) {
61 + if ( empty( $normalized_term ) ) {
74 62 // Don't add anything extra.
75 63 return $result;
76 64 }
77 65
@@ -76,25 +64,24 @@
76 64 }
77 65
78 66 $matching_addon = $this->matching_addon( $addon_list, $normalized_term );
79 67
80 - if ( ! $matching_addon || ! $this->should_display_hint( $matching_addon ) ) {
68 + if ( empty( $matching_addon ) || ! $this->should_display_hint( $matching_addon ) ) {
81 69 return $result;
82 70 }
83 71
84 72 $inject = (array) $this->get_plugin_data();
85 73 $overrides = array(
86 - // Helps to determine if that an injected card.
87 - 'plugin-search' => true,
88 - 'name' => sprintf(
74 + 'plugin-search' => true, // Helps to determine if that an injected card.
75 + 'name' => sprintf(
89 76 /* translators: Formidable addon name */
90 77 esc_html_x( 'Formidable %s', 'Formidable Addon Name', 'formidable' ),
91 78 $addon_list[ $matching_addon ]['name']
92 79 ),
93 - 'addon' => $addon_list[ $matching_addon ]['slug'],
94 - 'short_description' => $addon_list[ $matching_addon ]['excerpt'],
95 - 'slug' => self::$slug,
96 - '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'],
97 84 );
98 85
99 86 if ( ! empty( $addon_list[ $matching_addon ]['external'] ) ) {
100 87 unset( $overrides['name'] );
@@ -113,12 +100,9 @@
113 100 * Search for any addons that match the searched terms.
114 101 *
115 102 * @since 4.12
116 103 *
117 - * @param array $addon_list
118 - * @param array $normalized_term
119 - *
120 - * @return int|null
104 + * @return int
121 105 */
122 106 private function matching_addon( $addon_list, $normalized_term ) {
123 107 $matching_addon = null;
124 108
@@ -131,12 +115,13 @@
131 115 if ( ! isset( $addon_opts['search_terms'] ) ) {
132 116 $addon_opts['search_terms'] = '';
133 117 }
134 118
135 - $addon_terms = $this->search_to_array( $addon_opts['search_terms'] . ' ' . $addon_opts['name'] );
136 - $matched_terms = array_intersect( $addon_terms, $normalized_term );
119 + $addon_terms = $this->search_to_array( $addon_opts['search_terms'] . ' ' . $addon_opts['name'] );
137 120
138 - if ( count( $matched_terms ) === count( $normalized_term ) ) {
121 + $matches = ! empty( array_intersect( $addon_terms, $normalized_term ) );
122 +
123 + if ( $matches ) {
139 124 $matching_addon = $addon_id;
140 125 break;
141 126 }
142 127 }
@@ -189,31 +174,26 @@
189 174
190 175 /**
191 176 * Modify URL used to fetch to plugin information so it pulls Formidable plugin page.
192 177 *
178 + * @param string $url URL to load in dialog pulling the plugin page from wporg.
179 + *
193 180 * @since 4.12
194 181 *
195 - * @param string $url URL to load in dialog pulling the plugin page from wporg.
196 - *
197 182 * @return string The URL with 'formidable' instead of 'frm-plugin-search'.
198 183 */
199 184 public function plugin_details( $url ) {
200 - // phpcs:disable Generic.WhiteSpace.ScopeIndent
201 185 return false !== stripos( $url, 'tab=plugin-information&plugin=' . self::$slug )
202 186 ? 'plugin-install.php?tab=plugin-information&plugin=formidable&TB_iframe=true&width=600&height=550'
203 187 : $url;
204 - // phpcs:enable Generic.WhiteSpace.ScopeIndent
205 188 }
206 189
207 190 /**
208 191 * @since 4.12
209 - *
210 - * @return void
211 192 */
212 193 private function maybe_dismiss() {
213 194 $addon = FrmAppHelper::get_param( 'frm-dismiss', '', 'get', 'absint' );
214 -
215 - if ( $addon ) {
195 + if ( ! empty( $addon ) ) {
216 196 $this->add_to_dismissed_hints( $addon );
217 197 }
218 198 }
219 199
@@ -225,9 +205,9 @@
225 205 * @return array List of dismissed hints.
226 206 */
227 207 protected function get_dismissed_hints() {
228 208 $dismissed_hints = get_option( self::$dismissed_opt );
229 - return $dismissed_hints && is_array( $dismissed_hints ) ? $dismissed_hints : array();
209 + return ! empty( $dismissed_hints ) && is_array( $dismissed_hints ) ? $dismissed_hints : array();
230 210 }
231 211
232 212 /**
233 213 * Save the hint in the list of dismissed hints.
@@ -239,9 +219,9 @@
239 219 * @return bool Whether the card was added to the list and hence dismissed.
240 220 */
241 221 protected function add_to_dismissed_hints( $hint ) {
242 222 $hints = array_merge( $this->get_dismissed_hints(), array( $hint ) );
243 - return update_option( self::$dismissed_opt, $hints, false );
223 + return update_option( self::$dismissed_opt, $hints, 'no' );
244 224 }
245 225
246 226 /**
247 227 * Checks that the addon slug passed should be displayed.
@@ -269,26 +249,25 @@
269 249 * Take a raw search query and return something a bit more standardized and
270 250 * easy to work with.
271 251 *
272 252 * @param string $term The raw search term.
273 - *
274 253 * @return string A simplified/sanitized version.
275 254 */
276 255 private function sanitize_search_term( $term ) {
277 256 $term = strtolower( urldecode( $term ) );
278 257
279 - // Remove non-alpha/space chars.
258 + // remove non-alpha/space chars.
280 259 $term = preg_replace( '/[^a-z ]/', '', $term );
281 260
282 - // Remove strings that don't help matches.
283 - return trim( str_replace( array( 'formidable', 'free', 'wordpress', 'wp ', 'plugin' ), '', $term ) );
261 + // remove strings that don't help matches.
262 + $term = trim( str_replace( array( 'formidable', 'free', 'wordpress', 'wp ', 'plugin' ), '', $term ) );
263 +
264 + return $term;
284 265 }
285 266
286 267 /**
287 268 * @since 4.12
288 269 *
289 - * @param string $terms
290 - *
291 270 * @return array
292 271 */
293 272 private function search_to_array( $terms ) {
294 273 $terms = $this->sanitize_search_term( $terms );
@@ -299,10 +278,8 @@
299 278 * Put some more appropriate links on our custom result cards.
300 279 *
301 280 * @param array $links Related links.
302 281 * @param array $plugin Plugin result information.
303 - *
304 - * @return array
305 282 */
306 283 public function insert_related_links( $links, $plugin ) {
307 284 if ( self::$slug !== $plugin['slug'] ) {
308 285 return $links;
@@ -310,9 +287,9 @@
310 287
311 288 // By the time this filter is applied, self_admin_url was already applied and we don't need it anymore.
312 289 remove_filter( 'self_admin_url', array( $this, 'plugin_details' ) );
313 290
314 - $links = array();
291 + $links = array();
315 292 $is_installed = $this->is_installed( $plugin['plugin'] );
316 293 $is_active = is_plugin_active( $plugin['plugin'] );
317 294
318 295 // Plugin installed, active, feature not enabled; prompt to enable.
@@ -317,17 +294,17 @@
317 294
318 295 // Plugin installed, active, feature not enabled; prompt to enable.
319 296 if ( ! $is_active && $is_installed ) {
320 297 if ( current_user_can( 'activate_plugins' ) ) {
321 - $activate_url = add_query_arg(
298 + $activate_url = add_query_arg(
322 299 array(
323 - 'action' => 'activate',
300 + 'action' => 'activate',
324 301 '_wpnonce' => wp_create_nonce( 'activate-plugin_' . $plugin['plugin'] ),
325 302 'plugin' => $plugin['plugin'],
326 303 ),
327 304 admin_url( 'plugins.php' )
328 305 );
329 - $links['frm_get_started'] = '<a href="' . esc_url( $activate_url ) . '" class="button activate-now" aria-label="Activate ' . esc_attr( $plugin['name'] ) . '">' . esc_html__( '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>';
330 307 }
331 308 } elseif ( ! $is_active && isset( $plugin['url'] ) ) {
332 309 // Go to the add-ons page to install.
333 310 $links[] = '<a
@@ -332,9 +309,10 @@
332 309 // Go to the add-ons page to install.
333 310 $links[] = '<a
334 311 class="button-secondary"
335 312 href="' . esc_url( admin_url( 'admin.php?page=formidable-addons' ) ) . '"
336 - >' . esc_html__( 'Install Now', 'formidable' ) . '</a>';
313 + >' . __( 'Install Now', 'formidable' ) . '</a>';
314 +
337 315 } elseif ( ! empty( $plugin['link'] ) ) {
338 316 // Add link pointing to a relevant doc page in formidable.com.
339 317 $links[] = '<a
340 318 class="button-primary frm-plugin-search__learn-more"
@@ -341,14 +319,14 @@
341 319 href="' . esc_url( FrmAppHelper::admin_upgrade_link( 'plugin-learn-more', $plugin['link'] ) ) . '"
342 320 target="_blank"
343 321 data-addon="' . esc_attr( $plugin['addon'] ) . '"
344 322 >' . esc_html__( 'Learn more', 'formidable' ) . '</a>';
345 - }//end if
323 + }
346 324
347 325 // Dismiss link.
348 326 $dismiss = add_query_arg( array( 'frm-dismiss' => $plugin['id'] ) );
349 327 $links[] = '<a
350 - href="' . esc_url( $dismiss ) . '"
328 + href="' . $dismiss . '"
351 329 class="frm-plugin-search__dismiss"
352 330 data-addon="' . esc_attr( $plugin['addon'] ) . '"
353 331 >' . esc_html__( 'Hide this suggestion', 'formidable' ) . '</a>';
354 332
@@ -356,9 +334,8 @@
356 334 }
357 335
358 336 /**
359 337 * @param string $plugin
360 - *
361 338 * @return bool
362 339 */
363 340 protected function is_installed( $plugin ) {
364 341 $all_plugins = FrmAppHelper::get_plugins();
@@ -366,10 +343,8 @@
366 343 }
367 344
368 345 /**
369 346 * Load the search scripts and CSS for PSH.
370 - *
371 - * @return void
372 347 */
373 348 public function load_plugins_search_script() {
374 349 wp_enqueue_script( self::$slug, FrmAppHelper::plugin_url() . '/js/plugin-search.js', array(), FrmAppHelper::plugin_version(), true );
375 350 wp_localize_script(