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