Base controller class

package GlotPress

 Methods

__construct()

__construct() 

after_request()

after_request() 

before_request()

before_request() 

Checks whether a user is allowed to do an action.

can(string $action, string|null $object_type = null, integer|null $object_id = null, array|null $extra = null) : boolean
since 2.3.0 Added the `$extra` parameter.

Parameters

$action

string

The action.

$object_type

stringnull

Optional. Type of an object. Default null.

$object_id

integernull

Optional. ID of an object. Default null.

$extra

arraynull

Optional. Extra information for deciding the outcome.

Returns

booleanThe verdict.

Determines whether a user can perfom an action and redirects in case of a failure.

can_or_forbidden(string $action, string|null $object_type = null, integer|null $object_id = null, string|null $message = null, array|null $extra = null) : false
since 1.0.0

Parameters

$action

string

The action.

$object_type

stringnull

Optional. Type of an object. Default null.

$object_id

integernull

Optional. ID of an object. Default null.

$message

stringnull

Error message in case of a failure. Default: 'You are not allowed to do that!'.

$extra

arraynull

Pass-through parameter to can().

Returns

false

Redirects and exits if the current user isn't allowed to do an action.

cannot_and_redirect(string $action, string|null $object_type = null, integer|null $object_id = null, string|null $url = null) : boolean
since 1.0.0

Parameters

$action

string

The action.

$object_type

stringnull

Optional. Type of an object. Default null.

$object_id

integernull

Optional. ID of an object. Default null.

$url

stringnull

Optional. URL to redirect to. Default: referrer or index page, if referrer is missing.

Returns

booleanWhether a redirect happened.

die_with_404()

die_with_404($args = array()

Parameters

$args

die_with_error()

die_with_error($message, $status = 500

Parameters

$message

$status

exit_()

exit_($message = 0

Parameters

$message

header()

header($string) 

Parameters

$string

Sets HTTP headers for content download.

headers_for_download(string $filename, string $last_modified = ''

Parameters

$filename

string

The name of the file.

$last_modified

string

Optional. Date when the file was last modified. Default: ''.

Same as validate(), but redirects to $url if the thing isn't valid.

invalid_and_redirect(object $thing, string $url = null) : boolean

Note: this method calls $this->exit_() after the redirect and the code after it won't be executed.

Parameters

$thing

object

a GP_Thing instance to validate

$url

string

where to redirect if the thing doesn't validate

Returns

booleanwhether the thing is valid

Verifies a nonce for a route and redirects in case the nonce is invalid.

invalid_nonce_and_redirect(string $action, string|null $url = null) : boolean
since 2.0.0

Parameters

$action

string

Context for the created nonce.

$url

stringnull

The URL to redirect. Default: 'null', the referrer.

Returns

booleanFalse if the nonce is valid, true if the redirect has happened.

logged_in_or_forbidden()

logged_in_or_forbidden() 

redirect()

redirect($url = null

Parameters

$url

redirect_with_error()

redirect_with_error($message, $url = null

Parameters

$message

$url

set_notices_and_errors()

set_notices_and_errors() 

status_header()

status_header($status) 

Parameters

$status

Loads a template.

tmpl(string $template, array $args = array(), boolean|string $honor_api = true

Parameters

$template

string

Template name to load.

$args

array

Associative array with arguements, which will be exported in the template PHP file.

$honor_api

booleanstring

If this is true or 'api' and the route is processing an API request the template name will be suffixed with .api. The actual file loaded will be template.api.php.

Validates a thing and add its errors to the route's errors.

validate(object $thing) : boolean

Parameters

$thing

object

a GP_Thing instance to validate

Returns

booleanwhether the thing is valid

Verifies a nonce for a route.

verify_nonce(string $action) : boolean
since 2.0.0

Parameters

$action

string

Context for the created nonce.

Returns

booleanFalse if the nonce is invalid, true if valid.

Retrieves referer from '_wp_http_referer' or HTTP referer.

get_http_referer() : false | string

Unlike wp_get_referer(), it doesn't check if the referer is the same as the current request URL.

since 2.0.0

Returns

falsestringFalse on failure. Referer URL on success.

 Properties

 

$api

$api 

Default

false
 

$class_name

$class_name 

Default

 

$errors

$errors 

Default

array()
 

$exit_message

$exit_message 

Default

 

$exited

$exited 

Default

false
 

$fake_request

$fake_request 

Default

false
 

$headers

$headers 

Default

array()
 

$http_status

$http_status 

Default

 

$last_method_called

$last_method_called 

Default

 

$loaded_template

$loaded_template 

Default

null
 

$notices

$notices 

Default

array()
 

$redirected

$redirected 

Default

false
 

$redirected_to

$redirected_to 

Default

null
 

$rendered_template

$rendered_template 

Default

false
 

$request_running

$request_running 

Default

false
 

$template_output

$template_output 

Default

null
 

$template_path

$template_path 

Default

null