GC_HTTP_Requests_Hooks::dispatch()

最后更新于:2021-12-01 11:11:58

GC_( string$hook, array$parameters=array())

Dispatch a Requests hook to a native GeChiUI action.

参数

$hook

(string) (Required) Hook name.

$parameters

(array) (Optional) 参数 to pass to callbacks.

Default value: array()

响应

(bool) True if hooks were run, false if nothing was hooked.

源文件

文件: gc-includes/class-gc-http-requests-hooks.php

	public function dispatch( $hook, $parameters = array() ) {
		$result = parent::dispatch( $hook, $parameters );

		// Handle back-compat actions.
		switch ( $hook ) {
			case 'curl.before_send':
				/** This action is documented in gc-includes/class-gc-http-curl.php */
				do_action_ref_array( 'http_api_curl', array( &$parameters[0], $this->request, $this->url ) );
				break;
		}

		/**
		 * Transforms a native Request hook to a GeChiUI action.
		 *
		 * This action maps Requests internal hook to a native GeChiUI action.
		 *
		 * @see https://github.com/rmccue/Requests/blob/master/docs/hooks.md
		 *
		 * @since 4.7.0
		 *
		 * @param array $parameters 参数 from Requests internal hook.
		 * @param array $request Request data in GC_Http format.
		 * @param string $url URL to request.
		 */
		do_action_ref_array( "requests-{$hook}", $parameters, $this->request, $this->url ); // phpcs:ignore GeChiUI.NamingConventions.ValidHookName.UseUnderscores

		return $result;
	}