Created
April 13, 2022 22:28
-
-
Save wpmudev-sls/2745a06923eeada579703e990dddff24 to your computer and use it in GitHub Desktop.
[WPMU DEV] Prevents PayPal Inputs Zoom
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: [WPMU DEV] Prevents PayPal Inputs Zoom | |
* Plugin URI: https://wpmudev.com/ | |
* Description: Chrome mobile has a bug that auto zooms the screen when you select an input field from an embed page - EG.: the iFrame used by the PayPal checkout. This plugin is a workaround for this situation. | |
* Author: Glauber Silva @ WPMUDEV | |
* Author URI: https://wpmudev.com/ | |
* Task: SLS-3307 | |
* License: GPLv2 or later | |
* | |
* @package WPMU_DEV_Prevents_PayPal_Inputs_Zoom | |
*/ | |
defined( 'ABSPATH' ) || exit; | |
add_action( | |
'wp_footer', | |
function() { | |
?> | |
<script type="text/javascript"> | |
function readyHandler() { | |
if ( navigator.userAgentData.mobile ) { | |
var scalable = true; | |
var observer = new MutationObserver(function(mutations, observer) { | |
//console.log(mutations, observer); | |
setTimeout( function(){ | |
var PayPal = document.querySelector("iframe[title=PayPal]"); | |
if ( !! PayPal && scalable ) { | |
var viewport = document.querySelector("meta[name=viewport]"); | |
if ( !! viewport ) { | |
viewport.setAttribute('content', 'width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0'); | |
} else { | |
var metaTag=document.createElement('meta'); | |
metaTag.name = "viewport" | |
metaTag.content = "width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" | |
document.getElementsByTagName('head')[0].appendChild(metaTag); | |
} | |
scalable = false; | |
} | |
}, 100 ); | |
}); | |
observer.observe(document, { | |
subtree: true, | |
attributes: true | |
}); | |
} | |
} | |
// Check if the DOMContentLoaded has already been completed | |
if ( document.readyState !== 'loading' ) { | |
readyHandler(); | |
} else { | |
document.addEventListener( 'DOMContentLoaded', readyHandler ); | |
} | |
</script> | |
<?php | |
}, | |
9999 | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment