From c5ce18ca3151e6ca3a44aaf8ca71be4bd6e5858e Mon Sep 17 00:00:00 2001 From: Matthew Bernhardt Date: Tue, 30 Jun 2026 16:52:24 -0400 Subject: [PATCH 1/3] Update NLS link based on cookie state ** Why are these changes being introduced: We want users of WordPress to see a different configuration of the search form, depending on whether they have opted in to using natural language search in Search MIT Libraries. We also want to have an ability to declare the default condition (if the user does not have a cookie set), and also the ability to suppress the entire NLS link if it turns out there's a problem on launch day. ** Relevant ticket(s): * https://mitlibraries.atlassian.net/browse/use-631 ** How does this address that need: This defines two new options within the multisearch widget configuration form: - nls_included, which determines whether the link is shown at all - nls_default, which defines whether the NLS option should be shown as enabled or disabled if the user has no cookie set. We also introduce two methods in the widget class, to read the cookie state and set the nls_enabled variable based on the priority of: 1. The user's cookie value 2. The widget's declared default value The link to alter the cookie is also calculated based on this logic, in a separate method. ** Document any side effects to this change: The choice to add an nls_included variable is a late decision between Jeremy and I. Fingers crossed, it should not be necessary. The plugin version is also bumped to 1.7. --- .../class-multisearch-widget.php | 97 +++++++++++++++++++ .../mitlib-multisearch-widget.php | 2 +- .../templates/tab-all-use.php | 11 ++- 3 files changed, 105 insertions(+), 5 deletions(-) diff --git a/web/app/plugins/mitlib-multisearch-widget/class-multisearch-widget.php b/web/app/plugins/mitlib-multisearch-widget/class-multisearch-widget.php index 4bdda903..c3e5329d 100644 --- a/web/app/plugins/mitlib-multisearch-widget/class-multisearch-widget.php +++ b/web/app/plugins/mitlib-multisearch-widget/class-multisearch-widget.php @@ -119,6 +119,13 @@ public function widget( $args, $instance ) { if ( $instance['targets'] == 'use' ) { + // Determine whether to enable NLS based on widget settings and the user's cookie. + $nls_enabled = $this->readCookie( $instance['nls_default'] ); + + $nls_link_toggle = $this->setToggleValue( $nls_enabled ); + + $nls_included = $instance['nls_included']; + echo '
'; include( $all_template ); echo '
'; @@ -162,6 +169,11 @@ public function form( $instance ) { if ( '' == $instance['bento_url'] ) { $bento_url = 'https://lib.mit.edu/'; } + $nls_default = $instance['nls_default']; + if ( '' == $instance['nls_default'] ) { + $nls_default = 'off'; + } + $nls_included = $instance['nls_included']; ?>

+

Natural language search

+

+ Should the natural language option be shown?
+ +

+

Which is the default query mode?

+ +
Advanced search | More ways to search - + + + From aa2f9db4e9b7750ad22540c1f87292f06ed7ad23 Mon Sep 17 00:00:00 2001 From: Matthew Bernhardt Date: Wed, 1 Jul 2026 23:42:30 -0400 Subject: [PATCH 2/3] Address automated code review feedback --- .../class-multisearch-widget.php | 8 +++++--- .../mitlib-multisearch-widget/templates/tab-all-use.php | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/web/app/plugins/mitlib-multisearch-widget/class-multisearch-widget.php b/web/app/plugins/mitlib-multisearch-widget/class-multisearch-widget.php index c3e5329d..7423605c 100644 --- a/web/app/plugins/mitlib-multisearch-widget/class-multisearch-widget.php +++ b/web/app/plugins/mitlib-multisearch-widget/class-multisearch-widget.php @@ -317,9 +317,11 @@ public function update( $new_instance, $old_instance ) { } /** - * ReadCookie looks for the 'nls_enabled' domain cookie in the $_COOKIE - * superglobal. If no value is found, it returns the default value - which is - * defined via the widget settings form. + * ReadCookie looks for the 'STYXKEY_nls_enabled' domain cookie in the $_COOKIE superglobal. If no value is found, it + * returns the default value - which is defined via the widget settings form. (We use the STYXKEY prefix in the cookie + * name because this is what Pantheon allows to pass through its caching layers). + * + * @see https://docs.pantheon.io/cookies#cache-varying-cookies * * @param string $nls_enabled Either 'on' (for hybrid) or 'off' (for keyword) - defined in widget settings form. */ diff --git a/web/app/plugins/mitlib-multisearch-widget/templates/tab-all-use.php b/web/app/plugins/mitlib-multisearch-widget/templates/tab-all-use.php index 159ce69f..a17c84e6 100644 --- a/web/app/plugins/mitlib-multisearch-widget/templates/tab-all-use.php +++ b/web/app/plugins/mitlib-multisearch-widget/templates/tab-all-use.php @@ -34,7 +34,7 @@ class="field field-text" From 3f29d44382c4fda316cf596b419ce6311b634b14 Mon Sep 17 00:00:00 2001 From: Matthew Bernhardt Date: Thu, 2 Jul 2026 13:30:30 -0400 Subject: [PATCH 3/3] Stakeholder review --- .../plugins/mitlib-multisearch-widget/templates/tab-all-use.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/app/plugins/mitlib-multisearch-widget/templates/tab-all-use.php b/web/app/plugins/mitlib-multisearch-widget/templates/tab-all-use.php index a17c84e6..f8dc89ff 100644 --- a/web/app/plugins/mitlib-multisearch-widget/templates/tab-all-use.php +++ b/web/app/plugins/mitlib-multisearch-widget/templates/tab-all-use.php @@ -34,7 +34,7 @@ class="field field-text"