From a94a3d303732e7a48276d6ae5da32a033edbd099 Mon Sep 17 00:00:00 2001 From: Dat Hoang Date: Mon, 17 May 2021 15:29:06 +0700 Subject: [PATCH] Sanitize slug in the hook method `maybe_keep_post_name_empty` Also update the comment of this method to reflect the current GitHub issues --- modules/custom-status/custom-status.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/modules/custom-status/custom-status.php b/modules/custom-status/custom-status.php index f3ee0231c..c76af2588 100644 --- a/modules/custom-status/custom-status.php +++ b/modules/custom-status/custom-status.php @@ -1373,10 +1373,9 @@ function fix_custom_status_timestamp( $data, $postarr ) { * @since 0.9.4 * * If the post_name is set, set it, otherwise keep it empty - * - * @see https://github.com/Automattic/Edit-Flow/issues/123 - * @see http://core.trac.wordpress.org/browser/tags/3.4.2/wp-includes/post.php#L2530 - * @see http://core.trac.wordpress.org/browser/tags/3.4.2/wp-includes/post.php#L2646 + * + * @see https://github.com/Automattic/Edit-Flow/issues/523 + * @see https://github.com/Automattic/Edit-Flow/issues/633 */ public function maybe_keep_post_name_empty( $data, $postarr ) { $status_slugs = wp_list_pluck( $this->get_custom_statuses(), 'slug' ); @@ -1389,7 +1388,7 @@ public function maybe_keep_post_name_empty( $data, $postarr ) { // If the post_name was intentionally set, set the post_name if ( ! empty( $postarr['post_name'] ) ) { - $data['post_name'] = $postarr['post_name']; + $data['post_name'] = sanitize_title( $postarr['post_name'] ); return $data; } @@ -1406,7 +1405,7 @@ public function maybe_keep_post_name_empty( $data, $postarr ) { * * `wp_unique_post_slug` is used to set the `post_name`. When a custom status is used, WordPress will try * really hard to set `post_name`, and we leverage `wp_unique_post_slug` to prevent it being set - * + * * @see: https://github.com/WordPress/WordPress/blob/396647666faebb109d9cd4aada7bb0c7d0fb8aca/wp-includes/post.php#L3932 */ public function fix_unique_post_slug( $override_slug, $slug, $post_ID, $post_status, $post_type, $post_parent ) {