diff --git a/README.txt b/README.txt
index bb067d32..3b7408db 100644
--- a/README.txt
+++ b/README.txt
@@ -109,6 +109,12 @@ WebDevStudios provides end-to-end WordPress opportunities from strategy and plan
Follow along with the changelog on [Github](https://github.com/WebDevStudios/wp-search-with-algolia/releases).
+= 1.5.0 =
+* Fix an issue where Pinterest follows a link to the Algolia domain to source text and/or images
+ * Move Algolia scripts to footer by default
+ * Changes algolia_load_scripts_in_footer filter default argument to "true"
+ * Move autocomplete.php template output to footer by default
+
= 1.4.0 =
* Update Algolia PHP Search Client version 2.7.0.
* Update Algolia JS libraries to most recent compatible (non-breaking) versions
diff --git a/algolia.php b/algolia.php
index d6bc953b..d0cbf9cf 100644
--- a/algolia.php
+++ b/algolia.php
@@ -3,7 +3,7 @@
* Plugin Name: WP Search with Algolia
* Plugin URI: https://github.com/WebDevStudios/wp-search-with-algolia
* Description: Integrate the powerful Algolia search service with WordPress
- * Version: 1.4.0
+ * Version: 1.5.0
* Requires at least: 5.0
* Requires PHP: 7.2
* Author: WebDevStudios
@@ -26,7 +26,7 @@
}
// The Algolia Search plugin version.
-define( 'ALGOLIA_VERSION', '1.4.0' );
+define( 'ALGOLIA_VERSION', '1.5.0' );
// The minmum required PHP version.
define( 'ALGOLIA_MIN_PHP_VERSION', '7.2' );
diff --git a/classmap.php b/classmap.php
index ff445fac..014de7e0 100644
--- a/classmap.php
+++ b/classmap.php
@@ -25,6 +25,8 @@
require_once ALGOLIA_PATH . 'includes/class-algolia-settings.php';
require_once ALGOLIA_PATH . 'includes/class-algolia-template-loader.php';
require_once ALGOLIA_PATH . 'includes/class-algolia-utils.php';
+require_once ALGOLIA_PATH . 'includes/class-algolia-styles.php';
+require_once ALGOLIA_PATH . 'includes/class-algolia-scripts.php';
require_once ALGOLIA_PATH . 'includes/indices/class-algolia-index.php';
require_once ALGOLIA_PATH . 'includes/indices/class-algolia-index-replica.php';
diff --git a/composer.json b/composer.json
index eb4d7c1a..de7dae47 100644
--- a/composer.json
+++ b/composer.json
@@ -1,6 +1,6 @@
{
"name": "webdevstudios/wp-search-with-algolia",
- "version": "1.4.0",
+ "version": "1.5.0",
"description": "Integrate the powerful Algolia search service with WordPress.",
"authors": [
{
diff --git a/includes/class-algolia-plugin.php b/includes/class-algolia-plugin.php
index fdb94f33..b4618bbc 100644
--- a/includes/class-algolia-plugin.php
+++ b/includes/class-algolia-plugin.php
@@ -77,6 +77,26 @@ class Algolia_Plugin {
*/
private $changes_watchers;
+ /**
+ * Instance of Algolia_Styles.
+ *
+ * @author WebDevStudios
+ * @since 1.5.0
+ *
+ * @var Algolia_Styles
+ */
+ private $styles;
+
+ /**
+ * Instance of Algolia_Scripts.
+ *
+ * @author WebDevStudios
+ * @since 1.5.0
+ *
+ * @var Algolia_Scripts
+ */
+ private $scripts;
+
/**
* Instance of Algolia_Template_Loader.
*
@@ -120,16 +140,11 @@ public static function get_instance() {
* @since 1.0.0
*/
private function __construct() {
- // Register the assets so that they can be used in other plugins outside of the context of the core features.
- add_action( 'wp_enqueue_scripts', array( $this, 'register_assets' ) );
- add_action( 'admin_enqueue_scripts', array( $this, 'register_assets' ) );
-
- $this->settings = new Algolia_Settings();
-
- $this->api = new Algolia_API( $this->settings );
-
+ $this->settings = new Algolia_Settings();
+ $this->api = new Algolia_API( $this->settings );
$this->compatibility = new Algolia_Compatibility();
-
+ $this->styles = new Algolia_Styles();
+ $this->scripts = new Algolia_Scripts();
add_action( 'init', array( $this, 'load' ), 20 );
}
@@ -242,87 +257,6 @@ public function get_autocomplete_config() {
return $this->autocomplete_config;
}
- /**
- * Register scripts and styles.
- *
- * @author WebDevStudios
- * @since 1.0.0
- */
- public function register_assets() {
-
- $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
-
- /**
- * Filters the `$in_footer` argument to `wp_register_script()` for Algolia Scripts.
- *
- * @since 1.3.0
- *
- * @param bool $in_footer Whether to enqueue the script before
instead of in the
. Default 'false'.
- */
- $in_footer = (bool) apply_filters( 'algolia_load_scripts_in_footer', false );
-
- // CSS.
- wp_register_style(
- 'algolia-autocomplete',
- ALGOLIA_PLUGIN_URL . 'css/algolia-autocomplete.css',
- [],
- ALGOLIA_VERSION,
- 'screen'
- );
- wp_register_style(
- 'algolia-instantsearch',
- ALGOLIA_PLUGIN_URL . 'css/algolia-instantsearch.css',
- [],
- ALGOLIA_VERSION,
- 'screen'
- );
-
- // JS.
- wp_register_script(
- 'algolia-search',
- ALGOLIA_PLUGIN_URL . 'js/algoliasearch/dist/algoliasearch.jquery' . $suffix . '.js',
- [
- 'jquery',
- 'underscore',
- 'wp-util',
- ],
- ALGOLIA_VERSION,
- $in_footer
- );
- wp_register_script(
- 'algolia-autocomplete',
- ALGOLIA_PLUGIN_URL . 'js/autocomplete.js/dist/autocomplete' . $suffix . '.js',
- [
- 'jquery',
- 'underscore',
- 'wp-util',
- ],
- ALGOLIA_VERSION,
- $in_footer
- );
- wp_register_script(
- 'algolia-autocomplete-noconflict',
- ALGOLIA_PLUGIN_URL . 'js/autocomplete-noconflict.js',
- [
- 'algolia-autocomplete',
- ],
- ALGOLIA_VERSION,
- $in_footer
- );
-
- wp_register_script(
- 'algolia-instantsearch',
- ALGOLIA_PLUGIN_URL . 'js/instantsearch.js/dist/instantsearch-preact' . $suffix . '.js',
- [
- 'jquery',
- 'underscore',
- 'wp-util',
- ],
- ALGOLIA_VERSION,
- $in_footer
- );
- }
-
/**
* Load indices.
*
@@ -491,4 +425,28 @@ public function get_templates_path() {
public function get_template_loader() {
return $this->template_loader;
}
+
+ /**
+ * Get the Algolia_Styles.
+ *
+ * @author WebDevStudios
+ * @since 1.5.0
+ *
+ * @return Algolia_Styles
+ */
+ public function get_styles() {
+ return $this->styles;
+ }
+
+ /**
+ * Get the Algolia_Scripts.
+ *
+ * @author WebDevStudios
+ * @since 1.5.0
+ *
+ * @return Algolia_Scripts
+ */
+ public function get_scripts() {
+ return $this->scripts;
+ }
}
diff --git a/includes/class-algolia-scripts.php b/includes/class-algolia-scripts.php
new file mode 100644
index 00000000..32d5f920
--- /dev/null
+++ b/includes/class-algolia-scripts.php
@@ -0,0 +1,86 @@
+
+ * @since 1.5.0
+ *
+ * @package WebDevStudios\WPSWA
+ */
+
+/**
+ * Class Algolia_Scripts
+ *
+ * @since 1.5.0
+ */
+class Algolia_Scripts {
+
+ /**
+ * Algolia_Scripts constructor.
+ *
+ * @author WebDevStudios
+ * @since 1.5.0
+ */
+ public function __construct() {
+ add_action( 'wp_enqueue_scripts', [ $this, 'register_scripts' ] );
+ }
+
+ /**
+ * Register scripts.
+ *
+ * @author WebDevStudios
+ * @since 1.5.0
+ */
+ public function register_scripts() {
+
+ $in_footer = Algolia_Utils::get_scripts_in_footer_argument();
+
+ $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
+
+ wp_register_script(
+ 'algolia-search',
+ ALGOLIA_PLUGIN_URL . 'js/algoliasearch/dist/algoliasearch.jquery' . $suffix . '.js',
+ [
+ 'jquery',
+ 'underscore',
+ 'wp-util',
+ ],
+ ALGOLIA_VERSION,
+ $in_footer
+ );
+
+ wp_register_script(
+ 'algolia-autocomplete',
+ ALGOLIA_PLUGIN_URL . 'js/autocomplete.js/dist/autocomplete' . $suffix . '.js',
+ [
+ 'jquery',
+ 'underscore',
+ 'wp-util',
+ ],
+ ALGOLIA_VERSION,
+ $in_footer
+ );
+
+ wp_register_script(
+ 'algolia-autocomplete-noconflict',
+ ALGOLIA_PLUGIN_URL . 'js/autocomplete-noconflict.js',
+ [
+ 'algolia-autocomplete',
+ ],
+ ALGOLIA_VERSION,
+ $in_footer
+ );
+
+ wp_register_script(
+ 'algolia-instantsearch',
+ ALGOLIA_PLUGIN_URL . 'js/instantsearch.js/dist/instantsearch-preact' . $suffix . '.js',
+ [
+ 'jquery',
+ 'underscore',
+ 'wp-util',
+ ],
+ ALGOLIA_VERSION,
+ $in_footer
+ );
+ }
+}
diff --git a/includes/class-algolia-styles.php b/includes/class-algolia-styles.php
new file mode 100644
index 00000000..e5b5984e
--- /dev/null
+++ b/includes/class-algolia-styles.php
@@ -0,0 +1,52 @@
+
+ * @since 1.5.0
+ *
+ * @package WebDevStudios\WPSWA
+ */
+
+/**
+ * Class Algolia_Styles
+ *
+ * @since 1.5.0
+ */
+class Algolia_Styles {
+
+ /**
+ * Algolia_Styles constructor.
+ *
+ * @author WebDevStudios
+ * @since 1.5.0
+ */
+ public function __construct() {
+ add_action( 'wp_enqueue_scripts', [ $this, 'register_styles' ] );
+ }
+
+ /**
+ * Register styles.
+ *
+ * @author WebDevStudios
+ * @since 1.5.0
+ */
+ public function register_styles() {
+
+ wp_register_style(
+ 'algolia-autocomplete',
+ ALGOLIA_PLUGIN_URL . 'css/algolia-autocomplete.css',
+ [],
+ ALGOLIA_VERSION,
+ 'screen'
+ );
+
+ wp_register_style(
+ 'algolia-instantsearch',
+ ALGOLIA_PLUGIN_URL . 'css/algolia-instantsearch.css',
+ [],
+ ALGOLIA_VERSION,
+ 'screen'
+ );
+ }
+}
diff --git a/includes/class-algolia-template-loader.php b/includes/class-algolia-template-loader.php
index 009d159d..dba2a540 100644
--- a/includes/class-algolia-template-loader.php
+++ b/includes/class-algolia-template-loader.php
@@ -35,8 +35,20 @@ class Algolia_Template_Loader {
public function __construct( Algolia_Plugin $plugin ) {
$this->plugin = $plugin;
+ $in_footer = Algolia_Utils::get_scripts_in_footer_argument();
+
// Inject Algolia configuration in a JavaScript variable.
- add_filter( 'wp_head', array( $this, 'load_algolia_config' ) );
+ if ( true === $in_footer ) {
+ add_filter(
+ 'wp_footer',
+ [ $this, 'load_algolia_config' ]
+ );
+ } else {
+ add_filter(
+ 'wp_head',
+ [ $this, 'load_algolia_config' ]
+ );
+ }
// Listen for native templates to override.
add_filter( 'template_include', array( $this, 'template_loader' ) );
@@ -44,7 +56,12 @@ public function __construct( Algolia_Plugin $plugin ) {
// Load autocomplete.js search experience if its enabled.
if ( $this->should_load_autocomplete() ) {
add_filter( 'wp_enqueue_scripts', array( $this, 'enqueue_autocomplete_scripts' ) );
- add_filter( 'wp_head', array( $this, 'load_autocomplete_template' ), PHP_INT_MAX );
+
+ if ( true === $in_footer ) {
+ add_filter( 'wp_footer', array( $this, 'load_autocomplete_template' ) );
+ } else {
+ add_filter( 'wp_head', array( $this, 'load_autocomplete_template' ) );
+ }
}
}
diff --git a/includes/class-algolia-utils.php b/includes/class-algolia-utils.php
index f6b1e77e..ed671ba2 100644
--- a/includes/class-algolia-utils.php
+++ b/includes/class-algolia-utils.php
@@ -243,4 +243,27 @@ public static function explode_content( $content ) {
return $parts;
}
+
+ /**
+ * Get the `$in_footer` argument for registering scripts.
+ *
+ * @author WebDevStudios
+ * @since 1.5.0
+ *
+ * @return bool
+ */
+ public static function get_scripts_in_footer_argument() {
+ /**
+ * Filters the `$in_footer` argument to `wp_register_script()` for Algolia Scripts.
+ *
+ * @since 1.3.0
+ * @since 1.5.0 The default changed from 'false' to 'true'.
+ *
+ * @param bool $in_footer Whether to enqueue the script before instead of in the . Default 'true'.
+ */
+ return (bool) apply_filters(
+ 'algolia_load_scripts_in_footer',
+ true
+ );
+ }
}
diff --git a/package.json b/package.json
index b3f44a2a..ac56d4eb 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "wp-search-with-algolia",
- "version": "1.4.0",
+ "version": "1.5.0",
"description": "Integrate the powerful Algolia search service with WordPress.",
"author": "WebDevStudios",
"license": "GPL-3.0",