I am developing a WP plugin called e.g. DD_Awesome_Plugin and this is my code so far (simplified version without additional code logic within class functions):
class DD_Awesome_PLugin {
public function __construct()
{
}
public function add_menu_page()
{
add_options_page('DD Awesome PLugin', 'DD Awesome PLugin', 'administrator', __FILE__, array('DD_Awesome_PLugin', 'display_options_page'));
}
public function display_options_page()
{
$plugin_options = get_option('dd_my_awesome_plugin');
echo "Here we go admin!";
/* and after echo I need to triger a function "trigger_me_from_class()" that is located outside of the class. */
}
}
add_action('admin_menu', function() {
DD_Awesome_PLugin::add_menu_page();
});
add_action('admin_init', function() {
new DD_Awesome_PLugin();
include_once dirname(__FILE__) . ('/simple_html_dom.php');
});
/* just trigger this function "trigger_me_from_class" from "display_options_page" function (situated in DD_Awesome_plugin class above) */
public function trigger_me_from_class()
{
$str = date('Y-m-d H:i:s', time());
wp_mail('info@example.com', 'DD success message', "Success at $str." );
}
Create a static getter for your class instance:
And now you get the plugin instance with:
Or: