Plugin Directory

Changeset 3297631


Ignore:
Timestamp:
05/20/2025 07:48:50 PM (7 months ago)
Author:
webdevstudios
Message:

release version 2.9.0

Location:
wp-search-with-algolia
Files:
1236 added
13 edited

Legend:

Unmodified
Added
Removed
  • wp-search-with-algolia/trunk/README.txt

    r3265924 r3297631  
    33Tags: search, algolia, autocomplete, instantsearch, relevance search, faceted search, find-as-you-type search, ecommerce, seo, woocommerce, advanced search
    44Requires at least: 5.3
    5 Tested up to: 6.7.2
     5Tested up to: 6.8.1
    66Requires PHP: 7.4
    7 Stable tag: 2.8.3
     7Stable tag: 2.9.0
    88License: GNU General Public License v2.0, MIT License
    99
     
    128128
    129129Follow along with the changelog on [Github](https://github.com/WebDevStudios/wp-search-with-algolia/releases).
     130
     131= 2.9.0 =
     132* Added: Instantsearch Template options. Choose between "Legacy" hogan.js/WP Utils templates and "Modern" Javascript string literals. "Modern" is more in line with Algolia Documentation.
     133* Added: ability to customize default Headers for Algolia Search Client configuration.
     134* Added: Initial support for programmatic Secured API key creation.
     135* Updated: Sync'd up `get_items()` methods to allow for specifying specific IDs for posts, terms, and users.
     136* Updated: Instantsearch templates use "Posts per page" amount by default, from WordPress Reading settings.
     137* Updated: Amended Autocomplete settings page to remove more builtin post types that don't need to be available.
    130138
    131139= 2.8.3 =
  • wp-search-with-algolia/trunk/algolia.php

    r3265924 r3297631  
    44 * Plugin URI:        https://github.com/WebDevStudios/wp-search-with-algolia
    55 * Description:       Integrate the powerful Algolia search service with WordPress
    6  * Version:           2.8.3
     6 * Version:           2.9.0
    77 * Requires at least: 5.3
    88 * Requires PHP:      7.4
     
    2727
    2828// The Algolia Search plugin version.
    29 define( 'ALGOLIA_VERSION', '2.8.3' );
     29define( 'ALGOLIA_VERSION', '2.9.0' );
    3030
    3131// The minmum required PHP version.
  • wp-search-with-algolia/trunk/includes/admin/class-algolia-admin-page-native-search.php

    r3196600 r3297631  
    122122        );
    123123
     124        add_settings_field(
     125            'algolia_instantsearch_template_version',
     126            esc_html__( 'Instantsearch Template version', 'wp-search-with-algolia' ),
     127            [ $this, 'instantsearch_template_version' ],
     128            $this->slug,
     129            $this->section
     130        );
     131
    124132        register_setting( $this->option_group, 'algolia_override_native_search', array( $this, 'sanitize_override_native_search' ) );
     133
     134        register_setting( $this->option_group, 'algolia_instantsearch_template_version', [
     135            'type'              => 'string',
     136            'sanitize_callback' => 'sanitize_text_field',
     137            'default'           => 'legacy'
     138        ] );
    125139    }
    126140
     
    135149
    136150        require_once dirname( __FILE__ ) . '/partials/form-override-search-option.php';
     151    }
     152
     153    /**
     154     * Get Instantsearch template version
     155     *
     156     * @author WebDevStudios <[email protected]>
     157     * @since  2.9.0
     158     */
     159    public function instantsearch_template_version() {
     160        $value = $this->plugin->get_settings()->get_instantsearch_template_version();
     161
     162        require_once dirname( __FILE__ ) . '/partials/form-override-search-version-option.php';
    137163    }
    138164
  • wp-search-with-algolia/trunk/includes/class-algolia-settings.php

    r2808073 r3297631  
    3030        add_option( 'algolia_autocomplete_config', array() );
    3131        add_option( 'algolia_override_native_search', 'native' );
     32        add_option( 'algolia_instantsearch_template_version', 'legacy' );
    3233        add_option( 'algolia_index_name_prefix', 'wp_' );
    3334        add_option( 'algolia_api_is_reachable', 'no' );
     
    150151
    151152        // Native WordPress.
    152         $excluded[] = 'revision';
    153         $excluded[] = 'custom_css';
    154         $excluded[] = 'customize_changeset';
    155         $excluded[] = 'oembed_cache';
    156         $excluded[] = 'user_request';
    157         $excluded[] = 'wp_block';
    158         $excluded[] = 'wp_global_styles';
    159         $excluded[] = 'wp_navigation';
    160         $excluded[] = 'wp_template';
    161         $excluded[] = 'wp_template_part';
     153        $builtin = get_post_types( [ '_builtin' => true ] );
     154        // Preserve posts, pages, and attachments
     155        unset( $builtin['post'] );
     156        unset( $builtin['page'] );
     157        unset( $builtin['attachment'] );
     158
     159        foreach( $builtin as $type ) {
     160            $excluded[] = $type;
     161        }
    162162
    163163        // Native to WordPress VIP platform.
     
    497497        update_option( 'algolia_powered_by_enabled', 'no' );
    498498    }
     499
     500    /**
     501     * Return the version keyword for Instantsearch version to use.
     502     *
     503     * @since 2.9.0
     504     *
     505     * @return mixed|null
     506     */
     507    public function get_instantsearch_template_version() {
     508        $chosen = get_option( 'algolia_instantsearch_template_version', 'legacy' );
     509
     510        return apply_filters( 'algolia_instantsearch_template_version', $chosen );
     511    }
     512
     513    /**
     514     * Return whether or not the keyword version is set to 'modern' or 'legacy'.
     515     *
     516     * @since 2.9.0
     517     *
     518     * @return bool
     519     */
     520    public function should_use_instantsearch_modern() {
     521        $version = $this->get_instantsearch_template_version();
     522
     523        return $version === 'modern';
     524    }
    499525}
  • wp-search-with-algolia/trunk/includes/class-algolia-template-loader.php

    r2808073 r3297631  
    7676        $autocomplete_config = $this->plugin->get_autocomplete_config();
    7777
    78         $config = array(
    79             'debug'              => defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG,
    80             'application_id'     => $settings->get_application_id(),
    81             'search_api_key'     => $settings->get_search_api_key(),
    82             'powered_by_enabled' => $settings->is_powered_by_enabled(),
    83             'query'              => get_search_query(),
    84             'autocomplete'       => array(
     78        $config = [
     79            'debug'                => defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG,
     80            'application_id'       => $settings->get_application_id(),
     81            'search_api_key'       => $settings->get_search_api_key(),
     82            'powered_by_enabled'   => $settings->is_powered_by_enabled(),
     83            'search_hits_per_page' => get_option( 'posts_per_page' ),
     84            'query'                => get_search_query(),
     85            'indices'              => [],
     86            'autocomplete'         => [
    8587                'sources'        => $autocomplete_config->get_config(),
    8688                'input_selector' => (string) apply_filters( 'algolia_autocomplete_input_selector', "input[name='s']:not(.no-autocomplete):not(#adminbar-search)" ),
    87             ),
    88             'indices'            => array(),
    89         );
     89            ],
     90        ];
    9091
    9192        // Inject all the indices into the config to ease instantsearch.js integrations.
     
    200201        );
    201202
    202         return Algolia_Template_Utils::locate_template( 'instantsearch.php' );
     203        $instantsearch_is_modern = $this->plugin->get_settings()->should_use_instantsearch_modern();
     204        $chosen_file            = ( $instantsearch_is_modern ) ? 'instantsearch-modern.php' : 'instantsearch.php';
     205        return Algolia_Template_Utils::locate_template( $chosen_file );
    203206    }
    204207
  • wp-search-with-algolia/trunk/includes/factories/class-algolia-search-client-factory.php

    r3050678 r3297631  
    7171        );
    7272
     73        /**
     74         * Allows for customizing an Algolia secured API key.
     75         * @see https://www.algolia.com/doc/api-reference/api-methods/generate-secured-api-key/
     76         *
     77         * @param array $value Array of secured API key arguments. Default empty array.
     78         */
     79        $custom_secured_key_config = apply_filters(
     80            'algolia_custom_secured_key',
     81            []
     82        );
     83
     84        if ( ! empty( $custom_secured_key_config ) && is_array( $custom_secured_key_config ) ) {
     85            $custom_secured_key_config = wp_parse_args(
     86                $custom_secured_key_config,
     87                [
     88                    'filters'           => '',
     89                    'validUntil'        => '',
     90                    'restrictIndices'   => [],
     91                    'restrictSources'   => '',
     92                    'userToken'         => '',
     93                ]
     94            );
     95
     96            $api_key = SearchClient::generateSecuredApiKey( $api_key, $custom_secured_key_config );
     97        }
     98
    7399        if ( ! empty( $custom_config ) && is_array( $custom_config ) ) {
    74100            $config = SearchConfig::create( $app_id, $api_key );
     
    83109                $config->setWriteTimeout( (int) $custom_config['writeTimeout'] );
    84110            }
     111
     112            if ( is_array( $custom_config['DefaultHeaders'] ) && ! empty( $custom_config['DefaultHeaders'] ) ) {
     113                $config->setDefaultHeaders( $custom_config['DefaultHeaders'] );
     114            }
     115
    85116            return SearchClient::createWithConfig( $config );
    86117        }
  • wp-search-with-algolia/trunk/includes/indices/class-algolia-index.php

    r2983873 r3297631  
    717717     * @since  1.0.0
    718718     *
    719      * @param int $page       The page.
    720      * @param int $batch_size The batch size.
     719     * @param int   $page         The page.
     720     * @param int   $batch_size   The batch size.
     721     * @param array $specific_ids Array of IDs to retrieve and index.
    721722     *
    722723     * @return array
    723724     */
    724     abstract protected function get_items( $page, $batch_size );
     725    abstract protected function get_items( $page, $batch_size, $specific_ids = [] );
    725726
    726727    /**
  • wp-search-with-algolia/trunk/includes/indices/class-algolia-posts-index.php

    r2983873 r3297631  
    458458     * @param int   $page         The page.
    459459     * @param int   $batch_size   The batch size.
    460      * @param array $specific_ids Array of IDs to specifically fetch and index.
     460     * @param array $specific_ids Array of post IDs to retrieve and index.
    461461     *
    462462     * @return array
     
    472472            'suppress_filters' => true,
    473473        ];
    474         if ( ! empty( $specific_ids ) ) {
    475             $args['post__in'] = (array) $specific_ids;
     474        if ( ! empty( $specific_ids ) && is_array( $specific_ids ) ) {
     475            $args['post__in'] = $specific_ids;
    476476        }
    477477        $query = new WP_Query( $args );
  • wp-search-with-algolia/trunk/includes/indices/class-algolia-searchable-posts-index.php

    r2983873 r3297631  
    442442     * @param int   $page         The page.
    443443     * @param int   $batch_size   The batch size.
    444      * @param array $specific_ids Array of IDs to specifically fetch and index.
     444     * @param array $specific_ids Array of post IDs to retrieve and index.
    445445     *
    446446     * @return array
     
    459459            'update_post_term_cache' => false,
    460460        ];
    461         if ( ! empty( $specific_ids ) ) {
    462             $args['post__in'] = (array) $specific_ids;
     461        if ( ! empty( $specific_ids ) && is_array( $specific_ids ) ) {
     462            $args['post__in'] = $specific_ids;
    463463        }
    464464        $query = new WP_Query( $args );
  • wp-search-with-algolia/trunk/includes/indices/class-algolia-terms-index.php

    r2726272 r3297631  
    196196     * @since  1.0.0
    197197     *
    198      * @param int $page       The page.
    199      * @param int $batch_size The batch size.
    200      *
    201      * @return array
    202      */
    203     protected function get_items( $page, $batch_size ) {
     198     * @param int   $page         The page.
     199     * @param int   $batch_size   The batch size.
     200     * @param array $specific_ids Array of terms to retrieve and index.
     201     *
     202     * @return array
     203     */
     204    protected function get_items( $page, $batch_size, $specific_ids = [] ) {
    204205        $offset = $batch_size * ( $page - 1 );
    205206
    206         $args = array(
     207        $args = [
     208            'taxonomy'   => $this->taxonomy,
    207209            'order'      => 'ASC',
    208210            'orderby'    => 'id',
     
    210212            'number'     => $batch_size,
    211213            'hide_empty' => false, // Let users choose what to index.
    212         );
    213 
    214         // We use prior to 4.5 syntax for BC purposes.
    215         return get_terms( $this->taxonomy, $args );
     214        ];
     215
     216        if ( ! empty( $specific_ids ) && is_array( $specific_ids ) ) {
     217            $args['include'] = $specific_ids;
     218        }
     219
     220        return get_terms( $args );
    216221    }
    217222
  • wp-search-with-algolia/trunk/includes/indices/class-algolia-users-index.php

    r2726272 r3297631  
    186186     * @since  1.0.0
    187187     *
    188      * @param int $page       The page.
    189      * @param int $batch_size The batch size.
    190      *
    191      * @return array
    192      */
    193     protected function get_items( $page, $batch_size ) {
     188     * @param int   $page         The page.
     189     * @param int   $batch_size   The batch size.
     190     * @param array $specific_ids Array of user to retrieve and index.
     191     *
     192     * @return array
     193     */
     194    protected function get_items( $page, $batch_size, $specific_ids = [] ) {
    194195        $offset = $batch_size * ( $page - 1 );
    195196
    196         $args = array(
     197        $args = [
    197198            'order'   => 'ASC',
    198199            'orderby' => 'ID',
    199200            'offset'  => $offset,
    200201            'number'  => $batch_size,
    201         );
     202        ];
     203
     204        if ( ! empty( $specific_ids ) && is_array( $specific_ids ) ) {
     205            $args['include'] = $specific_ids;
     206        }
    202207
    203208        // We use prior to 4.5 syntax for BC purposes, no `paged` arg.
  • wp-search-with-algolia/trunk/includes/utilities/class-algolia-template-utils.php

    r2887859 r3297631  
    4242        'autocomplete.php',
    4343        'instantsearch.php',
     44        'instantsearch-modern.php',
    4445    ];
    4546
  • wp-search-with-algolia/trunk/templates/instantsearch.php

    r3034675 r3297631  
    66 * @since   1.0.0
    77 *
    8  * @version 2.7.1
     8 * @version 2.9.0
    99 * @package WebDevStudios\WPSWA
    1010 */
     
    122122
    123123                    instantsearch.widgets.configure({
    124                         hitsPerPage: 10,
     124                        hitsPerPage: algolia.search_hits_per_page,
    125125                    }),
    126126
Note: See TracChangeset for help on using the changeset viewer.