diff --git a/wordpress.org/public_html/wp-content/plugins/photo-directory/inc/uploads.php b/wordpress.org/public_html/wp-content/plugins/photo-directory/inc/uploads.php index ecceb1aded..e52b9f21fc 100644 --- a/wordpress.org/public_html/wp-content/plugins/photo-directory/inc/uploads.php +++ b/wordpress.org/public_html/wp-content/plugins/photo-directory/inc/uploads.php @@ -429,6 +429,9 @@ public static function customize_fu_response_notices( $notices ) { case 'file-not-jpg': $rejection = __( 'Your submission must be an image in the JPEG format.', 'wporg-photos' ); break; + case 'shortcode-in-text': + $rejection = __( 'The title, description, and caption cannot contain shortcodes. Please remove them and submit again.', 'wporg-photos' ); + break; case 'file-too-large': $rejection = sprintf( __( 'The file size for your submission is too large. Please submit a photo smaller than %d MB in size.', 'wporg-photos' ), @@ -498,9 +501,7 @@ public static function sanitize_submitted_description( $post_array ) { continue; } - $value = $sanitize( wp_unslash( $post_array[ $field ] ) ); - - $post_array[ $field ] = wp_slash( strip_shortcodes( $value ) ); + $post_array[ $field ] = wp_slash( $sanitize( wp_unslash( $post_array[ $field ] ) ) ); } return $post_array; @@ -702,6 +703,20 @@ 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. + $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 ) ) { + return 'shortcode-in-text'; + } + } + return false; }