Skip to content

Move preview capability checks into the specific preview handlers. #222

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions inc/read-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -461,20 +461,25 @@ public static function query() {
public static function preview() {
$response = '<p>' . __( 'Nothing to preview.', 'o2' ) . '</p>';

// Only users that can edit posts should be able to see the preview
if ( ! current_user_can( 'edit_posts' ) ) {
self::die_failure( 'cannot_edit_posts', __( 'Sorry, you are not allowed to edit posts on this site.', 'o2' ) );
}

if ( ! empty( $_REQUEST['data'] ) ) {
switch ( $_REQUEST['type'] ) {
case 'comment':
// Reserve Comment previews for logged in users if required.
if ( get_option( 'comment_registration' ) && ! is_user_logged_in() ) {
self::die_failure( 'cannot_comment', __( 'Sorry, you are not allowed to comment on this site.', 'o2' ) );
}

$response = apply_filters( 'o2_preview_comment', wp_unslash( $_REQUEST['data'] ) );
$response = wp_unslash( apply_filters( 'pre_comment_content', $response ) );
$response = trim( apply_filters( 'comment_text', $response ) );

break;
case 'post':
// Only users that can edit posts should be able to see the preview
if ( ! current_user_can( 'edit_posts' ) ) {
self::die_failure( 'cannot_edit_posts', __( 'Sorry, you are not allowed to edit posts on this site.', 'o2' ) );
}

$message = new stdClass;
$message->titleRaw = '';
$message->contentRaw = wp_unslash( $_REQUEST['data'] );
Expand Down