WC_REST_WCCOM_Site_Controller::check_permission
Check permissions.
Please note that access to this endpoint is also governed by the WC_WCCOM_Site::authenticate_wccom() method.
Метод класса: WC_REST_WCCOM_Site_Controller{}
Хуки из метода
Возвращает
bool|WP_Error.
Использование
$WC_REST_WCCOM_Site_Controller = new WC_REST_WCCOM_Site_Controller(); $WC_REST_WCCOM_Site_Controller->check_permission();
Список изменений
| С версии 7.8.0 | Введена. |
Код WC_REST_WCCOM_Site_Controller::check_permission() WC REST WCCOM Site Controller::check permission WC 11.2.2
public function check_permission() {
$current_user = wp_get_current_user();
if ( empty( $current_user ) || ( $current_user instanceof WP_User && ! $current_user->exists() ) ) {
/**
* This filter allows to provide a custom error message when the user is not authenticated.
*
* @since 3.7.0
*/
$error = apply_filters(
WC_WCCOM_Site::AUTH_ERROR_FILTER_NAME,
new Installer_Error( Installer_Error_Codes::NOT_AUTHENTICATED )
);
return new WP_Error(
$error->get_error_code(),
$error->get_error_message(),
array( 'status' => $error->get_http_code() )
);
}
if ( ! $this->user_has_permission( $current_user ) ) {
$error = new Installer_Error( Installer_Error_Codes::NO_PERMISSION );
return new WP_Error(
$error->get_error_code(),
$error->get_error_message(),
array( 'status' => $error->get_http_code() )
);
}
return true;
}