wikimedia / interconnection-wordpress-theme

WordPress theme created for https://diff.wikimedia.org/
GNU General Public License v2.0
3 stars 0 forks source link

#879: Lock Polylang Content Duplication to Enabled #23

Closed MiguelAxcar closed 9 months ago

MiguelAxcar commented 1 year ago

Locks Polylang Content Duplication to Enabled

Summary

This pull request adds the function toggle_polylang_content_duplication, which lock the content duplication feature to "enabled" across different languages in Polylang. By updating the 'pll_duplicate_content' user meta to "enabled," the function ensure that content duplication is always active.

The feature is controlled by this button, now always active: image

When editing a content on WordPress admin, the feature is also expected to work if the toggle gets unchecked by user and user clicks on button "+" on the language sidebar.

Functionality

The button annotated on the screenshot below, present on all the content page, leads to a link like this.

image

Related Ticket

See #879

How to Test

  1. Access a content page on frontend
  2. Find the component "Can you help us translate this article?" (screenshot above)
  3. Select a language and click on "Submit" button
  4. Verify that content of the article gets copied to the new post
  5. On the language sidebar, choose a language and click on "+" button
MiguelAxcar commented 1 year ago

Thanks for the review @kadamwhite and @goldenapples

Than, the approach you suggest is the one I am trying now.. Will flip this PR to draft.

MiguelAxcar commented 1 year ago

I pushed a new commit, which is working as expected.

I think that the most straight-forward way to accomplish this feature specs is this piece of code, but it's not working as expected - Seems that it does not use this hook to create the button.

function filter_pll_duplicate_content( $value, $user_id, $meta_key, $single ) {
    if ( $meta_key === 'pll_duplicate_content' ) {
        return [ 'post' => true ];
    }
    return $value;
}
add_filter( 'get_user_metadata', 'filter_pll_duplicate_content', 10, 4 );
MiguelAxcar commented 1 year ago

@kadamwhite Thank you for pointing out this concern.

Yeah, it does seem like it should go into a loop, but here's possible causes why it didn't in my tests:

Anyway, I added a few guards to avoid it anyway.

The feature is working as expected.

ckoerner commented 1 year ago

@ckoerner Are there any post types where we use this translation flow, other than posts or pages? I didn't see it for Events, but might have been looking in the wrong place.

The main focus is on posts and that's where the workflow mostly happens. Pages and events are rarely translated (and that's fine).