WP_Abilities_Registry::get_instance(): WP_Abilities_Registry|null

In this article

Utility method to retrieve the main instance of the registry class.

Description

The instance will be created if it does not exist yet.

Return

WP_Abilities_Registry|null The main registry instance, or null when init action has not fired.

Source

public static function get_instance(): ?self {
	if ( ! did_action( 'init' ) ) {
		_doing_it_wrong(
			__METHOD__,
			sprintf(
				// translators: %s: init action.
				__( 'Ability API should not be initialized before the %s action has fired.' ),
				'<code>init</code>'
			),
			'6.9.0'
		);
		return null;
	}

	if ( null === self::$instance ) {
		self::$instance = new self();

		// Ensure ability category registry is initialized first to allow categories to be registered
		// before abilities that depend on them.
		WP_Ability_Categories_Registry::get_instance();

		/**
		 * Fires when preparing abilities registry.
		 *
		 * Abilities should be created and register their hooks on this action rather
		 * than another action to ensure they're only loaded when needed.
		 *
		 * @since 6.9.0
		 *
		 * @param WP_Abilities_Registry $instance Abilities registry object.
		 */
		do_action( 'wp_abilities_api_init', self::$instance );
	}

	return self::$instance;
}

Hooks

do_action( ‘wp_abilities_api_init’, WP_Abilities_Registry $instance )

Fires when preparing abilities registry.

Changelog

VersionDescription
6.9.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.