Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inline action an filter documentation #367

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions includes/class-algolia-autocomplete-config.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,13 @@ public function get_config() {
$entry['enabled'] = true;
}

/**
* Filters the configuration settings for Autocomplete.
*
* @since 1.0.0
*
* @param array $config Array of configuration options to be used with Autocomplete javascript configuration.
*/
$config = (array) apply_filters( 'algolia_autocomplete_config', $config );

// Remove manually disabled indices.
Expand Down
27 changes: 26 additions & 1 deletion includes/class-algolia-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,15 @@ public function load_indices() {
),
'names'
);

/**
* Filters the array of searchable post types.
*
* @since 1.0.0
*
* @param array $searchable_post_types Array of registered post types that are not excluded from search.
* @return array $value Filtered array of post types.
*/
$searchable_post_types = (array) apply_filters( 'algolia_searchable_post_types', $searchable_post_types );
$this->indices[] = new Algolia_Searchable_Posts_Index( $searchable_post_types );

Expand Down Expand Up @@ -318,7 +327,14 @@ public function load_indices() {
// Add the users index.
$this->indices[] = new Algolia_Users_Index();

// Allow developers to filter the indices.
/**
* Filters the array of indices to load.
*
* @since 1.0.0
*
* @param array $indices Array of indices to load.
* @return array $value Filtered array of indices.
*/
$this->indices = (array) apply_filters( 'algolia_indices', $this->indices );

foreach ( $this->indices as $index ) {
Expand All @@ -338,6 +354,15 @@ public function load_indices() {
}
}

/**
* Filters the array of changes watchers to work with.
*
* @since 1.0.0
*
* @param array $change_watchers Array of watchers to work with.
* @param array $indices Array of indices.
* @return array $value Filtered array of watchers.
*/
$this->changes_watchers = (array) apply_filters( 'algolia_changes_watchers', $this->changes_watchers, $this->indices );

foreach ( $this->changes_watchers as $watcher ) {
Expand Down
36 changes: 35 additions & 1 deletion includes/class-algolia-search.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,24 @@ public function pre_get_posts( WP_Query $query ) {
)
);

/**
* Filters the order by clause for our backend search query.
*
* @since 1.0.0
*
* @param null $value Order by parameter. Default null.
* @return string $value Filtered order by parameter.
*/
$order_by = apply_filters( 'algolia_search_order_by', null );

/**
* Filters the order clause for our backend search query.
*
* @since 1.0.0
*
* @param string $value Order parameter. Default 'desc'.
* @return string $value Filtered order parameter.
*/
$order = apply_filters( 'algolia_search_order', 'desc' );

try {
Expand Down Expand Up @@ -235,7 +252,7 @@ public function posts_search( $search, WP_Query $query ) {
* Output the bundled styles for highlighting search result matches, if enabled.
*
* @author WebDevStudios <[email protected]>
* @since 1.0.0
* @since 1.2.0
*
* @return void
*/
Expand All @@ -244,6 +261,14 @@ public function output_highlighting_bundled_styles() {
return;
}

/**
* Filters whether or not to output styling for search highlight.
*
* @since 1.2.0
*
* @param bool $value Whether or not to output styling CSS
* @return bool $value Filtered determination.
*/
if ( ! apply_filters( 'algolia_search_highlighting_enable_bundled_styles', true ) ) {
return;
}
Expand Down Expand Up @@ -354,6 +379,15 @@ public function highlight_get_the_excerpt( $excerpt, $post ) {
* @return bool
*/
private function highlighting_enabled() : bool {

/**
* Filters whether or not highlighting is enabled.
*
* @since 1.2.0
*
* @param bool $value Whether or not highlighting is enabled.
* @return mixed $value Determined highlight enabled status.
*/
return apply_filters( 'algolia_search_highlighting_enabled', true );
}
}
33 changes: 33 additions & 0 deletions includes/class-algolia-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,14 @@ public function get_synced_indices_ids() {
$ids[] = $this->get_native_search_index_id();
}

/**
* Filters the indices IDs that will be synced.
*
* @since 1.0.0
*
* @param array $ids Array of IDs to sync.
* @return array $value Filtered array of IDs.
*/
return (array) apply_filters( 'algolia_get_synced_indices_ids', $ids );
}

Expand Down Expand Up @@ -252,6 +260,14 @@ public function get_excluded_taxonomies() {
'algolia_excluded_taxonomies'
);

/**
* Filters the array of taxonomies to be excluded from syncing.
*
* @since 1.7.0
*
* @param array $excluded Array of taxonomies to exclude.
* @return array $value Filtered array of taxonomies.
*/
$excluded = (array) apply_filters( 'algolia_excluded_taxonomies', $excluded );

return $excluded;
Expand Down Expand Up @@ -332,6 +348,14 @@ public function should_override_search_in_backend() {
public function should_override_search_with_instantsearch() {
$value = $this->get_override_native_search() === 'instantsearch';

/**
* Filters whether or not we should override search with instantsearch.js
*
* @since 1.0.0
*
* @param bool $value Whether or not we should override.
* @return bool $value Filtered determination of override.
*/
return (bool) apply_filters( 'algolia_should_override_search_with_instantsearch', $value );
}

Expand All @@ -344,6 +368,15 @@ public function should_override_search_with_instantsearch() {
* @return string
*/
public function get_native_search_index_id() {

/**
* Filters the native search index ID.
*
* @since 1.0.0
*
* @param string $value The index ID for native search.
* @return string $vaule The filtered index ID.
*/
return (string) apply_filters( 'algolia_native_search_index_id', 'searchable_posts' );
}

Expand Down
34 changes: 32 additions & 2 deletions includes/class-algolia-template-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ public function load_algolia_config() {
'query' => get_search_query(),
'autocomplete' => array(
'sources' => $autocomplete_config->get_config(),

/**
* Filters the CSS-style selector used to locate search inputs to add Autocomplete to.
*
* @since 1.0.0
*
* @param string $value Selector to target with.
* @return string $value Updated selector.
*/
'input_selector' => (string) apply_filters( 'algolia_autocomplete_input_selector', "input[name='s']:not(.no-autocomplete):not(#adminbar-search)" ),
),
'indices' => array(),
Expand All @@ -99,6 +108,15 @@ public function load_algolia_config() {
}

// Give developers a last chance to alter the configuration.
/**
* Filters the final result of the algolia config object to be used.
* Gives developers one last change to alter the configuration.
*
* @since 1.0.0
*
* @param array $config Array of configuration options
* @return array $config Final configuration.
*/
$config = (array) apply_filters( 'algolia_config', $config );

echo '<script type="text/javascript">var algolia = ' . wp_json_encode( $config ) . ';</script>';
Expand Down Expand Up @@ -147,7 +165,13 @@ public function enqueue_autocomplete_scripts() {
wp_enqueue_script( 'algolia-autocomplete' );
wp_enqueue_script( 'algolia-autocomplete-noconflict' );

// Allow users to easily enqueue custom styles and scripts.
/**
* Fires after Algolia Autocomplete assets have been enqueued.
*
* Allows users to easily enqueue custom styles and scripts that could depend on Autocomplete.
*
* @since 1.0.0
*/
do_action( 'algolia_autocomplete_scripts' );
}

Expand Down Expand Up @@ -194,7 +218,13 @@ function () {
// Enqueue the instantsearch.js library.
wp_enqueue_script( 'algolia-instantsearch' );

// Allow users to easily enqueue custom styles and scripts.
/**
* Fires after Algolia Instantsearch assets have been enqueued.
*
* Allow users to easily enqueue custom styles and scripts that could depend on InstantSearch.
*
* @since 1.0.0
*/
do_action( 'algolia_instantsearch_scripts' );
}
);
Expand Down
33 changes: 32 additions & 1 deletion includes/class-algolia-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,15 @@ public static function get_post_images( $post_id ) {
}

if ( $post_thumbnail_id ) {

/**
* Filters the sizes to fetch image paths for.
*
* @since 1.0.0
*
* @param array $value Array of image sizes to fetch. Default: thumbnail.
* @return array $value Amended array of images sizes.
*/
$sizes = (array) apply_filters( 'algolia_post_images_sizes', array( 'thumbnail' ) );
foreach ( $sizes as $size ) {
$info = wp_get_attachment_image_src( $post_thumbnail_id, $size );
Expand All @@ -137,7 +146,20 @@ public static function get_post_images( $post_id ) {
}
}

return (array) apply_filters( 'algolia_get_post_images', $images );
/**
* Filters the final array of images and image data.
*
* Parameter will be an array keyed by image size, and has
* URL, width and height details for each image.
*
* @since 1.0.0
* @since NEXT Added post_id as second parameter.
*
* @param array $images Array of images data.
* @param int $post_id Current post ID being indexed.
* @return array $images Final array of images data.
*/
return (array) apply_filters( 'algolia_get_post_images', $images, $post_id );
}

/**
Expand Down Expand Up @@ -192,6 +214,14 @@ public static function remove_content_noise( $content ) {
$noise_patterns[] = '/\[\/?et_pb.*?\]/';
}

/**
* Filters the "noise" patterns to run content through.
*
* @since 1.0.0
*
* @param array $value Array of REGEX patterns to use.
* @return array Amended array of patterns.
*/
$noise_patterns = (array) apply_filters( 'algolia_strip_patterns', $noise_patterns );

foreach ( $noise_patterns as $pattern ) {
Expand Down Expand Up @@ -253,6 +283,7 @@ public static function explode_content( $content ) {
* @return bool
*/
public static function get_scripts_in_footer_argument() {

/**
* Filters the `$in_footer` argument to `wp_register_script()` for Algolia Scripts.
*
Expand Down
16 changes: 16 additions & 0 deletions includes/factories/class-algolia-search-client-factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,27 @@ class Algolia_Search_Client_Factory {
*/
public static function create( string $app_id, string $api_key ): SearchClient {

/**
* Filters the UA Integration name value.
*
* @since 1.0.0
*
* @param string $value Default: "WP Search with Algolia"
* @return string $value New UA integration name.
*/
$integration_name = (string) apply_filters(
'algolia_ua_integration_name',
'WP Search with Algolia'
);

/**
* Filters the UA Integration version value.
*
* @since 1.0.0
*
* @oaram string $value Default: Current Algolia plugin version.
* @return string $value Custom UA integration version.
*/
$integration_version = (string) apply_filters(
'algolia_ua_integration_version',
ALGOLIA_VERSION
Expand Down
Loading