Validating ajax search

Is there a way to prevent user from entering script tag to the form? Yes, escaping. It is one of the fundamental cornerstones of web security, and completely missing from the code in the question. Take this example: <a href=”<?php echo $foo; ?>”> How do we know it’s actually a URL? Your colleague has said … Read more

Executing php on button press

Php is a server-side language. Meaning the code is executed and the user will receive the compiled html code. The only way to execute php code as user is through ‘post’ or ‘get’ requests. So essentially loading a new page. The only workaround is using ajax to load new php code dynamically. But it may … Read more

Multiple TinyMCE on button click is initialized and appended but why only last one is writeable?

Ok, with many hours of debugging and I finally came to know why it was not working. So everything is supposed to work the way it should be but there was a minor mistake in my JavaScript. Previous JavaScript var counter = 1; document.getElementById(‘add_more_content_block’).addEventListener(‘click’, function(e) { e.preventDefault(); var editor_id = “editor_”+counter; document.getElementById(‘add_content_box’).innerHTML += `<div class=”wp-`+editor_id+`-editor-container”> … Read more

How to add JS script in specific pages in WordPress?

If you’re using IDs for is_page() you should pass them as integers, not strings. Otherwise WordPress is looking for pages with a slug of “3854”, not a page with that ID. So instead of: if ( is_page( array( ‘3854’, ‘253’ ) ) ) {} Use: if ( is_page( array( 3854, 253 ) ) ) {}