Plugin Directory

Changeset 2586104

Timestamp:
08/20/2021 05:06:27 PM (3 years ago)
Author:
bradparbs
Message:

Update to version 1.1.0 from GitHub

Location:
one-search-result
Files:
2 deleted
8 edited
1 copied

Legend:

Unmodified
Added
Removed
  • one-search-result/tags/1.1.0/one-search-result.php

    r2539075 r2586104  
    33 * Plugin Name: One Search Result
    44 * Description: Automatically send a user to the page or post if it's the only search result available.
    5  * Version:     1.0.3
     5 * Version:     1.
    66 * Author:      Brad Parbs
    77 * Author URI:  https://bradparbs.com/
     
    1313 */
    1414
    15 if ( ! defined( 'ABSPATH' ) ) {
    16     exit;
    17 }
     15add_action( 'template_redirect', __NAMESPACE__ . '\\one_search_result' );
    1816
    1917/**
    2018 * If there is one search result, redirect to it automatically.
    2119 */
    22 add_action(
    23     'template_redirect',
    24     function () {
    25         // Only apply to the search results.
    26         if ( ! is_search() ) {
    27             return;
    28         }
     20function one_search_result() {
     21    // Only apply to the search results.
     22    if ( ! is_search() ) {
     23        return;
     24    }
    2925
    30         // Filter 'one_search_result_pre_check' if you need to short-circuit it in some cases.
    31         if ( ! apply_filters( 'one_search_result_pre_check', true ) ) {
    32             return;
    33         }
     26    // Filter 'one_search_result_pre_check' if you need to short-circuit it in some cases.
     27    if ( ! apply_filters( 'one_search_result_pre_check', true ) ) {
     28        return;
     29    }
    3430
    35         global $wp_query;
     31    global $wp_query;
    3632
    37         // Make sure we have results before doing anything.
    38         if ( ! isset( $wp_query->posts ) || ! isset( $wp_query->post_count ) ) {
    39             return;
    40         }
     33    // Make sure we have results before doing anything.
     34    if ( ! isset( $wp_query->posts ) || ! isset( $wp_query->post_count ) ) {
     35        return;
     36    }
    4137
    42         // If we only have one result, perfect!
    43         if ( ! ( 1 === $wp_query->post_count && 1 === count( $wp_query->posts ) ) ) {
    44             return;
    45         }
     38    // If we only have one result, perfect!
     39    if ( ! ( 1 === $wp_query->post_count && 1 === count( $wp_query->posts ) ) ) {
     40        return;
     41    }
    4642
    47         // Grab the permalink and make sure we got it.
    48         $dest = get_permalink( $wp_query->posts[0] );
    49         if ( ! $dest ) {
    50             return;
    51         }
     43    // Grab the permalink and make sure we got it.
     44    $dest = get_permalink( $wp_query->posts[0] );
     45    if ( ! $dest ) {
     46        return;
     47    }
    5248
    53         // Send it off!
    54         wp_safe_redirect( $dest, 302 );
    55         exit;
     49    // Send it off!
     50    );
     51    exit;
    5652
    57     }
    58 );
     53}
  • one-search-result/tags/1.1.0/readme.txt

    r2539075 r2586104  
    11=== One Search Result ===
    2 Contributors: bradparbs
     2Contributors: bradparbs
    33Tags: search, content, results, redirects
    44Requires at least: 5.2
    5 Tested up to: 5.7.2
    6 Stable tag: 1.0.3
     5Tested up to: 5.
     6Stable tag: 1.
    77License: GPLv2 or later
    88Requires PHP: 5.6
     
    1414When there is only one search result available for a query, automatically redirect the user to that result.
    1515
    16 ## Details
     16This will work with any theme and any posts, pages, or custom post types that would be shown in search results.
    1717
    18 This will work with any theme and any objects that would be shown in search results.
     18== Available Filters ==
    1919
    2020You can filter `one_search_result_pre_check` to false if you need to short-circuit and disable the redirect dynamically.
    2121
     22
    2223
    23 == Installation ==
     24== ==
    2425
    25  - Install the plugin.
    26  - Better search experience!
     26= 1.1.0 =
     27
     28* Added another filter, cleaned up code.
     29
     30= 1.0.3 =
     31
     32* Initial release
  • one-search-result/trunk/one-search-result.php

    r2539075 r2586104  
    33 * Plugin Name: One Search Result
    44 * Description: Automatically send a user to the page or post if it's the only search result available.
    5  * Version:     1.0.3
     5 * Version:     1.
    66 * Author:      Brad Parbs
    77 * Author URI:  https://bradparbs.com/
     
    1313 */
    1414
    15 if ( ! defined( 'ABSPATH' ) ) {
    16     exit;
    17 }
     15add_action( 'template_redirect', __NAMESPACE__ . '\\one_search_result' );
    1816
    1917/**
    2018 * If there is one search result, redirect to it automatically.
    2119 */
    22 add_action(
    23     'template_redirect',
    24     function () {
    25         // Only apply to the search results.
    26         if ( ! is_search() ) {
    27             return;
    28         }
     20function one_search_result() {
     21    // Only apply to the search results.
     22    if ( ! is_search() ) {
     23        return;
     24    }
    2925
    30         // Filter 'one_search_result_pre_check' if you need to short-circuit it in some cases.
    31         if ( ! apply_filters( 'one_search_result_pre_check', true ) ) {
    32             return;
    33         }
     26    // Filter 'one_search_result_pre_check' if you need to short-circuit it in some cases.
     27    if ( ! apply_filters( 'one_search_result_pre_check', true ) ) {
     28        return;
     29    }
    3430
    35         global $wp_query;
     31    global $wp_query;
    3632
    37         // Make sure we have results before doing anything.
    38         if ( ! isset( $wp_query->posts ) || ! isset( $wp_query->post_count ) ) {
    39             return;
    40         }
     33    // Make sure we have results before doing anything.
     34    if ( ! isset( $wp_query->posts ) || ! isset( $wp_query->post_count ) ) {
     35        return;
     36    }
    4137
    42         // If we only have one result, perfect!
    43         if ( ! ( 1 === $wp_query->post_count && 1 === count( $wp_query->posts ) ) ) {
    44             return;
    45         }
     38    // If we only have one result, perfect!
     39    if ( ! ( 1 === $wp_query->post_count && 1 === count( $wp_query->posts ) ) ) {
     40        return;
     41    }
    4642
    47         // Grab the permalink and make sure we got it.
    48         $dest = get_permalink( $wp_query->posts[0] );
    49         if ( ! $dest ) {
    50             return;
    51         }
     43    // Grab the permalink and make sure we got it.
     44    $dest = get_permalink( $wp_query->posts[0] );
     45    if ( ! $dest ) {
     46        return;
     47    }
    5248
    53         // Send it off!
    54         wp_safe_redirect( $dest, 302 );
    55         exit;
     49    // Send it off!
     50    );
     51    exit;
    5652
    57     }
    58 );
     53}
  • one-search-result/trunk/readme.txt

    r2539075 r2586104  
    11=== One Search Result ===
    2 Contributors: bradparbs
     2Contributors: bradparbs
    33Tags: search, content, results, redirects
    44Requires at least: 5.2
    5 Tested up to: 5.7.2
    6 Stable tag: 1.0.3
     5Tested up to: 5.
     6Stable tag: 1.
    77License: GPLv2 or later
    88Requires PHP: 5.6
     
    1414When there is only one search result available for a query, automatically redirect the user to that result.
    1515
    16 ## Details
     16This will work with any theme and any posts, pages, or custom post types that would be shown in search results.
    1717
    18 This will work with any theme and any objects that would be shown in search results.
     18== Available Filters ==
    1919
    2020You can filter `one_search_result_pre_check` to false if you need to short-circuit and disable the redirect dynamically.
    2121
     22
    2223
    23 == Installation ==
     24== ==
    2425
    25  - Install the plugin.
    26  - Better search experience!
     26= 1.1.0 =
     27
     28* Added another filter, cleaned up code.
     29
     30= 1.0.3 =
     31
     32* Initial release
Note: See TracChangeset for help on using the changeset viewer.