WordPress-Plugin-Boilerplate icon indicating copy to clipboard operation
WordPress-Plugin-Boilerplate copied to clipboard

How to get instance of variables?

Open mastmaster opened this issue 6 years ago • 2 comments

Hi, In this file iben-woocommerce-bank-options.php How can i get the plugin name after below function is fire?

function run_iben_woocommerce_bank_options() {

	$plugin = new Iben_Woocommerce_Bank_Options();
	$plugin->run();

}
run_iben_woocommerce_bank_options();

For example $plugin->get_plugin_name(); or $this->get_plugin_name() is not working

Thanks

mastmaster avatar Oct 25 '18 14:10 mastmaster

is this right?


function run_iben_woocommerce_bank_options() {
	$plugin = new Iben_Woocommerce_Bank_Options();	
	$plugin->run();	
}
run_iben_woocommerce_bank_options();
	

/**
 * Check if WooCommerce is activated
 */
add_action( 'plugins_loaded', 'checkWOO' );

function checkWOO(){
	if ( class_exists( 'woocommerce' ) ) { 
	
	} else { 
		add_action( 'admin_notices', 'errormsg' );
	}
}

GET INSTANCE AGAIN

$plugin_instance = new Iben_Woocommerce_Bank_Options();

$plugin_name = $plugin_instance->get_plugin_name();

	
if ( ! function_exists( 'errormsg' ) ) {
	
	function errormsg($plugin_name) {
		global $plugin_name;
	    $class = 'notice notice-error';
	    $message = sprintf( __( 'Error you did not meet the WP minimum version. %s', 'text-domain' ), $plugin_name);
	    printf( '<div class="%1$s"><p>%2$s</p></div>', $class, $message );
	}
	
}

mastmaster avatar Oct 25 '18 15:10 mastmaster

Hi,

I'm a learning now. If I'm saying some crazy thing you guys can correct me.

What's is the debug of $plugin_instance? If the object is returned you need to check if the function get_plugin_name has protected or private type. If the method has those types you need to change or create a new function to have access and use.

If nothing is returned in $plugin_instance you need to check if your function is being fired before the class load.

rafaelluz-f avatar Oct 25 '18 16:10 rafaelluz-f