Skip to content
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

Custom slug removed when Contributor submits post for review #13857

Closed
earnjam opened this issue Feb 13, 2019 · 8 comments · Fixed by #46361
Closed

Custom slug removed when Contributor submits post for review #13857

earnjam opened this issue Feb 13, 2019 · 8 comments · Fixed by #46361
Assignees
Labels
[Feature] Permalink The permalink of a post or page and the experience of setting or editing it [Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature does not function as intended

Comments

@earnjam
Copy link
Contributor

earnjam commented Feb 13, 2019

Describe the bug
When a user with the role of Contributor submits a post for review, it erases any customization to the post slug/permalink and resets to the default version based on the post title.

To Reproduce
Steps to reproduce the behavior:

  1. Create a new post as a Contributor
  2. Customize the slug in the permalink
  3. Save a draft
  4. Go back to the posts screen
  5. Edit the draft post again, see that the custom slug remains.
  6. Submit for review, notice that the permalink slug now is back to the default

Expected behavior
Slug should remain as the customized version

Screenshots
contrib-slug-reset

@earnjam earnjam added [Type] Bug An existing feature does not function as intended [Feature] Permalink The permalink of a post or page and the experience of setting or editing it labels Feb 13, 2019
@Sh4d0wHunt3rX
Copy link

Sh4d0wHunt3rX commented Mar 29, 2019

I was searching to see if this issue has been resolved after YEARS! Seems not, no one really cares about it really I guess.

This is the issue reported 4 years ago:
https://core.trac.wordpress.org/ticket/29999

3 years ago by me:
https://core.trac.wordpress.org/ticket/37262

Reported again 2 weeks ago here:
https://core.trac.wordpress.org/ticket/46486

A patch also created for it but never came with the core of the wordpress, so each time I need to patch this manually. My posts which have been created by contributors are publishing automatically after 1 year, so suddenly I see, slugs of tens of my posts have been reset. (The times that I forget to patch this after each wp update) Then I need to spend hours to rewrite those slugs!

@Mostafa-shenawy
Copy link

To fix this issue, follow these steps:

1- Go to this file => /wp-admin/includes/meta-boxes.php

2- replace this

if ( ! ( 'pending' == get_post_status( $post ) && ! current_user_can( $post_type_object->cap->publish_posts ) ) ) {
add_meta_box( 'slugdiv', __( 'Slug' ), 'post_slug_meta_box', null, 'normal', 'core', array( '__back_compat_meta_box' => true ) );
}

by this

add_meta_box( 'slugdiv', __( 'Slug' ), 'post_slug_meta_box', null, 'normal', 'core', array( '__back_compat_meta_box' => true ) );

3- Go to this file => wp-admin/edit-form-advanced.php

4- replace this

if ( $post_type_object->public && ! ( 'pending' == get_post_status( $post ) && !current_user_can( $post_type_object->cap->publish_posts ) ) ) {

by this

if ( $post_type_object->public ) {

5- Go to this file => wp-includes/post.php

6- Comment this section out

if ( ! $update && 'pending' === $post_status && ! current_user_can( $post_type_object->cap->publish_posts ) ) {
$post_name = '';
} elseif ( $update && 'pending' === $post_status && ! current_user_can( 'publish_post', $post_ID ) ) {
$post_name = '';
}

@SergeyBiryukov
Copy link
Member

Just noting that this indeed seems like a duplicate of https://core.trac.wordpress.org/ticket/29999, as mentioned above.

@Mostafa-shenawy
Copy link

@SergeyBiryukov, please check carefully again, the first step in my comment is in another file than ticket you mentioned

@akshaypinto
Copy link

Is there proposed fix for this using actions or filters rather than editing inline wordpress code. This is so that this can be made maintainable

@paaljoachim
Copy link
Contributor

I just tested with WordPress 5.7. Gutenberg plugin 10.3 and the TT1 Block editor theme.

The issue is still valid. I am getting the same result as @earnjam William did.

@Mamaduka
Copy link
Member

Mamaduka commented Dec 9, 2022

I've updated the condition when the slug is editable; the field won't be rendered if a user cannot publish the post. See #46361 for more details.

@jrxbicycle
Copy link

jrxbicycle commented Jul 23, 2024

I am running into this issue, with contributors accidentally resetting a custom slug to the post title when they submit for review (WP 6.6). #46361 was intended to solve this, right? It seems that the slug edit field is unavailable to contributors, but the slug is still being reset by this code in wp-includes/post.php

/*
 * Don't allow contributors to set the post slug for pending review posts.
 *
 * For new posts check the primitive capability, for updates check the meta capability.
 */
if ( 'pending' === $post_status ) {
	$post_type_object = get_post_type_object( $post_type );

	if ( ! $update && $post_type_object && ! current_user_can( $post_type_object->cap->publish_posts ) ) {
		$post_name = '';
	} elseif ( $update && ! current_user_can( 'publish_post', $post_id ) ) {
		$post_name = '';
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Permalink The permalink of a post or page and the experience of setting or editing it [Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants