Skip to content

Add configurable Quick Create mode for translations#609

Open
apermo wants to merge 11 commits intolloc:masterfrom
apermo:feature/608-quick-create
Open

Add configurable Quick Create mode for translations#609
apermo wants to merge 11 commits intolloc:masterfrom
apermo:feature/608-quick-create

Conversation

@apermo
Copy link
Copy Markdown
Contributor

@apermo apermo commented Apr 15, 2026

Closes #608

Summary

  • Add Quick Create setting (Advanced Settings) that replaces the classic post-new.php link with a REST API call
  • New POST msls/v1/create-translation endpoint creates a draft post on the target blog with mapped taxonomies and MSLS links
  • Works in both the post listing columns and the editor metabox — same code path via MslsAdminIcon::get_a()
  • All data is filterable: msls_quick_create_post_data, msls_quick_create_tax_input, msls_quick_create_after_insert, msls_quick_create_response

Details

  • Default post data: title/content prefixed with From [lang]:, status draft, mapped categories/tags
  • Post meta, custom taxonomies, featured images are extensible via filters but not handled by default
  • Uses semantic <button> element with aria-label for the Quick Create trigger
  • On success the button is replaced with an edit link in place

Test plan

  • Enable Quick Create in Advanced Settings, verify the "+" icons in the post listing trigger AJAX creation
  • Verify the created draft post has correct title, content, mapped taxonomies, and MSLS link
  • Verify the icon updates to an edit link after creation
  • Disable Quick Create, verify the "+" icons link to post-new.php as before
  • Run composer test — 403 tests pass

apermo added 7 commits April 14, 2026 22:36
Add activate_quick_create checkbox to the
Advanced Settings section, allowing users to
enable silent translation creation without
leaving the current post.
Register msls/v1/create-translation POST endpoint.
Creates a draft translation post on the target
blog with mapped taxonomies and MSLS links. All
data is filterable via dedicated hooks.
Add a '+' button per language when no translation
is linked. In classic mode it opens post-new.php
in a new tab. When Quick Create is enabled, it
calls the REST API and updates the UI in place.
Add tests for permission check, source not found,
and successful translation creation. Update
existing test expectations for new setting count.
Add uglify step for msls-quick-create.js and fix
PHPStan issue in MslsRestApi taxonomy lookup.
Quick Create now applies everywhere the '+' icon
appears: post listing columns and the metabox.
The logic lives in MslsAdminIcon::get_a() so both
contexts use the same code path. Updated setting
label and allowed data attributes in wp_kses.
Replace <a href="#"> anti-pattern with a semantic
<button> element. Reset button styles via CSS,
add aria-label for accessibility, and replace the
button with an <a> edit link on success.
@apermo apermo requested a review from lloc as a code owner April 15, 2026 06:33
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a 'Quick Create' feature for the Multisite Language Switcher plugin, allowing users to generate draft translations with a single click. The implementation includes a new REST API endpoint, frontend logic for asynchronous requests, and administrative settings. Review feedback highlights a security vulnerability where source post permissions are not verified, a missing return type hint in the REST callback, and several opportunities for defensive programming, such as verifying the existence of post types and taxonomies on target blogs to improve robustness.

Comment thread includes/MslsRestApi.php
Comment thread includes/MslsRestApi.php
Comment thread includes/MslsRestApi.php
Comment thread includes/MslsRestApi.php
}

foreach ( $post_data['_msls_tax_input'] as $taxonomy => $term_ids ) {
wp_set_object_terms( $new_post_id, $term_ids, $taxonomy );
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider checking if the taxonomy exists on the target blog before calling wp_set_object_terms. This prevents potential issues if a taxonomy is not registered on all blogs in the network.

if ( taxonomy_exists( $taxonomy ) ) {
			wp_set_object_terms( $new_post_id, $term_ids, $taxonomy );
		}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

default only matches tags and categories, any custom taxonomies are to be implemented via the filters, so that is likely not an issue.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Skipped — by default only mapped categories and tags are assigned. Custom taxonomies go through the msls_quick_create_tax_input filter where the implementer controls which taxonomies to include.

Comment thread includes/MslsRestApi.php
Add read_post capability check on source blog to
prevent content leaking. Verify post_type exists
on target blog before inserting. Guard against
empty post IDs in link map iteration.
apermo added 3 commits April 15, 2026 10:35
Move the 'From xx:' prefix from prepare_post_data
into a public static filter callback registered on
msls_quick_create_post_data. Consumers can now
remove_filter to disable the prefix or replace it.
The WordPress plugin check requires the
translators comment on the line directly above
the __() call, not above the sprintf().
The 'From xx:' prefix breaks markup when applied
to post_content. Only prefix post_title by default.
Content is copied as-is from the source post.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add configurable Quick Create mode for translations

1 participant