Accessing core Google configuration
Filter: gal_gather_scopes
The Login plugin applies this filter to allow your extension to instruct it to obtain extra Google authorization scopes (permissions) when users login to via Google. For example, you can tell the Login plugin to ask for authorization to access the user’s Drive, in addition to the profile permissions it always asks for.
Params:
$scopes – Array of scopes from other plugins.
Return:
Array of scopes, adding your own scopes first if needed. Do not worry about potential duplicates – the plugin takes care of that.
Example:
function my_gather_scopes($scopes) { return array_merge($scopes, Array('https://www.googleapis.com/auth/drive.readonly', 'https://www.googleapis.com/auth/drive.file'); } add_filter('gal_gather_scopes', 'my_gather_scopes' );
Filter: gal_get_clientid
This is a filter implemented by the Login plugin that your extension might call. Your extension is unlikely to implement this filter itself, but may want to make use of its return value.
This obtains the Google Cloud Console Project’s Client ID from the Login plugin – the Client ID is the code that the admin enters when they first set up the Login plugin.
You may want to pass this to your own Javascript code in order to call Google APIs on the browser. The Drive plugin does this – see its source code.
Params:
Empty string (ignored)
Returns:
String containing Client ID or empty string if Login plugin is not yet configured.
Example:
$clientid = apply_filters('gal_get_clientid', '');
Filter: gal_client_config_ini
The Login plugin applies this filter to allow your extension to specify a filesystem path to an INI file OR a GoogleGAL_Config object to pass to Google’s client library on instantiation
Params:
None
Return:
String – full filesystem path to your INI file. See client library source code in core/Google/Client.php to understand the format and options for this INI file.
GoogleGAL_Config object – an instance of this config object class.
Null – default, don’t pass any configuration file.
Example 1 – config in an ini-file instructing Google client library to not cache requests in the filesystem at all:
function my_client_config_ini($inipath) { if (!class_exists('GoogleGAL_Cache_Null')) { require_once '/var/www/~username/wp/wp-content/plugins/googleappslogin-enterprise/core/Google/Cache/Null.php'; /* <--- you will need to enter the full path here */ } return '/var/ini/my_google_client_library_settings.ini'; } add_filter('gal_client_config_ini', 'my_client_config_ini', 10, 1);
And the my_google_client_library_settings.ini file would contain just one line:
cache_class = GoogleGAL_Cache_Null
Example 2 - providing a custom config object that supplies Proxy options for calling the Google servers:
function my_client_config_ini($inipath) { if (!class_exists('GoogleGAL_Config') || !class_exists('GoogleGAL_IO_Curl')) { return $inipath; } if (!class_exists('GoogleGAL_IO_Curl_My')) { class GoogleGAL_IO_Curl_My extends GoogleGAL_IO_Curl { public function __construct(GoogleGAL_Client $client) { parent::__construct($client); $this->setOptions(array( CURLOPT_PROXY => 'https://proxy.url/', CURLOPT_PROXYUSERPWD => 'userpwd' )); } } } $conf = new GoogleGAL_Config(); $conf->setIoClass('GoogleGAL_IO_Curl_My'); return $conf; } add_filter('gal_client_config_ini', 'my_client_config_ini', 10, 1);