Am I using the correct do_action to add my own extension to Anspress plugin?

3.89K viewsCore
0

This is found in anspress-question-answer.php. I see that there is a ” do_action(‘anspress_loaded’); “. Is this what I use to add my own extension (similar to your categories-for-anspress extension)? I’m asking because I don’t think categories-for-anspress extension is using this…

 

/**
* Initializes the plugin by setting localization, hooks, filters, and administrative functions.
* @return instance
*/
public static function instance()
{
if (! isset(self::$instance) && ! (self::$instance instanceof AnsPress)) {
self::$instance = new AnsPress();
self::$instance->_setup_constants();

add_action('plugins_loaded', array( self::$instance, 'load_textdomain' ));


add_action('bp_loaded', array( self::$instance, 'bp_include' ));

global $ap_classes;
$ap_classes = array();

self::$instance->includes();

self::$instance->anspress_forms = new AnsPress_Process_Form();
self::$instance->anspress_actions = new AnsPress_Actions();
self::$instance->anspress_ajax = new AnsPress_Ajax();
self::$instance->anspress_query_filter = new AnsPress_Query_Filter();
self::$instance->anspress_theme = new AnsPress_Theme();
self::$instance->anspress_cpt = new AnsPress_PostTypes();
self::$instance->anspress_reputation = new AP_Reputation();
self::$instance->anspress_users = new AnsPress_User();
///self::$instance->third_party = new AnsPress_3rd_party();

/**
* ACTION: anspress_loaded
* Hooks for extension to load their codes after AnsPress is leaded
*/
do_action('anspress_loaded');
}

return self::$instance;
}
1

Sure why not? If you don’t need to hook to anything specific.

I ask because categories-for-anspress uses ‘plugins_loaded’…so why the difference?

I assume Anspress hooks there so they can override plugins, possibly their other plugins. Could be other possibilities too, plugins_loaded loads before setup_theme, after_setup_theme, and init.

$discounts is a new instance, but they did not use it, so maybe its for a future purpose…

Really all that matter is you hook where you need to hook to accomplish your specific task. Hooks provide lots of alternatives and there’s many ways to approach things.