WP_Abilities_Registry::get_instancepublic staticWP 6.9.0

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

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

Method of the class: WP_Abilities_Registry{}

Hooks from the method

Returns

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

Usage

$result = WP_Abilities_Registry::get_instance(): ?self;

Changelog

Since 6.9.0 Introduced.

WP_Abilities_Registry::get_instance() code WP 7.0

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;
}