Skip to content

Commit

Permalink
Merge pull request #592 from Chassis/591-update-to-wordpress-5.0.1
Browse files Browse the repository at this point in the history
Update to WordPress 5.0.1
  • Loading branch information
Bronson Quick committed Dec 13, 2018
2 parents 73e71a8 + e734db1 commit a8cd6f5
Show file tree
Hide file tree
Showing 13 changed files with 289 additions and 77 deletions.
112 changes: 77 additions & 35 deletions wp/wp-activate.php
Expand Up @@ -18,6 +18,50 @@
die();
}

$valid_error_codes = array( 'already_active', 'blog_taken' );

list( $activate_path ) = explode( '?', wp_unslash( $_SERVER['REQUEST_URI'] ) );
$activate_cookie = 'wp-activate-' . COOKIEHASH;

$key = '';
$result = null;

if ( isset( $_GET['key'] ) && isset( $_POST['key'] ) && $_GET['key'] !== $_POST['key'] ) {
wp_die( __( 'A key value mismatch has been detected. Please follow the link provided in your activation email.' ), __( 'An error occurred during the activation' ), 400 );
} elseif ( ! empty( $_GET['key'] ) ) {
$key = $_GET['key'];
} elseif ( ! empty( $_POST['key'] ) ) {
$key = $_POST['key'];
}

if ( $key ) {
$redirect_url = remove_query_arg( 'key' );

if ( $redirect_url !== remove_query_arg( false ) ) {
setcookie( $activate_cookie, $key, 0, $activate_path, COOKIE_DOMAIN, is_ssl(), true );
wp_safe_redirect( $redirect_url );
exit;
} else {
$result = wpmu_activate_signup( $key );
}
}

if ( $result === null && isset( $_COOKIE[ $activate_cookie ] ) ) {
$key = $_COOKIE[ $activate_cookie ];
$result = wpmu_activate_signup( $key );
setcookie( $activate_cookie, ' ', time() - YEAR_IN_SECONDS, $activate_path, COOKIE_DOMAIN, is_ssl(), true );
}

if ( $result === null || ( is_wp_error( $result ) && 'invalid_key' === $result->get_error_code() ) ) {
status_header( 404 );
} elseif ( is_wp_error( $result ) ) {
$error_code = $result->get_error_code();

if ( ! in_array( $error_code, $valid_error_codes ) ) {
status_header( 400 );
}
}

nocache_headers();

if ( is_object( $wp_object_cache ) )
Expand Down Expand Up @@ -69,13 +113,14 @@ function wpmu_activate_stylesheet() {
<?php
}
add_action( 'wp_head', 'wpmu_activate_stylesheet' );
add_action( 'wp_head', 'wp_sensitive_page_meta' );

get_header( 'wp-activate' );
?>

<div id="signup-content" class="widecolumn">
<div class="wp-activate-container">
<?php if ( empty($_GET['key']) && empty($_POST['key']) ) { ?>
<?php if ( ! $key ) { ?>

<h2><?php _e('Activation Key Required') ?></h2>
<form name="activateform" id="activateform" method="post" action="<?php echo network_site_url('wp-activate.php'); ?>">
Expand All @@ -89,42 +134,39 @@ function wpmu_activate_stylesheet() {
</form>

<?php } else {

$key = !empty($_GET['key']) ? $_GET['key'] : $_POST['key'];
$result = wpmu_activate_signup( $key );
if ( is_wp_error($result) ) {
if ( 'already_active' == $result->get_error_code() || 'blog_taken' == $result->get_error_code() ) {
$signup = $result->get_error_data();
?>
<h2><?php _e('Your account is now active!'); ?></h2>
<?php
echo '<p class="lead-in">';
if ( $signup->domain . $signup->path == '' ) {
printf(
/* translators: 1: login URL, 2: username, 3: user email, 4: lost password URL */
__( 'Your account has been activated. You may now <a href="%1$s">log in</a> to the site using your chosen username of &#8220;%2$s&#8221;. Please check your email inbox at %3$s for your password and login instructions. If you do not receive an email, please check your junk or spam folder. If you still do not receive an email within an hour, you can <a href="%4$s">reset your password</a>.' ),
network_site_url( 'wp-login.php', 'login' ),
$signup->user_login,
$signup->user_email,
wp_lostpassword_url()
);
} else {
printf(
/* translators: 1: site URL, 2: username, 3: user email, 4: lost password URL */
__( 'Your site at %1$s is active. You may now log in to your site using your chosen username of &#8220;%2$s&#8221;. Please check your email inbox at %3$s for your password and login instructions. If you do not receive an email, please check your junk or spam folder. If you still do not receive an email within an hour, you can <a href="%4$s">reset your password</a>.' ),
sprintf( '<a href="http://%1$s">%1$s</a>', $signup->domain ),
$signup->user_login,
$signup->user_email,
wp_lostpassword_url()
);
}
echo '</p>';
if ( is_wp_error( $result ) && in_array( $result->get_error_code(), $valid_error_codes ) ) {
$signup = $result->get_error_data();
?>
<h2><?php _e( 'Your account is now active!' ); ?></h2>
<?php
echo '<p class="lead-in">';
if ( $signup->domain . $signup->path == '' ) {
printf(
/* translators: 1: login URL, 2: username, 3: user email, 4: lost password URL */
__( 'Your account has been activated. You may now <a href="%1$s">log in</a> to the site using your chosen username of &#8220;%2$s&#8221;. Please check your email inbox at %3$s for your password and login instructions. If you do not receive an email, please check your junk or spam folder. If you still do not receive an email within an hour, you can <a href="%4$s">reset your password</a>.' ),
network_site_url( 'wp-login.php', 'login' ),
$signup->user_login,
$signup->user_email,
wp_lostpassword_url()
);
} else {
?>
<h2><?php _e( 'An error occurred during the activation' ); ?></h2>
<p><?php echo $result->get_error_message(); ?></p>
<?php
printf(
/* translators: 1: site URL, 2: username, 3: user email, 4: lost password URL */
__( 'Your site at %1$s is active. You may now log in to your site using your chosen username of &#8220;%2$s&#8221;. Please check your email inbox at %3$s for your password and login instructions. If you do not receive an email, please check your junk or spam folder. If you still do not receive an email within an hour, you can <a href="%4$s">reset your password</a>.' ),
sprintf( '<a href="http://%1$s">%1$s</a>', $signup->domain ),
$signup->user_login,
$signup->user_email,
wp_lostpassword_url()
);
}
echo '</p>';
} elseif ( $result === null || is_wp_error( $result ) ) {
?>
<h2><?php _e( 'An error occurred during the activation' ); ?></h2>
<?php if ( is_wp_error( $result ) ) : ?>
<p><?php echo $result->get_error_message(); ?></p>
<?php endif; ?>
<?php
} else {
$url = isset( $result['blog_id'] ) ? get_home_url( (int) $result['blog_id'] ) : '';
$user = get_userdata( (int) $result['user_id'] );
Expand Down
14 changes: 14 additions & 0 deletions wp/wp-admin/about.php
Expand Up @@ -60,6 +60,20 @@
<a href="freedoms.php?privacy-notice" class="nav-tab"><?php _e( 'Privacy' ); ?></a>
</h2>

<div class="changelog point-releases">
<h3><?php _e( 'Maintenance and Security Releases' ); ?></h3>
<p>
<?php
/* translators: %s: WordPress version number */
printf( __( '<strong>Version %s</strong> addressed some security issues.' ), '5.0.1' );
?>
<?php
/* translators: %s: Codex URL */
printf( __( 'For more information, see <a href="%s">the release notes</a>.' ), 'https://codex.wordpress.org/Version_5.0.1' );
?>
</p>
</div>

<div class="feature-section one-col">
<div class="col">
<h2><?php _e( 'Say Hello to the New Editor' ); ?></h2>
Expand Down
6 changes: 5 additions & 1 deletion wp/wp-admin/includes/ajax-actions.php
Expand Up @@ -2090,7 +2090,11 @@ function wp_ajax_upload_attachment() {
$post_id = null;
}

$post_data = isset( $_REQUEST['post_data'] ) ? $_REQUEST['post_data'] : array();
$post_data = ! empty( $_REQUEST['post_data'] ) ? _wp_get_allowed_postdata( _wp_translate_postdata( false, (array) $_REQUEST['post_data'] ) ) : array();

if ( is_wp_error( $post_data ) ) {
wp_die( $post_data->get_error_message() );
}

// If the context is custom header or background, make sure the uploaded file is an image.
if ( isset( $post_data['context'] ) && in_array( $post_data['context'], array( 'custom-header', 'custom-background' ) ) ) {
Expand Down
4 changes: 3 additions & 1 deletion wp/wp-admin/includes/class-wp-screen.php
Expand Up @@ -278,7 +278,9 @@ public static function get( $hook_name = '' ) {

switch ( $base ) {
case 'post' :
if ( isset( $_GET['post'] ) )
if ( isset( $_GET['post'] ) && isset( $_POST['post_ID'] ) && (int) $_GET['post'] !== (int) $_POST['post_ID'] )
wp_die( __( 'A post ID mismatch has been detected.' ), __( 'Sorry, you are not allowed to edit this item.' ), 400 );
elseif ( isset( $_GET['post'] ) )
$post_id = (int) $_GET['post'];
elseif ( isset( $_POST['post_ID'] ) )
$post_id = (int) $_POST['post_ID'];
Expand Down
48 changes: 35 additions & 13 deletions wp/wp-admin/includes/post.php
Expand Up @@ -174,6 +174,27 @@ function _wp_translate_postdata( $update = false, $post_data = null ) {
return $post_data;
}

/**
* Returns only allowed post data fields
*
* @since 4.9.9
*
* @param array $post_data Array of post data. Defaults to the contents of $_POST.
* @return object|bool WP_Error on failure, true on success.
*/
function _wp_get_allowed_postdata( $post_data = null ) {
if ( empty( $post_data ) ) {
$post_data = $_POST;
}

// Pass through errors
if ( is_wp_error( $post_data ) ) {
return $post_data;
}

return array_diff_key( $post_data, array_flip( array( 'meta_input', 'file', 'guid' ) ) );
}

/**
* Update an existing post with values provided in $_POST.
*
Expand Down Expand Up @@ -242,6 +263,7 @@ function edit_post( $post_data = null ) {
$post_data = _wp_translate_postdata( true, $post_data );
if ( is_wp_error($post_data) )
wp_die( $post_data->get_error_message() );
$translated = _wp_get_allowed_postdata( $post_data );

// Post Formats
if ( isset( $post_data['post_format'] ) )
Expand Down Expand Up @@ -321,7 +343,7 @@ function edit_post( $post_data = null ) {
$attachment_data = isset( $post_data['attachments'][ $post_ID ] ) ? $post_data['attachments'][ $post_ID ] : array();

/** This filter is documented in wp-admin/includes/media.php */
$post_data = apply_filters( 'attachment_fields_to_save', $post_data, $attachment_data );
$translated = apply_filters( 'attachment_fields_to_save', $translated, $attachment_data );
}

// Convert taxonomy input to term IDs, to avoid ambiguity.
Expand Down Expand Up @@ -366,26 +388,26 @@ function edit_post( $post_data = null ) {
}
}

$post_data['tax_input'][ $taxonomy ] = $clean_terms;
$translated['tax_input'][ $taxonomy ] = $clean_terms;
}
}

add_meta( $post_ID );

update_post_meta( $post_ID, '_edit_last', get_current_user_id() );

$success = wp_update_post( $post_data );
$success = wp_update_post( $translated );
// If the save failed, see if we can sanity check the main fields and try again
if ( ! $success && is_callable( array( $wpdb, 'strip_invalid_text_for_column' ) ) ) {
$fields = array( 'post_title', 'post_content', 'post_excerpt' );

foreach ( $fields as $field ) {
if ( isset( $post_data[ $field ] ) ) {
$post_data[ $field ] = $wpdb->strip_invalid_text_for_column( $wpdb->posts, $field, $post_data[ $field ] );
if ( isset( $translated[ $field ] ) ) {
$translated[ $field ] = $wpdb->strip_invalid_text_for_column( $wpdb->posts, $field, $translated[ $field ] );
}
}

wp_update_post( $post_data );
wp_update_post( $translated );
}

// Now that we have an ID we can fix any attachment anchor hrefs
Expand Down Expand Up @@ -545,27 +567,25 @@ function bulk_edit_posts( $post_data = null ) {
unset( $post_data['tax_input']['category'] );
}

$post_data['post_ID'] = $post_ID;
$post_data['post_type'] = $post->post_type;
$post_data['post_mime_type'] = $post->post_mime_type;
$post_data['guid'] = $post->guid;

foreach ( array( 'comment_status', 'ping_status', 'post_author' ) as $field ) {
if ( ! isset( $post_data[ $field ] ) ) {
$post_data[ $field ] = $post->$field;
}
}

$post_data['ID'] = $post_ID;
$post_data['post_ID'] = $post_ID;

$post_data = _wp_translate_postdata( true, $post_data );
if ( is_wp_error( $post_data ) ) {
$skipped[] = $post_ID;
continue;
}
$post_data = _wp_get_allowed_postdata( $post_data );

if ( isset( $post_data['post_format'] ) ) {
set_post_format( $post_ID, $post_data['post_format'] );
if ( isset( $shared_post_data['post_format'] ) ) {
set_post_format( $post_ID, $shared_post_data['post_format'] );
unset( $post_data['tax_input']['post_format'] );
}

Expand Down Expand Up @@ -757,9 +777,10 @@ function wp_write_post() {
$translated = _wp_translate_postdata( false );
if ( is_wp_error($translated) )
return $translated;
$translated = _wp_get_allowed_postdata( $translated );

// Create the post.
$post_ID = wp_insert_post( $_POST );
$post_ID = wp_insert_post( $translated );
if ( is_wp_error( $post_ID ) )
return $post_ID;

Expand Down Expand Up @@ -1685,6 +1706,7 @@ function wp_create_post_autosave( $post_data ) {
$post_data = _wp_translate_postdata( true, $post_data );
if ( is_wp_error( $post_data ) )
return $post_data;
$post_data = _wp_get_allowed_postdata( $post_data );

$post_author = get_current_user_id();

Expand Down
10 changes: 8 additions & 2 deletions wp/wp-admin/post.php
Expand Up @@ -16,7 +16,9 @@

wp_reset_vars( array( 'action' ) );

if ( isset( $_GET['post'] ) )
if ( isset( $_GET['post'] ) && isset( $_POST['post_ID'] ) && (int) $_GET['post'] !== (int) $_POST['post_ID'] )
wp_die( __( 'A post ID mismatch has been detected.' ), __( 'Sorry, you are not allowed to edit this item.' ), 400 );
elseif ( isset( $_GET['post'] ) )
$post_id = $post_ID = (int) $_GET['post'];
elseif ( isset( $_POST['post_ID'] ) )
$post_id = $post_ID = (int) $_POST['post_ID'];
Expand All @@ -38,6 +40,10 @@
$post_type_object = get_post_type_object( $post_type );
}

if ( isset( $_POST['post_type'] ) && $post && $post_type !== $_POST['post_type'] ) {
wp_die( __( 'A post type mismatch has been detected.' ), __( 'Sorry, you are not allowed to edit this item.' ), 400 );
}

if ( isset( $_POST['deletepost'] ) )
$action = 'delete';
elseif ( isset($_POST['wp-preview']) && 'dopreview' == $_POST['wp-preview'] )
Expand Down Expand Up @@ -189,7 +195,7 @@

// Update the thumbnail filename
$newmeta = wp_get_attachment_metadata( $post_id, true );
$newmeta['thumb'] = $_POST['thumb'];
$newmeta['thumb'] = wp_basename( $_POST['thumb'] );

wp_update_attachment_metadata( $post_id, $newmeta );

Expand Down
2 changes: 2 additions & 0 deletions wp/wp-includes/class-wp.php
Expand Up @@ -289,6 +289,8 @@ public function parse_request($extra_query_vars = '') {
foreach ( $this->public_query_vars as $wpvar ) {
if ( isset( $this->extra_query_vars[$wpvar] ) )
$this->query_vars[$wpvar] = $this->extra_query_vars[$wpvar];
elseif ( isset( $_GET[ $wpvar ] ) && isset( $_POST[ $wpvar ] ) && $_GET[ $wpvar ] !== $_POST[ $wpvar ] )
wp_die( __( 'A variable mismatch has been detected.' ), __( 'Sorry, you are not allowed to view this item.' ), 400 );
elseif ( isset( $_POST[$wpvar] ) )
$this->query_vars[$wpvar] = $_POST[$wpvar];
elseif ( isset( $_GET[$wpvar] ) )
Expand Down

0 comments on commit a8cd6f5

Please sign in to comment.