| @@ -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,19 +70,18 @@ | ||
| 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 | 86 | if ( ! empty( $addon_list[ $matching_addon ]['external'] ) ) { |
| 96 | 87 | unset( $overrides['name'] ); |
| @@ -109,12 +100,9 @@ | ||
| 109 | 100 | * Search for any addons that match the searched terms. |
| 110 | 101 | * |
| 111 | 102 | * @since 4.12 |
| 112 | 103 | * |
| 113 | - * @param array $addon_list | |
| 114 | - * @param array $normalized_term | |
| 115 | - * | |
| 116 | - * @return int|null | |
| 104 | + * @return int | |
| 117 | 105 | */ |
| 118 | 106 | private function matching_addon( $addon_list, $normalized_term ) { |
| 119 | 107 | $matching_addon = null; |
| 120 | 108 | |
| @@ -129,11 +117,11 @@ | ||
| 129 | 117 | } |
| 130 | 118 | |
| 131 | 119 | $addon_terms = $this->search_to_array( $addon_opts['search_terms'] . ' ' . $addon_opts['name'] ); |
| 132 | 120 | |
| 133 | - $matched_terms = array_intersect( $addon_terms, $normalized_term ); | |
| 121 | + $matches = ! empty( array_intersect( $addon_terms, $normalized_term ) ); | |
| 134 | 122 | |
| 135 | - if ( count( $matched_terms ) === count( $normalized_term ) ) { | |
| 123 | + if ( $matches ) { | |
| 136 | 124 | $matching_addon = $addon_id; |
| 137 | 125 | break; |
| 138 | 126 | } |
| 139 | 127 | } |
| @@ -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,9 +266,8 @@ | ||
| 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 ); |
| @@ -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,9 +287,9 @@ | ||
| 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'] ); |
| 310 | 294 | |
| 311 | 295 | // Plugin installed, active, feature not enabled; prompt to enable. |
| @@ -310,11 +294,11 @@ | ||
| 310 | 294 | |
| 311 | 295 | // Plugin installed, active, feature not enabled; prompt to enable. |
| 312 | 296 | if ( ! $is_active && $is_installed ) { |
| 313 | 297 | if ( current_user_can( 'activate_plugins' ) ) { |
| 314 | - $activate_url = add_query_arg( | |
| 298 | + $activate_url = add_query_arg( | |
| 315 | 299 | array( |
| 316 | - 'action' => 'activate', | |
| 300 | + 'action' => 'activate', | |
| 317 | 301 | '_wpnonce' => wp_create_nonce( 'activate-plugin_' . $plugin['plugin'] ), |
| 318 | 302 | 'plugin' => $plugin['plugin'], |
| 319 | 303 | ), |
| 320 | 304 | admin_url( 'plugins.php' ) |
| @@ -335,9 +319,9 @@ | ||
| 335 | 319 | href="' . esc_url( FrmAppHelper::admin_upgrade_link( 'plugin-learn-more', $plugin['link'] ) ) . '" |
| 336 | 320 | target="_blank" |
| 337 | 321 | data-addon="' . esc_attr( $plugin['addon'] ) . '" |
| 338 | 322 | >' . esc_html__( 'Learn more', 'formidable' ) . '</a>'; |
| 339 | - }//end if | |
| 323 | + } | |
| 340 | 324 | |
| 341 | 325 | // Dismiss link. |
| 342 | 326 | $dismiss = add_query_arg( array( 'frm-dismiss' => $plugin['id'] ) ); |
| 343 | 327 | $links[] = '<a |
| @@ -359,10 +343,8 @@ | ||
| 359 | 343 | } |
| 360 | 344 | |
| 361 | 345 | /** |
| 362 | 346 | * Load the search scripts and CSS for PSH. |
| 363 | - * | |
| 364 | - * @return void | |
| 365 | 347 | */ |
| 366 | 348 | public function load_plugins_search_script() { |
| 367 | 349 | wp_enqueue_script( self::$slug, FrmAppHelper::plugin_url() . '/js/plugin-search.js', array(), FrmAppHelper::plugin_version(), true ); |
| 368 | 350 | wp_localize_script( |