\Gianism\ServiceGoogle

Google client

Summary

Methods
Properties
Constants
handle_analytics()
handle_save_analytics()
handle_create_table()
__get()
save_token()
save_profile()
ga_ajax()
token_url()
token_save_url()
table_create_url()
table_exists()
is_connected()
boot_auto_cron()
ga_cron()
disconnect()
set_option()
is_pseudo_mail()
parse_request()
handle_login()
profile_connect()
connection_message()
login_form()
filter_link()
button()
login_button()
connect_button()
disconnect_button()
user_can_register()
get_instance()
_()
e()
get()
post()
request()
nonce_action()
nonce_create()
nonce_field()
verify_nonce()
is_ssl_required()
is_enabled()
get_meta_owner()
get_service_instance()
$url_prefix
$verbose_service_name
$umeta_account
$umeta_plus
$crons
$message_key_name
$api
$plus
$ga_client
$ga
$ga_token
$ga_profile
$ga_accounts
$ga_table
$service_name
$enabled
$dir
$url
$all_services
$nonce_key_name
AJAX_ACTION
AJAX_TABLE
AJAX_CRON
__construct()
handle_default()
is_cron_ready()
get_api_url()
init_action()
handle_connect()
handle_disconnect()
get_redirect_to()
get_action()
filter_redirect()
get_redirect_endpoint()
is_smartphone()
hook_connect()
hook_disconnect()
user_password_unknown()
valid_username_from_mail()
api_error_string()
duplicate_account_string()
welcome()
auth_fail()
mail_fail_string()
registration_error_string()
kill_wrong_access()
test_user_can_register()
get_response()
add_message()
wp_die()
session_write()
session_get()
session_delete()
$ggl_consumer_key
$ggl_consumer_secret
$option_keys
$name
$version
$domain
N/A
get_profile()
$_api
$_plus
$_ga
$_ga_client
$instances
$_all_services
N/A

Constants

AJAX_ACTION

AJAX_ACTION

Action name

AJAX_TABLE

AJAX_TABLE

Create table action

AJAX_CRON

AJAX_CRON

Cron checker

Properties

$url_prefix

$url_prefix : string

URL prefix

If this property is empty, service name will be used. e.g. http://example.jp/facebook/

Type

string

$verbose_service_name

$verbose_service_name : string

Verbose service name

If not set, $this->service_name will be used;

Type

string

$umeta_account

$umeta_account : string

Type

string

$umeta_plus

$umeta_plus : string

Type

string

$crons

$crons : array

Cron ready classes

Type

array

$message_key_name

$message_key_name : string

Message post type

Type

string

$api

$api : \Google_Client

Type

\Google_Client

$plus

$plus : \Google_Service_Plus

Type

\Google_Service_Plus

$ga_client

$ga_client : \Google_Client

Type

\Google_Client

$ga

$ga : \Google_Service_Analytics

Type

\Google_Service_Analytics

$ga_token

$ga_token : string

Type

string

$ga_profile

$ga_profile : array

Type

array

$ga_accounts

$ga_accounts : array

Type

array

$ga_table

$ga_table : string

Type

string

$service_name

$service_name : string

Type

string

$enabled

$enabled : bool

Type

bool

$dir

$dir : string

Type

string

$url

$url : string

Type

string

$all_services

$all_services : array

Type

array

$nonce_key_name

$nonce_key_name : string

Type

string

$ggl_consumer_key

$ggl_consumer_key : string

Type

string

$ggl_consumer_secret

$ggl_consumer_secret : string

Type

string

$option_keys

$option_keys : array

Option key to retrieve

Type

array

$name

$name : string

Name

Used for option key, nonce, etc.

Type

string

$version

$version : string

Version number

Type

string

$domain

$domain : string

i18n Domain

Type

string

$_api

$_api : \Google_Client

Oauth client store

Type

\Google_Client

$_plus

$_plus : \Google_Service_Plus

Plus client

Type

\Google_Service_Plus

$_ga

$_ga : \Google_Service_Analytics

Analytics service

Type

\Google_Service_Analytics

$_ga_client

$_ga_client : \Google_Client

Analytics client

Type

\Google_Client

$instances

$instances : \Gianism\Singleton

Instance holder

Type

\Gianism\Singleton

$_all_services

$_all_services : array

All services

Type

array

Methods

handle_analytics()

handle_analytics(\WP_Query $wp_query)

Redirect to Google analytics

Parameters

\WP_Query $wp_query

handle_save_analytics()

handle_save_analytics(\WP_Query $wp_query)

Save token

Parameters

\WP_Query $wp_query

handle_create_table()

handle_create_table(\WP_Query $wp_query)

Create table

Parameters

\WP_Query $wp_query

__get()

__get(string $name) : mixed

Getter

Parameters

string $name

Returns

mixed

save_token()

save_token(string $token, bool $delete) : bool

Save token

Parameters

string $token
bool $delete

Default false.

Returns

bool

save_profile()

save_profile(string $profile) : bool

Save profile

Parameters

string $profile

Returns

bool

ga_ajax()

ga_ajax()

Ajax action

token_url()

token_url(string $redirect, bool $delete) : string

Get redirect url to get analytics token

Parameters

string $redirect
bool $delete

Default false

Returns

string

token_save_url()

token_save_url(string $redirect) : string

Get redirect url to save analytics token

Parameters

string $redirect

Returns

string

table_create_url()

table_create_url(string $redirect) : string

Table create

Parameters

string $redirect

Returns

string

table_exists()

table_exists() : bool

Detect if table exists

Returns

bool

is_connected()

is_connected(int $user_id) : bool

Detect if user is connected to this service

Parameters

int $user_id

Returns

bool

boot_auto_cron()

boot_auto_cron()

Register cron automatically

ga_cron()

ga_cron()

Google analytics cron check

disconnect()

disconnect(int $user_id) : mixed

Disconnect user from this service

Parameters

int $user_id

Returns

mixed

set_option()

set_option() : void

Setup default option

is_pseudo_mail()

is_pseudo_mail(string $mail) : bool

This controller reutrn always false

Parameters

string $mail

Returns

bool

parse_request()

parse_request(string $action, \WP_Query $wp_query) : void

Called on redirect endpoint

Parameters

string $action
\WP_Query $wp_query

handle_login()

handle_login(\WP_Query $wp_query)

Make user login

Parameters

\WP_Query $wp_query

profile_connect()

profile_connect(\WP_User $user) : void

Show connect button on profile page

Parameters

\WP_User $user

connection_message()

connection_message(string $context) : string

Connection message

Overriding this function, you can customize connection message

Parameters

string $context

Returns

string

login_form()

login_form(boolean $is_register) : void

Display login buttons

Parameters

boolean $is_register

filter_link()

filter_link(string $markup, string $href, string $text, bool $is_register) : string

Resturns link to filter

Parameters

string $markup
string $href
string $text
bool $is_register

Returns

string

button()

button(string $text, string $href, bool $icon_name, array $class_names, array $attributes) : string

Create common button

Parameters

string $text
string $href
bool $icon_name
array $class_names
array $attributes

Returns

string

login_button()

login_button(string $redirect, bool $register) : string

Show login button

Parameters

string $redirect
bool $register

Returns

string

connect_button()

connect_button(string $redirect_to) : string

Get connect button

Parameters

string $redirect_to

If not set, profile page's URL

Returns

string

disconnect_button()

disconnect_button(string $redirect_to) : string

Get disconnect button

Parameters

string $redirect_to

If not set, profile page's URL

Returns

string

user_can_register()

user_can_register() : bool

Detect if user can register

Returns

bool

get_instance()

get_instance(array $argument) : self

Get instance

Parameters

array $argument

Returns

self

_()

_(string $string) : string

Alias of __

Parameters

string $string

Returns

string

e()

e(string $string)

Alias of _e

Parameters

string $string

get()

get(string $key) : mixed

Return $_GET

Parameters

string $key

Returns

mixed

post()

post(string $key) : mixed

Return $_POST

Parameters

string $key

Returns

mixed

request()

request(string $key) : mixed

return $_REQUEST

Parameters

string $key

Returns

mixed

nonce_action()

nonce_action(string $action) : string

Return nonce name with prefix

Parameters

string $action

Returns

string

nonce_create()

nonce_create(string $action) : string

Parameters

string $action

Returns

string

nonce_field()

nonce_field(string $action, bool $referrer)

Alias of wp_nonce_field

Parameters

string $action
bool $referrer

Default false.

verify_nonce()

verify_nonce(string $action, string $referrer) : boolean

Check nonce

Parameters

string $action
string $referrer

Returns

boolean

is_ssl_required()

is_ssl_required() : boolean

Returns if login is forced to use SSL.

To override it, use filter gianism_force_ssl_login

Returns

boolean

is_enabled()

is_enabled(string $service) : bool

Determine if service is enabled.

Parameters

string $service

If not specified, one of the services are enabled, return true.

Returns

bool

get_meta_owner()

get_meta_owner(string $key, string $value) : int

Retrieve user meta's owner ID

Parameters

string $key
string $value

Returns

int —

User ID. If not exists, return 0

get_service_instance()

get_service_instance(string $service) : null|\Gianism\Service\Common\Mail

Get service instance

Parameters

string $service

Returns

null|\Gianism\Service\Common\Mail

__construct()

__construct(array $argument)

Constructor

Parameters

array $argument

handle_default()

handle_default(string $action) : void

Handle callback request

This function must exit at last.

Parameters

string $action

is_cron_ready()

is_cron_ready(string $class_name) : bool

Detect if subclass is ready

Parameters

string $class_name

Returns

bool

get_api_url()

get_api_url(string $action) : string|false

Return api URL to authenticate

If you need additional information (ex. token), use $this->session_write inside.

$this->session_write('token', $token); return $url;

Parameters

string $action

'connect', 'login'

Throws

\Exception

Returns

string|false —

URL to redirect

init_action()

init_action() : void

Initialize

If some stuff is required, override this.

handle_connect()

handle_connect(\WP_Query $wp_query)

Handle connect

Parameters

\WP_Query $wp_query

handle_disconnect()

handle_disconnect(\WP_Query $wp_query)

Handle disconnect

Parameters

\WP_Query $wp_query

get_redirect_to()

get_redirect_to(string $default, array $args) : string

Returns redirect to url if set.

Parameters

string $default
array $args

Returns

string

get_action()

get_action() : string

Returns current action name.

Returns

string

filter_redirect()

filter_redirect(string $url, string $context) : string

Filter redirect URL

Parameters

string $url
string $context

login, connect, disconnect

Returns

string

get_redirect_endpoint()

get_redirect_endpoint(string $action, string $nonce_key, array $args) : string

Get URL for immediate endpoint.

Parameters

string $action

'connect', 'disconnect', 'login' or else.

string $nonce_key

If empty, nonce won't be set.

array $args

Returns

string

is_smartphone()

is_smartphone() : boolean

Detect if current client is smartphone.

Returns

boolean

hook_connect()

hook_connect(int $user_id, mixed $data, bool $on_creation)

Fires connect hook

Parameters

int $user_id
mixed $data
bool $on_creation

hook_disconnect()

hook_disconnect(mixed $user_id)

Fires disconnect hook

Parameters

mixed $user_id

user_password_unknown()

user_password_unknown(int $user_id)

Use's password is automatically generated

Parameters

int $user_id

valid_username_from_mail()

valid_username_from_mail(string $email) : string

Create valid username from email address

Parameters

string $email

Throws

\Exception

Returns

string

api_error_string()

api_error_string() : string

Returns API error string

Returns

string

duplicate_account_string()

duplicate_account_string() : string

Message account duplication

Returns

string

welcome()

welcome(string $who)

Add welcome message

Parameters

string $who

auth_fail()

auth_fail(string $message)

Add error message

Parameters

string $message

mail_fail_string()

mail_fail_string() : string

Add error message

Returns

string

registration_error_string()

registration_error_string() : string

Registration error string

Returns

string

kill_wrong_access()

kill_wrong_access()

Kill wrong access

test_user_can_register()

test_user_can_register() : bool

Test if can register.

Throws

\Exception

Returns

bool

get_response()

get_response(string $endpoint, string|array $request, string $method, bool $json, array $additional_headers) : array|\stdClass|bool|null

Get Request

Parameters

string $endpoint
string|array $request
string $method

If x-www-form-urlencoded required, pass array or else, pass query string.

bool $json

if this request is JSON

array $additional_headers

Additional headers.

Returns

array|\stdClass|bool|null

add_message()

add_message(string $string, bool $error)

Add message to show

Parameters

string $string
bool $error

wp_die()

wp_die(string $message, int $status_code, bool $return)

Short hand for wp_die

Parameters

string $message
int $status_code
bool $return

session_write()

session_write(string $key, mixed $value)

Write session

Parameters

string $key
mixed $value

session_get()

session_get(string $key) : bool

Get session

After get, session key will be deleted.

Parameters

string $key

Returns

bool

session_delete()

session_delete(string $key)

Delete session

Parameters

string $key

get_profile()

get_profile() : \Google_Service_Oauth2_Userinfo

Returns Profile

Returns

\Google_Service_Oauth2_Userinfo