• Resolved Xavi Ivars

    (@xavivars)


    Hi, is there any filter that can be used to prefill some content when creating new posts?

    Currently, when a post/page gets created in another language, it creates a draft with the same title than the original one, and with empty content.

    I’d tried to find it in the code, but I don’t quite get the difference between, for example, mlp_before_post_synchronization and mlp_pre_save_post. Which one is the one to use? Is there any documentation detailing what the filters are?

    Thanks a lot!

    • This topic was modified 7 years, 1 month ago by Xavi Ivars.
Viewing 1 replies (of 1 total)
  • Hi there,

    yes, there are approriate hooks to be leveraged.

    There are several differences between the two hooks you mentioned. The first one, mlp_before_post_synchronization, is an action that is being fired a single time only, just before the synchronization is about to happen. It allows you to do things before the whole process gets started, and MultilingualPress itself is using this action for a few things.

    The second, mlp_pre_save_post, is a filter that is working depending on the type of translator you are using. If you are using the simple post translator (no TinyMCE in the meta box), this filter is applied to the original post data. It allows you to manipulate the data that is used by default for all remote posts.

    If you happen to use the advanced translator (with a TinyMCE in the meta box), the latter filter is applied individually to all remote posts that exist and are about to get updated. It allows you to individually change each post’s data that is about to be stored to the database.

    In your case, however, where you are interested in manipulating the data for a new post only, you would have to use a second filter, mlp_pre_insert_post. It is fired for (remote) posts – and also depends on the type of translator. The simple one applies it to all posts, while the advanced translator only applies it for posts that are yet to be created. This is it what you want to use.

    Yes, this is pretty inconcsistent – and we are about to change and improve this with the next major release.

    Summary:
    Hook into mlp_pre_insert_post, take all two arguments, check if there is (no) content in the first (array key post_content) and accordingly take the original content (available through the WP_Post object stored in the second array, key source_post).

    In our GitHub repository, there is a Wiki with some documentation on all action and filter hooks. However, this is the same documentation you can also find inline in the code.

    But, if you have content in your original post, the draft for the remote site should include this as is – and not only the title.

    I hope this helps.

    Cheers,
    Thorsten

Viewing 1 replies (of 1 total)
  • The topic ‘Prefill content of translations’ is closed to new replies.