Calling plugin function inside custom plugin for onclick event

I want testFunction() to call check() that i created in my plugin php when i click My Button. How do i make it work ?

?php
function createButton()
{
    echo 'button onclick="testFunction()"My Button/button';
}

function check()
{
    alert("Works");
}

function my_php_function()
{
    echo 'script
    function testFunction() {
      check();
    }
  /script';
}
add_action( 'wp_footer', 'my_php_function' );

Topic functions actions events hooks plugins Wordpress

Category Web


I could not stand by and see that mangled code. Here is what I think you meant to do.

<?php
function createButton()
{
    echo '<button onclick="testFunction()">My Button</button>';
}

function my_php_function()
{
    echo '<script>
    function check()
    {
        alert("Works");
    }
    function testFunction() {
      check();
    }
  </script>';
}
add_action( 'wp_footer', 'my_php_function' );

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.