Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
/**
* Adds custom SearchWP\Source for MyCustomSources.
*/
add_action( 'plugins_loaded', function() {
class MyCustomSource extends \SearchWP\Source {
// Unique name for this source.
protected $name = 'mycustomsource';
// Database column name that tracks entries for this Source.
protected $db_id_column = 'id';
function __construct() {
global $wpdb;
// The database table storing entries.
$this->db_table = $wpdb->get_blog_prefix() . 'my_db_table';
// Labels for this Source.
$this->labels = [
'plural' => 'My Custom Source Entries',
'singular' => 'My Custom Source Entry',
];
// Attributes for this Source.
$this->attributes = [ [
'name' => 'content',
'label' => 'Entry Content',
'default' => \SearchWP\Utils::get_min_engine_weight(),
'data' => function( $entry_id ) {
return MyCustomSource::get_content( $entry_id );
},
], ];
}
// Returns a native object.
public function entry( \SearchWP\Entry $entry, $query = false ) {
return MyCustomSource::get_entry( $entry->get_id() );
}
}
// Append this Source to the list of available Sources in SearchWP.
add_filter( 'searchwp\sources', function( $sources ) {
$sources[] = new MyCustomSource();
return $sources;
} );
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.