Skip to content

Commit

Permalink
added support for "search_provider" WebExtension
Browse files Browse the repository at this point in the history
  • Loading branch information
pfefferle committed Jan 22, 2024
1 parent 717798b commit 76d41b0
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 9 deletions.
25 changes: 25 additions & 0 deletions includes/class-discovery.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use WP_Error;

use function OpenSearchDocument\url_template;

/**
* Handles all discovery mechanisms
*/
Expand All @@ -16,6 +18,7 @@ public static function init() {

add_filter( 'site_icon_image_sizes', array( static::class, 'site_icon_image_sizes' ) );
add_action( 'osd_xml', array( static::class, 'osd_xml' ) );
add_filter( 'web_app_manifest', array( static::class, 'web_app_manifest' ) );

// Add autodiscovery.
add_action( 'wp_head', array( static::class, 'add_head' ) );
Expand Down Expand Up @@ -125,4 +128,26 @@ public static function osd_xml() {
<?php
}
}

/**
* Modifies the site's web app manifest.
*
* @param array $manifest The associative web app manifest array.
* @return array The filtered $manifest.
*/
public static function web_app_manifest( $manifest ) {
if ( ! isset( $manifest['chrome_settings_overrides'] ) ) {
$manifest['chrome_settings_overrides'] = array();
}

$manifest['chrome_settings_overrides']['search_provider'] = array(
'name' => \get_bloginfo( 'name' ),
'search_url' => url_template( false ),
'keyword' => \sanitize_title( get_bloginfo( 'name' ) ),
'favicon_url' => \get_site_icon_url( 32 ),
'encoding' => \get_bloginfo( 'charset' ),
);

return $manifest;
}
}
2 changes: 1 addition & 1 deletion open-search-document.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Open Search Document
* Plugin URI: https://github.com/pfefferle/wordpress-open-search-document/
* Description: Create an Open Search Document for your blog.
* Version: 4.0.1
* Version: 4.1.0
* Author: Matthias Pfefferle
* Author URI: https://github.com/pfefferle/wordpress-open-search-document/
* License: GPL-2.0-or-later
Expand Down
11 changes: 7 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@
**Tags:** open search, opensearch, open search document, osd, search
**Requires at least:** 4.6
**Tested up to:** 6.4
**Stable tag:** 4.0.1
**Stable tag:** 4.1.0

Create an OpenSearch Document for your blog.

## description ##

Create an OpenSearch Document for your blog.
The plugin creates an OpenSearch Document for your blog.

The plugin supports Google Chromes "[Tab to Search](https://www.chromium.org/tab-to-search)", Firefox' "[OpenSearch plugins](https://developer.mozilla.org/de/docs/OpenSearch_Plugin_f%C3%BCr_Firefox_erstellen)", Safaris "[Quick Website Search](https://developer.apple.com/library/content/releasenotes/General/WhatsNewInSafari/Articles/Safari_8_0.html)", and [custom searches](https://support.microsoft.com/de-de/instantanswers/390c87f8-911e-47a3-adca-c80a1e4076ca/change-the-default-search-engine-in-microsoft-edge) for Microsofts Edge browser.
It supports Google Chromes ["Tab to Search"](https://www.chromium.org/tab-to-search) and ["search_provider" WebExtension](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/chrome_settings_overrides), Firefox' ["OpenSearch plugins"](https://developer.mozilla.org/en-US/docs/Web/OpenSearch), Safaris ["Quick Website Search"](https://developer.apple.com/library/content/releasenotes/General/WhatsNewInSafari/Articles/Safari_8_0.html), and ["custom searches"](https://support.microsoft.com/en-us/microsoft-edge/change-your-default-search-engine-in-microsoft-edge-cccaf51c-a4df-a43e-8036-d4d2c527a791) for Microsofts Edge browser.

From the [spec](http://www.opensearch.org/Specifications/OpenSearch/1.1):

> Search clients can use OpenSearch description documents to learn about the public interface of a search engine. These description documents contain parameterized URL templates that indicate how the search client should make search requests. Search engines can use the OpenSearch response elements to add search metadata to results in a variety of content formats.
The plugin includes:
Other integrations and extensions:

* Extension links for [HTML](http://www.opensearch.org/Specifications/OpenSearch/1.1#Autodiscovery_in_HTML.2FXHTML), [Atom and RSS](http://www.opensearch.org/Specifications/OpenSearch/1.1#Autodiscovery_in_RSS.2FAtom)
* Autodiscovery via [XRDS-Simple](http://wordpress.org/plugins/xrds-simple/), [host-meta](http://wordpress.org/plugins/host-meta/) and [WebFinger](http://wordpress.org/plugins/webfinger/)
Expand Down Expand Up @@ -57,6 +57,9 @@ You can add custom params to the search URL using the `osd_search_url_template`

## Changelog ##

### 4.1.0 ###
* added ["search_provider" WebExtension](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/chrome_settings_overrides) support

### 4.0.1 ###
* fix broken XML output

Expand Down
11 changes: 7 additions & 4 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@ Contributors: pfefferle, johnnoone
Tags: open search, opensearch, open search document, osd, search
Requires at least: 4.6
Tested up to: 6.4
Stable tag: 4.0.1
Stable tag: 4.1.0

Create an OpenSearch Document for your blog.

== description ==

Create an OpenSearch Document for your blog.
The plugin creates an OpenSearch Document for your blog.

The plugin supports Google Chromes "[Tab to Search](https://www.chromium.org/tab-to-search)", Firefox' "[OpenSearch plugins](https://developer.mozilla.org/de/docs/OpenSearch_Plugin_f%C3%BCr_Firefox_erstellen)", Safaris "[Quick Website Search](https://developer.apple.com/library/content/releasenotes/General/WhatsNewInSafari/Articles/Safari_8_0.html)", and [custom searches](https://support.microsoft.com/de-de/instantanswers/390c87f8-911e-47a3-adca-c80a1e4076ca/change-the-default-search-engine-in-microsoft-edge) for Microsofts Edge browser.
It supports Google Chromes ["Tab to Search"](https://www.chromium.org/tab-to-search) and ["search_provider" WebExtension](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/chrome_settings_overrides), Firefox' ["OpenSearch plugins"](https://developer.mozilla.org/en-US/docs/Web/OpenSearch), Safaris ["Quick Website Search"](https://developer.apple.com/library/content/releasenotes/General/WhatsNewInSafari/Articles/Safari_8_0.html), and ["custom searches"](https://support.microsoft.com/en-us/microsoft-edge/change-your-default-search-engine-in-microsoft-edge-cccaf51c-a4df-a43e-8036-d4d2c527a791) for Microsofts Edge browser.

From the [spec](http://www.opensearch.org/Specifications/OpenSearch/1.1):

> Search clients can use OpenSearch description documents to learn about the public interface of a search engine. These description documents contain parameterized URL templates that indicate how the search client should make search requests. Search engines can use the OpenSearch response elements to add search metadata to results in a variety of content formats.

The plugin includes:
Other integrations and extensions:

* Extension links for [HTML](http://www.opensearch.org/Specifications/OpenSearch/1.1#Autodiscovery_in_HTML.2FXHTML), [Atom and RSS](http://www.opensearch.org/Specifications/OpenSearch/1.1#Autodiscovery_in_RSS.2FAtom)
* Autodiscovery via [XRDS-Simple](http://wordpress.org/plugins/xrds-simple/), [host-meta](http://wordpress.org/plugins/host-meta/) and [WebFinger](http://wordpress.org/plugins/webfinger/)
Expand Down Expand Up @@ -49,6 +49,9 @@ You can add custom params to the search URL using the `osd_search_url_template`

== Changelog ==

= 4.1.0 =
* added ["search_provider" WebExtension](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/chrome_settings_overrides) support

= 4.0.1 =
* fix broken XML output

Expand Down

0 comments on commit 76d41b0

Please sign in to comment.