– SOLVED – OK I HAVE ENDED UP WORKING WITH THIS :
<?php extract( shortcode_atts( array(
'maths' => '',
'reviews' => 'on',
), $attr )
);
if ( $reviews == 'on' ) {
$csrc = esc_url( GCP_UP_CHART_API ) . "https://drive.google.com" . "/" . esc_attr( wp_kses_post( $rev_holder ) ) . "/" . esc_attr( wp_kses_post( $maths ) );
$url_drive_yes = ( '<p style="padding-left: 100px; max-width: 680px; text-align: center; border-radius: 30px;' . $pagedisplay . '">' . $page_yes .
'<a href="https://drive.google.com/' . esc_attr( wp_kses_post( $rev_holder ) ) . '/' . esc_attr( wp_kses_post( $maths ) ) . '" target="_blank">' .
'<img style="float: none!important; max-height:680px!important; max-width:680px!important;" alt="Page Review" src="' . $csrc . '">' . '</a></p>' );
?>
<div style="float:none!important; display: inline-block; padding: 10px 10px 10px 0" onclick="process()">
<strong> <?php echo $url_drive_yes;?>
</strong>
</div>
<script>
function process() {
let text = "IMPORTANT! DO NOT CLOSE THIS WINDOWS: Confirm returning to complete the form";
if ( confirm( text ) == true ) {
return window.open( encodeURI( $url_drive_yes ) );
} else {
document.write( "Sorry! You canceled! <strong>Please wait 3s...</strong> or refresh to try again" );
event.preventDefault();
setTimeout("location.reload(true);", 3000);
}
}
</script>
–ORIGINAL POST–
I have a piece of php shortcode that is ending below as follow
extract( shortcode_atts( array(
'maths' => '',
'reviews' => 'on',
), $attr )
);
if ( $reviews == 'on' ) {
$csrc = esc_url( GCP_UP_CHART_API ) . "https://drive.google.com" . "/" . esc_attr( wp_kses_post( $rev_holder ) ) . "/" . esc_attr( wp_kses_post( $maths ) );
$url_drive_yes = ( '<p style="padding-left: 100px; max-width: 680px; text-align: center; border-radius: 30px;' . $pagedisplay . '">' . $page_yes .
'<a href="https://drive.google.com/' . esc_attr( wp_kses_post( $rev_holder ) ) . '/' . esc_attr( wp_kses_post( $maths ) ) . '" target="_blank">' .
'<img style="float: none!important; max-height:680px!important; max-width:680px!important;" alt="Page Review" src="' . $csrc . '">' . '</a></p>' );
return $url_drive_yes;
It is working as intended and the return is correctly working. But I need user to confirm their choice before to proceed. So when adding this particular windows confirm script and shortcode on any front user page everything works fine.
<button onclick="process()"> [mybill year="2022"] </button>
<p id="googleinvoice"></p>
<script>
function process() {
let text = "IMPORTANT: I confirm returning to complete the process";
if (confirm(text) == true) {
window.open("https://drive.google.com/mybill/2022/yes/");
} else {
text = "You canceled!";
}
document.getElementById("googleinvoice").innerHTML = text;
}
</script>
However, on the front user page when adding the shortcodes, I have to manually add every window confirm scripts and when there are multiples in one page it's causing conflicts in wordpress.
So I want to automatize it by wrapping the windows confirm JS script around the "return $url_drive_yes;" on the code side, so it will generate automatically the windows confirms before user proceeds. I just don't get how to insert the script in the php code and make it work and your help will be appreciated. Thank you
source https://stackoverflow.com/questions/71470631/how-to-include-php-return-values-in-window-open-script
No comments:
Post a Comment