how to share the variable to different function on the same class
-
I want to print what I input in wordpress, but I still not get the variable from different function in the same class
The following is my code:class Test{ private $infos; function get_info() { if ( isset($_REQUEST['my_info']) ) { $this->infos = $_REQUEST['my_info']; echo 'your input is:'.$this->infos; } // Always die in functions echoing ajax content or it will display 0 or another word // die(); } function salcodes_year() { echo 'the data is:'.$this->var; return $this->var; } function js2php_register(){ add_action( 'wp_ajax_test_info', array($this, 'get_info') ); add_action( 'wp_ajax_nopriv_test_info', array($this, 'get_info') ); add_shortcode( 'current_year', array($this, 'salcodes_year') ); } } $test = new Test; $test->js2php_register();
Version:
WordPress 5.8.2
PHP 7.4.27
MySQL 5.7.37 Community Server (GPL)Help me, please!
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘how to share the variable to different function on the same class’ is closed to new replies.