g as a valid comment * author email address. Setting the comment author email to an empty * string is allowed when a comment is being updated. * * @since 4.7.0 * * @param string $value Author email value submitted. * @param WP_REST_Request $request Full details about the request. * @param string $param The parameter name. * @return string|WP_Error The sanitized email address, if valid, * otherwise an error. */ public function check_comment_author_email( $value, $request, $param ) { $email = (string) $value; if ( empty( $email ) ) { return $email; } $check_email = rest_validate_request_arg( $email, $request, $param ); if ( is_wp_error( $check_email ) ) { return $check_email; } return $email; } /** * If empty comments are not allowed, checks if the provided comment content is not empty. * * @since 5.6.0 * * @param array $prepared_comment The prepared comment data. * @return bool True if the content is allowed, false otherwise. */ protected function check_is_comment_content_allowed( $prepared_comment ) { if ( ! isset( $prepared_comment['comment_content'] ) ) { return true; } $check = wp_parse_args( $prepared_comment, array( 'comment_post_ID' => 0, 'comment_author' => null, 'comment_author_email' => null, 'comment_author_url' => null, 'comment_parent' => 0, 'user_id' => 0, ) ); /** This filter is documented in wp-includes/comment.php */ $allow_empty = apply_filters( 'allow_empty_comment', false, $check ); if ( $allow_empty ) { return true; } // Allow empty notes only when resolution metadata is valid. if ( isset( $check['comment_type'] ) && 'note' === $check['comment_type'] && isset( $check['meta']['_wp_note_status'] ) && in_array( $check['meta']['_wp_note_status'], array( 'resolved', 'reopen' ), true ) ) { return true; } /* * Do not allow a comment to be created with missing or empty * comment_content. See wp_handle_comment_submission(). */ return '' !== $check['comment_content']; } /** * Checks that a post can receive a comment or a note from the current user. * * Used when creating a note and when changing the parent post of an existing * comment or note, so that attaching content to a post is authorized the same * way whichever path it arrives by. * * @since 7.1.1 * * @param int $post_id Target post ID. * @param WP_REST_Request $request Full details about the request. * @param bool $is_note Optional. Whether the comment is a note. Default false. * @return true|WP_Error True if the post can receive the comment, error object otherwise. */ protected function check_target_post_permission( int $post_id, WP_REST_Request $request, bool $is_note = false ) { if ( ! $post_id ) { return new WP_Error( 'rest_comment_invalid_post_id', __( 'Sorry, you are not allowed to create this comment without a post.' ), array( 'status' => 403 ) ); } /* * 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, which is what check_edit_permission() grants * on the post a comment is moving away from. Requiring the same at the * destination means both ends of a move are authorized alike. */ 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 ) { if ( $is_note ) { return new WP_Error( 'rest_cannot_create_note', __( 'Sorry, you are not allowed to create notes for this post.' ), array( 'status' => rest_authorization_required_code() ) ); } return new WP_Error( 'rest_cannot_edit', __( 'Sorry, you are not allowed to edit this comment.' ), array( 'status' => rest_authorization_required_code() ) ); } $post = get_post( $post_id ); if ( ! $post ) { return new WP_Error( 'rest_comment_invalid_post_id', __( 'Sorry, you are not allowed to create this comment without a post.' ), array( 'status' => 403 ) ); } /* * The remaining rules mirror the create-time checks for notes only. They are * deliberately not applied to other comments, because moderators move comments * onto posts whose discussion has closed and onto drafts today. Enforcing the * create-time rules there would break that without blocking anything the * capability check above already permits. */ if ( ! $is_note ) { return true; } if ( ! $this->check_post_type_supports_notes( $post->post_type ) ) { return new WP_Error( 'rest_comment_not_supported_post_type', __( 'Sorry, this post type does not support notes.' ), array( 'status' => 403 ) ); } if ( 'trash' === $post->post_status ) { return new WP_Error( 'rest_comment_trash_post', __( 'Sorry, you are not allowed to create a comment on this post.' ), array( 'status' => 403 ) ); } if ( ! $this->check_read_post_permission( $post, $request ) ) { return new WP_Error( 'rest_cannot_read_post', __( 'Sorry, you are not allowed to read the post for this comment.' ), array( 'status' => rest_authorization_required_code() ) ); } return true; } /** * Check if post type supports notes. * * @param string $post_type Post type name. * @return bool True if post type supports notes, false otherwise. */ private function check_post_type_supports_notes( $post_type ) { $supports = get_all_post_type_supports( $post_type ); if ( ! isset( $supports['editor'] ) ) { return false; } if ( ! is_array( $supports['editor'] ) ) { return false; } return array_any( $supports['editor'], fn( $item ) => ! empty( $item['notes'] ) ); } } تویوتا کارینا – بازرگانی لاستیک شریفی Skip to navigation Skip to main content
بازرگانی لاستیک شریفی، ارائه کننده انواع لاستیک و رینگ