v1.1.0
This commit is contained in:
parent
a157afe625
commit
02cd01e862
20 changed files with 1365 additions and 646 deletions
|
|
@ -124,19 +124,8 @@ if ( ! class_exists( 'AI_Translator_CLI' ) ) {
|
|||
WP_CLI::error( __( 'The --post-id and --post-type flags are mutually exclusive.', 'robotstxt-ai-translator' ) );
|
||||
}
|
||||
|
||||
$current_user = wp_get_current_user();
|
||||
if ( ! $current_user || 0 === (int) $current_user->ID ) {
|
||||
WP_CLI::warning( __( 'No user context. Pass --user=<id|login> so post updates carry an author and capability checks apply.', 'robotstxt-ai-translator' ) );
|
||||
}
|
||||
|
||||
if ( ! $dry_run && ! $this->translator->is_available() ) {
|
||||
WP_CLI::error( __( 'The WordPress AI plugin is not active.', 'robotstxt-ai-translator' ) );
|
||||
}
|
||||
|
||||
if ( ! $dry_run && ! $this->translator->is_supported() ) {
|
||||
WP_CLI::error( __( 'The WordPress AI plugin has no provider configured for text generation.', 'robotstxt-ai-translator' ) );
|
||||
}
|
||||
|
||||
// Validate locale before AI checks so the user sees the right error when
|
||||
// both the locale is missing and the AI provider is unconfigured.
|
||||
if ( ! in_array( $locale, $this->translator->get_installed_locales(), true ) ) {
|
||||
WP_CLI::error(
|
||||
sprintf(
|
||||
|
|
@ -147,9 +136,22 @@ if ( ! class_exists( 'AI_Translator_CLI' ) ) {
|
|||
);
|
||||
}
|
||||
|
||||
$current_user = wp_get_current_user();
|
||||
if ( ! $current_user || 0 === (int) $current_user->ID ) {
|
||||
WP_CLI::warning( __( 'No user context. Pass --user=<id|login> so post updates carry an author and capability checks apply.', 'robotstxt-ai-translator' ) );
|
||||
}
|
||||
|
||||
if ( ! $dry_run && ! $this->translator->is_available() ) {
|
||||
WP_CLI::error( __( 'AI features are disabled for this WordPress installation.', 'robotstxt-ai-translator' ) );
|
||||
}
|
||||
|
||||
if ( ! $dry_run && ! $this->translator->is_supported() ) {
|
||||
WP_CLI::error( __( 'No AI provider is configured for text generation. Open Settings → AI to set one up.', 'robotstxt-ai-translator' ) );
|
||||
}
|
||||
|
||||
$settings = $this->settings->get_settings();
|
||||
|
||||
if ( empty( $settings['translate_title'] ) && empty( $settings['translate_content'] ) ) {
|
||||
if ( empty( $settings['translate_title'] ) && empty( $settings['translate_content'] ) && empty( $settings['translate_excerpt'] ) ) {
|
||||
WP_CLI::error( __( 'No translation fields are enabled in the plugin settings.', 'robotstxt-ai-translator' ) );
|
||||
}
|
||||
|
||||
|
|
@ -212,6 +214,16 @@ if ( ! class_exists( 'AI_Translator_CLI' ) ) {
|
|||
$update['post_content'] = $translated_content;
|
||||
}
|
||||
|
||||
if ( ! empty( $settings['translate_excerpt'] ) && post_type_supports( $post->post_type, 'excerpt' ) ) {
|
||||
$translated_excerpt = $this->translator->translate( $post->post_excerpt, $locale );
|
||||
if ( is_wp_error( $translated_excerpt ) ) {
|
||||
WP_CLI::warning( sprintf( '#%d excerpt: %s', $post->ID, $translated_excerpt->get_error_message() ) );
|
||||
++$failures;
|
||||
continue;
|
||||
}
|
||||
$update['post_excerpt'] = $translated_excerpt;
|
||||
}
|
||||
|
||||
$result = wp_update_post( $update, true );
|
||||
|
||||
if ( is_wp_error( $result ) ) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue