| @@ -26,8 +26,9 @@ | ||
| 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 | 29 | * @since 4.12 |
| 30 | + * | |
| 30 | 31 | * @param object $screen WP Screen object. |
| 31 | 32 | * |
| 32 | 33 | * @return void |
| 33 | 34 | */ |
| @@ -32,15 +33,17 @@ | ||
| 32 | 33 | * @return void |
| 33 | 34 | */ |
| 34 | 35 | public function start( $screen ) { |
| 35 | 36 | // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 36 | - if ( 'plugin-install' === $screen->base && ( ! isset( $_GET['paged'] ) || 1 === intval( $_GET['paged'] ) ) ) { | |
| 37 | - add_filter( 'plugins_api_result', array( $this, 'inject_suggestion' ), 10, 3 ); | |
| 38 | - add_filter( 'self_admin_url', array( $this, 'plugin_details' ) ); | |
| 39 | - add_filter( 'plugin_install_action_links', array( $this, 'insert_related_links' ), 10, 2 ); | |
| 40 | - add_action( 'admin_enqueue_scripts', array( $this, 'load_plugins_search_script' ) ); | |
| 41 | - $this->maybe_dismiss(); | |
| 37 | + if ( 'plugin-install' !== $screen->base || ( isset( $_GET['paged'] ) && 1 !== intval( $_GET['paged'] ) ) ) { | |
| 38 | + return; | |
| 42 | 39 | } |
| 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(); | |
| 43 | 46 | } |
| 44 | 47 | |
| 45 | 48 | /** |
| 46 | 49 | * Intercept the plugins API response and add in an appropriate card. |
| @@ -65,9 +68,10 @@ | ||
| 65 | 68 | $addon_list = $this->get_addons(); |
| 66 | 69 | |
| 67 | 70 | // Lowercase, trim, remove punctuation/special chars, decode url, remove 'formidable'. |
| 68 | 71 | $normalized_term = $this->search_to_array( $args->search ); |
| 69 | - if ( empty( $normalized_term ) ) { | |
| 72 | + | |
| 73 | + if ( ! $normalized_term ) { | |
| 70 | 74 | // Don't add anything extra. |
| 71 | 75 | return $result; |
| 72 | 76 | } |
| 73 | 77 | |
| @@ -72,9 +76,9 @@ | ||
| 72 | 76 | } |
| 73 | 77 | |
| 74 | 78 | $matching_addon = $this->matching_addon( $addon_list, $normalized_term ); |
| 75 | 79 | |
| 76 | - if ( empty( $matching_addon ) || ! $this->should_display_hint( $matching_addon ) ) { | |
| 80 | + if ( ! $matching_addon || ! $this->should_display_hint( $matching_addon ) ) { | |
| 77 | 81 | return $result; |
| 78 | 82 | } |
| 79 | 83 | |
| 80 | 84 | $inject = (array) $this->get_plugin_data(); |
| @@ -127,10 +131,9 @@ | ||
| 127 | 131 | if ( ! isset( $addon_opts['search_terms'] ) ) { |
| 128 | 132 | $addon_opts['search_terms'] = ''; |
| 129 | 133 | } |
| 130 | 134 | |
| 131 | - $addon_terms = $this->search_to_array( $addon_opts['search_terms'] . ' ' . $addon_opts['name'] ); | |
| 132 | - | |
| 135 | + $addon_terms = $this->search_to_array( $addon_opts['search_terms'] . ' ' . $addon_opts['name'] ); | |
| 133 | 136 | $matched_terms = array_intersect( $addon_terms, $normalized_term ); |
| 134 | 137 | |
| 135 | 138 | if ( count( $matched_terms ) === count( $normalized_term ) ) { |
| 136 | 139 | $matching_addon = $addon_id; |
| @@ -187,16 +190,19 @@ | ||
| 187 | 190 | /** |
| 188 | 191 | * Modify URL used to fetch to plugin information so it pulls Formidable plugin page. |
| 189 | 192 | * |
| 190 | 193 | * @since 4.12 |
| 194 | + * | |
| 191 | 195 | * @param string $url URL to load in dialog pulling the plugin page from wporg. |
| 192 | 196 | * |
| 193 | 197 | * @return string The URL with 'formidable' instead of 'frm-plugin-search'. |
| 194 | 198 | */ |
| 195 | 199 | public function plugin_details( $url ) { |
| 200 | + // phpcs:disable Generic.WhiteSpace.ScopeIndent | |
| 196 | 201 | return false !== stripos( $url, 'tab=plugin-information&plugin=' . self::$slug ) |
| 197 | 202 | ? 'plugin-install.php?tab=plugin-information&plugin=formidable&TB_iframe=true&width=600&height=550' |
| 198 | 203 | : $url; |
| 204 | + // phpcs:enable Generic.WhiteSpace.ScopeIndent | |
| 199 | 205 | } |
| 200 | 206 | |
| 201 | 207 | /** |
| 202 | 208 | * @since 4.12 |
| @@ -204,9 +210,10 @@ | ||
| 204 | 210 | * @return void |
| 205 | 211 | */ |
| 206 | 212 | private function maybe_dismiss() { |
| 207 | 213 | $addon = FrmAppHelper::get_param( 'frm-dismiss', '', 'get', 'absint' ); |
| 208 | - if ( ! empty( $addon ) ) { | |
| 214 | + | |
| 215 | + if ( $addon ) { | |
| 209 | 216 | $this->add_to_dismissed_hints( $addon ); |
| 210 | 217 | } |
| 211 | 218 | } |
| 212 | 219 | |
| @@ -218,9 +225,9 @@ | ||
| 218 | 225 | * @return array List of dismissed hints. |
| 219 | 226 | */ |
| 220 | 227 | protected function get_dismissed_hints() { |
| 221 | 228 | $dismissed_hints = get_option( self::$dismissed_opt ); |
| 222 | - return ! empty( $dismissed_hints ) && is_array( $dismissed_hints ) ? $dismissed_hints : array(); | |
| 229 | + return $dismissed_hints && is_array( $dismissed_hints ) ? $dismissed_hints : array(); | |
| 223 | 230 | } |
| 224 | 231 | |
| 225 | 232 | /** |
| 226 | 233 | * Save the hint in the list of dismissed hints. |
| @@ -232,9 +239,9 @@ | ||
| 232 | 239 | * @return bool Whether the card was added to the list and hence dismissed. |
| 233 | 240 | */ |
| 234 | 241 | protected function add_to_dismissed_hints( $hint ) { |
| 235 | 242 | $hints = array_merge( $this->get_dismissed_hints(), array( $hint ) ); |
| 236 | - return update_option( self::$dismissed_opt, $hints, 'no' ); | |
| 243 | + return update_option( self::$dismissed_opt, $hints, false ); | |
| 237 | 244 | } |
| 238 | 245 | |
| 239 | 246 | /** |
| 240 | 247 | * Checks that the addon slug passed should be displayed. |
| @@ -262,20 +269,19 @@ | ||
| 262 | 269 | * Take a raw search query and return something a bit more standardized and |
| 263 | 270 | * easy to work with. |
| 264 | 271 | * |
| 265 | 272 | * @param string $term The raw search term. |
| 273 | + * | |
| 266 | 274 | * @return string A simplified/sanitized version. |
| 267 | 275 | */ |
| 268 | 276 | private function sanitize_search_term( $term ) { |
| 269 | 277 | $term = strtolower( urldecode( $term ) ); |
| 270 | 278 | |
| 271 | - // remove non-alpha/space chars. | |
| 279 | + // Remove non-alpha/space chars. | |
| 272 | 280 | $term = preg_replace( '/[^a-z ]/', '', $term ); |
| 273 | 281 | |
| 274 | - // remove strings that don't help matches. | |
| 275 | - $term = trim( str_replace( array( 'formidable', 'free', 'wordpress', 'wp ', 'plugin' ), '', $term ) ); | |
| 276 | - | |
| 277 | - return $term; | |
| 282 | + // Remove strings that don't help matches. | |
| 283 | + return trim( str_replace( array( 'formidable', 'free', 'wordpress', 'wp ', 'plugin' ), '', $term ) ); | |
| 278 | 284 | } |
| 279 | 285 | |
| 280 | 286 | /** |
| 281 | 287 | * @since 4.12 |
| @@ -280,8 +286,9 @@ | ||
| 280 | 286 | /** |
| 281 | 287 | * @since 4.12 |
| 282 | 288 | * |
| 283 | 289 | * @param string $terms |
| 290 | + * | |
| 284 | 291 | * @return array |
| 285 | 292 | */ |
| 286 | 293 | private function search_to_array( $terms ) { |
| 287 | 294 | $terms = $this->sanitize_search_term( $terms ); |
| @@ -318,9 +325,9 @@ | ||
| 318 | 325 | 'plugin' => $plugin['plugin'], |
| 319 | 326 | ), |
| 320 | 327 | admin_url( 'plugins.php' ) |
| 321 | 328 | ); |
| 322 | - $links['frm_get_started'] = '<a href="' . esc_url( $activate_url ) . '" class="button activate-now" aria-label="Activate ' . esc_attr( $plugin['name'] ) . '">' . __( 'Activate', 'formidable' ) . '</a>'; | |
| 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 | |
| 323 | 330 | } |
| 324 | 331 | } elseif ( ! $is_active && isset( $plugin['url'] ) ) { |
| 325 | 332 | // Go to the add-ons page to install. |
| 326 | 333 | $links[] = '<a |
| @@ -325,10 +332,9 @@ | ||
| 325 | 332 | // Go to the add-ons page to install. |
| 326 | 333 | $links[] = '<a |
| 327 | 334 | class="button-secondary" |
| 328 | 335 | href="' . esc_url( admin_url( 'admin.php?page=formidable-addons' ) ) . '" |
| 329 | - >' . __( 'Install Now', 'formidable' ) . '</a>'; | |
| 330 | - | |
| 336 | + >' . esc_html__( 'Install Now', 'formidable' ) . '</a>'; | |
| 331 | 337 | } elseif ( ! empty( $plugin['link'] ) ) { |
| 332 | 338 | // Add link pointing to a relevant doc page in formidable.com. |
| 333 | 339 | $links[] = '<a |
| 334 | 340 | class="button-primary frm-plugin-search__learn-more" |
| @@ -340,9 +346,9 @@ | ||
| 340 | 346 | |
| 341 | 347 | // Dismiss link. |
| 342 | 348 | $dismiss = add_query_arg( array( 'frm-dismiss' => $plugin['id'] ) ); |
| 343 | 349 | $links[] = '<a |
| 344 | - href="' . $dismiss . '" | |
| 350 | + href="' . esc_url( $dismiss ) . '" | |
| 345 | 351 | class="frm-plugin-search__dismiss" |
| 346 | 352 | data-addon="' . esc_attr( $plugin['addon'] ) . '" |
| 347 | 353 | >' . esc_html__( 'Hide this suggestion', 'formidable' ) . '</a>'; |
| 348 | 354 | |
| @@ -350,8 +356,9 @@ | ||
| 350 | 356 | } |
| 351 | 357 | |
| 352 | 358 | /** |
| 353 | 359 | * @param string $plugin |
| 360 | + * | |
| 354 | 361 | * @return bool |
| 355 | 362 | */ |
| 356 | 363 | protected function is_installed( $plugin ) { |
| 357 | 364 | $all_plugins = FrmAppHelper::get_plugins(); |