Multisite-Language-Switcher icon indicating copy to clipboard operation
Multisite-Language-Switcher copied to clipboard

Bug: Link to create new translation from edit screen is broken for pages

Open hatsumatsu opened this issue 3 years ago • 2 comments

Describe the bug

In v2.5.4 the link to create a new translation for a page in the edit screen seems to be broken. When creating/editing a page the link next to the select/search field for remote posts points to /wp-admin/post-new.php instead of /wp-admin/post-new.php?post_type=page.

To Reproduce Steps to reproduce the behavior:

  1. Create a new page
  2. Click on the flag icon in the MSLS meta box next to the select field to create a new translation in a remote site.
  3. The link points to the New post screen in the remote site instead of the New page screen

Expected behaviour The link points to /wp-admin/post-new.php?post_type=page

Screenshots

Environment (please complete the following information):

  • Plugin Version 2.5.4

hatsumatsu avatar May 27 '22 21:05 hatsumatsu

@hatsumatsu I believe that the fix in 2.5.5 solved that problem, right?

lloc avatar Jun 01 '22 15:06 lloc

@lloc In a quick test it appears that 2.5.5 is affected, too.

hatsumatsu avatar Jun 01 '22 16:06 hatsumatsu

@lloc were you able to reproduce the problem in 2.5.5 or is there anything I can help fixing it?

hatsumatsu avatar Aug 24 '22 12:08 hatsumatsu

I have the same problem with 2.5.5 - and it does not only affect pages but all posts which are not "post" type, since the parameter post_type is always missing for the "new" button if the post is saved and not a new one.

Also see https://wordpress.org/support/topic/bug-adding-translation-for-saved-pages-always-links-to-post-as-type

arnowelzel avatar Sep 04 '22 16:09 arnowelzel

I isolated the cause for this, but I don't have a solution yet.

\lloc\Msls\MslsAdminIcon::create uses \lloc\Msls\MslsPostType::get_request to determine the post type using the following code:

	/**
	 * @return string
	 */
	public function get_request(): string {
		$request   = MslsPlugin::get_superglobals( [ 'post_type' ] );
		$post_type = ! empty( $request['post_type'] ) ? esc_attr( $request['post_type'] ) : 'post';

		return in_array( $post_type, $this->get() ) ? $post_type : '';
	}

For new pages, this is page, but if the page is saved it will return post regardless of what kind of post type is edited. It seems only the request parameters are used then and not the real type of the post being edited.

arnowelzel avatar Sep 04 '22 19:09 arnowelzel

Ok, I found a solution and will create a pull request for that.

arnowelzel avatar Sep 04 '22 19:09 arnowelzel