Yoast\WP\SEO\Abilities\Infrastructure
Indexable_Access_Checker::ensure_can_edit
Ensures the current user may edit the object behind the given indexable.
Метод класса: Indexable_Access_Checker{}
Хуков нет.
Возвращает
true|WP_Error. True when the object is editable, or a 403 error.
Использование
$Indexable_Access_Checker = new Indexable_Access_Checker(); $Indexable_Access_Checker->ensure_can_edit( $indexable );
- $indexable(Indexable) (обязательный)
- The post or term indexable.
Код Indexable_Access_Checker::ensure_can_edit() Indexable Access Checker::ensure can edit Yoast 28.9
public function ensure_can_edit( Indexable $indexable ) {
$is_term = ( $indexable->object_type === 'term' );
$capability = ( $is_term ) ? 'edit_term' : 'edit_post';
if ( \current_user_can( $capability, (int) $indexable->object_id ) ) {
return true;
}
// Mirrors WP core's rest_cannot_edit wording, with a whole sentence per type so it can be translated.
if ( $is_term ) {
return new WP_Error(
'yoast_seo_cannot_edit_term',
\__( 'Sorry, you are not allowed to edit this term.', 'wordpress-seo' ),
[ 'status' => 403 ],
);
}
return new WP_Error(
'yoast_seo_cannot_edit_post',
\__( 'Sorry, you are not allowed to edit this post.', 'wordpress-seo' ),
[ 'status' => 403 ],
);
}