I am developing a plugin for woocommerce payment gateway.
When I put the code of class definition inside the callback function who is fired by 'plugins_loaded',it works.
<?php
add_action('plugins_loaded','WC_test_gateway_plugin');
function WC_test_gateway_plugin{
class my_gateway extends WC_Payment_Gateways{
//code
}
}
?>
But when I put it into global scope, it will show that the WC_Payment_Gateways is undefined.
<?php
class my_gateway extends WC_Payment_Gateways{
//code
}
?>
What's the difference between these 2 practices?
Is it a bad practice to put class definition inside callback function? Any better way for it?
plugins_loaded
is meant to be used here, and you should make a file formy_gateway
class andinclude
it in yourWC_test_gateway_plugin
callback. – Ismail Feb 10 '17 at 11:46