Is there a way to add inline php code to the editor using wp_print_scripts
? I'm trying to find a way to display text from a php string into a value of input of a block.
Here's my code:
function shapeSpace_print_scripts() {
?>
<?php $block_yt_url = 'test';?>
<script>
jQuery(document).ready(function ($) {
let $yt_url = false;
$(document).on( "click", '#yt_run .acf-button-group', function() {
$(".editor-post-publish-button__button").hide();
$(".acf-block-body div div.acf-block-fields.acf-fields div.acf-field.acf-field-text.acf-field-6260f423f1666").css({'height':'inherit','padding':'16px 20px','overflow':'inherit'});
$(".acf-block-body div div.acf-block-fields.acf-fields div.acf-field.acf-field-text.acf-field-6260f423f1666").val(<?php echo $block_yt_url;?>);
$('#yt_url .acf-input input').keyup(function(e) {
if(e.keyCode == 13) {
$yt_url = true;
};
if(e.keyCode == 46) {
$yt_url = true;
};
if(e.keyCode == 8) {
$yt_url = true;
};
checkStatus();
});
});
function checkStatus(){
if($yt_url) {
$(".editor-post-publish-button__button").show();
}
}
});
</script>
<?php
}
add_action('wp_print_scripts', 'shapeSpace_print_scripts');
wp_add_inline_script
?wp_add_inline_script
doesn't.wp_add_inline_script
lets you enqueue an inline script so you don't have to manually hardcode the script tag yourself, but it still gets printed in the correct order, and only when the script you need it in is enqueued. The second parameter is the text that goes inside the script tag