wpseek.com
Uma área de pesquisa sobre o WordPress para devs e autores do tema
_wp_check_comment_target_post is private and should not be used in themes or plugins directly.
_wp_check_comment_target_post › WordPress Function
Desde7.1.5
Obsoleton/a
› _wp_check_comment_target_post ( $comment, $post_id )
| Acesso: |
|
| Parâmetros: (2) |
|
| Retorna: |
|
| Definido em: |
|
| Codex: |
Checks that the current user may move a comment to another post.
Mirrors the checks applied by the REST API comments controller when the parent post of a comment or note is changed.Fonte
function _wp_check_comment_target_post( WP_Comment $comment, int $post_id ) {
$post = $post_id ? get_post( $post_id ) : null;
if ( ! $post ) {
return new WP_Error( 'comment_post_invalid', __( 'Invalid post ID.' ) );
}
/*
* Notes are editorial content, so they may only be attached to a post the
* user can edit. Any other comment needs either comment moderation rights
* or edit access to the post, matching what 'edit_comment' requires on the
* post the comment is moving away from.
*/
$is_note = 'note' === strtolower( $comment->comment_type );
if ( $is_note ) {
$can_target_post = current_user_can( 'edit_post', $post->ID );
} else {
$can_target_post = current_user_can( 'moderate_comments' ) || current_user_can( 'edit_post', $post->ID );
}
if ( ! $can_target_post ) {
return new WP_Error( 'comment_post_invalid', __( 'Sorry, you are not allowed to move this comment to that post.' ) );
}
if ( ! $is_note ) {
return true;
}
$supports_notes = false;
$supports = get_all_post_type_supports( $post->post_type );
if ( isset( $supports['editor'] ) && is_array( $supports['editor'] ) ) {
$supports_notes = array_any(
$supports['editor'],
static function ( $item ) {
return is_array( $item ) && ! empty( $item['notes'] );
}
);
}
if ( ! $supports_notes ) {
return new WP_Error( 'comment_post_invalid', __( 'Sorry, this post type does not support notes.' ) );
}
if ( 'trash' === $post->post_status || ! current_user_can( 'read_post', $post->ID ) ) {
return new WP_Error( 'comment_post_invalid', __( 'Sorry, you are not allowed to move this comment to that post.' ) );
}
return true;
}