Automattic\WooCommerce\Admin\Marketing

MarketingChannels{} │ WC 7.4.0

MarketingChannels repository class

Хуки из класса

Использование

$MarketingChannels = new MarketingChannels();
// use class methods

Методы

  1. public get_registered_channels()
  2. public register( MarketingChannelInterface $channel )
  3. public unregister_all()
  4. ERROR: no method name found on line ``
  5. ERROR: no method name found on line ``
  6. ERROR: no method name found on line ``
  7. ERROR: no method name found on line ``

Список изменений

С версии 7.4.0 Введена.

Код MarketingChannels{} WC 11.3.0

class MarketingChannels {
	/**
	 * The registered marketing channels.
	 *
	 * @var MarketingChannelInterface[]
	 */
	private $registered_channels = [];

	/**
	 * Registers a marketing channel.
	 *
	 * @param MarketingChannelInterface $channel The marketing channel to register.
	 *
	 * @return void
	 *
	 * @throws Exception If the given marketing channel is already registered.
	 */
	public function register( MarketingChannelInterface $channel ): void {
		if ( isset( $this->registered_channels[ $channel->get_slug() ] ) ) {
			throw new Exception( __( 'Marketing channel cannot be registered because there is already a channel registered with the same slug!', 'woocommerce' ) );
		}

		$this->registered_channels[ $channel->get_slug() ] = $channel;
	}

	/**
	 * Unregisters all marketing channels.
	 *
	 * @return void
	 */
	public function unregister_all(): void {
		unset( $this->registered_channels );
	}

	/**
	 * Returns an array of all registered marketing channels.
	 *
	 * @return MarketingChannelInterface[]
	 */
	public function get_registered_channels(): array {
		/**
		 * Filter the list of registered marketing channels.
		 *
		 * @param MarketingChannelInterface[] $channels Array of registered marketing channels.
		 *
		 * @since 7.4.0
		 */
		$channels = apply_filters( 'woocommerce_marketing_channels', $this->registered_channels );

		return array_values( $channels );
	}
}