Skip to content

Commit

Permalink
Merge pull request #1 from MB-Jan/develop
Browse files Browse the repository at this point in the history
Updated script tag to avoid loading issues of elements.js
  • Loading branch information
bjornharvold authored Apr 1, 2024
2 parents a3f0ab6 + 51ba694 commit 261cc8d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Changelog of wink-wordpress-plugin.

## 1.4.14 (2024-02-26)
## 1.4.15 (2024-03-31)

### Other changes

Expand Down
4 changes: 2 additions & 2 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ Contributors: MB-Jan, bjornharvold
Tags: wink2travel, travel, hotel, booking, affiliate network
Requires at least: 4.7
Tested up to: 6.4
Stable tag: 1.4.14
Version: 1.4.14
Stable tag: 1.4.15
Version: 1.4.15
Requires PHP: 7.4
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Expand Down
19 changes: 12 additions & 7 deletions wink.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* Plugin Name: Wink Affiliate WordPress Plugin
* Description: This plugin integrates your Wink affiliate account with WordPress. It integrates with Gutenberg, Elementor, Avada, WPBakery and as shortcodes.
* Version: 1.4.14
* Version: 1.4.15
* Author: Wink
* Author URI: https://wink.travel/
* License: GPL-3.0
Expand Down Expand Up @@ -40,7 +40,7 @@ function __construct() {
//add_action('init', array( $this,'gutenbergBlockRegistration' ) ); // Adding Gutenberg Block
add_action( 'wp_enqueue_scripts', array($this, 'loadScripts' )); // too resource intensive to search all pages for Wink elements. Scripts need to be added all the time.

add_filter( 'clean_url', array($this,'jsHelper'), 11, 1 ); // Helper to add attribute to js tag
add_filter( 'script_loader_tag', array($this,'jsHelper'), 11, 3 ); // Helper to add attribute to js tag
add_action( 'admin_enqueue_scripts', array($this,'customizeScripts'));

add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), array($this,'settingsLink' ));
Expand Down Expand Up @@ -69,21 +69,26 @@ function customizeScripts() {
wp_enqueue_style( 'winkCustomizer', $this->pluginURL . 'css/customize.css', array(), $this->version );
}
}
function jsHelper($url) {
function jsHelper($tag, $handle, $src) {
$env = winkCore::environmentURL('js', $this->environmentVal);
$optimize = array(
$env.'/elements.js?ver='.$this->version
'wink-Elements',
'wink-Elements-Poly',
'wink-Elements-main'
);
if ( in_array( $url, $optimize ) ) { // this will be optimized
return "$url' defer data-cfasync='true";
if ( in_array( $handle, $optimize ) ) { // this will be optimized
$tag = '<script type="module" src="' . esc_url( $src ) . '" defer data-cfasync="true"></script>';
}
return $url;
return $tag;
}

function loadScripts() {
if (!empty(get_option($this->clientIdKey, false))) {
$env = winkCore::environmentURL('js', $this->environmentVal);
wp_enqueue_style('wink',$env.'/styles.css',array(),$this->version);
wp_enqueue_script('wink-Elements',$env.'/elements.js',array(),$this->version,true);
// wp_enqueue_script('wink-Elements-Poly',$env.'/polyfills.js',array(),$this->version,true);
// wp_enqueue_script('wink-Elements-main',$env.'/main.js',array(),$this->version,true);
}
}
function adminNotice() {
Expand Down

0 comments on commit 261cc8d

Please sign in to comment.