Skip to content

Commit

Permalink
Merge pull request #103 from WebDevStudios/fix/101-pinterest-incompat…
Browse files Browse the repository at this point in the history
…ibility

Version 1.5.0 Pinterest incompatibility
  • Loading branch information
richaber authored Oct 7, 2020
2 parents 6332237 + cee0d02 commit 057ca7f
Show file tree
Hide file tree
Showing 10 changed files with 240 additions and 96 deletions.
6 changes: 6 additions & 0 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions algolia.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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' );
Expand Down
2 changes: 2 additions & 0 deletions classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -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": [
{
Expand Down
138 changes: 48 additions & 90 deletions includes/class-algolia-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,26 @@ class Algolia_Plugin {
*/
private $changes_watchers;

/**
* Instance of Algolia_Styles.
*
* @author WebDevStudios <contact@webdevstudios.com>
* @since 1.5.0
*
* @var Algolia_Styles
*/
private $styles;

/**
* Instance of Algolia_Scripts.
*
* @author WebDevStudios <contact@webdevstudios.com>
* @since 1.5.0
*
* @var Algolia_Scripts
*/
private $scripts;

/**
* Instance of Algolia_Template_Loader.
*
Expand Down Expand Up @@ -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 );
}

Expand Down Expand Up @@ -242,87 +257,6 @@ public function get_autocomplete_config() {
return $this->autocomplete_config;
}

/**
* Register scripts and styles.
*
* @author WebDevStudios <contact@webdevstudios.com>
* @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 </body> instead of in the <head>. 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.
*
Expand Down Expand Up @@ -491,4 +425,28 @@ public function get_templates_path() {
public function get_template_loader() {
return $this->template_loader;
}

/**
* Get the Algolia_Styles.
*
* @author WebDevStudios <contact@webdevstudios.com>
* @since 1.5.0
*
* @return Algolia_Styles
*/
public function get_styles() {
return $this->styles;
}

/**
* Get the Algolia_Scripts.
*
* @author WebDevStudios <contact@webdevstudios.com>
* @since 1.5.0
*
* @return Algolia_Scripts
*/
public function get_scripts() {
return $this->scripts;
}
}
86 changes: 86 additions & 0 deletions includes/class-algolia-scripts.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php
/**
* Algolia_Scripts class file.
*
* @author WebDevStudios <contact@webdevstudios.com>
* @since 1.5.0
*
* @package WebDevStudios\WPSWA
*/

/**
* Class Algolia_Scripts
*
* @since 1.5.0
*/
class Algolia_Scripts {

/**
* Algolia_Scripts constructor.
*
* @author WebDevStudios <contact@webdevstudios.com>
* @since 1.5.0
*/
public function __construct() {
add_action( 'wp_enqueue_scripts', [ $this, 'register_scripts' ] );
}

/**
* Register scripts.
*
* @author WebDevStudios <contact@webdevstudios.com>
* @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
);
}
}
52 changes: 52 additions & 0 deletions includes/class-algolia-styles.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
/**
* Algolia_Styles class file.
*
* @author WebDevStudios <contact@webdevstudios.com>
* @since 1.5.0
*
* @package WebDevStudios\WPSWA
*/

/**
* Class Algolia_Styles
*
* @since 1.5.0
*/
class Algolia_Styles {

/**
* Algolia_Styles constructor.
*
* @author WebDevStudios <contact@webdevstudios.com>
* @since 1.5.0
*/
public function __construct() {
add_action( 'wp_enqueue_scripts', [ $this, 'register_styles' ] );
}

/**
* Register styles.
*
* @author WebDevStudios <contact@webdevstudios.com>
* @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'
);
}
}
21 changes: 19 additions & 2 deletions includes/class-algolia-template-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,33 @@ 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' ) );

// 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' ) );
}
}
}

Expand Down
Loading

0 comments on commit 057ca7f

Please sign in to comment.