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