Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/clone/wp-conte.../plugins/interact.../src/Plugin
File: Assets.php
<?php
[0] Fix | Delete
namespace Saltus\WP\Plugin\Saltus\InteractiveMaps\Plugin;
[1] Fix | Delete
[2] Fix | Delete
use Saltus\WP\Plugin\Saltus\InteractiveMaps\Core;
[3] Fix | Delete
[4] Fix | Delete
/**
[5] Fix | Delete
* Manage Assets like scripts and styles.
[6] Fix | Delete
*/
[7] Fix | Delete
class Assets {
[8] Fix | Delete
[9] Fix | Delete
/**
[10] Fix | Delete
* The plugin's instance.
[11] Fix | Delete
*
[12] Fix | Delete
* @var Core
[13] Fix | Delete
*/
[14] Fix | Delete
public $core;
[15] Fix | Delete
[16] Fix | Delete
/**
[17] Fix | Delete
* Options for Map CPT
[18] Fix | Delete
*/
[19] Fix | Delete
private $options;
[20] Fix | Delete
[21] Fix | Delete
/**
[22] Fix | Delete
* Define Assets
[23] Fix | Delete
*
[24] Fix | Delete
* @param Core $core This plugin's instance.
[25] Fix | Delete
*/
[26] Fix | Delete
public function __construct( Core $core ) {
[27] Fix | Delete
[28] Fix | Delete
$options = get_option( 'interactive-maps' );
[29] Fix | Delete
[30] Fix | Delete
$this->options = $options;
[31] Fix | Delete
[32] Fix | Delete
$this->core = $core;
[33] Fix | Delete
[34] Fix | Delete
// control minify plugins
[35] Fix | Delete
$this->exclude_from_minify();
[36] Fix | Delete
[37] Fix | Delete
}
[38] Fix | Delete
[39] Fix | Delete
/**
[40] Fix | Delete
* Exclude plugin files from minify plugins
[41] Fix | Delete
*/
[42] Fix | Delete
public function exclude_from_minify() {
[43] Fix | Delete
// wp rocket
[44] Fix | Delete
add_filter(
[45] Fix | Delete
'rocket_exclude_defer_js', function( $excluded_files = array() ) {
[46] Fix | Delete
$excluded_files[] = '/wp-content/plugins/interactive-geo-maps/(.*).js';
[47] Fix | Delete
$excluded_files[] = 'https://cdn.amcharts.com/';
[48] Fix | Delete
return $excluded_files;
[49] Fix | Delete
}
[50] Fix | Delete
);
[51] Fix | Delete
[52] Fix | Delete
}
[53] Fix | Delete
[54] Fix | Delete
/**
[55] Fix | Delete
* Load assets.
[56] Fix | Delete
*/
[57] Fix | Delete
public function load_assets() {
[58] Fix | Delete
[59] Fix | Delete
add_action( 'admin_enqueue_scripts', array( $this, 'load_admin_styles' ) );
[60] Fix | Delete
add_action( 'admin_enqueue_scripts', array( $this, 'load_admin_scripts' ) );
[61] Fix | Delete
[62] Fix | Delete
}
[63] Fix | Delete
[64] Fix | Delete
/**
[65] Fix | Delete
* Load assets
[66] Fix | Delete
*/
[67] Fix | Delete
public function load_admin_styles() {
[68] Fix | Delete
[69] Fix | Delete
global $typenow;
[70] Fix | Delete
[71] Fix | Delete
// we load the file across the admin, to remove the trial notices and so on
[72] Fix | Delete
// will need to be improved.
[73] Fix | Delete
[74] Fix | Delete
[75] Fix | Delete
// styles
[76] Fix | Delete
wp_register_style(
[77] Fix | Delete
$this->core->name . '_admin',
[78] Fix | Delete
plugins_url( 'assets/admin/css/admin-style.min.css', $this->core->file_path ),
[79] Fix | Delete
false,
[80] Fix | Delete
$this->core->version
[81] Fix | Delete
);
[82] Fix | Delete
[83] Fix | Delete
wp_enqueue_style( $this->core->name . '_admin' );
[84] Fix | Delete
[85] Fix | Delete
if ( $typenow === 'igmap' ) {
[86] Fix | Delete
// also add normal map styles
[87] Fix | Delete
$this->load_map_styles();
[88] Fix | Delete
}
[89] Fix | Delete
}
[90] Fix | Delete
[91] Fix | Delete
public function load_admin_scripts() {
[92] Fix | Delete
[93] Fix | Delete
global $typenow;
[94] Fix | Delete
global $post;
[95] Fix | Delete
global $pagenow;
[96] Fix | Delete
[97] Fix | Delete
if ( $typenow === 'igmap' && ( $pagenow === 'post.php' || $pagenow === 'post-new.php' ) ) {
[98] Fix | Delete
[99] Fix | Delete
if ( $pagenow === 'post.php' && $post ) {
[100] Fix | Delete
[101] Fix | Delete
$atts = array(
[102] Fix | Delete
'id' => $post->ID,
[103] Fix | Delete
);
[104] Fix | Delete
[105] Fix | Delete
// get current map initial meta
[106] Fix | Delete
$map = new Map( $this->core );
[107] Fix | Delete
$map->setup( $atts );
[108] Fix | Delete
$meta = $map->meta;
[109] Fix | Delete
[110] Fix | Delete
} elseif ( $pagenow === 'post-new.php' ) {
[111] Fix | Delete
[112] Fix | Delete
$options = $this->options;
[113] Fix | Delete
[114] Fix | Delete
$meta = [
[115] Fix | Delete
'disabled' => true,
[116] Fix | Delete
'container' => 'map_preview_1',
[117] Fix | Delete
'zoomMaster' => isset( $options['zoomMaster'] ) ? $options['zoomMaster'] : false,
[118] Fix | Delete
];
[119] Fix | Delete
}
[120] Fix | Delete
[121] Fix | Delete
if ( ! is_array( $meta ) ) {
[122] Fix | Delete
$meta = [];
[123] Fix | Delete
}
[124] Fix | Delete
[125] Fix | Delete
// include meta value saying we're in the admin
[126] Fix | Delete
$meta['admin'] = '1';
[127] Fix | Delete
$meta['container_info'] = 'map_visual_info';
[128] Fix | Delete
$meta['container_click_data'] = 'map_click_events_info';
[129] Fix | Delete
$meta['container_click_coordinates'] = 'map_click_events_coordinates';
[130] Fix | Delete
$meta['regionLabelCustomCoordinates'] = 'regionLabelCustomCoordinates';
[131] Fix | Delete
[132] Fix | Delete
$this->load_map_scripts( $meta );
[133] Fix | Delete
[134] Fix | Delete
$this->load_google_scripts();
[135] Fix | Delete
[136] Fix | Delete
// jsonTree
[137] Fix | Delete
$this->load_json_tree();
[138] Fix | Delete
[139] Fix | Delete
// autocomplete
[140] Fix | Delete
$this->load_autocomplete();
[141] Fix | Delete
[142] Fix | Delete
// Admin Custom Javascript
[143] Fix | Delete
wp_register_script(
[144] Fix | Delete
$this->core->name . '_admin_build',
[145] Fix | Delete
plugins_url( 'assets/admin/js/admin-scripts.js', $this->core->file_path ),
[146] Fix | Delete
array(),
[147] Fix | Delete
$this->core->version,
[148] Fix | Delete
true
[149] Fix | Delete
);
[150] Fix | Delete
wp_enqueue_script( $this->core->name . '_admin_build' );
[151] Fix | Delete
[152] Fix | Delete
$this->options['ajax_url'] = admin_url( 'admin-ajax.php' );
[153] Fix | Delete
$this->options['ajax_nonce'] = wp_create_nonce( 'igmaps_edit' );
[154] Fix | Delete
$this->options['max_input_vars'] = ini_get( 'max_input_vars' );
[155] Fix | Delete
$this->options['messages'] = [
[156] Fix | Delete
/* translators: region code refers to a alphanumeric code that represents a particular region */
[157] Fix | Delete
'regionCode' => __( 'Region Code', 'interactive-geo-maps' ),
[158] Fix | Delete
'regionName' => __( 'Region Name', 'interactive-geo-maps' ),
[159] Fix | Delete
'fullData' => __( 'Full Available Data', 'interactive-geo-maps' ),
[160] Fix | Delete
'jsonError' => __( 'Error: can\'t process data', 'interactive-geo-maps' ),
[161] Fix | Delete
'maxInputError' => __( '<strong>Attention!</strong> Your map has too many entries for your server to handle when saving it. <br> To prevent loosing map data, avoid updating your map until this issue is solved. <a href="https://interactivegeomaps.com/docs/max-input-vars-issue" target="_blank">Read more about this issue here</a>.', 'interactive-geo-maps' ),
[162] Fix | Delete
'addToMap' => __( 'Add this region to map', 'interactive-geo-maps' ),
[163] Fix | Delete
'regionCodeInfo' => __('Click + to add region to the map', 'interactive-geo-maps' ),
[164] Fix | Delete
'resetAutoLabels' => __('Are you sure you want to reset the labels positions?', 'interactive-geo-maps' ),
[165] Fix | Delete
];
[166] Fix | Delete
[167] Fix | Delete
wp_localize_script( $this->core->name . '_admin_build', 'iMapsOptions', $this->options );
[168] Fix | Delete
}
[169] Fix | Delete
[170] Fix | Delete
}
[171] Fix | Delete
[172] Fix | Delete
/**
[173] Fix | Delete
* Load jsonTree script
[174] Fix | Delete
*
[175] Fix | Delete
* @return void
[176] Fix | Delete
*/
[177] Fix | Delete
public function load_json_tree() {
[178] Fix | Delete
wp_register_script(
[179] Fix | Delete
$this->core->name . '_jsontree',
[180] Fix | Delete
plugins_url( 'assets/admin/vendor/jsonTree/jsonTree.js', $this->core->file_path ),
[181] Fix | Delete
array(),
[182] Fix | Delete
$this->core->version,
[183] Fix | Delete
true
[184] Fix | Delete
);
[185] Fix | Delete
wp_enqueue_script( $this->core->name . '_jsontree' );
[186] Fix | Delete
[187] Fix | Delete
// styles
[188] Fix | Delete
wp_register_style(
[189] Fix | Delete
$this->core->name . '_jsontree',
[190] Fix | Delete
plugins_url( 'assets/admin/vendor/jsonTree/jsonTree.css', $this->core->file_path ),
[191] Fix | Delete
false,
[192] Fix | Delete
$this->core->version
[193] Fix | Delete
);
[194] Fix | Delete
[195] Fix | Delete
wp_enqueue_style( $this->core->name . '_jsontree' );
[196] Fix | Delete
}
[197] Fix | Delete
[198] Fix | Delete
public function load_autocomplete() {
[199] Fix | Delete
wp_register_script(
[200] Fix | Delete
$this->core->name . '_autocomplete',
[201] Fix | Delete
plugins_url( 'assets/admin/vendor/autocomplete/autocomplete.js', $this->core->file_path ),
[202] Fix | Delete
array(),
[203] Fix | Delete
$this->core->version,
[204] Fix | Delete
true
[205] Fix | Delete
);
[206] Fix | Delete
wp_enqueue_script( $this->core->name . '_autocomplete' );
[207] Fix | Delete
[208] Fix | Delete
// styles
[209] Fix | Delete
wp_register_style(
[210] Fix | Delete
$this->core->name . '_autocomplete',
[211] Fix | Delete
plugins_url( 'assets/admin/vendor/autocomplete/autocomplete.css', $this->core->file_path ),
[212] Fix | Delete
false,
[213] Fix | Delete
$this->core->version
[214] Fix | Delete
);
[215] Fix | Delete
[216] Fix | Delete
wp_enqueue_style( $this->core->name . '_autocomplete' );
[217] Fix | Delete
}
[218] Fix | Delete
[219] Fix | Delete
public function load_google_scripts() {
[220] Fix | Delete
[221] Fix | Delete
if ( $this->options['googleApiKey'] && $this->options['googleApiKey'] !== '' ) {
[222] Fix | Delete
wp_register_script(
[223] Fix | Delete
$this->core->name . '_google_geocoding',
[224] Fix | Delete
sprintf( 'https://maps.googleapis.com/maps/api/js?key=%s&libraries=places', $this->options['googleApiKey'] ),
[225] Fix | Delete
array(),
[226] Fix | Delete
$this->core->version,
[227] Fix | Delete
true
[228] Fix | Delete
);
[229] Fix | Delete
wp_enqueue_script( $this->core->name . '_google_geocoding' );
[230] Fix | Delete
}
[231] Fix | Delete
[232] Fix | Delete
}
[233] Fix | Delete
[234] Fix | Delete
/**
[235] Fix | Delete
* Load assets
[236] Fix | Delete
*/
[237] Fix | Delete
public function load_map_styles() {
[238] Fix | Delete
[239] Fix | Delete
$hasfilter = has_filter( 'igm_public_assets_url' );
[240] Fix | Delete
if ( $hasfilter ) {
[241] Fix | Delete
$url = apply_filters( 'igm_public_assets_url', 'css/styles.min.css' );
[242] Fix | Delete
} else {
[243] Fix | Delete
$url = plugins_url( 'assets/public/css/styles.min.css', $this->core->file_path );
[244] Fix | Delete
}
[245] Fix | Delete
[246] Fix | Delete
// styles
[247] Fix | Delete
wp_register_style(
[248] Fix | Delete
$this->core->name . '_main',
[249] Fix | Delete
$url,
[250] Fix | Delete
false,
[251] Fix | Delete
$this->core->version
[252] Fix | Delete
);
[253] Fix | Delete
[254] Fix | Delete
wp_enqueue_style( $this->core->name . '_main' );
[255] Fix | Delete
[256] Fix | Delete
if ( '' !== $this->core->extra_styles ) {
[257] Fix | Delete
[258] Fix | Delete
// since some code might be sanitized but we still need these operators in javascript
[259] Fix | Delete
$css = $this->core->extra_styles;
[260] Fix | Delete
$css = str_replace('&gt;','>',$css);
[261] Fix | Delete
$css = str_replace('&lt;','<',$css);
[262] Fix | Delete
$css = str_replace('&amp;','&',$css);
[263] Fix | Delete
[264] Fix | Delete
wp_add_inline_style( $this->core->name . '_main', $css );
[265] Fix | Delete
}
[266] Fix | Delete
[267] Fix | Delete
}
[268] Fix | Delete
[269] Fix | Delete
public function load_map_scripts( $localize = false ) {
[270] Fix | Delete
[271] Fix | Delete
$deps = array();
[272] Fix | Delete
$async_urls = array();
[273] Fix | Delete
[274] Fix | Delete
// options to localize script - make data available to the script
[275] Fix | Delete
$options = $this->options;
[276] Fix | Delete
[277] Fix | Delete
$localize_options = array(
[278] Fix | Delete
'animations' => isset( $options['animations'] ) ? $options['animations'] : true,
[279] Fix | Delete
'lazyLoad' => isset( $options['lazyLoad'] ) ? $options['lazyLoad'] : false,
[280] Fix | Delete
'async' => isset( $options['async'] ) ? $options['async'] : false,
[281] Fix | Delete
'hold' => isset( $options['hold'] ) ? $options['hold'] : false,
[282] Fix | Delete
'locale' => isset( $options['amcharts_locale'] ) && trim( $options['amcharts_locale'] ) !== '' ? trim( $options['amcharts_locale'] ) : false,
[283] Fix | Delete
'lang' => isset( $options['amcharts_lang'] ) && trim( $options['amcharts_lang'] ) !== '' ? trim( $options['amcharts_lang'] ) : false,
[284] Fix | Delete
);
[285] Fix | Delete
[286] Fix | Delete
if ( is_admin() ) {
[287] Fix | Delete
// in admin, let's not use async for now
[288] Fix | Delete
$localize_options['async'] = false;
[289] Fix | Delete
// if we're in the admin area, do not hold maps rendering
[290] Fix | Delete
$localize_options['hold'] = false;
[291] Fix | Delete
}
[292] Fix | Delete
[293] Fix | Delete
// $version = '4'; //'version/4.7.18';
[294] Fix | Delete
$version = apply_filters( 'igm_amcharts_version', 'version/4.10.29' );
[295] Fix | Delete
[296] Fix | Delete
if ( isset( $options['amcharts_version'] ) && trim( $options['amcharts_version'] ) !== '' ) {
[297] Fix | Delete
$version = apply_filters( 'igm_amcharts_version', 'version/' . $options['amcharts_version'] );
[298] Fix | Delete
}
[299] Fix | Delete
[300] Fix | Delete
$url_path = apply_filters( 'igm_amcharts_lib_url', 'https://cdn.amcharts.com/lib/' );
[301] Fix | Delete
[302] Fix | Delete
if ( $localize ) {
[303] Fix | Delete
[304] Fix | Delete
if ( ! empty( $localize ) ) {
[305] Fix | Delete
[306] Fix | Delete
$this->core->add_localize_data( $localize );
[307] Fix | Delete
[308] Fix | Delete
}
[309] Fix | Delete
}
[310] Fix | Delete
[311] Fix | Delete
// if we load async
[312] Fix | Delete
if ( isset( $localize_options['async'] ) && $localize_options['async'] ) {
[313] Fix | Delete
array_push( $async_urls, $url_path . $version . '/core.js' );
[314] Fix | Delete
array_push( $async_urls, $url_path . $version . '/maps.js' );
[315] Fix | Delete
if ( isset( $localize_options['animations'] ) && $localize_options['animations'] ) {
[316] Fix | Delete
array_push( $async_urls, $url_path . $version . '/themes/animated.js' );
[317] Fix | Delete
}
[318] Fix | Delete
if ( isset( $options['amcharts_locale'] ) && trim( $options['amcharts_locale'] ) !== '' ) {
[319] Fix | Delete
array_push( $async_urls, $url_path . $version . '/lang/' . $options['amcharts_locale'] . '.js' );
[320] Fix | Delete
}
[321] Fix | Delete
[322] Fix | Delete
if ( isset( $options['amcharts_lang'] ) && trim( $options['amcharts_lang'] ) !== '' ) {
[323] Fix | Delete
array_push( $async_urls, $url_path . $version . '/geodata/lang/' . strtoupper( $options['amcharts_locale'] ) . '.js' );
[324] Fix | Delete
}
[325] Fix | Delete
[326] Fix | Delete
// build proper dependencies
[327] Fix | Delete
foreach ( $this->core->script_localize_data as $mapsdata => $mapdata ) {
[328] Fix | Delete
if ( ! isset( $mapdata['urls'] ) ) {
[329] Fix | Delete
continue;
[330] Fix | Delete
}
[331] Fix | Delete
foreach ( $mapdata['urls'] as $k => $url ) {
[332] Fix | Delete
array_push( $async_urls, $url );
[333] Fix | Delete
}
[334] Fix | Delete
}
[335] Fix | Delete
}
[336] Fix | Delete
[337] Fix | Delete
// if we won't be using async loading
[338] Fix | Delete
else {
[339] Fix | Delete
[340] Fix | Delete
wp_register_script(
[341] Fix | Delete
$this->core->name . '_amcharts_core',
[342] Fix | Delete
$url_path . $version . '/core.js',
[343] Fix | Delete
array(),
[344] Fix | Delete
$this->core->version,
[345] Fix | Delete
true
[346] Fix | Delete
);
[347] Fix | Delete
wp_enqueue_script( $this->core->name . '_amcharts_core' );
[348] Fix | Delete
[349] Fix | Delete
$this->modify_script_tag( $this->core->name . '_amcharts_core', $this->options );
[350] Fix | Delete
[351] Fix | Delete
wp_register_script(
[352] Fix | Delete
$this->core->name . '_amcharts_maps',
[353] Fix | Delete
$url_path . $version . '/maps.js',
[354] Fix | Delete
array( $this->core->name . '_amcharts_core' ),
[355] Fix | Delete
$this->core->version,
[356] Fix | Delete
true
[357] Fix | Delete
);
[358] Fix | Delete
wp_enqueue_script( $this->core->name . '_amcharts_maps' );
[359] Fix | Delete
[360] Fix | Delete
array_push( $deps, $this->core->name . '_amcharts_maps' );
[361] Fix | Delete
[362] Fix | Delete
$this->modify_script_tag( $this->core->name . '_amcharts_maps' );
[363] Fix | Delete
[364] Fix | Delete
if ( isset( $localize_options['animations'] ) && $localize_options['animations'] ) {
[365] Fix | Delete
[366] Fix | Delete
wp_register_script(
[367] Fix | Delete
$this->core->name . '_amcharts_animated',
[368] Fix | Delete
$url_path . $version . '/themes/animated.js',
[369] Fix | Delete
array( $this->core->name . '_amcharts_maps' ),
[370] Fix | Delete
$this->core->version,
[371] Fix | Delete
true
[372] Fix | Delete
);
[373] Fix | Delete
wp_enqueue_script( $this->core->name . '_amcharts_animated' );
[374] Fix | Delete
array_push( $deps, $this->core->name . '_amcharts_animated' );
[375] Fix | Delete
[376] Fix | Delete
$this->modify_script_tag( $this->core->name . '_amcharts_animated' );
[377] Fix | Delete
[378] Fix | Delete
}
[379] Fix | Delete
[380] Fix | Delete
if ( isset( $options['amcharts_locale'] ) && trim( $options['amcharts_locale'] ) !== '' ) {
[381] Fix | Delete
wp_register_script(
[382] Fix | Delete
$this->core->name . '_amcharts_locale',
[383] Fix | Delete
$url_path . $version . '/lang/' . $options['amcharts_locale'] . '.js',
[384] Fix | Delete
array( $this->core->name . '_amcharts_maps' ),
[385] Fix | Delete
$this->core->version,
[386] Fix | Delete
true
[387] Fix | Delete
);
[388] Fix | Delete
wp_enqueue_script( $this->core->name . '_amcharts_locale' );
[389] Fix | Delete
array_push( $deps, $this->core->name . '_amcharts_locale' );
[390] Fix | Delete
[391] Fix | Delete
$this->modify_script_tag( $this->core->name . '_amcharts_locale' );
[392] Fix | Delete
}
[393] Fix | Delete
[394] Fix | Delete
if ( isset( $options['amcharts_lang'] ) && trim( $options['amcharts_lang'] ) !== '' ) {
[395] Fix | Delete
wp_register_script(
[396] Fix | Delete
$this->core->name . '_amcharts_lang',
[397] Fix | Delete
$url_path . '4' . '/geodata/lang/' . strtoupper( $options['amcharts_lang'] ) . '.js',
[398] Fix | Delete
array( $this->core->name . '_amcharts_maps' ),
[399] Fix | Delete
$this->core->version,
[400] Fix | Delete
true
[401] Fix | Delete
);
[402] Fix | Delete
wp_enqueue_script( $this->core->name . '_amcharts_lang' );
[403] Fix | Delete
array_push( $deps, $this->core->name . '_amcharts_lang' );
[404] Fix | Delete
[405] Fix | Delete
$this->modify_script_tag( $this->core->name . '_amcharts_lang' );
[406] Fix | Delete
}
[407] Fix | Delete
[408] Fix | Delete
// build proper dependencies
[409] Fix | Delete
foreach ( $this->core->script_localize_data as $key => $mapdata ) {
[410] Fix | Delete
if ( ! isset( $mapdata['urls'] ) ) {
[411] Fix | Delete
continue;
[412] Fix | Delete
}
[413] Fix | Delete
foreach ( $mapdata['urls'] as $k => $url ) {
[414] Fix | Delete
wp_register_script(
[415] Fix | Delete
$this->core->name . '_' . $k,
[416] Fix | Delete
$url,
[417] Fix | Delete
$this->core->name . '_amcharts_maps',
[418] Fix | Delete
$this->core->version,
[419] Fix | Delete
true
[420] Fix | Delete
);
[421] Fix | Delete
array_push( $deps, $this->core->name . '_' . $k );
[422] Fix | Delete
[423] Fix | Delete
$this->modify_script_tag( $this->core->name . '_' . $k );
[424] Fix | Delete
}
[425] Fix | Delete
}
[426] Fix | Delete
}
[427] Fix | Delete
[428] Fix | Delete
// we remove script, to reset the localized data, just in case
[429] Fix | Delete
wp_deregister_script( $this->core->name . '_map_service' );
[430] Fix | Delete
[431] Fix | Delete
[432] Fix | Delete
//public asset
[433] Fix | Delete
[434] Fix | Delete
$hasfilter = has_filter( 'igm_public_assets_url' );
[435] Fix | Delete
if ( $hasfilter ) {
[436] Fix | Delete
$service_url = apply_filters( 'igm_public_assets_url', 'map-service/app.min.js' );
[437] Fix | Delete
} else {
[438] Fix | Delete
$url = defined('WP_DEBUG') && true === WP_DEBUG ? 'assets/public/map-service/app.js' : 'assets/public/map-service/app.min.js';
[439] Fix | Delete
$service_url = plugins_url( $url, $this->core->file_path );
[440] Fix | Delete
}
[441] Fix | Delete
[442] Fix | Delete
wp_register_script(
[443] Fix | Delete
$this->core->name . '_map_service',
[444] Fix | Delete
$service_url,
[445] Fix | Delete
$deps,
[446] Fix | Delete
$this->core->version,
[447] Fix | Delete
true
[448] Fix | Delete
);
[449] Fix | Delete
[450] Fix | Delete
wp_enqueue_script( $this->core->name . '_map_service' );
[451] Fix | Delete
[452] Fix | Delete
if ( $this->core->extra_scripts !== '' ) {
[453] Fix | Delete
wp_add_inline_script( $this->core->name . '_map_service', $this->core->extra_scripts );
[454] Fix | Delete
}
[455] Fix | Delete
[456] Fix | Delete
if ( isset( $localize_options['async'] ) && $localize_options['async'] ) {
[457] Fix | Delete
$this->async_script_tag( $this->core->name . '_map_service' );
[458] Fix | Delete
} else {
[459] Fix | Delete
$this->modify_script_tag( $this->core->name . '_map_service' );
[460] Fix | Delete
}
[461] Fix | Delete
[462] Fix | Delete
$final_data = [
[463] Fix | Delete
'options' => $localize_options,
[464] Fix | Delete
'data' => $this->core->script_localize_data,
[465] Fix | Delete
'async' => array_values( array_unique( $async_urls ) ),
[466] Fix | Delete
'version' => $this->core->version,
[467] Fix | Delete
];
[468] Fix | Delete
[469] Fix | Delete
wp_localize_script( $this->core->name . '_map_service', 'iMapsData', $final_data );
[470] Fix | Delete
[471] Fix | Delete
}
[472] Fix | Delete
[473] Fix | Delete
/**
[474] Fix | Delete
* Add the script id to the script tag and hopefully remove async attribute added by other plugins
[475] Fix | Delete
*
[476] Fix | Delete
* @param string $script_id
[477] Fix | Delete
* @return void
[478] Fix | Delete
*/
[479] Fix | Delete
public function modify_script_tag( $script_id ) {
[480] Fix | Delete
add_filter(
[481] Fix | Delete
'script_loader_tag',
[482] Fix | Delete
function( $tag, $handle, $src ) use ( $script_id ) {
[483] Fix | Delete
[484] Fix | Delete
// check against our registered script handle
[485] Fix | Delete
if ( $script_id === $handle ) {
[486] Fix | Delete
// add attributes of your choice
[487] Fix | Delete
$tag = str_replace( 'async=\'async\'', '', $tag );
[488] Fix | Delete
}
[489] Fix | Delete
return $tag;
[490] Fix | Delete
},
[491] Fix | Delete
31, // async for WordPress plugin uses 20
[492] Fix | Delete
3
[493] Fix | Delete
);
[494] Fix | Delete
}
[495] Fix | Delete
[496] Fix | Delete
/**
[497] Fix | Delete
* Add the async attribute to script tag
[498] Fix | Delete
*
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function