Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -703,16 +703,24 @@ protected static function validate_upload_form() {
return 'checkbox_unchecked_license';
}

foreach ( [ 'post_title', 'post_content', 'post_excerpt' ] as $field ) {
// phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Read raw: sanitizing before the check would hide what it looks for.
// The same fields and sanitizers `sanitize_submitted_description()` stores them with.
$fields = [
'post_title' => 'sanitize_text_field',
'post_content' => 'sanitize_textarea_field',
'post_excerpt' => 'sanitize_text_field',
];

foreach ( $fields as $field => $sanitize ) {
// phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Sanitized on the next line, by whichever callback stores the field.
$submitted = isset( $_POST[ $field ] ) ? wp_unslash( $_POST[ $field ] ) : '';

// A field can arrive as an array, which Frontend Uploader drops before it builds the post.
if ( ! is_string( $submitted ) || '' === $submitted ) {
continue;
}

if ( preg_match( '/' . get_shortcode_regex() . '/', $submitted ) ) {
// Anything but a clean no-match is refused: preg_match() returns false when PCRE gives up.
if ( 0 !== preg_match( '/' . get_shortcode_regex() . '/', $sanitize( $submitted ) ) ) {
return 'shortcode-in-text';
}
}
Expand Down