Skip to content

Instantly share code, notes, and snippets.

@jchristopher
jchristopher / searchwp-customizations.php
Last active February 9, 2021 20:24
Custom SearchWP Gutenberg Block Parser
<?php
// Disable automatic block parsing during SearchWP index.
add_filter( 'searchwp\source\post\attributes\content\do_blocks', '__return_false' );
// SearchWP custom Block parser.
add_filter( 'searchwp\source\post\attributes\content', function( $content, $args ) {
if ( 'post' === $args['post']->post_type ) {
// This will hold the content we want to index for this Post.
$content_to_index = '';
@jchristopher
jchristopher / searchwp-customizations.php
Created January 25, 2021 13:29
Customize SearchWP's Indexer throttle
<?php
// Customize SearchWP's Indexer throttle.
add_filter( 'searchwp\background_process\load_throttle',
function( $throttle, $args ) {
return 4 * $args['load'];
},
10, 2 );
@jchristopher
jchristopher / searchwp-customizations.php
Created January 25, 2021 13:21
Increase SearchWP's load maximum threshold
<?php
// Increase SearchWP's load maximum threshold to allow loads up to 4 instead of 2.
// @link https://searchwp.com/documentation/hooks/searchwp-background_process-load_maximum/
add_filter( 'searchwp\background_process\load_maximum', function( $max ) {
return 4;
} );
@jchristopher
jchristopher / searchwp-customizations.php
Created January 25, 2021 13:14
Disable SearchWP system load monitoring
<?php
// Disable SearchWP system load monitoring.
add_filter( 'searchwp\background_process\load_monitoring', '__return_false' );
@jchristopher
jchristopher / searchwp-customizations.php
Last active July 27, 2021 17:50
Provide HTTP Basic Authentication credentials to SearchWP (and WP Cron)
<?php
// Provide HTTP Basic Authentication credentials to SearchWP (and WP Cron).
class MySearchWPBasicAuthCreds {
private $username = 'username'; // HTTP Basic Auth username.
private $password = 'password'; // HTTP Basic Auth password.
function __construct() {
// Provide HTTP Basic Authentication credentials to SearchWP.
add_filter(
@jchristopher
jchristopher / searchwp-customizations.php
Created January 15, 2021 12:41
Customize the SearchWP Query arguments used for REST requests
<?php
// Customize the SearchWP Query arguments used for REST requests.
add_filter( 'searchwp\rest\args', function( $args, $params ) {
// $args are sent to \SWP_Query after this.
// @link https://searchwp.com/documentation/classes/swp_query/
return $args;
}, 10, 2 );
@jchristopher
jchristopher / searchwp-customizations.php
Last active January 15, 2021 12:42
Customize the SearchWP Engine used for applicable REST requests
<?php
// Customize the SearchWP Engine used for applicable REST requests.
add_filter( 'searchwp\rest\engine', function( $engine, $args ) {
return 'my_rest_engine_name';
}, 10, 2 );
@jchristopher
jchristopher / searchwp-customizations.php
Created January 15, 2021 12:37
Disable default SearchWP REST API Integration
<?php
// Disable default SearchWP REST API Integration.
add_filter( 'searchwp\rest', '__return_false' );
@jchristopher
jchristopher / searchwp-4.1-manual-primary-keys.sql
Last active January 14, 2021 11:37
Manually add primary keys introduced in SearchWP 4.1
# wp_searchwp_tokens already has a primary key.
ALTER TABLE `wp_searchwp_index` ADD COLUMN `indexid` BIGINT(20) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT FIRST;
ALTER TABLE `wp_searchwp_log` ADD COLUMN `logid` BIGINT(20) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT FIRST;
ALTER TABLE `wp_searchwp_status` CHANGE `site` `site` BIGINT(20) unsigned NOT NULL COMMENT 'Site ID';
ALTER TABLE `wp_searchwp_status` ADD COLUMN `statusid` BIGINT(20) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT FIRST;
@jchristopher
jchristopher / searchwp-customizations.php
Created January 11, 2021 16:32
Prevent SearchWP from considering repeated terms
<?php
// Prevent SearchWP from considering repeated terms.
add_filter( 'searchwp\tokens\string', function( $string ) {
return implode( ' ', array_unique( explode( ' ', strtolower( $string ) ) ) );
} );