diff --git a/CHANGELOG.md b/CHANGELOG.md index ce80313..6c978ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,15 @@ All notable changes to this project will be documented in this file. +## [0.2.3] - 2025-03-09 + +### Changed + +- Enhanced field indexing to strictly respect settings configuration +- Improved schema manager to only include explicitly selected fields +- Refined factory class to ensure proper field filtering from settings +- Added filter `wp_loupe_field_{$field_name}` to allow field modification. + ## [0.2.2] - 2025-03-08 ### Changed @@ -252,4 +261,5 @@ All notable changes to this project will be documented in this file. [0.1.7]: https://github.com/soderlind/wp-loupe/releases/tag/0.1.7 [0.2.0]: https://github.com/soderlind/wp-loupe/releases/tag/0.2.0 [0.2.1]: https://github.com/soderlind/wp-loupe/releases/tag/0.2.1 -[0.2.2]: https://github.com/soderlind/wp-loupe/releases/tag/0.2.2 \ No newline at end of file +[0.2.2]: https://github.com/soderlind/wp-loupe/releases/tag/0.2.2 +[0.2.3]: https://github.com/soderlind/wp-loupe/releases/tag/0.2.3 \ No newline at end of file diff --git a/README.md b/README.md index e68d74a..7c8733a 100644 --- a/README.md +++ b/README.md @@ -129,16 +129,14 @@ This filter allows you to index posts and pages that are protected by a password add_filter( 'wp_loupe_index_protected','__return_true' ); ``` -### `wp_loupe_schema_content` +### `wp_loupe_field_{$field_name}` -This filter allows you to modify the content before it's indexed. By default, removes HTML comments from content (i.e. remove WordPress block comments). +This filter allows you to change the field content before it is indexed. + +By default, the following is used to remove HTML tags and comments from `post_content`. Among others, it removes the WordPress block comments. ```php -add_filter('wp_loupe_schema_content', function($content) { - // Modify content before indexing - $content = preg_replace('//s', '', $content); - return $content; -}); +add_filter( 'wp_loupe_field_post_content', 'wp_strip_all_tags' ); ``` ### `wp_loupe_schema_{$post_type}` diff --git a/composer.json b/composer.json index 44527b3..cb52cdf 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "type": "wordpress-plugin", "description": "Search engine for WordPress. It uses the Loupe search engine to create a search index for your posts and pages and to search the index.", "homepage": "https://github.com/soderlind/wp-loupe", - "version": "0.2.2", + "version": "0.2.3", "license": "GPL-2.0+", "authors": [ { diff --git a/includes/class-wp-loupe-indexer.php b/includes/class-wp-loupe-indexer.php index e899255..c7476e7 100644 --- a/includes/class-wp-loupe-indexer.php +++ b/includes/class-wp-loupe-indexer.php @@ -29,8 +29,8 @@ public function __construct( $post_types ) { $this->db = WP_Loupe_DB::get_instance(); $this->schema_manager = new WP_Loupe_Schema_Manager(); - $this->init(); $this->register_hooks(); + $this->init(); } /** @@ -44,6 +44,7 @@ private function register_hooks() { } add_action( 'wp_trash_post', array( $this, 'trash_post' ), 10, 2 ); add_action( 'admin_init', array( $this, 'handle_reindex' ) ); + add_filter( 'wp_loupe_field_post_content', 'wp_strip_all_tags' ); } /** @@ -274,7 +275,7 @@ private function prepare_document( \WP_Post $post ): array { } if ( property_exists( $post, $field_name ) ) { - $document[ $field_name ] = $post->{$field_name}; + $document[ $field_name ] = apply_filters( "wp_loupe_field_{$field_name}", $post->{$field_name} ); } elseif ( strpos( $field_name, 'taxonomy_' ) === 0 ) { $taxonomy = substr( $field_name, 9 ); $terms = wp_get_post_terms( $post->ID, $taxonomy, array( 'fields' => 'names' ) ); diff --git a/includes/class-wp-loupe-loader.php b/includes/class-wp-loupe-loader.php index 3fe1f4f..a07aa65 100644 --- a/includes/class-wp-loupe-loader.php +++ b/includes/class-wp-loupe-loader.php @@ -61,7 +61,10 @@ private function setup_post_types() { * @return void */ private function init_components() { + new WP_Loupe_Updater(); + new WPLoupe_Settings_Page(); + $this->search = new WP_Loupe_Search( $this->post_types ); $this->indexer = new WP_Loupe_Indexer( $this->post_types ); } diff --git a/includes/class-wp-loupe-settings.php b/includes/class-wp-loupe-settings.php index a2e7457..e1c63de 100644 --- a/includes/class-wp-loupe-settings.php +++ b/includes/class-wp-loupe-settings.php @@ -323,35 +323,36 @@ public function enqueue_admin_assets($hook) { return; } + $version = WP_Loupe_Utils::get_version_number(); + // Register and enqueue Select2 wp_register_style( 'select2css', WP_LOUPE_URL . 'lib/css/select2.min.css', [], - '4.0.13' + $version ); wp_register_script( 'select2', WP_LOUPE_URL . 'lib/js/select2.min.js', ['jquery'], - '4.0.13', + $version, true ); - // Register and enqueue admin assets wp_register_style( 'wp-loupe-admin', WP_LOUPE_URL . 'lib/css/admin.css', ['select2css'], - WP_LOUPE_VERSION + $version ); wp_register_script( 'wp-loupe-admin', WP_LOUPE_URL . 'lib/js/admin.js', ['jquery', 'select2', 'wp-api-fetch'], - WP_LOUPE_VERSION, + $version, true ); @@ -452,5 +453,4 @@ public function add_help_tabs() { ) ); } -} -new WPLoupe_Settings_Page(); +} \ No newline at end of file diff --git a/includes/class-wp-loupe-utils.php b/includes/class-wp-loupe-utils.php index 8a8b73d..aeceacb 100644 --- a/includes/class-wp-loupe-utils.php +++ b/includes/class-wp-loupe-utils.php @@ -95,6 +95,18 @@ public static function dump( $var ) { } } + // return version number based upon plugin file version + /** + * Get version number based upon plugin version + * + * @since 0.0.1 + * @return string Version number + */ + public static function get_version_number() { + $plugin_data = get_plugin_data( WP_LOUPE_FILE ); + $version = $plugin_data[ 'Version' ]; + return $version; + } /** * Remove transients from the database diff --git a/package.json b/package.json index 969a8a1..4fc6b0e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "wp-loupe", - "version": "0.2.2", + "version": "0.2.3", "description": "Enhance the search functionality of your WordPress site with WP Loupe.", "main": "index.js", "scripts": { diff --git a/readme.txt b/readme.txt index 0eff397..7da6688 100644 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Tags: search, loupe, posts, pages, custom post types, typo-tolerant, fast search Requires at least: 6.3 Requires PHP: 8.1 Tested up to: 6.7 -Stable tag: 0.2.2 +Stable tag: 0.2.3 Donate link: https://paypal.me/PerSoderlind License: GPLv2 or later License URI: https://www.gnu.org/licenses/gpl-2.0.html @@ -85,10 +85,6 @@ Default: WP_CONTENT_DIR . '/wp-loupe-db' Modifies which post types are included in search. Default: ['post', 'page'] -= wp_loupe_filterable_attribute_{$post_type} = -Customizes searchable attributes per post type. -Default: ['post_title', 'post_date', 'post_content'] - = wp_loupe_posts_per_page = Controls search results per page. Default: WordPress "Blog pages show at most" setting @@ -97,14 +93,23 @@ Default: WordPress "Blog pages show at most" setting Controls indexing of password-protected posts. Default: false -= wp_loupe_schema_content = -Modifies content before indexing. -Default: Removes HTML comments += wp_loupe_field_{$field_name} = +Modifies a field before indexing. +Default: Removes HTML comments from `post_content` + += wp_loupe_schema_{$post_type} = +Customizes the schema for a post type. -For usage examples, see the plugin's README.md file. +For usage examples, see the [filter documentation at GitHub](https://github.com/soderlind/wp-loupe?tab=readme-ov-file#filters). == Changelog == += 0.2.3 = +* Enhanced field indexing to strictly respect settings configuration +* Improved schema manager to only include explicitly selected fields +* Refined factory class to ensure proper field filtering from settings +* Added filter `wp_loupe_field_{$field_name}` to allow field modification. + = 0.2.2 = * Changed: Modified field indexing to only include explicitly selected fields in settings * Changed: Updated schema manager to respect indexable field settings diff --git a/wp-loupe.php b/wp-loupe.php index 4202520..3adeb41 100644 --- a/wp-loupe.php +++ b/wp-loupe.php @@ -10,7 +10,7 @@ * Plugin Name: WP Loupe * Plugin URI: https://github.com/soderlind/wp-loupe * Description: Enhance the search functionality of your WordPress site with WP Loupe. - * Version: 0.2.2 + * Version: 0.2.3 * Author: Per Soderlind * Author URI: https://soderlind.no * License: GPL-2.0+ @@ -30,7 +30,6 @@ } define( 'WP_LOUPE_FILE', __FILE__ ); -define( 'WP_LOUPE_VERSION', '0.1.7' ); define( 'WP_LOUPE_NAME', plugin_basename( WP_LOUPE_FILE ) ); define( 'WP_LOUPE_PATH', plugin_dir_path( WP_LOUPE_FILE ) ); define( 'WP_LOUPE_URL', plugin_dir_url( WP_LOUPE_FILE ) ); @@ -41,6 +40,21 @@ * Initialize plugin */ function init() { + if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { + return; + } + + // if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) { + // return; + // } + if ( defined( 'WP_CLI' ) && WP_CLI ) { + return; + } + // don't run the setup on heartbeat requests + if ( defined( 'DOING_AJAX' ) && DOING_AJAX && isset( $_SERVER['HTTP_X_WP_NONCE'] ) ) { + return; + } + WP_Loupe_Loader::get_instance(); if ( ! WP_Loupe_Utils::has_sqlite() ) { return;