How to call a PHP function in WordPress when you click on a button?

How to process the textarea field with the standard WordPress function wpautop() when clicking the button?

Here's the form:

textarea id="my_ta"Lorem ipsum!/textarea
button id="button_processing_ta"Обработать/button

Here's the handler (to function.php):

?php
  function my_action_javascript() { ?
    script
      document.getElementById( 'button_processing_ta' ).addEventListener( 'click', function() {
        let my_ta = document.getElementById( 'my_ta' );

        // ???
        wpautop( my_ta.value );
      });
    /script
  ?php }

  add_action( 'admin_print_footer_scripts', 'my_action_javascript', 99 );
?

Sorry for my English...

Topic wp-autop Wordpress

Category Web


Take a look at AJAX in Plugins which uses admin-ajax.php. This is a way for you to interact with WordPress via a javascript request to WordPress.

About

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