Plugin Directory

Changeset 3092553


Ignore:
Timestamp:
05/25/2024 08:12:27 PM (22 months ago)
Author:
webmaster85
Message:

Added improvements.

Location:
instant-search
Files:
13 added
5 edited

Legend:

Unmodified
Added
Removed
  • instant-search/trunk/instant-search.php

    r3086833 r3092553  
    99 * Plugin URI: https://instant-search.marincas.net
    1010 * Description: A WordPress search plugin with live and voice search.
    11  * Version: 1.0.1
     11 * Version: 1.0.2
    1212 * Author: webmaster85
    1313 * Author URI: https://www.marincas.net
     
    1717 
    1818function instant_search_form() {
    19     ob_start();
    20     include plugin_dir_path(__FILE__) . 'searchform.php';
    21     $form = ob_get_clean();
    22     return $form;
     19    ob_start(); 
     20    include plugin_dir_path(__FILE__) . 'searchform.php'; 
     21    $form = ob_get_clean(); 
     22    return $form; 
    2323}
    2424add_shortcode('instant_search', 'instant_search_form');
     
    2727    wp_enqueue_script('instant_search', plugins_url('instant_search.js', __FILE__), array('jquery'), '1.0', true);
    2828    wp_enqueue_style('instant_search', plugins_url('instant_search.css', __FILE__));
    29     wp_enqueue_style('font-awesome', 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/css/all.min.css'); // Enqueue Font Awesome
     29    wp_enqueue_style('font-awesome', 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/css/all.min.css');
    3030    wp_localize_script('instant_search', 'instant_search', array('ajax_url' => admin_url('admin-ajax.php'), 'display_style' => get_option('instant_search_display_style', 'list')));
    3131}
     32
    3233add_action('wp_enqueue_scripts', 'instant_search_scripts');
     34
     35    function wpdocs_enqueue_custom_admin_style() {
     36        wp_register_style( 'custom_wp_admin_css', plugin_dir_url( __FILE__ ) . 'settings.css', false, '1.0.0' );
     37        wp_enqueue_style( 'custom_wp_admin_css' );
     38    }
     39    add_action( 'admin_enqueue_scripts', 'wpdocs_enqueue_custom_admin_style' );
    3340
    3441function instant_search_ajax() {
     
    6168add_action('admin_menu', 'instant_search_menu');
    6269
    63 
    64 /* SEARCH BY SKU START */
     70function instant_search_custom_styles() {
     71    $search_form_width = get_option('instant_search_form_width', '300px');
     72    echo '<style>
     73        .search-wrapper {
     74            width: ' . esc_attr($search_form_width) . ';
     75        }
     76    </style>';
     77}
     78add_action('wp_head', 'instant_search_custom_styles');
     79
    6580function search_by_sku( $search, $query_vars ) {
    6681global $wpdb;
     
    90105}
    91106add_filter( 'posts_search', 'search_by_sku', 999, 2 );
    92 /* SEARCH BY SKU STOP */
    93107
    94108function instant_search_options() {
     
    96110        wp_die(__('You do not have sufficient permissions to access this page.'));
    97111    }
    98     // Check if form has been submitted and process it
    99     if (isset($_POST['post_types'])) {
    100         $post_types = array_map('sanitize_text_field', $_POST['post_types']);
    101         update_option('instant_search_post_types', $post_types);
    102     }
    103     if (isset($_POST['display_style'])) {
    104         $display_style = sanitize_text_field($_POST['display_style']);
    105         update_option('instant_search_display_style', $display_style);
    106     }
    107     // Retrieve options
    108     $post_types = get_option('instant_search_post_types', array('post', 'page'));
     112    if ($_SERVER['REQUEST_METHOD'] === 'POST') {
     113        if (isset($_POST['post_types'])) {
     114            $post_types = array_map('sanitize_text_field', $_POST['post_types']);
     115            update_option('instant_search_post_types', $post_types);
     116        }
     117        if (isset($_POST['display_style'])) {
     118            $display_style = sanitize_text_field($_POST['display_style']);
     119            update_option('instant_search_display_style', $display_style);
     120        }
     121        if (isset($_POST['search_placeholder'])) {
     122            $search_placeholder = sanitize_text_field($_POST['search_placeholder']);
     123            update_option('instant_search_placeholder', $search_placeholder);
     124        }
     125        if (isset($_POST['search_form_width'])) {
     126            $search_form_width = sanitize_text_field($_POST['search_form_width']);
     127            update_option('instant_search_form_width', $search_form_width);
     128        }
     129    }
     130     $post_types = get_option('instant_search_post_types', array('post', 'page'));
    109131    $display_style = get_option('instant_search_display_style', 'list');
     132    $search_placeholder = get_option('instant_search_placeholder', 'What are we searching for today?');
    110133    $all_post_types = get_post_types(array('public' => true), 'names');
    111 ?>
    112 
    113 <div class="wrap">
    114     <h2>Instant Search Settings</h2>
    115     <h2>Use this shortcode to display the search form anywhere:     
    116     <h1>[instant_search]</h1>   
    117     </h2>
    118     <h3>Select the post types you like the form to show results for:</h3>
    119     <form method="post" action="">
    120         <?php foreach ($all_post_types as $post_type): ?>
    121             <input type="checkbox" name="post_types[]" value="<?php echo esc_attr($post_type); ?>"<?php if (in_array($post_type, $post_types)) echo ' checked'; ?> /> <?php echo esc_html($post_type); ?><br />
    122         <?php endforeach; ?>
    123         <h3>Select how the search results should be displayed:</h3>
    124         <select name="display_style">
    125             <option value="list"<?php if ($display_style == 'list') echo ' selected'; ?>>List</option>
    126             <option value="grid"<?php if ($display_style == 'grid') echo ' selected'; ?>>Grid</option>
    127         </select>
     134    $search_form_width = get_option('instant_search_form_width', '50%');
     135    ?>
     136
     137    <div class="wrapper">
     138    <h2 class="bigtitle">Instant Search Settings <button id="toggle-ads-button">Show Ads</button></h2> 
     139    <div id="toggle-ads">
     140        <script>
     141        jQuery(document).ready(function() {
     142            jQuery("#toggle-ads-button").click(function() {
     143                jQuery("#toggle-ads").toggle();
     144                if (jQuery("#toggle-ads").is(":visible")) {
     145                    jQuery("#toggle-ads-button").text("Hide Ads").css("background-color", "red");;
     146                } else {
     147                    jQuery("#toggle-ads-button").text("Show Ads").css("background-color", "#1ED760");
     148                }
     149            });
     150        });
     151        </script>       
     152        <div class="ads-images">   
    128153        <h3>Want to create stunning websites with the assistance of AI?</h3>
    129154        <a href="https://www.elegantthemes.com/affiliates/idevaffiliate.php?id=47480" target="_blank" rel="nofollow">
    130155            <img style="border:0px" src="<?php echo esc_url(plugins_url('/banner/et-affiliate.png', __FILE__)); ?>" width="570" height="100" alt="">
    131         </a>
     156        </a>       
    132157        <h3>Check out the best E-Commerce theme:</h3>
    133158        <a href="https://themeforest.net/item/rey-multipurpose-woocommerce-theme/24689383" target="_blank" rel="nofollow">
     
    137162        <a href="https://hosterion.ro/client/aff.php?aff=160" target="_blank" rel="nofollow">
    138163            <img style="border:0px" src="<?php echo esc_url(plugins_url('/banner/hosterion-affiliate.png', __FILE__)); ?>" width="570" height="100" alt="">
    139         </a>
    140         <h1>Do you like the plugin? You can support it by donating <a href="https://instant-search.marincas.net/#donate" target="_blank">here</a>.</h1>
    141         <p class="submit">
     164        </a>   
     165        </div>     
     166        </div> 
     167     <form method="post" action="">     
     168    <div class="articles"> 
     169  <article>
     170    <div class="article-wrapper">
     171    <h1>
     172      1
     173      </h1>
     174      <div class="article-body">
     175        <h2>Select the post types</h2>
     176        <p>
     177        Choose the types of posts you'd like the form to display results for. Each WordPress site, depending on the themes and plugins in use, may have various custom post types. These might include products, posts, pages, attachments, global sections, templates, etc. The plugin automatically detects all available post types, so you can get search results from any of them. Feel free to select multiple options.
     178        </p>
     179        <p>
     180        <?php foreach ($all_post_types as $post_type): ?>
     181            <input type="checkbox" name="post_types[]" value="<?php echo esc_attr($post_type); ?>"<?php if (in_array($post_type, $post_types)) echo ' checked'; ?> /> <?php echo esc_html($post_type); ?><br />
     182        <?php endforeach; ?>
     183        </p>       
     184      </div>
     185    </div>
     186  </article> 
     187   <article>
     188    <div class="article-wrapper">
     189    <h1>
     190      2
     191      </h1>
     192      <div class="article-body">
     193        <h2>Search results display</h2>
     194        <p>
     195          Depending on your choice here, your website visitors will see search results either in a grid (3 columns) or in a list format. The grid view is perfect for desktops, offering a visually appealing layout, while the list view is ideal for small screens like phones, ensuring better readability and easier navigation.
     196        </p> 
     197        <p class="display-styles">
     198        <select name="display_style">
     199            <option value="list"<?php if ($display_style == 'list') echo ' selected'; ?>>List</option>
     200            <option value="grid"<?php if ($display_style == 'grid') echo ' selected'; ?>>Grid</option>
     201        </select>
     202        </p>       
     203      </div>
     204    </div>
     205  </article> 
     206   <article>
     207    <div class="article-wrapper">
     208    <h1>
     209      3
     210      </h1>
     211      <div class="article-body">
     212        <h2>Placeholder text</h2>
     213        <p>
     214          In this field, you can set a personalized message that will be displayed inside the search form. The default is usually "Search..." but you have the flexibility to change it. For example, you could use "What are we searching for today?" or anything else that suits your needs.
     215        </p>
     216        <p class="placeholder-text">
     217        <input type="text" style="min-width:250px;" name="search_placeholder" value="<?php echo esc_attr($search_placeholder); ?>" />
     218        </p>       
     219      </div>
     220    </div>
     221  </article> 
     222   <article>
     223    <div class="article-wrapper">
     224    <h1>
     225      4
     226      </h1>
     227      <div class="article-body">
     228        <h2>Width</h2>
     229        <p>
     230          You can customize the width of the search form in this field. By default it's set to 300px, but you can change it to any CSS unit that suits your website's layout. For instance, you could use 50% for a responsive design, 300px for a fixed width, or 30vh to make it proportional to the viewport height.
     231        </p>       
     232        <p class="width-text">
     233            <input type="text" style="min-width:250px;" name="search_form_width" value="<?php echo esc_attr($search_form_width); ?>" placeholder="e.g., 50%, 300px, 30vh" />
     234        </p>
     235      </div>
     236    </div>
     237  </article> 
     238   <article>
     239    <div class="article-wrapper">
     240    <h1>
     241      5
     242      </h1>
     243      <div class="article-body">
     244        <h2>Shortcode</h2>
     245        <p>
     246          Use the shortcode to display a search form anywhere. Personally, I find it works best when placed in the website's header. It optimizes user experience and navigation, as it's a prime location for visitors to initiate searches, thus enhancing overall site usability.
     247        </p>       
     248        <h3 class="the-shortcode">
     249        [instant_search]
     250        </h3>
     251      </div>
     252    </div>
     253  </article> 
     254   <article>
     255    <div class="article-wrapper">
     256    <h1>
     257      6
     258      </h1>
     259      <div class="article-body">
     260        <h2>Donate</h2>
     261        <p>
     262          I use the donations to improve the plugin. That could mean a variety of things. I mainly buy web development courses that let me upgrade my skills to understand the whole environment better, how the search works in-depth, and see the big picture.
     263        </p>   
     264            <p style="text-align:center;">
     265         <button class="donate-button" ><a href="https://instant-search.marincas.net/#donate" target="_blank">Donate here</a></button>
     266            </p>
     267      </div>
     268    </div>
     269  </article> 
     270  </div>   
     271     <p class="submit">
    142272            <input type="submit" class="button-primary" value="Save Changes" />
    143         </p>
    144     </form>
    145 </div>
    146 
     273        </p>   
     274      </form>   
     275</div>
    147276<?php
    148 } // End of instant_search_options function
     277}
    149278?>
  • instant-search/trunk/instant_search.css

    r3086833 r3092553  
    22  box-sizing: border-box;
    33}
    4 
    54#search-results.list .search-result {
    65    display: block; 
     
    98    padding: 25px;
    109}
    11 
    1210#search-results.list .search-result img {
    1311  width: -webkit-fill-available;
    1412}
    15 
    1613#search-results.grid .search-result {
    1714    display: inline-block;
     
    2017    box-sizing: border-box;
    2118}
    22 
    2319#search-results.grid .search-result img {   
    2420    width: 100%;
    2521   
    2622}
    27 
    2823#search-results {
    2924    text-align:center;
     
    3429   
    3530}
    36 
    3731#search-results * {
    3832    font-size:1em!important;
    3933    line-height: 1em!important;
    4034}
    41 
    4235#search-results img {
    4336    margin-bottom:10px;
    4437   
    4538}
    46 
    47 
    48 
    4939form#searchform input[type=text] {
    5040  padding: 10px;
     
    5545
    5646}
    57 
    58 /* Overlay Styles */
    5947.search-overlay {
    6048    position: fixed;
     
    6957    align-items: center;
    7058}
    71 
    7259#search-results {   
    7360display:none;
     
    8168    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    8269}
    83 
    84 
    85 
    8670.search-wrapper {
    8771    position: relative;
     
    8973    align-items: center;
    9074}
    91 
    9275#s {
    93     flex-grow: 1; /* Makes the input take up the available space */
    94     padding-right: 40px; /* Adds padding to prevent text from being hidden behind the button */
     76    flex-grow: 1;
     77    padding-right: 40px;
    9578}
    96 
    9779#voice-search-btn {
    9880    position: absolute;
     
    10284    background: none;
    10385    cursor: pointer;
    104     color: #333; /* Adjust color as needed */
     86    color: #333;
    10587    padding: 10px;
    10688}
    107 
    10889#voice-search-btn i {
    109     font-size: 20px; /* Adjust size as needed */
     90    font-size: 20px;
    11091}
    111 
    112 
    113 
    114 /* MEDIA QUERIES */
    11592@media only screen and (max-width: 767px) {
    11693
     
    11996    padding: 5px;   
    12097}
    121 
    122 
    12398#search-results.list .search-result {     
    12499    width: 90%;
    125100    padding: 5px;
    126101}
    127 
    128102#search-results.grid .search-result { 
    129103    width: 40%;   
    130104}
    131 
    132105form#searchform input[type=text] {
    133106  min-width:100%;
    134 
    135107}
    136 
    137 
    138108}
  • instant-search/trunk/instant_search.js

    r3089664 r3092553  
    11jQuery(document).ready(function($) {
    2     // Function to create and get the overlay
    32    function getOrCreateOverlay() {
    43        let overlay = $('#search-overlay');
    5         // Check if the overlay already exists
    64        if (overlay.length === 0) {
    7             // Create the overlay and search results container
    85            overlay = $('<div id="search-overlay" class="search-overlay" style="display: none;"></div>');
    96            let searchResults = $('<div id="search-results" class="' + instant_search.display_style + '" style="display: none;"></div>');
     
    1310        return overlay;
    1411    }
    15 
    1612    var debounceTimeout;
    17     var currentRequest = null; // Track the current AJAX request
    18     var delay = 300; // Delay in milliseconds
    19 
     13    var currentRequest = null;
     14    var delay = 100;
    2015    $('#s').on('input', function() {
    2116        clearTimeout(debounceTimeout);
     
    3126            } else {
    3227                if (currentRequest != null) {
    33                     currentRequest.abort(); // Abort the ongoing request
     28                    currentRequest.abort();
    3429                }
    3530                currentRequest = $.ajax({
     
    4540                    },
    4641                    complete: function() {
    47                         currentRequest = null; // Reset the current request tracker
     42                        currentRequest = null;
    4843                    }
    4944                });
     
    5146        }, delay);
    5247    });
    53     // Close overlay on click outside of search results
    5448    $(document).on('click', '#search-overlay', function(e) {
    5549        if ($(e.target).closest('#search-results').length === 0) {
     
    5953        }
    6054    });
    61     // Prevent closing when clicking inside the search results
    6255    $(document).on('click', '#search-results', function(e) {
    63         e.stopPropagation(); // Prevent event from bubbling to overlay
     56        e.stopPropagation();
    6457    });
    65     /* VOICE SEARCH START */
     58
    6659    if ('webkitSpeechRecognition' in window) {
    6760        var recognition = new webkitSpeechRecognition();
     
    7164        recognition.onresult = function(event) {
    7265            var transcript = event.results[0][0].transcript;
    73             var cleanedTranscript = transcript.replace(/[.,\/#!$%\^&\*;:{}=\-_`~()]/g,""); // Regex to remove punctuation
    74             $('#s').val(cleanedTranscript).trigger('input'); // Set cleaned transcript
     66            var cleanedTranscript = transcript.replace(/[.,\/#!$%\^&\*;:{}=\-_`~()]/g,"");
     67            $('#s').val(cleanedTranscript).trigger('input');
    7568        };
    7669
     
    7972        });
    8073    } else {
    81         $('#voice-search-btn').hide(); // Hide the button if not supported
    82     }
    83     /* VOICE SEARCH STOP */
     74        $('#voice-search-btn').hide();
     75    }   
    8476});
  • instant-search/trunk/readme.txt

    r3089664 r3092553  
    55Requires at least: 4.7
    66Tested up to: 6.5.3
    7 Stable tag: 1.0.1
     7Stable tag: 1.0.2
    88Requires PHP: 7.4
    99License: GPLv2 or later
     
    3131- Display live search results in a grid
    3232- Display live search results in a list
     33- Customize the text
     34- Customize the width
    3335- Submit for searching
    3436
     
    6971- Display live search results in a grid
    7072- Display live search results in a list
     73- Customize the text
     74- Customize the width
    7175- Submit for searching
    7276
     
    98102
    99103== Changelog ==
     104
     105= 1.0.2 =
     106
     107Added improvements.
     108
    100109= 1.0.1 =
    101110
     
    115124
    116125== Upgrade Notice ==
    117 Added features.
     126
     127Added improvements.
  • instant-search/trunk/searchform.php

    r3086833 r3092553  
    11<?php
    22    if ( ! defined( 'ABSPATH' ) ) {
    3         exit; // Exit if accessed directly
     3        exit;
    44    }
    55?>
    66<form role="search" method="get" id="searchform" action="<?php echo esc_url(home_url('/')); ?>">
    77    <div class="search-wrapper">
    8         <input type="text" value="" name="s" id="s" placeholder="What are we searching for today?" />
     8        <input type="text" value="" name="s" id="s" placeholder="<?php echo esc_attr(get_option('instant_search_placeholder', 'What are we searching for today?')); ?>" />
    99        <button type="button" id="voice-search-btn" aria-label="Voice Search"><i class="fas fa-microphone"></i></button>
    1010    </div>
Note: See TracChangeset for help on using the changeset viewer.