Git Product home page Git Product logo

Comments (5)

gbouteiller avatar gbouteiller commented on May 28, 2024 1

@digg I answered you about the PR and it's crystal clear as I was trying to do the same but failed with wp menu assign ( I didn't know about the runcommand magic ).
About wp pll post create, I don't know if it's possible/advised to use complex arguments ( like JSON for instance ). For now what I'm doing is :

wp pll post create fr --post_type=page --post_title='Accueil' --post_status=publish --porcelain # returns 3
wp pll post create en --post_type=page --post_title='Home' --post_status=publish --porcelain # returns 4
wp pll post bind '{ "en": 3, "fr": 4 }'

with :

public function bind( $args, $assoc_args ) {
  $bindings = json_decode( $args[0], true );
  $this->api->save_post_translations( $bindings );
  $this->cli->success( 'Posts bound.' );
}

public function create( $args, $assoc_args ) {
  list( $language ) = $args;
  
  $languages = $this->api->languages_list();
  $default_language = $this->api->default_language();

  if ( ! $this->api->is_translated_post_type( $this->cli->flag( $assoc_args, 'post_type' ) ) ) {

    $this->cli->error( 'Polylang does not manage languages and translations for this post type.' );
  }

  $porcelain = isset( $assoc_args['porcelain'] );
  $assoc_args['porcelain'] = true;

  ob_start();

  $this->cli->command( array( 'post', 'create' ), $assoc_args );

  $post_id = ob_get_clean();
  $this->api->set_post_language( $post_id, $language );
  $porcelain ? $this->cli->log( $post_id ) : $this->cli->success( sprintf( 'Created post %s.', $post_id ) );
}

The code is simple as it's just a proof of concept ( missing some error handling, etc ).
And the use could be easily simplified as :

wp pll post create --post_type=page --post_title='{ "fr": "Accueil", "en": "Home"}'  --post_status=publish --porcelain

But I don't know if it's best practice, as I mentioned above, to use JSON arg in WP-CLI philosophy.
Perhaps something like this instead :

wp pll post create --post_type=page --post_title='Accueil' --post_title_en='Home' --post-status=publish --porcelain

from polylang-cli.

diggy avatar diggy commented on May 28, 2024

@gbouteiller An important idea behind this package is that CRUD commands perform batch operations, e.g. wp post delete deletes a post, while wp pll post delete deletes a post and all its translations.

So I guess the same logic would have to be applied to wp pll post create, which would create a post and its "translations". More fine-grained control would be obtained by passing some extra params, e.g. wp pll post create 34 de would create a German translation for the post with ID 34.

Automating a multilingual setup is one of the main reasons this package exists. The use case you're describing (creating and setting home pages) is definitely something I would like to see polylang-cli be able to do. With a little creativity however (and the latest master) I think this is already possible:

$ wp option update show_on_front page
$ wp pll post generate --post_type=page --format=ids --count=1 | xargs -n1 -I {} sh -c 'wp option update page_on_front {}'

from polylang-cli.

gbouteiller avatar gbouteiller commented on May 28, 2024

At first, I was just thinking about something similar to polylang : a translation is a post, so wp pll post create is for creating only one translation ( I've forked your project to do something like that ). But I understand what you mean and it makes sense in the CRUD logic. So, how would you create a page with title and content in three different languages for example?
About your example, wp post generate doesn't give you the possibility to set titles and translations, does it? For now, I'm using the fork to generate translated pages and link them together and after that I'm able to use wp option update page_on_front.
Another question on my mind related to an issue I posted on polylang is about menu location assignments, do you want to discuss it here or do I open another issue for that?

from polylang-cli.

diggy avatar diggy commented on May 28, 2024

Unfortunately, wp post generate allows only to set the post content, title is automatically generated based on the post type object's singular_name label.

So, how would you create a page with title and content in three different languages for example?

I'm not really sure, but very much open to suggestions :) Where would the input come from?

Right now I'm thinking to use wp create post internally and duplicate the post object to the other languages.

Another question on my mind related to an issue I posted on polylang is about menu location assignments, do you want to discuss it here or do I open another issue for that?

Yes, it would be better to discuss this in another ticket.

from polylang-cli.

diggy avatar diggy commented on May 28, 2024

@gbouteiller I just pushed a wp pll menu create command at #48, we can discuss it there if you like

from polylang-cli.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.