why does add_action or add_shortcode not create an instance of a class
-
I wanted to create an instance of a class when my program start add_shortcode(), but I find it not worked.
Does anyone can help me solve this problem?
The following is my code:class Test{ private $infos; function get_info() { if ( isset($_REQUEST['my_info']) ) { $infos = $_REQUEST['my_info']; if (get_option('my_url')){ update_option('my_url', $infos); }else{ add_option('my_url', $infos); } } die(); } function salcodes_year() { echo plugin_dir_url(__FILE__) . 'src/my_test1.php'; require_once plugin_dir_url(__FILE__) . 'src/my_test1.php'; $my_crawler = new Test_one($infos); return get_option('my_url'); } function js2php_register(){ add_action( 'wp_ajax_crawler_info', array($this, 'get_info') ); add_action( 'wp_ajax_nopriv_crawler_info', array($this, 'get_info') ); add_shortcode( 'current_year', array($this, 'salcodes_year') ); } } $test = new Test; $test->js2php_register();
Through my testing I found no matter how do I put these code,
require_once plugin_dir_url(__FILE__) . 'src/my_test1.php';
&$my_crawler = new Test_one($infos);
, in the function ofadd_shortcode()
oradd_action('wp_ajax_')
both are not work…Does anyone help me, Please
Thanks
Viewing 11 replies - 1 through 11 (of 11 total)
Viewing 11 replies - 1 through 11 (of 11 total)
- The topic ‘why does add_action or add_shortcode not create an instance of a class’ is closed to new replies.